/* ============================================================================
   Travel Ops — design tokens. THE ONE FILE THAT HOLDS A VALUE.
   ============================================================================

   Every colour, size, radius and duration in the app comes from here. A screen
   that needs a value it cannot find should get a token, not a literal: the
   moment two screens pick their own #e2e8f0 they drift, and nobody notices
   until the day a brand colour has to change.

   Four groups, in the order they depend on each other:
     1. the brand ramp        — the one thing an agency overrides
     2. semantic surfaces     — what the ramp means on a page
     3. the five status colours — UI_SPEC §1, the only colour-coding in the app
     4. everything that is not colour — type, space, radius, shadow, motion

   Dark mode follows the DEVICE, and can be overridden per page with
   data-theme. Both are defined here and nowhere else.                        */

:root {
  /* ---- 1. brand -----------------------------------------------------------
     The default is a deep slate-indigo: sober enough for an invoice, dark
     enough for white text at every size. `--brand` is written at runtime from
     the agency's own setting when it has one, so everything downstream of it
     rebrands without touching a stylesheet. */
  --brand-ink: #0f172a;       /* the header, primary buttons, focus rings */
  --brand: #1d4ed8;           /* links and the one accent                */
  --brand-strong: #1e40af;    /* its hover / pressed state               */
  --brand-soft: #dbeafe;      /* a tint of it behind selected things     */
  --on-brand: #ffffff;

  /* Three ROLES the brand feeds, kept separate because they behave differently
     in dark mode: the header stays dark in both schemes, the primary button
     inverts, and the focus ring has to clear whatever is behind it. */
  --header-bg: #0f172a;
  --header-fg: #f8fafc;
  --primary-bg: #0f172a;
  --primary-fg: #ffffff;
  --focus-ring: #0f172a;

  /* ---- 2. surfaces and text ---------------------------------------------- */
  --surface-page: #f8fafc;
  --surface-card: #ffffff;
  --surface-sunken: #f1f5f9;  /* inputs at rest, code, quiet panels */
  --surface-inverse: #0f172a;

  --text: #0f172a;            /* 16.7:1 on card — body copy            */
  --text-muted: #475569;      /*  8.6:1 on card — secondary lines      */
  --text-subtle: #5f6d85;     /*  5.2:1 on card, 4.8:1 on a sunken panel */
  --text-on-inverse: #f8fafc;

  --border: #e2e8f0;
  --border-strong: #cbd5e1;

  /* ---- 3. the five status colours (UI_SPEC §1) ----------------------------
     grey draft · blue quoted · green confirmed · amber needs attention ·
     red overdue. Each has a background, a foreground that clears AA on it, and
     a border for the cases that need an outline rather than a fill. */
  --grey-bg: #f1f5f9;  --grey-fg: #334155;  --grey-line: #cbd5e1;
  --blue-bg: #dbeafe;  --blue-fg: #1e40af;  --blue-line: #bfdbfe;
  --green-bg: #dcfce7; --green-fg: #15803d; --green-line: #bbf7d0;
  --amber-bg: #fef3c7; --amber-fg: #92400e; --amber-line: #fde68a;
  --red-bg: #fee2e2;   --red-fg: #b91c1c;   --red-line: #fecaca;
  /* The unread badge: a red dark enough for WHITE text, which the status
     `--red-fg` is not asked to be — that one is text ON a red tint. */
  --bell-red: #c81e1e;

  /* ---- 4. type -----------------------------------------------------------
     One family, seven sizes. 16px is the body size and the minimum for any
     input: anything smaller makes iOS zoom the page when it is focused, which
     is the single most irritating thing a phone form can do. */
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  --text-xs: 0.75rem;    /* 12 — tags, table captions            */
  --text-sm: 0.8125rem;  /* 13 — table cells, meta lines         */
  --text-md: 0.875rem;   /* 14 — secondary body                  */
  --text-base: 1rem;     /* 16 — body, every input               */
  --text-lg: 1.125rem;   /* 18 — card headings                   */
  --text-xl: 1.375rem;   /* 22 — page headings                   */
  --text-2xl: 1.75rem;   /* 28 — the one big number on a screen  */

  --leading-tight: 1.25;
  --leading: 1.5;

  /* ---- space: a 4px scale, because everything in the UI is a multiple of it */
  --space-1: 2px;
  --space-2: 4px;
  --space-3: 8px;
  --space-4: 12px;
  --space-5: 16px;
  --space-6: 24px;
  --space-7: 32px;
  --space-8: 48px;

  /* ---- radius ------------------------------------------------------------ */
  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;
  --radius-full: 999px;

  /* ---- shadow: three, and they mean depth, not decoration ----------------- */
  --shadow-sm: 0 1px 2px rgb(15 23 42 / 0.06);
  --shadow: 0 2px 8px rgb(15 23 42 / 0.08);
  --shadow-lg: 0 12px 32px rgb(15 23 42 / 0.18);

  /* ---- motion ------------------------------------------------------------ */
  --ease: cubic-bezier(0.2, 0, 0, 1);
  --fast: 120ms;
  --base: 200ms;

  /* ---- layout constants --------------------------------------------------- */
  /* The rail is gone — the navigation is the top bar. Kept because the
     settings screen's own left column is the same width, and one number for
     "a column of links" is better than two that drift apart. */
  --rail-w: 208px;
  /* The sticky header's height, as a token because anything that scrolls to a
     fragment has to clear it. Measured, not guessed: 44px of tap target plus
     the padding either side. */
  --topbar-h: 60px;
  --tabbar-h: calc(56px + env(safe-area-inset-bottom));
  --content-max: 1100px;
  /* A form or one record reads at 1100; a list or a board takes the window.
     A line of text 1,400px wide is a line nobody finishes. */
  --content-narrow: 1100px;
  /* Every tappable thing is at least this tall. 44px is Apple's number and
     Android's is 48dp; the larger of the two is the one to build to. */
  --tap: 44px;

  color-scheme: light dark;
}

/* ============================================================================
   Dark mode. It follows the device, and `data-theme` on <html> overrides it in
   either direction — so a person who wants light at night can have it, and a
   printed page is never dark.
   ========================================================================= */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --brand-ink: #0b1220;
    --brand: #93b4fd;
    --brand-strong: #bfd3ff;
    --brand-soft: #1e293b;
    --on-brand: #0b1220;

    /* The header and the primary button are separate roles from the brand ramp.
       Collapsing them is what makes a dark theme come out black-on-black: the
       header wants to stay dark in both schemes, while the primary button has to
       INVERT to stay legible. */
    --header-bg: #131c2e;
    --header-fg: #e8eef7;
    --primary-bg: #93b4fd;
    --primary-fg: #0b1220;
    --focus-ring: #93b4fd;

    --surface-page: #0b1220;
    --surface-card: #131c2e;
    --surface-sunken: #1b2539;
    --surface-inverse: #e8eef7;

    --text: #e8eef7;
    --text-muted: #b6c4d9;
    --text-subtle: #92a3bb;
    --text-on-inverse: #0b1220;

    --border: #263349;
    --border-strong: #35455f;

    /* The light pastels are unreadable on a dark card, so the status colours
       invert: a dark tint behind a light foreground, same five meanings. */
    --grey-bg: #1f2937;  --grey-fg: #cbd5e1;  --grey-line: #334155;
    --blue-bg: #14264a;  --blue-fg: #a8c5ff;  --blue-line: #1e3a8a;
    --green-bg: #0f2f1f; --green-fg: #86efac; --green-line: #166534;
    --amber-bg: #3a2a08; --amber-fg: #fcd34d; --amber-line: #92400e;
    --red-bg: #3a1417;   --red-fg: #fca5a5;   --red-line: #991b1b;
  --bell-red: #c81e1e;

    --shadow-sm: 0 1px 2px rgb(0 0 0 / 0.4);
    --shadow: 0 2px 10px rgb(0 0 0 / 0.5);
    --shadow-lg: 0 14px 36px rgb(0 0 0 / 0.6);
  }
}

:root[data-theme="dark"] {
  --brand-ink: #0b1220;
  --brand: #93b4fd;
  --brand-strong: #bfd3ff;
  --brand-soft: #1e293b;
  --on-brand: #0b1220;

  /* The header and the primary button are separate roles from the brand ramp.
     Collapsing them is what makes a dark theme come out black-on-black: the
     header wants to stay dark in both schemes, while the primary button has to
     INVERT to stay legible. */
  --header-bg: #131c2e;
  --header-fg: #e8eef7;
  --primary-bg: #93b4fd;
  --primary-fg: #0b1220;
  --focus-ring: #93b4fd;

  --surface-page: #0b1220;
  --surface-card: #131c2e;
  --surface-sunken: #1b2539;
  --surface-inverse: #e8eef7;

  --text: #e8eef7;
  --text-muted: #b6c4d9;
  --text-subtle: #92a3bb;
  --text-on-inverse: #0b1220;

  --border: #263349;
  --border-strong: #35455f;

  --grey-bg: #1f2937;  --grey-fg: #cbd5e1;  --grey-line: #334155;
  --blue-bg: #14264a;  --blue-fg: #a8c5ff;  --blue-line: #1e3a8a;
  --green-bg: #0f2f1f; --green-fg: #86efac; --green-line: #166534;
  --amber-bg: #3a2a08; --amber-fg: #fcd34d; --amber-line: #92400e;
  --red-bg: #3a1417;   --red-fg: #fca5a5;   --red-line: #991b1b;
  --bell-red: #c81e1e;

  --shadow-sm: 0 1px 2px rgb(0 0 0 / 0.4);
  --shadow: 0 2px 10px rgb(0 0 0 / 0.5);
  --shadow-lg: 0 14px 36px rgb(0 0 0 / 0.6);
}

/* Someone who has asked their device to stop animating gets no animation.
   Not "less" — none, other than the opacity fades that carry meaning. */
@media (prefers-reduced-motion: reduce) {
  :root { --fast: 1ms; --base: 1ms; }
  *, *::before, *::after {
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 1ms !important;
    scroll-behavior: auto !important;
  }
}

/* ---- the compatibility layer, and it is meant to be temporary --------------
   The screens built in steps 1-9 use these names. They now resolve to tokens,
   so a screen that has not been refactored yet still gets the new palette and
   dark mode for free. Nothing NEW should use them. */
:root {
  --fg: var(--text);
  --bg: var(--surface-page);
  --card: var(--surface-card);
  --line: var(--border);
  --muted: var(--text-subtle);
  --accent: var(--brand);
  --accent-ink: var(--on-brand);
  --tabh: var(--tabbar-h);
}
