/* APHCS styles. One column on phones with the primary action in the thumb
   zone; two panes on PC. Large tap targets, visible focus, dark mode and a
   high-contrast mode. No external fonts. */

:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #eef1f5;
  --text: #16202a;
  --muted: #56626e;
  --line: #d6dce3;
  --primary: #123d5a;
  --primary-text: #ffffff;
  --accent: #f2c230; /* Ottawa's yellow notices */
  --ok: #1b7a43;
  --ok-bg: #e3f4ea;
  --warn: #8a5a00;
  --warn-bg: #fff4d6;
  --danger: #a4262c;
  --danger-bg: #fbe5e6;
  --info-bg: #e6f0f8;
  --radius: 12px;
  --tap: 48px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .06), 0 2px 8px rgba(0, 0, 0, .05);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", Ubuntu, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f141a;
    --surface: #171e26;
    --surface-2: #1f2832;
    --text: #e8edf2;
    --muted: #9fb0bf;
    --line: #2c3845;
    --primary: #5aa9e6;
    --primary-text: #07121c;
    --ok-bg: #12301f;
    --ok: #6fd39a;
    --warn-bg: #3a2c05;
    --warn: #f5c451;
    --danger-bg: #3d1216;
    --danger: #ff8a8f;
    --info-bg: #13283a;
    --shadow: none;
  }
}

[data-contrast="high"] {
  --bg: #000;
  --surface: #000;
  --surface-2: #111;
  --text: #fff;
  --muted: #fff;
  --line: #fff;
  --primary: #ffd400;
  --primary-text: #000;
  --ok: #7dff9f;
  --ok-bg: #000;
  --warn: #ffd400;
  --warn-bg: #000;
  --danger: #ff6b6b;
  --danger-bg: #000;
  --info-bg: #000;
}
[data-contrast="high"] .card, [data-contrast="high"] .btn { border-width: 2px; }

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 16px/1.5 var(--font);
  background: var(--bg);
  color: var(--text);
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
}
a { color: var(--primary); }
[data-contrast="high"] a { color: #ffd400; }
h1 { font-size: 1.5rem; line-height: 1.25; margin: .25rem 0 1rem; }
h2 { font-size: 1.2rem; margin: 1.25rem 0 .5rem; }
h3 { font-size: 1.05rem; margin: 1rem 0 .4rem; }
p { margin: .4rem 0 .8rem; }
small, .muted { color: var(--muted); }
code, .mono { font-family: var(--mono); font-size: .92em; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.skip { position: absolute; left: -999px; top: 0; background: var(--surface); padding: .5rem 1rem; z-index: 10; }
.skip:focus { left: .5rem; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Top bar */
.topbar {
  display: flex; align-items: center; gap: 1rem; padding: .6rem 1rem;
  background: var(--primary); color: var(--primary-text); position: sticky; top: 0; z-index: 5;
}
.brand { display: flex; align-items: center; gap: .5rem; color: inherit; text-decoration: none; font-weight: 700; letter-spacing: .02em; }
.topnav { display: none; gap: .25rem; flex: 1; }
.topnav a { color: inherit; text-decoration: none; padding: .5rem .75rem; border-radius: 8px; }
.topnav a[aria-current="page"], .topnav a:hover { background: rgba(255, 255, 255, .15); }
.mode-pill { margin-left: auto; font-size: .8rem; border: 1px solid currentColor; border-radius: 999px; padding: .15rem .6rem; opacity: .9; }
.badge { display: inline-block; min-width: 1.4em; padding: 0 .4em; border-radius: 999px; background: var(--accent); color: #111; font-size: .78rem; font-weight: 700; text-align: center; }

/* Bottom tab bar (phones) */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 5;
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar a { display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 60px; font-size: .78rem; color: var(--muted); text-decoration: none; }
.tabbar a span[aria-hidden] { font-size: 1.3rem; line-height: 1.1; }
.tabbar a[aria-current="page"] { color: var(--primary); font-weight: 600; }
.tabbar .snap span[aria-hidden] { background: var(--primary); color: var(--primary-text); border-radius: 50%; width: 2.2rem; height: 2.2rem; display: grid; place-items: center; }

@media (min-width: 900px) {
  body { padding-bottom: 2rem; }
  .topnav { display: flex; }
  .tabbar { display: none; }
}

.app-main { max-width: 1180px; margin: 0 auto; padding: 1rem; }
.app-main.narrow, .narrow { max-width: 560px; margin-left: auto; margin-right: auto; }
.banner { padding: .7rem 1rem; text-align: center; }
.banner.warn { background: var(--warn-bg); color: var(--warn); }

/* Two panes on PC: ticket list beside the open ticket */
.split { display: block; }
.split .pane-list { display: none; }
@media (min-width: 900px) {
  .split { display: grid; grid-template-columns: 340px 1fr; gap: 1.25rem; align-items: start; }
  .split .pane-list { display: block; position: sticky; top: 70px; max-height: calc(100vh - 90px); overflow: auto; }
}

/* Cards and lists */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; margin-bottom: 1rem; box-shadow: var(--shadow); }
.card > h2:first-child, .card > h3:first-child { margin-top: 0; }
.card.ok { border-color: var(--ok); }
.card.warn { background: var(--warn-bg); border-color: var(--warn); }
.card.danger { background: var(--danger-bg); border-color: var(--danger); }
.card.info { background: var(--info-bg); }
.stack > * + * { margin-top: .75rem; }
.row { display: flex; gap: .75rem; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.grid2 { display: grid; gap: 1rem; }
@media (min-width: 700px) { .grid2 { grid-template-columns: 1fr 1fr; } }

.list { list-style: none; margin: 0; padding: 0; }
.list > li { border-bottom: 1px solid var(--line); }
.list > li:last-child { border-bottom: 0; }
.ticket-row { display: grid; grid-template-columns: 1fr auto; gap: .25rem .75rem; padding: .8rem .25rem; text-decoration: none; color: inherit; min-height: var(--tap); }
.ticket-row:hover { background: var(--surface-2); }
.ticket-row .title { font-weight: 600; }
.ticket-row .meta { color: var(--muted); font-size: .9rem; grid-column: 1 / -1; }
.ticket-row[aria-current="page"] { background: var(--surface-2); border-left: 4px solid var(--accent); }

.kv { display: grid; grid-template-columns: minmax(8rem, 38%) 1fr; gap: .35rem 1rem; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }

/* Status chips */
.chip { display: inline-flex; align-items: center; gap: .3rem; border-radius: 999px; padding: .1rem .6rem; font-size: .8rem; font-weight: 600; border: 1px solid var(--line); background: var(--surface-2); white-space: nowrap; }
.chip.rebuts, .chip.strong, .chip.ok { background: var(--ok-bg); color: var(--ok); border-color: var(--ok); }
.chip.neutral, .chip.moderate { background: var(--warn-bg); color: var(--warn); border-color: var(--warn); }
.chip.supports_city, .chip.weak, .chip.danger { background: var(--danger-bg); color: var(--danger); border-color: var(--danger); }
.chip.unproven { background: var(--surface-2); color: var(--muted); }
.chip.pending { border-style: dashed; }

/* Deadlines and money */
.countdown { font-weight: 700; }
.countdown.urgent { color: var(--danger); }
.deadline-list { list-style: none; padding: 0; margin: 0; }
.deadline-list li { display: grid; grid-template-columns: 1fr auto; gap: .1rem 1rem; padding: .55rem 0; border-bottom: 1px dashed var(--line); }
.deadline-list li.rights .label { font-weight: 600; }
.deadline-list li.passed { opacity: .6; }
.deadline-list .basis { grid-column: 1 / -1; font-size: .82rem; color: var(--muted); }
.money { font-variant-numeric: tabular-nums; font-weight: 700; }
.big-number { font-size: 2rem; font-weight: 800; line-height: 1.1; }
.hero { display: grid; gap: .25rem; padding: 1rem; border-radius: var(--radius); background: var(--primary); color: var(--primary-text); margin-bottom: 1rem; }
.hero a { color: inherit; }
.hero .muted { color: inherit; opacity: .85; font-weight: 600; }

/* Buttons and forms */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  min-height: var(--tap); padding: .6rem 1.1rem; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
}
.btn:hover { background: var(--surface-2); }
.btn-primary { background: var(--primary); color: var(--primary-text); border-color: var(--primary); }
.btn-primary:hover { filter: brightness(1.08); background: var(--primary); }
.btn-danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-small { min-height: 36px; padding: .3rem .7rem; font-size: .9rem; }
.btn[disabled], .btn[aria-disabled="true"] { opacity: .5; pointer-events: none; }
.btn-block { width: 100%; }
form.inline { display: inline; }

.actions-bar { display: flex; gap: .6rem; flex-wrap: wrap; margin: 1rem 0; }
@media (max-width: 899px) {
  /* Primary actions sit in the thumb zone above the tab bar. */
  .actions-bar.sticky {
    position: sticky; bottom: calc(66px + env(safe-area-inset-bottom)); z-index: 4;
    background: var(--bg); padding: .6rem 0; margin: 0 -1rem; padding-left: 1rem; padding-right: 1rem; border-top: 1px solid var(--line);
  }
  .actions-bar.sticky .btn { flex: 1; }
}

label { display: block; font-weight: 600; margin: .75rem 0 .3rem; }
label.inline { display: flex; align-items: center; gap: .5rem; font-weight: 500; }
input[type="text"], input[type="email"], input[type="tel"], input[type="date"], input[type="time"], input[type="number"], input[type="url"], input[type="password"], select, textarea {
  width: 100%; min-height: var(--tap); padding: .55rem .7rem; border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface); color: var(--text); font: inherit;
}
textarea { min-height: 7rem; resize: vertical; }
input[type="checkbox"], input[type="radio"] { width: 1.3rem; height: 1.3rem; }
.hint { font-size: .88rem; color: var(--muted); margin-top: .2rem; }
fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: .5rem 1rem 1rem; margin: 0 0 1rem; }
legend { font-weight: 700; padding: 0 .4rem; }

/* Field confirmation */
.field-row { display: grid; grid-template-columns: 1fr auto; gap: .25rem .75rem; align-items: end; padding: .6rem 0; border-bottom: 1px solid var(--line); }
.field-row.low { background: var(--warn-bg); margin: 0 -1rem; padding-left: 1rem; padding-right: 1rem; }
.field-row .ocr { grid-column: 1 / -1; font-size: .82rem; color: var(--muted); }
.field-row.confirmed .confirm-btn { color: var(--ok); border-color: var(--ok); }

/* Evidence */
.thumb-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .75rem; }
.thumb { border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--surface-2); }
.thumb img { width: 100%; height: 130px; object-fit: cover; display: block; }
.thumb .doc { height: 130px; display: grid; place-items: center; font-size: 2rem; color: var(--muted); }
.thumb .cap { padding: .4rem .5rem; font-size: .85rem; }
.fact { padding: .6rem 0; border-bottom: 1px dashed var(--line); }
.fact:last-child { border-bottom: 0; }
.fact .src { font-size: .8rem; color: var(--muted); }
.element-group { margin-bottom: 1rem; }
.request { display: grid; gap: .5rem; padding: .75rem; border-radius: 10px; background: var(--info-bg); margin-bottom: .6rem; }

/* Draft review */
.sentence { padding: .5rem .6rem; border-left: 4px solid var(--ok); background: var(--surface); margin: .35rem 0; border-radius: 0 8px 8px 0; }
.sentence.rewritten { border-left-color: var(--warn); }
.sentence.removed { border-left-color: var(--danger); opacity: .65; text-decoration: line-through; }
.sentence .cites { margin-top: .25rem; display: flex; gap: .3rem; flex-wrap: wrap; }
.exhibit-tag { font-family: var(--mono); font-size: .78rem; padding: 0 .4rem; border-radius: 6px; background: var(--surface-2); border: 1px solid var(--line); text-decoration: none; color: var(--text); }
.sentence .note { font-size: .82rem; color: var(--warn); }
.sentence textarea { min-height: 4rem; margin-top: .3rem; }

/* Assist step panel: designed to sit beside the City tab in a narrow window */
.stepper { list-style: none; padding: 0; margin: 0; counter-reset: step; }
.step { border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: .75rem; background: var(--surface); }
.step > summary { list-style: none; cursor: pointer; padding: .8rem 1rem; font-weight: 700; display: flex; gap: .6rem; align-items: center; min-height: var(--tap); }
.step > summary::before { counter-increment: step; content: counter(step); display: grid; place-items: center; width: 1.8rem; height: 1.8rem; border-radius: 50%; background: var(--surface-2); flex: none; }
.step.done > summary::before { content: "✓"; background: var(--ok-bg); color: var(--ok); }
.step[open] > summary { border-bottom: 1px solid var(--line); }
.step .body { padding: .75rem 1rem; }
.copy-field { display: grid; grid-template-columns: 1fr auto; gap: .2rem .6rem; align-items: center; padding: .5rem 0; border-bottom: 1px dashed var(--line); }
.copy-field .label { font-size: .85rem; color: var(--muted); grid-column: 1 / -1; }
.copy-field .value { font-family: var(--mono); overflow-wrap: anywhere; white-space: pre-wrap; max-height: 12rem; overflow: auto; }
.copy-btn.copied { background: var(--ok-bg); color: var(--ok); border-color: var(--ok); }
.copy-btn.copied::after { content: " ✓"; }

/* Live view */
.live-view { display: grid; gap: .75rem; }
.live-view canvas { width: 100%; height: auto; background: #000; border-radius: 10px; touch-action: none; }
.live-controls { display: flex; gap: .5rem; flex-wrap: wrap; }

/* Capture */
.capture { position: relative; border-radius: var(--radius); overflow: hidden; background: #000; aspect-ratio: 3 / 4; max-height: 70vh; margin: 0 auto; }
@media (min-width: 900px) { .capture { aspect-ratio: 4 / 3; } }
.capture video, .capture canvas { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.drop-zone { border: 2px dashed var(--line); border-radius: var(--radius); padding: 1.25rem; text-align: center; color: var(--muted); }
.drop-zone.dragover { border-color: var(--primary); background: var(--info-bg); }
.queue { list-style: none; padding: 0; display: grid; gap: .5rem; }
.queue li { display: flex; gap: .6rem; align-items: center; }
.queue img { width: 56px; height: 56px; object-fit: cover; border-radius: 8px; }

/* Payment */
.pay-amount { font-size: 2.4rem; font-weight: 800; }
.pay-warning { font-weight: 700; color: var(--danger); }

/* QR linking */
.qr { background: #fff; padding: .75rem; border-radius: 10px; display: inline-block; }
.qr svg { width: 220px; height: 220px; display: block; }
.code { font-family: var(--mono); font-size: 1.8rem; letter-spacing: .15em; font-weight: 800; }

/* Tables */
table { border-collapse: collapse; width: 100%; }
th, td { text-align: left; padding: .5rem .4rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: .85rem; color: var(--muted); font-weight: 600; }
.table-scroll { overflow-x: auto; }

.empty { text-align: center; padding: 2rem 1rem; color: var(--muted); }
#toast { position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: var(--text); color: var(--bg); padding: .6rem 1rem; border-radius: 10px; opacity: 0; transition: opacity .2s; pointer-events: none; z-index: 20; }
#toast.show { opacity: 1; }
.htmx-indicator { display: none; }
.htmx-request .htmx-indicator, .htmx-request.htmx-indicator { display: inline; }
.spinner { display: inline-block; width: 1rem; height: 1rem; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; vertical-align: -2px; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation: none; } #toast { transition: none; } }
details > summary { cursor: pointer; }
.pre { white-space: pre-wrap; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.mt0 { margin-top: 0; }

/* Script-toggled elements stay hidden even when a class sets display. */
[hidden] { display: none !important; }
/* Long unbroken strings (links, hashes, URLs) wrap instead of widening the page. */
.mono, .src, .card li, .card dd, .card p, .hint { overflow-wrap: anywhere; }
