/* ============================================================
   S4E Education — theo brand logo:
   trời xanh đậm #0E3070→#1D57B8, mây trắng, vàng rồng #F6B41F,
   đỏ cam cổng #E4552F. Chữ tròn đầy (Baloo 2) + Be Vietnam Pro.
   ============================================================ */
:root {
  --navy: #0e3070;
  --royal: #1d57b8;
  --royal-soft: #e8f0fc;
  --sky-bg: #f2f7fd;
  --gold: #f6b41f;
  --gold-deep: #d8940a;
  --gold-soft: #fdf3d9;
  --coral: #e4552f;
  --coral-soft: #fdece6;
  --olive: #3f8a4f;
  --olive-soft: #e9f5eb;
  --ink: #17284e;
  --ink-soft: #5a6b8c;
  --card: #ffffff;
  --line: #dde7f3;
  --r: 16px;
  --font-display: "Baloo 2", "Be Vietnam Pro", sans-serif;
  --font-body: "Be Vietnam Pro", "Segoe UI", sans-serif;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
.login-card input { width: 100%; }
html, body { margin: 0; background: var(--sky-bg); color: var(--ink); font-family: var(--font-body); font-size: 15.5px; line-height: 1.55; }
h1, h2, h3 { font-family: var(--font-display); font-weight: 700; margin: 0 0 0.35em; line-height: 1.15; }
h1 { font-size: 1.6rem; } h2 { font-size: 1.12rem; } h3 { font-size: 0.98rem; }
.muted { color: var(--ink-soft); font-size: 0.88rem; }
.tiny { color: var(--ink-soft); font-size: 0.78rem; }

/* ---------- Shell: sidebar + content ---------- */
.shell { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }

.sidebar {
  background: linear-gradient(175deg, var(--royal) 0%, var(--navy) 78%);
  color: #fff;
  padding: 22px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.logo { font-family: var(--font-display); font-weight: 800; font-size: 1.5rem; padding: 0 10px 14px; letter-spacing: 0.01em; }
.logo .four { color: var(--gold); }
.logo small { display: block; font-size: 0.62rem; font-weight: 600; letter-spacing: 0.16em; color: #bcd2f5; }

.sidebar nav button {
  display: block; width: 100%; text-align: left;
  font-family: var(--font-display); font-weight: 600; font-size: 0.95rem;
  background: transparent; color: #d7e5fb; border: none;
  border-radius: 999px; padding: 10px 16px; cursor: pointer;
}
.sidebar nav button:hover { background: rgba(255,255,255,0.12); color: #fff; }
.sidebar nav button.active { background: var(--gold); color: var(--navy); }
.sidebar .who { margin-top: auto; padding: 12px 10px 34px; font-size: 0.85rem; color: #cfdffa; position: relative; z-index: 1; }
.sidebar .who b { color: #fff; display: block; }
.sidebar .who button { background: none; border: none; color: var(--gold); text-decoration: underline; cursor: pointer; padding: 0; font-size: 0.8rem; }
.sidebar .clouds { position: absolute; left: 0; right: 0; bottom: 0; opacity: 0.9; pointer-events: none; }

main.content {
  padding: clamp(18px, 2.6vw, 38px) clamp(14px, 3vw, 44px) 120px;
  max-width: 1320px;
  margin: 0 auto;
  width: 100%;
  min-width: 0;
}

/* Header band mỗi trang — dải trời + mây (signature) */
.band {
  position: relative;
  background: linear-gradient(120deg, var(--royal), #2f6fd6 60%, #3f83e8);
  color: #fff;
  border-radius: var(--r);
  padding: clamp(18px, 2.4vw, 30px) clamp(20px, 2.8vw, 34px);
  margin-bottom: 22px;
  overflow: hidden;
}
.band h1 { color: #fff; margin-bottom: 2px; }
.band .muted { color: #d9e7fc; }
.band svg.cl { position: absolute; right: -8px; bottom: -10px; width: 240px; opacity: 0.55; }

/* ---------- Cards & grid ---------- */
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
@media (max-width: 880px) { .grid2, .grid3 { grid-template-columns: 1fr; } }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 18px 20px; margin-bottom: 16px; }
.stat { text-align: left; }
.stat .num { font-family: var(--font-display); font-weight: 800; font-size: 1.9rem; color: var(--royal); line-height: 1; }
.stat .num.gold { color: var(--gold-deep); }
.stat .lbl { font-size: 0.82rem; color: var(--ink-soft); margin-top: 4px; }

.pill { display: inline-block; border-radius: 999px; font-size: 0.74rem; font-weight: 600; padding: 3px 11px; margin-right: 6px; }
.pill.blue { background: var(--royal-soft); color: var(--royal); }
.pill.gold { background: var(--gold-soft); color: var(--gold-deep); }
.pill.red { background: var(--coral-soft); color: var(--coral); }
.pill.green { background: var(--olive-soft); color: var(--olive); }
.pill.gray { background: #eef1f6; color: var(--ink-soft); }

.up { color: var(--olive); font-weight: 700; }
.down { color: var(--coral); font-weight: 700; }

/* ---------- Bảng ---------- */
table.tbl { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.tbl th { text-align: left; font-size: 0.74rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-soft); padding: 8px 10px; border-bottom: 2px solid var(--line); }
.tbl td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tbl tr:hover td { background: var(--sky-bg); }
.tbl .mono, .mono { font-variant-numeric: tabular-nums; font-weight: 600; }

/* ---------- Buttons & forms ---------- */
.btn {
  font-family: var(--font-display); font-weight: 700; font-size: 0.92rem;
  border: none; border-radius: 999px; padding: 10px 22px; cursor: pointer;
  background: var(--royal); color: #fff;
}
.btn:hover { background: var(--navy); }
.btn.gold { background: var(--gold); color: var(--navy); }
.btn.gold:hover { background: var(--gold-deep); color: #fff; }
.btn.ghost { background: var(--royal-soft); color: var(--royal); }
.btn.small { padding: 7px 14px; font-size: 0.82rem; }
.btn:focus-visible, .linkbtn:focus-visible { outline: 3px solid rgba(246,180,31,0.6); outline-offset: 2px; }
.linkbtn { background: none; border: none; color: var(--royal); font-weight: 600; cursor: pointer; padding: 0; text-decoration: underline; font-size: 0.88rem; }

label { display: block; font-weight: 600; font-size: 0.86rem; margin: 12px 0 4px; }
input[type="text"], input[type="password"], input[type="number"], input[type="date"], textarea, select {
  width: 100%; border: 1.5px solid var(--line); border-radius: 12px;
  padding: 10px 12px; font-family: var(--font-body); font-size: 0.95rem; background: #fff; color: var(--ink);
}
textarea { min-height: 90px; resize: vertical; }
input:focus, textarea:focus, select:focus { outline: 3px solid rgba(29,87,184,0.25); }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 8px; margin: 4px 0 16px; flex-wrap: wrap; }
.tabs button {
  font-family: var(--font-display); font-weight: 700; font-size: 0.9rem;
  border: 1.5px solid var(--line); background: #fff; color: var(--ink-soft);
  border-radius: 999px; padding: 8px 18px; cursor: pointer;
}
.tabs button.active { background: var(--navy); border-color: var(--navy); color: #fff; }
.tabs.sub button.active { background: var(--gold); border-color: var(--gold); color: var(--navy); }

/* ---------- Chart ---------- */
.chartbox { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 16px; }
.chartbox svg { width: 100%; height: auto; display: block; }

/* ---------- Diagnostics / gợi ý ---------- */
.diag { border: 1px solid var(--line); border-left: 5px solid var(--line); border-radius: 12px; background: #fff; padding: 12px 16px; margin-bottom: 10px; }
.diag.red { border-left-color: var(--coral); }
.diag.orange { border-left-color: var(--gold); }
.diag.yellow { border-left-color: #b9ce46; }
.diag .warn { font-weight: 700; font-size: 0.93rem; }
.diag .sugg { font-size: 0.88rem; margin-top: 3px; }
.diag .evid { font-size: 0.76rem; color: var(--ink-soft); margin-top: 6px; border-top: 1px dashed var(--line); padding-top: 5px; font-variant-numeric: tabular-nums; }
.diag.teacher-only { background: var(--gold-soft); }
.diag.teacher-only .tonly { font-size: 0.72rem; font-weight: 700; color: var(--gold-deep); }

.skilltrend { display: grid; grid-template-columns: minmax(0, 1fr) minmax(56px, 110px) max-content; gap: 8px; align-items: center; padding: 7px 0; border-bottom: 1px solid var(--line); font-size: 0.88rem; }
.skilltrend > span:first-child { min-width: 0; overflow-wrap: break-word; }
.skilltrend > .mono { white-space: nowrap; font-size: 0.82rem; }
.skilltrend .bar { height: 10px; border-radius: 5px; background: var(--sky-bg); overflow: hidden; border: 1px solid var(--line); }
.skilltrend .bar i { display: block; height: 100%; background: var(--royal); }

/* ---------- Homework ---------- */
.hw { border: 1px solid var(--line); border-radius: var(--r); background: #fff; padding: 14px 18px; margin-bottom: 12px; }
.hw .head { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; flex-wrap: wrap; }
.hw .fb { background: var(--royal-soft); border-radius: 10px; padding: 10px 14px; margin-top: 10px; font-size: 0.9rem; }
.hw .ai { background: var(--gold-soft); border-radius: 10px; padding: 12px 14px; margin-top: 10px; font-size: 0.9rem; white-space: pre-line; }
.thread { margin-top: 10px; border-top: 1px dashed var(--line); padding-top: 8px; }
.thread .msg { font-size: 0.87rem; padding: 4px 0; }
.thread .msg b { color: var(--royal); }

/* ---------- Login ---------- */
.login-wrap { min-height: 100vh; min-height: 100dvh; overflow-y: auto; display: flex; align-items: center; justify-content: center; padding: 24px;
  background: linear-gradient(165deg, #2f6fd6 0%, var(--royal) 40%, var(--navy) 100%); }
.login-card { background: #fff; border-radius: 22px; padding: 34px 34px 28px; width: 100%; max-width: 440px; box-shadow: 0 18px 60px rgba(6, 24, 64, 0.4); }
.login-card .logo { color: var(--navy); font-size: 2rem; padding: 0 0 4px; }
.rolebtns { display: flex; gap: 8px; margin-top: 6px; }
.rolebtns button { flex: 1; font-family: var(--font-display); font-weight: 700; border: 2px solid var(--line); background: #fff; color: var(--ink-soft); border-radius: 12px; padding: 12px 6px; cursor: pointer; font-size: 0.9rem; }
.rolebtns button.active { border-color: var(--gold); background: var(--gold-soft); color: var(--navy); }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--navy); color: #fff; border-radius: 999px; padding: 11px 22px; font-size: 0.9rem; opacity: 0; pointer-events: none; transition: opacity 0.25s; z-index: 60; }
.toast.show { opacity: 1; }

.dropzone { border: 2px dashed var(--royal); border-radius: var(--r); background: #fff; padding: 34px 22px; text-align: center; cursor: pointer; }
.dropzone.over { background: var(--royal-soft); border-style: solid; }

.view { display: none; }
.view.visible { display: block; animation: rise 0.22s ease; }
@keyframes rise { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .view.visible { animation: none; } }

/* ---------- Nhóm nút chọn (thay dropdown) ---------- */
.choices { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 6px; }
.choices button {
  font-family: var(--font-body); font-weight: 600; font-size: 0.84rem;
  border: 1.5px solid var(--line); background: #fff; color: var(--ink-soft);
  border-radius: 999px; padding: 7px 14px; cursor: pointer;
}
.choices button:hover { border-color: var(--royal); color: var(--royal); }
.choices button.active { background: var(--royal); border-color: var(--royal); color: #fff; }
.choices button:focus-visible { outline: 3px solid rgba(246,180,31,0.6); outline-offset: 1px; }

/* ---------- Trinh xem hoc lieu bao ve ---------- */
.viewer-backdrop { position: fixed; inset: 0; background: rgba(6,20,50,0.8); z-index: 50; display: flex; align-items: center; justify-content: center; padding: 18px; }
.viewer-box { position: relative; background: #fff; border-radius: var(--r); width: min(1000px, 96vw); height: min(86vh, 760px); display: flex; flex-direction: column; overflow: hidden; }
.viewer-bar { display: flex; justify-content: space-between; align-items: center; padding: 10px 16px; border-bottom: 1px solid var(--line); }
.viewer-body { flex: 1; overflow: hidden; }
.viewer-body iframe, .viewer-body video { width: 100%; height: 100%; border: none; display: block; background: #000; }
.wm { position: absolute; inset: 42px 0 0; pointer-events: none; display: flex; flex-wrap: wrap; align-content: space-around; justify-content: space-around; opacity: 0.14; transform: rotate(-24deg) scale(1.3); font-family: var(--font-display); font-weight: 800; font-size: 1rem; color: var(--navy); z-index: 5; }
.wm span { padding: 26px 34px; white-space: nowrap; }
@media print { body { display: none !important; } }

/* ---------- Test player 2 cot ---------- */
.split { display: flex; height: 74vh; border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; background: #fff; }
.split .pane-l { overflow: hidden; } .split .pane-l iframe { width: 100%; height: 100%; border: none; }
.split .pane-r { overflow-y: auto; padding: 14px 16px; border-left: 1px solid var(--line); }
.qrow { padding: 8px 0; border-bottom: 1px solid var(--line); }
.qrow .qn { font-weight: 700; margin-right: 8px; }
.lock { opacity: 0.55; }
.badge-days { font-size: 0.72rem; color: var(--olive); font-weight: 700; }

.avatar-btn { width: 40px; height: 40px; border-radius: 50%; border: 2px solid var(--gold); background: var(--royal); color: #fff; font-size: 1.1rem; cursor: pointer; display: block; margin-bottom: 6px; overflow: hidden; padding: 0; }
.avatar-btn img { width: 100%; height: 100%; object-fit: cover; }
.help-fab { position: fixed; right: 22px; bottom: 22px; width: 46px; height: 46px; border-radius: 50%; border: none; background: var(--gold); color: var(--navy); font-family: var(--font-display); font-weight: 800; font-size: 1.3rem; cursor: pointer; box-shadow: 0 6px 18px rgba(6,24,64,0.35); z-index: 45; }
.req { color: var(--coral); font-weight: 700; }
.tagline { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0; }
.tag { background: var(--royal-soft); color: var(--royal); border-radius: 999px; padding: 3px 12px; font-size: 0.8rem; font-weight: 600; border: none; cursor: pointer; }
.tag.solid { background: var(--royal); color: #fff; }
.tag .x { margin-left: 6px; font-weight: 800; }
.pager { display: flex; gap: 6px; align-items: center; margin-top: 10px; }
.tbl td.merge { background: var(--sky-bg); font-weight: 700; }

/* Giữ lại các tinh chỉnh nhỏ độc lập từ bản cũ */
.card { overflow-x: auto; }
table.tbl { min-width: 540px; }
#who-ava { background: transparent !important; border: 2px solid #fff !important; color: #fff !important; }
.bugico { display: inline-block; width: 14px; height: 14px; margin-right: 6px; vertical-align: -2px; }

/* ============================================================
   DYNAMIC SIZING v11 — lưới tự co giãn theo bề rộng thật:
   điện thoại 1 cột, tablet 2 cột, desktop 2–3 cột. Không cần
   media query riêng nhờ auto-fill + minmax(min(...,100%),1fr).
   ============================================================ */
.cardgrid {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(auto-fill, minmax(min(430px, 100%), 1fr));
  align-items: start;
  margin-bottom: 16px;
}
.cardgrid > .card, .cardgrid > .hw { margin-bottom: 0; min-width: 0; }

.cols2 {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(auto-fit, minmax(min(430px, 100%), 1fr));
  align-items: start;
  margin-bottom: 16px;
}
.cols2 > .card { margin-bottom: 0; min-width: 0; }

/* Nút nổi: ? hướng dẫn (vàng) + ⚠ báo lỗi (đỏ cam) xếp chồng góc phải dưới */
#help-fab, #bug-fab {
  position: fixed; right: 22px;
  width: 52px; height: 52px; border-radius: 50%; border: none;
  cursor: pointer; box-shadow: 0 6px 20px rgba(6, 24, 64, 0.35); z-index: 45;
  display: flex; align-items: center; justify-content: center; padding: 0;
}
#help-fab { bottom: 22px; background: var(--gold); color: var(--navy); font-family: var(--font-display); font-weight: 800; font-size: 1.5rem; }
#bug-fab { bottom: 86px; background: var(--coral); }
#bug-fab:hover { background: #c8451f; }

/* Nút ＋ thêm giáo viên trong Phân công lớp */
.addtag {
  display: inline-flex; align-items: center; justify-content: center;
  width: 26px; height: 26px; border-radius: 50%;
  border: 1.5px dashed var(--royal); background: #fff; color: var(--royal);
  font-weight: 800; font-size: 1rem; line-height: 1; cursor: pointer;
  vertical-align: middle; margin-left: 4px;
}
.addtag:hover { background: var(--royal); color: #fff; border-style: solid; }

/* Màn rất rộng: chữ dễ đọc hơn một chút */
@media (min-width: 1440px) {
  html, body { font-size: 16.5px; }
}

/* ============================================================
   RESPONSIVE v10 — một nơi duy nhất, đặt CUỐI file để thắng cascade.
   Desktop giữ nguyên sidebar dọc 240px; máy tính bảng/điện thoại
   chuyển sang thanh bar trên cùng + hàng menu cuộn ngang.
   ============================================================ */

/* ---- Máy tính bảng & điện thoại (≤ 880px) ---- */
@media (max-width: 880px) {
  .shell { grid-template-columns: 1fr; }

  /* Sidebar → top bar dính trên cùng: hàng 1 = logo + người dùng, hàng 2 = menu cuộn ngang */
  .sidebar {
    position: sticky; top: 0; z-index: 40;
    height: auto; min-height: 0;
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-areas: "logo who" "nav nav";
    align-items: center;
    gap: 4px 10px;
    padding: 8px 12px 8px;
    padding-top: calc(8px + env(safe-area-inset-top));
    box-shadow: 0 4px 14px rgba(6, 24, 64, 0.25);
  }
  .sidebar .clouds { display: none; }
  .sidebar .logo { grid-area: logo; font-size: 1.15rem; padding: 0; }
  .sidebar .logo small { display: none; }

  .sidebar nav {
    grid-area: nav;
    display: flex; flex-wrap: nowrap; gap: 6px;
    overflow-x: auto; -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding: 2px 0 4px;
  }
  .sidebar nav::-webkit-scrollbar { display: none; }
  .sidebar nav button { width: auto; flex: none; white-space: nowrap; font-size: 0.85rem; padding: 9px 14px; min-height: 40px; }

  /* Khối người dùng: giữ avatar + tên + Đăng xuất (bản cũ ẩn mất → mobile không đăng xuất được) */
  .sidebar .who { grid-area: who; margin-top: 0; padding: 0; display: flex; align-items: center; gap: 8px; }
  .sidebar .who #who-role { display: none !important; }
  .sidebar .who b { font-size: 0.8rem; max-width: 110px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .sidebar .who #who-ava { width: 34px !important; height: 34px !important; font-size: 0.9rem !important; }

  main.content { padding: 16px 12px calc(96px + env(safe-area-inset-bottom)); max-width: none; }

  .band { padding: 16px 16px; }
  .band svg.cl { display: none; }
  h1 { font-size: 1.3rem; }
  .card { padding: 14px 14px; }
  .grid3 { grid-template-columns: 1fr 1fr; }

  /* Trình làm bài 2 cột → xếp chồng dọc */
  .split { flex-direction: column; height: auto; }
  .split .pane-l { flex: none !important; height: 44vh; height: 44dvh; }
  .split .pane-r { border-left: none; border-top: 1px solid var(--line); max-height: 46vh; max-height: 46dvh; }

  /* Trình xem học liệu → toàn màn hình */
  .viewer-backdrop { padding: 0; }
  .viewer-box { width: 100vw; height: 100vh; height: 100dvh; border-radius: 0; }

  .login-card { padding: 24px 18px; }

  /* iOS tự phóng to khi focus nếu font < 16px → đặt tối thiểu 16px trên mobile */
  input[type="text"], input[type="password"], input[type="number"], input[type="date"], textarea, select { font-size: 16px; padding: 11px 12px; }

  /* Vùng chạm thoải mái hơn cho ngón tay */
  .btn { min-height: 42px; }
  .choices button { padding: 9px 15px; min-height: 38px; }
  .tabs button { min-height: 40px; }

  #help-fab, #bug-fab { right: 12px; width: 48px; height: 48px; }
  #help-fab { bottom: calc(12px + env(safe-area-inset-bottom)); font-size: 1.3rem; }
  #bug-fab { bottom: calc(70px + env(safe-area-inset-bottom)); }
  .toast { bottom: calc(76px + env(safe-area-inset-bottom)); max-width: calc(100vw - 32px); text-align: center; }
}

/* ---- Điện thoại: bảng co vừa màn hình, KHÔNG phải kéo ngang ---- */
@media (max-width: 640px) {
  table.tbl { min-width: 0; font-size: 0.82rem; }
  .tbl th { padding: 6px 5px; font-size: 0.66rem; letter-spacing: 0.03em; }
  .tbl td { padding: 8px 5px; word-break: break-word; }
  .tbl td input[type="text"], .tbl td input[type="number"] { max-width: 100% !important; }
  .card { overflow-x: visible; }
}

/* ---- Tablet dọc / laptop hẹp (881–1120px): sidebar gọn để nội dung rộng hơn ---- */
@media (min-width: 881px) and (max-width: 1120px) {
  .shell { grid-template-columns: 200px 1fr; }
  .sidebar { padding: 18px 10px; }
  .sidebar nav button { font-size: 0.88rem; padding: 9px 13px; }
}

/* ---- Điện thoại nhỏ (≤ 480px) ---- */
@media (max-width: 480px) {
  html, body { font-size: 14.5px; }
  .grid2, .grid3 { grid-template-columns: 1fr; gap: 10px; }
  .stat .num { font-size: 1.5rem; }
  .rolebtns { flex-direction: column; }
  .sidebar .who b { max-width: 84px; }
  .band { padding: 14px 14px; }
  h1 { font-size: 1.2rem; }
  .wm { font-size: 0.85rem; }
  .wm span { padding: 18px 22px; }
}

/* ---- Màn hình rất rộng: nội dung căn giữa cho dễ đọc ---- */
@media (min-width: 1500px) {
  main.content { margin: 0 auto; }
}
