/* Utsho EMS app layer — app components built in the Utsho V2 language (marked "extension" where the system has no equivalent). */
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--ground); color: var(--ink); font: 400 16px/1.6 var(--font-text); -webkit-font-smoothing: antialiased; }
h1, h2, h3, h4 { font-family: var(--font-display); margin: 0; }
a { color: var(--red-600); }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--ink-muted); }
.small { font-size: 14px; }
.caption { font: 500 13px/1.5 var(--font-text); color: var(--ink-muted); }
.hidden { display: none !important; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.center { text-align: center; }
.bn { font-family: var(--font-text); }
i.ph-bold { line-height: 1; }

/* ---------- shell ---------- */
.app { display: grid; grid-template-columns: 264px 1fr; min-height: 100vh; }
.sidebar { position: sticky; top: 0; height: 100vh; overflow-y: auto; padding: var(--space-4) var(--space-3) var(--space-6); display: flex; flex-direction: column; gap: var(--space-4); }
.brand { background: var(--white); border-radius: var(--radius-md); padding: var(--space-3) var(--space-4); border: var(--stroke-ink) solid var(--ink-900); box-shadow: var(--shadow-sticker); }
.brand img { display: block; width: 100%; height: auto; }
.brand-sub { font: 700 12px/1.3 var(--font-text); letter-spacing: .1em; text-transform: uppercase; color: var(--ink-900); text-align: center; margin-top: 6px; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-group { margin-top: var(--space-3); }
.nav-head { display: flex; align-items: center; gap: var(--space-2); font: 700 12px/1.2 var(--font-text); letter-spacing: .08em; text-transform: uppercase; color: var(--ink-muted); padding: 6px var(--space-3); }
.nav-head .n { font-family: var(--font-display); opacity: .8; }
.nav a { display: flex; align-items: center; gap: var(--space-3); padding: 7px var(--space-3); border-radius: 10px; color: var(--ink); text-decoration: none; font: 500 15px/1.3 var(--font-text); border: 2px solid transparent; }
.nav a i { font-size: 19px; flex: none; }
.nav a:hover { background: var(--ground-raised); }
.nav a.active { background: var(--white); color: var(--ink-900); border-color: var(--ink-900); box-shadow: var(--shadow-sticker-sm); font-weight: 700; }
.nav a:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.side-foot { margin-top: auto; font: 500 13px/1.4 var(--font-text); color: var(--ink-muted); padding: 0 var(--space-3); }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: 20; background: var(--white); border-bottom: 2px solid var(--ink-900); display: flex; align-items: center; gap: var(--space-3); padding: 10px var(--space-6); }
.topbar .menu-btn { display: none; }
.topbar .search { flex: 1; max-width: 460px; position: relative; }
.topbar .search input { width: 100%; padding-left: 38px; }
.topbar .search > i { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); font-size: 18px; color: var(--grey-600); }
.search-results { position: absolute; top: calc(100% + 6px); left: 0; right: 0; background: var(--white); border: 2px solid var(--ink-900); border-radius: 10px; box-shadow: var(--shadow-sticker); max-height: 360px; overflow-y: auto; z-index: 30; }
.search-results a { display: flex; justify-content: space-between; gap: var(--space-3); padding: 8px 12px; color: var(--ink-900); text-decoration: none; border-bottom: 1px solid var(--line); }
.search-results a:hover, .search-results a.on { background: var(--red-050); }
.topbar .spacer { flex: 1; }
.session-pick { display: flex; align-items: center; gap: var(--space-2); }
.session-pick select { min-width: 110px; }
.user-chip { display: flex; align-items: center; gap: var(--space-2); }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--red-600); color: var(--white); border: 2px solid var(--ink-900); display: grid; place-items: center; font: 700 14px/1 var(--font-display); }
.content { padding: var(--space-6) var(--space-6) var(--space-16); max-width: 1440px; width: 100%; }

/* ---------- page header ---------- */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--space-4); flex-wrap: wrap; margin-bottom: var(--space-6); }
.page-head h1 { font: 700 32px/1.2 var(--font-display); display: flex; align-items: center; gap: var(--space-3); }
.page-head h1 i { font-size: 30px; color: var(--red-600); }
.page-head .lead { margin: 4px 0 0; color: var(--ink-muted); max-width: 720px; }
.page-head .actions { display: flex; gap: var(--space-2); flex-wrap: wrap; }
.crumb { font: 600 13px/1.3 var(--font-text); color: var(--ink-muted); text-transform: uppercase; letter-spacing: .08em; margin-bottom: 4px; }

/* ---------- layout helpers ---------- */
.stack { display: flex; flex-direction: column; gap: var(--space-6); }
.stack-sm { display: flex; flex-direction: column; gap: var(--space-3); }
.row { display: flex; gap: var(--space-3); align-items: center; flex-wrap: wrap; }
.row-end { display: flex; gap: var(--space-2); justify-content: flex-end; flex-wrap: wrap; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-6); }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--space-6); }
.grid-tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: var(--space-8) var(--space-6); padding-top: var(--space-4); }
.panel { background: var(--white); border: 2px solid var(--ink-900); border-radius: var(--radius-md); padding: var(--space-6); }
.panel-title { font: 700 20px/1.35 var(--font-display); margin: 0 0 var(--space-4); display: flex; align-items: center; gap: var(--space-2); }
.panel-title i { color: var(--red-600); }
.panel-title .grow { flex: 1; }
.section-title { font: 700 22px/1.35 var(--font-display); margin: 0; }
.divider { border: 0; border-top: 1.5px solid var(--line); margin: var(--space-4) 0; }

/* ---------- stat tiles (HookCard frame, icon in the red tab) ---------- */
.tile { position: relative; background: var(--white); border: var(--stroke-ink) solid var(--ink-900); border-radius: var(--radius-md); box-shadow: var(--shadow-sticker); padding: var(--space-6) var(--space-4) var(--space-4); }
.tile .ut-card-tab { font-size: 18px; }
.tile .label { font: 600 14px/1.3 var(--font-text); color: var(--grey-600); }
.tile .value { font: 700 34px/1.1 var(--font-display); margin-top: 4px; font-variant-numeric: tabular-nums; }
.tile .value small { font-size: 16px; color: var(--grey-600); font-weight: 600; }
.tile .sub { font: 500 13px/1.4 var(--font-text); color: var(--grey-600); margin-top: 4px; }
a.tile { text-decoration: none; color: inherit; display: block; }
a.tile:hover { transform: translate(-1px, -1px); box-shadow: 5px 5px 0 0 #000; }

/* ---------- forms (extension) ---------- */
label.f { display: flex; flex-direction: column; gap: 4px; font: 600 14px/1.3 var(--font-text); min-width: 0; }
label.f .hint { font: 500 12.5px/1.4 var(--font-text); color: var(--grey-600); }
label.f .req { color: var(--red-600); }
input, select, textarea { font: 400 15px/1.4 var(--font-text); color: var(--ink-900); background: var(--white); border: 1.5px solid var(--border-strong); border-radius: var(--radius-sm); padding: 8px 10px; min-width: 0; }
textarea { min-height: 90px; resize: vertical; }
input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 3px solid var(--focus); outline-offset: 1px; border-color: var(--ink-900); }
input[type="checkbox"], input[type="radio"] { width: 18px; height: 18px; accent-color: var(--red-600); padding: 0; }
input:disabled, select:disabled { background: #f4f4f4; color: var(--grey-600); }
input.invalid { border-color: var(--red-600); background: var(--red-050); }
.check { display: inline-flex; align-items: center; gap: 8px; font: 500 15px/1.3 var(--font-text); cursor: pointer; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: var(--space-4); }
.form-grid .span-2 { grid-column: span 2; }
.form-grid .span-all { grid-column: 1 / -1; }
.filters { display: flex; gap: var(--space-3); flex-wrap: wrap; align-items: flex-end; margin-bottom: var(--space-4); }
.filters label.f { min-width: 150px; }
input:not([type="checkbox"]):not([type="radio"]):not([type="file"]), select { height: 40px; }
select { padding-top: 0; padding-bottom: 0; }
/* Seal on fields that came from the birth record: centred on the input itself, clear of the dropdown arrow */
.vwrap { position: relative; display: block; }
.vwrap > input, .vwrap > select { width: 100%; padding-right: 34px; }
.vwrap::after { content: "\e606"; font-family: "Phosphor-Bold"; position: absolute; right: 10px; top: 50%; transform: translateY(-50%); color: var(--red-600); font-size: 16px; line-height: 1; pointer-events: none; }
.vwrap-select > select { padding-right: 56px; }
.vwrap-select::after { right: 30px; }

/* ---------- table (extension) ---------- */
.table-wrap { overflow-x: auto; border: 2px solid var(--ink-900); border-radius: var(--radius-md); background: var(--white); }
table.t { width: 100%; border-collapse: collapse; font: 400 14px/1.4 var(--font-text); }
table.t th { background: var(--ground-deep); text-align: left; font: 700 13px/1.3 var(--font-text); padding: 9px 10px; border-bottom: 2px solid var(--ink-900); white-space: nowrap; position: sticky; top: 0; }
table.t td { padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.t tr:last-child td { border-bottom: 0; }
table.t tbody tr:hover td { background: #fffafa; }
table.t td.num, table.t th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.t tr.sub td { background: #fafafa; }
table.t .fail { color: var(--red-600); font-weight: 700; }
table.t tfoot td { font-weight: 700; background: #fafafa; border-top: 2px solid var(--ink-900); }
.name-cell .bn { display: block; font-size: 13px; color: var(--grey-600); }
.empty { text-align: center; padding: var(--space-12) var(--space-6); color: var(--grey-600); }
.empty i { font-size: 44px; color: var(--red-600); display: block; margin-bottom: var(--space-2); }
.empty h3 { font: 700 20px/1.3 var(--font-display); color: var(--ink-900); margin-bottom: 4px; }

/* actions menu */
.menu-wrap { position: relative; display: inline-block; }
.menu { position: absolute; right: 0; top: calc(100% + 4px); background: var(--white); border: 2px solid var(--ink-900); border-radius: 10px; box-shadow: var(--shadow-sticker); min-width: 190px; z-index: 40; padding: 4px; }
.menu button { display: flex; width: 100%; align-items: center; gap: 10px; background: none; border: 0; padding: 8px 10px; font: 500 14px/1.3 var(--font-text); text-align: left; border-radius: 6px; cursor: pointer; color: var(--ink-900); }
.menu button:hover { background: var(--red-050); }
.menu button i { font-size: 17px; }

/* ---------- tabs (extension) ---------- */
.tabs { display: flex; gap: var(--space-2); border-bottom: 2px solid var(--ink-900); margin-bottom: var(--space-6); flex-wrap: wrap; }
.tabs button { background: none; border: 2px solid transparent; border-bottom: 0; padding: 8px 14px; font: 600 15px/1.3 var(--font-text); cursor: pointer; border-radius: 10px 10px 0 0; display: flex; gap: 8px; align-items: center; color: var(--ink-900); margin-bottom: -2px; }
.tabs button.on { background: var(--white); border-color: var(--ink-900); border-bottom: 2px solid var(--white); }

/* ---------- dialog & toast (extension) ---------- */
.overlay { position: fixed; inset: 0; background: rgba(0, 0, 0, .45); display: flex; align-items: flex-start; justify-content: center; padding: 6vh var(--space-4); z-index: 100; overflow-y: auto; }
.dialog { background: var(--white); border: var(--stroke-ink) solid var(--ink-900); border-radius: var(--radius-md); box-shadow: 6px 6px 0 0 #000; width: 100%; max-width: 560px; }
.dialog.wide { max-width: 920px; }
.dialog-head { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-4) var(--space-6); border-bottom: 2px solid var(--ink-900); }
.dialog-head h2 { font: 700 22px/1.3 var(--font-display); flex: 1; }
.dialog-head i { font-size: 24px; color: var(--red-600); }
.dialog-body { padding: var(--space-6); }
.dialog-foot { display: flex; justify-content: flex-end; gap: var(--space-2); padding: var(--space-4) var(--space-6); border-top: 1.5px solid var(--line); }
.x-btn { background: none; border: 0; cursor: pointer; font-size: 22px; padding: 4px; color: var(--ink-900); }
#toasts { position: fixed; right: var(--space-6); bottom: var(--space-6); display: flex; flex-direction: column; gap: var(--space-2); z-index: 200; }
.toast { display: flex; gap: 10px; align-items: center; background: var(--white); border: 2px solid var(--ink-900); border-radius: 12px; box-shadow: var(--shadow-sticker); padding: 10px 14px; font: 500 15px/1.4 var(--font-text); max-width: 420px; animation: pop .15s ease-out; }
.toast i { font-size: 20px; }
.toast.ok i { color: var(--ink-900); }
.toast.err { background: var(--alert); }
@keyframes pop { from { transform: translateY(8px); opacity: 0; } }

/* ---------- stepper & progress (extension) ---------- */
.stepper { display: flex; gap: var(--space-2); flex-wrap: wrap; margin-bottom: var(--space-6); }
.step { display: flex; align-items: center; gap: 8px; padding: 6px 12px 6px 6px; border: 2px solid var(--line); border-radius: var(--radius-pill); font: 600 14px/1.2 var(--font-text); color: var(--grey-600); background: var(--white); }
.step .dot { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; border: 2px solid currentColor; font: 700 13px/1 var(--font-display); }
.step.on { border-color: var(--ink-900); color: var(--ink-900); box-shadow: var(--shadow-sticker-sm); }
.step.on .dot { background: var(--red-600); color: var(--white); border-color: var(--ink-900); }
.step.done { color: var(--ink-900); border-color: var(--ink-900); }
.step.done .dot { background: var(--ink-900); color: var(--white); }
.progress { height: 12px; border: 2px solid var(--ink-900); border-radius: var(--radius-pill); background: var(--white); overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--red-600); }
.progress.done > span { background: var(--ink-900); }
.pbar-row { display: grid; grid-template-columns: 110px 1fr 60px; gap: var(--space-3); align-items: center; font-size: 14px; }

/* ---------- marks entry grid ---------- */
.marks-grid input.mk { width: 76px; text-align: right; padding: 6px 8px; font-variant-numeric: tabular-nums; }
.marks-grid input.mk.absent { background: var(--alert); font-weight: 700; text-align: center; }
.marks-grid input.mk.saving { border-color: var(--grey-600); border-style: dashed; }
.marks-grid input.mk.err { border-color: var(--red-600); background: var(--red-050); }
.marks-grid td.tot { font-weight: 700; }
.save-state { font: 600 13px/1.3 var(--font-text); display: inline-flex; gap: 6px; align-items: center; color: var(--grey-600); }
.matrix td.cell { text-align: center; min-width: 120px; }
.matrix td.cell button { background: none; border: 0; cursor: pointer; padding: 0; text-align: center; }
.matrix .cnt { display: block; font-size: 12px; color: var(--grey-600); margin-top: 2px; }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr; }
.login-art { position: relative; overflow: hidden; background: var(--red-600); color: var(--white); padding: var(--space-12); display: flex; flex-direction: column; justify-content: center; gap: var(--space-6); }
.login-art .brand { max-width: 300px; }
.login-art h1 { font: 700 52px/1 var(--font-display); }
.login-art p { font: 500 19px/1.5 var(--font-text); max-width: 460px; margin: 0; }
.login-art .ut-hl { color: var(--sun-300); }
.login-form { display: flex; align-items: center; justify-content: center; padding: var(--space-8); background: var(--white); }
.login-form .ut-card { width: 100%; max-width: 420px; }

/* charts */
.chart { width: 100%; height: auto; max-height: 420px; display: block; font-family: var(--font-text); }
.chart text { font-size: 12px; fill: var(--ink-900); }
.legend { display: flex; gap: var(--space-4); flex-wrap: wrap; font: 500 13px/1.3 var(--font-text); margin-top: var(--space-2); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend b { width: 14px; height: 14px; border: 1.5px solid #000; display: inline-block; border-radius: 3px; }

/* chips used for reasons */
.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.chip { font: 500 12.5px/1.3 var(--font-text); border: 1.5px solid var(--ink-900); border-radius: var(--radius-pill); padding: 1px 8px; background: var(--white); }

/* OMR scanning */
.omr-capture { display: flex; gap: var(--space-3); align-items: center; flex-wrap: wrap; }
.omr-capture .ut-btn { min-height: 48px; font-size: 16px; }
.omr-tips { margin: 4px 0 0; padding-left: 20px; }
.omr-reading { display: flex; align-items: center; gap: var(--space-2); color: var(--grey-600); }
.omr-result { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 340px), 1fr)); gap: var(--space-6); align-items: start; }
.omr-left { max-width: 480px; }
.omr-left { display: flex; flex-direction: column; gap: 6px; }
.omr-sheet { width: 100%; height: auto; border: 2px solid var(--ink-900); border-radius: var(--radius-sm); cursor: zoom-in; background: #fff; }
.omr-sheet.big { position: fixed; inset: 0; z-index: 90; width: auto; height: 100vh; max-width: 100vw; margin: 0 auto; border-radius: 0; cursor: zoom-out; box-shadow: 0 0 0 100vmax rgba(0, 0, 0, .7); }
table.t td.omr-id { font: 700 18px/1.2 var(--font-display); letter-spacing: .08em; }
.omr-answers { display: grid; grid-template-columns: repeat(auto-fill, minmax(58px, 1fr)); gap: 4px; }
.omr-a { display: flex; justify-content: space-between; align-items: baseline; gap: 4px; border: 1.5px solid var(--line); border-radius: 6px; padding: 2px 6px; font-variant-numeric: tabular-nums; }
.omr-a .q { font: 500 12px/1.2 var(--font-text); color: var(--grey-600); }
.omr-a b { font: 700 16px/1.2 var(--font-text); }
.omr-a.omr-blank b { color: var(--grey-600); font-weight: 500; }
.omr-a.omr-multiple { border-color: var(--red-600); background: var(--red-050); }
.omr-a.omr-partial { border: 2px solid var(--ink-900); background: var(--alert); }
.key-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); gap: var(--space-2) var(--space-6); outline: none; }
.key-grid:focus-visible { outline: 3px solid var(--focus); outline-offset: 4px; border-radius: 8px; }
.key-col { display: flex; flex-direction: column; gap: 2px; }
.key-row { display: flex; align-items: center; gap: 6px; padding: 2px 6px; border-radius: 8px; border: 2px solid transparent; }
.key-row:nth-child(even) { background: var(--red-050); }
.key-row.cur { border-color: var(--ink-900); background: var(--sun-300); }
.key-row .kq { width: 30px; text-align: right; font: 600 14px/1 var(--font-text); font-variant-numeric: tabular-nums; color: var(--grey-600); cursor: pointer; }
.key-row.empty .kq { color: var(--red-600); }
.key-row.cancelled .kq { text-decoration: line-through; }
.key-row .menu-wrap .ut-btn { padding: 3px 8px; }
.kb { width: 34px; height: 34px; border-radius: 50%; border: 1.5px solid var(--red-600); background: var(--white); color: var(--red-600); font: 600 15px/1 var(--font-text); cursor: pointer; padding: 0; flex: none; }
.kb.on { background: var(--ink-900); border-color: var(--ink-900); color: var(--white); }
.kb:disabled { cursor: default; opacity: .45; }
.kb:focus-visible { outline: 3px solid var(--focus); outline-offset: 1px; }
.scan-card { padding: var(--space-4); }
.scan-card.scan-review { border-color: var(--ink-900); box-shadow: var(--shadow-sticker-sm); background: #fffef0; }
.scan-body { display: grid; grid-template-columns: 140px minmax(0, 1fr); gap: var(--space-4); align-items: start; }
.scan-thumb { width: 140px; }
.scan-score { font: 700 22px/1.1 var(--font-display); font-variant-numeric: tabular-nums; }
.omr-tag { display: inline-block; margin-left: 4px; font: 700 10.5px/1.4 var(--font-text); letter-spacing: .04em; border: 1.5px solid var(--ink-900); border-radius: 4px; padding: 0 4px; color: var(--ink-900); text-decoration: none; vertical-align: middle; }
table.t tr.omr-flag-row td { background: #fffbd6; }
.review-grid.muted { opacity: .4; pointer-events: none; }
.key-print { margin-bottom: 5mm; break-inside: avoid; }
.key-print h3 { margin: 0 0 2mm; font: 700 15px/1.3 var(--font-display); }

@media (max-width: 1100px) {
  .grid-3 { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; z-index: 60; left: 0; top: 0; width: 280px; transform: translateX(-100%); transition: transform .2s; box-shadow: 6px 0 0 #000; }
  body.nav-open .sidebar { transform: none; }
  .topbar { padding: 8px var(--space-4); flex-wrap: wrap; }
  .topbar .menu-btn { display: inline-flex; }
  .topbar .search { order: 5; flex-basis: 100%; max-width: none; }
  .content { padding: var(--space-4) var(--space-4) var(--space-12); }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .page-head h1 { font-size: 26px; }
  .login-wrap { grid-template-columns: 1fr; }
  .login-art { padding: var(--space-8) var(--space-4); }
  .login-art h1 { font-size: 36px; }
  .form-grid .span-2 { grid-column: auto; }
  .user-chip .who { display: none; }
  .omr-capture .ut-btn { flex: 1 1 140px; }
}
