/* CPD Mate web. Mirrors the iOS app: same screens, same words, same colours.
   Each block names the SwiftUI piece it stands in for. The tokens are pinned
   in fixtures/ui-tokens.json and checked by test/ui-parity.test.ts.
   Rules: CLAUDE.md, "Web and iOS stay aligned". */

/* ── Tokens ─────────────────────────────────────────────────────────────── */
:root {
  color-scheme: light dark;
  /* Brand (Theme.swift) */
  --accent: #0F766E;
  --accent-ink: #FFFFFF;
  --done: #15803D;
  --behind: #B45309;
  --destructive: #FF3B30;
  /* Apple system colours (iOS gets these from the system) */
  --bg: #F2F2F7;            /* systemGroupedBackground */
  --cell: #FFFFFF;          /* secondarySystemGroupedBackground */
  --label: #000000;
  --label-2: rgba(60, 60, 67, 0.6);    /* secondaryLabel */
  --label-3: rgba(60, 60, 67, 0.3);    /* tertiaryLabel */
  --separator: rgba(60, 60, 67, 0.29);
  --fill: rgba(120, 120, 128, 0.16);   /* secondarySystemFill: chips, tracks */
  --glass: rgba(255, 255, 255, 0.62);
  --glass-edge: rgba(255, 255, 255, 0.7);
  --shadow: 0 8px 28px rgba(0, 0, 0, 0.14);
  /* Type: iOS text styles at the default Dynamic Type size */
  --font: -apple-system, BlinkMacSystemFont, system-ui, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
  --large-title: 700 34px/41px var(--font);
  --title2: 700 22px/28px var(--font);
  --headline: 600 17px/22px var(--font);
  --body: 400 17px/22px var(--font);
  --subheadline: 400 15px/20px var(--font);
  --footnote: 400 13px/18px var(--font);
  --caption: 400 12px/16px var(--font);
  /* Shape */
  --section-radius: 26px;   /* iOS 26 inset-grouped sections */
  --gutter: 16px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --accent: #2DD4BF;
    --accent-ink: #042F2E;
    --done: #4ADE80;
    --behind: #FBBF24;
    --destructive: #FF453A;
    --bg: #000000;
    --cell: #1C1C1E;
    --label: #FFFFFF;
    --label-2: rgba(235, 235, 245, 0.6);
    --label-3: rgba(235, 235, 245, 0.3);
    --separator: rgba(84, 84, 88, 0.6);
    --fill: rgba(120, 120, 128, 0.32);
    --glass: rgba(40, 40, 44, 0.6);
    --glass-edge: rgba(255, 255, 255, 0.12);
    --shadow: 0 8px 28px rgba(0, 0, 0, 0.5);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--label);
  font: var(--body);
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 60%, transparent); outline-offset: 2px; }
.num { font-variant-numeric: tabular-nums; }
.secondary { color: var(--label-2); }
.footnote { font: var(--footnote); }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
svg.icon { width: 1.1em; height: 1.1em; flex: none; vertical-align: -0.18em; }

/* ── NavigationStack: bar, large title, subtitle ────────────────────────── */
.nav {
  position: sticky; top: 0; z-index: 20;
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
  min-height: 52px;
  padding: calc(6px + env(safe-area-inset-top)) var(--gutter) 6px;
  transition: background 0.2s, box-shadow 0.2s;
}
/* Scroll edge effect: the bar turns to glass once content is under it. */
.nav.scrolled {
  background: var(--glass);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
  backdrop-filter: blur(24px) saturate(180%);
  box-shadow: 0 0.5px 0 var(--separator);
}
.nav .leading { justify-self: start; display: flex; gap: 8px; }
.nav .trailing { justify-self: end; display: flex; gap: 8px; }
.nav .inline-title { font: var(--headline); text-align: center; opacity: 0; transition: opacity 0.2s; max-width: calc(100vw - 150px); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav.scrolled .inline-title, .nav.inline .inline-title { opacity: 1; }
.nav .inline-title small { display: block; font: var(--caption); color: var(--label-2); }

.title-block { max-width: 760px; margin: 0 auto; padding: 0 calc(var(--gutter) + 4px) 8px; }
.large-title { font: var(--large-title); letter-spacing: 0.01em; margin: 0; }
.subtitle { font: var(--subheadline); color: var(--label-2); margin: 2px 0 0; }

/* Toolbar items on glass (iOS 26): round glass buttons. */
.glass-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 4px;
  min-width: 44px; height: 44px; padding: 0 12px;
  border: 0.5px solid var(--glass-edge); border-radius: 999px;
  background: var(--glass); color: var(--label);
  -webkit-backdrop-filter: blur(24px) saturate(180%); backdrop-filter: blur(24px) saturate(180%);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.08);
  font: var(--body);
}
.glass-btn.icon-only { padding: 0; width: 44px; }
.glass-btn.back { color: var(--label); text-decoration: none; }
a.glass-btn { text-decoration: none; }
.glass-btn.confirm { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.glass-btn:disabled { opacity: 0.35; cursor: default; }

/* ── List(.insetGrouped) ────────────────────────────────────────────────── */
main { max-width: 760px; margin: 0 auto; padding: 0 var(--gutter) calc(120px + env(safe-area-inset-bottom)); }
.section { margin: 0 0 20px; }
.section.compact { margin-bottom: 12px; }
.section-header { font: var(--footnote); color: var(--label-2); text-transform: none; padding: 0 20px 7px; margin: 0; font-weight: 600; }
.section-footer { font: var(--footnote); color: var(--label-2); padding: 7px 20px 0; margin: 0; }
.section-footer p { margin: 0 0 8px; }
.cells { background: var(--cell); border-radius: var(--section-radius); overflow: hidden; }
.cell {
  position: relative; display: flex; align-items: center; gap: 12px;
  width: 100%; min-height: 44px; padding: 11px 20px;
  background: none; border: 0; text-align: left; color: var(--label);
}
.cell + .cell::before {
  content: ''; position: absolute; top: 0; left: 20px; right: 0; height: 0.5px; background: var(--separator);
}
button.cell:active, a.cell:active { background: var(--fill); }
a.cell { text-decoration: none; }
.cell .grow { flex: 1; min-width: 0; }
.cell .detail { color: var(--label-2); font-variant-numeric: tabular-nums; flex: none; }
.cell .chevron { color: var(--label-3); flex: none; }
.cell.action { color: var(--accent); }
.cell.destructive { color: var(--destructive); justify-content: center; }
.cell.centered { justify-content: center; }
.cell.plain { color: var(--label-2); }
.cell .sub { display: block; font: var(--footnote); color: var(--label-2); margin-top: 2px; }
.cell .title { display: block; overflow-wrap: anywhere; }

/* LabeledContent */
.labeled { justify-content: space-between; }

/* ── Registration card (RegistrationCard) ───────────────────────────────── */
.reg-card { display: block; padding: 16px 20px; }
.reg-card .top { display: flex; align-items: center; gap: 16px; }
.reg-card .ring { width: 56px; height: 56px; flex: none; }
.reg-card h2 { font: var(--headline); margin: 0 0 2px; }
.reg-card .total { display: flex; align-items: baseline; gap: 4px; }
.reg-card .total b { font: var(--title2); font-weight: 600; font-variant-numeric: tabular-nums; }
.reg-card .total span { color: var(--label-2); }
.status { display: flex; align-items: center; gap: 5px; font: var(--subheadline); margin-top: 2px; }
.status.done { color: var(--done); }
.status.onTrack { color: var(--accent); }
.status.behind { color: var(--behind); }
.reg-card .reqs { display: grid; gap: 10px; margin-top: 14px; }
.reg-card .cycle-line { font: var(--footnote); color: var(--label-2); margin-top: 14px; }
.reg-card .chev-wrap { display: flex; align-items: center; gap: 8px; }

/* ProgressRing */
.ring circle { fill: none; }
.ring .track { stroke-opacity: 0.2; }
.ring .bar { stroke-linecap: round; transition: stroke-dashoffset 0.4s ease; }
.tint-done { color: var(--done); }
.tint-onTrack { color: var(--accent); }
.tint-behind { color: var(--behind); }

/* RequirementRow */
.req .line { display: flex; align-items: baseline; gap: 6px; font: var(--footnote); }
.req .line .grow { flex: 1; }
.req .line .amount { color: var(--label-2); font-variant-numeric: tabular-nums; }
.req .met { color: var(--done); }
.progress { height: 4px; border-radius: 2px; background: var(--fill); margin-top: 6px; overflow: hidden; }
.progress > span { display: block; height: 100%; border-radius: inherit; background: var(--accent); transition: width 0.3s; }
.progress.met > span { background: var(--done); }

/* Detail hero */
.hero { display: grid; justify-items: center; gap: 14px; padding: 20px; }
.hero .ring-wrap { position: relative; width: 180px; height: 180px; }
.hero .ring { width: 180px; height: 180px; }
.hero .centre { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; }
.hero .centre b { font: 700 34px/41px ui-rounded, var(--font); font-variant-numeric: tabular-nums; }
.hero .centre span { font: var(--subheadline); color: var(--label-2); }
.hero .status { font: var(--headline); text-align: center; }

/* ActivityRow */
.activity-row { align-items: baseline; }
.activity-row .meta { color: var(--label-3); display: inline-flex; gap: 6px; flex: none; }

/* Nudge (activities needing a reflection) */
.nudge { color: var(--label); }
.nudge .icon { color: var(--accent); }

/* ── Onboarding (OnboardingView) ────────────────────────────────────────── */
.welcome { padding: 8px 20px 20px; }
.welcome .mark { width: 52px; height: 52px; color: var(--accent); }
.welcome h2 { font: var(--title2); margin: 10px 0 6px; }
.welcome p { color: var(--label-2); margin: 0; }
.pick-circle { width: 24px; height: 24px; flex: none; color: var(--label-3); }
.pick-circle.on { color: var(--accent); }

/* ── Sign in (SignInView) ───────────────────────────────────────────────── */
.signin { min-height: 100dvh; display: grid; place-items: center; padding: 32px var(--gutter); }
.signin .panel { width: 100%; max-width: 400px; text-align: center; }
.signin .app-icon { width: 88px; height: 88px; border-radius: 22px; margin: 0 auto 18px; display: grid; place-items: center; background: var(--accent); color: var(--accent-ink); box-shadow: var(--shadow); }
.signin .app-icon svg { width: 52px; height: 52px; }
.signin h1 { font: var(--large-title); margin: 0 0 8px; }
.signin .lede { color: var(--label-2); margin: 0 0 28px; }
.signin .buttons { display: grid; gap: 12px; }
.provider-btn { display: flex; align-items: center; justify-content: center; gap: 8px; height: 50px; border-radius: 999px; font: var(--headline); text-decoration: none; border: 0; }
.provider-btn.apple { background: #000; color: #fff; }
.provider-btn.google { background: #fff; color: #1f1f1f; border: 1px solid #747775; }
@media (prefers-color-scheme: dark) { .provider-btn.apple { background: #fff; color: #000; } }
.provider-btn svg { width: 20px; height: 20px; }
.signin .notice { margin-top: 24px; font: var(--footnote); color: var(--label-2); }
.signin .error { color: var(--destructive); font: var(--subheadline); margin: 0 0 16px; }
.dev-signin { margin-top: 28px; padding-top: 20px; border-top: 0.5px solid var(--separator); display: grid; gap: 8px; text-align: left; }
.dev-signin p { margin: 0; font: var(--footnote); color: var(--label-2); }

/* ── Bottom bar: .safeAreaBar(edge: .bottom) + .glassProminent ─────────── */
.bottom-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 15;
  display: flex; justify-content: center;
  padding: 24px var(--gutter) calc(8px + env(safe-area-inset-bottom));
  pointer-events: none;
  /* The scroll edge effect: content fades out under the button. */
  background: linear-gradient(to bottom, transparent, color-mix(in srgb, var(--bg) 85%, transparent) 55%);
}
.glass-prominent {
  pointer-events: auto;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; max-width: 480px; height: 52px;
  border: 0.5px solid rgba(255, 255, 255, 0.35); border-radius: 999px;
  background: color-mix(in srgb, var(--accent) 88%, transparent); color: var(--accent-ink);
  -webkit-backdrop-filter: blur(20px) saturate(180%); backdrop-filter: blur(20px) saturate(180%);
  box-shadow: var(--shadow), inset 0 1px 0 rgba(255, 255, 255, 0.35);
  font: var(--headline);
}
.glass-prominent:disabled { opacity: 0.45; }
.glass-prominent:active { transform: scale(0.98); }

/* ── Form controls (Form rows) ──────────────────────────────────────────── */
.field-cell { display: block; padding: 11px 20px; }
.field-cell input, .field-cell textarea, .field-cell select {
  width: 100%; border: 0; background: none; padding: 0; font: var(--body); outline-offset: 4px;
}
.field-cell { position: relative; }
.field-cell + .field-cell::before, .cell + .field-cell::before, .field-cell + .cell::before, .chip-row + .field-cell::before {
  content: ''; position: absolute; top: 0; left: 20px; right: 0; height: 0.5px; background: var(--separator);
}
.field-cell textarea { resize: vertical; min-height: 66px; line-height: 22px; }
input::placeholder, textarea::placeholder { color: var(--label-3); }
.inline-input { width: 96px; border: 0; background: none; text-align: right; font: var(--body); font-variant-numeric: tabular-nums; color: var(--label-2); }
input[type='date'].inline-input { width: auto; }
select.inline-select { border: 0; background: none; font: var(--body); color: var(--label-2); text-align: right; }
.hint { font: var(--footnote); color: var(--label-2); margin: 4px 0 0; }

/* Toggle (switch) */
.switch { position: relative; width: 51px; height: 31px; flex: none; }
.switch input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.switch span { position: absolute; inset: 0; border-radius: 999px; background: var(--fill); transition: background 0.2s; pointer-events: none; }
.switch span::after { content: ''; position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; border-radius: 50%; background: #fff; box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2); transition: transform 0.2s; }
.switch input:checked + span { background: var(--done); }
.switch input:checked + span::after { transform: translateX(20px); }
.switch input:focus-visible + span { outline: 3px solid color-mix(in srgb, var(--accent) 60%, transparent); outline-offset: 2px; }

/* Stepper */
.stepper { display: inline-flex; border-radius: 9px; background: var(--fill); overflow: hidden; flex: none; }
.stepper button { width: 46px; height: 32px; border: 0; background: none; font-size: 20px; line-height: 1; }
.stepper button + button { border-left: 0.5px solid var(--separator); }

/* ChipStyle */
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; flex: none;
  min-width: 44px; min-height: 44px; padding: 0 14px;
  border: 1.5px solid transparent; border-radius: 999px;
  background: var(--fill); color: var(--label);
  font: 500 15px/20px var(--font); white-space: nowrap;
}
.chip[aria-pressed='true'] { color: var(--accent); background: color-mix(in srgb, var(--accent) 18%, transparent); border-color: var(--accent); }
.chip:active { opacity: 0.6; }
.chip-row { padding: 6px 20px 11px; }

/* ── Sheets (.sheet with Button(role: .close) / .confirm) ───────────────── */
dialog.sheet {
  width: 100%; max-width: 620px; max-height: 94dvh;
  margin: auto auto 0; padding: 0;
  border: 0; border-radius: 34px 34px 0 0;
  background: var(--bg); color: var(--label);
  overflow: hidden; display: flex; flex-direction: column;
}
dialog.sheet:not([open]) { display: none; }
dialog.sheet::backdrop { background: rgba(0, 0, 0, 0.35); }
dialog.sheet.medium { max-height: 60dvh; }
.sheet-head { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; padding: 14px 16px 10px; }
.sheet-head h2 { font: var(--headline); margin: 0; text-align: center; }
.sheet-head .trailing { justify-self: end; }
.sheet-body { overflow-y: auto; padding: 4px var(--gutter) calc(24px + env(safe-area-inset-bottom)); }
@media (min-width: 700px) {
  dialog.sheet { margin: auto; border-radius: 34px; max-height: 86dvh; }
  dialog.sheet.medium { max-height: 70dvh; }
}

/* Confirmation dialog (.confirmationDialog) */
dialog.confirm-dialog { width: min(420px, calc(100% - 32px)); margin: auto auto calc(16px + env(safe-area-inset-bottom)); padding: 0; border: 0; background: none; color: var(--label); }
dialog.confirm-dialog::backdrop { background: rgba(0, 0, 0, 0.35); }
.confirm-dialog .group { background: var(--cell); border-radius: 22px; overflow: hidden; margin-bottom: 8px; text-align: center; }
.confirm-dialog .message { padding: 14px 20px; font: var(--footnote); color: var(--label-2); }
.confirm-dialog .message b { display: block; color: var(--label-2); font-weight: 600; margin-bottom: 2px; }
.confirm-dialog button { display: block; width: 100%; min-height: 56px; border: 0; background: none; font: var(--body); color: var(--accent); border-top: 0.5px solid var(--separator); }
.confirm-dialog button.destructive { color: var(--destructive); }
.confirm-dialog .cancel button { border: 0; font-weight: 600; }
@media (min-width: 700px) { dialog.confirm-dialog { margin: auto; } }

/* Menu (toolbar ⋯) */
.menu {
  position: fixed; z-index: 40; min-width: 250px; padding: 6px;
  border-radius: 22px; background: var(--glass); border: 0.5px solid var(--glass-edge);
  -webkit-backdrop-filter: blur(30px) saturate(180%); backdrop-filter: blur(30px) saturate(180%);
  box-shadow: var(--shadow);
}
.menu button { display: flex; width: 100%; align-items: center; justify-content: space-between; gap: 16px; padding: 11px 14px; border: 0; border-radius: 14px; background: none; text-align: left; color: var(--label); }
.menu button:hover, .menu button:focus-visible { background: var(--fill); }
.menu hr { border: 0; height: 0.5px; background: var(--separator); margin: 4px 10px; }
.menu button.destructive { color: var(--destructive); }

/* Toast stands in for the success haptic. */
.toast {
  position: fixed; left: 50%; bottom: calc(92px + env(safe-area-inset-bottom)); z-index: 50;
  transform: translate(-50%, 12px); opacity: 0; pointer-events: none;
  padding: 10px 18px; border-radius: 999px;
  background: var(--glass); border: 0.5px solid var(--glass-edge); color: var(--label);
  -webkit-backdrop-filter: blur(24px) saturate(180%); backdrop-filter: blur(24px) saturate(180%);
  box-shadow: var(--shadow); font: var(--subheadline);
  transition: opacity 0.2s, transform 0.2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ContentUnavailableView */
.unavailable { text-align: center; padding: 64px 20px; color: var(--label-2); }
.unavailable svg { width: 48px; height: 48px; margin-bottom: 8px; }
.unavailable h2 { font: var(--title2); color: var(--label); margin: 0 0 6px; }

.loading { display: grid; place-items: center; min-height: 60dvh; color: var(--label-2); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
@media (prefers-reduced-transparency: reduce) {
  :root { --glass: var(--cell); }
}
