/* StudyRUN control panel: one typeface, one accent, borders instead of shadows.
   Nothing smaller than 14px; colour marks status only. */

:root {
  --bg: #f3f5f3;
  --surface: #ffffff;
  --surface-2: #f8faf8;
  --text: #1f2a28;
  --text-2: #5f6e6a;
  --line: #dde3df;
  --line-2: #c9d2cd;
  --ink: #1c3b39;
  --accent: #e9b23c;
  --accent-2: #d9a12a;
  --good: #2e7d4f;
  --good-soft: #e3f3e8;
  --warn: #9a6400;
  --warn-soft: #fff1d1;
  --bad: #b3362b;
  --bad-soft: #fbe7e4;
  --info: #2f6fa3;
  --info-soft: #e4eef7;
  --radius: 8px;
  --series-1: #2a78d6;
  --series-1-strong: #1c5cab;
  --radius-s: 6px;
  font-family: "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  font-synthesis: none;
  -webkit-font-smoothing: antialiased;
}
* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; }
img { display: block; }
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: .55; }
a { color: var(--ink); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, p, dl, dd { margin: 0; }
h1 { font-size: 26px; font-weight: 600; line-height: 1.25; letter-spacing: -.01em; }
h2 { font-size: 17px; font-weight: 600; line-height: 1.3; }
.muted { color: var(--text-2); }
:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }

.skip-link { position: fixed; top: -80px; left: 16px; background: var(--ink); color: #fff; padding: 10px 14px; border-radius: var(--radius-s); z-index: 100; }
.skip-link:focus { top: 12px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

/* Buttons */
.button { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 40px; padding: 8px 16px; border-radius: var(--radius-s); border: 1px solid var(--line-2); background: var(--surface); color: var(--text); font-weight: 500; white-space: nowrap; }
.button:hover:not(:disabled) { background: var(--surface-2); border-color: #aeb9b4; text-decoration: none; }
.button.primary { background: var(--accent); border-color: var(--accent-2); color: var(--ink); font-weight: 600; }
.button.primary:hover:not(:disabled) { background: #f0bd4e; }
.button.danger { color: var(--bad); border-color: #e3b9b4; }
.button.danger:hover:not(:disabled) { background: var(--bad-soft); }
.button.small { min-height: 34px; padding: 5px 12px; }
.button.full-width { width: 100%; }
.icon-button { width: 36px; height: 36px; display: grid; place-items: center; border: 1px solid var(--line-2); border-radius: var(--radius-s); background: var(--surface); font-size: 22px; line-height: 1; }
.icon-button:hover { background: var(--surface-2); }

/* Status pills */
.badge { display: inline-flex; align-items: center; gap: 7px; padding: 4px 11px 4px 9px; border-radius: 999px; font-size: 14px; font-weight: 500; white-space: nowrap; background: #eceff0; color: #4f5c59; }
.badge::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; flex: none; }
.badge.good { background: var(--good-soft); color: var(--good); }
.badge.pending { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.blue { background: var(--info-soft); color: var(--info); }

/* Shell */
.app-shell { display: grid; grid-template-columns: 220px minmax(0, 1fr); min-height: 100vh; }
.sidebar { background: var(--surface); border-right: 1px solid var(--line); display: flex; flex-direction: column; padding: 22px 14px 18px; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 22px; color: var(--text); font-size: 17px; font-weight: 600; }
.brand:hover { text-decoration: none; }
.brand img { width: 32px; height: 32px; }
.navigation { display: flex; flex-direction: column; gap: 2px; }
.navigation a { display: block; padding: 10px 13px; border-radius: var(--radius-s); color: var(--text); border-left: 3px solid transparent; }
.navigation a:hover { background: var(--surface-2); text-decoration: none; }
.navigation a[aria-current="page"] { background: var(--bg); border-left-color: var(--accent); font-weight: 600; color: var(--ink); }
.sidebar-bottom { margin-top: auto; padding: 14px 10px 0; border-top: 1px solid var(--line); display: flex; flex-direction: column; align-items: flex-start; gap: 8px; }
.sidebar-bottom strong { font-weight: 600; overflow-wrap: anywhere; }

.workspace { min-width: 0; }
main { padding: 28px 36px 44px; }
.page-header { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-bottom: 18px; }
.page-title-row { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.page-header .actions { display: flex; align-items: center; gap: 10px; flex: none; }
.status-line { color: var(--text-2); min-height: 22px; margin: -6px 0 12px; }
.notice { padding: 12px 14px; border-radius: var(--radius-s); border: 1px solid var(--line); border-left: 4px solid var(--info); background: var(--surface); margin-bottom: 16px; white-space: pre-line; overflow-wrap: anywhere; }
.notice.error { border-left-color: var(--bad); color: var(--bad); }

/* Cards */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; }
.card h2 + .form-grid { margin-top: 16px; }
.card-header { display: flex; justify-content: space-between; align-items: baseline; gap: 16px; margin-bottom: 14px; }
.stack > * + * { margin-top: 16px; }
.settings-form { max-width: none; }
.two-columns { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; align-items: stretch; margin-bottom: 16px; }

/* Overview */
.figures { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 16px; }
.figure { padding: 18px 20px; border-left: 1px solid var(--line); }
.figure:first-child { border-left: 0; }
.figure .label { color: var(--text-2); }
.figure .value { font-size: 30px; font-weight: 600; line-height: 1.2; margin-top: 6px; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.summary-row { display: flex; justify-content: space-between; gap: 16px; padding: 10px 0; border-top: 1px solid var(--line); }
.summary-row:first-child { border-top: 0; }
.summary-row dt { color: var(--text-2); }
.summary-row dd { font-weight: 600; font-variant-numeric: tabular-nums; text-align: right; }

/* Forms */
label { display: block; font-weight: 500; }
input, select, textarea { width: 100%; min-height: 40px; padding: 8px 11px; border: 1px solid var(--line-2); border-radius: var(--radius-s); background: var(--surface); }
input:focus, select:focus, textarea:focus { border-color: var(--ink); outline: 2px solid var(--ink); outline-offset: 0; }
textarea { resize: vertical; min-height: 72px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px 20px; }
.field label { margin-bottom: 6px; }
.field label span { font-weight: 400; color: var(--text-2); margin-left: 4px; }
.field.span-2 { grid-column: 1 / -1; }
.checkbox-field label { display: flex; align-items: center; gap: 10px; font-weight: 400; padding-top: 28px; }
.checkbox-field input { width: 20px; height: 20px; min-height: 0; margin: 0; }
.form-actions { display: flex; align-items: center; gap: 14px; }

/* Tables */
.table-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.table-toolbar { display: flex; align-items: center; gap: 14px; padding: 14px 16px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.search-field { flex: 1 1 240px; max-width: 340px; }
.filter-field select { width: auto; max-width: 220px; }
.table-toolbar .count { margin-left: auto; color: var(--text-2); white-space: nowrap; }
.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; text-align: left; }
th { padding: 11px 16px; background: var(--surface-2); color: var(--text-2); font-weight: 500; white-space: nowrap; border-bottom: 1px solid var(--line); }
td { padding: 14px 16px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: #fbfcfb; }
td strong { display: block; font-weight: 600; max-width: 320px; overflow-wrap: anywhere; }
td .subtext { display: block; color: var(--text-2); margin-top: 2px; max-width: 320px; overflow-wrap: anywhere; }
.numeric { font-variant-numeric: tabular-nums; white-space: nowrap; }
.record-id { color: var(--text-2); overflow-wrap: anywhere; }
.cell-action { text-align: right; white-space: nowrap; }
.empty-state { padding: 40px 20px; text-align: center; color: var(--text-2); }
.audit-table td { vertical-align: top; }
.audit-table td:last-child { max-width: 560px; overflow-wrap: anywhere; white-space: pre-wrap; line-height: 1.6; }

/* Dialogs */
.modal { padding: 0; border: 1px solid var(--line-2); border-radius: var(--radius); width: 600px; max-width: calc(100vw - 32px); max-height: calc(100dvh - 40px); color: var(--text); }
.modal::backdrop { background: rgba(28, 59, 57, .45); }
.modal-header { display: flex; justify-content: space-between; align-items: center; gap: 14px; padding: 18px 22px; border-bottom: 1px solid var(--line); }
.modal-header h2 { font-size: 19px; }
.modal-body { padding: 20px 22px; overflow-y: auto; max-height: calc(100dvh - 190px); }
.modal-footer { display: flex; justify-content: flex-end; gap: 10px; flex-wrap: wrap; padding: 14px 22px; border-top: 1px solid var(--line); background: var(--surface-2); }

/* Sign in and startup */
.startup { min-height: 100vh; display: flex; align-items: center; justify-content: center; }
.login-view { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 40px 20px; }
.login-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 28px; }
.login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 22px; font-size: 19px; font-weight: 600; }
.login-card label { margin: 14px 0 6px; }
.login-card .button { margin-top: 22px; }
.form-error { color: var(--bad); margin-top: 14px; }

/* Responsive */
/* ---- Public policy pages */
main.policy { max-width: 760px; margin: 0 auto; padding: 36px 20px 60px; }
main.policy h1 { font-size: 28px; margin-bottom: 18px; }
main.policy p { white-space: pre-wrap; margin: 0 0 14px; line-height: 1.6; }
main.policy h2 { font-size: 19px; margin: 26px 0 10px; }
main.policy ul { margin: 0 0 14px 22px; padding: 0; line-height: 1.6; }
main.policy li { margin: 0 0 6px; }
.policy-warning { margin: 0 0 14px; padding: 10px 14px; border-radius: 10px; background: #fff4d6; color: #7a4b00; font-size: 14px; }

/* ---- Paging */
.table-footer { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; border-top: 1px solid var(--line); color: var(--text-2); }
.table-footer .range { font-variant-numeric: tabular-nums; }
.pager { display: flex; gap: 8px; }

/* ---- Question bank */
.field-hint { color: var(--text-2); font-size: 14px; margin: 6px 0 0; }
.options-grid { display: grid; gap: 10px; }
.option-row { display: grid; grid-template-columns: 22px 28px minmax(0, 1fr); align-items: center; gap: 10px; font-weight: 400; margin: 0; cursor: pointer; }
.option-row input[type=radio] { width: 20px; height: 20px; min-height: 0; margin: 0; }
.option-row.sinhala-row { grid-template-columns: 28px minmax(0, 1fr); }
.option-letter { font-weight: 600; color: var(--text-2); }
.question-cell { max-width: 560px; }
.question-cell strong { display: block; overflow-wrap: anywhere; }
.question-cell .subtext { display: block; max-width: none; white-space: pre-wrap; overflow-wrap: anywhere; }
#page-questions .table-scroll td:nth-child(5) { max-width: 240px; overflow-wrap: anywhere; }
.modal.wide { width: 760px; }
.manage-summary { font-weight: 600; margin: 14px 0 12px; }
.batch-table { border: 1px solid var(--line); border-radius: var(--radius-s); }
.batch-table td { padding: 12px 14px; }
.batch-table .cell-action .button + .button { margin-left: 8px; }
.code-form { display: flex; gap: 10px; flex-wrap: wrap; margin: 14px 0; }
.code-form input { flex: 1 1 180px; width: auto; }
.code-form input[type=number] { flex: 0 1 220px; }
.subscriber { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 13px; }
.danger-zone { margin-top: 22px; padding: 16px; border: 1px solid #e3b9b4; border-radius: var(--radius-s); background: var(--bad-soft); }
.danger-zone h3 { font-size: 16px; color: var(--bad); margin: 0 0 6px; }
.danger-zone .muted { margin: 0 0 12px; }
.danger-row { display: flex; gap: 10px; flex-wrap: wrap; }
.danger-row input { flex: 1 1 200px; width: auto; }

/* Monitoring: one range bar above everything it scopes, figures, four single-series charts and a table. */
.range-bar { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px 16px; margin-bottom: 12px; }
.range-presets { display: inline-flex; flex-wrap: wrap; gap: 2px; padding: 3px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.range-button { min-height: 36px; padding: 6px 12px; border: 0; border-radius: var(--radius-s); background: transparent; color: var(--text-2); font-weight: 500; }
.range-button:hover { background: var(--surface-2); color: var(--text); }
.range-button[aria-pressed="true"] { background: var(--ink); color: #fff; }
.range-custom { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px; }
.range-custom label { display: flex; flex-direction: column; gap: 4px; color: var(--text-2); }
.range-custom input { width: auto; }
.monitor-range { margin: 0 0 12px; }
.monitor-figures { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.monitor-figures .figure:nth-child(4) { border-left: 0; }
.monitor-figures .figure:nth-child(n + 4) { border-top: 1px solid var(--line); }
.figure .detail { margin-top: 2px; color: var(--text-2); }
.monitor-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; margin-bottom: 16px; }
.chart-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 8px; }
.chart-subtitle { margin: 2px 0 0; color: var(--text-2); }
.chart { position: relative; height: 250px; }
.chart.loading { opacity: .5; }
.chart svg { display: block; overflow: visible; }
.chart svg:focus { outline: 2px solid var(--ink); outline-offset: 4px; }
.chart .grid { stroke: var(--line); stroke-width: 1; shape-rendering: crispEdges; }
.chart .axis-label { fill: var(--text-2); font-size: 14px; font-variant-numeric: tabular-nums; }
.chart .series-line { fill: none; stroke: var(--series-1); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .series-area { fill: var(--series-1); fill-opacity: .1; }
.chart .series-bar { fill: var(--series-1); }
.chart .series-bar.is-active { fill: var(--series-1-strong); }
.chart .marker { fill: var(--series-1); stroke: var(--surface); stroke-width: 2; }
.chart .crosshair { stroke: var(--text-2); stroke-width: 1; shape-rendering: crispEdges; }
.chart .value-label { fill: var(--text); font-size: 14px; font-weight: 600; }
.chart .empty-label { fill: var(--text-2); font-size: 15px; }
.chart-tooltip { position: absolute; top: 0; z-index: 2; padding: 8px 10px; background: var(--surface); border: 1px solid var(--line-2); border-radius: var(--radius-s); box-shadow: 0 4px 14px rgba(28, 59, 57, .12); white-space: nowrap; pointer-events: none; }
.chart-tooltip strong { display: block; font-size: 16px; font-weight: 600; font-variant-numeric: tabular-nums; }
.chart-tooltip .key { display: inline-block; width: 14px; height: 2px; margin-right: 8px; vertical-align: middle; background: var(--series-1); }
.chart-tooltip span:last-child { color: var(--text-2); }
.chart-table { max-height: 250px; overflow-y: auto; border: 1px solid var(--line); border-radius: var(--radius-s); }
.chart-table td, .chart-table th { padding: 8px 12px; }
.monitor-players { margin-bottom: 12px; }
.monitor-players .table-toolbar h2 { margin: 0; }

@media (min-width: 1700px) {
  main { padding: 32px 48px 48px; }
  .two-columns { gap: 20px; }
}
@media (max-width: 1100px) {
  main { padding: 24px 28px 40px; }
  .figures { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .figure:nth-child(3) { border-left: 0; }
  .figure:nth-child(n + 3) { border-top: 1px solid var(--line); }
}
@media (max-width: 800px) {
  .app-shell { display: block; }
  .sidebar { position: static; height: auto; padding: 10px 16px 0; border-right: 0; border-bottom: 1px solid var(--line); flex-direction: row; flex-wrap: wrap; align-items: center; }
  .brand { padding: 6px 0; }
  .sidebar-bottom { margin: 0 0 0 auto; border: 0; padding: 0; flex-direction: row; align-items: center; gap: 10px; }
  .navigation { flex-basis: 100%; order: 3; flex-direction: row; overflow-x: auto; gap: 4px; padding: 6px 0 0; scrollbar-width: none; }
  .navigation::-webkit-scrollbar { display: none; }
  .navigation a { white-space: nowrap; border-left: 0; border-bottom: 3px solid transparent; border-radius: var(--radius-s) var(--radius-s) 0 0; padding: 8px 10px; }
  .navigation a[aria-current="page"] { border-bottom-color: var(--accent); background: transparent; }
  main { padding: 20px 16px 36px; }
  .page-header { flex-wrap: wrap; }
  .two-columns { grid-template-columns: 1fr; }
  .monitor-grid { grid-template-columns: 1fr; }
  .monitor-figures { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .monitor-figures .figure:nth-child(odd) { border-left: 0; }
  .monitor-figures .figure:nth-child(4) { border-left: 1px solid var(--line); }
  .table-scroll table { min-width: 600px; }
  .table-scroll th:first-child, .table-scroll td:first-child { min-width: 200px; }
  #page-leaderboards .table-scroll table { min-width: 0; }
  .modal-header, .modal-body { padding: 16px; }
  .modal-footer { padding: 12px 16px; }
  .detail-list .summary-row { grid-template-columns: 1fr; gap: 2px; }
}
@media (max-width: 480px) {
  .figures { grid-template-columns: 1fr; }
  .figure { border-left: 0; }
  .figure + .figure { border-top: 1px solid var(--line); }
  .form-grid { grid-template-columns: 1fr; }
  .checkbox-field label { padding-top: 0; }
  .modal-footer .button { flex: 1 1 auto; }
  .login-card { padding: 22px; }
}
@media (prefers-reduced-motion: no-preference) {
  .button, .navigation a { transition: background-color .12s, border-color .12s; }
  .switch-track, .switch-track::before { transition: background-color .15s, transform .15s; }
}
