/* --- Reset & Base Styles --- */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Lato', 'Arial', sans-serif;
    background-color: #f8f9fa;
    color: #343a40;
    line-height: 1.6;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    min-height: 100vh;
    padding: 20px;
}

/* --- Main Container --- */
#quiz-container {
    background-color: #ffffff;
    border-radius: 12px;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.08);
    width: 100%;
    max-width: 900px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

header {
    background-color: #4a90e2; /* Primary Blue */
    color: #ffffff;
    padding: 20px 30px;
    text-align: center;
}

h1 {
    font-size: 1.7rem;
    font-weight: 700;
}

main {
    padding: 25px 30px;
}

aside#history-and-progress {
    background-color: #f1f3f5;
    padding: 25px 30px;
    border-top: 1px solid #dee2e6;
}

/* --- Question Area --- */
#question-container {
    margin-bottom: 25px;
}

.initial-message {
     color: #6c757d;
     font-style: italic;
     text-align: center;
     padding: 15px 0;
}

.question {
    background-color: #ffffff;
    padding: 18px;
    margin-bottom: 18px;
    border: 1px solid #e9ecef;
    border-radius: 8px;
}

.question p:first-child { /* Question text */
    font-size: 1.1rem;
    font-weight: 700;
    margin-bottom: 15px;
    color: #212529;
}

.options {
    list-style: none;
    padding: 0;
}

.options label {
    display: flex;
    align-items: center;
    background-color: #f8f9fa;
    padding: 12px 15px;
    border: 1px solid #dee2e6;
    border-radius: 6px;
    cursor: pointer;
    transition: background-color 0.2s ease, border-color 0.2s ease;
    position: relative;
    font-size: 1rem;
    margin-bottom: 8px;
    min-height: 48px;
}

.options label:hover {
    background-color: #e9ecef;
    border-color: #adb5bd;
}

/* Hide default radio button visually but keep accessible */
.options input[type="radio"] {
    position: absolute;
    opacity: 0;
    width: 1.1em; /* Match size of custom one */
    height: 1.1em;
    left: 12px; /* Position near custom one */
    top: 50%;
    transform: translateY(-50%);
    margin: 0;
    cursor: pointer;
    z-index: 1; /* Place above custom visuals initially */
}

/* Custom radio button visual container */
.options label .custom-radio {
    width: 22px;
    height: 22px;
    border: 2px solid #adb5bd;
    border-radius: 50%;
    margin-right: 12px; /* Space between radio and text */
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: #fff;
    transition: border-color 0.2s ease;
    flex-shrink: 0; /* Prevent shrinking */
}

/* Custom radio button inner dot */
.options label .custom-radio::after {
    content: '';
    display: block;
    width: 12px;
    height: 12px;
    background-color: #4a90e2; /* Blue color */
    border-radius: 50%;
    transform: scale(0); /* Hidden by default */
    transition: transform 0.2s ease;
}

/* --- Style changes when the radio IS CHECKED --- */
/* Change the border of the custom radio */
.options input[type="radio"]:checked + .custom-radio {
    border-color: #4a90e2; /* Blue border */
}

/* Show the inner dot */
.options input[type="radio"]:checked + .custom-radio::after {
    transform: scale(1); /* Show inner dot */
}

/* --- Attempt to style LABEL background on check (Based on original CSS idea, may not work reliably cross-browser) --- */
/* This targets the label directly when the INPUT *inside* it is checked. Standard CSS doesn't directly support this well. */
/* We rely on specific browser behavior or potential future :has() support */
/* For more reliability, use JavaScript to add a 'selected' class */
.options input[type="radio"]:checked ~ label { /* Attempting general sibling combinator, might work in some edge cases */
    /* background-color: #e7f3ff; */ /* Light blue background - Commented out as likely unreliable */
    /* border-color: #a6cfff; */
    /* font-weight: bold; */
}
/* More specific attempt (often needed) */
.options label:has(input[type="radio"]:checked) { /* Uses :has() - Check browser support! */
     background-color: #e7f3ff;
     border-color: #a6cfff;
     /* font-weight: bold; */ /* Optional */
}
/* Fallback if :has() isn't supported: Only the custom radio circle/dot will change visually. */


/* Focus style - Apply to the custom radio visual */
.options input[type="radio"]:focus + .custom-radio {
     box-shadow: 0 0 0 3px rgba(74, 144, 226, 0.3);
}

/* --- Styles AFTER Grading (JS adds .correct/.incorrect to label) --- */
.options label.correct {
    border-color: #28a745 !important;
    background-color: #e9f7ef !important;
    color: #155724;
    font-weight: bold;
}
.options label.correct .custom-radio { /* Style custom radio */
     border-color: #28a745 !important;
}
.options label.correct .custom-radio::after { /* Style inner dot */
    background-color: #28a745 !important;
     transform: scale(1) !important; /* Ensure visible */
}

.options label.incorrect {
    border-color: #dc3545 !important;
    background-color: #fdeeee !important;
    color: #721c24;
    font-weight: bold;
}
.options label.incorrect .custom-radio { /* Style custom radio */
     border-color: #dc3545 !important;
}
/* Keep inner dot blue if selected + incorrect, to show selection */
.options input[type="radio"]:checked + .custom-radio.incorrect::after { /* This selector needs JS class */
    /* Requires JS to add 'incorrect' class to custom-radio span if label has it */
    background-color: #4a90e2 !important;
    transform: scale(1) !important;
}
/* If NOT checked, but is the correct answer (shown after grading) */
.options label.correct:not(:has(input:checked)) .custom-radio::after {
    /* Needs :has() or JS class */
     background-color: #28a745 !important;
     transform: scale(1) !important;
}


/* --- Controls --- */
#controls { margin-top: 25px; text-align: center; padding-top: 20px; border-top: 1px solid #e9ecef; }
#result { font-size: 1.2rem; font-weight: 700; margin-bottom: 15px; color: #4a90e2; min-height: 1.5em; }
.btn { color: white; padding: 12px 25px; border: none; border-radius: 6px; font-size: 1rem; font-weight: 700; cursor: pointer; transition: background-color 0.2s ease, box-shadow 0.2s ease; margin: 5px; display: inline-block; }
.btn-primary { background-color: #4a90e2; }
.btn-primary:hover { background-color: #357ABD; box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); }
.btn:disabled { background-color: #adb5bd; cursor: not-allowed; box-shadow: none; }

/* --- Sidebar / History / Progress --- */
.history-section { margin-bottom: 30px; }
.history-section h2 { font-size: 1.3rem; color: #343a40; margin-bottom: 15px; border-bottom: 2px solid #4a90e2; padding-bottom: 5px; display: inline-block; }
#history-container ul { list-style: none; padding-left: 0; margin-top: 10px; }
#history-container li { background-color: #fff0f1; border: 1px solid #f5c6cb; border-left: 4px solid #dc3545; padding: 10px 15px; margin-bottom: 10px; border-radius: 4px; font-size: 0.9rem; }
#history-container li p { margin-bottom: 5px; word-wrap: break-word; }
#history-container li strong { color: #721c24; }
#history-container .correct { color: #155724; font-weight: bold; }
#history-container .incorrect { color: #721c24; font-weight: bold; }
#final-history-container .average-percentage { font-size: 1.1rem; font-weight: bold; text-align: center; color: #333; margin-bottom: 20px; background-color: #e9ecef; padding: 12px; border-radius: 6px; }
#final-history-container .history-table { width: 100%; border-collapse: collapse; margin-top: 15px; font-size: 0.9rem; }
#final-history-container .history-table thead { background-color: #4a90e2; color: #fff; }
#final-history-container .history-table th,
#final-history-container .history-table td { padding: 10px 12px; border: 1px solid #dee2e6; text-align: center; }
#final-history-container .history-table tbody tr:nth-child(even) { background-color: #f8f9fa; }
#final-history-container .history-table tbody tr:hover { background-color: #e9ecef; }
#spiderChart, #chart { margin: 25px auto; display: block; max-width: 100%; height: auto; background-color: #fff; padding: 10px; border-radius: 8px; border: 1px solid #e9ecef; }

/* --- Responsive --- */
@media (max-width: 768px) {
    body { padding: 10px; }
    #quiz-container { max-width: 100%; }
    main, aside#history-and-progress { padding: 20px; }
    h1 { font-size: 1.5rem; }
    .question p:first-child { font-size: 1rem; }
    .options label { font-size: 0.95rem; padding: 10px 12px; padding-left: 40px; }
    .options label .custom-radio { left: 10px; width: 20px; height: 20px; }
    .options label .custom-radio::after { left: 5px; top: 5px; width: 10px; height: 10px; /* Re-center inner */ }
    .btn { padding: 10px 20px; font-size: 0.95rem; }
    #result { font-size: 1.1rem; }
    .history-section h2 { font-size: 1.2rem; }
    #final-history-container .history-table th,
    #final-history-container .history-table td { padding: 8px 10px; font-size: 0.85rem; }
}
@media (max-width: 480px) {
     header { padding: 15px 20px; }
    h1 { font-size: 1.3rem; }
     main, aside#history-and-progress { padding: 15px; }
     .question { padding: 12px; }
    .btn { width: 100%; margin: 5px 0; }
    #controls { display: flex; flex-direction: column; }
     .options label { padding-left: 42px; }
     .options label .custom-radio { left: 12px; }
     .options label .custom-radio::after { left: 5px; top: 5px; /* Re-center inner */ }
}
/* 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 */
}
/* --- CSS cho Nút Hướng dẫn --- */
.help-btn {
    position: absolute;
    top: 15px; /* Điều chỉnh vị trí trên/dưới */
    right: 20px; /* Điều chỉnh vị trí trái/phải */
    background-color: #fff;
    color: #4a90e2; /* Màu xanh dương chính */
    border: 1px solid #4a90e2;
    border-radius: 50%; /* Làm tròn nút */
    width: 35px; /* Kích thước nút */
    height: 35px;
    font-size: 1.3rem; /* Kích thước dấu '?' */
    font-weight: bold;
    cursor: pointer;
    line-height: 33px; /* Căn giữa dấu '?' theo chiều dọc */
    text-align: center;
    padding: 0;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
    transition: background-color 0.2s, color 0.2s, box-shadow 0.2s;
    z-index: 10; /* Đảm bảo nút nằm trên header */
}

.help-btn:hover {
    background-color: #e7f3ff; /* Màu nền nhạt hơn khi hover */
    color: #357ABD; /* Màu chữ đậm hơn khi hover */
    box-shadow: 0 4px 8px rgba(0,0,0,0.15);
}

/* Đảm bảo header có đủ không gian cho nút */
header {
    position: relative; /* Cần thiết để định vị tuyệt đối cho nút con */
    padding-right: 65px; /* Thêm padding bên phải header nếu cần */
}


/* --- CSS cho Modal Hướng dẫn --- */
.modal-overlay {
    display: none; /* Ẩn modal mặc định */
    position: fixed; /* Giữ cố định trên màn hình */
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.6); /* Lớp phủ mờ màu đen */
    justify-content: center; /* Căn giữa theo chiều ngang */
    align-items: center; /* Căn giữa theo chiều dọc */
    z-index: 1050; /* Đảm bảo modal nằm trên cùng */
    padding: 20px; /* Thêm padding để tránh sát viền */
}

.modal-visible {
    display: flex; /* Hiện modal */
}

.modal-content {
    background-color: #fff;
    padding: 25px 30px; /* Padding bên trong modal */
    border-radius: 10px; /* Bo góc */
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
    max-width: 90%; /* Chiều rộng tối đa */
    width: 750px; /* Chiều rộng cụ thể */
    max-height: 85vh; /* Chiều cao tối đa, chiếm 85% chiều cao màn hình */
    overflow-y: auto; /* Thêm thanh cuộn nếu nội dung dài */
    position: relative; /* Để định vị nút đóng */
}

.modal-content h2 {
     margin-top: 0;
     color: #4a90e2; /* Màu xanh dương cho tiêu đề */
     border-bottom: 2px solid #e9ecef; /* Đường gạch dưới */
     padding-bottom: 10px;
     margin-bottom: 20px;
     font-size: 1.5rem;
}

.modal-content h3 {
    margin-top: 25px;
    margin-bottom: 10px;
    color: #343a40; /* Màu chữ đậm hơn */
    font-size: 1.2rem;
}

 .modal-content p, .modal-content li {
     margin-bottom: 12px; /* Khoảng cách giữa các đoạn/mục */
     line-height: 1.7; /* Giãn dòng */
     color: #495057; /* Màu chữ nội dung */
 }

 .modal-content ul {
     padding-left: 25px; /* Thụt lề cho danh sách */
     list-style: disc; /* Dấu chấm đầu dòng */
 }

 .modal-content strong {
      color: #007bff; /* Màu nhấn mạnh */
      font-weight: 600;
 }

.modal-close-btn {
    position: absolute;
    top: 10px; /* Vị trí nút đóng */
    right: 15px;
    background: none;
    border: none;
    font-size: 2rem; /* Kích thước nút đóng 'x' */
    font-weight: bold;
    color: #adb5bd; /* Màu nút đóng */
    cursor: pointer;
    line-height: 1;
    padding: 5px;
    transition: color 0.2s;
}

.modal-close-btn:hover {
    color: #555; /* Màu nút đóng khi hover */
}

/* Responsive cho modal */
@media (max-width: 768px) {
    .modal-content {
        width: 90%;
        max-width: 600px; /* Giảm chiều rộng tối đa */
        padding: 20px;
    }
    .modal-content h2 {
        font-size: 1.3rem;
    }
     .modal-content h3 {
        font-size: 1.1rem;
    }
}

@media (max-width: 480px) {
     .help-btn {
         width: 30px;
         height: 30px;
         font-size: 1.1rem;
         line-height: 28px;
         top: 12px;
         right: 15px;
     }
     header {
         padding-right: 55px; /* Điều chỉnh padding header cho màn hình nhỏ */
     }
    .modal-content {
        width: 95%;
        padding: 15px;
    }
    .modal-close-btn {
        top: 5px;
        right: 10px;
        font-size: 1.8rem;
    }
}
/* --- Backup & Restore Section --- */
.backup-restore {
    margin-top: 2rem;
    padding-top: 1.5rem;
    border-top: 1px solid #dee2e6;
	    padding: 30px;
}

.backup-restore h3 {
    margin-bottom: 1rem;
}

.backup-restore button,
.restore-label {
    display: inline-block; /* Align next to each other */
    margin-right: 1rem;
    margin-bottom: 0.5rem; /* Spacing for wrapping */
    padding: 0.6rem 1.2rem;
    font-size: 0.9rem;
    font-weight: 500;
    border: 1px solid #007bff;
    border-radius: 6px;
    cursor: pointer;
    transition: background-color 0.2s ease, color 0.2s ease;
    background-color: #fff;
    color: #007bff;
    text-align: center;
}

.backup-restore button:hover,
.restore-label:hover {
    background-color: #e7f3ff;
}

.backup-restore .restore-label {
    background-color: #28a745; /* Green for restore */
    border-color: #28a745;
    color: white;
}
.backup-restore .restore-label:hover {
     background-color: #218838;
     border-color: #1e7e34;
}

.backup-restore .note {
    font-size: 0.85rem;
    color: #6c757d;
    margin-top: 0.5rem;
}