/* tech2 design tokens
   Single source of truth for color, type, space, radius, elevation and motion.
   Every component reads semantic tokens (--bg, --text, --accent) — never raw palette
   values — so dark mode and any future rebrand are a change in this file alone. */

:root {
  color-scheme: light dark;

  /* ---- Palette: brand (anchored on the legacy highlight #003680) ---- */
  --blue-950: #001226;
  --blue-900: #001a3d;
  --blue-800: #002a5c;
  --blue-700: #003680;
  --blue-600: #0a4a9e;
  --blue-500: #1565c0;
  --blue-400: #4187d4;
  --blue-300: #7fb0e4;
  --blue-200: #b3d1f0;
  --blue-100: #d9e6f7;
  --blue-50:  #eef4fc;

  /* ---- Palette: neutrals ---- */
  --gray-950: #0b0e13;
  --gray-900: #12161d;
  --gray-850: #171c25;
  --gray-800: #1e242f;
  --gray-700: #2c3441;
  --gray-600: #495260;
  --gray-500: #6b7480;
  --gray-400: #949ca8;
  --gray-300: #c2c8d0;
  --gray-200: #dfe3e8;
  --gray-150: #eaedf1;
  --gray-100: #f2f4f7;
  --gray-50:  #f8f9fb;
  --white:    #ffffff;

  /* ---- Palette: status ---- */
  --red-600:    #c22b2b;
  --red-500:    #dc3545;
  --red-100:    #fbe3e5;
  --amber-600:  #b45309;
  --amber-500:  #f0a020;
  --amber-100:  #fdf0d5;
  --green-600:  #1a7f43;
  --green-500:  #22a75a;
  --green-100:  #ddf3e5;
  --violet-500: #6b46c1;

  /* ---- Semantic: light (default) ---- */
  --bg:            var(--gray-100);
  --bg-header:     var(--blue-700);
  --surface:       var(--white);
  --surface-sunk:  var(--gray-50);
  --surface-alt:   var(--gray-150);
  --scrim:         rgb(8 12 20 / 48%);

  --text:          var(--gray-900);
  --text-dim:      var(--gray-600);
  --text-faint:    var(--gray-500);
  --text-on-brand: var(--white);

  --border:        var(--gray-200);
  --border-strong: var(--gray-300);

  --accent:        var(--blue-700);
  --accent-hover:  var(--blue-600);
  --accent-soft:   var(--blue-50);
  --accent-text:   var(--blue-700);

  --danger:        var(--red-500);
  --danger-soft:   var(--red-100);
  --danger-text:   var(--red-600);
  --warn:          var(--amber-500);
  --warn-soft:     var(--amber-100);
  --warn-text:     #8a3f06;            /* amber-600 was 4.45:1 on its soft chip in sunlight */
  --ok:            var(--green-500);
  --ok-soft:       var(--green-100);
  --ok-text:       #14652f;            /* green-600 was 4.33:1 on its soft chip */

  /* Work order priority rails: PriorityCode 1 = Red Flag, 2 = End of Day */
  --prio-1: var(--red-500);
  --prio-2: var(--amber-500);
  --prio-0: var(--gray-300);

  /* ---- Type ---- */
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;

  --text-2xs: 0.6875rem; /* 11 */
  --text-xs:  0.75rem;   /* 12 */
  --text-sm:  0.8125rem; /* 13 */
  --text-md:  0.9375rem; /* 15 — body default, matches iOS */
  --text-lg:  1.0625rem; /* 17 */
  --text-xl:  1.25rem;   /* 20 */
  --text-2xl: 1.5rem;    /* 24 */
  --text-3xl: 1.9375rem; /* 31 */

  --weight-normal: 400;
  --weight-medium: 500;
  --weight-semi:   600;
  --weight-bold:   700;

  --leading-tight:  1.2;
  --leading-snug:   1.35;
  --leading-normal: 1.5;

  /* ---- Space (4px base) ---- */
  --s-1:  0.25rem;
  --s-2:  0.5rem;
  --s-3:  0.75rem;
  --s-4:  1rem;
  --s-5:  1.25rem;
  --s-6:  1.5rem;
  --s-8:  2rem;
  --s-10: 2.5rem;
  --s-12: 3rem;
  --s-16: 4rem;

  /* ---- Radius ---- */
  --r-xs:   4px;
  --r-sm:   8px;
  --r-md:   12px;
  --r-lg:   16px;
  --r-xl:   22px;
  --r-full: 999px;

  /* ---- Elevation ---- */
  --shadow-sm: 0 1px 2px rgb(12 18 28 / 6%), 0 1px 1px rgb(12 18 28 / 4%);
  --shadow-md: 0 2px 6px rgb(12 18 28 / 8%), 0 1px 2px rgb(12 18 28 / 6%);
  --shadow-lg: 0 8px 24px rgb(12 18 28 / 12%), 0 2px 6px rgb(12 18 28 / 8%);
  --shadow-up: 0 -2px 12px rgb(12 18 28 / 8%);

  /* ---- Sign-in ----
     Literal colours rather than semantic ones, and no dark-mode override, because the
     sign-in screen is deliberately dark in both themes: it is a brand moment with nothing
     to read, and a fixed dark field makes the keypad the only lit thing on the screen.
     Shared by .login-wrap and login.html's <body> so the gradient reaches the window edge
     rather than stopping at the 420px content column. */
  --login-bg: radial-gradient(120% 90% at 50% 22%, #1d3f6b 0%, #14294a 45%, #0b1626 100%);

  /* ---- Motion ---- */
  --dur-fast:  120ms;
  --dur-base:  200ms;
  --dur-slow:  320ms;
  --ease-out:    cubic-bezier(0.22, 1, 0.36, 1);
  --ease-in-out: cubic-bezier(0.65, 0, 0.35, 1);
  --ease-spring: cubic-bezier(0.34, 1.4, 0.64, 1);

  /* ---- Layout ---- */
  --header-h: 52px;
  --tabbar-h: 54px;
  --tap-min:  44px; /* never build a target smaller than this */
  --icon-md:  20px; /* default icon box; see .ico in components.css */
  --content-max: 720px;

  /* ---- Safe areas (fall back to 0 off-iOS) ---- */
  --sat: env(safe-area-inset-top, 0px);
  --sar: env(safe-area-inset-right, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);

  /* ---- Stacking ---- */
  --z-base:   0;
  --z-sticky: 10;
  --z-header: 20;
  --z-tabbar: 20;
  --z-fab:    25;
  --z-scrim:  30;
  --z-sheet:  35;
  --z-toast:  40;
  --z-viewer: 50;
}

/* ---- Semantic: dark. Techs work at night; this is not a nice-to-have. ---- */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:            var(--gray-950);
    --bg-header:     var(--gray-900);
    --surface:       var(--gray-850);
    --surface-sunk:  var(--gray-900);
    --surface-alt:   var(--gray-800);
    --scrim:         rgb(0 0 0 / 62%);

    --text:          var(--gray-100);
    --text-dim:      var(--gray-400);
    --text-faint:    var(--gray-400);   /* gray-500 was 3.6:1 on surface in dark */

    --border:        var(--gray-800);
    --border-strong: var(--gray-700);

    --accent:        var(--blue-400);
    --accent-hover:  var(--blue-300);
    --accent-soft:   rgb(65 135 212 / 14%);
    --accent-text:   var(--blue-300);

    --danger-soft:   rgb(220 53 69 / 16%);
    --danger-text:   #ff8b93;
    --warn-soft:     rgb(240 160 32 / 16%);
    --warn-text:     #f5c265;
    --ok-soft:       rgb(34 167 90 / 16%);
    --ok-text:       #6fd897;

    --shadow-sm: 0 1px 2px rgb(0 0 0 / 40%);
    --shadow-md: 0 2px 8px rgb(0 0 0 / 45%);
    --shadow-lg: 0 10px 30px rgb(0 0 0 / 55%);
    --shadow-up: 0 -2px 14px rgb(0 0 0 / 45%);
  }
}

/* Explicit override, set by the Me tab. */
[data-theme="dark"] {
  --bg:            var(--gray-950);
  --bg-header:     var(--gray-900);
  --surface:       var(--gray-850);
  --surface-sunk:  var(--gray-900);
  --surface-alt:   var(--gray-800);
  --scrim:         rgb(0 0 0 / 62%);
  --text:          var(--gray-100);
  --text-dim:      var(--gray-400);
  --text-faint:    var(--gray-400);   /* gray-500 was 3.6:1 on surface in dark */
  --border:        var(--gray-800);
  --border-strong: var(--gray-700);
  --accent:        var(--blue-400);
  --accent-hover:  var(--blue-300);
  --accent-soft:   rgb(65 135 212 / 14%);
  --accent-text:   var(--blue-300);
  --danger-soft:   rgb(220 53 69 / 16%);
  --danger-text:   #ff8b93;
  --warn-soft:     rgb(240 160 32 / 16%);
  --warn-text:     #f5c265;
  --ok-soft:       rgb(34 167 90 / 16%);
  --ok-text:       #6fd897;
  --shadow-sm: 0 1px 2px rgb(0 0 0 / 40%);
  --shadow-md: 0 2px 8px rgb(0 0 0 / 45%);
  --shadow-lg: 0 10px 30px rgb(0 0 0 / 55%);
  --shadow-up: 0 -2px 14px rgb(0 0 0 / 45%);
}

@media (prefers-reduced-motion: reduce) {
  :root {
    --dur-fast: 0ms;
    --dur-base: 0ms;
    --dur-slow: 0ms;
  }
}
