/* DriverVault webfonts — Archivo (UI + display, italic 800 is the brand voice) + DM Mono (data/labels).
   Must precede @import "tailwindcss": Tailwind v4 inlines its import into many
   rules, so any @import after it would violate CSS's "imports must come first". */
@import url("https://fonts.googleapis.com/css2?family=Archivo:ital,wght@0,400;0,500;0,600;0,700;0,800;1,600;1,700;1,800&family=DM+Mono:ital,wght@0,400;0,500;1,400&display=swap");

@import "tailwindcss";

/* Tailwind v4 defaults dark: to a prefers-color-scheme media query. We need
   theme to be user-selectable (light/dark/system), so switch it to a class
   strategy — prefs.js toggles .dark on <html> based on the saved preference. */
@custom-variant dark (&:where(.dark, .dark *));

/* ============================================================================
   DriverVault design tokens (from the design system). Raw ramps + semantic
   aliases live here as CSS custom properties; .dark re-points the aliases so
   any component styled with the aliases themes for free.
   ========================================================================== */
:root {
  color-scheme: light;

  /* ---- Brand blue ramp (from the DriverVault mark) ---- */
  --brand-900: #0b1730;
  --brand-800: #0f1e3d;
  --brand-700: #1e40af;
  --brand-600: #2563eb;
  --brand-500: #3b82f6;
  --brand-400: #60a5fa;
  --brand-300: #93c5fd;
  --brand-200: #c7dbfb;
  --brand-100: #e8f0fd;

  /* ---- Cool neutrals ---- */
  --ink-900: #0f1e3d;
  --ink-700: #28374f;
  --ink-600: #3e4e68;
  --ink-500: #5c6b85;
  --ink-400: #7a8aa6;
  --ink-300: #b4bece;
  --ink-200: #d6deea;
  --ink-100: #e4e9f2;
  --ink-50: #eef2f8;
  --ink-25: #f7f9fc;
  --white: #ffffff;

  /* ---- Semantic (car status: OK / due / fault) ---- */
  --success-600: #1f8a5b;
  --success-100: #e1f3ea;
  --warning-600: #d9822b;
  --warning-100: #fbeddd;
  --danger-600: #dc2a45;
  --danger-100: #fbe3e7;
  --info-600: #2563eb;
  --info-100: #e8f0fd;

  /* ---- Semantic aliases ---- */
  --surface-page: var(--ink-25);
  --surface-card: var(--white);
  --surface-sunken: var(--ink-50);
  --surface-inverse: var(--brand-900);

  --border-subtle: var(--ink-100);
  --border-default: var(--ink-200);
  --border-strong: var(--ink-300);

  --text-strong: var(--ink-900);
  --text-body: var(--ink-600);
  --text-muted: var(--ink-400);
  --text-inverse: var(--white);
  --text-brand: var(--brand-700);

  --accent: var(--brand-600);
  --accent-hover: var(--brand-700);
  --accent-press: var(--brand-800);
  --focus-ring: var(--brand-400);

  /* ---- Elevation (soft, cool, low-spread) ---- */
  --shadow-xs: 0 1px 2px rgba(15, 30, 61, 0.06);
  --shadow-sm: 0 1px 2px rgba(15, 30, 61, 0.04), 0 2px 6px rgba(15, 30, 61, 0.06);
  --shadow-md: 0 1px 2px rgba(15, 30, 61, 0.04), 0 12px 30px -12px rgba(15, 30, 61, 0.14);
  --shadow-lg: 0 1px 2px rgba(15, 30, 61, 0.04), 0 24px 60px -28px rgba(15, 30, 61, 0.22);
  --shadow-focus: 0 0 0 3px rgba(96, 165, 250, 0.45);

  /* ---- Type ---- */
  --font-display: "Archivo", system-ui, sans-serif;
  --font-sans: "Archivo", system-ui, sans-serif;
  --font-mono: "DM Mono", ui-monospace, "SF Mono", monospace;
}

/* Dark theme — prefs.js toggles .dark on <html>. Re-points semantic aliases +
   the raw ramp steps a few surfaces read directly (from the DS dark.css). */
html.dark {
  color-scheme: dark;

  /* Raw ramp steps used directly by some surfaces (tracks, tints, washes) */
  --ink-25: #0b1730;
  --ink-50: #132441;
  --ink-100: #1b2c49;
  --ink-200: #26395a;
  --ink-300: #3c5173;
  --brand-100: #17294a;

  /* Semantic status tints, re-cut for dark surfaces */
  --success-100: #12352a;
  --warning-100: #3a2a16;
  --danger-100: #3a1620;
  --info-100: #122a4d;

  --surface-page: #0b1730;
  --surface-card: #13233f;
  --surface-sunken: #0f1e38;
  --surface-inverse: #f2f6fc;

  --border-subtle: #21324f;
  --border-default: #2c3f5e;
  --border-strong: #3c5173;

  --text-strong: #f2f6fc;
  --text-body: #b7c4d9;
  --text-muted: #7c8ca8;
  --text-inverse: #0b1730;
  --text-brand: #93c5fd;

  --accent: #3b82f6;
  --accent-hover: #60a5fa;
  --accent-press: #2563eb;
  --focus-ring: #60a5fa;

  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4), 0 2px 6px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 1px 2px rgba(0, 0, 0, 0.35), 0 12px 30px -12px rgba(0, 0, 0, 0.55);
  --shadow-lg: 0 1px 2px rgba(0, 0, 0, 0.4), 0 24px 60px -28px rgba(0, 0, 0, 0.65);
  --shadow-focus: 0 0 0 3px rgba(96, 165, 250, 0.5);
}

/* ============================================================================
   Map DriverVault tokens into Tailwind's theme so semantic utilities exist:
   bg-card, bg-page, text-strong, text-muted, border-subtle, bg-brand-600,
   text-success, bg-warning-soft, shadow-card, rounded-card, font-mono, etc.
   `inline` keeps the var() reference in generated utilities so they flip in
   dark mode automatically (no dark: variant needed for semantic colors).
   ========================================================================== */
@theme inline {
  --font-sans: var(--font-sans);
  --font-mono: var(--font-mono);

  /* Brand ramp */
  --color-brand-100: var(--brand-100);
  --color-brand-200: var(--brand-200);
  --color-brand-300: var(--brand-300);
  --color-brand-400: var(--brand-400);
  --color-brand-500: var(--brand-500);
  --color-brand-600: var(--brand-600);
  --color-brand-700: var(--brand-700);
  --color-brand-800: var(--brand-800);
  --color-brand-900: var(--brand-900);

  /* Surfaces */
  --color-page: var(--surface-page);
  --color-card: var(--surface-card);
  --color-sunken: var(--surface-sunken);
  --color-inverse: var(--surface-inverse);

  /* Text */
  --color-strong: var(--text-strong);
  --color-body: var(--text-body);
  --color-muted: var(--text-muted);
  --color-brandtext: var(--text-brand);
  --color-oninverse: var(--text-inverse);

  /* Borders (color tokens — used as border-subtle/default/strong) */
  --color-subtle: var(--border-subtle);
  --color-default: var(--border-default);
  --color-strongline: var(--border-strong);

  /* Accent + focus */
  --color-accent: var(--accent);
  --color-accent-hover: var(--accent-hover);
  --color-accent-press: var(--accent-press);
  --color-focus: var(--focus-ring);

  /* Status — solid (600) + soft tint (100) */
  --color-success: var(--success-600);
  --color-success-soft: var(--success-100);
  --color-warning: var(--warning-600);
  --color-warning-soft: var(--warning-100);
  --color-danger: var(--danger-600);
  --color-danger-soft: var(--danger-100);
  --color-info: var(--info-600);
  --color-info-soft: var(--info-100);

  /* Radius */
  --radius-control: 12px;
  --radius-card: 22px;
  --radius-pill: 999px;

  /* Elevation */
  --shadow-xs: var(--shadow-xs);
  --shadow-sm: var(--shadow-sm);
  --shadow-card: var(--shadow-md);
  --shadow-pop: var(--shadow-lg);
}

html,
body,
#app {
  height: 100%;
}

body {
  margin: 0;
  font-family: var(--font-sans);
  background: var(--surface-page);
  color: var(--text-body);
  -webkit-font-smoothing: antialiased;
}

/* Small mono eyebrow labels / data units (RANGE, TIRE PSI, LAST SERVICE). */
.eyebrow {
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.16em;
  font-size: 11px;
  color: var(--text-muted);
}

/* Monospaced data (numbers, units, VINs) so columns align. */
.data {
  font-family: var(--font-mono);
  letter-spacing: 0.02em;
  font-variant-numeric: tabular-nums;
}

/* ============================================================================
   DriverVault component primitives — shared class recipes so every view stays on
   brand without repeating long utility strings. Styled via semantic tokens so
   they flip in dark mode automatically.
   ========================================================================== */
@layer components {
  /* Cards: border + soft shadow together, generous radius. */
  .dh-card {
    background: var(--surface-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-card);
    box-shadow: var(--shadow-md);
  }

  /* Buttons — shared shape/motion. */
  .dh-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    border-radius: var(--radius-control);
    padding: 0.5rem 1rem;
    font-weight: 600;
    font-size: 0.875rem;
    line-height: 1.25rem;
    transition: background-color 0.15s cubic-bezier(0.2, 0.7, 0.2, 1),
      color 0.15s, border-color 0.15s, transform 0.15s, box-shadow 0.15s;
    cursor: pointer;
    white-space: nowrap;
  }
  .dh-btn:focus-visible {
    outline: none;
    box-shadow: var(--shadow-focus);
  }
  .dh-btn:active {
    transform: scale(0.98);
  }
  .dh-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
  }

  .dh-btn-primary {
    background: var(--accent);
    color: #fff;
  }
  .dh-btn-primary:hover:not(:disabled) {
    background: var(--accent-hover);
  }
  .dh-btn-primary:active:not(:disabled) {
    background: var(--accent-press);
  }

  .dh-btn-ghost {
    background: transparent;
    color: var(--text-body);
    border: 1px solid var(--border-subtle);
  }
  .dh-btn-ghost:hover:not(:disabled) {
    background: var(--surface-sunken);
    color: var(--text-strong);
  }

  .dh-btn-danger {
    background: var(--danger-600);
    color: #fff;
  }
  .dh-btn-danger:hover:not(:disabled) {
    filter: brightness(0.94);
  }

  /* Text/number fields + selects. */
  .dh-input {
    width: 100%;
    background: var(--surface-card);
    color: var(--text-strong);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-control);
    padding: 0.5rem 0.75rem;
    font-size: 0.875rem;
    line-height: 1.25rem;
    transition: border-color 0.15s, box-shadow 0.15s;
  }
  .dh-input::placeholder {
    color: var(--text-muted);
  }
  .dh-input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: var(--shadow-focus);
  }

  /* DateField: the browser's picker parked out of sight behind the calendar
     button, so the visible box can keep the user's own segment order. Not
     display:none — showPicker() needs a rendered element to open against. */
  .dv-date-picker {
    position: absolute;
    right: 0.5rem;
    bottom: 0;
    width: 1px;
    height: 1px;
    padding: 0;
    border: 0;
    opacity: 0;
    pointer-events: none;
  }
  .dv-date-open {
    position: absolute;
    top: 50%;
    right: 0.25rem;
    transform: translateY(-50%);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.25rem;
    border-radius: var(--radius-control);
    color: var(--text-muted);
    transition: color 0.15s, background 0.15s;
  }
  .dv-date-open:hover {
    color: var(--text-strong);
    background: var(--surface-sunken);
  }
  .dv-date-open:focus-visible {
    outline: none;
    color: var(--text-strong);
    box-shadow: var(--shadow-focus);
  }

  .dh-label {
    display: block;
    margin-bottom: 0.375rem;
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--text-body);
  }

  /* Status pills — soft tint + solid text. */
  .dh-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    border-radius: var(--radius-pill);
    padding: 0.125rem 0.625rem;
    font-size: 0.75rem;
    font-weight: 600;
    line-height: 1.25rem;
  }
  .dh-badge-success {
    background: var(--success-100);
    color: var(--success-600);
  }
  .dh-badge-warning {
    background: var(--warning-100);
    color: var(--warning-600);
  }
  .dh-badge-danger {
    background: var(--danger-100);
    color: var(--danger-600);
  }
  .dh-badge-neutral {
    background: var(--surface-sunken);
    color: var(--text-muted);
  }
}
