/* SmartMark OMR v0.6.0 — Modern Dark Premium UI */
:root {
  color-scheme: dark;
  --bg: #0c1117;
  --bg2: #161b22;
  --card: #1c2128;
  --card2: #242b35;
  --ink: #e6edf3;
  --ink2: #8b949e;
  --muted: #6e7681;
  --brand: #58a6ff;
  --brand2: #79c0ff;
  --brand-glow: rgba(88,166,255,.15);
  --accent: #3fb950;
  --accent2: #56d364;
  --line: #30363d;
  --line2: #21262d;
  --danger: #f85149;
  --warn: #d29922;
  --ok: #3fb950;
  --shadow: 0 8px 24px rgba(0,0,0,.25);
  --radius: 14px;
  --radius-lg: 20px;
}

/* Light Theme Variables */
:root[data-theme="light"],
body[data-theme="light"] {
  color-scheme: light;
  --bg: #f8fafc;
  --bg2: #ffffff;
  --bg3: #f1f5f9;
  --card: #ffffff;
  --card2: #f1f5f9;
  --card-sub: #f8fafc;
  --ink: #0f172a;
  --ink2: #334155;
  --muted: #64748b;
  --brand: #0284c7;
  --brand2: #0369a1;
  --brand-glow: rgba(2, 132, 199, 0.12);
  --accent: #16a34a;
  --accent2: #22c55e;
  --line: #e2e8f0;
  --line2: #cbd5e1;
  --danger: #dc2626;
  --warn: #d97706;
  --ok: #16a34a;
  --shadow: 0 4px 20px -2px rgba(15, 23, 42, 0.08), 0 2px 6px -1px rgba(15, 23, 42, 0.04);
}

[data-theme="light"] input,
[data-theme="light"] select,
[data-theme="light"] textarea {
  color-scheme: light;
  background: #ffffff;
  color: #0f172a;
  border-color: #cbd5e1;
}

[data-theme="light"] select option {
  background-color: #ffffff;
  color: #0f172a;
}

[data-theme="light"] select optgroup {
  background-color: #f8fafc;
  color: #64748b;
}

[data-theme="light"] .topbar {
  background: rgba(255, 255, 255, 0.94);
  border-bottom: 1px solid #e2e8f0;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}

[data-theme="light"] .modal-card {
  background: #ffffff;
  color: #0f172a;
  border-color: #e2e8f0;
  box-shadow: 0 20px 40px rgba(15, 23, 42, 0.16);
}

[data-theme="light"] .auth-card {
  background: #ffffff;
  border-color: #e2e8f0;
  box-shadow: 0 20px 40px rgba(15, 23, 42, 0.1);
}

[data-theme="light"] .auth-wrapper {
  background: linear-gradient(135deg, #f1f5f9 0%, #e2e8f0 100%);
}

/* Home Hero Light Mode */
[data-theme="light"] .home-hero {
  background: linear-gradient(135deg, #e0f2fe 0%, #eff6ff 50%, #f0fdf4 100%);
  border-bottom: 1px solid #cbd5e1;
  position: relative;
  box-shadow: 0 4px 16px -4px rgba(2, 132, 199, 0.08);
}

[data-theme="light"] .home-hero::before {
  background: radial-gradient(ellipse at 50% 0%, rgba(2, 132, 199, 0.12) 0%, transparent 70%);
}

[data-theme="light"] .home-hero h1 {
  background: linear-gradient(135deg, #0284c7 0%, #059669 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  font-weight: 900;
  letter-spacing: -0.02em;
}

[data-theme="light"] .home-hero p {
  color: #334155;
  opacity: 1;
  font-weight: 500;
}

/* Home Stats Light Mode */
[data-theme="light"] .stat-card {
  background: #ffffff;
  border: 1px solid #e2e8f0;
  box-shadow: 0 4px 12px -2px rgba(15, 23, 42, 0.06);
  border-radius: 14px;
}

[data-theme="light"] .stat-card .stat-val {
  color: #0284c7;
  font-weight: 900;
}

[data-theme="light"] .stat-card .stat-label {
  color: #64748b;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-size: 0.72rem;
}

/* Menu Cards Light Mode */
[data-theme="light"] .menu-card {
  background: #ffffff;
  border: 1px solid #e2e8f0;
  box-shadow: 0 4px 14px -3px rgba(15, 23, 42, 0.05);
  border-radius: 16px;
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

[data-theme="light"] .menu-card:hover {
  background: #ffffff;
  border-color: #0284c7;
  transform: translateY(-2px);
  box-shadow: 0 12px 24px -4px rgba(2, 132, 199, 0.14);
}

[data-theme="light"] .menu-card .mc-title {
  color: #0f172a;
  font-weight: 800;
  font-size: 1.05rem;
}

[data-theme="light"] .menu-card .mc-desc {
  color: #64748b;
  font-size: 0.85rem;
  line-height: 1.4;
}

[data-theme="light"] .menu-card .mc-icon {
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.06));
}

[data-theme="light"] .menu-card.primary {
  background: linear-gradient(135deg, #0284c7 0%, #0369a1 100%) !important;
  border: 1px solid #0284c7 !important;
  box-shadow: 0 8px 24px -2px rgba(2, 132, 199, 0.35) !important;
}

[data-theme="light"] .menu-card.primary:hover {
  filter: brightness(1.05);
  box-shadow: 0 12px 28px -2px rgba(2, 132, 199, 0.45) !important;
}

[data-theme="light"] .menu-card.primary .mc-title {
  color: #ffffff !important;
  font-weight: 800;
}

[data-theme="light"] .menu-card.primary .mc-desc {
  color: #e0f2fe !important;
}

[data-theme="light"] .menu-card.primary .mc-icon {
  background: rgba(255, 255, 255, 0.22) !important;
  border-radius: 12px;
  padding: 6px 10px;
}

[data-theme="light"] .card {
  background: #ffffff;
  border: 1px solid #e2e8f0;
  box-shadow: 0 4px 16px -2px rgba(15, 23, 42, 0.05);
}

[data-theme="light"] .part-box {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
}

[data-theme="light"] .machine-code-badge {
  background: #f1f5f9;
  border-color: #cbd5e1;
  color: #0284c7;
}

[data-theme="light"] table th {
  background: #f8fafc;
  color: #334155;
  border-color: #e2e8f0;
}

[data-theme="light"] table td {
  border-color: #e2e8f0;
  color: #0f172a;
}

[data-theme="light"] table tr:hover td {
  background: #f8fafc;
}

[data-theme="light"] .tab {
  color: #64748b;
  background: #f1f5f9;
  border-color: #e2e8f0;
}

[data-theme="light"] .tab.active {
  background: #ffffff;
  color: var(--brand);
  border-color: var(--brand);
}

/* Exam Dashboard Light Mode High Contrast */
[data-theme="light"] .dash-action-btn {
  background: #ffffff !important;
  border: 1.5px solid #cbd5e1 !important;
  color: #0f172a !important;
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.05);
}
[data-theme="light"] .dash-action-btn:hover {
  border-color: #0284c7 !important;
  background: #f8fafc !important;
  transform: translateY(-2px);
  box-shadow: 0 8px 20px rgba(2, 132, 199, 0.12);
}
[data-theme="light"] .dash-action-btn .dash-info strong {
  color: #0f172a !important;
  font-weight: 800 !important;
}
[data-theme="light"] .dash-action-btn .dash-info span {
  color: #475569 !important;
  font-weight: 600 !important;
}
[data-theme="light"] .dash-action-btn.primary {
  background: linear-gradient(135deg, #f0fdf4 0%, #dcfce7 100%) !important;
  border: 1.5px solid #34d399 !important;
  box-shadow: 0 4px 14px rgba(22, 163, 74, 0.15) !important;
}
[data-theme="light"] .dash-action-btn.primary:hover {
  background: linear-gradient(135deg, #dcfce7 0%, #bbf7d0 100%) !important;
  border-color: #22c55e !important;
  box-shadow: 0 8px 22px rgba(22, 163, 74, 0.22) !important;
}
[data-theme="light"] .dash-action-btn.primary .dash-info strong {
  color: #065f46 !important;
  font-weight: 900 !important;
}
[data-theme="light"] .dash-action-btn.primary .dash-info span {
  color: #047857 !important;
  font-weight: 600 !important;
}
[data-theme="light"] .dash-action-btn.secondary {
  background: linear-gradient(135deg, #f0f9ff 0%, #e0f2fe 100%) !important;
  border: 1.5px solid #38bdf8 !important;
  box-shadow: 0 4px 14px rgba(2, 132, 199, 0.12) !important;
}
[data-theme="light"] .dash-action-btn.secondary:hover {
  background: linear-gradient(135deg, #e0f2fe 0%, #bae6fd 100%) !important;
  border-color: #0284c7 !important;
  box-shadow: 0 8px 22px rgba(2, 132, 199, 0.2) !important;
}
[data-theme="light"] .dash-action-btn.secondary .dash-info strong {
  color: #0369a1 !important;
  font-weight: 900 !important;
}
[data-theme="light"] .dash-action-btn.secondary .dash-info span {
  color: #075985 !important;
  font-weight: 600 !important;
}

/* Exam Overview & Stats Light Mode */
[data-theme="light"] .exam-info-overview {
  background: #f8fafc !important;
  border: 1px solid #cbd5e1 !important;
}
[data-theme="light"] .info-pill {
  color: #0f172a !important;
}
[data-theme="light"] .info-pill .info-k {
  color: #475569 !important;
}
[data-theme="light"] .dash-stat-box {
  background: #ffffff !important;
  border: 1px solid #cbd5e1 !important;
  box-shadow: 0 2px 6px rgba(15, 23, 42, 0.04);
}
[data-theme="light"] .dash-stat-box small {
  color: #475569 !important;
  font-weight: 700 !important;
}
[data-theme="light"] .dash-stat-box strong {
  color: #0f172a !important;
}

/* Controls & Inputs Light Mode */
[data-theme="light"] .ghost {
  background: #ffffff;
  color: #1e293b;
  border: 1px solid #cbd5e1;
}
[data-theme="light"] .ghost:hover {
  background: #f1f5f9;
  color: #0f172a;
  border-color: #94a3b8;
}
[data-theme="light"] .back-btn {
  background: #f1f5f9;
  border-color: #cbd5e1;
  color: #0f172a;
}
[data-theme="light"] .ans-tool-btn {
  background: #ffffff;
  border-color: #cbd5e1;
  color: #0f172a;
}
[data-theme="light"] .ans-tool-btn:hover {
  background: #f8fafc;
  border-color: #0284c7;
  color: #0284c7;
}
[data-theme="light"] .code-selector-bar {
  background: #f8fafc;
  border-color: #cbd5e1;
}
[data-theme="light"] .code-chip {
  background: #ffffff;
  border-color: #cbd5e1;
  color: #334155;
}
[data-theme="light"] .mcq-opt-btn {
  background: #ffffff;
  border-color: #cbd5e1;
  color: #0f172a;
}
[data-theme="light"] .tf-toggle-btn {
  background: #ffffff;
  border-color: #cbd5e1;
  color: #0f172a;
}
[data-theme="light"] .short-q-item {
  background: #f8fafc;
  border-color: #cbd5e1;
}
[data-theme="light"] .short-q-head {
  color: #475569 !important;
  font-weight: 700;
}
[data-theme="light"] .short-q-input {
  background: #ffffff !important;
  border-color: #cbd5e1 !important;
  color: #0f172a !important;
}
[data-theme="light"] .modal-card h2,
[data-theme="light"] .modal-card h3,
[data-theme="light"] .modal-card p,
[data-theme="light"] .modal-card label {
  color: #0f172a;
}
[data-theme="light"] .modal-card .muted {
  color: #64748b;
}

* { box-sizing: border-box; }
body {
  margin: 0; font-family: 'Times New Roman', Times, serif;
  background: var(--bg); color: var(--ink); -webkit-font-smoothing: antialiased;
  transition: background-color 0.2s ease, color 0.2s ease;
}
button, input, select, textarea { font-family: 'Times New Roman', Times, serif; font-size: inherit; }

/* === BUTTONS === */
button {
  border: 0; border-radius: 12px; padding: .72rem 1.1rem;
  background: var(--brand); color: #fff; font-weight: 700; cursor: pointer;
  transition: all .15s; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
button:hover { filter: brightness(1.12); }
button:active { transform: scale(.97); }
button.secondary { background: var(--card2); color: var(--brand2); border: 1px solid var(--line); }
button.secondary:hover { background: var(--brand-glow); border-color: var(--brand); }
button.ghost, button.btn-ghost { background: transparent !important; color: var(--brand) !important; border: 1px solid var(--line) !important; }
button.ghost:hover, button.btn-ghost:hover { background: var(--brand-glow) !important; }
button.danger { background: rgba(248,81,73,.12); color: var(--danger); border: 1px solid rgba(248,81,73,.3); }
button.danger:hover { background: rgba(248,81,73,.2); }
button:disabled { opacity: .5; cursor: not-allowed; }

/* === LAYOUT === */
.app-shell { max-width: 900px; margin: 0 auto; padding-bottom: 20px; }
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 16px;
  background: rgba(12,17,23,.92); backdrop-filter: blur(16px) saturate(1.2);
  border-bottom: 1px solid var(--line);
  transition: background-color 0.2s ease, border-color 0.2s ease;
}
.brand { font-size: 1.1rem; font-weight: 900; color: var(--ink); }
.subtitle { font-size: .88rem; color: var(--ink); margin-top: 0; }
.topbar .subtitle { font-size: 0.9rem; font-weight: 600; color: var(--ink); }

.topbar-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}
.topbar-btn {
  border-radius: 999px !important;
  padding: 0.4rem 0.8rem !important;
  font-size: 0.8rem !important;
  display: inline-flex !important;
  align-items: center !important;
  gap: 5px !important;
  white-space: nowrap !important;
}
.topbar-btn .btn-icon {
  font-size: 0.95rem;
}
.topbar-icon-btn {
  border-radius: 999px !important;
  padding: 0.4rem 0.7rem !important;
  font-size: 1rem !important;
  cursor: pointer;
  display: inline-flex !important;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s ease, background 0.2s ease;
}
.topbar-icon-btn:hover {
  transform: scale(1.1);
}

.machine-code-badge {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.92rem;
  font-weight: 800;
  color: var(--brand);
  background: var(--card2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 10px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  letter-spacing: 0.05em;
}
.btn-request-activation {
  background: linear-gradient(135deg, #0284c7 0%, #16a34a 100%) !important;
  color: #ffffff !important;
  font-weight: 800 !important;
  border: none !important;
  box-shadow: 0 4px 14px rgba(2, 132, 199, 0.3) !important;
  padding: 0.65rem 1.2rem !important;
  border-radius: 10px !important;
  cursor: pointer;
  transition: all 0.2s ease !important;
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  gap: 6px !important;
}
.btn-request-activation:hover {
  filter: brightness(1.1) !important;
  transform: translateY(-1px) !important;
}
.activation-request-banner {
  background: rgba(245, 158, 11, 0.12);
  border: 1px solid rgba(245, 158, 11, 0.35);
  border-radius: 10px;
  padding: 12px 16px;
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.badge {
  display: inline-flex; align-items: center; gap: 4px;
  border-radius: 999px; padding: .3rem .7rem;
  background: rgba(63,185,80,.12); color: var(--accent); font-size: .72rem; font-weight: 800;
  border: 1px solid rgba(63,185,80,.25);
}
.badge.neutral { background: var(--card2); color: var(--ink2); border-color: var(--line); }
.badge.warn { background: rgba(210,153,34,.12); color: var(--warn); border-color: rgba(210,153,34,.3); }
.badge.danger { background: rgba(248,81,73,.12); color: var(--danger); border-color: rgba(248,81,73,.3); }

.app-version-tag {
  display: inline-flex; align-items: center; vertical-align: middle; margin-left: 5px;
  padding: 2px 7px; border-radius: 999px;
  background: var(--brand-glow); color: var(--brand); border: 1px solid rgba(88,166,255,.2);
  font-size: .6rem; font-weight: 900; letter-spacing: .02em;
}

.card {
  background: var(--card); margin: 12px; border: 1px solid var(--line);
  border-radius: var(--radius-lg); padding: 18px; box-shadow: var(--shadow);
}

/* === FORMS === */
label { display: flex; flex-direction: column; gap: 5px; font-size: .82rem; font-weight: 600; color: var(--ink2); }
input, select, textarea {
  width: 100%; border: 1px solid var(--line); border-radius: 10px;
  padding: .72rem .85rem; background: var(--bg2); color: var(--ink); outline: none; transition: .2s;
  color-scheme: dark;
}
select option {
  background-color: #161b22;
  color: #e6edf3;
  padding: 8px 12px;
}
select optgroup {
  background-color: #161b22;
  color: #8b949e;
}
input:focus, select:focus, textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-glow); }

/* === VIEWS === */
.hidden { display: none !important; }
.view { display: none; }
.view.active { display: block; }

/* === HOME === */
.home-hero {
  background: linear-gradient(135deg, #0d1117 0%, #161b22 50%, #0d1117 100%);
  position: relative; overflow: hidden;
  padding: 36px 20px 48px; text-align: center;
  border-bottom: 1px solid var(--line);
}
.home-hero::before {
  content: ''; position: absolute; inset: 0;
  background: radial-gradient(ellipse at 50% 0%, rgba(88,166,255,.08) 0%, transparent 70%);
  pointer-events: none;
}
.home-hero h1 {
  font-size: 2rem; margin: 0 0 6px; font-weight: 900;
  background: linear-gradient(135deg, var(--brand) 0%, var(--accent) 100%);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
  background-clip: text;
}
.home-hero p { opacity: .7; font-size: .92rem; margin: 0; color: var(--ink2); }

.home-stats {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px;
  padding: 0 16px; margin-top: -24px; position: relative; z-index: 2;
}
.stat-card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; text-align: center; box-shadow: var(--shadow);
}
.stat-card .stat-val { font-size: 1.5rem; font-weight: 900; color: var(--brand); }
.stat-card .stat-label { font-size: .68rem; color: var(--muted); margin-top: 2px; text-transform: uppercase; letter-spacing: .04em; }

.menu-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 12px;
  padding: 24px 16px 8px;
}
.menu-card {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius-lg);
  padding: 16px 14px; text-align: center; cursor: pointer;
  transition: all .18s; min-height: 92px;
  box-shadow: 0 2px 8px rgba(0,0,0,.15);
}
.menu-card:hover { border-color: var(--brand); box-shadow: 0 0 20px var(--brand-glow); transform: translateY(-2px); }
.menu-card:active { transform: scale(.98); }
.menu-card .mc-icon { font-size: 1.85rem; margin-bottom: 6px; }
.menu-card .mc-title { font-weight: 800; font-size: .95rem; color: var(--ink); margin: 0; }
.menu-card .mc-desc { font-size: .75rem; color: var(--muted); line-height: 1.35; margin-top: 2px; }
.menu-card.primary {
  background: linear-gradient(135deg, rgba(88,166,255,.14) 0%, rgba(63,185,80,.12) 100%);
  border-color: rgba(88,166,255,.4);
}
.menu-card.primary .mc-title { color: var(--brand); font-weight: 900; }
.menu-card.full { grid-column: 1 / -1; flex-direction: row; gap: 14px; padding: 14px 20px; min-height: auto; }
.menu-card.full .mc-icon { margin-bottom: 0; font-size: 1.7rem; }
.menu-card.full .mc-text { text-align: left; }

/* === SECTION TITLES === */
.section-title {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px;
}
.section-title h1, .section-title h2 { font-size: 1.1rem; margin: 0; }
.back-btn { padding: 4px 10px; font-size: .88rem; border: none; box-shadow: none; background: transparent; color: var(--brand); }

.muted { color: var(--muted); font-size: .82rem; }
.actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }
.actions.compact { margin: 0; }

/* === TABS === */
.tabs {
  display: flex; gap: 4px; padding: 4px; background: var(--bg2);
  border-radius: 12px; margin: 12px 0; border: 1px solid var(--line);
}
.tab {
  flex: 1; background: transparent; color: var(--muted); border: none;
  padding: .6rem; font-size: .84rem; border-radius: 10px;
}
.tab.active { background: var(--card2); color: var(--brand); box-shadow: 0 2px 8px rgba(0,0,0,.2); }

/* === EXAM LIST === */
.exam-list { display: flex; flex-direction: column; gap: 12px; margin-top: 14px; }
.exam-card {
  background: var(--card2); padding: 16px; border-radius: var(--radius);
  border: 1px solid var(--line); border-left: 4px solid var(--line);
  transition: all .16s; cursor: default;
}
.exam-card.is-selected { border-left-color: var(--brand); box-shadow: 0 0 16px var(--brand-glow); }
.exam-card h3 { margin: 0 0 6px; font-size: 1.1rem; color: var(--brand2); }
.exam-card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 12px; }
.exam-card-date { font-size: .72rem; color: var(--muted); margin-top: 4px; }
.exam-card-meta {
  display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px;
}
.exam-card-meta > span {
  display: inline-flex; align-items: center; gap: 4px;
  background: var(--bg2); border: 1px solid var(--line); padding: 4px 8px;
  border-radius: 8px; font-size: .74rem; color: var(--ink2);
}
.exam-card-summary-row {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 14px;
}
.meta-tag {
  display: inline-flex; align-items: center; gap: 5px;
  background: var(--bg2); border: 1px solid var(--line); padding: 5px 11px;
  border-radius: 8px; font-size: .78rem; color: var(--ink2); font-weight: 500;
}
.meta-tag b { color: var(--ink); font-weight: 700; }
.exam-card-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.exam-card-actions button { padding: .5rem .75rem; font-size: .8rem; border-radius: 8px; min-height: 36px; }
.exam-action-primary { background: var(--brand) !important; color: #fff !important; font-weight: 800 !important; }
.exam-delete-action { margin-left: auto; }
.exam-card-actions-v2 { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.btn-hero-grade {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%) !important;
  color: #fff !important; font-weight: 800 !important; font-size: .84rem !important;
  padding: .5rem 1.15rem !important; border-radius: 999px !important; border: none !important;
  box-shadow: 0 4px 12px rgba(37,99,235,0.28) !important; cursor: pointer; transition: transform .14s, box-shadow .14s;
}
.btn-sub-action { padding: .46rem .8rem !important; font-size: .8rem !important; border-radius: 8px !important; min-height: 34px !important; }
.exam-card-actions-v2 .btn-sub-action.danger { margin-left: auto; }
.btn-sub-action.danger-sub {
  color: #ef4444 !important;
  background: rgba(239, 68, 68, 0.05) !important;
  border: 1px dashed rgba(239, 68, 68, 0.28) !important;
  transition: all 0.15s ease;
}
.btn-sub-action.danger-sub:hover {
  background: rgba(239, 68, 68, 0.12) !important;
  border-color: #ef4444 !important;
}

/* === SETUP === */
.setup-group { margin-bottom: 22px; }
.setup-label { font-weight: 800; font-size: .92rem; margin-bottom: 10px; color: var(--ink); }
.modern-input {
  width: 100%; border: none; border-bottom: 2px solid var(--line);
  border-radius: 0; background: transparent; padding: 8px 4px;
  font-size: 1rem; color: var(--ink); outline: none; transition: .2s;
}
.modern-input:focus { border-bottom-color: var(--brand); }
.part-box {
  background: var(--bg2); padding: 16px; border-radius: 12px;
  margin-bottom: 14px; border: 1px solid var(--line);
}
.part-title { font-weight: 700; font-size: .88rem; color: var(--brand2); margin-bottom: 12px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.grid-2 label { font-size: .78rem; color: var(--muted); font-weight: 500; }
.total-score-banner {
  text-align: center; font-size: 1.08rem; font-weight: bold; color: var(--warn);
  background: rgba(210,153,34,.08); padding: 12px; border-radius: 12px; margin-top: 20px;
  border: 1px solid rgba(210,153,34,.2);
}

/* === ANSWERS === */
.answer-panel { display: none; }
.answer-panel.active { display: block; }
.file-drop {
  border: 1.5px dashed var(--line); border-radius: 14px;
  padding: 18px; background: var(--bg2); cursor: pointer; transition: .2s;
}
.file-drop:hover { border-color: var(--brand); background: var(--brand-glow); }
.file-drop input { border: 0; padding: 8px 0; background: transparent; }
.file-drop span { font-weight: 400; color: var(--muted); font-size: .78rem; }
.file-drop.small { padding: 10px; margin-top: 10px; }
.preview-box {
  margin-top: 12px; padding: 12px; border-radius: 12px;
  background: var(--bg2); border: 1px solid var(--line); font-size: .82rem;
  white-space: pre-wrap; overflow: auto; color: var(--ink2);
}
.inline-form { display: flex; gap: 8px; }
.inline-form input { flex: 1; }
.answer-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 7px; }
.answer-row {
  display: flex; align-items: center; gap: 7px;
  background: var(--bg2); border: 1px solid var(--line); padding: 7px; border-radius: 10px;
}
.answer-row b { min-width: 26px; color: var(--ink); }
.answer-row input { padding: .5rem; }
.qr-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.qr-out { margin-top: 12px; display: flex; justify-content: center; min-height: 40px; }

.answer-library { margin-top: 18px; padding-top: 18px; border-top: 1px solid var(--line); }
.answer-library-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.answer-library-head h2 { margin: 0 0 4px; font-size: 1.05rem; }
.code-chips { display: flex; gap: 7px; overflow: auto; padding: 2px 0 10px; scrollbar-width: thin; }
.code-chip {
  flex: 0 0 auto; background: var(--brand-glow); color: var(--brand);
  border: 1px solid rgba(88,166,255,.25); padding: .5rem .72rem;
  border-radius: 999px; font-size: .76rem;
}
.answer-cards { display: grid; gap: 9px; }
.answer-code-card {
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--card2); overflow: hidden;
}
.answer-code-card summary {
  list-style: none; cursor: pointer; display: flex;
  align-items: center; justify-content: space-between; gap: 12px; padding: 12px 13px;
}
.answer-code-card summary::-webkit-details-marker { display: none; }
.answer-code-card summary span:first-child { display: flex; align-items: center; gap: 8px; min-width: 0; }
.answer-code-card summary small {
  font-size: .66rem; font-weight: 800; color: var(--muted);
  background: var(--bg2); padding: 3px 6px; border-radius: 999px;
}
.summary-action { font-size: .73rem; color: var(--brand); font-weight: 800; }
.answer-code-body { padding: 0 13px 13px; border-top: 1px solid var(--line); }
.answer-part { padding: 10px 0 0; }
.answer-part > b { display: block; font-size: .74rem; margin-bottom: 5px; color: var(--muted); }
.answer-sequence {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: .78rem; line-height: 1.55; word-break: break-word;
  background: var(--bg2); border-radius: 9px; padding: 8px; color: var(--accent);
}
.edit-answer-btn { margin-top: 11px; width: 100%; }
.answer-editor-panel {
  margin-top: 14px; border: 1.5px solid rgba(88,166,255,.3); background: rgba(88,166,255,.04);
  border-radius: 16px; padding: 14px;
}
.editor-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }
.import-success { line-height: 1.65; }
#reviewAnswerEditor .answer-row { margin: 0; color: inherit; }
#reviewAnswerEditor .answer-row input { text-transform: uppercase; }
#reviewAnswerEditor [data-edit-short] { text-transform: none; }
#regradeStatus { border-color: rgba(63,185,80,.3); background: rgba(63,185,80,.06); color: var(--accent); }

/* === MODERN EXAM DASHBOARD === */
.dashboard-action-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 12px; margin: 18px 0;
}
.dash-action-btn {
  display: flex; align-items: center; gap: 14px; padding: 14px 18px;
  background: var(--card2); border: 1.5px solid var(--line); border-radius: 14px;
  color: var(--ink); text-align: left; cursor: pointer; transition: all .15s cubic-bezier(0.4,0,0.2,1);
}
.dash-action-btn:hover { border-color: var(--brand); transform: translateY(-2px); box-shadow: 0 4px 16px rgba(0,0,0,.25); }
.dash-action-btn.primary {
  background: linear-gradient(135deg, rgba(46,160,67,.22), rgba(35,134,54,.1));
  border-color: rgba(46,160,67,.5); box-shadow: 0 4px 18px rgba(46,160,67,.15);
}
.dash-action-btn.primary:hover { border-color: var(--accent); background: linear-gradient(135deg, rgba(46,160,67,.35), rgba(35,134,54,.2)); }
.dash-action-btn.secondary {
  background: linear-gradient(135deg, rgba(56,189,248,.15), rgba(14,165,233,.05));
  border-color: rgba(56,189,248,.35);
}
.dash-icon { font-size: 1.8rem; line-height: 1; flex-shrink: 0; }
.dash-info { display: flex; flex-direction: column; gap: 2px; }
.dash-info strong { font-size: .95rem; font-weight: 800; color: var(--ink); }
.dash-info span { font-size: .78rem; color: var(--muted); }

.exam-info-overview {
  display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0 16px;
  padding: 12px 14px; background: var(--bg2); border: 1px solid var(--line); border-radius: 12px;
}
.info-pill { font-size: .82rem; color: var(--ink); display: flex; align-items: center; gap: 5px; }
.info-pill .info-k { color: var(--muted); font-size: .78rem; }

.dash-stats-row {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 20px;
}
.dash-stat-box {
  background: var(--card2); border: 1px solid var(--line); border-radius: 12px;
  padding: 12px; text-align: center;
}
.dash-stat-box small { display: block; font-size: .75rem; color: var(--muted); margin-bottom: 4px; }
.dash-stat-box strong { font-size: 1.35rem; font-weight: 800; color: var(--ink); }

/* === SCIENTIFIC ANSWER HUB === */
.answer-toolbar {
  display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0;
}
.ans-tool-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 16px; font-size: .84rem; font-weight: 700; border-radius: 10px;
  background: var(--card2); border: 1px solid var(--line); color: var(--ink);
  cursor: pointer; transition: all .15s;
}
.ans-tool-btn:hover { border-color: var(--brand); color: #fff; }
.ans-tool-btn.secondary { background: var(--brand); color: #fff; border-color: var(--brand); }
.ans-tool-btn.secondary:hover { background: var(--brand2); }

.code-selector-bar {
  background: var(--bg2); border: 1px solid var(--line); border-radius: 14px;
  padding: 12px 16px; margin-bottom: 16px;
}
.code-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.code-chip {
  padding: 7px 16px; font-size: .85rem; font-weight: 700; border-radius: 999px;
  background: var(--card2); border: 1.5px solid var(--line); color: var(--ink);
  cursor: pointer; transition: all .15s;
}
.code-chip:hover { border-color: var(--brand); }
.code-chip.active {
  background: var(--brand); color: #fff; border-color: var(--brand);
  box-shadow: 0 2px 10px rgba(15,118,110,.4);
}

.active-answer-box {
  background: var(--card2); border: 1.5px solid var(--line); border-radius: 16px;
  padding: 18px; margin-top: 12px;
}
.ans-section { margin-bottom: 22px; }
.ans-sec-head {
  display: flex; justify-content: space-between; align-items: center;
  border-bottom: 1px solid var(--line); padding-bottom: 8px; margin-bottom: 12px;
}
.ans-sec-title { font-size: .92rem; font-weight: 800; color: var(--accent); }
.ans-sec-hint { font-size: .75rem; color: var(--muted); }

/* MCQ Interactive Matrix */
.mcq-matrix {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 8px;
}
.mcq-q-item {
  background: var(--bg2); border: 1px solid var(--line); border-radius: 10px;
  padding: 6px 8px; display: flex; align-items: center; justify-content: space-between;
}
.mcq-q-num { font-size: .75rem; font-weight: 800; color: var(--muted); width: 28px; }
.mcq-opt-group { display: flex; gap: 3px; }
.mcq-opt-btn {
  width: 24px; height: 24px; padding: 0; font-size: .78rem; font-weight: 800;
  border-radius: 6px; border: 1px solid var(--line); background: var(--card);
  color: var(--muted); cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: all .1s;
}
.mcq-opt-btn:hover { border-color: var(--brand); color: #fff; }
.mcq-opt-btn.selected {
  background: var(--accent); border-color: var(--accent); color: #fff;
  box-shadow: 0 1px 6px rgba(46,160,67,.4);
}

/* TF Interactive Table */
.tf-matrix {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 10px;
}
.tf-q-item {
  background: var(--bg2); border: 1px solid var(--line); border-radius: 12px;
  padding: 10px 12px;
}
.tf-q-head {
  font-size: .82rem; font-weight: 800; color: var(--ink); margin-bottom: 8px;
  display: flex; justify-content: space-between;
}
.tf-sub-group { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.tf-sub-item { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.tf-sub-label { font-size: .72rem; color: var(--muted); font-weight: 700; text-transform: uppercase; }
.tf-toggle-btn {
  width: 100%; height: 28px; padding: 0; font-size: .82rem; font-weight: 900;
  border-radius: 6px; border: 1px solid var(--line); cursor: pointer;
  display: flex; align-items: center; justify-content: center; transition: all .12s;
}
.tf-toggle-btn.dung {
  background: rgba(46,160,67,.2); border-color: var(--accent); color: #4ade80;
}
.tf-toggle-btn.sai {
  background: rgba(248,81,73,.15); border-color: var(--danger); color: #f87171;
}
.tf-toggle-btn.trong {
  background: var(--card); border-color: var(--line); color: var(--muted);
}

/* Short Interactive Grid */
.short-matrix {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px;
}
.short-q-item {
  background: var(--bg2); border: 1px solid var(--line); border-radius: 10px;
  padding: 8px 10px; display: flex; flex-direction: column; gap: 4px;
}
.short-q-head { font-size: .75rem; font-weight: 800; color: var(--muted); }
.short-q-input {
  width: 100%; padding: 6px 8px; font-size: .92rem; font-weight: 800;
  background: var(--card); border: 1.5px solid var(--line); border-radius: 8px;
  color: var(--ink); text-align: center;
}
.short-q-input:focus { border-color: var(--brand); outline: none; }

/* === CAMERA & GRADING === */
.scan-launcher { text-align: center; padding: 24px 18px; }
.scan-launcher p { color: var(--muted); max-width: 560px; margin: 0 auto 18px; }
.start-grading {
  width: min(420px, 100%); min-height: 56px; font-size: 1.05rem; border-radius: 14px;
  background: linear-gradient(135deg, var(--brand), var(--accent));
}
.scan-image-fallback { margin: 14px auto 0; max-width: 420px; text-align: left; }
.grading-stage { position: fixed; inset: 0; z-index: 100; background: #000; overflow: hidden; }
.grading-stage video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; background: #000; }
.grading-status-text {
  position: absolute; top: 20px; left: 50%; transform: translateX(-50%);
  background: rgba(12,17,23,.88); backdrop-filter: blur(8px);
  color: #fff; padding: 8px 18px; border-radius: 999px;
  font-size: .82rem; font-weight: 700; z-index: 20; pointer-events: none;
  border: 1px solid var(--line); text-align: center; max-width: 85%;
  white-space: normal; overflow-wrap: anywhere; line-height: 1.35;
}
.grading-status-text:has(div) {
  background: transparent !important;
  backdrop-filter: none !important;
  border: none !important;
  padding: 0 !important;
}
.grading-stage canvas#overlay { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.grading-exit {
  position: absolute; right: max(14px, env(safe-area-inset-right)); top: max(14px, env(safe-area-inset-top));
  z-index: 100 !important; width: 44px; height: 44px; padding: 0; border-radius: 999px;
  background: rgba(0,0,0,.65); backdrop-filter: blur(8px);
  color: #fff; font-size: 1.7rem; font-weight: 400; border: 1.5px solid rgba(255,255,255,.4);
  cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.grading-manual-btn {
  position: absolute;
  bottom: max(22px, env(safe-area-inset-bottom, 22px));
  left: 50%;
  transform: translateX(-50%);
  z-index: 30;
  background: rgba(2, 132, 199, 0.92);
  backdrop-filter: blur(8px);
  color: #fff;
  border: 2px solid rgba(255, 255, 255, 0.7);
  padding: 11px 26px;
  border-radius: 999px;
  font-weight: 800;
  font-size: 0.95rem;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: transform 0.15s ease, background 0.15s ease;
  user-select: none;
  -webkit-user-select: none;
}
.grading-manual-btn:active {
  transform: translateX(-50%) scale(0.94);
  background: #0369a1;
}
.grading-flash {
  position: absolute; inset: 0; pointer-events: none;
  border: 0 solid rgba(63,185,80,.95); opacity: 0; transition: opacity .14s, border-width .14s;
}
.grading-flash.ok { opacity: 1; border-width: 10px; }
.grading-flash.bad { opacity: 1; border-width: 10px; border-color: rgba(210,153,34,.95); }
body.grading-mode { overflow: hidden; background: #000; }
body.grading-mode .topbar, body.grading-mode .bottom-nav,
body.grading-mode main > .view:not(#view-scan), body.grading-mode #scanLauncher { display: none !important; }
body.grading-mode .app-shell { max-width: none; padding: 0; }
body.grading-mode #view-scan { display: block !important; }
body.grading-mode #view-scan > .card { display: none !important; }
body.grading-mode #gradingStage { display: block !important; }

/* === RESULTS TABLE === */
.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; min-width: 650px; }
th, td { padding: 10px 9px; border-bottom: 1px solid var(--line); font-size: .8rem; text-align: left; }
th { background: var(--bg2); position: sticky; top: 0; color: var(--ink2); font-weight: 700; }
td { color: var(--ink); }

.stat-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 10px 0; }
.stat-row > div { background: var(--card2); padding: 10px; border-radius: 12px; border: 1px solid var(--line); }
.stat-row small { display: block; color: var(--muted); }
.stat-row strong { font-size: 1.05rem; color: var(--brand); }
.invalid { color: var(--warn); font-weight: 800; }
.ok { color: var(--ok); font-weight: 800; }

/* === CLASSES VIEW === */
.class-list { display: flex; flex-direction: column; gap: 10px; margin-top: 14px; }
.class-card {
  background: var(--card2); padding: 16px; border-radius: var(--radius);
  border: 1px solid var(--line); cursor: pointer; transition: all .15s;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.class-card:hover { border-color: var(--brand); box-shadow: 0 0 12px var(--brand-glow); }
.class-card h3 { margin: 0; font-size: 1rem; color: var(--ink); }
.class-card .class-meta { font-size: .75rem; color: var(--muted); margin-top: 4px; }
.class-card .class-count { font-size: 1.1rem; font-weight: 900; color: var(--brand); }

.student-table { width: 100%; border-collapse: collapse; min-width: 0; }
.student-table th, .student-table td { padding: 8px 10px; border-bottom: 1px solid var(--line); font-size: .84rem; }
.student-table th { background: var(--bg2); color: var(--ink2); text-align: left; }

/* === ADMIN VIEW === */
.user-list { display: flex; flex-direction: column; gap: 8px; margin-top: 14px; }
.user-card {
  background: var(--card2); padding: 14px 16px; border-radius: var(--radius);
  border: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; gap: 10px;
}
.user-card.inactive { opacity: .55; border-left: 3px solid var(--danger); }
.user-info h4 { margin: 0; font-size: .92rem; color: var(--ink); }
.user-info .user-email { font-size: .75rem; color: var(--muted); }
.user-info .user-meta { display: flex; gap: 8px; margin-top: 4px; flex-wrap: wrap; }
.user-actions { display: flex; gap: 6px; flex-shrink: 0; }
.user-actions button { padding: .4rem .6rem; font-size: .72rem; min-height: auto; }

/* === DOWNLOAD MODAL === */
.download-modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.6); backdrop-filter: blur(4px);
  z-index: 200; display: flex; align-items: center; justify-content: center; padding: 16px;
}
.download-modal {
  background: var(--card); border-radius: var(--radius-lg); width: min(480px, 100%);
  padding: 24px; border: 1px solid var(--line); box-shadow: 0 20px 60px rgba(0,0,0,.4);
}
.download-modal h2 { margin: 0 0 16px; font-size: 1.2rem; }
.download-item {
  display: flex; align-items: center; gap: 14px; padding: 14px;
  background: var(--card2); border: 1px solid var(--line); border-radius: var(--radius);
  margin-bottom: 10px; transition: all .15s;
}
.download-item:hover { border-color: var(--brand); }
.download-item .dl-icon { font-size: 1.5rem; }
.download-item .dl-info { flex: 1; }
.download-item .dl-title { font-weight: 700; font-size: .92rem; }
.download-item .dl-desc { font-size: .72rem; color: var(--muted); margin-top: 2px; }

/* === AUTH === */
.auth-wrapper {
  position: fixed; inset: 0; z-index: 1000;
  display: flex; align-items: center; justify-content: center; padding: 16px;
  background: var(--bg);
}
.auth-wrapper.hidden { display: none !important; }
.auth-card {
  background: var(--card); width: 100%; max-width: 420px;
  border-radius: var(--radius-lg); padding: 32px 24px;
  box-shadow: 0 20px 60px rgba(0,0,0,.3); border: 1px solid var(--line);
}
.auth-card .brand { font-size: 1.5rem; text-align: center; color: var(--brand); margin-bottom: 8px; }
.auth-divider {
  display: flex; align-items: center; text-align: center; color: var(--muted); margin: 24px 0; font-size: .82rem;
}
.auth-divider::before, .auth-divider::after { content: ''; flex: 1; border-bottom: 1px solid var(--line); }
.auth-divider span { padding: 0 10px; }
.auth-status {
  margin: 12px 0 0; padding: 10px 12px; border-radius: 12px;
  font-size: .82rem; line-height: 1.45; overflow-wrap: anywhere;
}
.auth-status[hidden] { display: none !important; }
.auth-status.is-error { color: var(--danger); background: rgba(248,81,73,.08); border: 1px solid rgba(248,81,73,.2); }
.auth-status.is-info { color: var(--brand); background: var(--brand-glow); border: 1px solid rgba(88,166,255,.2); }
#auth-submit:disabled { opacity: .6; cursor: wait; }

/* === TOAST === */
.toast {
  position: fixed; left: 50%; bottom: 40px; transform: translateX(-50%) translateY(20px);
  background: #0f172a; color: #ffffff; padding: 12px 24px; border-radius: 999px;
  opacity: 0; pointer-events: none; transition: .25s ease; z-index: 9999999 !important; font-size: .88rem; font-weight: 700;
  border: 1px solid rgba(255,255,255,0.2); box-shadow: 0 10px 30px rgba(0,0,0,.5);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); pointer-events: auto; }

/* === MODALS === */
.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,.7); backdrop-filter: blur(6px);
  display: grid; place-items: center; padding: 12px; z-index: 99999;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}
.modal-card {
  position: relative; background: var(--card); border-radius: var(--radius-lg);
  width: min(520px, 100%); padding: 18px; border: 1px solid var(--line);
  max-height: calc(100vh - 24px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}
.modal-card video { width: 100%; aspect-ratio: 1; background: #000; border-radius: var(--radius); object-fit: cover; }
.modal-close {
  position: absolute; right: 10px; top: 8px; background: var(--card2);
  color: var(--ink); width: 36px; height: 36px; padding: 0; border-radius: 999px; font-size: 1.4rem;
}
.result-review-card {
  width: min(740px, 98%) !important;
  max-height: 92vh;
  overflow-y: auto;
  padding: 0 !important;
}

/* === SCROLLBAR === */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--line); border-radius: 999px; }

/* === BOTTOM NAV (hidden) === */
.bottom-nav { display: none !important; }

/* === RESPONSIVE === */
@media (max-width: 680px) {
  .topbar { padding: 8px 10px; }
  .topbar-actions { gap: 4px; }
  .topbar-btn { padding: 0.38rem 0.52rem !important; font-size: 0.8rem !important; border-radius: 10px !important; }
  .topbar-btn .btn-text { display: none !important; }
  .topbar-btn .btn-icon { margin: 0 !important; font-size: 1.05rem !important; }
  .topbar-icon-btn { padding: 0.38rem 0.52rem !important; font-size: 1.05rem !important; border-radius: 10px !important; }
  .brand { font-size: 0.95rem; }
  .subtitle { font-size: 0.7rem; }
  .form-grid, .score-grid, .qr-grid { grid-template-columns: 1fr; }

  /* 1. TỐI ƯU GIAO DIỆN CHÍNH / TRANG CHỦ (Ảnh 1) */
  .home-hero { padding: 20px 14px 28px !important; }
  .home-hero h1 { font-size: 1.58rem !important; margin: 0 0 4px !important; }
  .home-hero p { font-size: 0.78rem !important; }
  .home-stats { grid-template-columns: repeat(3, 1fr) !important; gap: 8px !important; margin-top: -16px !important; padding: 0 10px !important; }
  .stat-card { padding: 10px 6px !important; border-radius: 12px !important; }
  .stat-card .stat-val { font-size: 1.25rem !important; font-weight: 800 !important; }
  .stat-card .stat-label { font-size: 0.72rem !important; }
  .menu-grid { grid-template-columns: 1fr 1fr !important; gap: 8px !important; padding: 14px 10px 8px !important; }
  .menu-card { padding: 12px 10px !important; min-height: 72px !important; border-radius: 12px !important; }
  .menu-card .mc-icon { font-size: 1.4rem !important; margin-bottom: 2px !important; }
  .menu-card .mc-title { font-size: 0.84rem !important; font-weight: 700 !important; }
  .menu-card.full { padding: 11px 14px !important; gap: 10px !important; min-height: auto !important; }
  .menu-card.full .mc-icon { font-size: 1.35rem !important; margin-bottom: 0 !important; }
  .card { margin: 8px 6px !important; border-radius: 14px !important; padding: 12px !important; }

  /* 2. TỐI ƯU DANH SÁCH BÀI CHẤM (Ảnh 2) */
  .exam-card { padding: 14px 12px !important; margin-bottom: 12px !important; border-radius: 14px !important; }
  .exam-card-head h3 { font-size: 1.05rem !important; }
  .exam-card-date { font-size: 0.72rem !important; }
  .exam-card-summary-row { gap: 6px !important; margin-bottom: 10px !important; }
  .meta-tag { padding: 4px 8px !important; font-size: 0.74rem !important; border-radius: 6px !important; }
  .exam-card-actions, .exam-card-actions-v2 { display: grid !important; grid-template-columns: repeat(2, minmax(0, 1fr)) !important; gap: 6px !important; }
  .exam-card-actions-v2 .btn-hero-grade { grid-column: 1 / -1 !important; width: 100% !important; padding: 9px !important; font-size: 0.88rem !important; }
  .exam-card-actions-v2 .btn-sub-action { padding: 6px 8px !important; font-size: 0.78rem !important; min-height: 32px !important; width: 100% !important; justify-content: center !important; }
  .exam-card-actions-v2 .btn-sub-action.danger-sub { grid-column: 1 / -1 !important; min-height: 28px !important; font-size: 0.74rem !important; padding: 5px !important; }

  /* 3. TỐI ƯU CHI TIẾT BÀI CHẤM / DASHBOARD (Ảnh 3) */
  .dashboard-action-grid { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; gap: 6px !important; margin: 8px 0 10px !important; }
  .dash-action-btn { padding: 9px 12px !important; gap: 10px !important; border-radius: 10px !important; min-height: 44px !important; }
  .dash-action-btn.primary { grid-column: 1 / -1 !important; padding: 10px 14px !important; min-height: auto !important; justify-content: center !important; }
  .dash-action-btn:last-child { grid-column: auto !important; }
  .dash-icon { font-size: 1.3rem !important; }
  .dash-info strong { font-size: 0.88rem !important; font-weight: 800 !important; }
  .exam-info-overview { display: grid !important; grid-template-columns: repeat(2, minmax(0, 1fr)) !important; padding: 6px 10px !important; gap: 4px 8px !important; margin: 6px 0 10px !important; border-radius: 10px !important; }
  .info-pill { font-size: 0.74rem !important; gap: 4px !important; white-space: nowrap !important; overflow: hidden !important; text-overflow: ellipsis !important; }
  .info-pill .info-k { font-size: 0.70rem !important; }
  .dash-stats-row { display: grid !important; grid-template-columns: repeat(4, 1fr) !important; gap: 4px !important; margin-bottom: 10px !important; }
  .dash-stat-box { padding: 6px 2px !important; border-radius: 8px !important; }
  .dash-stat-box small { font-size: 0.65rem !important; margin-bottom: 2px !important; white-space: nowrap !important; overflow: hidden !important; text-overflow: ellipsis !important; }
  .dash-stat-box strong { font-size: 1.05rem !important; white-space: nowrap !important; }

  .stat-row { grid-template-columns: repeat(2, 1fr); }
  .scan-launcher { margin: 8px; padding: 20px 14px; }
  .grading-exit { width: 42px; height: 42px; }
  .answer-library-head { align-items: center; }
  .answer-grid { grid-template-columns: repeat(2, 1fr); }
  .editor-actions { display: grid; grid-template-columns: 1fr 1fr; }
  .editor-actions button { width: 100%; padding: .72rem .5rem; }
  .user-card { flex-direction: column; align-items: flex-start; }
  .user-actions { width: 100%; }

  /* Tối ưu thanh công cụ đáp án & bộ chọn mã đề trên điện thoại */
  .answer-toolbar { display: grid !important; grid-template-columns: 1fr 1fr !important; gap: 6px !important; margin: 8px 0 12px !important; }
  .ans-tool-btn { padding: 7px 6px !important; font-size: 0.78rem !important; white-space: nowrap !important; justify-content: center !important; border-radius: 8px !important; }
  .code-selector-bar { padding: 10px 12px !important; margin-bottom: 12px !important; border-radius: 12px !important; }
  .code-chip { padding: 5px 12px !important; font-size: 0.8rem !important; }
  .active-answer-box { padding: 12px 10px !important; border-radius: 12px !important; }
}
@media (max-width: 420px) {
  .grading-status-text { top: max(12px, env(safe-area-inset-top)); padding: 8px 10px; font-size: .72rem; }
  .menu-grid { gap: 6px; padding: 12px 8px 6px; }
  .home-stats { gap: 6px; padding: 0 8px; }
  .exam-card-actions, .exam-card-actions-v2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .exam-card-actions button, .exam-card-actions-v2 button { width: 100%; justify-content: center; }
  .exam-card-actions .exam-delete-action, .exam-card-actions-v2 .btn-sub-action.danger { margin-left: 0; }
  .exam-card-actions .exam-action-primary, .exam-card-actions-v2 .btn-hero-grade { grid-column: 1 / -1; }
}

/* camera-stage helpers from legacy */
.camera-card { padding: 0; overflow: hidden; }
.camera-stage { position: relative; aspect-ratio: 3/4; background: #000; overflow: hidden; }
.camera-stage video { width: 100%; height: 100%; object-fit: cover; }
.camera-stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.corner-hint { position: absolute; width: 28px; height: 28px; border-color: var(--accent); }
.step-score { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; margin-top: 12px; }
.step-score span { font-size: .7rem; color: var(--muted); }
.step-score input { padding: .5rem; }
.manual-section { margin-top: 14px; }
.manual-title { font-weight: 800; margin-bottom: 8px; }
.triplet { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.form-grid, .score-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.hero { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.hero-score { font-size: 2rem; font-weight: 900; }
.result-card { font-size: .88rem; }
.result-score { font-size: 2rem; font-weight: 900; color: var(--brand); }
.result-detail { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 10px; }
.result-detail div { background: var(--card2); padding: 9px; border-radius: 10px; border: 1px solid var(--line); }
.scan-status-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1px; background: var(--line); border-top: 1px solid var(--line); }
.scan-status-grid > div { background: var(--card); padding: 10px; text-align: center; }
.scan-status-grid small { display: block; color: var(--muted); font-size: .65rem; }
.scan-status-grid strong { display: block; margin-top: 3px; font-size: .88rem; }
.switch { display: flex; flex-direction: row; align-items: center; gap: 6px; font-size: .76rem; }
.switch input { width: auto; }
.camera-toolbar { display: flex; align-items: center; gap: 8px; padding: 12px; }
.camera-toolbar button { flex: 1; }
.capture-button {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 44px; padding: 0 14px; border-radius: 12px;
  background: var(--card2); color: var(--ink); font-weight: 700; cursor: pointer;
}
.capture-button input { display: none; }
.camera-env { margin: 10px 0 0; font-size: 13px; border-radius: 10px; padding: 8px 12px; border: 1px solid var(--line); }
.camera-env.ok { border-color: rgba(63,185,80,.3); background: rgba(63,185,80,.06); }
.camera-env.warn { border-color: rgba(210,153,34,.3); background: rgba(210,153,34,.06); }
.camera-env.error { border-color: rgba(248,81,73,.3); background: rgba(248,81,73,.06); }
.guide-frame {
  position: absolute; inset: 8%; border: 2px solid rgba(255,255,255,.6);
  border-radius: 14px; box-shadow: 0 0 0 999px rgba(0,0,0,.15);
  display: flex; align-items: flex-end; justify-content: center;
}
.guide-frame span {
  background: rgba(0,0,0,.5); color: #fff; padding: 6px 10px;
  border-radius: 999px; font-size: .72rem; margin-bottom: 10px;
}

/* === SETTINGS VIEW === */
.settings-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-top: 14px;
}
.settings-item {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px 18px;
  background: var(--card2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  transition: border-color .15s;
}
.settings-item:hover {
  border-color: rgba(88,166,255,.3);
}
.settings-item-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}
.settings-bullet-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--ink);
  display: flex;
  align-items: center;
  gap: 6px;
}
.settings-bullet-title span.val {
  color: var(--brand);
  font-weight: 900;
  background: var(--brand-glow);
  padding: 2px 8px;
  border-radius: 6px;
}
.ui-slider-wrap {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.ui-range {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  border-radius: 999px;
  background: var(--line);
  outline: none;
  cursor: pointer;
  padding: 0;
  margin: 10px 0 6px;
}
.ui-range::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--brand);
  cursor: pointer;
  box-shadow: 0 0 10px rgba(88,166,255,0.5);
  transition: transform .1s;
}
.ui-range::-webkit-slider-thumb:hover {
  transform: scale(1.15);
}
.ui-range-labels {
  display: flex;
  justify-content: space-between;
  font-size: 0.72rem;
  color: var(--muted);
}
/* iOS/Modern Toggle Switch */
.ui-switch {
  position: relative;
  display: inline-block;
  width: 52px;
  height: 30px;
  flex-shrink: 0;
  cursor: pointer;
}
.ui-switch input {
  opacity: 0;
  width: 0;
  height: 0;
  position: absolute;
}
.ui-switch-track {
  position: absolute;
  cursor: pointer;
  top: 0; left: 0; right: 0; bottom: 0;
  background-color: var(--line);
  transition: .25s;
  border-radius: 34px;
  border: 1px solid rgba(255,255,255,0.1);
}
.ui-switch-track:before {
  position: absolute;
  content: "";
  height: 22px;
  width: 22px;
  left: 3px;
  bottom: 3px;
  background-color: #fff;
  transition: .25s;
  border-radius: 50%;
  box-shadow: 0 2px 5px rgba(0,0,0,0.35);
}
.ui-switch input:checked + .ui-switch-track {
  background-color: var(--accent);
}
.ui-switch input:checked + .ui-switch-track:before {
  transform: translateX(22px);
}

/* === STATISTICS & SCORE DISTRIBUTION MODAL === */
.stats-modal-card {
  width: min(860px, 98%) !important;
  max-height: 92vh;
  overflow-y: auto;
  padding: 22px !important;
}
.stats-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
  padding-right: 36px;
}
.stats-kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 10px;
  margin-bottom: 22px;
}
.stats-kpi-card {
  background: var(--card2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
  text-align: center;
  transition: transform .15s;
}
.stats-kpi-card:hover {
  transform: translateY(-2px);
  border-color: var(--brand);
}
.stats-kpi-label {
  font-size: 0.72rem;
  color: var(--muted);
  text-transform: uppercase;
  font-weight: 700;
  letter-spacing: .03em;
  margin-bottom: 4px;
}
.stats-kpi-val {
  font-size: 1.45rem;
  font-weight: 900;
  color: var(--brand);
}
.stats-kpi-val.ok { color: var(--accent); }
.stats-kpi-val.warn { color: var(--warn); }
.stats-kpi-val.danger { color: var(--danger); }
.stats-kpi-sub {
  font-size: 0.7rem;
  color: var(--muted);
  margin-top: 2px;
}

/* Distribution Chart Box */
.stats-chart-box {
  background: var(--card2);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  margin-bottom: 20px;
}
.stats-chart-title {
  font-size: 0.95rem;
  font-weight: 800;
  color: var(--ink);
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.stats-histogram-svg {
  width: 100%;
  height: 140px;
  display: block;
  overflow: visible;
}

/* Tier progress bar */
.stats-tier-bar {
  display: flex;
  height: 14px;
  border-radius: 999px;
  overflow: hidden;
  margin: 12px 0 14px;
  background: var(--line);
}
.stats-tier-seg {
  height: 100%;
  transition: width .3s;
}
.stats-tier-legend {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 8px;
  font-size: 0.78rem;
}
.stats-tier-item {
  display: flex;
  align-items: center;
  gap: 6px;
}
.stats-tier-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* Question analysis table */
.stats-question-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
  margin-top: 10px;
}
.stats-question-table th, .stats-question-table td {
  padding: 8px 12px;
  text-align: left;
  border-bottom: 1px solid var(--line);
}
.stats-question-table th {
  color: var(--muted);
  font-weight: 700;
  background: rgba(0,0,0,.15);
}
.stats-ai-assessment {
  background: linear-gradient(135deg, rgba(88,166,255,.08) 0%, rgba(63,185,80,.06) 100%);
  border: 1px solid rgba(88,166,255,.25);
  border-radius: var(--radius);
  padding: 14px 18px;
  font-size: 0.86rem;
  line-height: 1.5;
  color: var(--ink);
  margin-top: 14px;
}

/* ========================================================
   LIVE GRADING BANNER / CARD (Chuẩn hình ảnh mẫu TNMaker)
   ======================================================== */
.live-grading-card {
  background: rgba(255, 255, 255, 0.96) !important;
  backdrop-filter: blur(8px);
  color: #1e293b !important;
  border-radius: 8px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.28);
  padding: 6px 10px;
  margin: 0;
  border: 1px solid #cbd5e1;
  font-family: inherit;
  text-align: left;
}
.live-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  margin-bottom: 4px;
}
.live-stt-badge {
  background: #1e40af;
  color: #ffffff;
  font-weight: 800;
  font-size: 0.9rem;
  min-width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  padding: 0 3px;
  flex-shrink: 0;
}
.live-name-crop {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 28px;
  background: #f8fafc;
  border: 1px solid #cbd5e1;
  border-radius: 4px;
  overflow: hidden;
  padding: 1px 4px;
  min-width: 0;
}
.live-name-crop img {
  max-height: 100%;
  max-width: 100%;
  object-fit: contain;
}
.live-name-text {
  font-weight: 700;
  font-size: 0.85rem;
  color: #0f172a;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.live-score-pill {
  background: #16a34a;
  color: #ffffff;
  font-weight: 800;
  font-size: 1.05rem;
  padding: 2px 8px;
  border-radius: 5px;
  letter-spacing: 0.5px;
  flex-shrink: 0;
}
.live-card-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.76rem;
  color: #64748b;
  margin-bottom: 2px;
  line-height: 1.25;
}
.live-card-row strong {
  color: #0f172a;
  font-weight: 800;
}
.live-progress-bar {
  display: flex;
  height: 5px;
  border-radius: 3px;
  overflow: hidden;
  background: #e2e8f0;
  margin-top: 4px;
  border: 1px solid #cbd5e1;
}
.live-progress-bar .seg-correct {
  background: #16a34a;
  height: 100%;
  transition: width 0.2s ease;
}
.live-progress-bar .seg-warning {
  background: #f59e0b;
  height: 100%;
  transition: width 0.2s ease;
}
.live-progress-bar .seg-wrong {
  background: #dc2626;
  height: 100%;
  transition: width 0.2s ease;
}

/* Floating overlay on top of camera - centered, compact, does not cover top 2 anchors or exit button */
.grading-overlay-card {
  position: absolute;
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  width: calc(100% - 130px);
  max-width: 320px;
  z-index: 22;
  pointer-events: auto;
  animation: slideDownIn 0.2s ease-out;
}
@keyframes slideDownIn {
  from { opacity: 0; transform: translate(-50%, -10px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

/* License & Quota Pills */
.license-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;
  transition: all 0.2s ease;
}
.license-pill.licensed {
  background: rgba(34, 197, 94, 0.15);
  color: #22c55e;
  border: 1px solid rgba(34, 197, 94, 0.4);
}
.license-pill.trial {
  background: rgba(245, 158, 11, 0.15);
  color: #f59e0b;
  border: 1px solid rgba(245, 158, 11, 0.4);
}
.license-pill.trial.expired {
  background: rgba(239, 68, 68, 0.15);
  color: #ef4444;
  border: 1px solid rgba(239, 68, 68, 0.4);
}

/* ==========================================================================
   BỘ HIỆU CHỈNH TỌA ĐỘ MẪU PHIẾU TRỰC QUAN (ADMIN / OMR TOOL CHUYÊN SÂU)
   Giao diện 2 cột chuẩn theo ảnh media_1792104436704_5c60b581.png
   ========================================================================== */
.calib-modal-card {
  width: 98vw;
  max-width: 1540px;
  height: 96vh;
  max-height: 98vh;
  display: flex;
  flex-direction: column;
  padding: 0;
  overflow: hidden;
  background: var(--card);
  border-radius: 12px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.45);
}

.calib-container-2col {
  display: flex;
  flex: 1;
  height: 100%;
  overflow: hidden;
}

/* CỘT TRÁI: BẢNG ĐIỀU KHIỂN DỊCH TỌA ĐỘ */
.calib-sidebar {
  width: 340px;
  min-width: 320px;
  max-width: 360px;
  background: var(--bg2, #f8fafc);
  border-right: 1px solid var(--line, #e2e8f0);
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px 12px;
  overflow-y: auto;
  box-sizing: border-box;
  flex-shrink: 0;
}

/* CỘT PHẢI: KHUNG HIỂN THỊ CANVAS & LƯỚI ĐỎ */
.calib-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: #0f172a;
  overflow: hidden;
  position: relative;
}

/* Top bar của cột phải */
.calib-top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  padding: 10px 16px;
  background: var(--card, #ffffff);
  border-bottom: 1px solid var(--line, #e2e8f0);
  z-index: 5;
}

/* Viewport cuộn Canvas */
.calib-canvas-viewport {
  flex: 1;
  overflow: auto;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 20px;
  background: #0b1120;
}

.calib-canvas-wrapper {
  transform-origin: top center;
  transition: transform 0.1s ease-out;
  display: inline-block;
}

#calibCanvas {
  display: block;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.7);
  background: #ffffff;
  border-radius: 4px;
  cursor: crosshair;
  image-rendering: -webkit-optimize-contrast;
  image-rendering: crisp-edges;
}

/* Các nhóm trong sidebar */
.calib-group {
  background: var(--card, #ffffff);
  border: 1px solid var(--line, #e2e8f0);
  border-radius: 8px;
  padding: 10px 12px;
}
.calib-group-compact {
  padding: 8px 10px;
}
.calib-group-title {
  font-size: 0.82rem;
  font-weight: 800;
  color: var(--ink, #1e293b);
  display: block;
  margin-bottom: 6px;
}

.calib-select {
  width: 100%;
  padding: 6px 8px;
  font-size: 0.82rem;
  font-weight: 600;
  border: 1px solid var(--line, #cbd5e1);
  border-radius: 6px;
  background: var(--surface, #ffffff);
  color: var(--ink, #0f172a);
}
.calib-select-sm {
  flex: 1;
  padding: 4px 6px;
  font-size: 0.8rem;
  font-weight: 600;
  border: 1px solid var(--line, #cbd5e1);
  border-radius: 6px;
  background: var(--surface, #ffffff);
  color: var(--ink, #0f172a);
}

/* Bảng dịch 4 cạnh */
.calib-edge-table {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 4px;
}
.calib-edge-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}
.calib-edge-name {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--ink, #334155);
  min-width: 65px;
}

/* Cặp nút mũi tên đỏ */
.calib-arrow-pair {
  display: flex;
  gap: 4px;
}
.btn-calib-arrow {
  width: 32px;
  height: 30px;
  background: #ffffff;
  border: 1px solid #cbd5e1;
  border-radius: 4px;
  color: #dc2626;
  font-size: 13px;
  font-weight: 900;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(0,0,0,0.06);
  user-select: none;
  transition: all 0.12s ease;
}
.btn-calib-arrow:hover {
  background: #fef2f2;
  border-color: #ef4444;
  color: #b91c1c;
  transform: translateY(-1px);
}
.btn-calib-arrow:active {
  background: #fee2e2;
  transform: scale(0.92);
}

/* Icon minh họa cạnh đỏ */
.calib-edge-thumb {
  width: 36px;
  height: 30px;
  border: 1px solid #94a3b8;
  border-radius: 2px;
  background-color: #f8fafc;
  background-image: 
    linear-gradient(to right, #e2e8f0 1px, transparent 1px),
    linear-gradient(to bottom, #e2e8f0 1px, transparent 1px);
  background-size: 7px 7px;
  box-sizing: border-box;
}
.thumb-top { border-top: 4px solid #dc2626 !important; }
.thumb-bottom { border-bottom: 4px solid #dc2626 !important; }
.thumb-left { border-left: 4px solid #dc2626 !important; }
.thumb-right { border-right: 4px solid #dc2626 !important; }

/* Hàng chọn từng cột/hàng */
.calib-single-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 6px;
}

/* D-pad và Bước dịch */
.calib-step-selector {
  display: flex;
  align-items: center;
  gap: 2px;
}
.btn-step {
  padding: 2px 6px;
  font-size: 0.72rem;
  font-weight: 700;
  border-radius: 4px;
  border: 1px solid var(--line, #cbd5e1);
  background: var(--surface, #ffffff);
  color: var(--muted, #64748b);
  cursor: pointer;
}
.btn-step.active {
  background: #dc2626;
  color: #ffffff;
  border-color: #dc2626;
}
.btn-calib-dpad {
  padding: 5px 8px;
  font-size: 0.76rem;
  font-weight: 700;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  background: #ffffff;
  color: #334155;
  cursor: pointer;
  flex: 1;
  text-align: center;
}
.btn-calib-dpad:hover {
  background: #f1f5f9;
  border-color: #94a3b8;
}

/* Các nút hành động chính ở sidebar */
.calib-actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 4px;
}
.btn-calib-action {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px 12px;
  font-size: 0.82rem;
  font-weight: 700;
  border: 1px solid var(--line, #cbd5e1);
  border-radius: 8px;
  background: var(--card, #ffffff);
  color: var(--ink, #1e293b);
  cursor: pointer;
  text-align: left;
  transition: all 0.15s ease;
}
.btn-calib-action .btn-icon {
  font-size: 1.05rem;
}
.btn-calib-action:hover {
  transform: translateY(-1px);
  box-shadow: 0 2px 6px rgba(0,0,0,0.08);
}
.btn-save-curr {
  background: #f0fdf4;
  border-color: #86efac;
  color: #15803d;
}
.btn-save-curr:hover {
  background: #dcfce7;
}
.btn-save-new {
  background: #eff6ff;
  border-color: #93c5fd;
  color: #1d4ed8;
}
.btn-save-new:hover {
  background: #dbeafe;
}
.btn-test-scan {
  background: #faf5ff;
  border-color: #d8b4fe;
  color: #7e22ce;
}
.btn-test-scan:hover {
  background: #f3e8ff;
}
.btn-reset {
  color: #b45309;
}
.btn-exit {
  color: #dc2626;
}

/* Nút zoom */
.calib-zoom-controls {
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--bg2, #f1f5f9);
  border: 1px solid var(--line, #cbd5e1);
  border-radius: 6px;
  padding: 2px 4px;
}
.btn-zoom {
  padding: 3px 8px;
  font-size: 0.75rem;
  font-weight: 700;
  border: none;
  background: transparent;
  color: var(--ink, #334155);
  cursor: pointer;
  border-radius: 4px;
}
.btn-zoom:hover {
  background: var(--card, #ffffff);
}

.btn-calib-upload {
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--bg2, #f1f5f9);
  border: 1px solid var(--line, #cbd5e1);
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--ink, #334155);
}
.btn-calib-upload:hover {
  background: var(--brand);
  color: #ffffff;
  border-color: var(--brand);
}

/* Responsive cho màn hình nhỏ / điện thoại */
@media (max-width: 900px) {
  .calib-container-2col {
    flex-direction: column-reverse;
  }
  .calib-sidebar {
    width: 100%;
    min-width: 100%;
    max-width: 100%;
    height: 45vh;
    border-right: none;
    border-top: 1px solid var(--line);
  }
  .calib-main {
    height: 55vh;
  }
}

/* ==========================================================================
   BẢNG ĐIỀU CHỈNH CẤU TRÚC SỐ CỘT SBD, MÃ ĐỀ & SỐ CÂU PHẦN I, II, III
   ========================================================================== */
.calib-structure-table {
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: var(--card, #ffffff);
  border: 1px solid var(--line, #e2e8f0);
  border-radius: 8px;
  padding: 8px 10px;
}
.calib-structure-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}
.calib-structure-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--ink, #334155);
}
.calib-counter {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--bg2, #f8fafc);
  border: 1px solid var(--line, #cbd5e1);
  border-radius: 6px;
  padding: 2px 4px;
}
.btn-counter {
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 0.82rem;
  padding: 2px 6px;
  border-radius: 4px;
  color: var(--brand, #2563eb);
  font-weight: 800;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.12s;
}
.btn-counter:hover {
  background: var(--brand, #2563eb);
  color: #ffffff;
}
.counter-val {
  font-size: 0.84rem;
  font-weight: 800;
  min-width: 22px;
  text-align: center;
  color: var(--ink, #0f172a);
}

/* ==========================================================================
   MODAL CHỌN MẪU PHIẾU DI ĐỘNG (MOBILE BOTTOM SHEET - CHỮ NHỎ GỌN 1 HÀNG)
   ========================================================================== */
#mobileTemplatePickerModal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(4px);
  z-index: 99999;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.mobile-tpl-card {
  width: 100%;
  max-width: 520px;
  background: var(--card, #1e293b);
  border-radius: 20px 20px 0 0;
  padding: 16px 16px 20px;
  max-height: 82vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.4);
  animation: slideUpTpl 0.2s ease-out;
}
@keyframes slideUpTpl {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}
.mobile-tpl-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line, #334155);
}
.mobile-tpl-title {
  font-size: 0.95rem;
  font-weight: 800;
  color: var(--ink, #f8fafc);
  display: flex;
  align-items: center;
  gap: 6px;
}
.mobile-tpl-list {
  display: flex;
  flex-direction: column;
  gap: 5px;
  overflow-y: auto;
  max-height: 55vh;
  padding-right: 2px;
}
.mobile-tpl-option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 5px 8px;
  border-radius: 7px;
  background: var(--bg2, #0f172a);
  border: 1px solid var(--line, #334155);
  cursor: pointer;
  transition: all 0.12s ease;
  white-space: nowrap;
  overflow: hidden;
  min-height: 28px;
}
.mobile-tpl-option.active {
  background: rgba(37, 99, 235, 0.16);
  border-color: #3b82f6;
}
.mobile-tpl-text {
  font-size: 0.74rem !important;
  font-weight: 600;
  color: var(--ink, #f1f5f9);
  white-space: nowrap !important;
  overflow: hidden !important;
  text-overflow: ellipsis !important;
  flex: 1;
  margin-right: 6px;
  line-height: 1.2 !important;
}
.mobile-tpl-radio {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid var(--muted, #64748b);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.mobile-tpl-radio.selected {
  border-color: #10b981;
  background: #10b981;
}
.mobile-tpl-radio.selected::after {
  content: '';
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #ffffff;
}

/* Tối ưu ô select trên điện thoại */
@media (max-width: 680px) {
  #templateMode, #calibTemplateSelect {
    font-size: 0.76rem !important;
    padding: 6px 8px !important;
    white-space: nowrap !important;
    text-overflow: ellipsis !important;
    overflow: hidden !important;
    line-height: 1.25 !important;
  }
  #templateMode option, #calibTemplateSelect option {
    font-size: 0.76rem !important;
    white-space: nowrap !important;
    text-overflow: ellipsis !important;
  }

  /* Tối ưu modal thống kê & phổ điểm trên điện thoại */
  .stats-header {
    padding: 8px 10px !important;
    gap: 6px !important;
    margin-bottom: 8px !important;
  }
  #statsExamTitle {
    font-size: 0.95rem !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
  }
  .stats-chart-box {
    padding: 8px 10px !important;
    margin-bottom: 8px !important;
    border-radius: 10px !important;
  }
  .stats-histogram-svg {
    height: 125px !important;
  }

  /* Tối ưu thanh tiêu đề kết quả chấm trên điện thoại: bố cục 2 tầng khoa học, không bao giờ bị kéo dài */
  #view-results .section-title.results-header-box {
    gap: 8px !important;
    margin-bottom: 8px !important;
  }
  #view-results .results-title-bar {
    padding-bottom: 4px !important;
  }
  #view-results .results-title-group .back-btn {
    padding: 4px 8px !important;
    font-size: 0.85rem !important;
  }
  #view-results .results-title-group h1 {
    font-size: 1.05rem !important;
  }
  #view-results .results-quick-actions #clearResults {
    padding: 4px 8px !important;
    font-size: 0.74rem !important;
  }
  #view-results .results-actions-grid {
    display: grid !important;
    grid-template-columns: repeat(auto-fit, minmax(100px, 1fr)) !important;
    gap: 6px !important;
    width: 100% !important;
  }
  #view-results .results-actions-grid button {
    width: 100% !important;
    padding: 7px 4px !important;
    font-size: 0.75rem !important;
    font-weight: 600 !important;
    text-align: center !important;
    justify-content: center !important;
  }
}

/* =============================================================================
   CHẾ ĐỘ PHÓNG TO TRÊN MÁY TÍNH & QUẢN LÝ MẪU PHIẾU CHUYÊN SÂU
   ============================================================================= */
#templateManagerModal.maximized .modal-card {
  max-width: 98vw !important;
  width: 98vw !important;
  max-height: 96vh !important;
  height: 96vh !important;
  border-radius: 12px;
}
#templateManagerModal.maximized .modern-table th,
#templateManagerModal.maximized .modern-table td {
  padding: 8px 10px;
  font-size: 0.82rem;
  vertical-align: middle;
}
#templateManagerModal .template-actions-cell {
  white-space: nowrap !important;
  text-align: right;
}
#templateManagerModal .template-actions-group {
  display: inline-flex !important;
  align-items: center;
  justify-content: flex-end;
  gap: 3px !important;
  flex-wrap: nowrap !important;
  white-space: nowrap !important;
}
#templateManagerModal .template-actions-group button {
  white-space: nowrap !important;
  padding: 3px 6px !important;
  font-size: 0.74rem !important;
  line-height: 1.2 !important;
}
#templateZoomCanvas {
  image-rendering: -webkit-optimize-contrast;
  image-rendering: crisp-edges;
}

/* Modal xem phóng to chi tiết mẫu phiếu */
.template-zoom-modal-card {
  max-width: 96vw;
  width: 1240px;
  max-height: 96vh;
  height: 94vh;
  display: flex;
  flex-direction: column;
  padding: 0;
  overflow: hidden;
  background: var(--card);
}
.template-zoom-toolbar {
  padding: 10px 18px;
  background: var(--bg2);
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}
.template-zoom-viewport {
  flex: 1;
  overflow: auto;
  background: #0f172a;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 24px;
  position: relative;
  user-select: none;
}
.template-zoom-canvas-wrap {
  position: relative;
  box-shadow: 0 12px 48px rgba(0, 0, 0, 0.7);
  border-radius: 4px;
  transform-origin: top center;
  transition: transform 0.12s ease-out;
  background: #ffffff;
}

/* Tên bài thi hiển thị đúng 1 dòng trên Dashboard */
#activeExamTitle {
  margin: 0;
  text-align: center;
  flex: 1;
  font-size: 1.18rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

/* Thumbnail ảnh tên học sinh trong bảng kết quả */
.name-crop-thumb {
  height: 40px;
  max-height: 48px;
  max-width: 320px;
  width: auto;
  border-radius: 4px;
  border: 1px solid #cbd5e1;
  vertical-align: middle;
  object-fit: contain;
  background: #ffffff;
  display: inline-block;
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
  transition: transform 0.15s ease;
}
.name-crop-thumb:hover {
  transform: scale(1.05);
}

/* Tối ưu chọn mẫu phiếu hiển thị 1 dòng cỡ chữ nhỏ */
#templateMode {
  font-size: 0.76rem !important;
  white-space: nowrap !important;
  text-overflow: ellipsis !important;
  overflow: hidden !important;
  line-height: 1.25 !important;
}
#templateMode option {
  font-size: 0.76rem !important;
  white-space: nowrap !important;
  text-overflow: ellipsis !important;
}

/* Tối ưu nút đổi theme trên điện thoại cảm ứng */
#themeToggleBtn {
  touch-action: manipulation;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  min-width: 36px;
  min-height: 36px;
}

/* Custom Template Dropdown Menu (Khắc phục hoàn toàn cỡ chữ to trên Android - Giống ảnh 2) */
.custom-template-selector-wrap {
  position: relative;
  width: 100%;
}
.custom-tpl-trigger {
  width: 100%;
  display: flex !important;
  align-items: center !important;
  justify-content: space-between !important;
  padding: 8px 12px !important;
  font-size: 0.8rem !important;
  border-radius: 8px !important;
  cursor: pointer;
  background: var(--card, #ffffff);
  border: 1px solid var(--line, #cbd5e1);
  color: var(--ink, #0f172a);
  text-align: left;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}
.custom-tpl-trigger-text {
  flex: 1;
  white-space: nowrap !important;
  overflow: hidden !important;
  text-overflow: ellipsis !important;
  margin-right: 8px;
  font-size: 0.8rem !important;
  line-height: 1.25 !important;
  font-weight: 600;
  color: var(--ink, #0f172a);
}
.custom-tpl-trigger-icon {
  font-size: 0.72rem;
  color: var(--muted, #64748b);
  flex-shrink: 0;
  transition: transform 0.15s ease;
}
.custom-tpl-trigger.open .custom-tpl-trigger-icon {
  transform: rotate(180deg);
}

.custom-template-dropdown-menu {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  z-index: 1050;
  background: var(--card, #ffffff);
  border: 1px solid var(--line, #cbd5e1);
  border-radius: 8px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.16);
  max-height: 290px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
  padding: 4px 0;
}
.custom-tpl-dropdown-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  font-size: 0.78rem;
  color: var(--ink, #1e293b);
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  border-bottom: 1px solid rgba(0, 0, 0, 0.04);
  transition: background 0.12s ease;
  line-height: 1.25;
}
.custom-tpl-dropdown-item:last-child {
  border-bottom: none;
}
.custom-tpl-dropdown-item:hover,
.custom-tpl-dropdown-item:active {
  background: rgba(2, 132, 199, 0.10);
  color: var(--brand, #0284c7);
}
.custom-tpl-dropdown-item.selected {
  background: rgba(2, 132, 199, 0.14);
  color: var(--brand, #0284c7);
  font-weight: 700;
}
.custom-tpl-item-title {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.custom-tpl-item-check {
  font-size: 0.8rem;
  color: var(--brand, #0284c7);
  margin-left: 6px;
  flex-shrink: 0;
  font-weight: 800;
}

/* === HERO CREATE EXAM BUTTON (THIẾT KẾ KHOA HỌC, ĐẸP, GỌN, CĂN GIỮA) === */
.hero-create-card {
  grid-column: 1 / -1;
  display: flex !important;
  flex-direction: row !important;
  align-items: center !important;
  justify-content: center !important;
  gap: 12px !important;
  padding: 14px 20px !important;
  min-height: 54px !important;
  border-radius: 14px !important;
  background: linear-gradient(135deg, #0284c7 0%, #0369a1 100%) !important;
  border: 1px solid rgba(255, 255, 255, 0.22) !important;
  box-shadow: 0 6px 18px -2px rgba(2, 132, 199, 0.35) !important;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1) !important;
  position: relative;
  overflow: hidden;
}

[data-theme="dark"] .hero-create-card {
  background: linear-gradient(135deg, #0284c7 0%, #1e40af 100%) !important;
  border: 1px solid rgba(56, 189, 248, 0.3) !important;
  box-shadow: 0 4px 20px rgba(2, 132, 199, 0.3) !important;
}

.hero-create-card:hover {
  transform: translateY(-2px) !important;
  box-shadow: 0 10px 24px -2px rgba(2, 132, 199, 0.45) !important;
  filter: brightness(1.05);
}

.hero-create-card:active {
  transform: scale(0.985) !important;
}

.hcc-icon-box {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #ffffff;
  flex-shrink: 0;
  backdrop-filter: blur(4px);
}

.hcc-text-box {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.hcc-title-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.hcc-title {
  color: #ffffff !important;
  font-weight: 800;
  font-size: 1.05rem;
  letter-spacing: -0.01em;
  margin: 0;
  line-height: 1.25;
}

.hcc-badge {
  font-size: 0.68rem;
  font-weight: 800;
  color: #0284c7;
  background: #ffffff;
  padding: 2px 7px;
  border-radius: 6px;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
  display: inline-block;
  line-height: 1.3;
}

[data-theme="dark"] .hcc-badge {
  color: #0369a1;
  background: #e0f2fe;
}

.hcc-desc {
  display: none !important;
}

.hcc-arrow-box {
  position: absolute;
  right: 16px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.18);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #ffffff;
  flex-shrink: 0;
  transition: all 0.2s;
}

.hero-create-card:hover .hcc-arrow-box {
  transform: translateX(3px);
  background: rgba(255, 255, 255, 0.3);
}

@media (max-width: 768px) {
  .hero-create-card {
    padding: 10px 14px !important;
    min-height: 48px !important;
    border-radius: 12px !important;
    gap: 10px !important;
  }
  .hcc-icon-box {
    width: 30px !important;
    height: 30px !important;
    border-radius: 8px !important;
  }
  .hcc-icon-box svg {
    width: 18px !important;
    height: 18px !important;
  }
  .hcc-title {
    font-size: 0.95rem !important;
  }
  .hcc-badge {
    font-size: 0.62rem !important;
    padding: 1.5px 6px !important;
  }
  .hcc-arrow-box {
    right: 12px;
    width: 22px !important;
    height: 22px !important;
  }
}

/* === IN-APP AUTO UPDATE & FORCE UPDATE MODAL === */
.force-update-overlay {
  position: fixed;
  inset: 0;
  z-index: 999999;
  background: rgba(15, 23, 42, 0.94);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.force-update-box {
  max-width: 480px;
  width: 100%;
  background: #1e293b;
  border: 2px solid #ef4444;
  border-radius: 18px;
  padding: 28px 24px;
  text-align: center;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.8), 0 0 30px rgba(239, 68, 68, 0.25);
  animation: popIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  color: #f8fafc;
}

[data-theme="light"] .force-update-box {
  background: #ffffff;
  color: #0f172a;
  border-color: #dc2626;
  box-shadow: 0 20px 40px -10px rgba(0, 0, 0, 0.2), 0 0 25px rgba(220, 38, 38, 0.2);
}

.force-update-icon {
  font-size: 3.2rem;
  margin-bottom: 12px;
  animation: bounceUpdate 1.4s infinite ease-in-out;
}

.btn-force-download {
  display: block;
  width: 100%;
  padding: 14px 20px;
  background: linear-gradient(135deg, #ef4444 0%, #b91c1c 100%);
  color: #ffffff !important;
  font-weight: 800;
  font-size: 1rem;
  border-radius: 12px;
  text-decoration: none !important;
  box-shadow: 0 4px 16px rgba(239, 68, 68, 0.45);
  transition: transform 0.15s, filter 0.15s;
  text-align: center;
  box-sizing: border-box;
}

.btn-force-download:hover {
  transform: translateY(-2px);
  filter: brightness(1.08);
}

.btn-force-download:active {
  transform: scale(0.98);
}

.optional-update-banner {
  background: rgba(14, 165, 233, 0.12);
  border: 1px solid #0284c7;
  border-radius: 12px;
  padding: 10px 16px;
  margin: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  animation: slideDown 0.3s ease-out;
}

.btn-small-update {
  padding: 6px 14px;
  background: #0284c7;
  color: #ffffff !important;
  font-size: 0.84rem;
  font-weight: 700;
  border-radius: 8px;
  text-decoration: none !important;
  transition: background 0.15s;
  display: inline-block;
}

.btn-small-update:hover {
  background: #0369a1;
}

.btn-small-dismiss {
  padding: 6px 12px;
  background: transparent;
  border: 1px solid rgba(148, 163, 184, 0.3);
  color: inherit;
  font-size: 0.82rem;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-small-dismiss:hover {
  background: rgba(148, 163, 184, 0.12);
}

@keyframes popIn {
  from { opacity: 0; transform: scale(0.92); }
  to { opacity: 1; transform: scale(1); }
}

@keyframes bounceUpdate {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

@keyframes slideDown {
  from { opacity: 0; transform: translateY(-10px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

/* === TỰ ĐỘNG ẨN CÁC NÚT CÀI ĐẶT KHI MỞ TRONG APP / STANDALONE === */
@media all and (display-mode: standalone), all and (display-mode: fullscreen), all and (display-mode: minimal-ui) {
  #homePwaInstallBtn,
  #homePwaInstallWrap,
  #pwaInstallBtn,
  #pwaInlineGuide,
  .pwa-install-hide-when-installed {
    display: none !important;
  }
}
body.is-pwa-installed #homePwaInstallBtn,
body.is-pwa-installed #homePwaInstallWrap,
body.is-pwa-installed #pwaInstallBtn,
body.is-pwa-installed #pwaInlineGuide,
body.is-pwa-installed .pwa-install-hide-when-installed,
html.is-pwa-installed #homePwaInstallBtn,
html.is-pwa-installed #homePwaInstallWrap,
html.is-pwa-installed #pwaInstallBtn,
html.is-pwa-installed #pwaInlineGuide,
html.is-pwa-installed .pwa-install-hide-when-installed,
.is-pwa-installed #homePwaInstallBtn,
.is-pwa-installed #homePwaInstallWrap,
.is-pwa-installed #pwaInstallBtn,
.is-pwa-installed #pwaInlineGuide,
.is-pwa-installed .pwa-install-hide-when-installed {
  display: none !important;
}

/* === ẨN CÁC THÔNG BÁO THEO YÊU CẦU TRÊN ĐIỆN THOẠI & APP === */
#offlineOmrStatusPill {
  display: none !important;
}

@media (max-width: 768px), all and (display-mode: standalone), all and (display-mode: fullscreen), all and (display-mode: minimal-ui) {
  #syncStatusBadge {
    display: none !important;
  }
}
body.is-pwa-installed #syncStatusBadge,
html.is-pwa-installed #syncStatusBadge,
.is-pwa-installed #syncStatusBadge {
  display: none !important;
}

/* === TOP BANNER & HERO CARD CÀI ĐẶT ỨNG DỤNG (KHI MỞ QUA TRÌNH DUYỆT) === */
.mobile-top-install-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: linear-gradient(90deg, #0f172a 0%, #1e293b 100%);
  border-bottom: 1.5px solid rgba(2, 132, 199, 0.4);
  padding: 8px 14px;
  position: sticky;
  top: 0;
  z-index: 10000;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
}
[data-theme="light"] .mobile-top-install-bar {
  background: linear-gradient(90deg, #f8fafc 0%, #e0f2fe 100%);
  border-bottom-color: rgba(2, 132, 199, 0.3);
}
.mobile-top-install-bar .top-bar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.mobile-top-install-bar .top-bar-logo {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  flex-shrink: 0;
}
.mobile-top-install-bar .top-bar-meta {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.mobile-top-install-bar .top-bar-title {
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.mobile-top-install-bar .top-bar-sub {
  font-size: 0.74rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.mobile-top-install-bar .top-bar-action {
  background: linear-gradient(135deg, #0284c7 0%, #10b981 100%);
  color: #ffffff !important;
  font-weight: 700;
  font-size: 0.84rem;
  padding: 7px 14px;
  border-radius: 999px;
  border: none;
  cursor: pointer;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  box-shadow: 0 2px 10px rgba(2, 132, 199, 0.4);
  transition: transform 0.15s, box-shadow 0.15s;
}
.mobile-top-install-bar .top-bar-action:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 14px rgba(2, 132, 199, 0.5);
}

/* Auth Hero Install Card */
.auth-hero-install-card {
  margin-bottom: 20px;
  padding: 16px 14px;
  border-radius: 16px;
  background: linear-gradient(135deg, rgba(2, 132, 199, 0.12) 0%, rgba(16, 185, 129, 0.1) 100%);
  border: 1.5px solid rgba(2, 132, 199, 0.35);
  box-shadow: 0 6px 20px rgba(2, 132, 199, 0.12);
  text-align: center;
  position: relative;
  overflow: hidden;
}
[data-theme="light"] .auth-hero-install-card {
  background: linear-gradient(135deg, #f0f9ff 0%, #ecfdf5 100%);
  border-color: #38bdf8;
  box-shadow: 0 6px 20px rgba(2, 132, 199, 0.1);
}
.auth-hero-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  color: #0284c7;
  background: rgba(2, 132, 199, 0.12);
  border: 1px solid rgba(2, 132, 199, 0.25);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.auth-hero-badge-pulse {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #10b981;
  box-shadow: 0 0 8px #10b981;
  animation: badge-pulse 1.8s infinite;
}
@keyframes badge-pulse {
  0% { transform: scale(0.9); opacity: 0.8; }
  50% { transform: scale(1.3); opacity: 1; }
  100% { transform: scale(0.9); opacity: 0.8; }
}
.auth-hero-content {
  margin-bottom: 12px;
}
.auth-hero-title {
  font-size: 1.05rem;
  font-weight: 800;
  color: var(--ink);
  margin-bottom: 4px;
}
.auth-hero-desc {
  font-size: 0.82rem;
  color: var(--muted);
  line-height: 1.45;
  margin: 0;
}
.auth-hero-btn {
  width: 100%;
  background: linear-gradient(135deg, #0284c7 0%, #059669 100%);
  color: #ffffff !important;
  font-weight: 800;
  font-size: 0.96rem;
  letter-spacing: 0.02em;
  padding: 12px 16px;
  border-radius: 12px;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  box-shadow: 0 4px 16px rgba(2, 132, 199, 0.35);
  position: relative;
  overflow: hidden;
  transition: transform 0.15s, box-shadow 0.15s;
}
.auth-hero-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(2, 132, 199, 0.45);
}
.auth-hero-btn:active {
  transform: translateY(0);
}
.auth-hero-links {
  margin-top: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 0.78rem;
  color: var(--muted);
  flex-wrap: wrap;
}
.auth-hero-dot {
  opacity: 0.5;
}
.auth-hero-apk-link {
  color: var(--brand);
  text-decoration: underline;
  font-weight: 600;
}
.auth-hero-apk-link:hover {
  color: #10b981;
}

/* Ensure hidden in standalone and grading/review mode */
body.is-pwa-installed #mobileTopInstallBar,
html.is-pwa-installed #mobileTopInstallBar,
.is-pwa-installed #mobileTopInstallBar,
body.grading-mode #mobileTopInstallBar,
html.grading-mode #mobileTopInstallBar,
body.grading-mode .mobile-top-install-bar,
body.review-modal-open #mobileTopInstallBar,
body.grading-mode #authHeroInstallBanner,
body.grading-mode #appInstallSection,
body.grading-mode #homePwaInstallWrap,
body.grading-mode #pwaInstallBtn,
body.grading-mode #homePwaInstallBtn,
body.is-pwa-installed #authHeroInstallBanner,
html.is-pwa-installed #authHeroInstallBanner,
.is-pwa-installed #authHeroInstallBanner {
  display: none !important;
}

/* Nút tắt X rõ ràng, nổi bật ở góc phải màn hình xem kết quả bài thi */
.result-review-floating-close {
  position: absolute;
  top: 7px;
  right: 10px;
  z-index: 25;
  width: 32px;
  height: 32px;
  border-radius: 999px;
  background: rgba(239, 68, 68, 0.12);
  color: #ef4444;
  border: 1.5px solid rgba(239, 68, 68, 0.35);
  font-size: 1.25rem;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  line-height: 1;
  padding: 0;
  transition: all 0.15s ease;
}
.result-review-floating-close:hover {
  background: #ef4444;
  color: #ffffff;
  transform: scale(1.1);
}

details.review-details-collapse summary::-webkit-details-marker {
  display: none;
}
details.review-details-collapse summary {
  list-style: none;
}

/* ===== THỐNG KÊ LỰA CHỌN THEO TỪNG MÃ ĐỀ & CHI TIẾT HỌC SINH ===== */
#examCodeStatsModal {
  z-index: 1000;
}
#optionStudentsModal {
  z-index: 1060;
}
#resultReviewModal {
  z-index: 1120;
}

.code-stat-selector {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 4px 2px 10px;
  margin-bottom: 14px;
  scrollbar-width: thin;
}
.code-stat-selector::-webkit-scrollbar {
  height: 4px;
}
.code-stat-selector::-webkit-scrollbar-thumb {
  background: rgba(148, 163, 184, 0.4);
  border-radius: 999px;
}

.code-stat-btn {
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 0.84rem;
  font-weight: 700;
  border: 1px solid var(--line, #cbd5e1);
  background: var(--bg2, #f8fafc);
  color: var(--ink, #1e293b);
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s ease;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.code-stat-btn:hover {
  background: var(--card, #ffffff);
  border-color: var(--brand, #0284c7);
  color: var(--brand, #0284c7);
  transform: translateY(-1px);
}
.code-stat-btn.active {
  background: var(--brand, #0284c7);
  border-color: var(--brand, #0284c7);
  color: #ffffff;
  box-shadow: 0 2px 8px rgba(2, 132, 199, 0.35);
}

.code-summary-bar {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}
.code-summary-box {
  background: var(--bg2, #f8fafc);
  border: 1px solid var(--line, #e2e8f0);
  border-radius: 10px;
  padding: 7px 10px;
  text-align: center;
}
.code-summary-box small {
  display: block;
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--muted, #64748b);
  margin-bottom: 2px;
}
.code-summary-box strong {
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--ink, #0f172a);
}

/* Card câu hỏi Phần I - 4 cột cân đối, không cuộn ngang */
.opt-q-card {
  background: var(--card, #ffffff);
  border: 1px solid var(--line, #e2e8f0);
  border-radius: 10px;
  padding: 6px 10px;
  margin-bottom: 6px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03);
  transition: all 0.15s ease;
}
.opt-q-card:hover {
  border-color: #93c5fd;
}
.opt-q-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 5px;
  padding-bottom: 4px;
  border-bottom: 1px dashed var(--line, #e2e8f0);
}
.opt-q-num {
  font-weight: 800;
  font-size: 0.88rem;
  color: var(--ink, #1e293b);
}
.correct-key-pill {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 1px 8px;
  background: #dcfce7;
  color: #15803d;
  border: 1px solid #86efac;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 800;
}
.opt-empty-badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 1px 6px;
  background: #fef3c7;
  color: #b45309;
  border: 1px solid #fde68a;
  border-radius: 6px;
  font-size: 0.72rem;
  font-weight: 600;
  cursor: pointer;
}

/* Grid các phương án A, B, C, D: 4 cột đều nhau */
.opt-q-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}
@media (max-width: 640px) {
  .opt-q-grid {
    grid-template-columns: repeat(4, 1fr) !important;
    gap: 4px !important;
  }
  .opt-btn {
    padding: 3px 2px !important;
    min-height: 34px !important;
    flex-direction: column !important;
    justify-content: center !important;
    text-align: center !important;
    gap: 1px !important;
    border-radius: 6px !important;
  }
  .opt-btn .opt-text {
    font-size: 0.75rem !important;
    gap: 2px !important;
    justify-content: center !important;
  }
  .opt-btn .opt-count {
    font-size: 0.65rem !important;
    line-height: 1 !important;
  }
  .code-summary-bar {
    grid-template-columns: repeat(4, 1fr) !important;
    gap: 4px !important;
    margin-bottom: 8px !important;
  }
  .code-summary-box {
    padding: 5px 2px !important;
    border-radius: 8px !important;
  }
  .code-summary-box small {
    font-size: 0.62rem !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
  }
  .code-summary-box strong {
    font-size: 1.0rem !important;
    white-space: nowrap !important;
  }
}

/* Nút bấm phương án */
.opt-btn {
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 0.82rem;
  font-weight: 700;
  border: 1.5px solid var(--line, #cbd5e1);
  background: var(--bg2, #f8fafc);
  color: var(--ink, #334155);
  cursor: pointer;
  min-height: 40px;
  text-align: left;
  transition: all 0.15s ease;
  user-select: none;
}
.opt-btn:hover {
  transform: translateY(-1.5px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
  border-color: var(--brand, #0284c7);
}
.opt-btn:active {
  transform: translateY(0);
}
.opt-btn .opt-fill-bar {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  background: rgba(2, 132, 199, 0.12);
  z-index: 1;
  pointer-events: none;
  transition: width 0.3s ease;
}
.opt-btn .opt-text {
  position: relative;
  z-index: 2;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.82rem;
}
.opt-btn .opt-count {
  position: relative;
  z-index: 2;
  font-size: 0.74rem;
  color: var(--muted, #64748b);
  font-weight: 700;
}
.opt-btn.is-correct {
  border-color: #22c55e !important;
  background: #f0fdf4 !important;
  color: #15803d !important;
}
.opt-btn.is-correct .opt-fill-bar {
  background: rgba(34, 197, 94, 0.22) !important;
}
.opt-btn.is-correct .opt-count {
  color: #166534 !important;
}
.opt-btn.is-zero {
  opacity: 0.6;
  border-style: dashed;
}

/* Phần II - Đúng / Sai dạng Card trên mobile */
.opt-tf-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 0;
  border-bottom: 1px dashed var(--line, #e2e8f0);
}
.opt-tf-row:last-child {
  border-bottom: none;
  padding-bottom: 0;
}
.opt-tf-label {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 90px;
}
.opt-tf-btns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  flex: 1;
}

/* Card học sinh trong modal chi tiết phương án (Kèm ảnh tên chụp) */
.student-drill-cards {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.student-drill-card {
  background: var(--card, #ffffff);
  border: 1px solid var(--line, #e2e8f0);
  border-radius: 10px;
  padding: 10px 12px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.03);
}
.student-drill-card-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
}
.student-drill-idx {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 6px;
  background: var(--bg2, #f1f5f9);
  color: var(--muted, #64748b);
  font-size: 0.75rem;
  font-weight: 800;
  flex-shrink: 0;
}
.student-drill-name-img-wrap {
  margin: 6px 0 6px 32px;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.student-drill-name-img {
  max-height: 38px;
  max-width: 220px;
  border-radius: 4px;
  border: 1px solid #cbd5e1;
  background: #ffffff;
  object-fit: contain;
}
.student-drill-card-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px dashed var(--line, #e2e8f0);
}

/* =============================================================================
   MODAL PHÓNG TO & VUỐT CHUYỂN BÀI THI HỌC SINH (HORIZONTAL & VERTICAL SWIPE)
   ============================================================================= */
#sheetImageZoomModal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.94);
  backdrop-filter: blur(8px);
  z-index: 100000;
  display: none;
  touch-action: none;
}
#sheetImageZoomModal {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  background: rgba(0, 0, 0, 0.96);
  z-index: 99999;
  display: flex;
  flex-direction: column;
  padding: 0;
  margin: 0;
  overflow: hidden;
  box-sizing: border-box;
}
#sheetImageZoomModal:not(.hidden) {
  display: flex !important;
}
.sheet-zoom-container {
  display: flex;
  flex-direction: column;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  position: relative;
  background: #000;
}

/* Thanh Header điều khiển: Gọn gàng, khoa học, thanh lịch */
.sheet-zoom-header {
  flex-shrink: 0;
  width: 100%;
  background: rgba(15, 23, 42, 0.92);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
  padding: 6px 12px;
  box-sizing: border-box;
  z-index: 100;
}

.sheet-zoom-header-main {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  gap: 8px;
}

/* Nút quay lại / thoát bên trái */
.sheet-zoom-back-btn {
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  gap: 4px !important;
  background: rgba(255, 255, 255, 0.12) !important;
  border: 1px solid rgba(255, 255, 255, 0.22) !important;
  color: #ffffff !important;
  padding: 5px 11px !important;
  border-radius: 8px !important;
  font-size: 0.82rem !important;
  font-weight: 700 !important;
  cursor: pointer !important;
  white-space: nowrap !important;
  flex-shrink: 0 !important;
  transition: all 0.15s ease !important;
}
.sheet-zoom-back-btn:active {
  background: rgba(255, 255, 255, 0.28) !important;
  transform: scale(0.96) !important;
}

/* Tiêu đề thông tin học sinh ở giữa */
.sheet-zoom-title {
  flex: 1;
  min-width: 0;
  text-align: center;
  font-size: 0.84rem;
  font-weight: 700;
  color: #f8fafc;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding: 0 6px;
  line-height: 1.35;
}

/* Cụm nút thao tác bên phải */
.sheet-zoom-header-right {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.sheet-zoom-zalo-btn {
  display: inline-flex !important;
  align-items: center !important;
  gap: 3px !important;
  background: rgba(0, 104, 255, 0.2) !important;
  border: 1px solid rgba(0, 104, 255, 0.45) !important;
  color: #60a5fa !important;
  padding: 5px 9px !important;
  border-radius: 8px !important;
  font-size: 0.78rem !important;
  font-weight: 700 !important;
  cursor: pointer !important;
  white-space: nowrap !important;
  transition: all 0.15s ease !important;
}
.sheet-zoom-zalo-btn:active {
  background: rgba(0, 104, 255, 0.45) !important;
}

.sheet-zoom-delete-btn {
  display: inline-flex !important;
  align-items: center !important;
  gap: 3px !important;
  background: rgba(239, 68, 68, 0.16) !important;
  border: 1px solid rgba(239, 68, 68, 0.38) !important;
  color: #f87171 !important;
  padding: 5px 9px !important;
  border-radius: 8px !important;
  font-size: 0.78rem !important;
  font-weight: 700 !important;
  cursor: pointer !important;
  white-space: nowrap !important;
  transition: all 0.15s ease !important;
}
.sheet-zoom-delete-btn:active {
  background: rgba(239, 68, 68, 0.38) !important;
}

.sheet-zoom-continue-btn {
  display: inline-flex !important;
  align-items: center !important;
  gap: 3px !important;
  background: #0284c7 !important;
  border: 1px solid #38bdf8 !important;
  color: #ffffff !important;
  padding: 5px 11px !important;
  border-radius: 8px !important;
  font-size: 0.78rem !important;
  font-weight: 700 !important;
  cursor: pointer !important;
  white-space: nowrap !important;
  box-shadow: 0 2px 6px rgba(2, 132, 199, 0.4) !important;
  transition: all 0.15s ease !important;
}
.sheet-zoom-continue-btn:active {
  background: #0369a1 !important;
  transform: scale(0.96) !important;
}

.sheet-zoom-close-btn {
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  width: 28px !important;
  height: 28px !important;
  border-radius: 50% !important;
  background: rgba(255, 255, 255, 0.14) !important;
  border: 1px solid rgba(255, 255, 255, 0.25) !important;
  color: #ffffff !important;
  font-size: 0.95rem !important;
  font-weight: 800 !important;
  cursor: pointer !important;
  flex-shrink: 0 !important;
  padding: 0 !important;
  margin-left: 2px !important;
  line-height: 1 !important;
  transition: all 0.15s ease !important;
}
.sheet-zoom-close-btn:active {
  background: rgba(255, 255, 255, 0.35) !important;
}

/* Nút thoát nổi dư thừa: Ẩn đi để không làm lệch ảnh */
.sheet-zoom-floating-corner-back {
  display: none !important;
}

/* Khu vực hiển thị ảnh bài thi: CĂN GIỮA TUYỆT ĐỐI */
#sheetZoomViewport {
  flex: 1;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  position: relative;
  overflow: hidden;
  padding: 6px;
  margin: 0;
  box-sizing: border-box;
  background: #000;
  width: 100vw;
  height: 100%;
  touch-action: pan-x pan-y pinch-zoom;
  -webkit-overflow-scrolling: touch;
}

#sheetZoomViewport.is-zoomed {
  overflow: auto;
  cursor: grab;
  display: block !important;
  text-align: center;
}

#sheetZoomImageEl {
  max-width: 98vw !important;
  max-height: calc(100dvh - 84px) !important;
  width: auto !important;
  height: auto !important;
  object-fit: contain !important;
  margin: auto !important;
  display: block !important;
  border-radius: 8px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.85);
  user-select: none;
  -webkit-user-drag: none;
  transition: width 0.14s ease-out, height 0.14s ease-out;
  cursor: zoom-in;
}

#sheetZoomViewport.is-zoomed #sheetZoomImageEl {
  margin: auto !important;
  display: inline-block !important;
}

.sheet-zoom-footer {
  flex-shrink: 0;
  padding: 4px 10px;
  font-size: 0.72rem;
  background: rgba(15, 23, 42, 0.88);
  color: #94a3b8;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

/* Tối ưu hiển thị khoa học trên điện thoại màn hình nhỏ (< 480px) */
@media (max-width: 480px) {
  .sheet-zoom-header {
    padding: 5px 8px;
  }
  .sheet-zoom-header-main {
    flex-wrap: wrap;
    gap: 4px 6px;
  }
  .sheet-zoom-back-btn {
    padding: 4px 8px !important;
    font-size: 0.78rem !important;
  }
  .sheet-zoom-title {
    order: 1;
    font-size: 0.78rem;
    text-align: left;
    padding-left: 2px;
  }
  .sheet-zoom-header-right {
    order: 2;
    width: auto;
    margin-left: auto;
    gap: 4px;
  }
  .sheet-zoom-zalo-btn,
  .sheet-zoom-delete-btn,
  .sheet-zoom-continue-btn {
    padding: 4px 7px !important;
    font-size: 0.74rem !important;
  }
  .sheet-zoom-close-btn {
    width: 26px !important;
    height: 26px !important;
    font-size: 0.88rem !important;
  }
  #sheetZoomImageEl {
    max-height: calc(100dvh - 76px) !important;
  }
}

.review-swipe-anim-next {
  animation: slideInFromRight 0.22s cubic-bezier(0.16, 1, 0.3, 1);
}
.review-swipe-anim-prev {
  animation: slideInFromLeft 0.22s cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes slideInFromRight {
  from { opacity: 0; transform: translateX(40px); }
  to { opacity: 1; transform: translateX(0); }
}
@keyframes slideInFromLeft {
  from { opacity: 0; transform: translateX(-40px); }
  to { opacity: 1; transform: translateX(0); }
}





/* ===== LAUNCHER MENU CĂN THẲNG DỌC (1 CỘT ĐỀU ĐẸP) ===== */
.home-menu-list {
  display: flex;
  flex-direction: column;
  gap: 9px;
  padding: 16px 14px 12px;
  max-width: 600px;
  margin: 0 auto;
}

.menu-list-item {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 10px 14px;
  min-height: 48px;
  cursor: pointer;
  transition: all 0.18s cubic-bezier(0.16, 1, 0.3, 1);
  box-shadow: 0 2px 8px rgba(0,0,0,0.04);
  user-select: none;
}

.menu-list-item:hover {
  border-color: var(--brand);
  transform: translateY(-1.5px);
  box-shadow: 0 6px 16px rgba(0,0,0,0.08);
}

.menu-list-item:active {
  transform: scale(0.985);
}

.mli-icon-box {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: var(--bg2);
  border: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.35rem;
  flex-shrink: 0;
}

.mli-content {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.mli-title {
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mli-title-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.mli-badge {
  font-size: 0.68rem;
  font-weight: 800;
  padding: 2px 7px;
  border-radius: 999px;
  background: rgba(255,255,255,0.22);
  color: #fff;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.mli-arrow {
  color: var(--muted);
  font-size: 1.25rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: transform 0.15s ease;
}

.menu-list-item:hover .mli-arrow {
  transform: translateX(3px);
  color: var(--brand);
}

/* Nút Tạo bài chấm mới: Gọn gàng, thanh mảnh, đồng bộ với hàng dọc */
.menu-list-item.primary {
  background: linear-gradient(135deg, #0284c7 0%, #0369a1 100%) !important;
  border: 1px solid #0284c7 !important;
  box-shadow: 0 4px 16px rgba(2, 132, 199, 0.35) !important;
}

.menu-list-item.primary .mli-title {
  color: #ffffff !important;
  font-weight: 800;
}

.menu-list-item.primary .mli-icon-box {
  background: rgba(255, 255, 255, 0.22) !important;
  border-color: rgba(255, 255, 255, 0.35) !important;
  color: #ffffff !important;
}

.menu-list-item.primary .mli-arrow {
  color: #ffffff !important;
}

/* Thống kê mã đề: Đáp án sai học sinh đã chọn hiển thị đỏ nhạt */
.opt-btn.is-wrong-picked {
  border-color: #fca5a5 !important;
  background: #fef2f2 !important;
  color: #b91c1c !important;
}
.opt-btn.is-wrong-picked .opt-fill-bar {
  background: rgba(239, 68, 68, 0.16) !important;
}
.opt-btn.is-wrong-picked .opt-count {
  color: #991b1b !important;
}
[data-theme="dark"] .opt-btn.is-wrong-picked {
  background: rgba(239, 68, 68, 0.15) !important;
  border-color: rgba(239, 68, 68, 0.45) !important;
  color: #f87171 !important;
}
[data-theme="dark"] .opt-btn.is-wrong-picked .opt-fill-bar {
  background: rgba(239, 68, 68, 0.22) !important;
}
[data-theme="dark"] .opt-btn.is-wrong-picked .opt-count {
  color: #fca5a5 !important;
}

/* PWA Installation Floating Banner & Hide when installed or scanning */
body.grading-mode #pwaFloatingInstallBar,
.is-pwa-installed #pwaFloatingInstallBar,
.is-pwa-installed #homePwaInstallMenuItem,
.is-pwa-installed #authPwaInstallBtnWrap {
  display: none !important;
}

/* =============================================================================
   GIAO DIỆN THANH CÔNG CỤ KẾT QUẢ CHẤM KHOA HỌC & GỌN GÀNG (DESKTOP & MOBILE)
   ============================================================================= */
#view-results .section-title.results-header-box {
  display: flex !important;
  flex-direction: column !important;
  align-items: stretch !important;
  gap: 10px !important;
  margin-bottom: 12px !important;
}

#view-results .results-title-bar {
  display: flex !important;
  align-items: center !important;
  justify-content: space-between !important;
  position: relative !important;
  width: 100% !important;
  gap: 8px !important;
  padding-bottom: 6px !important;
  border-bottom: 1px solid var(--line) !important;
}

#view-results .results-title-bar .back-btn {
  z-index: 2 !important;
  padding: 4px 10px !important;
  font-size: 0.95rem !important;
  font-weight: 800 !important;
  border-radius: 8px !important;
  flex-shrink: 0 !important;
  cursor: pointer;
}

#view-results .results-title-heading {
  position: absolute !important;
  left: 50% !important;
  transform: translateX(-50%) !important;
  margin: 0 !important;
  font-size: 1.15rem !important;
  font-weight: 800 !important;
  color: var(--fg) !important;
  text-align: center !important;
  white-space: nowrap !important;
  pointer-events: none !important;
  z-index: 1 !important;
}

#view-results .results-quick-actions {
  display: flex !important;
  align-items: center !important;
  gap: 6px !important;
  flex-shrink: 0 !important;
}

#view-results .results-quick-actions #clearResults {
  padding: 5px 12px !important;
  font-size: 0.8rem !important;
  border-radius: 8px !important;
  white-space: nowrap !important;
  font-weight: 700 !important;
  cursor: pointer;
}

#view-results .results-actions-grid {
  display: flex !important;
  align-items: center !important;
  gap: 6px !important;
  flex-wrap: wrap !important;
  width: 100% !important;
  margin: 0 !important;
}

#view-results .results-actions-grid button {
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  gap: 4px !important;
  padding: 6px 12px !important;
  font-size: 0.82rem !important;
  border-radius: 8px !important;
  white-space: nowrap !important;
  cursor: pointer !important;
}


/* =============================================================================
   GIAO DIỆN KẾT QUẢ KHOA HỌC & CHUYÊN NGHIỆP: KPI STRIP, NÚT TÊN GỌN, BẢNG PHẦN II
   ============================================================================= */

/* 1. Băng 4 chỉ số thống kê kết quả: Grid 4 ô hiện đại, khoa học, chuyên nghiệp */
.results-stats-strip {
  display: grid !important;
  grid-template-columns: repeat(4, 1fr) !important;
  gap: 6px !important;
  margin: 6px 0 8px !important;
  width: 100% !important;
}

.results-stat-card {
  background: var(--bg2, #f8fafc);
  border: 1px solid var(--line, #e2e8f0);
  border-radius: 8px;
  padding: 6px 4px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.02);
  transition: all 0.15s ease;
}

.results-stat-label {
  display: block;
  font-size: 0.66rem;
  font-weight: 700;
  color: var(--muted, #64748b);
  margin-bottom: 2px;
  white-space: nowrap;
}

.results-stat-val {
  display: block;
  font-size: 1.05rem;
  font-weight: 800;
  color: var(--ink, #0f172a);
  line-height: 1.2;
  white-space: nowrap;
}

[data-theme="dark"] .results-stat-card {
  background: rgba(255, 255, 255, 0.04);
  border-color: rgba(255, 255, 255, 0.1);
}
[data-theme="dark"] .results-stat-val {
  color: var(--fg, #f8fafc);
}

/* 2. Thanh điều khiển Tên & Sắp xếp SBD */
.results-filter-toolbar {
  display: flex !important;
  justify-content: space-between !important;
  align-items: center !important;
  flex-wrap: wrap !important;
  gap: 6px !important;
  margin: 4px 0 6px !important;
  padding: 4px 0 !important;
}

/* Nút toggle Tên SBD / Viết tay: Thu nhỏ gọn gàng, tinh tế */
.name-mode-toggle {
  display: inline-flex !important;
  align-items: center !important;
  background: var(--bg2, #f1f5f9) !important;
  border: 1px solid var(--line, #cbd5e1) !important;
  border-radius: 999px !important;
  padding: 2px !important;
  gap: 2px !important;
}

.name-mode-toggle button {
  padding: 3px 8px !important;
  font-size: 0.72rem !important;
  font-weight: 700 !important;
  border-radius: 999px !important;
  border: none !important;
  cursor: pointer !important;
  transition: all 0.15s ease !important;
  white-space: nowrap !important;
  min-height: unset !important;
  line-height: 1.3 !important;
}

.name-mode-toggle button.primary {
  background: var(--brand, #0284c7) !important;
  color: #ffffff !important;
  box-shadow: 0 1px 3px rgba(2, 132, 199, 0.25) !important;
}

.name-mode-toggle button.secondary {
  background: transparent !important;
  color: var(--muted, #64748b) !important;
  box-shadow: none !important;
}

.name-mode-toggle button.secondary:hover {
  color: var(--ink, #0f172a) !important;
}

.sort-sbd-label {
  display: inline-flex !important;
  align-items: center !important;
  gap: 4px !important;
  font-size: 0.74rem !important;
  font-weight: 700 !important;
  color: var(--muted, #64748b) !important;
  cursor: pointer !important;
  user-select: none !important;
}

[data-theme="dark"] .name-mode-toggle {
  background: rgba(255, 255, 255, 0.08) !important;
  border-color: rgba(255, 255, 255, 0.15) !important;
}
[data-theme="dark"] .name-mode-toggle button.secondary {
  color: #94a3b8 !important;
}

/* 3. Bảng thống kê Phần II (Đúng / Sai) khoa học & chuyên nghiệp */
.opt-stat-table-wrap {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: 10px;
  border: 1px solid var(--line, #e2e8f0);
  background: var(--card, #ffffff);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.03);
  margin-bottom: 8px;
}

.opt-stat-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
  min-width: 460px;
}

.opt-stat-table th {
  background: var(--bg2, #f8fafc);
  padding: 8px 6px;
  font-weight: 800;
  color: var(--ink, #1e293b);
  border-bottom: 1px solid var(--line, #e2e8f0);
  font-size: 0.76rem;
  white-space: nowrap;
}

.opt-stat-table td {
  padding: 6px 6px;
  border-bottom: 1px dashed var(--line, #e2e8f0);
  vertical-align: middle;
  text-align: center;
}

.opt-stat-table tr:last-child td {
  border-bottom: none;
}

.opt-stat-table .opt-stat-qcol {
  background: var(--bg2, #f8fafc);
  border-right: 1px solid var(--line, #e2e8f0);
  font-weight: 800;
  color: var(--ink, #1e293b);
  width: 58px;
}

.opt-stat-table .opt-stat-subcol {
  border-right: 1px dashed var(--line, #e2e8f0);
  width: 48px;
}

.opt-stat-table .opt-stat-anscol {
  border-right: 1px dashed var(--line, #e2e8f0);
  width: 70px;
}

.opt-stat-table .opt-stat-btncol {
  padding: 4px 6px;
}

.opt-stat-table .opt-stat-btncol .opt-btn {
  width: 100%;
  box-sizing: border-box;
}

[data-theme="dark"] .opt-stat-table-wrap {
  background: var(--card, #1e293b);
  border-color: var(--line, #334155);
}
[data-theme="dark"] .opt-stat-table th {
  background: rgba(255, 255, 255, 0.06);
  color: var(--fg, #f8fafc);
  border-color: var(--line, #334155);
}
[data-theme="dark"] .opt-stat-table td {
  border-color: rgba(255, 255, 255, 0.08);
}
[data-theme="dark"] .opt-stat-table .opt-stat-qcol {
  background: rgba(255, 255, 255, 0.04);
  color: var(--fg, #f8fafc);
  border-color: var(--line, #334155);
}


/* ==========================================================================
   Card câu hỏi Phần II: Đúng / Sai - Khoa học, siêu gọn gàng 1 dòng, không cuộn ngang
   ========================================================================== */
.tf-q-cards-list {
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px;
}
@media (min-width: 768px) {
  .tf-q-cards-list {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
  }
}
.tf-q-card {
  padding: 6px 10px;
  border-radius: 8px;
  background: var(--card, #ffffff);
  border: 1px solid var(--line, #e2e8f0);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03);
  transition: border-color 0.15s ease;
}
.tf-q-card:hover {
  border-color: #93c5fd;
}
.tf-head-keys {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  flex-wrap: wrap;
}
.tf-mini-key {
  font-size: 0.72rem;
  padding: 1px 5px;
  background: var(--bg2, #f1f5f9);
  border-radius: 4px;
  display: inline-flex;
  align-items: center;
  gap: 2px;
}
.tf-sub-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 4px;
}
.tf-sub-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 1px 0;
}
.tf-sub-label {
  display: flex;
  align-items: center;
  width: 22px;
  min-width: 22px;
  flex-shrink: 0;
}
.tf-letter {
  font-size: 0.82rem;
  font-weight: 800;
  color: var(--brand, #0f766e);
}
.tf-sub-btns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 5px;
  flex: 1;
}
.tf-sub-btns .opt-btn {
  display: flex !important;
  flex-direction: row !important;
  justify-content: space-between !important;
  align-items: center !important;
  white-space: nowrap !important;
  padding: 3px 8px !important;
  min-height: 26px !important;
  height: 26px !important;
  border-radius: 6px !important;
  box-sizing: border-box !important;
}
.tf-sub-btns .opt-btn .opt-text {
  display: inline-flex !important;
  align-items: center !important;
  gap: 2px !important;
  font-size: 0.76rem !important;
  white-space: nowrap !important;
}
.tf-sub-btns .opt-btn .opt-count {
  font-size: 0.72rem !important;
  font-weight: 700 !important;
  white-space: nowrap !important;
  line-height: 1 !important;
}
.tf-empty-pill {
  flex-shrink: 0;
  padding: 1px 5px !important;
  font-size: 0.68rem !important;
  white-space: nowrap !important;
}

[data-theme="dark"] .tf-q-card {
  background: var(--card, #1e293b);
  border-color: var(--line, #334155);
}
[data-theme="dark"] .tf-mini-key {
  background: rgba(255, 255, 255, 0.08);
}

@keyframes pwaBounce {
  0% { transform: scale(0.92); }
  100% { transform: scale(1.12); }
}
