/* ZIMFIC design system — shared by the public site, member account and admin.
   Probfix type (Space Grotesk / Inter / IBM Plex Mono) and palette, flat:
   no gradients, one token per colour, every text/background pair ≥ WCAG AA. */

/* ---------- Tokens ---------- */

:root {
  color-scheme: light;

  /* Surfaces */
  --bg: #EEF0F4;          /* page */
  --surface: #FFFFFF;     /* cards, fields */
  --surface-2: #F6F8FA;   /* wells, table heads, hover */
  --line: #DFE3EB;        /* hairlines */
  --line-2: #CBD2DE;      /* field borders, strong dividers */

  /* Ink — contrast on --surface: 17.6 / 8.4 / 6.5 */
  --text: #101423;
  --text-2: #454D63;
  --text-3: #565E70;

  /* Brand */
  --accent: #076F94;      /* text and fills under white text: ≥ 4.96:1 on every surface */
  --accent-hover: #065A78;
  --accent-soft: #E6F4F9; /* tinted background; --accent text on it is 5.0:1 */
  --accent-line: #14AEDF; /* decoration only: focus rings, bars, borders */
  --navy: #0F163A;        /* dark surfaces */
  --on-navy: #FFFFFF;
  --on-navy-2: #C9D1E6;   /* 11.9:1 on navy */
  --on-navy-accent: #7FD9F4;

  /* Status */
  --ok: #0B7B55;      --ok-soft: #E4F3EC;
  --danger: #C92A2A;  --danger-soft: #FBEAEA;
  --warn: #A34D08;    --warn-soft: #FBEFE3;

  /* Data (validated categorical order; first three CVD-safe all-pairs) */
  --s1: #0E96C2;
  --s2: #3B4BA8;
  --s3: #E4572E;

  /* Type */
  --display: "Space Grotesk", Inter, system-ui, sans-serif;
  --sans: Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  /* Space (4px grid), radius, motion */
  --sp-1: 4px; --sp-2: 8px; --sp-3: 12px; --sp-4: 16px; --sp-5: 20px; --sp-6: 24px; --sp-8: 32px;
  --r-sm: 8px; --r: 10px; --r-lg: 14px;
  --control: 44px;          /* one height for every field, button and choice */
  --ease: cubic-bezier(.2, .7, .2, 1);
  --shadow-pop: 0 12px 32px rgba(16, 20, 35, .16);
}

/* ---------- Base ---------- */

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; font-family: var(--sans); font-size: 15px; line-height: 1.5; color: var(--text); background: var(--bg);
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
}
h1, h2, h3, h4 { font-family: var(--display); font-weight: 700; letter-spacing: -.02em; line-height: 1.15; margin: 0; text-wrap: balance; }
p { margin: 0; text-wrap: pretty; }
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }
img, svg { display: block; }
[hidden] { display: none !important; }
::selection { background: var(--accent); color: #fff; }
:focus-visible { outline: 2px solid var(--accent-line); outline-offset: 2px; }

/* ---------- Icons (sprite: /assets/icons.svg) ---------- */

.i { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.i-sm { width: 16px; height: 16px; }

/* ---------- Brand ---------- */

.brand { display: inline-flex; align-items: center; gap: var(--sp-2); text-decoration: none; color: inherit; }
.brand-mark {
  width: 32px; height: 32px; flex: none; border-radius: var(--r-sm); display: grid; place-items: center;
  background: var(--accent); color: #fff; font-family: var(--display); font-weight: 700; font-size: 16px;
}
.brand-name { font-family: var(--display); font-weight: 700; font-size: 15px; letter-spacing: .06em; }
.brand-sub { font-size: 12px; color: var(--text-3); line-height: 1.2; }

/* ---------- Text roles ---------- */

.eyebrow { font-family: var(--mono); font-size: 11px; font-weight: 600; letter-spacing: .1em; text-transform: uppercase; color: var(--accent); }
.hint { color: var(--text-2); }
.link { background: none; border: 0; padding: 0; color: var(--accent); font-weight: 600; cursor: pointer; text-decoration: none; }
.link:hover { color: var(--accent-hover); text-decoration: underline; text-underline-offset: 3px; }

/* ---------- Fields ---------- */

.fields { display: grid; gap: 14px; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-3); }
.row-house { grid-template-columns: 96px 1fr; }
.field { display: grid; gap: 6px; min-width: 0; }
.label { font-size: 13px; font-weight: 600; color: var(--text-2); }
.optional { font-weight: 400; color: var(--text-3); margin-left: 2px; }

/* 16px text keeps iOS Safari from zooming on focus */
.input {
  width: 100%; height: var(--control); padding: 0 var(--sp-3); font-size: 16px;
  background: var(--surface); border: 1px solid var(--line-2); border-radius: var(--r);
  outline: none; -webkit-appearance: none; appearance: none; transition: border-color .15s, box-shadow .15s;
}
textarea.input { height: auto; min-height: 104px; padding: 10px var(--sp-3); resize: vertical; line-height: 1.5; }
select.input {
  padding-right: 36px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' fill='none'%3E%3Cpath d='M1 1.5l5 5 5-5' stroke='%23565E70' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center;
}
.input[type="date"] { line-height: calc(var(--control) - 2px); }
.input::placeholder { color: #6B7385; }
.input:hover { border-color: #AEB7C7; }
.input:focus { border-color: var(--accent-line); box-shadow: 0 0 0 3px rgba(20, 174, 223, .18); }
.field.invalid .input { border-color: var(--danger); box-shadow: 0 0 0 3px rgba(201, 42, 42, .1); }
.error-text { display: none; font-size: 13px; color: var(--danger); }
.field.invalid .error-text { display: block; }

.input-icon { position: relative; }
.input-icon > svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--text-3); pointer-events: none; }
.input-icon > .input { padding-left: 40px; }
.input-icon > .input.has-action { padding-right: 68px; }
.input-action {
  position: absolute; right: 4px; top: 4px; height: calc(var(--control) - 8px); padding: 0 var(--sp-3);
  border: 0; border-radius: var(--r-sm); background: var(--surface-2); color: var(--text-2); font-size: 13px; font-weight: 600; cursor: pointer;
}

/* ---------- Choices (radio / checkbox as tiles) ---------- */

.choices { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--sp-2); }
.choice { position: relative; min-width: 0; }
.choice input { position: absolute; opacity: 0; pointer-events: none; }
.choice > span {
  display: flex; align-items: center; gap: var(--sp-2); height: 100%; min-height: var(--control); padding: 8px var(--sp-3);
  border: 1px solid var(--line-2); border-radius: var(--r); background: var(--surface); cursor: pointer;
  font-size: 14px; font-weight: 500; line-height: 1.25; white-space: nowrap; transition: border-color .15s, background .15s;
}
.choice > span:hover { border-color: #AEB7C7; }
/* Label and hint sit on one line: hint pushed to the right edge */
.choice > span > span { display: flex; align-items: baseline; justify-content: space-between; gap: var(--sp-2); width: 100%; min-width: 0; }
.choice small { font-size: 12px; font-weight: 400; color: var(--text-3); overflow: hidden; text-overflow: ellipsis; }
.choice input:checked + span { border-color: var(--accent); background: var(--accent-soft); box-shadow: inset 0 0 0 1px var(--accent); }
.choice input:focus-visible + span { outline: 2px solid var(--accent-line); outline-offset: 2px; }
.field.invalid .choice > span { border-color: #E3A3A3; }
.choices.center { display: flex; flex-wrap: wrap; }
.choices.center .choice { flex: 1 1 0; min-width: max-content; }
.choices.center .choice > span { justify-content: center; }

.check { display: flex; gap: var(--sp-3); align-items: flex-start; padding: var(--sp-3); border-radius: var(--r); background: var(--surface-2); font-size: 14px; color: var(--text-2); cursor: pointer; }
.check input { width: 18px; height: 18px; margin: 2px 0 0; flex: none; accent-color: var(--accent); }
.field.invalid .check { box-shadow: inset 0 0 0 1px var(--danger); }

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2);
  height: var(--control); padding: 0 var(--sp-5); border-radius: var(--r); border: 1px solid transparent;
  font-size: 15px; font-weight: 600; white-space: nowrap; text-decoration: none; cursor: pointer;
  transition: background .15s, border-color .15s, color .15s;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--line-2); }
.btn-secondary:hover { border-color: var(--text-3); }
.btn-ghost { background: transparent; color: var(--text-2); padding: 0 var(--sp-3); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-block { width: 100%; }
.btn-sm { height: 36px; padding: 0 var(--sp-3); font-size: 14px; }
.btn[disabled] { opacity: .65; cursor: progress; }
.icon-btn {
  width: 36px; height: 36px; flex: none; display: grid; place-items: center; border-radius: var(--r-sm);
  border: 1px solid var(--line); background: var(--surface); color: var(--text-2); cursor: pointer;
}
.icon-btn:hover { color: var(--text); border-color: var(--line-2); }

.spinner { width: 16px; height: 16px; flex: none; border-radius: 50%; border: 2px solid rgba(255, 255, 255, .4); border-top-color: #fff; animation: spin .8s linear infinite; }
.spinner.dark { border-color: var(--line); border-top-color: var(--accent); width: 22px; height: 22px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Surfaces ---------- */

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: var(--sp-4); min-width: 0; }
.alert { padding: 10px var(--sp-3); border-radius: var(--r); background: var(--danger-soft); color: var(--danger); font-size: 14px; }
.notice { display: flex; gap: var(--sp-2); padding: 10px var(--sp-3); border-radius: var(--r); background: var(--accent-soft); color: var(--text-2); font-size: 13px; }
.chip { display: inline-flex; align-items: center; height: 22px; padding: 0 var(--sp-2); border-radius: 999px; background: var(--accent-soft); color: var(--accent-hover); font-size: 12px; font-weight: 600; white-space: nowrap; }
.chip.ok { background: var(--ok-soft); color: var(--ok); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.empty { padding: var(--sp-5) var(--sp-3); text-align: center; color: var(--text-3); font-size: 14px; }
.loading { display: grid; place-items: center; min-height: 240px; }

/* ---------- Bottom sheet / dialog ---------- */

.sheet { position: fixed; inset: 0; z-index: 100; display: flex; align-items: flex-end; justify-content: center; }
.sheet-bg { position: absolute; inset: 0; background: rgba(16, 20, 35, .5); animation: fade .2s both; }
.sheet-panel {
  position: relative; display: flex; flex-direction: column; width: 100%; max-width: 560px; max-height: calc(100dvh - 16px);
  background: var(--surface); border-radius: var(--r-lg) var(--r-lg) 0 0; overflow: hidden; animation: rise .28s var(--ease) both;
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); padding: var(--sp-3) var(--sp-4); border-bottom: 1px solid var(--line); }
.sheet-head h2 { font-size: 18px; }
.sheet-body { flex: 1; overflow-y: auto; overscroll-behavior: contain; padding: var(--sp-4); background: var(--surface); }
.sheet-foot { display: flex; gap: var(--sp-2); padding: var(--sp-3) var(--sp-4) calc(var(--sp-3) + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); }
.sheet-foot .btn { flex: 1; }
@media (min-width: 640px) {
  .sheet { align-items: center; padding: var(--sp-6); }
  .sheet-panel { border-radius: var(--r-lg); max-height: calc(100vh - 48px); box-shadow: var(--shadow-pop); }
}

.toast {
  position: fixed; left: 50%; bottom: calc(var(--sp-5) + env(safe-area-inset-bottom)); z-index: 200; transform: translateX(-50%);
  display: flex; align-items: center; gap: var(--sp-2); width: max-content; max-width: calc(100% - 32px);
  padding: 10px var(--sp-4); border-radius: var(--r); background: var(--navy); color: #fff; font-size: 14px; font-weight: 500;
  box-shadow: var(--shadow-pop); animation: rise .25s var(--ease) both;
}

@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes rise { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
.toast { animation-name: toast; }
@keyframes toast { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; } }

@media (max-width: 480px) {
  .row { grid-template-columns: 1fr; }
  .row.row-house { grid-template-columns: 88px 1fr; }
}

/* ---------- Utilities ---------- */

.mt-3 { margin-top: var(--sp-3); }
