:root {
  --sidebar-bg: #0f172a;
  --sidebar-fg: #94a3b8;
  --sidebar-fg-active: #ffffff;
  --sidebar-active-bg: #1e293b;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-soft: #eff6ff;
  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --success: #16a34a;
  --success-bg: #dcfce7;
  --warning: #d97706;
  --warning-bg: #fef3c7;
  --danger: #dc2626;
  --danger-bg: #fee2e2;
  --info-bg: #e0f2fe;
  --info-fg: #0369a1;
  --radius: 10px;
  --radius-sm: 7px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 1px 3px rgba(15, 23, 42, .1);
  --shadow-lg: 0 10px 30px rgba(15, 23, 42, .18);
  font-family: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); min-width: 320px; -webkit-font-smoothing: antialiased; }
[hidden] { display: none !important; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -0.01em; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid transparent; border-radius: var(--radius-sm); cursor: pointer;
  font: inherit; font-weight: 550; padding: 9px 16px; transition: background .15s, border-color .15s, color .15s;
  white-space: nowrap;
}
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-secondary:hover:not(:disabled) { background: var(--surface-2); }
.btn-ghost { background: transparent; color: var(--sidebar-fg); border-color: transparent; }
.btn-ghost:hover { background: var(--sidebar-active-bg); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: #b91c1c; }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-block { width: 100%; }
.btn svg { width: 18px; height: 18px; }

/* ---------- Auth ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px;
  background: radial-gradient(1200px 600px at 20% -10%, #dbeafe, transparent), var(--bg); }
.auth-card { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-lg); padding: 32px; }
.auth-brand { display: flex; align-items: center; gap: 10px; font-size: 20px; font-weight: 700; }
.brand-mark { color: var(--primary); }
.auth-tagline { color: var(--muted); margin: 10px 0 24px; }
.auth-title { margin-bottom: 6px; }
.auth-tabs { display: flex; gap: 4px; background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 4px; margin-bottom: 20px; }
.auth-tab { flex: 1; border: none; background: transparent; padding: 8px; border-radius: 5px;
  cursor: pointer; font: inherit; font-weight: 550; color: var(--muted); }
.auth-tab.is-active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.auth-form { display: flex; flex-direction: column; gap: 14px; }
.center { text-align: center; }

label { display: flex; flex-direction: column; gap: 6px; font-weight: 550; font-size: 13px; color: #334155; }
.hint { color: var(--muted); font-weight: 400; }
input, select, textarea {
  font: inherit; padding: 9px 11px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text); width: 100%;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
textarea { resize: vertical; min-height: 70px; }

/* ---------- Shell ---------- */
.shell { display: grid; grid-template-columns: 244px 1fr; min-height: 100vh; }
.sidebar { background: var(--sidebar-bg); color: var(--sidebar-fg); display: flex; flex-direction: column;
  padding: 18px 12px; position: sticky; top: 0; height: 100vh; }
.sidebar-brand { display: flex; align-items: center; gap: 10px; color: #fff; font-weight: 700; font-size: 17px;
  padding: 6px 10px 18px; }
.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav-item { display: flex; align-items: center; gap: 11px; padding: 10px 12px; border-radius: var(--radius-sm);
  color: var(--sidebar-fg); cursor: pointer; font-weight: 550; border: none; background: transparent;
  width: 100%; text-align: left; font-size: 14px; }
.nav-item:hover { background: var(--sidebar-active-bg); color: #e2e8f0; }
.nav-item.is-active { background: var(--sidebar-active-bg); color: var(--sidebar-fg-active); }
.nav-item.is-active svg { color: var(--primary); }
.nav-item svg { width: 19px; height: 19px; flex: none; }
.sidebar-foot { border-top: 1px solid #1e293b; padding-top: 14px; display: flex; flex-direction: column; gap: 10px; }
.user-chip { display: flex; align-items: center; gap: 9px; padding: 0 4px; }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--primary); color: #fff;
  display: grid; place-items: center; font-weight: 650; font-size: 13px; flex: none; text-transform: uppercase; }
.user-email { color: #cbd5e1; font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.main { display: flex; flex-direction: column; min-width: 0; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 16px 28px; background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10; }
.topbar h1 { font-size: 19px; }
.school-picker { flex-direction: row; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; }
.school-picker select { width: auto; min-width: 180px; }
.view { padding: 24px 28px 48px; }

/* ---------- Cards & sections ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 16px 20px; border-bottom: 1px solid var(--border); }
.card-head h2 { font-size: 15px; }
.card-body { padding: 20px; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; }
.section-head p { color: var(--muted); margin: 4px 0 0; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 20px; }

/* ---------- Stat tiles ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px 20px; box-shadow: var(--shadow); }
.stat-label { color: var(--muted); font-size: 12.5px; font-weight: 550; text-transform: uppercase; letter-spacing: .03em; }
.stat-value { font-size: 30px; font-weight: 700; margin-top: 6px; letter-spacing: -.02em; }
.stat-icon { width: 38px; height: 38px; border-radius: 9px; display: grid; place-items: center; margin-bottom: 12px; }
.stat-icon svg { width: 20px; height: 20px; }
.tint-blue { background: var(--info-bg); color: var(--info-fg); }
.tint-green { background: var(--success-bg); color: var(--success); }
.tint-amber { background: var(--warning-bg); color: var(--warning); }
.tint-red { background: var(--danger-bg); color: var(--danger); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
thead th { text-align: left; padding: 11px 16px; color: var(--muted); font-weight: 600; font-size: 12px;
  text-transform: uppercase; letter-spacing: .03em; background: var(--surface-2); border-bottom: 1px solid var(--border);
  white-space: nowrap; }
tbody td { padding: 13px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface-2); }
.cell-strong { font-weight: 600; }
.cell-muted { color: var(--muted); }

/* ---------- Badges ---------- */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; border-radius: 20px;
  font-size: 12px; font-weight: 600; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-green { background: var(--success-bg); color: #15803d; }
.badge-amber { background: var(--warning-bg); color: #b45309; }
.badge-red { background: var(--danger-bg); color: #b91c1c; }
.badge-gray { background: #f1f5f9; color: #475569; }
.badge-blue { background: var(--info-bg); color: var(--info-fg); }

/* ---------- Empty state ---------- */
.empty { text-align: center; padding: 48px 24px; color: var(--muted); }
.empty svg { width: 40px; height: 40px; margin-bottom: 12px; color: #cbd5e1; }
.empty h3 { color: #334155; margin-bottom: 6px; }

/* ---------- Forms in cards ---------- */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; }
.form-actions { display: flex; gap: 10px; margin-top: 18px; }
.checks { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 10px; }
.checks label { flex-direction: row; align-items: center; gap: 8px; font-weight: 500; }
.checks input { width: auto; }
.full { grid-column: 1 / -1; }

/* ---------- Row actions menu ---------- */
.row-actions { position: relative; display: inline-block; }
.icon-btn { border: 1px solid var(--border); background: var(--surface); border-radius: 6px; width: 32px; height: 32px;
  display: inline-grid; place-items: center; cursor: pointer; color: var(--muted); }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn svg { width: 17px; height: 17px; }
.menu { position: absolute; right: 0; top: 36px; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); box-shadow: var(--shadow-lg); min-width: 170px; padding: 5px; z-index: 30; }
.menu button { display: flex; align-items: center; gap: 9px; width: 100%; text-align: left; border: none;
  background: transparent; padding: 8px 10px; border-radius: 5px; cursor: pointer; font: inherit; color: var(--text); }
.menu button:hover { background: var(--surface-2); }
.menu button.danger { color: var(--danger); }
.menu button svg { width: 16px; height: 16px; }
.menu-sep { height: 1px; background: var(--border); margin: 4px 0; }

/* ---------- Modal ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(15, 23, 42, .5); display: grid; place-items: center;
  z-index: 100; padding: 24px; }
.modal { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow-lg);
  width: 100%; max-width: 460px; max-height: 90vh; overflow: auto; }
.modal-wide { max-width: 900px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 22px;
  border-bottom: 1px solid var(--border); }
.modal-head h2 { font-size: 16px; }
.modal-body { padding: 22px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 16px 22px; border-top: 1px solid var(--border); }
.modal-close { border: none; background: transparent; cursor: pointer; color: var(--muted); font-size: 22px; line-height: 1; }

/* ---------- QR ---------- */
.qr-box { display: flex; flex-direction: column; align-items: center; gap: 14px; }
.qr-frame { padding: 14px; background: #fff; border: 1px solid var(--border); border-radius: var(--radius); width: 300px; height: 300px; }
.qr-frame svg { width: 100%; height: 100%; display: block; }
.qr-meta { text-align: center; color: var(--muted); font-size: 13px; }
.steps { margin: 0; padding-left: 18px; color: #334155; font-size: 13px; line-height: 1.7; }

/* ---------- Callout ---------- */
.callout { background: var(--info-bg); color: var(--info-fg); border-radius: var(--radius-sm); padding: 12px 14px; font-size: 13px; }
.callout-warn { background: var(--warning-bg); color: #92400e; }
.mono { font-family: ui-monospace, "SFMono-Regular", Menlo, monospace; font-size: 12.5px; word-break: break-all; }

/* ---------- Toast ---------- */
.toast { position: fixed; bottom: 24px; right: 24px; z-index: 200; padding: 13px 18px; border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg); color: #fff; font-weight: 550; max-width: 380px; }
.toast-success { background: #15803d; }
.toast-error { background: var(--danger); }

/* ---------- Play iframe ---------- */
#play-iframe { min-height: 640px; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; margin-top: 16px; }
#play-iframe:empty { display: none; }

/* ---------- Responsive ---------- */
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; z-index: 50; width: 244px; height: 100vh; transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: none; }
  .view { padding: 18px; }
  .topbar { padding: 14px 18px; }
}

/* App picker list */
.app-list { max-height: 220px; overflow-y: auto; border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 8px 12px; display: flex; flex-direction: column; gap: 6px; background: var(--surface-2); }
.app-list .app-row { flex-direction: row; align-items: center; gap: 9px; font-weight: 500; }
.app-list input { width: auto; }

/* Copyable value + button (enrolment tokens, server URL) */
.copy-row { display: flex; gap: 8px; align-items: center; }
.copy-row .invite-link { flex: 1; min-width: 0; }
.btn-copy { white-space: nowrap; padding: 8px 12px; }

/* Headings inside long forms (policy editor) */
.section-head { margin-top: 10px; padding: 10px 0 2px; border-top: 1px solid var(--border); color: var(--text); font-size: 13px; }
.form-grid > .section-head:first-child { border-top: 0; margin-top: 0; }

/* ---- Policy editor (tabbed, staff-friendly) ---- */
.policy-top { display: flex; gap: 16px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 14px; }
.policy-top .grow { flex: 1; min-width: 240px; }
.policy-top label { min-width: 260px; }
.ptabs { display: flex; gap: 6px; border-bottom: 1px solid var(--border); margin: 0 0 18px; overflow-x: auto; }
.ptab { border: none; background: transparent; padding: 10px 14px; font: inherit; font-weight: 600; font-size: 13px;
  color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; white-space: nowrap; }
.ptab:hover { color: var(--text); }
.ptab.is-active { color: var(--primary); border-bottom-color: var(--primary); }
.ptab-panel { animation: fade .15s ease; }
.plain { color: var(--text); font-size: 14px; margin: 0 0 14px; line-height: 1.5; }
.app-source { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px 14px; margin-bottom: 12px; background: var(--surface); }
.app-source-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; font-size: 13px; }
.app-source-head .btn { margin-left: auto; }
.app-source .app-row { display: flex; flex-direction: row; align-items: center; gap: 10px; padding: 8px 6px; border-radius: 8px; font-weight: 500; }
.app-source .app-row:hover { background: var(--surface-2); }
.app-source .app-row input { width: auto; }
.app-row-text { display: flex; flex-direction: column; }
.app-row-title { font-weight: 600; }
.app-source .app-list { border: none; padding: 0; max-height: 240px; }
details.advanced { margin: 4px 0 18px; }
details.advanced summary { cursor: pointer; color: var(--muted); font-size: 13px; }
details.advanced textarea { margin-top: 8px; }
.radio-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 10px; }
.radio-card { display: flex; flex-direction: row; gap: 10px; align-items: flex-start; border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 12px; cursor: pointer; font-weight: 400; font-size: 13px; line-height: 1.45; }
.radio-card:has(input:checked) { border-color: var(--primary); background: var(--info-bg); }
.radio-card input { width: auto; margin-top: 3px; }
.opt-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 16px; }
.opt-group { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px 14px; background: var(--surface); }
.opt-group h4 { margin: 0 0 8px; font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.opt { display: flex; flex-direction: row; align-items: flex-start; gap: 10px; padding: 7px 4px; border-radius: 8px; font-weight: 500; font-size: 13px; }
.opt:hover { background: var(--surface-2); }
.opt input { width: auto; margin-top: 3px; }
.opt-text { display: flex; flex-direction: column; gap: 2px; }
.opt-text .hint { font-size: 12px; }
.modal-wide { max-width: 980px; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
