/* Giao diện chung cho học sinh và thầy cô. Mobile-first, dùng tốt ở 360px, chữ >= 16px, nút >= 44px. */
/* ---------- Bộ màu giao diện ----------
   Mặc định là "Bầu trời". Học sinh đổi bộ màu ở trang chính; bộ màu đặt bằng <html data-theme="...">.
   Màu Khẩn cấp (--khancap) và màu các mức DASS-21 giữ nguyên ở mọi bộ màu.
   Mỗi cặp chữ/nền đã kiểm tra độ tương phản >= 4.5 (chuẩn WCAG AA). */
:root {
  --nen: #F5F7FF; --chu: #1E2340; --chinh: #4A5BE0; --chinh-dam: #3341B8; --chinh-nhat: #E3EAFF;
  --khancap: #c62828; --vien: #D5DBF2; --trang: #fff; --nhat: #5A6180; --ok: #2e7d32;
  --bo-nut: 999px; --bo-o: 12px; --bo-the: 18px; --bong: 0 2px 10px rgba(30, 35, 64, .08);
  /* Màu 6 ô ở trang chính: nền và chữ */
  --o1-nen: #E3EAFF; --o1-chu: #2F3A9E; --o2-nen: #DCF5EA; --o2-chu: #0E6146;
  --o3-nen: #FFE6DA; --o3-chu: #9A3B12; --o4-nen: #F1E8FF; --o4-chu: #5B2D9E;
  --o5-nen: #FFF3C9; --o5-chu: #7A5600; --o6-nen: #E0F4FF; --o6-chu: #0B5577; --o-vien: transparent;
}
/* Bạc hà: xanh ngọc mát dịu */
:root[data-theme="mint"] {
  --nen: #F1FBF8; --chu: #123B35; --chinh: #0B7F74; --chinh-dam: #075E56; --chinh-nhat: #D5F3EC;
  --vien: #C7E6DE; --nhat: #4D6A65; --bong: 0 2px 10px rgba(18, 59, 53, .08);
  --o1-nen: #D5F3EC; --o1-chu: #0B5E55; --o2-nen: #FFF1C2; --o2-chu: #755300;
  --o3-nen: #FFE4DC; --o3-chu: #9A3B1E; --o4-nen: #E2EDFF; --o4-chu: #234B9A;
  --o5-nen: #F0E6FF; --o5-chu: #5B2D9E; --o6-nen: #E6F6D5; --o6-chu: #2F5A0B;
}
/* Hoàng hôn: tím ấm */
:root[data-theme="sunset"] {
  --nen: #FAF7FF; --chu: #2A1F45; --chinh: #6A45E8; --chinh-dam: #5030C2; --chinh-nhat: #ECE5FF;
  --vien: #DDD3F5; --nhat: #645A7D; --bong: 0 2px 10px rgba(42, 31, 69, .08);
  --o1-nen: #ECE5FF; --o1-chu: #4A2FB0; --o2-nen: #DDF4EE; --o2-chu: #0E5F4B;
  --o3-nen: #FFE3EC; --o3-chu: #9B2453; --o4-nen: #FFEBD6; --o4-chu: #8A4A08;
  --o5-nen: #E0EEFF; --o5-chu: #234B9A; --o6-nen: #FFF3C9; --o6-chu: #7A5600;
}
/* Cổ điển: giao diện ban đầu, ô trắng viền xám, góc bo nhỏ */
:root[data-theme="classic"] {
  --nen: #f6f9fc; --chu: #1c2a39; --chinh: #2563a8; --chinh-dam: #1b4b82; --chinh-nhat: var(--chinh-nhat);
  --vien: #c9d6e3; --nhat: #5a6b7d;
  --bo-nut: 10px; --bo-o: 8px; --bo-the: 12px; --bong: none;
  --o1-nen: #fff; --o1-chu: #1c2a39; --o2-nen: #fff; --o2-chu: #1c2a39; --o3-nen: #fff; --o3-chu: #1c2a39;
  --o4-nen: #fff; --o4-chu: #1c2a39; --o5-nen: #fff; --o5-chu: #1c2a39; --o6-nen: #fff; --o6-chu: #1c2a39;
  --o-vien: #c9d6e3;
}
* { box-sizing: border-box; }
body { margin: 0; font-family: system-ui, "Segoe UI", Roboto, sans-serif; font-size: 16px; line-height: 1.5; background: var(--nen); color: var(--chu); }
[hidden] { display: none !important; }
h2 { font-size: 1.4rem; margin: 8px 0 12px; }
a { color: var(--chinh); }

/* Thanh trên cùng */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 12px; background: var(--chinh); color: #fff; }
.topbar h1 { margin: 0; font-size: 1.1rem; }
.topbar-right { display: flex; align-items: center; gap: 8px; }
.sos { display: inline-flex; align-items: center; justify-content: center; min-height: 44px; padding: 0 14px; background: var(--khancap); color: #fff; font-weight: 700; border: 2px solid #fff; border-radius: var(--bo-nut); font-size: 1rem; cursor: pointer; }
.topbar .btn-link { color: #fff; }

.container { max-width: 640px; margin: 0 auto; padding: 16px; }
.container-wide { max-width: 960px; }

/* Hộp khẩn cấp */
.sos-panel { background: #fff3e0; border-bottom: 3px solid var(--khancap); padding: 12px 16px; }
.sos-panel[hidden] { display: none; }
.sos-panel p { margin: 4px 0; }
.sos-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 8px 0; }
.sos-number { font-size: 1.4rem; font-weight: 700; color: var(--khancap); }

/* Nút */
.btn { display: flex; align-items: center; justify-content: center; width: 100%; min-height: 48px; padding: 8px 16px; font-size: 1rem; font-weight: 600; border-radius: var(--bo-nut); border: 2px solid var(--chinh); cursor: pointer; margin: 8px 0; text-align: center; text-decoration: none; }
.btn-primary { background: var(--chinh); color: #fff; }
.btn-primary:hover { background: var(--chinh-dam); }
.btn-secondary { background: var(--trang); color: var(--chinh); }
.btn-link { background: none; border: none; color: var(--chinh); text-decoration: underline; width: auto; min-height: 44px; margin: 0; font-weight: 400; }
.btn:disabled { opacity: .6; cursor: default; }
.btn-small { width: auto; min-height: 44px; margin: 0; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible { outline: 3px solid #f9a825; outline-offset: 2px; }

/* Biểu mẫu */
.field { margin: 12px 0; }
.field label { display: block; font-weight: 600; margin-bottom: 4px; }
.field input, .field select { width: 100%; min-height: 48px; padding: 8px 12px; font-size: 1rem; border: 2px solid var(--vien); border-radius: var(--bo-o); background: var(--trang); color: var(--chu); }
.hint { margin: 4px 0 0; color: var(--nhat); font-size: .95rem; }
.message { padding: 10px 12px; background: #fdecea; color: #8e1b1b; border-radius: 8px; margin: 8px 0; }
.message[hidden] { display: none; }
.choice-row { display: flex; gap: 8px; margin: 8px 0; }
.choice-row .btn { margin: 0; }

/* Thẻ, lưới */
.card { background: var(--trang); border: 1px solid var(--vien); border-radius: var(--bo-the); padding: 16px; box-shadow: var(--bong); margin: 12px 0; }
.note { padding: 12px; background: #fff3e0; border-radius: 8px; }
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 16px 0; }
.tile { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; min-height: 120px; padding: 12px 8px; background: var(--trang); border: 2px solid var(--o-vien); border-radius: var(--bo-the); box-shadow: var(--bong); color: var(--chu); text-decoration: none; font-weight: 700; text-align: center; transition: transform .12s ease; }
.tile:active { transform: scale(.96); }
/* Mỗi ô một màu riêng để em dễ nhớ (bộ Cổ điển thì các ô đều trắng). */
.tile:nth-child(1) { background: var(--o1-nen); color: var(--o1-chu); }
.tile:nth-child(2) { background: var(--o2-nen); color: var(--o2-chu); }
.tile:nth-child(3) { background: var(--o3-nen); color: var(--o3-chu); }
.tile:nth-child(4) { background: var(--o4-nen); color: var(--o4-chu); }
.tile:nth-child(5) { background: var(--o5-nen); color: var(--o5-chu); }
.tile:nth-child(6) { background: var(--o6-nen); color: var(--o6-chu); }
.tile-icon { display: inline-flex; align-items: center; justify-content: center; width: 56px; height: 56px; font-size: 2rem; background: rgba(255, 255, 255, .7); border-radius: 50%; }
:root[data-theme="classic"] .tile-icon { width: auto; height: auto; background: none; }
/* Máy đã bật "giảm chuyển động" thì tắt hiệu ứng nhún. */
@media (prefers-reduced-motion: reduce) { .tile { transition: none; } .tile:active { transform: none; } }

/* Chọn màu giao diện (trang chính học sinh) */
.theme-picker { margin: 24px 0 8px; text-align: center; }
.theme-picker p { margin: 0 0 8px; color: var(--nhat); }
.theme-row { display: flex; justify-content: center; flex-wrap: wrap; gap: 12px; }
.theme-dot { display: flex; flex-direction: column; align-items: center; gap: 4px; min-width: 64px; padding: 4px; background: none; border: none; color: var(--chu); font-size: .9rem; font-family: inherit; cursor: pointer; }
.theme-swatch { width: 44px; height: 44px; border-radius: 50%; border: 3px solid var(--trang); box-shadow: 0 0 0 2px var(--vien); }
.theme-dot[aria-pressed="true"] { font-weight: 700; }
.theme-dot[aria-pressed="true"] .theme-swatch { box-shadow: 0 0 0 3px var(--chu); }
.theme-swatch-sky { background: linear-gradient(135deg, #4A5BE0 50%, #FFE6DA 50%); }
.theme-swatch-mint { background: linear-gradient(135deg, #0B7F74 50%, #FFF1C2 50%); }
.theme-swatch-sunset { background: linear-gradient(135deg, #6A45E8 50%, #FFE3EC 50%); }
.theme-swatch-classic { background: linear-gradient(135deg, #2563a8 50%, #ffffff 50%); }
/* Số ô lẻ: ô cuối trải hết bề ngang và thấp hơn cho cân. */
.tile:last-child:nth-child(odd) { grid-column: 1 / -1; min-height: 80px; }
.tile .dot { position: absolute; top: 10px; right: 10px; width: 14px; height: 14px; background: var(--khancap); border-radius: 50%; }
.tile .dot[hidden] { display: none; }

/* Tên đăng nhập hiển thị to */
.login-name-box { text-align: center; padding: 16px; margin: 12px 0; background: var(--chinh-nhat); border: 2px dashed var(--chinh); border-radius: 12px; }
.login-name { font-size: 1.8rem; font-weight: 800; word-break: break-all; margin: 8px 0; }

/* Menu giáo viên */
.menu { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px 12px; background: var(--chinh-nhat); border-bottom: 1px solid var(--vien); }
.menu a { display: inline-flex; align-items: center; min-height: 44px; padding: 0 12px; border-radius: 8px; text-decoration: none; font-weight: 600; background: var(--trang); border: 1px solid var(--vien); }
.menu a.active { background: var(--chinh); color: #fff; border-color: var(--chinh); }

/* Thông báo nhỏ */
.toast { position: fixed; left: 12px; right: 12px; bottom: 16px; max-width: 480px; margin: 0 auto; padding: 12px 16px; background: var(--chu); color: #fff; border-radius: 10px; z-index: 50; }
.toast-error { background: #8e1b1b; }
.disclaimer { color: var(--nhat); font-size: .95rem; }

/* Chat */
.chat-list { display: flex; flex-direction: column; gap: 8px; height: 50vh; min-height: 240px; overflow-y: auto; padding: 8px; background: var(--trang); border: 1px solid var(--vien); border-radius: var(--bo-the); }
.bubble { max-width: 85%; padding: 8px 12px; border-radius: 14px; word-break: break-word; }
.bubble-mine { align-self: flex-end; background: var(--chinh); color: #fff; }
.bubble-other { align-self: flex-start; background: #e8eef5; }
.bubble-who { font-size: .85rem; font-weight: 700; }
.bubble-text { white-space: pre-wrap; }
.bubble-time { font-size: .8rem; opacity: .8; text-align: right; }
.chat-img { display: block; max-width: 100%; max-height: 260px; border-radius: 8px; margin-top: 4px; }
.seen { align-self: flex-end; font-size: .85rem; color: var(--nhat); }
.composer { margin-top: 8px; }
.chat-input, .filters input[type=search], .filters select, .side select, .side input[type=text], .side textarea { width: 100%; padding: 8px 12px; font-size: 1rem; border: 2px solid var(--vien); border-radius: var(--bo-o); min-height: 44px; font-family: inherit; }
.composer-row { display: flex; gap: 8px; justify-content: flex-end; margin-top: 4px; }
.conv-item { display: block; text-decoration: none; color: var(--chu); }
.badge { display: inline-block; margin-left: 8px; padding: 2px 8px; background: var(--khancap); color: #fff; border-radius: 10px; font-size: .85rem; }
.badge-urgent { background: #c62828; }
.conv-item-urgent { border-left: 6px solid #c62828; background: #fff4f4; }
.urgent-hint { margin-top: 8px; }
.filters { display: grid; gap: 8px; margin-bottom: 8px; }
.check { display: flex; align-items: center; gap: 8px; min-height: 44px; }
.check input { width: 24px; height: 24px; }
.detail-grid { display: grid; gap: 16px; }
@media (min-width: 800px) { .detail-grid { grid-template-columns: 2fr 1fr; } }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.chip { min-height: 44px; padding: 0 12px; border-radius: 22px; border: 1px solid var(--chinh); background: var(--chinh-nhat); color: var(--chinh-dam); cursor: pointer; }
.note-item { padding: 8px; margin: 6px 0; background: #fffbe6; border-radius: 8px; }
.side label { display: block; font-weight: 600; margin-top: 8px; }

/* Báo cáo */
.steps { font-weight: 700; color: var(--chinh-dam); }
.badge-status { background: var(--chinh); }
.bubble-mine-card { background: var(--chinh-nhat); }
.field textarea { width: 100%; padding: 8px 12px; font-size: 1rem; border: 2px solid var(--vien); border-radius: var(--bo-o); font-family: inherit; }
.check input[type=checkbox] { flex: none; }
.info-row { margin: 4px 0; }
.badge-internal { background: #6d4c41; }

/* Kiểm tra cảm xúc */
.btn-option { justify-content: flex-start; text-align: left; background: var(--trang); color: var(--chu); border-color: var(--vien); }
.btn-option.selected { border-color: var(--chinh); background: var(--chinh-nhat); color: var(--chinh-dam); }
.question { font-size: 1.2rem; margin: 8px 0 16px; }
.level { display: inline-block; padding: 2px 10px; border-radius: 10px; font-weight: 700; border: 2px solid; }
.level-normal { background: #e8f5e9; color: #1b5e20; border-color: #2e7d32; }
.level-mild { background: #fffde7; color: #6b5900; border-color: #b59a00; }
.level-moderate { background: #fff3e0; color: #8a4b00; border-color: #e07b00; }
.level-severe { background: #fdecea; color: #a31515; border-color: #c62828; }
.level-extreme { background: #6a1b9a; color: #fff; border-color: #4a148c; }

/* Quản trị và podcast */
.tabs { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 12px; }
.tab { min-height: 44px; padding: 0 16px; border: 2px solid var(--chinh); border-radius: 22px; background: var(--trang); color: var(--chinh-dam); font-weight: 600; cursor: pointer; }
.tab.active { background: var(--chinh); color: #fff; }
.player { width: 100%; aspect-ratio: 16 / 9; min-height: 200px; border: 0; border-radius: 10px; margin-top: 8px; }
.note textarea { width: 100%; font-family: inherit; font-size: .95rem; }
.card .btn-small { margin-top: 8px; }
.footer { text-align: center; padding-top: 0; }
.footer a { display: inline-flex; align-items: center; min-height: 44px; }

/* ---------- M15 Thống kê ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin: 12px 0; }
.stat-number { font-size: 1.75rem; font-weight: 700; margin: 4px 0; }
.chart-box { position: relative; height: 240px; margin-bottom: 12px; }
.stat-table { width: 100%; border-collapse: collapse; font-size: 1rem; }
.stat-table th, .stat-table td { text-align: left; padding: 8px 6px; border-bottom: 1px solid #e2e8f0; }

/* S18 – Cuộc thi trắc nghiệm */
.quiz-progress { height: 8px; background: var(--vien); border-radius: 4px; overflow: hidden; margin: 4px 0 12px; }
.quiz-progress > div { height: 100%; background: var(--chinh); }
.quiz-question { font-size: 1.2rem; }
.quiz-options { display: grid; gap: 10px; margin: 12px 0; }
.quiz-option { display: flex; align-items: center; gap: 12px; width: 100%; min-height: 56px; padding: 10px 12px; font-size: 1rem; text-align: left; color: var(--chu); background: var(--trang); border: 2px solid var(--vien); border-radius: var(--bo-o); cursor: pointer; font-family: inherit; }
.quiz-option[aria-pressed="true"] { border-color: var(--chinh); background: var(--chinh-nhat); font-weight: 600; }
.quiz-letter { flex: 0 0 36px; height: 36px; display: inline-flex; align-items: center; justify-content: center; border-radius: 50%; background: var(--nen); border: 2px solid var(--vien); font-weight: 700; }
.quiz-option[aria-pressed="true"] .quiz-letter { background: var(--chinh); border-color: var(--chinh); color: #fff; }
.quiz-result { text-align: center; }
.quiz-editor-q { border-left: 4px solid var(--chinh); }
.quiz-editor-q .field input[type=radio] { width: auto; min-height: auto; }
.quiz-answer-row { display: flex; align-items: center; gap: 8px; margin: 6px 0; }
.quiz-answer-row input[type=text] { flex: 1; min-height: 44px; padding: 8px 12px; font-size: 1rem; border: 2px solid var(--vien); border-radius: 8px; }
.quiz-answer-row input[type=radio] { width: 24px; height: 24px; }
.quiz-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.quiz-actions .btn { width: auto; }
.table-scroll { overflow-x: auto; }
.quiz-deadline { font-weight: 600; color: var(--khancap); }
.quiz-check { display: flex; align-items: center; gap: 10px; min-height: 44px; margin: 8px 0; cursor: pointer; }
.quiz-check input { width: 22px; height: 22px; flex: 0 0 auto; }
.field input[type=datetime-local] { width: 100%; }
