/* ============================================================================
   Modernist — the admin console's design system.

   The same system the iOS app is built on (ios/LifeAhead/DesignSystem/), ported
   to CSS so both surfaces read as one product. Its rules, from DS.swift:

     flat, Archivo throughout, zero corner radius anywhere, 2px rules,
     near-mono ink on a light ground with one red accent, everything flush
     left including button labels. No shadows on in-page surfaces, no
     gradients, no emoji, no icons.

   Light values come from design_handoff_life_ahead_ios/design/modernist-styles.css;
   dark values from ios/LifeAhead/Assets.xcassets/DS*.colorset, which is the only
   place the dark palette was ever authored.

   Self-contained: no framework, no build step, no CDN, no JavaScript beyond the
   theme switch in base.html.
   ============================================================================ */

@font-face {
  font-family: "Archivo";
  src: url("/static/fonts/Archivo-Regular.ttf") format("truetype");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Archivo";
  src: url("/static/fonts/Archivo-SemiBold.ttf") format("truetype");
  font-weight: 600;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Archivo";
  src: url("/static/fonts/Archivo-ExtraBold.ttf") format("truetype");
  font-weight: 800;
  font-style: normal;
  font-display: swap;
}

/* ---------- tokens ---------- */

:root {
  /* Archivo ships 400/600/800 in this product. There is no 500 or 700 — asking
     for one synthesises a face that does not match the app. */
  --font: "Archivo", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  --fs-micro: 11px;
  --fs-kicker: 12px;
  --fs-sm: 13px;
  --fs-base: 15px;
  --fs-h5: 16px;
  --fs-h4: 20px;
  --fs-h3: 25px;
  --fs-h2: 32px;
  --fs-h1: 42px;

  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-6: 24px;
  --sp-8: 32px;
  --sp-12: 48px;

  --rule: 2px;      /* between sections */
  --hairline: 1px;  /* between list rows */
  --gutter: 20px;
}

/* Three selectors, two palettes:
     :root / [data-theme=light]              → light
     [data-theme=dark]                       → dark, chosen explicitly
     prefers-color-scheme + :not([light])    → dark, following the system
   The dark values appear twice because a media query cannot be aliased to a
   selector. They must be edited together — the ordering below (media query
   last, equal specificity) is what makes an explicit choice beat the system. */

:root,
html[data-theme="light"] {
  --bg: #f3f2f2;
  --surface: #eae9e9;
  --ink: #201e1d;
  --on-accent: #f3f2f2;
  --accent: #ec3013;
  --accent-pressed: #dd2b0f;
  /* The accent-to-ground pair is only ~3.8:1 — enough for fields, icons and
     large type, NOT for body copy. Anything at paragraph size uses this. */
  --accent-text: #ae1800;
  --neutral-200: #eae7e7;
  --neutral-300: #d7d3d3;
  --neutral-500: #9b9797;

  /* Secondary colour is alpha over ink, per the design. */
  --divider: rgba(32, 30, 29, 0.40);
  --hairline-color: rgba(32, 30, 29, 0.18);
  --label-deemph: rgba(32, 30, 29, 0.45);
  --kicker: rgba(32, 30, 29, 0.55);
  --caption-muted: rgba(32, 30, 29, 0.50);
  --body-secondary: rgba(32, 30, 29, 0.65);
  --row-press: rgba(32, 30, 29, 0.05);

  color-scheme: light;
}

/* Dark alphas are bumped: light type on a dark ground reads optically
   thinner at the same value (DSColor.swift). */
html[data-theme="dark"] {
  --bg: #141313;
  --surface: #1e1d1d;
  --ink: #eceaea;
  --on-accent: #f3f2f2;
  --accent: #ec3013;
  --accent-pressed: #ff563c;
  --accent-text: #ff9783;
  --neutral-200: #2d2b2b;
  --neutral-300: #444141;
  --neutral-500: #605d5d;

  --divider: rgba(236, 234, 234, 0.40);
  --hairline-color: rgba(236, 234, 234, 0.24);
  --label-deemph: rgba(236, 234, 234, 0.52);
  --kicker: rgba(236, 234, 234, 0.62);
  --caption-muted: rgba(236, 234, 234, 0.58);
  --body-secondary: rgba(236, 234, 234, 0.72);
  --row-press: rgba(236, 234, 234, 0.08);

  color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
  html:not([data-theme="light"]) {
    --bg: #141313;
    --surface: #1e1d1d;
    --ink: #eceaea;
    --on-accent: #f3f2f2;
    --accent: #ec3013;
    --accent-pressed: #ff563c;
    --accent-text: #ff9783;
    --neutral-200: #2d2b2b;
    --neutral-300: #444141;
    --neutral-500: #605d5d;

    --divider: rgba(236, 234, 234, 0.40);
    --hairline-color: rgba(236, 234, 234, 0.24);
    --label-deemph: rgba(236, 234, 234, 0.52);
    --kicker: rgba(236, 234, 234, 0.62);
    --caption-muted: rgba(236, 234, 234, 0.58);
    --body-secondary: rgba(236, 234, 234, 0.72);
    --row-press: rgba(236, 234, 234, 0.08);

    color-scheme: dark;
  }
}

/* ---------- reset ---------- */

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: var(--fs-base);
  font-weight: 400;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

/* Zero radius. Everywhere. If you are reaching for a radius, reconsider. */
button, input, select, textarea, table, fieldset { border-radius: 0; }

img { display: block; max-width: 100%; }

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

::selection {
  background: var(--accent);
  color: var(--on-accent);
}

/* ---------- typography ---------- */

h1, h2, h3, h4, h5 {
  font-weight: 800;
  line-height: 1.12;
  letter-spacing: -0.015em;
  margin: 0 0 var(--sp-2);
}
h1 { font-size: var(--fs-h1); }
h2 { font-size: var(--fs-h2); }
h3 { font-size: var(--fs-h3); }
h4 { font-size: var(--fs-h4); }
h5 { font-size: var(--fs-h5); }

p { margin: 0 0 var(--sp-3); }

a {
  color: var(--accent-text);
  text-underline-offset: 3px;
}
a:hover { color: var(--accent); }

code, .mono { font-family: var(--font-mono); font-size: var(--fs-sm); }

/* Uppercase, tracked-out kickers label every block in the system. */
.kicker {
  display: block;
  font-size: var(--fs-kicker);
  font-weight: 800;
  letter-spacing: 0.10em;
  text-transform: uppercase;
  color: var(--kicker);
  margin: 0 0 var(--sp-2);
}
.kicker-note {
  font-size: var(--fs-micro);
  font-weight: 400;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--caption-muted);
}
.caption { font-size: var(--fs-sm); color: var(--body-secondary); }
.muted { color: var(--caption-muted); }
.micro { font-size: var(--fs-micro); color: var(--caption-muted); }
.numeric { font-variant-numeric: tabular-nums; }

/* ---------- layout ---------- */

.container {
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 var(--gutter) var(--sp-12);
}

.section {
  border-top: var(--rule) solid var(--divider);
  padding-top: var(--sp-4);
  margin-top: var(--sp-8);
}
.section:first-of-type { margin-top: var(--sp-6); }

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--sp-4);
  flex-wrap: wrap;
  margin-bottom: var(--sp-4);
}

.page-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--sp-4);
  flex-wrap: wrap;
  margin: var(--sp-6) 0 var(--sp-2);
}

.stack > * + * { margin-top: var(--sp-3); }
.row { display: flex; gap: var(--sp-3); align-items: center; flex-wrap: wrap; }
.push { margin-left: auto; }

/* ---------- nav ---------- */

.site-nav {
  display: flex;
  align-items: center;
  gap: var(--sp-6);
  flex-wrap: wrap;
  padding: var(--sp-4) 0;
  border-bottom: var(--rule) solid var(--divider);
}

.brand {
  display: inline-flex;
  align-items: baseline;
  gap: var(--sp-2);
  text-decoration: none;
  color: var(--ink);
}
.brand-mark {
  font-size: var(--fs-sm);
  font-weight: 800;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}
.brand-sub {
  font-size: var(--fs-micro);
  font-weight: 400;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--caption-muted);
}

.nav-links {
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  flex-wrap: wrap;
  list-style: none;
  margin: 0;
  padding: 0;
}
.nav-links a {
  font-size: var(--fs-micro);
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  text-decoration: none;
  color: var(--body-secondary);
  padding-bottom: 2px;
  border-bottom: var(--rule) solid transparent;
}
.nav-links a:hover { color: var(--ink); }
.nav-links a.active {
  color: var(--ink);
  border-bottom-color: var(--accent);
}
.nav-email {
  font-size: var(--fs-micro);
  letter-spacing: 0.04em;
  color: var(--caption-muted);
}

.nav-theme { display: inline-flex; border: var(--hairline) solid var(--hairline-color); }
.nav-theme button {
  font: inherit;
  font-size: var(--fs-micro);
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 3px var(--sp-2);
  background: transparent;
  color: var(--caption-muted);
  border: 0;
  cursor: pointer;
}
.nav-theme button + button { border-left: var(--hairline) solid var(--hairline-color); }
.nav-theme button[aria-pressed="true"] { background: var(--ink); color: var(--bg); }

/* ---------- buttons ---------- */
/* Flush left, uppercase, tracked. Never centred. */

.btn,
button[type="submit"],
button:not(.nav-theme button) {
  display: inline-block;
  font: inherit;
  font-size: var(--fs-sm);
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  text-align: left;
  text-decoration: none;
  padding: var(--sp-3) var(--sp-4);
  border: var(--rule) solid var(--ink);
  background: transparent;
  color: var(--ink);
  cursor: pointer;
}
.btn:hover,
button:not(.nav-theme button):hover { background: var(--row-press); }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
}
.btn-primary:hover { background: var(--accent-pressed); border-color: var(--accent-pressed); }

.btn-small { font-size: var(--fs-micro); padding: var(--sp-1) var(--sp-2); border-width: var(--hairline); }
.btn-danger { border-color: var(--accent); color: var(--accent-text); }
.btn-danger:hover { background: var(--accent); color: var(--on-accent); }

.btn:disabled, button:disabled { opacity: 0.45; cursor: not-allowed; }

/* ---------- forms ---------- */

label, .field-label {
  display: block;
  font-size: var(--fs-micro);
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--kicker);
  margin-bottom: var(--sp-1);
}

input[type="text"], input[type="email"], input[type="password"],
input[type="number"], select, textarea {
  font: inherit;
  width: 100%;
  padding: var(--sp-2) var(--sp-3);
  background: var(--bg);
  color: var(--ink);
  border: var(--hairline) solid var(--divider);
}
input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
textarea { min-height: 9rem; resize: vertical; }

.field { margin-bottom: var(--sp-4); }
.field-inline { display: flex; gap: var(--sp-2); align-items: flex-end; flex-wrap: wrap; }
.field-inline .field { margin-bottom: 0; }

.checkbox-row { display: flex; align-items: center; gap: var(--sp-2); }
.checkbox-row label { margin: 0; }
.checkbox-row input { width: auto; }

.form-narrow { max-width: 26rem; }

/* ---------- notices ---------- */

.notice, .error {
  padding: var(--sp-3) var(--sp-4);
  margin-bottom: var(--sp-4);
  font-size: var(--fs-sm);
  border-left: var(--rule) solid var(--divider);
  background: var(--surface);
}
.error {
  border-left-color: var(--accent);
  color: var(--accent-text);
}

/* ---------- tables ---------- */

table { width: 100%; border-collapse: collapse; }

thead th {
  font-size: var(--fs-micro);
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--kicker);
  text-align: left;
  padding: var(--sp-2) var(--sp-3) var(--sp-2) 0;
  border-bottom: var(--rule) solid var(--divider);
  white-space: nowrap;
}
thead th a { color: inherit; text-decoration: none; }
thead th a:hover { color: var(--ink); }
thead th .sorted { color: var(--accent-text); }

tbody td {
  padding: var(--sp-3) var(--sp-3) var(--sp-3) 0;
  border-bottom: var(--hairline) solid var(--hairline-color);
  vertical-align: top;
}
tbody tr:hover { background: var(--row-press); }
td.right, th.right { text-align: right; padding-right: 0; }
td.actions { white-space: nowrap; }
td.actions form { display: inline; margin: 0; }

.table-scroll { overflow-x: auto; }

.tag {
  display: inline-block;
  font-size: var(--fs-micro);
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 1px var(--sp-2);
  border: var(--hairline) solid var(--divider);
  color: var(--body-secondary);
}
.tag-accent { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }

/* ---------- stat tiles ---------- */
/* A grid whose 2px gaps show the divider through — the gap *is* the rule. */

.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: var(--rule);
  background: var(--divider);
  border: var(--rule) solid var(--divider);
}
.tile {
  background: var(--bg);
  padding: var(--sp-4);
}
.tile-value {
  display: block;
  font-size: var(--fs-h2);
  font-weight: 800;
  line-height: 1.0;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
}
.tile-value.is-empty { color: var(--label-deemph); }
.tile-label {
  display: block;
  font-size: var(--fs-micro);
  font-weight: 400;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--kicker);
  margin-top: var(--sp-2);
}
.tile-note { display: block; font-size: var(--fs-micro); color: var(--caption-muted); }

/* ---------- calendar ---------- */

.calendar-head {
  display: flex;
  align-items: baseline;
  gap: var(--sp-3);
  margin-bottom: var(--sp-3);
}
.calendar-month { font-size: var(--fs-h4); font-weight: 800; letter-spacing: -0.015em; }

.calendar {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: var(--rule);
  background: var(--divider);
  border: var(--rule) solid var(--divider);
}
.calendar-dow {
  background: var(--bg);
  padding: var(--sp-2);
  font-size: var(--fs-micro);
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--kicker);
}
.cal-cell {
  position: relative;
  background: var(--bg);
  aspect-ratio: 1 / 1;
  padding: var(--sp-2);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}
.cal-cell.out { background: var(--surface); }
.cal-cell.future .cal-count { display: none; }
.cal-date {
  font-size: var(--fs-micro);
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--caption-muted);
}
.cal-cell.today .cal-date { color: var(--accent-text); font-weight: 800; }
.cal-count {
  font-size: var(--fs-h4);
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}
.cal-count.zero { color: var(--label-deemph); }

/* Five steps of accent, deepest for the month's peak. `.fill-4` and `.fill-5`
   carry light type because the field is saturated enough to need it. */
.cal-cell.fill-1 { background: color-mix(in srgb, var(--accent) 14%, var(--bg)); }
.cal-cell.fill-2 { background: color-mix(in srgb, var(--accent) 32%, var(--bg)); }
.cal-cell.fill-3 { background: color-mix(in srgb, var(--accent) 52%, var(--bg)); }
.cal-cell.fill-4 { background: color-mix(in srgb, var(--accent) 76%, var(--bg)); }
.cal-cell.fill-5 { background: var(--accent); }
.cal-cell.fill-4, .cal-cell.fill-5 { color: var(--on-accent); }
.cal-cell.fill-4 .cal-date, .cal-cell.fill-5 .cal-date { color: var(--on-accent); }

/* ---------- bar rows ---------- */

.bars { display: flex; flex-direction: column; gap: var(--sp-2); }
.bar-row {
  display: grid;
  grid-template-columns: minmax(6rem, 12rem) 1fr auto;
  align-items: center;
  gap: var(--sp-3);
  font-size: var(--fs-sm);
}
.bar-track { background: var(--surface); height: 14px; }
.bar-fill { background: var(--accent); height: 100%; min-width: 2px; }
.bar-value { font-variant-numeric: tabular-nums; color: var(--body-secondary); }

/* ---------- two-column split ---------- */

.split {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(310px, 1fr));
  gap: var(--sp-8);
}

/* ---------- auth ---------- */

.auth-page {
  max-width: 24rem;
  margin: 0 auto;
  padding-top: var(--sp-12);
}

/* ---------- print/small screens ---------- */

@media (max-width: 640px) {
  :root { --fs-h1: 32px; --fs-h2: 25px; --gutter: 16px; }
  .cal-cell { padding: var(--sp-1); }
  .cal-count { font-size: var(--fs-h5); }
  .site-nav { gap: var(--sp-3); }
}
