/* --- Reset & Base --- */
*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #0056d2; /* Màu xanh dương chủ đạo */
    --primary-light: #e6f0ff;
    --secondary-color: #f8f9fa; /* Màu nền sáng */
    --text-color: #343a40; /* Màu chữ chính */
    --text-light: #6c757d; /* Màu chữ phụ */
    --border-color: #dee2e6;
    --success-bg: #d1e7dd;
    --success-text: #0a3622;
    --error-bg: #f8d7da;
    --error-text: #58151c;
    --selected-bg: #cfe2ff;
    --selected-text: #052c65;
    --white: #ffffff;
    --shadow: 0 4px 15px rgba(0, 0, 0, 0.07);
    --border-radius: 8px;
    --font-family: 'Nunito Sans', sans-serif;
}

body {
    font-family: var(--font-family);
    background-color: var(--secondary-color);
    color: var(--text-color);
    line-height: 1.6;
    font-size: 16px;
}

.container {
    max-width: 900px; /* Giới hạn chiều rộng để dễ đọc */
    margin: 30px auto;
    background: var(--white);
    box-shadow: var(--shadow);
    border-radius: var(--border-radius);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    min-height: calc(100vh - 60px); /* Đảm bảo footer ở cuối */
}

/* --- Header --- */
.site-header {
    background-color: var(--primary-color);
    color: var(--white);
    padding: 15px 25px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: relative; /* Để định vị nút Help */
}

#myHeading {
    font-size: 1.6em;
    font-weight: 700;
    margin: 0;
}

.top-right-controls {
    position: static; /* Reset vị trí tuyệt đối cũ */
}

/* --- Progress Bar --- */
.progress-bar-container {
    padding: 20px 25px 0;
}

.progress-bar {
    width: 100%;
    background-color: #e9ecef;
    border-radius: var(--border-radius);
    overflow: hidden;
    cursor: pointer;
    height: 28px;
    position: relative;
    border: 1px solid var(--border-color);
}

.progress {
    height: 100%;
    background-color: var(--primary-color);
    transition: width 0.5s ease-in-out;
    border-radius: var(--border-radius); /* Chỉ bo góc bên trái nếu cần */
}

.progress-text {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--white); /* Màu chữ trên thanh progress */
    font-weight: 600;
    font-size: 0.9em;
    text-shadow: 1px 1px 1px rgba(0, 0, 0, 0.2);
    /* Đảm bảo text hiển thị tốt cả khi thanh progress đầy hoặc vơi */
    mix-blend-mode: difference; /* Thử nghiệm để chữ luôn tương phản */
    filter: invert(1) grayscale(1) contrast(10); /* Một cách khác */
}

/* --- Main Content --- */
#main-content {
    padding: 25px;
    flex-grow: 1; /* Đẩy footer xuống */
}

#content {
    margin-bottom: 20px;
}

#content p {
    font-weight: 600;
    font-size: 1.1em;
    margin-bottom: 15px;
    color: var(--text-color);
}

#content ul {
    list-style: none;
    padding: 0;
    margin-bottom: 30px; /* Khoảng cách giữa các câu hỏi */
}

/* --- Question/Answer Styling --- */
.question-block {
  padding: 15px;
  margin-bottom: 25px;
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
  transition: border-color 0.3s;
  position: relative;
  background-color: #fff; /* Nền trắng cho khối câu hỏi */
}

.question-block.completed {
  border-color: var(--primary-color);
}

/* Icon AI (Positioning giữ nguyên từ script.js) */
.ai-icon {
    position: absolute;
    top: 10px; /* Điều chỉnh nếu cần */
    right: 10px;
    font-size: 24px;
    cursor: pointer;
    color: var(--primary-color);
    opacity: 0.8;
    transition: opacity 0.3s;
}
.ai-icon:hover {
    opacity: 1;
}

#content li, #content h6 {
    display: block; /* Đảm bảo là block element */
    background-color: var(--secondary-color);
    margin: 8px 0;
    padding: 12px 15px;
    cursor: pointer;
    border-radius: 6px;
    border: 1px solid var(--border-color);
    transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease;
    font-weight: 400; /* Reset font-weight */
    font-size: 1em; /* Reset font-size */
}

#content li:hover, #content h6:hover {
    background-color: #e9ecef;
    border-color: #adb5bd;
}

#content li.selected, #content h6.selected {
    background-color: var(--selected-bg);
    color: var(--selected-text);
    border-color: var(--primary-color);
    font-weight: 600;
}

#content li.correct, #content h6.correct {
    background-color: var(--success-bg);
    color: var(--success-text);
    border-color: #a3cfbb;
    font-weight: 600;
}

#content li.incorrect {
    background-color: var(--error-bg);
    color: var(--error-text);
    border-color: #f1aeae;
    font-weight: 600;
}

#content li.disabled, #content h6.disabled {
    pointer-events: none;
    opacity: 0.7;
}

/* Image Styling trong câu hỏi/trả lời */
#content img {
    max-width: 100%; /* Ảnh không vượt quá container */
    height: auto;
    display: block; /* Tránh khoảng trắng thừa */
    margin: 10px auto; /* Căn giữa ảnh nếu cần */
    border-radius: 4px;
}

#content li .imd img, #content p .imd img {
    display: inline-block; /* Cho ảnh inline */
    vertical-align: middle;
    margin: 0 5px;
    max-width: 30px; /* Giới hạn kích thước ảnh inline nhỏ */
    max-height: 30px;
    filter: none; /* Bỏ filter mặc định nếu có */
}

/* --- Link List Styling --- */
#untestedLinks {
    list-style: none;
    padding: 0;
}

#untestedLinks li {
    background-color: var(--white);
    padding: 15px 20px;
    margin-bottom: 10px;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    cursor: pointer;
    transition: background-color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
    font-weight: 600;
}

#untestedLinks li:hover {
    background-color: var(--primary-light);
    border-color: var(--primary-color);
    box-shadow: 0 2px 8px rgba(0, 86, 210, 0.15);
    transform: translateY(-2px);
}

/* --- Buttons --- */
#controls {
    padding: 0 25px 25px; /* Padding cho khu vực nút điều khiển */
    display: flex;
    gap: 15px; /* Khoảng cách giữa các nút */
    justify-content: center; /* Căn giữa các nút */
}

button {
    padding: 12px 25px;
    border: none;
    border-radius: var(--border-radius);
    font-size: 1em;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
    background-color: var(--primary-color);
    color: var(--white);
    box-shadow: 0 2px 5px rgba(0, 86, 210, 0.2);
}

button:hover {
    background-color: #0041a1; /* Màu đậm hơn khi hover */
    box-shadow: 0 4px 10px rgba(0, 86, 210, 0.3);
    transform: translateY(-1px);
}

button:active {
     background-color: #00317a;
     transform: translateY(0);
     box-shadow: 0 1px 3px rgba(0, 86, 210, 0.2);
}

/* Nút phụ (ví dụ: Chọn bài khác) */
#chooseAnotherTest {
    background-color: var(--text-light);
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}
#chooseAnotherTest:hover {
     background-color: #5a6268;
     box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
}
#chooseAnotherTest:active {
     background-color: #495057;
     box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}


button:disabled {
    background-color: #adb5bd;
    cursor: not-allowed;
    opacity: 0.6;
    box-shadow: none;
    transform: none;
}

/* --- Analytics Section (Chart & History Table) --- */
#analytics {
    padding: 25px;
    background-color: var(--secondary-color); /* Nền hơi khác biệt */
    border-top: 1px solid var(--border-color);
    margin-top: 20px;
}

#analytics h2 {
    text-align: center;
    margin-bottom: 20px;
    font-size: 1.4em;
    color: var(--text-color);
}

#myChart {
    max-width: 100%;
    height: auto; /* Để Chart.js tự quản lý */
    margin-bottom: 30px;
}

#studyHistoryTable {
    max-width: 100%;
    overflow-x: auto; /* Cho phép cuộn ngang trên màn hình nhỏ */
}

#studyHistoryTable table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.95em;
}

#studyHistoryTable th, #studyHistoryTable td {
    padding: 10px 12px;
    border: 1px solid var(--border-color);
    text-align: center;
    vertical-align: middle;
}

#studyHistoryTable th {
    background-color: #e9ecef;
    font-weight: 600;
}

#studyHistoryTable td:nth-child(3) { /* Cột Tên bài học */
    text-align: left;
    min-width: 250px; /* Giữ cột tên bài rộng hơn */
}

#studyHistoryTable tr:nth-child(even) {
    background-color: var(--white);
}

#studyHistoryTable tr:hover {
    background-color: var(--primary-light);
}

/* --- Footer Toolbar --- */
.toolbar-bottom {
    background-color: #343a40; /* Màu nền tối */
    color: var(--white);
    padding: 12px 25px;
    text-align: center;
    font-weight: 600;
    font-size: 1.05em;
    margin-top: auto; /* Đẩy xuống cuối nếu container flex */
}

/* --- Help Button & Modal --- */
.help-button {
    background-color: rgba(255, 255, 255, 0.2); /* Bán trong suốt trên nền header */
    color: var(--white);
    border: 1px solid rgba(255, 255, 255, 0.5);
    padding: 8px 15px;
    border-radius: 6px;
    font-size: 0.9em;
    display: inline-flex; /* Cho icon và text */
    align-items: center;
    gap: 6px;
    box-shadow: none;
}
.help-button:hover {
    background-color: rgba(255, 255, 255, 0.3);
    border-color: var(--white);
    transform: none; /* Bỏ hiệu ứng transform */
}
.help-icon {
    font-weight: bold;
    font-size: 1.1em;
}

.help-modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.6);
  z-index: 1050; /* Cao hơn các element khác */
  overflow-y: auto;
  padding: 30px;
}

.help-modal-content {
  background-color: var(--white);
  margin: 5% auto;
  padding: 30px;
  border: none;
  max-width: 650px;
  border-radius: var(--border-radius);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
  position: relative;
  animation: fadeInModal 0.3s ease-out;
}

@keyframes fadeInModal {
    from { opacity: 0; transform: translateY(-20px); }
    to { opacity: 1; transform: translateY(0); }
}

.help-modal-content h2 {
  color: var(--primary-color);
  font-size: 1.5em;
  margin-top: 0;
  margin-bottom: 15px;
  border-bottom: 2px solid var(--border-color);
  padding-bottom: 10px;
}
.help-modal-content h3 {
  color: var(--text-color);
  font-size: 1.2em;
  margin-top: 20px;
  margin-bottom: 10px;
}

.help-modal-content ol {
  list-style-position: inside;
  padding-left: 5px;
  margin-bottom: 15px;
}

.help-modal-content li {
  color: var(--text-light);
  font-size: 1em;
  margin-bottom: 10px;
}

.help-modal-content li b {
  color: var(--text-color);
  font-weight: 600;
}

.help-modal-content p {
  color: var(--text-light);
  font-size: 1em;
  margin-bottom: 10px;
}
.help-modal-content p b {
    color: var(--error-text);
}

.help-close {
  position: absolute;
  top: 15px;
  right: 15px;
  color: #aaa;
  font-size: 28px;
  font-weight: bold;
  cursor: pointer;
  line-height: 1;
  transition: color 0.2s ease;
}
.help-close:hover { color: #555; }

/* --- AI Support Button & Box --- */
.support-toggle-btn {
    position: fixed;
    bottom: 25px;
    right: 25px;
    background: var(--primary-color);
    color: var(--white);
    border: none;
    width: 60px; /* Nút tròn */
    height: 60px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 28px; /* Kích thước icon lớn hơn */
    font-weight: normal;
    font-family: inherit;
    box-shadow: 0 5px 15px rgba(0, 86, 210, 0.3);
    transition: all 0.3s ease;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    padding: 0; /* Reset padding */
}

.support-toggle-btn:hover {
    background-color: #0041a1;
    transform: translateY(-3px) scale(1.05);
    box-shadow: 0 8px 20px rgba(0, 86, 210, 0.4);
}
.support-toggle-btn:active {
    transform: translateY(0) scale(1);
    box-shadow: 0 3px 10px rgba(0, 86, 210, 0.3);
}

/* AI Chat Box */
.support-box {
  position: fixed;
  bottom: 100px; /* Nâng lên trên nút toggle */
  right: 25px;
  width: 400px; /* Chiều rộng vừa phải */
  height: 65vh; /* Chiều cao tương đối */
  max-height: 600px; /* Giới hạn chiều cao tối đa */
  background: var(--white);
  border-radius: var(--border-radius);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
  overflow: hidden;
  z-index: 1010;
  display: none; /* Mặc định ẩn */
  flex-direction: column; /* Header trên, iframe dưới */
  border: 1px solid var(--border-color);
  animation: slideInUp 0.4s ease-out;
}

@keyframes slideInUp {
    from { opacity: 0; transform: translateY(30px); }
    to { opacity: 1; transform: translateY(0); }
}


.support-box.visible {
  display: flex;
}

.support-header-bar {
    background: var(--primary-color);
    color: white;
    padding: 10px 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0; /* Không co lại */
}

.support-header-bar .header-logo {
  font-size: 1.1em;
  font-weight: bold;
}

.support-header-bar .close-btn {
  background: none;
  border: none;
  color: white;
  font-size: 24px;
  cursor: pointer;
  padding: 0 5px;
  line-height: 1;
  opacity: 0.8;
  transition: opacity 0.2s;
}
.support-header-bar .close-btn:hover {
   opacity: 1;
}

.support-box iframe {
  flex-grow: 1; /* Chiếm hết không gian còn lại */
  border: none;
  width: 100%;
  height: 100%; /* Quan trọng */
}


/* --- Responsive --- */
@media (max-width: 768px) {
    body {
        font-size: 15px;
    }
    .container {
        width: 95%;
        margin: 15px auto;
        min-height: calc(100vh - 30px);
    }
    .site-header {
        padding: 12px 15px;
        flex-direction: column; /* Stack title and button */
        align-items: flex-start;
    }
    #myHeading {
        font-size: 1.4em;
        margin-bottom: 5px;
    }
    .top-right-controls {
        align-self: flex-end; /* Move button to the right */
    }

    .progress-bar-container {
        padding: 15px 15px 0;
    }
    #main-content, #analytics, #controls {
        padding: 15px;
    }
    #content li, #content h6 {
        padding: 10px 12px;
    }
     #untestedLinks li {
        padding: 12px 15px;
        font-size: 0.95em;
    }
    #controls {
        flex-direction: column; /* Stack buttons vertically */
        gap: 10px;
    }
    button {
        width: 100%; /* Full width buttons */
    }
    #studyHistoryTable th, #studyHistoryTable td {
        padding: 8px;
        font-size: 0.9em;
    }
     #studyHistoryTable td:nth-child(3) { /* Cột Tên bài học */
        min-width: 180px;
    }

    .support-box {
        width: 90%;
        height: 70vh;
        right: 5%;
        bottom: 90px;
    }
    .support-toggle-btn {
        bottom: 20px;
        right: 20px;
        width: 55px;
        height: 55px;
        font-size: 24px;
    }
     .help-modal-content {
        width: 95%;
        padding: 20px;
     }
}

@media (max-width: 480px) {
    .progress-text {
        font-size: 0.8em;
    }
     #myHeading {
        font-size: 1.3em;
    }
    .help-button {
        font-size: 0.85em;
        padding: 6px 10px;
    }
}
/* Container chính của hộp chat */
.support-box {
  /* Giữ các thuộc tính vị trí, kích thước, nền, bóng đổ cũ */
  position: fixed;
  /* bottom: 80px; /* Có thể cần điều chỉnh vị trí Y */
  /* right: 20px; */
  bottom: 20px; /* Đặt lại vị trí gần nút gốc hơn nếu muốn */
  right: 20px;
  width: 500px; /* Chiều rộng tổng thể */
  height: 60vh; /* Chiều cao tổng thể */
  background: white;
  border-radius: 16px; /* Bo góc */
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.2);
  overflow: hidden; /* Quan trọng */
  z-index: 1000;

  /* --- THAY ĐỔI QUAN TRỌNG --- */
  display: none; /* Mặc định ẩn */
  flex-direction: row; /* Sắp xếp con theo hàng ngang (header trái, iframe phải) */
}

/* Khi hộp chat được mở (có class visible) */
.support-box.visible {
  display: flex; /* Hiện và áp dụng flexbox */
}

/* Thanh header dọc bên trái */
.support-header-bar {
  background: #007bff; /* Màu nền xanh */
  color: white;
  width: 55px; /* Chiều rộng cố định cho thanh dọc */
  height: 100%; /* Chiều cao 100% của container */
  padding: 10px 0; /* Padding trên dưới */
  display: flex;
  flex-direction: column; /* Sắp xếp logo và nút đóng theo chiều dọc */
  justify-content: space-between; /* Đẩy logo lên trên, nút đóng xuống dưới */
  align-items: center; /* Căn giữa theo chiều ngang */
  flex-shrink: 0; /* Không cho phép thanh này co lại */
  box-sizing: border-box; /* Tính cả padding vào width */
}

/* Logo/Title trong header */
.support-header-bar .header-logo {
  font-size: 14px;
  font-weight: bold;
  margin-top: 10px; /* Khoảng cách trên */
  /* Có thể xoay chữ nếu muốn */
  /* writing-mode: vertical-rl; */
  /* transform: rotate(180deg); */
}

/* Phần chứa nút đóng */
.support-header-bar .header-controls {
   margin-bottom: 5px; /* Khoảng cách dưới */
}

/* Nút đóng (X) */
.support-header-bar .close-btn {
  background: none;
  border: none;
  color: white;
  font-size: 24px; /* Kích thước nút X */
  cursor: pointer;
  padding: 0; /* Bỏ padding mặc định */
  line-height: 1; /* Căn chỉnh chiều cao */
}
 .support-header-bar .close-btn:hover {
   opacity: 0.8; /* Hiệu ứng hover đơn giản */
}


/* Iframe chứa nội dung chat */
.support-box iframe {
  flex-grow: 1; /* Chiếm hết không gian ngang còn lại */
  height: 100%; /* Chiếm hết chiều cao */
  border: none; /* Bỏ viền */
  width: auto; /* Để flex-grow kiểm soát chiều rộng */
}

/* --- CSS cho nút bật/tắt gốc --- */
.support-toggle-btn {
  /* Giữ nguyên CSS cũ cho nút này */
  position: fixed;
  bottom: 20px;
  right: 20px;
  /* ... các thuộc tính khác ... */
  z-index: 999; /* Nằm dưới hộp chat khi mở */
}

 /* --- Responsive cho màn hình nhỏ --- */
 @media (max-width: 768px) {
   .support-box {
     width: 95%;
     height: 80vh;
     bottom: 10px; /* Điều chỉnh vị trí */
     right: 2.5%;
   }
   .support-header-bar {
      width: 45px; /* Thu nhỏ thanh header */
   }
    .support-header-bar .header-logo {
       font-size: 12px;
    }
    .support-header-bar .close-btn {
       font-size: 20px;
    }
 }
/* --- CSS Nâng Cấp cho Nút Trợ Lý AI --- */
.support-toggle-btn {
  position: fixed;
  bottom: 25px; /* Hơi nâng lên một chút */
  right: 25px;  /* Hơi cách lề một chút */
  background: linear-gradient(145deg, #0088ff, #0061c5); /* Gradient xanh dương hiện đại */
  color: #fff;
  border: none;
  padding: 10px 20px; /* Điều chỉnh padding */
  border-radius: 12px; /* Bo góc vuông vắn hơn, hiện đại hơn */
  cursor: pointer;
  font-size: 16px;
  font-weight: 600; /* Giữ nguyên hoặc 500 */
  font-family: 'Roboto', sans-serif; /* Đảm bảo font được áp dụng */
  letter-spacing: 0.5px; /* Tăng khoảng cách chữ một chút */
  box-shadow: 0 4px 10px rgba(0, 97, 197, 0.2), /* Bóng mờ chính */
              0 1px 3px rgba(0, 0, 0, 0.1);       /* Bóng nhẹ gần hơn */
  transition: all 0.25s cubic-bezier(0.25, 0.8, 0.25, 1); /* Transition mượt mà hơn */
  z-index: 999;
  display: inline-flex; /* Sử dụng flex để căn chỉnh icon và text */
  align-items: center;
  gap: 8px; /* Khoảng cách giữa icon và text */
  white-space: nowrap; /* Không xuống dòng */
}

.support-toggle-btn:hover {
  background: linear-gradient(145deg, #007ae0, #0055b0); /* Gradient đậm hơn khi hover */
  transform: translateY(-3px); /* Hiệu ứng nhấc lên nhẹ */
  box-shadow: 0 7px 18px rgba(0, 97, 197, 0.3), /* Bóng đổ rõ hơn khi hover */
              0 3px 6px rgba(0, 0, 0, 0.15);
}

.support-toggle-btn:active {
  transform: translateY(0px); /* Hiệu ứng nhấn xuống */
  background: #0056b3; /* Màu nền đậm khi nhấn */
  box-shadow: 0 2px 5px rgba(0, 97, 197, 0.2); /* Bóng đổ nhỏ hơn khi nhấn */
}
