/* Tokens */
:root {
  --bg: #f3f4f6;
  --surface: #ffffff;
  --surface-2: #f9fafb;
  --border: #e5e7eb;
  --border-strong: #d1d5db;
  --text: #0f172a;
  --text-2: #475569;
  --text-3: #94a3b8;
  --accent: #2f6feb;
  --accent-soft: #e6efff;
  --topbar: #2f4358;
  --topbar-text: #ffffff;
  --success: #16a34a;
  --warn: #f59e0b;
  --danger: #dc2626;
  --info: #0ea5e9;
  --radius: 8px;
  --radius-lg: 12px;
  --shadow-sm: 0 1px 2px rgba(15,23,42,.06);
  --shadow: 0 4px 16px rgba(15,23,42,.06);
  --pad: 20px;
  --gap: 16px;
}
[data-theme="dark"] {
  --bg: #0b1220;
  --surface: #111827;
  --surface-2: #0f1626;
  --border: #1f2a3d;
  --border-strong: #2a3650;
  --text: #e6edf7;
  --text-2: #94a3b8;
  --text-3: #64748b;
  --accent: #4d8af5;
  --accent-soft: #1a2a48;
  --topbar: #0e1726;
  --topbar-text: #e6edf7;
  --success: #22c55e;
  --warn: #fbbf24;
  --danger: #f87171;
  --info: #38bdf8;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.4);
  --shadow: 0 4px 16px rgba(0,0,0,.4);
}
[data-density="compact"] {
  --pad: 14px;
  --gap: 10px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); font-family: 'Inter', -apple-system, system-ui, sans-serif; font-size: 14px; line-height: 1.5; }
button { font-family: inherit; cursor: pointer; }
input, textarea, select { font-family: inherit; }
a { color: var(--accent); text-decoration: none; }

/* App shell */
.app { display: grid; grid-template-rows: 56px 1fr; min-height: 100vh; }
.topbar { background: var(--topbar); color: var(--topbar-text); display: flex; align-items: center; padding: 0 20px; gap: 24px; position: sticky; top: 0; z-index: 50; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; letter-spacing: 0.3px; }
.brand-mark { width: 32px; height: 32px; background: var(--accent); border-radius: 6px; display: grid; place-items: center; color: #fff; font-weight: 800; }
.role-pill { font-size: 11px; padding: 3px 8px; border-radius: 4px; background: rgba(255,255,255,.1); text-transform: uppercase; letter-spacing: 1px; font-weight: 600; }
.topnav { display: flex; gap: 4px; margin-left: 8px; flex: 1; }
.topnav a { color: rgba(255,255,255,.7); padding: 8px 12px; border-radius: 6px; font-weight: 500; }
.topnav a.active { color: #fff; background: rgba(255,255,255,.08); }
.topbar-actions { display: flex; align-items: center; gap: 12px; }
.icon-btn { background: transparent; border: 0; color: inherit; width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; cursor: pointer; opacity: .8; }
.icon-btn:hover { background: rgba(255,255,255,.08); opacity: 1; }
.avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--accent); color: #fff; display: grid; place-items: center; font-weight: 700; }

/* Layout with sidebar */
.shell { display: grid; grid-template-columns: 240px 1fr; min-height: calc(100vh - 56px); }
.sidebar { background: var(--surface); border-right: 1px solid var(--border); padding: 18px 12px; overflow-y: auto; }
.sidebar-section { font-size: 10px; text-transform: uppercase; letter-spacing: 1.2px; color: var(--text-3); margin: 18px 8px 6px; font-weight: 700; }
.sidebar-section:first-child { margin-top: 0; }
.nav-item { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 6px; color: var(--text-2); cursor: pointer; font-weight: 500; }
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); }
.nav-item .ico { width: 18px; height: 18px; opacity: .8; }
.nav-sub { padding-left: 28px; }
.nav-sub .nav-item { padding: 6px 10px; font-size: 13px; }

.main { padding: var(--pad) 28px; overflow: auto; }
.page-title { font-size: 26px; font-weight: 700; margin: 0 0 var(--pad); letter-spacing: -.2px; }
.page-sub { color: var(--text-2); margin: -12px 0 var(--pad); }

/* Cards */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: var(--pad); }
.card + .card { margin-top: var(--gap); }
.card-h { font-size: 15px; font-weight: 600; margin: 0 0 12px; display: flex; align-items: center; justify-content: space-between; }
.muted { color: var(--text-2); }
.row { display: flex; gap: var(--gap); align-items: center; }
.col { display: flex; flex-direction: column; gap: var(--gap); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--gap); }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--gap); }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--gap); }

/* Buttons */
.btn { display: inline-flex; align-items: center; gap: 8px; padding: 8px 14px; border-radius: 6px; border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); font-weight: 500; font-size: 13px; cursor: pointer; transition: all .12s; }
.btn:hover { background: var(--surface-2); }
.btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-primary:hover { filter: brightness(1.05); background: var(--accent); }
.btn-danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-ghost { border: 0; background: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-icon { width: 32px; padding: 0; justify-content: center; }

/* Inputs */
.input, .textarea, .select { width: 100%; padding: 8px 12px; border-radius: 6px; border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); font-size: 13px; transition: border-color .12s; }
.input:focus, .textarea:focus, .select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.textarea { min-height: 96px; resize: vertical; line-height: 1.55; }
.label { font-size: 12px; font-weight: 600; color: var(--text-2); margin-bottom: 6px; display: block; text-transform: uppercase; letter-spacing: .5px; }
.field { margin-bottom: 14px; }

/* Table */
.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: 1px; color: var(--text-3); font-weight: 600; padding: 10px 12px; border-bottom: 1px solid var(--border); }
.tbl td { padding: 12px; border-bottom: 1px solid var(--border); }
.tbl tr:last-child td { border-bottom: 0; }
.tbl tr:hover td { background: var(--surface-2); }

/* Badge */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border); }
.badge-success { background: color-mix(in oklch, var(--success) 15%, transparent); color: var(--success); border-color: transparent; }
.badge-warn { background: color-mix(in oklch, var(--warn) 18%, transparent); color: var(--warn); border-color: transparent; }
.badge-danger { background: color-mix(in oklch, var(--danger) 15%, transparent); color: var(--danger); border-color: transparent; }
.badge-info { background: color-mix(in oklch, var(--info) 15%, transparent); color: var(--info); border-color: transparent; }
.badge-accent { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

/* Stat */
.stat { display: flex; flex-direction: column; gap: 6px; }
.stat-v { font-size: 28px; font-weight: 700; letter-spacing: -.5px; }
.stat-l { font-size: 12px; color: var(--text-2); text-transform: uppercase; letter-spacing: 1px; font-weight: 600; }
.stat-d { font-size: 12px; color: var(--text-2); display: flex; align-items: center; gap: 4px; }

/* Sparkline / bars */
.bar-track { width: 100%; height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; }
.bar-fill { height: 100%; background: var(--accent); border-radius: 3px; }

/* Avatar small */
.av { width: 28px; height: 28px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: inline-grid; place-items: center; font-weight: 700; font-size: 11px; }

/* Cam grid for proctor */
.cam-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.cam { background: #0f1626; border-radius: 8px; aspect-ratio: 4/3; position: relative; overflow: hidden; border: 1px solid var(--border); }
.cam.flagged { border: 2px solid var(--danger); }
.cam-overlay { position: absolute; inset: 0; padding: 8px; display: flex; flex-direction: column; justify-content: space-between; color: #fff; font-size: 11px; }
.cam-name { background: rgba(0,0,0,.55); padding: 2px 6px; border-radius: 4px; align-self: flex-start; }
.cam-status { display: flex; gap: 4px; }
.cam-fake-bg { position: absolute; inset: 0; background:
  radial-gradient(ellipse at 30% 35%, #2a3a55 0%, transparent 45%),
  radial-gradient(ellipse at 70% 60%, #1c2638 0%, transparent 55%),
  linear-gradient(135deg, #0f1626, #1a2438);
}
.cam-face { position: absolute; left: 50%; top: 38%; transform: translate(-50%, -50%); width: 38%; aspect-ratio: 1; background: linear-gradient(160deg, #d4a988, #b8896a); border-radius: 50%; opacity: .85; }
.cam-shoulder { position: absolute; left: 50%; bottom: 0; transform: translateX(-50%); width: 75%; height: 30%; background: linear-gradient(180deg, #4a5568, #2d3748); border-radius: 50% 50% 0 0; }

/* Question editor */
.q-card { border: 1px solid var(--border); border-radius: 8px; padding: 14px; background: var(--surface); }
.q-card + .q-card { margin-top: 10px; }
.q-num { font-size: 11px; color: var(--text-3); text-transform: uppercase; letter-spacing: 1px; font-weight: 600; }

/* Exam taking */
.exam-shell { background: var(--bg); min-height: 100vh; }
.exam-bar { background: var(--surface); border-bottom: 1px solid var(--border); padding: 12px 24px; display: flex; align-items: center; gap: 20px; position: sticky; top: 0; z-index: 30; }
.timer { font-family: 'JetBrains Mono', ui-monospace, monospace; font-size: 22px; font-weight: 700; padding: 8px 14px; border-radius: 8px; background: var(--surface-2); border: 1px solid var(--border); letter-spacing: 1px; }
.timer.warn { background: color-mix(in oklch, var(--warn) 18%, transparent); color: var(--warn); border-color: transparent; }
.timer.danger { background: color-mix(in oklch, var(--danger) 18%, transparent); color: var(--danger); border-color: transparent; animation: pulse 1.4s infinite; }
@keyframes pulse { 0%,100%{opacity:1;} 50%{opacity:.6;} }

.exam-grid { display: grid; grid-template-columns: 220px 1fr 280px; gap: var(--gap); padding: var(--gap); align-items: start; }
.q-nav { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 12px; position: sticky; top: 76px; }
.q-nav-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; margin-top: 10px; }
.q-pill { aspect-ratio: 1; border-radius: 6px; border: 1px solid var(--border-strong); background: var(--surface); font-weight: 600; font-size: 12px; cursor: pointer; }
.q-pill.cur { border-color: var(--accent); background: var(--accent); color: #fff; }
.q-pill.ans { background: color-mix(in oklch, var(--success) 18%, transparent); color: var(--success); border-color: transparent; }
.q-pill.flag { background: color-mix(in oklch, var(--warn) 18%, transparent); color: var(--warn); border-color: transparent; }

.exam-q { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 28px 32px; min-height: 60vh; }
.exam-q h2 { font-size: 18px; margin: 0 0 8px; font-weight: 600; }
.exam-q .q-text { font-size: 16px; line-height: 1.65; margin: 14px 0 22px; }
.option { display: flex; gap: 12px; padding: 12px 14px; border: 1px solid var(--border-strong); border-radius: 8px; cursor: pointer; margin-bottom: 8px; }
.option:hover { background: var(--surface-2); }
.option.sel { border-color: var(--accent); background: var(--accent-soft); }
.option .radio { width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--border-strong); flex-shrink: 0; margin-top: 2px; }
.option.sel .radio { border-color: var(--accent); background: radial-gradient(circle, var(--accent) 40%, transparent 50%); }

.exam-aside { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 12px; position: sticky; top: 76px; max-height: calc(100vh - 90px); display: flex; flex-direction: column; }

/* Chat */
.chat { display: flex; flex-direction: column; gap: 8px; padding: 8px 4px; max-height: 240px; overflow-y: auto; flex: 1; }
.msg { padding: 8px 10px; border-radius: 8px; font-size: 12px; max-width: 85%; }
.msg.them { background: var(--surface-2); align-self: flex-start; }
.msg.me { background: var(--accent); color: #fff; align-self: flex-end; }
.msg .who { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 1px; opacity: .7; margin-bottom: 2px; }

/* Drag-drop schedule */
.cal { display: grid; grid-template-columns: 80px repeat(5, 1fr); gap: 4px; }
.cal-h { font-size: 11px; color: var(--text-3); text-transform: uppercase; font-weight: 600; padding: 6px; }
.cal-slot { background: var(--surface-2); border: 1px dashed var(--border); border-radius: 6px; min-height: 60px; padding: 4px; }
.cal-slot.over { border-color: var(--accent); background: var(--accent-soft); }
.cal-event { background: var(--accent); color: #fff; padding: 6px 8px; border-radius: 4px; font-size: 11px; cursor: grab; margin-bottom: 4px; }
.cal-event.draft { background: var(--warn); }
.cal-event.ready { background: var(--success); }

/* Charts */
.chart { display: flex; align-items: flex-end; gap: 6px; height: 120px; }
.bar { flex: 1; background: var(--accent); border-radius: 4px 4px 0 0; min-width: 6px; position: relative; }
.bar:hover::after { content: attr(data-v); position: absolute; bottom: 100%; left: 50%; transform: translateX(-50%); font-size: 11px; background: var(--text); color: var(--bg); padding: 2px 6px; border-radius: 4px; margin-bottom: 4px; white-space: nowrap; }

/* Switcher (role) */
.role-switch { display: flex; gap: 0; border: 1px solid rgba(255,255,255,.15); border-radius: 8px; padding: 3px; background: rgba(0,0,0,.2); }
.role-switch button { background: transparent; border: 0; color: rgba(255,255,255,.7); padding: 5px 12px; border-radius: 5px; font-size: 12px; font-weight: 600; cursor: pointer; }
.role-switch button.active { background: rgba(255,255,255,.15); color: #fff; }

/* Anti-cheat banner */
.ac-banner { padding: 8px 14px; border-radius: 6px; background: color-mix(in oklch, var(--info) 12%, transparent); border: 1px solid color-mix(in oklch, var(--info) 30%, transparent); color: var(--info); font-size: 12px; display: flex; align-items: center; gap: 8px; }
.focus-lost-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.85); color: #fff; display: grid; place-items: center; z-index: 100; padding: 40px; text-align: center; }

/* Doc preview (file upload) */
.doc-preview { border: 2px dashed var(--border-strong); border-radius: 8px; padding: 20px; text-align: center; color: var(--text-2); }
.doc-preview.has-file { border-style: solid; border-color: var(--success); background: color-mix(in oklch, var(--success) 6%, transparent); }

/* Misc */
.divider { height: 1px; background: var(--border); margin: 12px 0; }
.kbd { font-family: ui-monospace, monospace; font-size: 11px; padding: 1px 5px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 3px; }
.spacer { flex: 1; }
.tag { display: inline-block; padding: 2px 8px; border-radius: 4px; background: var(--surface-2); font-size: 11px; color: var(--text-2); border: 1px solid var(--border); }
.scroll-pane { overflow-y: auto; max-height: calc(100vh - 200px); }

/* Density compact tweaks */
[data-density="compact"] .card { padding: 14px; }
[data-density="compact"] .tbl td { padding: 8px 10px; }
[data-density="compact"] .page-title { font-size: 22px; margin-bottom: 14px; }
[data-density="compact"] .stat-v { font-size: 22px; }

/* Notifications */
.topbar-burger { display: none; }
.show-md { display: none; }
.notif-badge { position: absolute; top: 4px; right: 4px; background: var(--danger); color: #fff; font-size: 10px; font-weight: 700; min-width: 16px; height: 16px; border-radius: 8px; padding: 0 4px; display: grid; place-items: center; }
.overlay-bg { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 90; animation: fadeIn .15s; }
@keyframes fadeIn { from { opacity: 0 } to { opacity: 1 } }
.notif-panel { position: fixed; top: 56px; right: 12px; width: 380px; max-width: calc(100vw - 24px); max-height: calc(100vh - 80px); background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow); z-index: 95; display: flex; flex-direction: column; animation: slideDown .2s; }
@keyframes slideDown { from { transform: translateY(-8px); opacity: 0 } to { transform: none; opacity: 1 } }
.notif-list { flex: 1; overflow-y: auto; }
.notif-item { display: flex; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--border); cursor: pointer; }
.notif-item:hover { background: var(--surface-2); }
.notif-item.unread { background: color-mix(in oklch, var(--accent-soft) 50%, var(--surface)); }
.notif-ic { width: 32px; height: 32px; border-radius: 8px; display: grid; place-items: center; flex-shrink: 0; }
.notif-ic-success { background: color-mix(in oklch, var(--success) 18%, transparent); color: var(--success); }
.notif-ic-warn { background: color-mix(in oklch, var(--warn) 18%, transparent); color: var(--warn); }
.notif-ic-danger { background: color-mix(in oklch, var(--danger) 18%, transparent); color: var(--danger); }
.notif-ic-info { background: color-mix(in oklch, var(--info) 18%, transparent); color: var(--info); }
.notif-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); align-self: center; flex-shrink: 0; }

/* Modals */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: grid; place-items: center; z-index: 100; padding: 24px; animation: fadeIn .15s; }
.modal { background: var(--surface); border-radius: 12px; width: 760px; max-width: 100%; max-height: calc(100vh - 48px); display: flex; flex-direction: column; box-shadow: var(--shadow); animation: slideUp .2s; }
.modal-wide { width: 880px; }
@keyframes slideUp { from { transform: translateY(20px); opacity: 0 } to { transform: none; opacity: 1 } }
.modal-body { padding: 20px; overflow-y: auto; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 14px; }
.tab { background: transparent; border: 0; padding: 10px 14px; font-size: 13px; color: var(--text-2); cursor: pointer; border-bottom: 2px solid transparent; font-weight: 500; }
.tab.active { color: var(--accent); border-color: var(--accent); }
.settings-grid { display: grid; grid-template-columns: 220px 1fr; min-height: 500px; max-height: calc(100vh - 130px); }
.settings-nav { padding: 14px; border-right: 1px solid var(--border); overflow-y: auto; }
.settings-body { padding: 24px; overflow-y: auto; }

/* Mobile / tablet adapt */
@media (max-width: 1024px) {
  .hide-md { display: none !important; }
  .show-md { display: inline-flex; }
  .topbar-burger { display: grid; }
  .topbar { padding: 0 12px; gap: 12px; }
  .brand-name { display: none; }
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; top: 56px; left: 0; bottom: 0; width: 260px; transform: translateX(-100%); transition: transform .2s; z-index: 95; }
  .sidebar.open { transform: none; box-shadow: var(--shadow); }
  .sidebar-bg { top: 56px; }
  .main { padding: 16px; }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .rules-grid { grid-template-columns: 1fr !important; }
  .rules-toc { position: static !important; }
  .exam-grid { grid-template-columns: 1fr; }
  .q-nav, .exam-aside { position: static; }
  .cam-grid { grid-template-columns: repeat(2, 1fr); }
  .settings-grid { grid-template-columns: 1fr; min-height: auto; }
  .settings-nav { border-right: 0; border-bottom: 1px solid var(--border); display: flex; gap: 4px; overflow-x: auto; padding: 8px; }
  .settings-nav .nav-item { white-space: nowrap; }
  .role-pill, .role-switch { display: none !important; }
  .topnav { display: none !important; }
  .page-title { font-size: 20px; }
  .modal { max-height: calc(100vh - 24px); border-radius: 12px 12px 0 0; align-self: flex-end; }
  .modal-overlay { padding: 0; align-items: end; }
}
@media (max-width: 640px) {
  .topbar { gap: 8px; }
  .main { padding: 12px; }
  .card { padding: 14px; }
  .cam-grid { grid-template-columns: 1fr; }
  .stat-v { font-size: 22px; }
  .notif-panel { right: 0; left: 0; top: 56px; width: auto; max-width: none; border-radius: 0 0 12px 12px; }
  .tbl { font-size: 12px; }
  .tbl th, .tbl td { padding: 8px 6px; }
}
