/* Urvalskalkyl — app styles.
 *
 * The visual language is the TCB brand profile (brand/design-profile.md): warm paper
 * tones, petrol accent, Lora for headings, Karla for body — both self-hosted from
 * /shared/fonts (font-src 'self'; no off-origin request, ever).
 *
 * Responsive strategy (app-ux-guide.md §3): mobile-first base styles, desktop layered
 * on with min-width queries, so resizing a window keeps working. Input is detected
 * separately from size: (pointer: fine) tightens control heights for a mouse,
 * (hover: hover) is the only place hover effects live, and :active gives touch its
 * feedback. Type and spacing scale fluidly with clamp() instead of jumping at the
 * breakpoint.
 *
 * Contrast: every text/background pair below is >= 4.5:1 in both colour schemes
 * (verified with the script in brand/design-profile.md §3). --amber never carries
 * body text on light. Nothing carries meaning by colour alone — every danger colour
 * is paired with a word.
 */

/* ── tokens ───────────────────────────────────────────────────────────────── */

:root {
  --bg:          #f6f2ea;
  --surface:     #fdfbf7;
  --surface-2:   #efe9dd;
  --ink:         #16191c;
  --ink-2:       #3f454b;
  --line:        #d8d0bf;
  --line-2:      #e5dfd2;
  --accent:      #0f4f5e;
  --accent-hover:#0b3d49;
  --accent-ink:  #ffffff;
  --accent-2:    #e4eef0;
  --amber:       #a8763e;   /* decoration and hairlines only — 3.5:1 on paper, never body text */
  --danger:      #93000e;
  --danger-bg:   #fbeceb;
  --warn:        #6a4a00;
  --warn-bg:     #f9f0d8;
  --ok:          #1c5c30;

  --radius: 10px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(28, 24, 18, .05), 0 1px 6px rgba(28, 24, 18, .04);
  --tap: 44px;
  --gap: clamp(1rem, 0.8rem + 1vw, 1.5rem);
  --pad: clamp(1rem, 0.7rem + 1.5vw, 1.75rem);
  --measure: 34rem;

  --font: "Karla", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-display: "Lora", Georgia, "Times New Roman", serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  /* the shared widgets (ui.css) follow the app's face — this app chooses the brand body font */
  --ui-font: var(--font);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:          #121517;
    --surface:     #1a1f22;
    --surface-2:   #242b2f;
    --ink:         #ece8df;
    --ink-2:       #c2bcb0;
    --line:        #454d52;
    --line-2:      #2e3538;
    --accent:      #7fc2d4;
    --accent-hover:#9ed3e2;
    --accent-ink:  #0b2830;
    --accent-2:    #1c3138;
    --amber:       #d9a869;
    --danger:      #ff9a95;
    --danger-bg:   #3a1b1b;
    --warn:        #f0cf7a;
    --warn-bg:     #362d12;
    --ok:          #86d79b;
    --shadow: 0 1px 2px rgba(0, 0, 0, .35), 0 1px 8px rgba(0, 0, 0, .25);
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 1rem;
  line-height: 1.55;
  color: var(--ink);
  background: var(--bg);
}

h1, h2, h3 {
  font-family: var(--font-display);
  font-weight: 600;
  line-height: 1.2;
  margin: 0 0 .5rem;
  text-wrap: balance;
}
h1 { font-size: clamp(1.55rem, 1.2rem + 1.6vw, 2.1rem); }
h2 { font-size: clamp(1.25rem, 1.1rem + 0.7vw, 1.5rem); }
h3 { font-size: 1.1rem; }
p  { margin: 0 0 .75rem; text-wrap: pretty; }

:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}

.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;
}

.skip-link {
  position: absolute; left: .5rem; top: -4rem; z-index: 100;
  background: var(--surface); color: var(--ink);
  padding: .6rem .9rem; border: 2px solid var(--accent); border-radius: var(--radius);
}
.skip-link:focus { top: .5rem; }

.noscript { max-width: var(--measure); margin: 2rem auto; padding: 0 1rem; }
.boot { padding: 2rem var(--pad); color: var(--ink-2); }

/* ── app bar ──────────────────────────────────────────────────────────────── */

.appbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: .5rem 1rem;
  padding: .65rem var(--pad);
  background: var(--surface);
  border-bottom: 1px solid var(--line-2);
}
.appbar__name {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.15rem;
  color: var(--accent-hover);
  display: flex; align-items: center; gap: .55rem;
}
/* the brand mark rides along as a decorative image; the name carries the meaning */
.appbar__name::before {
  content: "";
  flex: 0 0 auto;
  width: 26px; height: 26px;
  background: url("/favicon.svg") center / contain no-repeat;
}
.appbar__name small {
  display: block;
  font-family: var(--font);
  font-weight: 400; font-size: .8rem;
  color: var(--ink-2);
}
.appbar__spacer { flex: 1 1 auto; }
.appbar__tools { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; }

/* ── save bar: permanent, never in a menu (app-data-guide.md Rule 6) ─────── */

.savebar {
  display: flex; flex-wrap: wrap; align-items: center; gap: .5rem .75rem;
  padding: .55rem var(--pad);
  background: var(--surface-2);
  border-bottom: 1px solid var(--line-2);
}
.savebar__line { margin: 0; font-size: .95rem; }
.savebar__line[data-danger="true"],
.savestate[data-danger="true"] { color: var(--danger); font-weight: 600; }
.savebar__actions { display: flex; flex-wrap: wrap; gap: .5rem; margin-left: auto; }

/* ── banners ──────────────────────────────────────────────────────────────── */

.banner {
  margin: .75rem var(--pad) 0;
  padding: .8rem 1rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-size: .95rem;
}
.banner p:last-child { margin-bottom: 0; }
.banner--lapsed { background: var(--danger-bg); color: var(--ink); border-color: var(--danger); }
.banner--unknown { background: var(--warn-bg); color: var(--ink); border-color: var(--warn); }
.banner--dev { background: var(--danger-bg); color: var(--ink); border-color: var(--danger); font-family: var(--mono); font-size: .85rem; }
.banner--first-run { background: var(--accent-2); border-color: var(--accent); }
.banner__actions { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .5rem; }

/* ── layout ───────────────────────────────────────────────────────────────── */

main {
  padding: var(--gap) var(--pad) 7rem;   /* room for the phone's fixed primary action */
  max-width: 68rem;
  margin: 0 auto;
}

.stack > * + * { margin-top: var(--gap); }
.prose { max-width: var(--measure); }
.muted { color: var(--ink-2); }
.small { font-size: .9rem; }

.card {
  background: var(--surface);
  border: 1px solid var(--line-2);
  border-radius: var(--radius);
  padding: var(--pad);
  box-shadow: var(--shadow);
}
.card + .card { margin-top: .75rem; }
.card__title { display: flex; flex-wrap: wrap; gap: .5rem; align-items: baseline; }
.card__title h3 { margin: 0; }
.card__meta { color: var(--ink-2); font-size: .9rem; margin: .25rem 0 .5rem; }
.card__actions { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .75rem; }

.cards { list-style: none; margin: 0; padding: 0; }

/* ── controls ─────────────────────────────────────────────────────────────── */

button, .btn {
  font: inherit;
  font-weight: 600;
  min-height: var(--tap);
  padding: .55rem 1.1rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
}
button:disabled { opacity: .55; cursor: not-allowed; }
/* touch gets its feedback on press — a finger covers the target (UXPin, touch design) */
button:active:not(:disabled) { transform: translateY(1px); }

.btn--primary, .ui-btn--primary {
  background: var(--accent); color: var(--accent-ink); border-color: var(--accent);
}
.btn--danger { color: var(--danger); border-color: var(--danger); }
.btn--quiet { border-color: transparent; background: transparent; text-decoration: underline; }

.linklike {
  background: none; border: none; padding: 0; min-height: 0; font-weight: 400;
  color: var(--accent); text-decoration: underline; cursor: pointer; font: inherit;
}

/* hover exists only where the input can hover — a touchscreen never sees these */
@media (hover: hover) {
  button:hover:not(:disabled) { background: var(--surface-2); }
  .btn--primary:hover:not(:disabled), .ui-btn--primary:hover:not(:disabled) {
    background: var(--accent-hover); border-color: var(--accent-hover);
  }
  .btn--danger:hover:not(:disabled) { background: var(--danger-bg); }
  .linklike:hover { color: var(--accent-hover); }
}

/* a mouse needs less height than a finger; a coarse pointer keeps the full 44 px */
@media (pointer: fine) {
  button, .btn { min-height: 2.5rem; }
}

/* ── fields: label, persistent helper, unit in the field, format by example ─ */

.field { margin: 0 0 1.25rem; max-width: var(--measure); }
.field__label { display: block; font-weight: 600; margin-bottom: .15rem; }
.field__help { margin: 0 0 .35rem; font-size: .9rem; color: var(--ink-2); }
.field__wrap { display: flex; align-items: stretch; }
.field input, .field select, .field textarea {
  font: inherit;
  width: 100%;
  min-height: var(--tap);
  padding: .5rem .65rem;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}
.field textarea { min-height: 6rem; resize: vertical; }
.field__wrap:has(.field__unit) input { border-radius: var(--radius-sm) 0 0 var(--radius-sm); }
.field__unit {
  display: flex; align-items: center; padding: 0 .7rem;
  border: 1px solid var(--line); border-left: 0;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  background: var(--surface-2); color: var(--ink-2); white-space: nowrap;
}
.field__example { margin: .3rem 0 0; font-size: .85rem; color: var(--ink-2); }
.field__error { margin: .3rem 0 0; font-size: .9rem; color: var(--danger); font-weight: 600; }
.field input[aria-invalid="true"], .field select[aria-invalid="true"] { border-color: var(--danger); border-width: 2px; }
.field input:disabled, .field select:disabled, .field textarea:disabled {
  background: var(--surface-2); color: var(--ink-2); cursor: not-allowed;
}
.field__locked,
.field__note { margin: .3rem 0 0; font-size: .85rem; color: var(--ink-2); }

fieldset { border: 1px solid var(--line-2); border-radius: var(--radius); padding: .75rem 1rem; margin: 0 0 1rem; background: var(--surface); }
legend { font-weight: 600; padding: 0 .35rem; }

/* ── flags: the number and its explanation are one object ─────────────────── */

.flags { list-style: none; margin: .5rem 0 0; padding: 0; }
.flag {
  display: block;
  margin: .4rem 0 0;
  padding: .6rem .75rem;
  background: var(--warn-bg);
  border: 1px solid var(--warn);
  border-radius: var(--radius-sm);
  font-size: .92rem;
}
.flag__id { font-family: var(--mono); font-size: .8rem; color: var(--ink-2); }

/* ── figures ──────────────────────────────────────────────────────────────── */

.figure { background: var(--surface); border: 1px solid var(--line-2); border-radius: var(--radius); padding: 1rem; box-shadow: var(--shadow); }
.figure__label { margin: 0; font-size: .95rem; color: var(--ink-2); }
.figure__value {
  margin: .1rem 0 0;
  font-family: var(--font-display);
  font-size: clamp(1.75rem, 1.4rem + 1.5vw, 2.25rem);
  font-weight: 600;
  font-variant-numeric: tabular-nums lining-nums;
}
.figure__value--none { font-family: var(--font); font-size: 1.1rem; font-weight: 600; color: var(--ink-2); }
.figure__value--sm { font-size: 1.2rem; }
.figure__note { margin: .4rem 0 0; font-size: .9rem; color: var(--ink-2); }

.kv { margin: 0; }
.kv div { display: flex; gap: .75rem; justify-content: space-between; padding: .35rem 0; border-bottom: 1px solid var(--line-2); }
.kv dt { color: var(--ink-2); }
.kv dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }

/* ── stepper ──────────────────────────────────────────────────────────────── */

.stepper__position { font-weight: 600; margin: 0 0 .25rem; color: var(--ink-2); }
.stepper__bar { list-style: none; display: flex; flex-wrap: wrap; gap: .35rem; margin: 0 0 1rem; padding: 0; }
.stepper__bar li { flex: 1 1 6rem; }
.stepper__bar button {
  width: 100%; min-height: var(--tap); padding: .35rem .5rem; font-size: .85rem;
  border-radius: var(--radius-sm); border: 1px solid var(--line); background: var(--surface);
}
.stepper__bar [aria-current="step"] {
  background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600;
}
.stepper__nav { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: 1.5rem; }
.stepper__body { display: flex; flex-direction: column; gap: 1.25rem; }
.stepper__body fieldset {
  border: 1px solid var(--line-2); border-radius: var(--radius);
  margin: 0 0 .75rem; padding: .75rem .9rem 1rem;
  background: var(--surface);
}
.stepper__body legend { font-weight: 600; padding: 0 .35rem; }

/* A finger is not a mouse pointer: every target it has to hit is at least 44 px tall, with
 * real space around it (app-ux-guide.md §3). Measured, not assumed — the link-shaped
 * buttons are the ones that fall short otherwise. Both conditions are listed because a
 * phone is narrow *and* coarse, and a touchscreen laptop is only coarse. */
@media (max-width: 720px), (pointer: coarse) {
  .stepper__bar { gap: .5rem; }
  .linklike { display: inline-flex; align-items: center; min-height: var(--tap); }
}

/* the phone's primary action sits in thumb reach and never scrolls away */
.thumbbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; gap: .5rem;
  padding: .6rem var(--pad) calc(.6rem + env(safe-area-inset-bottom));
  background: var(--surface);
  border-top: 1px solid var(--line-2);
  box-shadow: 0 -2px 10px rgba(28, 24, 18, .07);
}
.thumbbar button { flex: 1 1 auto; }
.thumbbar .btn--primary { flex: 2 1 auto; }
/* the fixed bar must not cover the last field on a phone */
.stepper__body { padding-bottom: 4.5rem; }

/* A value that is not filled in is never blank and never zero — it says so, and it says
 * so in a shape as well as a colour, because information may not be carried by colour
 * alone (app-ux-guide.md §7). */
.missing { color: var(--danger); font-weight: 600; font-style: italic; }

/* ── review ───────────────────────────────────────────────────────────────── */

.review { max-width: var(--measure); }
.review dl { margin: 0 0 1rem; }
.review .missing { color: var(--danger); font-weight: 600; }

/* ── dialog ───────────────────────────────────────────────────────────────── */

dialog {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  padding: 1.25rem;
  max-width: min(34rem, calc(100vw - 2rem));
  width: 100%;
  box-shadow: 0 8px 30px rgba(15, 15, 10, .25);
}
dialog::backdrop { background: rgb(20 16 8 / .5); }
dialog .card__actions { justify-content: flex-end; }

/* ── tables: cards on a phone, a table on a computer ──────────────────────── */

.datatable { display: none; }
.datatable table { border-collapse: collapse; width: 100%; }
.datatable th, .datatable td { text-align: left; padding: .45rem .6rem; border-bottom: 1px solid var(--line-2); }
.datatable td.num, .datatable th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ── desktop ──────────────────────────────────────────────────────────────── */

@media (min-width: 721px) {
  main { padding-bottom: 2rem; }
  .stepper__bar button { min-height: 2.6rem; }
  .thumbbar { position: static; border-top: 0; padding: 0; background: none; box-shadow: none; margin-top: 1.5rem; }
  .thumbbar button { flex: 0 0 auto; }
  .two-col { display: grid; grid-template-columns: minmax(0, 1fr) 20rem; gap: 1.5rem; align-items: start; }
  .datatable { display: block; overflow-x: auto; }
  .cards--collapsible { display: none; }
  .stepper__body { padding-bottom: 0; }
}

/* ── print: the filed artefact. Flags render in full, in place. ───────────── */

@media print {
  body { background: #fff; color: #000; }
  #app, .skip-link, #live { display: none !important; }
  #print-area { display: block !important; }
  #print-area { font-size: 11pt; }
  #print-area h1 { font-size: 18pt; }
  #print-area h2 { font-size: 13pt; margin-top: 1.2em; page-break-after: avoid; }
  #print-area .flag {
    background: none; border: 1pt solid #000; border-left: 3pt solid #000;
    padding: 4pt 6pt; page-break-inside: avoid;
  }
  #print-area .figure { border: 1pt solid #000; padding: 6pt; page-break-inside: avoid; }
  #print-area table { border-collapse: collapse; width: 100%; }
  #print-area th, #print-area td { border: .5pt solid #666; padding: 3pt 5pt; text-align: left; }
  #print-area td.num, #print-area th.num { text-align: right; }
  #print-area .printfoot { margin-top: 1.5em; border-top: .5pt solid #666; padding-top: .5em; font-size: 9pt; }
}

#print-area { display: none; }
