/* ============================================================================
   CivicSync design tokens
   Translated directly from DESIGN.md. Values here are the source of truth
   for color, typography, spacing, radius, and elevation across the app.
   ============================================================================ */

:root {
  /* --- Colors (from DESIGN.md `colors`) --- */
  --color-surface: #f8f9ff;
  --color-surface-dim: #cbdbf5;
  --color-surface-bright: #f8f9ff;
  --color-surface-container-lowest: #ffffff;
  --color-surface-container-low: #eff4ff;
  --color-surface-container: #e5eeff;
  --color-surface-container-high: #dce9ff;
  --color-surface-container-highest: #d3e4fe;
  --color-on-surface: #0b1c30;
  --color-on-surface-variant: #45464d;
  --color-inverse-surface: #213145;
  --color-inverse-on-surface: #eaf1ff;
  --color-outline: #76777d;
  --color-outline-variant: #c6c6cd;

  --color-primary: #0f172a; /* DESIGN.md prose: "Civic Blue" #0F172A used for primary surfaces/nav */
  --color-on-primary: #ffffff;
  --color-primary-container: #131b2e;
  /* Primary-button colors (Milestone 26.0): kept distinct from
     --color-primary/on-primary above because that pair also drives the
     always-dark authority sidebar background, which must not change.
     In light mode this matches the deep-navy button that already
     existed; only the dark-mode value (below) differs. */
  --color-btn-primary-bg: var(--color-primary);
  --color-btn-primary-text: var(--color-on-primary);
  --color-on-primary-container: #7c839b;

  --color-secondary: #515f74;
  --color-on-secondary: #ffffff;
  --color-secondary-container: #d5e3fd;
  --color-on-secondary-container: #57657b;

  --color-action: #003ea8; /* DESIGN.md "Action Blue" -- primary CTAs, focus rings, links */
  --color-tertiary-container: #00174b;
  --color-on-tertiary-container: #497cff;

  --color-error: #ba1a1a;
  --color-on-error: #ffffff;
  --color-error-container: #ffdad6;
  /* --- Authority accent (Milestone 26.0) --------------------------------
     A fixed institutional accent (not theme-flipped, same spirit as the
     citizen Civic Blue) marking "restricted institutional access" --
     used for the Authority Portal entry point and sparingly within the
     authority command center itself. Verified 9.4:1 contrast with
     white text. Gold is a thin accent only, never a fill. */
  --color-authority-red: #8a1728;
  --color-authority-red-hover: #711220;
  --color-authority-gold: #b8923f;

  --color-on-error-container: #93000a;

  --color-success: #1e7a34;
  --color-success-container: #dcf5e3;
  --color-warning: #8d5e00; /* darkened from #9a6700 (M25.5) to pass WCAG AA 4.5:1 for chip text */
  --color-warning-container: #fff3d6;

  --color-background: #f8f9ff;
  --color-on-background: #0b1c30;
  --color-card-border: #e2e8f0;
  --color-card-header-border: #f1f5f9;

  /* --- Typography (from DESIGN.md `typography`) --- */
  --font-family: 'Josefin Sans', 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;

  /* Milestone 26.0: every size below is expressed as a calc() against
     --a11y-font-scale (defined further down in this same :root block --
     CSS custom properties resolve at use time, not declaration order,
     so this is safe) so that the accessibility widget's text-size
     control scales EVERY typographic role uniformly -- headings,
     labels, body text -- from one shared source of truth. Previously
     only body's own font-size referenced the scale, so headings/labels
     (which each set their own explicit font-size via these same
     tokens) never scaled; that was the actual cause of "text scaling
     works on tracking but not landing" -- tracking's affected text
     happened to be plain, unstyled body text, landing's didn't. */
  --display-lg-size: calc(48px * var(--a11y-font-scale));
  --display-lg-weight: 700;
  --display-lg-line: calc(56px * var(--a11y-font-scale));
  --display-lg-tracking: -0.02em;

  --display-lg-mobile-size: calc(32px * var(--a11y-font-scale));
  --display-lg-mobile-line: calc(40px * var(--a11y-font-scale));

  --headline-md-size: calc(24px * var(--a11y-font-scale));
  --headline-md-weight: 600;
  --headline-md-line: calc(32px * var(--a11y-font-scale));
  --headline-md-tracking: -0.01em;

  --headline-sm-size: calc(20px * var(--a11y-font-scale));
  --headline-sm-weight: 600;
  --headline-sm-line: calc(28px * var(--a11y-font-scale));

  --body-lg-size: calc(18px * var(--a11y-font-scale));
  --body-lg-weight: 400;
  --body-lg-line: calc(28px * var(--a11y-font-scale));

  --body-md-size: calc(16px * var(--a11y-font-scale));
  --body-md-weight: 400;
  --body-md-line: calc(24px * var(--a11y-font-scale));

  --body-sm-size: calc(14px * var(--a11y-font-scale));
  --body-sm-weight: 400;
  --body-sm-line: calc(20px * var(--a11y-font-scale));

  --label-md-size: calc(12px * var(--a11y-font-scale));
  --label-md-weight: 600;
  --label-md-line: calc(16px * var(--a11y-font-scale));
  --label-md-tracking: 0.05em;

  /* --- Spacing (4px baseline grid, from DESIGN.md `spacing`) --- */
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 16px;
  --space-lg: 24px;
  --space-xl: 40px;
  --container-max: 1280px;
  --gutter: 24px;
  --margin-mobile: 16px;

  /* --- Radius (from DESIGN.md `rounded`) --- */
  --radius-sm: 0.125rem;
  --radius-default: 0.25rem;
  --radius-md: 0.375rem;
  --radius-lg: 0.5rem;
  --radius-xl: 0.75rem;
  --radius-full: 9999px;

  /* --- Layout tokens (Milestone 26.0) --- */
  --header-height: 68px;
  --header-height-mobile: 60px;
  --floating-widget-size: 48px;

  /* --- Elevation (from DESIGN.md "Elevation & Depth") ---
     A restrained 3-level scale, tinted with the primary navy
     (#0f172a = rgb(15 23 42)) rather than generic black, so elevation
     reads as part of the same palette instead of a bolted-on effect.
     sm = baseline resting elevation for ordinary cards; md = for
     content that should visually lead (e.g. headline KPIs); lg =
     reserved for overlays/modals sitting above page content. */
  --shadow-sm: 0 1px 2px 0 rgb(15 23 42 / 0.04), 0 1px 1px 0 rgb(15 23 42 / 0.03);
  --shadow-md: 0 4px 6px -1px rgb(15 23 42 / 0.08), 0 2px 4px -2px rgb(15 23 42 / 0.06);
  --shadow-lg: 0 10px 15px -3px rgb(15 23 42 / 0.10), 0 4px 6px -4px rgb(15 23 42 / 0.08);
  /* Kept as an alias for anything already referencing the old single
     token -- equivalent to --shadow-sm. */
  --shadow-subtle: var(--shadow-sm);

  /* --- Focus ring (Milestone 25.1) --- consistent, visible keyboard
     focus indicator for interactive controls that don't already have
     a bespoke :focus treatment (form inputs keep their own border-based
     focus style, unchanged). Uses the existing Action Blue -- no new
     color introduced. */
  --focus-ring: 0 0 0 2px var(--color-surface-container-lowest), 0 0 0 4px var(--color-action);

  /* --- Accessibility widget (Milestone 25.9) --------------------------------
     A single multiplier applied to body font-size via the accessibility
     panel. 1 = default. Persisted in localStorage by theme.js. */
  --a11y-font-scale: 1;
}

/* ============================================================================
   Dark theme (Milestone 25.9)
   A genuine, intentional dark palette -- not an inverted light theme.
   Every token below is a deliberate choice for that surface in the dark
   context, keeping the same Civic Blue/Action Blue identity. Applied via
   [data-theme="dark"] on <html> (set by theme.js, persisted in
   localStorage, falling back to the OS preference when the citizen/
   authority user hasn't explicitly chosen one yet).
   ============================================================================ */

[data-theme='dark'] {
  --color-surface: #0b1220;
  --color-surface-dim: #0b1220;
  --color-surface-bright: #101a2e;
  --color-surface-container-lowest: #101a2e;
  --color-surface-container-low: #131e35;
  --color-surface-container: #17233d;
  --color-surface-container-high: #1c2a47;
  --color-surface-container-highest: #223151;
  --color-on-surface: #e7ecf7;
  --color-on-surface-variant: #a7b3cc;
  --color-inverse-surface: #e7ecf7;
  --color-inverse-on-surface: #131e35;
  --color-outline: #4a5772;
  --color-outline-variant: #5a7099;

  --color-primary: #060b16;
  --color-on-primary: #e7ecf7;
  --color-primary-container: #101a2e;
  /* Dark mode: --color-primary is near-black (matches the always-dark
     authority sidebar), which is nearly indistinguishable from the
     dark page background when used for a primary button -- so primary
     buttons use the brighter action-blue instead, with dark text for
     contrast on it. */
  --color-btn-primary-bg: var(--color-action);
  --color-btn-primary-text: var(--color-primary);
  --color-on-primary-container: #a7b3cc;

  --color-secondary: #a7b3cc;
  --color-on-secondary: #0b1220;
  --color-secondary-container: #223151;
  --color-on-secondary-container: #c3cee6;

  --color-action: #6ea8ff; /* lightened Action Blue -- keeps AA contrast on dark surfaces */
  --color-tertiary-container: #0d1f3f;
  --color-on-tertiary-container: #7fa6ff;

  --color-error: #ff8a80;
  --color-on-error: #4c0004;
  --color-error-container: #5c1a17;
  --color-on-error-container: #ffdad6;

  --color-success: #7fd99a;
  --color-success-container: #163d24;
  --color-warning: #f0c05a;
  --color-warning-container: #40300a;

  --color-background: #0b1220;
  --color-on-background: #e7ecf7;
  --color-card-border: #223151;
  --color-card-header-border: #1c2a47;

  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.35), 0 1px 1px 0 rgb(0 0 0 / 0.25);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.45), 0 2px 4px -2px rgb(0 0 0 / 0.35);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.55), 0 4px 6px -4px rgb(0 0 0 / 0.4);
  --shadow-subtle: var(--shadow-sm);

  --focus-ring: 0 0 0 2px var(--color-surface-container-lowest), 0 0 0 4px var(--color-action);
}

/* Only follow the OS preference when the user has never explicitly
   chosen a theme in this browser -- theme.js adds data-theme-explicit
   to <html> the moment a citizen/authority user picks one, which
   disables this fallback block entirely via the attribute selector
   below never matching once that's present. */
@media (prefers-color-scheme: dark) {
  html:not([data-theme-explicit]) {
    --color-surface: #0b1220;
    --color-surface-dim: #0b1220;
    --color-surface-bright: #101a2e;
    --color-surface-container-lowest: #101a2e;
    --color-surface-container-low: #131e35;
    --color-surface-container: #17233d;
    --color-surface-container-high: #1c2a47;
    --color-surface-container-highest: #223151;
    --color-on-surface: #e7ecf7;
    --color-on-surface-variant: #a7b3cc;
    --color-inverse-surface: #e7ecf7;
    --color-inverse-on-surface: #131e35;
    --color-outline: #4a5772;
    --color-outline-variant: #5a7099;
    --color-primary: #060b16;
    --color-on-primary: #e7ecf7;
    --color-primary-container: #101a2e;
    --color-btn-primary-bg: var(--color-action);
    --color-btn-primary-text: var(--color-primary);
    --color-on-primary-container: #a7b3cc;
    --color-secondary: #a7b3cc;
    --color-on-secondary: #0b1220;
    --color-secondary-container: #223151;
    --color-on-secondary-container: #c3cee6;
    --color-action: #6ea8ff;
    --color-tertiary-container: #0d1f3f;
    --color-on-tertiary-container: #7fa6ff;
    --color-error: #ff8a80;
    --color-on-error: #4c0004;
    --color-error-container: #5c1a17;
    --color-on-error-container: #ffdad6;
    --color-success: #7fd99a;
    --color-success-container: #163d24;
    --color-warning: #f0c05a;
    --color-warning-container: #40300a;
    --color-background: #0b1220;
    --color-on-background: #e7ecf7;
    --color-card-border: #223151;
    --color-card-header-border: #1c2a47;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.35), 0 1px 1px 0 rgb(0 0 0 / 0.25);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.45), 0 2px 4px -2px rgb(0 0 0 / 0.35);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.55), 0 4px 6px -4px rgb(0 0 0 / 0.4);
    --shadow-subtle: var(--shadow-sm);
  }
}

/* ============================================================================
   Reset & base
   ============================================================================ */

*,
*::before,
*::after {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  font-family: var(--font-family);
  font-size: var(--body-md-size);
  line-height: var(--body-md-line);
  font-weight: var(--body-md-weight);
  color: var(--color-on-surface);
  background: var(--color-background);
  -webkit-font-smoothing: antialiased;
  transition: background-color 0.15s ease, color 0.15s ease;
}

/* Reduced motion (Milestone 25.9): respects the OS-level preference
   automatically, and can also be forced on via the accessibility
   widget (data-reduced-motion="true" on <html>, persisted by
   theme.js) for a user whose OS setting doesn't reflect their actual
   preference in this browser. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}
html[data-reduced-motion='true'] *,
html[data-reduced-motion='true'] *::before,
html[data-reduced-motion='true'] *::after {
  animation-duration: 0.001ms !important;
  animation-iteration-count: 1 !important;
  transition-duration: 0.001ms !important;
  scroll-behavior: auto !important;
}

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

a {
  color: inherit;
}

button,
input,
textarea,
select {
  font: inherit;
  color: inherit;
}

h1,
h2,
h3,
h4,
p {
  margin: 0;
}

ul {
  margin: 0;
  padding: 0;
  list-style: none;
}

/* --- Typography utility classes -------------------------------------------- */

.type-display-lg {
  font-size: var(--display-lg-mobile-size);
  font-weight: var(--display-lg-weight);
  line-height: var(--display-lg-mobile-line);
  letter-spacing: var(--display-lg-tracking);
}
@media (min-width: 768px) {
  .type-display-lg {
    font-size: var(--display-lg-size);
    line-height: var(--display-lg-line);
  }
}

.type-headline-md {
  font-size: var(--headline-md-size);
  font-weight: var(--headline-md-weight);
  line-height: var(--headline-md-line);
  letter-spacing: var(--headline-md-tracking);
}

.type-headline-sm {
  font-size: var(--headline-sm-size);
  font-weight: var(--headline-sm-weight);
  line-height: var(--headline-sm-line);
}

.type-body-lg {
  font-size: var(--body-lg-size);
  line-height: var(--body-lg-line);
}

.type-body-sm {
  font-size: var(--body-sm-size);
  line-height: var(--body-sm-line);
}

.type-label {
  font-size: var(--label-md-size);
  font-weight: var(--label-md-weight);
  line-height: var(--label-md-line);
  letter-spacing: var(--label-md-tracking);
  text-transform: uppercase;
  color: var(--color-on-surface-variant);
}

/* --- Layout primitives ------------------------------------------------------ */

.container {
  max-width: var(--container-max);
  margin: 0 auto;
  padding: 0 var(--margin-mobile);
}
@media (min-width: 768px) {
  .container {
    padding: 0 var(--gutter);
  }
}
@media (min-width: 1024px) {
  .container {
    padding: 0 var(--space-xl);
  }
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
