/* ---------- Fonts (self-hosted, works offline in Docker) ---------- */
@font-face { font-family: 'IBM Plex Sans Thai'; font-weight: 400; font-display: swap; src: url('/static/fonts/ibm-plex-sans-thai-thai-400-normal.woff2') format('woff2'); unicode-range: U+0E01-0E5B, U+200C-200D, U+25CC; }
@font-face { font-family: 'IBM Plex Sans Thai'; font-weight: 400; font-display: swap; src: url('/static/fonts/ibm-plex-sans-thai-latin-400-normal.woff2') format('woff2'); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: 'IBM Plex Sans Thai'; font-weight: 600; font-display: swap; src: url('/static/fonts/ibm-plex-sans-thai-thai-600-normal.woff2') format('woff2'); unicode-range: U+0E01-0E5B, U+200C-200D, U+25CC; }
@font-face { font-family: 'IBM Plex Sans Thai'; font-weight: 600; font-display: swap; src: url('/static/fonts/ibm-plex-sans-thai-latin-600-normal.woff2') format('woff2'); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }

/* ---------- Tokens ---------- */
:root {
  color-scheme: light;
  --bg: #f4f6fb;
  --bg-grad: radial-gradient(1200px 600px at 100% -10%, #dfe8ff 0%, transparent 60%), radial-gradient(900px 500px at -10% 110%, #e0f5ef 0%, transparent 55%);
  --surface: #ffffff;
  --surface-2: #f7f8fc;
  --border: #e3e7f0;
  --text: #182033;
  --muted: #5d6680;
  --primary: #3b5bdb;
  --primary-2: #5c7cfa;
  --primary-soft: #e8edff;
  --on-primary: #ffffff;
  --success: #2b8a3e; --success-soft: #e6f6ea;
  --warning: #b35c00; --warning-soft: #fff1df;
  --danger: #c92a2a; --danger-soft: #ffe8e8;
  --info: #1971c2; --info-soft: #e3f0fd;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 4px 16px rgba(16, 24, 40, .06);
  --shadow-lg: 0 12px 40px rgba(16, 24, 40, .14);
  --radius: 14px;
  --radius-sm: 10px;
  --sidebar: 260px;
  --focus: 0 0 0 3px rgba(59, 91, 219, .35);
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0d1220;
  --bg-grad: radial-gradient(1200px 600px at 100% -10%, #1b2550 0%, transparent 60%), radial-gradient(900px 500px at -10% 110%, #0f3030 0%, transparent 55%);
  --surface: #151c2e;
  --surface-2: #1b2338;
  --border: #283250;
  --text: #e6e9f2;
  --muted: #98a2bd;
  --primary: #7c93ff;
  --primary-2: #99aaff;
  --primary-soft: #232e55;
  --on-primary: #0d1220;
  --success: #69db7c; --success-soft: #16301e;
  --warning: #ffb05c; --warning-soft: #3a2a14;
  --danger: #ff8787; --danger-soft: #3a1b1f;
  --info: #74c0fc; --info-soft: #14283d;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 4px 16px rgba(0, 0, 0, .25);
  --shadow-lg: 0 12px 40px rgba(0, 0, 0, .5);
  --focus: 0 0 0 3px rgba(124, 147, 255, .45);
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  overflow-wrap: break-word;
  margin: 0; min-height: 100vh;
  font-family: 'IBM Plex Sans Thai', 'Noto Sans Thai', 'Sarabun', system-ui, -apple-system, 'Segoe UI', sans-serif;
  font-size: 15.5px; line-height: 1.65;
  color: var(--text); background: var(--bg); background-image: var(--bg-grad); background-attachment: fixed;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.3; margin: 0 0 .4em; font-weight: 600; }
h1 { font-size: clamp(1.35rem, 2.6vw, 1.75rem); }
h2 { font-size: 1.2rem; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 .8em; }
small, .muted { color: var(--muted); }
code { font-size: .85em; background: var(--surface-2); padding: .1em .35em; border-radius: 6px; word-break: break-all; }
hr { border: 0; border-top: 1px solid var(--border); margin: 1.2rem 0; }
:focus-visible { outline: none; box-shadow: var(--focus); border-radius: 8px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Theme changes fade colors when View Transitions are unavailable. */
body.theme-fade, body.theme-fade * { transition: background-color .45s ease, color .45s ease, border-color .45s ease, box-shadow .45s ease !important; }

/* ---------- Layout ---------- */
.shell { display: grid; grid-template-columns: var(--sidebar) 1fr; min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(12px); border-right: 1px solid var(--border);
  padding: 20px 14px; display: flex; flex-direction: column; gap: 6px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 16px; font-weight: 600; color: var(--text); }
.brand:hover { text-decoration: none; }
.brand-logo { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; color: #fff; background: linear-gradient(135deg, var(--primary), #20c997); box-shadow: var(--shadow); flex: none; }
.brand small { display: block; font-weight: 400; font-size: .75rem; }
.nav-label { font-size: .72rem; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); padding: 14px 12px 4px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 10px; color: var(--text); font-size: .95rem; }
.nav a svg { width: 19px; height: 19px; flex: none; opacity: .8; }
.nav a:hover { background: var(--surface-2); text-decoration: none; }
.nav a.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.nav a.active svg { opacity: 1; }
.sidebar-foot { margin-top: auto; border-top: 1px solid var(--border); padding-top: 12px; }
.me { display: flex; align-items: center; gap: 10px; padding: 6px 8px; }
.avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--primary-soft); color: var(--primary); display: grid; place-items: center; font-weight: 600; flex: none; }
.me-name { font-weight: 600; font-size: .92rem; line-height: 1.3; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 150px; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 28px; position: sticky; top: 0; z-index: 20; background: color-mix(in srgb, var(--bg) 80%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid transparent; }
.topbar .crumbs { color: var(--muted); font-size: .9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.content { padding: 8px 28px 48px; width: 100%; max-width: 1200px; }
.menu-btn { display: none; }
.scrim { display: none; }

.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px; margin: 8px 0 20px; }
.page-head p { margin: 0; color: var(--muted); }
.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

/* ---------- Components ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; }
.card + .card { margin-top: 16px; }
.grid > .card + .card, .form-cards > .card + .card { margin-top: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.grid { display: grid; gap: 16px; }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.stat { display: flex; gap: 14px; align-items: center; }
.stat-icon { width: 46px; height: 46px; border-radius: 12px; display: grid; place-items: center; flex: none; }
.stat-icon svg { width: 22px; height: 22px; }
.stat b { font-size: 1.6rem; line-height: 1.1; display: block; }
.stat span { color: var(--muted); font-size: .88rem; }
.tint-primary { background: var(--primary-soft); color: var(--primary); }
.tint-success { background: var(--success-soft); color: var(--success); }
.tint-warning { background: var(--warning-soft); color: var(--warning); }
.tint-info { background: var(--info-soft); color: var(--info); }

.btn {
  --b: var(--surface); --c: var(--text); --bd: var(--border);
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 9px 16px; border-radius: 10px; border: 1px solid var(--bd); background: var(--b); color: var(--c);
  font: inherit; font-size: .93rem; font-weight: 500; cursor: pointer; white-space: nowrap; text-decoration: none !important;
  transition: transform .12s ease, box-shadow .2s ease, background-color .2s ease;
}
.btn:hover { box-shadow: var(--shadow); }
.btn:active { transform: translateY(1px) scale(.99); }
.btn svg { width: 18px; height: 18px; }
.btn-primary { --b: linear-gradient(135deg, var(--primary), var(--primary-2)); --c: var(--on-primary); --bd: transparent; background: linear-gradient(135deg, var(--primary), var(--primary-2)); }
.btn-success { --b: var(--success); --c: #fff; --bd: transparent; }
:root[data-theme="dark"] .btn-success { --c: #0d1220; }
.btn-danger { --b: var(--danger-soft); --c: var(--danger); --bd: transparent; }
.btn-ghost { --b: transparent; --bd: transparent; }
.btn-sm { padding: 6px 11px; font-size: .85rem; border-radius: 8px; }
.btn-block { width: 100%; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.icon-btn { width: 40px; height: 40px; padding: 0; border-radius: 12px; }

.badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 10px; border-radius: 999px; font-size: .78rem; font-weight: 600; white-space: nowrap; background: var(--surface-2); color: var(--muted); }
.badge-draft { background: var(--warning-soft); color: var(--warning); }
.badge-published, .badge-submitted { background: var(--success-soft); color: var(--success); }
.badge-closed { background: var(--surface-2); color: var(--muted); }
.badge-admin { background: var(--danger-soft); color: var(--danger); }
.badge-staff { background: var(--info-soft); color: var(--info); }
.badge-auditor { background: var(--warning-soft); color: var(--warning); }
.badge-user { background: var(--primary-soft); color: var(--primary); }
.badge-ai { background: linear-gradient(135deg, #e5dbff, #d0ebff); color: #5f3dc4; }
:root[data-theme="dark"] .badge-ai { background: linear-gradient(135deg, #2b2150, #13304a); color: #c5b3ff; }

.alert { padding: 12px 16px; border-radius: var(--radius-sm); margin-bottom: 16px; display: flex; gap: 10px; align-items: flex-start; border: 1px solid transparent; animation: slideIn .35s ease; }
.alert > svg { width: 20px; height: 20px; flex: none; margin-top: 2px; }
.badge svg { width: 13px; height: 13px; }
.alert-success { background: var(--success-soft); color: var(--success); }
.alert-error { background: var(--danger-soft); color: var(--danger); }
.alert-info { background: var(--info-soft); color: var(--info); }
@keyframes slideIn { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }

/* Forms */
label { font-weight: 500; font-size: .92rem; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field-row { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
input[type=text], input[type=password], input[type=email], input[type=url], input[type=number], input[type=date], input[type=search], select, textarea {
  width: 100%; font: inherit; color: var(--text); background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 10px; padding: 9px 12px; transition: border-color .15s, box-shadow .15s, background-color .15s;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: var(--focus); background: var(--surface); }
textarea { min-height: 84px; resize: vertical; }
input[type=file] { font: inherit; font-size: .88rem; max-width: 100%; color: var(--muted); }
input[type=file]::file-selector-button { font: inherit; border: 1px solid var(--border); background: var(--surface); color: var(--text); padding: 6px 12px; border-radius: 8px; margin-right: 10px; cursor: pointer; }
.check { display: inline-flex; align-items: center; gap: 8px; font-weight: 400; cursor: pointer; }
input[type=checkbox], input[type=radio] { accent-color: var(--primary); width: 18px; height: 18px; }

.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 16px; }
.toolbar input, .toolbar select { width: auto; flex: 1 1 180px; }

/* Tables -> cards on small screens */
.table-wrap { overflow-x: auto; }
table.table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.table th, .table td { padding: 11px 12px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
.table th { font-weight: 600; color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; background: var(--surface-2); }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr { transition: background-color .15s; }
.table tbody tr:hover { background: var(--surface-2); }
.nowrap { white-space: nowrap; }

.empty { text-align: center; padding: 40px 16px; color: var(--muted); }
.empty svg { width: 46px; height: 46px; opacity: .5; margin-bottom: 8px; }

/* Form list cards */
.form-cards { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); }
.form-card { display: flex; flex-direction: column; gap: 10px; transition: transform .18s ease, box-shadow .18s ease; }
.form-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.form-card h3 { margin: 0; }
.form-card h3 a { color: var(--text); }
.form-card .desc { color: var(--muted); font-size: .9rem; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.form-card .meta { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: .82rem; color: var(--muted); }
.form-card .foot { margin-top: auto; display: flex; flex-wrap: wrap; gap: 6px; padding-top: 10px; border-top: 1px dashed var(--border); }

/* Questionnaire */
.q-section { margin-top: 20px; }
.q-section > h2 { display: flex; gap: 10px; align-items: center; padding: 12px 16px; border-radius: var(--radius-sm); background: var(--primary-soft); color: var(--primary); font-size: 1.05rem; }
.question { padding: 18px 20px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); margin-top: 12px; transition: border-color .2s, box-shadow .2s; }
.question:focus-within { border-color: var(--primary); box-shadow: var(--focus); }
.q-head { display: flex; gap: 12px; align-items: flex-start; }
.q-code { flex: none; min-width: 38px; height: 28px; padding: 0 8px; border-radius: 8px; background: var(--surface-2); color: var(--muted); display: grid; place-items: center; font-weight: 600; font-size: .85rem; }
.q-text { flex: 1; min-width: 0; font-weight: 500; overflow-wrap: anywhere; }
.q-text .req { color: var(--danger); margin-left: 2px; }
.q-ref { font-size: .8rem; }
.options { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0 4px; }
.option { position: relative; }
.option input { position: absolute; opacity: 0; pointer-events: none; }
.option span { display: inline-flex; align-items: center; gap: 6px; padding: 7px 16px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface-2); cursor: pointer; font-size: .92rem; transition: all .15s ease; user-select: none; }
.option span::before { content: ''; width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--muted); transition: all .15s ease; }
.option input[type=checkbox] + span::before { border-radius: 4px; }
.option input:checked + span { background: var(--primary-soft); border-color: var(--primary); color: var(--primary); font-weight: 600; }
.option input:checked + span::before { border-color: var(--primary); background: var(--primary); box-shadow: inset 0 0 0 2px var(--surface); }
.option input:focus-visible + span { box-shadow: var(--focus); }
.option input:disabled + span { cursor: default; }
.q-extra { display: grid; gap: 10px; margin-top: 12px; }
details.evidence { border: 1px dashed var(--border); border-radius: var(--radius-sm); padding: 10px 14px; background: var(--surface-2); }
details.evidence summary { cursor: pointer; font-size: .9rem; color: var(--primary); font-weight: 500; list-style: none; display: flex; align-items: center; gap: 6px; }
details.evidence summary::-webkit-details-marker { display: none; }
details.evidence[open] summary { margin-bottom: 10px; }
.ev-list { display: flex; flex-wrap: wrap; gap: 8px; margin: 6px 0; }
.ev-item { display: inline-flex; align-items: center; gap: 8px; padding: 6px 10px; border-radius: 10px; background: var(--surface); border: 1px solid var(--border); font-size: .85rem; max-width: 100%; }
.ev-item a { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 240px; }
.ev-item img { width: 44px; height: 44px; object-fit: cover; border-radius: 6px; }
.ev-item svg { width: 16px; height: 16px; flex: none; }
.ev-remove { font-size: .78rem; color: var(--danger); }
.answer { margin-top: 8px; padding: 8px 12px; border-radius: 10px; background: var(--surface-2); }
.sticky-actions { position: sticky; bottom: 12px; z-index: 10; margin-top: 20px; display: flex; flex-wrap: wrap; gap: 10px; justify-content: flex-end; padding: 12px; border-radius: var(--radius); background: color-mix(in srgb, var(--surface) 85%, transparent); backdrop-filter: blur(10px); border: 1px solid var(--border); box-shadow: var(--shadow-lg); }
.progress { height: 6px; border-radius: 99px; background: var(--surface-2); overflow: hidden; flex: 1 1 160px; align-self: center; }
.progress > i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--primary), #20c997); transition: width .3s ease; }
.score-ring { display: flex; align-items: center; gap: 16px; }
.score-ring b { font-size: 2rem; }

/* Builder */
.builder-section { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); margin-top: 16px; overflow: hidden; }
.builder-section > header { display: flex; gap: 8px; align-items: center; padding: 12px 14px; background: var(--surface-2); border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.builder-section > header input { flex: 1 1 220px; font-weight: 600; }
.builder-section .s-body { padding: 14px; }
.bq { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px; margin-bottom: 12px; background: var(--surface); animation: slideIn .25s ease; }
.bq-top { display: grid; grid-template-columns: 80px 1fr 170px; gap: 8px; }
.bq-opts { margin-top: 10px; display: grid; gap: 6px; }
.bq-opt { display: grid; grid-template-columns: 1fr 90px 36px; gap: 6px; }
.bq-flags { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 10px; align-items: center; font-size: .88rem; }
.bq-flags input[type=text] { width: auto; flex: 1 1 160px; }
.bq-tools { margin-left: auto; display: flex; gap: 4px; }

/* Dropzone */
.dropzone { border: 2px dashed var(--border); border-radius: var(--radius); padding: 36px 20px; text-align: center; background: var(--surface-2); transition: border-color .2s, background-color .2s, transform .2s; cursor: pointer; }
.dropzone.drag { border-color: var(--primary); background: var(--primary-soft); transform: scale(1.01); }
.dropzone svg { width: 48px; height: 48px; color: var(--primary); }
.dropzone input { display: none; }
.spinner { width: 18px; height: 18px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading-overlay { position: fixed; inset: 0; background: color-mix(in srgb, var(--bg) 70%, transparent); backdrop-filter: blur(6px); display: none; place-items: center; z-index: 100; }
.loading-overlay.show { display: grid; }
.loading-card { text-align: center; padding: 28px 32px; }
.ai-orb { width: 64px; height: 64px; margin: 0 auto 14px; border-radius: 50%; background: conic-gradient(from 0deg, #845ef7, #339af0, #20c997, #845ef7); animation: spin 1.6s linear infinite; mask: radial-gradient(circle, transparent 52%, #000 54%); -webkit-mask: radial-gradient(circle, transparent 52%, #000 54%); }

/* Timeline */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { display: flex; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--border); font-size: .9rem; }
.timeline li:last-child { border-bottom: 0; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--primary); margin-top: 8px; flex: none; }

/* Login */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.auth-card { width: 100%; max-width: 420px; padding: 32px 28px; }
.auth-card .brand { justify-content: center; padding-bottom: 6px; }
.btn-thaid { --b: #1f3d8a; --c: #fff; --bd: transparent; padding: 12px 16px; font-size: 1rem; }
:root[data-theme="dark"] .btn-thaid { --b: #2d54c0; }
.divider { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: .85rem; margin: 18px 0; }
.divider::before, .divider::after { content: ''; flex: 1; height: 1px; background: var(--border); }
.auth-corner { position: fixed; top: 16px; right: 16px; }

/* Pagination */
.pager { display: flex; gap: 6px; justify-content: center; margin-top: 16px; flex-wrap: wrap; }

/* ---------- Theme toggle (sun <-> moon morph) ---------- */
.theme-toggle { position: relative; overflow: hidden; }
.theme-toggle svg { width: 22px; height: 22px; transition: transform .6s cubic-bezier(.68, -0.55, .27, 1.55); }
.theme-toggle .sun-core { transition: r .5s ease, fill .4s ease; transform-origin: center; }
.theme-toggle .rays { transform-origin: 12px 12px; transition: transform .6s cubic-bezier(.68, -0.55, .27, 1.55), opacity .35s ease; }
.theme-toggle .moon-mask { transition: cx .55s ease, cy .55s ease; }
:root[data-theme="dark"] .theme-toggle svg { transform: rotate(-40deg); }
:root[data-theme="dark"] .theme-toggle .rays { transform: rotate(90deg) scale(0); opacity: 0; }
:root[data-theme="dark"] .theme-toggle .sun-core { r: 9; }
:root[data-theme="dark"] .theme-toggle .moon-mask { cx: 16; cy: 7; }
.theme-toggle::after { content: ''; position: absolute; inset: 0; border-radius: inherit; background: radial-gradient(circle, var(--primary-soft) 0%, transparent 70%); opacity: 0; transform: scale(.2); transition: opacity .5s, transform .5s; }
.theme-toggle.pop::after { opacity: 1; transform: scale(1.6); transition: 0s; }
/* Stars that twinkle when switching to dark */
.theme-toggle .star { opacity: 0; transform: scale(0); transform-origin: center; transform-box: fill-box; transition: opacity .3s ease .25s, transform .4s ease .25s; }
:root[data-theme="dark"] .theme-toggle .star { opacity: 1; transform: scale(1); }

::view-transition-old(root), ::view-transition-new(root) { animation: none; mix-blend-mode: normal; }
::view-transition-new(root) { z-index: 2; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* ---------- Responsive ---------- */
@media (max-width: 1100px) { .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 960px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; z-index: 50; left: 0; top: 0; width: min(84vw, 300px); transform: translateX(-105%); transition: transform .3s cubic-bezier(.2, .8, .2, 1); box-shadow: var(--shadow-lg); background: var(--surface); }
  body.nav-open .sidebar { transform: none; }
  .scrim { display: block; position: fixed; inset: 0; z-index: 40; background: rgba(0, 0, 0, .35); opacity: 0; pointer-events: none; transition: opacity .3s; }
  body.nav-open .scrim { opacity: 1; pointer-events: auto; }
  .menu-btn { display: inline-flex; }
  .topbar { padding: 10px 16px; }
  .content { padding: 4px 16px 40px; }
  .grid-2 { grid-template-columns: 1fr; }
}
@media (max-width: 720px) {
  body { font-size: 15px; }
  .grid-4 { grid-template-columns: 1fr 1fr; gap: 10px; }
  .card { padding: 16px; }
  .stat { flex-direction: column; align-items: flex-start; gap: 8px; }
  .question { padding: 14px; }
  .bq-top { grid-template-columns: 70px 1fr; }
  .bq-top select { grid-column: 1 / -1; }
  .bq-opt { grid-template-columns: 1fr 70px 36px; }
  .table.responsive thead { display: none; }
  .table.responsive, .table.responsive tbody, .table.responsive tr, .table.responsive td { display: block; width: 100%; }
  .table.responsive tr { border: 1px solid var(--border); border-radius: var(--radius-sm); margin-bottom: 10px; padding: 6px 4px; background: var(--surface); }
  .table.responsive td { border: 0; padding: 5px 10px; display: flex; gap: 10px; justify-content: space-between; text-align: right; }
  .table.responsive td::before { content: attr(data-label); font-weight: 600; color: var(--muted); font-size: .8rem; text-align: left; flex: none; max-width: 40%; }
  .table.responsive td.full { display: block; text-align: left; }
  .table.responsive td.full::before { display: block; max-width: none; }
  .sticky-actions { bottom: 8px; padding: 10px; }
  .sticky-actions .btn { flex: 1 1 auto; }
  .sticky-actions #progress-text { flex: 1 1 100%; order: -1; }
  .page-head { margin-top: 4px; }
}
@media print {
  .sidebar, .topbar, .sticky-actions, .no-print { display: none !important; }
  .shell { display: block; }
  body { background: #fff; }
}
