/* Qareken SAT — brand shell + shared components. Runner styles live in bluebook.css. */

:root {
  --brand: #FC5B20;
  --brand-dark: #D9480F;
  --brand-soft: #FFF1EA;
  --ink: #1F2328;
  --muted: #5F6B7A;
  --line: #E3E7ED;
  --bg: #F6F7F9;
  --card: #FFFFFF;
  --ok: #1F9D55;
  --ok-soft: #E6F6EC;
  --bad: #D93025;
  --bad-soft: #FDECEA;
  --warn: #E8A317;
  --warn-soft: #FFF6E0;
  --info: #2563EB;
  --info-soft: #E8F0FE;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .10);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, .18);
  --font: Roboto, system-ui, -apple-system, "Segoe UI", "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  --font-serif: "Noto Serif", Georgia, "Times New Roman", serif;
  --topbar-h: 60px;
  --bottomnav-h: 62px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}
body.modal-open { overflow: hidden; }
/* overflow:hidden does not stop Android pull-to-refresh, which would reload the app from inside a sheet. */
html.modal-open { overscroll-behavior-y: none; }
img, svg { max-width: 100%; }
a { color: var(--brand-dark); }
h1, h2, h3, h4 { line-height: 1.25; margin: 0 0 .5em; }
p { margin: 0 0 .75em; }
button { font: inherit; }
:focus-visible { outline: 3px solid rgba(252, 91, 32, .45); outline-offset: 2px; }

.muted { color: var(--muted); }
.small { font-size: 13px; }
.nowrap { white-space: nowrap; }
.text-ok { color: var(--ok); }
.text-bad { color: var(--bad); }
.text-warn { color: #9a6700; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); border: 0; }

/* ---------- Boot / spinner ---------- */
.boot { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px; padding: 24px; }
.spinner-wrap { display: flex; align-items: center; justify-content: center; gap: 12px; padding: 40px 16px; }
.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--brand); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Brand ---------- */
.brand-mark { display: inline-flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); min-width: 0; }
.brand-logo { display: block; flex: none; }
.brand-text { display: flex; flex-direction: column; line-height: 1.1; min-width: 0; }
.brand-name { font-weight: 800; letter-spacing: -.01em; font-size: 16px; white-space: nowrap; }
.brand-sub { font-size: 12px; color: var(--brand-dark); font-weight: 600; text-transform: uppercase; letter-spacing: .06em; }
.social-links { display: inline-flex; gap: 10px; align-items: center; }
.social-link { display: inline-block; border-radius: 8px; overflow: hidden; flex: none; transition: transform .15s; }
.social-link:hover { transform: translateY(-1px); }
.social-link svg { display: block; }
.credit-line { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.brand-footer { border-top: 1px solid var(--line); background: #fff; margin-top: 32px; }
.brand-footer-inner { max-width: 1180px; margin: 0 auto; padding: 18px 16px; display: flex; align-items: center; justify-content: space-between; gap: 14px; flex-wrap: wrap; font-size: 13px; color: var(--muted); }
.brand-footer-left { display: inline-flex; align-items: center; gap: 8px; }

/* ---------- Shell: student ---------- */
.shell { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: 30; background: rgba(255, 255, 255, .96); backdrop-filter: saturate(1.4) blur(8px); border-bottom: 1px solid var(--line); }
.topbar-inner { max-width: 1180px; margin: 0 auto; height: var(--topbar-h); display: flex; align-items: center; gap: 16px; padding: 0 16px; }
.topbar-brand { text-decoration: none; color: inherit; min-width: 0; }
.topnav { display: flex; gap: 4px; margin-left: 12px; flex: 1; }
.topnav-link { display: inline-flex; align-items: center; gap: 8px; padding: 8px 12px; border-radius: 999px; text-decoration: none; color: var(--muted); font-weight: 600; font-size: 14px; }
.topnav-link:hover { background: var(--bg); color: var(--ink); }
.topnav-link.active { background: var(--brand-soft); color: var(--brand-dark); }
.topbar-user { display: flex; align-items: center; gap: 6px; margin-left: auto; }
.topbar-name { font-weight: 600; font-size: 14px; max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.page-content { flex: 1; width: 100%; max-width: 1180px; margin: 0 auto; padding: 24px 16px; }
.bottomnav { display: none; }

@media (max-width: 760px) {
  .topnav { display: none; }
  .topbar-name { display: none; }
  .shell-student .page-content { padding: 16px 16px calc(var(--bottomnav-h) + var(--safe-b) + 16px); }
  .shell-student .brand-footer { margin-bottom: calc(var(--bottomnav-h) + var(--safe-b)); }
  .bottomnav { display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; background: #fff; border-top: 1px solid var(--line); padding-bottom: var(--safe-b); height: calc(var(--bottomnav-h) + var(--safe-b)); }
  .bottomnav-link { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; text-decoration: none; color: var(--muted); font-size: 11px; font-weight: 600; }
  .bottomnav-link.active { color: var(--brand); }
}

/* ---------- Shell: admin ---------- */
.shell-admin { flex-direction: row; }
.sidebar { width: 248px; flex: none; background: #fff; border-right: 1px solid var(--line); position: sticky; top: 0; height: 100vh; height: 100dvh; display: flex; flex-direction: column; padding: 16px 12px; z-index: 50; }
.sidebar-brand { padding: 4px 8px 18px; }
.sidebar-nav { display: flex; flex-direction: column; gap: 2px; flex: 1; overflow-y: auto; }
.sidebar-link { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 10px; color: var(--muted); text-decoration: none; font-weight: 600; font-size: 14px; }
.sidebar-link:hover { background: var(--bg); color: var(--ink); }
.sidebar-link.active { background: var(--brand-soft); color: var(--brand-dark); }
.sidebar-foot { border-top: 1px solid var(--line); padding-top: 12px; display: flex; flex-direction: column; gap: 8px; }
.sidebar-user { display: flex; align-items: center; gap: 8px; padding: 0 8px; font-weight: 600; font-size: 14px; }
.admin-main { flex: 1; min-width: 0; display: flex; flex-direction: column; min-height: 100vh; min-height: 100dvh; }
.admin-topbar { display: none; }
.drawer-backdrop { display: none; }

@media (max-width: 960px) {
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; transform: translateX(-100%); transition: transform .2s ease; box-shadow: var(--shadow-lg); }
  .shell-admin.drawer-open .sidebar { transform: none; }
  .shell-admin.drawer-open .drawer-backdrop { display: block; position: fixed; top: 0; right: 0; bottom: 0; left: 0; inset: 0; background: rgba(15, 23, 42, .35); z-index: 45; }
  .admin-topbar { display: flex; align-items: center; gap: 8px; position: sticky; top: 0; z-index: 30; height: 56px; padding: 0 8px; background: rgba(255, 255, 255, .96); border-bottom: 1px solid var(--line); }
  .shell-admin .page-content { padding: 16px; }
}

/* ---------- Shell: auth ---------- */
.shell-auth { background: radial-gradient(1200px 500px at 50% -10%, var(--brand-soft), transparent 70%), var(--bg); }
.auth-wrap { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 32px 16px; gap: 20px; }
.auth-brand { text-align: center; }
.auth-brand h1 { font-size: 26px; margin: 12px 0 2px; letter-spacing: -.02em; }
.auth-brand .brand-logo { margin: 0 auto; }
.auth-card { width: 100%; max-width: 400px; background: #fff; border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); padding: 24px; }
.shell-auth .brand-footer { margin-top: 0; background: transparent; }

/* ---------- Layout helpers ---------- */
.stack { display: flex; flex-direction: column; gap: 16px; }
.stack-sm { display: flex; flex-direction: column; gap: 8px; }
.row { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; }
.row-between { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 960px) { .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 640px) { .grid-2, .grid-3 { grid-template-columns: minmax(0, 1fr); } }
@media (max-width: 380px) { .grid-4 { grid-template-columns: minmax(0, 1fr); } }

.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 20px; }
.page-title { font-size: 26px; font-weight: 800; letter-spacing: -.02em; margin: 0; }
.page-subtitle { color: var(--muted); margin: 4px 0 0; }
.page-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.section-title { font-size: 18px; font-weight: 700; margin: 0 0 12px; }
@media (max-width: 640px) { .page-title { font-size: 22px; } }

/* ---------- Cards ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); min-width: 0; }
.card-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.card-header h2, .card-header h3 { font-size: 16px; margin: 0; }
.card-body { padding: 18px; }
.card-footer { padding: 12px 18px; border-top: 1px solid var(--line); display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
.card-link { text-decoration: none; color: inherit; display: block; transition: box-shadow .15s, transform .15s; }
.card-link:hover { box-shadow: var(--shadow-lg); transform: translateY(-1px); }
.error-box { border-color: #f5c2c0; background: #fffafa; }

.kpi { padding: 16px 18px; }
.kpi-label { color: var(--muted); font-size: 13px; font-weight: 600; }
.kpi-value { font-size: 28px; font-weight: 800; letter-spacing: -.02em; line-height: 1.2; }
.kpi-sub { font-size: 12px; color: var(--muted); }

/* ---------- Buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 42px; padding: 0 16px; border-radius: 10px; border: 1px solid transparent; font-weight: 700; font-size: 14px; cursor: pointer; text-decoration: none; white-space: nowrap; transition: background .15s, border-color .15s, color .15s, box-shadow .15s; user-select: none; }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--brand-dark); }
.btn-secondary { background: #fff; color: var(--ink); border-color: var(--line); }
.btn-secondary:hover:not(:disabled) { border-color: #c8ced6; background: #fafbfc; }
.btn-ghost { background: transparent; color: var(--ink); }
.btn-ghost:hover:not(:disabled) { background: var(--bg); }
.btn-danger { background: var(--bad); color: #fff; }
.btn-danger:hover:not(:disabled) { background: #b3261e; }
.btn-ok { background: var(--ok); color: #fff; }
.btn-sm { min-height: 34px; padding: 0 12px; font-size: 13px; border-radius: 8px; }
.btn-lg { min-height: 50px; padding: 0 22px; font-size: 16px; }
.btn-block { width: 100%; }
.btn-icon { width: 42px; padding: 0; }
.btn-sm.btn-icon { width: 34px; }

/* ---------- Forms ---------- */
.field { display: flex; flex-direction: column; gap: 6px; }
.field > label, .field-label { font-weight: 600; font-size: 14px; }
.field-hint { font-size: 12px; color: var(--muted); }
.field-error { font-size: 13px; color: var(--bad); }
.input, .select, .textarea { width: 100%; min-height: 44px; padding: 10px 12px; border: 1px solid #cfd5dd; border-radius: 10px; background: #fff; color: var(--ink); font: inherit; font-size: 16px; }
.textarea { min-height: 110px; resize: vertical; line-height: 1.45; }
.textarea.mono, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(252, 91, 32, .18); }
.input-group { display: flex; gap: 8px; }
.input-group .input { flex: 1; min-width: 0; }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: 14px; }
.check input { width: 18px; height: 18px; accent-color: var(--brand); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
@media (max-width: 640px) { .form-grid { grid-template-columns: minmax(0, 1fr); } }

/* ---------- Badges ---------- */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 700; background: var(--bg); color: var(--muted); white-space: nowrap; }
.badge-ok { background: var(--ok-soft); color: #137a40; }
.badge-bad { background: var(--bad-soft); color: #b3261e; }
.badge-warn { background: var(--warn-soft); color: #8a5a00; }
.badge-info { background: var(--info-soft); color: #1d4ed8; }
.badge-brand { background: var(--brand-soft); color: var(--brand-dark); }
.badge-muted { background: #eef0f3; color: var(--muted); }

/* ---------- Tables ---------- */
.table-wrap { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 700; padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; background: #fafbfc; }
.table td { padding: 11px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr.clickable { cursor: pointer; }
.table tbody tr.clickable:hover td { background: #fafbfc; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); overflow-x: auto; margin-bottom: 16px; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab { padding: 10px 14px; border: 0; background: none; font-weight: 700; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tab.active { color: var(--brand-dark); border-bottom-color: var(--brand); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 6px 12px; font-size: 13px; font-weight: 600; cursor: pointer; color: var(--muted); }
.chip.active { background: var(--ink); color: #fff; border-color: var(--ink); }

/* ---------- Empty / misc ---------- */
.empty { text-align: center; padding: 36px 16px; color: var(--muted); }
.empty p { margin-bottom: 12px; }
.divider { height: 1px; background: var(--line); margin: 8px 0; border: 0; }
.progress { height: 8px; background: #eef0f3; border-radius: 999px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--brand); border-radius: inherit; }
.notice { border-radius: 10px; padding: 12px 14px; font-size: 14px; background: var(--info-soft); color: #1e3a8a; }
.notice-warn { background: var(--warn-soft); color: #7a4f00; }
.notice-bad { background: var(--bad-soft); color: #8c1d18; }
.notice-ok { background: var(--ok-soft); color: #0f5f32; }
.copy-box { display: flex; align-items: center; gap: 8px; background: var(--bg); border: 1px dashed #cfd5dd; border-radius: 10px; padding: 10px 12px; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 14px; word-break: break-all; }
.copy-box > :first-child { flex: 1; }

/* ---------- Modal ---------- */
/* top/right/bottom/left: `inset` alone is dropped by iOS < 14.5 and Chrome/WebView < 87. */
.modal-overlay { position: fixed; top: 0; right: 0; bottom: 0; left: 0; inset: 0; z-index: 1000; background: rgba(15, 23, 42, .45); display: flex; align-items: center; justify-content: center; padding: 16px; opacity: 0; transition: opacity .18s; }
.modal-overlay.show { opacity: 1; }
.modal { background: #fff; border-radius: 16px; box-shadow: var(--shadow-lg); width: 100%; max-height: calc(100vh - 32px); max-height: calc(100dvh - 32px); display: flex; flex-direction: column; transform: translateY(8px); transition: transform .18s; }
.modal-overlay.show .modal { transform: none; }
.modal-sm { max-width: 420px; }
.modal-md { max-width: 560px; }
.modal-lg { max-width: 860px; }
.modal-full { max-width: 1100px; height: calc(100dvh - 32px); }
.modal-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 18px; border-bottom: 1px solid var(--line); }
.modal-title { font-size: 18px; margin: 0; }
.modal-close { border: 0; background: none; cursor: pointer; padding: 6px; border-radius: 8px; color: var(--muted); display: inline-flex; }
.modal-close:hover { background: var(--bg); color: var(--ink); }
.modal-body { padding: 18px; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; flex: 1; }
.modal-footer { padding: 12px 18px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
@media (max-width: 640px) {
  .modal-overlay { align-items: flex-end; padding: 0; }
  .modal { border-radius: 16px 16px 0 0; max-height: 92dvh; padding-bottom: var(--safe-b); }
  .modal-full { height: 96dvh; }
  .modal-footer .btn { flex: 1; }
}

/* ---------- Toast ---------- */
.toast-host { position: fixed; z-index: 2000; left: 50%; bottom: calc(24px + var(--safe-b)); transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; width: calc(100% - 32px); max-width: 420px; }
.toast { background: #1f2328; color: #fff; padding: 11px 16px; border-radius: 10px; font-size: 14px; font-weight: 600; box-shadow: var(--shadow-lg); opacity: 0; transform: translateY(8px); transition: opacity .2s, transform .2s; pointer-events: auto; text-align: center; }
.toast.show { opacity: 1; transform: none; }
.toast-success { background: #137a40; }
.toast-error { background: #b3261e; }
body[data-layout="student"] .toast-host { bottom: calc(var(--bottomnav-h) + var(--safe-b) + 16px); }

/* ---------- Charts ---------- */
.chart { position: relative; width: 100%; }
.chart svg { display: block; overflow: visible; }
.chart-grid { stroke: #eef0f3; stroke-width: 1; }
.chart-axis { fill: var(--muted); font-size: 11px; font-family: var(--font); }
.chart-value { fill: var(--ink); font-size: 11px; font-weight: 700; font-family: var(--font); }
.chart-legend { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 8px; font-size: 13px; color: var(--muted); }
.chart-legend-item { display: inline-flex; align-items: center; gap: 6px; }
.chart-legend-item i { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
.hbar-chart { display: flex; flex-direction: column; gap: 10px; }
.hbar-row { display: grid; grid-template-columns: minmax(90px, 38%) 1fr 48px; gap: 10px; align-items: center; font-size: 13px; }
.hbar-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hbar-track { height: 10px; background: #eef0f3; border-radius: 999px; overflow: hidden; }
.hbar-fill { height: 100%; border-radius: inherit; }
.hbar-value { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }
.vbar-chart { display: flex; align-items: stretch; gap: 8px; }
.vbar-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; min-width: 0; }
.vbar-value { font-size: 11px; font-weight: 700; height: 16px; }
.vbar-track { flex: 1; width: 100%; max-width: 44px; background: #f2f4f7; border-radius: 6px 6px 0 0; display: flex; align-items: flex-end; overflow: hidden; }
.vbar-fill { width: 100%; border-radius: 6px 6px 0 0; }
.vbar-label { font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.segbar { display: inline-grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 3px; width: 100%; max-width: 210px; }
.segbar span { height: 10px; background: #dfe3e8; border-radius: 2px; }
.segbar span.on { background: #324dc7; }

/* ---------- Rich content defaults ---------- */
.rich { overflow-wrap: anywhere; }
.rich p { margin: 0 0 .8em; }
.rich p:last-child { margin-bottom: 0; }
.rich table { border-collapse: collapse; margin: .6em 0; max-width: 100%; }
.rich th, .rich td { border: 1px solid #9aa3ad; padding: 4px 10px; text-align: center; }
.rich th { background: #f3f4f6; font-weight: 700; }
.rich caption { font-weight: 700; padding: 4px; }
.rich img, .rich svg { max-width: 100%; height: auto; }
/* KaTeX draws radicals/stretchy glyphs as SVGs that must keep KaTeX's own sizing. */
.rich .katex svg { height: inherit; max-width: none; }
.rich figure { margin: .6em 0; text-align: center; }
.rich figcaption { font-size: .9em; color: var(--muted); }
.rich ul, .rich ol { padding-left: 1.4em; margin: 0 0 .8em; }
.rich blockquote { margin: .5em 0; padding-left: 1em; border-left: 3px solid #d0d5db; }
.math-display { overflow-x: auto; overflow-y: hidden; padding: 2px 0; }
.math-fallback { font-family: ui-monospace, monospace; }
.katex { font-size: 1.08em; }
