/* web/shared/v3-tokens.css — V3 design system tokens + base components (design/v3-design-system.md, section 4).
 *
 * One file every V3 site shares (staff portal first, accounting AP1 next). No build step.
 * Theme: V3 Midnight is the signature theme and lives on bare :root. V3 Daylight applies when
 * the phone/computer is in light mode (Auto) or when <html data-theme="light"> is set;
 * <html data-theme="dark"> forces Midnight. Set data-theme before first paint (inline script)
 * so the page never flashes. All text/background pairs are contrast-checked in the design doc.
 * Status always shows an icon and a word as well as its color.
 *
 * Deployed to /shared/ in each portal's bucket (StmarkPortal first). A page links it; the staff
 * portal's own restyle (Phase 3) waits for Mark's preview approval.
 * Fonts are self-hosted from /shared/fonts (no Google Fonts calls).
 */

@font-face {
  font-family: 'Inter';
  src: url('fonts/inter-var-latin.woff2') format('woff2');
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'JetBrains Mono';
  src: url('fonts/jetbrains-mono-var-latin.woff2') format('woff2');
  font-weight: 100 800;
  font-style: normal;
  font-display: swap;
}

:root {
  /* V3 Midnight */
  --v3-bg: #0b1018;
  --v3-bg-raised: #121a26;
  --v3-card: #192332;
  --v3-border: #26334a;
  --v3-text: #f3f7fc;
  --v3-text-muted: #a5b3c5;
  --v3-text-subtle: #7c8ba1; /* timestamps only; the floor for text */
  --v3-accent: #5eeab0; /* mint */
  --v3-on-accent: #0b1018; /* dark text on mint buttons (12.6:1) */
  --v3-info: #22d3ee;
  --v3-success: #4ade80;
  --v3-warning: #fbbf24;
  --v3-critical: #f87171;
  --v3-accent-soft: rgba(94, 234, 176, 0.12);
  --v3-success-soft: rgba(74, 222, 128, 0.12);
  --v3-warning-soft: rgba(251, 191, 36, 0.12);
  --v3-critical-soft: rgba(248, 113, 113, 0.13);
  --v3-info-soft: rgba(34, 211, 238, 0.12);
  --v3-hero: linear-gradient(135deg, #17324a 0%, #143a35 100%);
  --v3-shadow: 0 1px 0 rgba(255, 255, 255, 0.03) inset;
  color-scheme: dark;

  /* Type, spacing, shape (same in both themes) */
  --v3-font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, system-ui, sans-serif;
  --v3-mono: 'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  --v3-fs-12: 12px;
  --v3-fs-14: 14px;
  --v3-fs-16: 16px;
  --v3-fs-20: 20px;
  --v3-fs-24: 24px;
  --v3-fs-32: 32px;
  --v3-r-input: 12px;
  --v3-r-card: 20px;
  --v3-r-pill: 999px;
  --v3-pad-card: 16px;
  --v3-touch: 44px;
  --v3-ease: 180ms ease;
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme='dark']) {
    /* V3 Daylight (Auto, light phone) */
    --v3-bg: #f5f7fb;
    --v3-bg-raised: #ffffff;
    --v3-card: #ffffff;
    --v3-border: #e2e8f0;
    --v3-text: #172033;
    --v3-text-muted: #5b6b82;
    --v3-text-subtle: #5b6b82;
    --v3-accent: #047857;
    --v3-on-accent: #ffffff;
    --v3-info: #0e7490;
    --v3-success: #15803d;
    --v3-warning: #b45309;
    --v3-critical: #b91c1c;
    --v3-accent-soft: rgba(4, 120, 87, 0.09);
    --v3-success-soft: rgba(21, 128, 61, 0.09);
    --v3-warning-soft: rgba(180, 83, 9, 0.09);
    --v3-critical-soft: rgba(185, 28, 28, 0.08);
    --v3-info-soft: rgba(14, 116, 144, 0.09);
    --v3-hero: linear-gradient(135deg, #e6f6f0 0%, #e3f1f7 100%);
    --v3-shadow: 0 1px 2px rgba(23, 32, 51, 0.06);
    color-scheme: light;
  }
}

:root[data-theme='light'] {
  /* V3 Daylight (chosen) — same values as above, so the choice wins both ways */
  --v3-bg: #f5f7fb;
  --v3-bg-raised: #ffffff;
  --v3-card: #ffffff;
  --v3-border: #e2e8f0;
  --v3-text: #172033;
  --v3-text-muted: #5b6b82;
  --v3-text-subtle: #5b6b82;
  --v3-accent: #047857;
  --v3-on-accent: #ffffff;
  --v3-info: #0e7490;
  --v3-success: #15803d;
  --v3-warning: #b45309;
  --v3-critical: #b91c1c;
  --v3-accent-soft: rgba(4, 120, 87, 0.09);
  --v3-success-soft: rgba(21, 128, 61, 0.09);
  --v3-warning-soft: rgba(180, 83, 9, 0.09);
  --v3-critical-soft: rgba(185, 28, 28, 0.08);
  --v3-info-soft: rgba(14, 116, 144, 0.09);
  --v3-hero: linear-gradient(135deg, #e6f6f0 0%, #e3f1f7 100%);
  --v3-shadow: 0 1px 2px rgba(23, 32, 51, 0.06);
  color-scheme: light;
}

@media (min-width: 1024px) {
  :root { --v3-pad-card: 20px; }
}

/* ---- Base ---------------------------------------------------------------- */
.v3 {
  background: var(--v3-bg);
  color: var(--v3-text);
  font-family: var(--v3-font);
  font-size: var(--v3-fs-16); /* never below 16px for body on phones (also stops iOS zoom) */
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
.v3 :focus-visible { outline: 2px solid var(--v3-accent); outline-offset: 2px; border-radius: 6px; }
.v3-mono { font-family: var(--v3-mono); font-variant-numeric: tabular-nums; }
.v3-muted { color: var(--v3-text-muted); }
.v3-subtle { color: var(--v3-text-subtle); font-size: var(--v3-fs-14); }
.v3-num { font-variant-numeric: tabular-nums; }

/* Card: the one object frame. Use by role, not on every block. */
.v3-card {
  background: var(--v3-card);
  border: 1px solid var(--v3-border);
  border-radius: var(--v3-r-card);
  padding: var(--v3-pad-card);
  box-shadow: var(--v3-shadow);
}

/* Buttons: 44px targets, 12px radius */
.v3-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--v3-touch); padding: 0 16px;
  border-radius: var(--v3-r-input); border: 1px solid var(--v3-border);
  background: transparent; color: var(--v3-text);
  font: 600 var(--v3-fs-14)/1 var(--v3-font); cursor: pointer;
  transition: background var(--v3-ease), border-color var(--v3-ease);
}
.v3-btn:hover { border-color: var(--v3-text-subtle); }
.v3-btn--primary { background: var(--v3-accent); border-color: var(--v3-accent); color: var(--v3-on-accent); }
.v3-btn--primary:hover { filter: brightness(1.05); }
.v3-btn--sm { min-height: 36px; padding: 0 12px; } /* desktop rows only */

/* Status pill: icon + word + color, never color alone */
.v3-pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px 3px 8px; border-radius: var(--v3-r-pill);
  font: 600 var(--v3-fs-12)/1.4 var(--v3-font); white-space: nowrap;
}
.v3-pill svg { width: 14px; height: 14px; flex: none; }
.v3-pill--current, .v3-pill--completed { color: var(--v3-success); background: var(--v3-success-soft); }
.v3-pill--expiring, .v3-pill--review { color: var(--v3-warning); background: var(--v3-warning-soft); }
.v3-pill--expired, .v3-pill--rejected, .v3-pill--failed { color: var(--v3-critical); background: var(--v3-critical-soft); }
.v3-pill--pending, .v3-pill--submitted { color: var(--v3-info); background: var(--v3-info-soft); }

/* Stat tile: big numeral, small label */
.v3-stat-label { font-size: var(--v3-fs-12); font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; color: var(--v3-text-muted); }
.v3-stat-value { font-size: var(--v3-fs-32); font-weight: 700; line-height: 1.1; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }

/* Freshness stamp: "Updated Nov 6, 6:00 AM"; warning style when older than its refresh */
.v3-fresh { display: inline-flex; align-items: center; gap: 6px; font-size: var(--v3-fs-14); color: var(--v3-text-muted); }
.v3-fresh--stale { color: var(--v3-warning); }

@media (prefers-reduced-motion: reduce) {
  .v3 *, .v3 *::before, .v3 *::after { transition: none !important; animation: none !important; }
}

/* ---- Generic status colors for pills outside the credential/request words ----
   (e.g. AP1 card-check results). Still icon + word + color. */
.v3-pill--success { color: var(--v3-success); background: var(--v3-success-soft); }
.v3-pill--warning { color: var(--v3-warning); background: var(--v3-warning-soft); }
.v3-pill--critical { color: var(--v3-critical); background: var(--v3-critical-soft); }
.v3-pill--info { color: var(--v3-info); background: var(--v3-info-soft); }
.v3-pill--neutral { color: var(--v3-text-muted); background: var(--v3-border); }

/* ======================================================================
   Desktop app shell (design/v3-design-system.md section 5): top bar with the
   workspace name, search, notifications and avatar; flat left sidebar; main
   column. First used by AP1 (accounting.stmarktransport.com).
   ====================================================================== */
.v3, .v3 body { margin: 0; }
.v3 *, .v3 *::before, .v3 *::after { box-sizing: border-box; }
.v3 a { color: var(--v3-info); text-decoration: none; }
.v3 a:hover { text-decoration: underline; }
.v3 h1, .v3 h2, .v3 h3 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
.v3 h1 { font-size: var(--v3-fs-24); }
.v3 h2 { font-size: var(--v3-fs-20); }

.v3-shell {
  display: grid;
  grid-template-columns: 232px 1fr;
  grid-template-rows: 56px 1fr;
  min-height: 100vh;
  /* the sidebar color runs the full height of long pages */
  background: linear-gradient(to right, var(--v3-bg-raised) 0 231px, var(--v3-border) 231px 232px, transparent 232px);
}
.v3-shell > * { min-width: 0; }
.v3-topbar {
  grid-column: 1 / -1;
  display: flex; align-items: center; gap: 12px;
  padding: 0 16px;
  background: var(--v3-bg-raised);
  border-bottom: 1px solid var(--v3-border);
  position: sticky; top: 0; z-index: 10;
}
.v3-topbar__spacer { flex: 1; }
.v3-mark {
  display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 8px;
  background: var(--v3-accent); color: var(--v3-on-accent);
  font-weight: 700; font-size: var(--v3-fs-12); letter-spacing: 0.02em;
}
.v3-workspace {
  display: inline-flex; align-items: center; gap: 8px; min-height: var(--v3-touch); padding: 0 12px;
  border-radius: var(--v3-r-input); border: 0; background: transparent; color: var(--v3-text);
  font: 600 var(--v3-fs-16)/1 var(--v3-font); cursor: pointer;
}
.v3-workspace:hover { background: var(--v3-card); }
.v3-search {
  flex: 1; max-width: 420px; margin-left: 16px;
  display: flex; align-items: center; gap: 8px; height: 36px; padding: 0 12px;
  border-radius: var(--v3-r-input); border: 1px solid var(--v3-border); background: var(--v3-bg);
  color: var(--v3-text-subtle); font-size: var(--v3-fs-14);
}
.v3-search kbd { margin-left: auto; font-family: var(--v3-mono); font-size: var(--v3-fs-12); border: 1px solid var(--v3-border); border-radius: 6px; padding: 0 6px; }
.v3-icon-btn {
  display: inline-grid; place-items: center; width: var(--v3-touch); height: var(--v3-touch);
  border-radius: var(--v3-r-input); border: 0; background: transparent; color: var(--v3-text-muted);
  cursor: pointer; position: relative; font: inherit;
}
.v3-icon-btn:hover { background: var(--v3-card); color: var(--v3-text); }
.v3-icon-btn__dot { position: absolute; top: 10px; right: 10px; width: 8px; height: 8px; border-radius: 50%; background: var(--v3-critical); border: 2px solid var(--v3-bg-raised); }
.v3-avatar {
  display: inline-grid; place-items: center; width: 32px; height: 32px; border-radius: 50%;
  background: var(--v3-card); border: 1px solid var(--v3-border); color: var(--v3-text);
  font-size: var(--v3-fs-12); font-weight: 600;
}
.v3-sidebar {
  padding: 12px; position: sticky; top: 56px; height: calc(100vh - 56px); overflow-y: auto;
}
.v3-nav { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.v3-nav a {
  display: flex; align-items: center; gap: 12px; min-height: 40px; padding: 0 12px;
  border-radius: 10px; color: var(--v3-text-muted); font-size: var(--v3-fs-14); font-weight: 500;
}
.v3-nav a:hover { background: var(--v3-card); color: var(--v3-text); text-decoration: none; }
.v3-nav a[aria-current='page'] { background: var(--v3-card); color: var(--v3-text); box-shadow: inset 2px 0 0 var(--v3-accent); }
.v3-nav svg { width: 18px; height: 18px; flex: none; }
.v3-nav__count { margin-left: auto; font-family: var(--v3-mono); font-size: var(--v3-fs-12); color: var(--v3-text-subtle); }
.v3-sidebar__foot { margin-top: 24px; padding: 12px; font-size: var(--v3-fs-12); color: var(--v3-text-subtle); }
.v3-main { padding: 24px 32px 32px; }
.v3-page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.v3-page-head p { margin: 4px 0 0; color: var(--v3-text-muted); font-size: var(--v3-fs-14); }
@media (max-width: 1023px) {
  .v3-shell { grid-template-columns: 1fr; grid-template-rows: 56px auto 1fr; background: none; }
  .v3-sidebar { position: static; height: auto; border-bottom: 1px solid var(--v3-border); background: var(--v3-bg-raised); padding: 8px 12px; overflow-x: auto; }
  .v3-nav { grid-auto-flow: column; grid-auto-columns: max-content; }
  .v3-sidebar__foot, .v3-search { display: none; }
  .v3-main { padding: 16px; }
}

/* Card header row, tiles, Action Center (the one hero card per page) */
.v3-card > header { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.v3-tiles { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 160px), 1fr)); }
.v3-tile { display: grid; gap: 8px; align-content: start; }
.v3-tile .v3-stat-label { display: flex; align-items: center; gap: 8px; }
.v3-tile .v3-stat-label svg { width: 16px; height: 16px; }
.v3-tile .v3-stat-value small { font-size: var(--v3-fs-16); font-weight: 500; color: var(--v3-text-muted); margin-left: 4px; }
.v3-tile__sub { font-size: var(--v3-fs-14); color: var(--v3-text-muted); }
.v3-hero { background: var(--v3-hero); }
.v3-actions { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.v3-action {
  display: flex; align-items: center; gap: 12px; min-height: 52px; padding: 8px 12px;
  border-radius: var(--v3-r-input); background: var(--v3-card); border: 1px solid var(--v3-border);
}
.v3-action__what { flex: 1; min-width: 0; }
.v3-action__what b { font-weight: 600; }
.v3-action__what .v3-subtle { display: block; }
@media (max-width: 600px) {
  .v3-action { flex-wrap: wrap; padding: 12px; }
  .v3-action__what { order: 3; flex-basis: 100%; }
  .v3-action .v3-btn { margin-left: auto; }
}

/* Banner (one line of context above the page, e.g. "dry run") */
.v3-banner {
  display: flex; align-items: flex-start; gap: 12px; padding: 12px 16px; margin-bottom: 20px;
  border-radius: var(--v3-r-input); font-size: var(--v3-fs-14);
  border: 1px solid var(--v3-border); background: var(--v3-info-soft);
}
.v3-banner svg { width: 18px; height: 18px; flex: none; margin-top: 2px; color: var(--v3-info); }
.v3-banner--warning { background: var(--v3-warning-soft); }
.v3-banner--warning svg { color: var(--v3-warning); }
.v3-fresh svg { width: 14px; height: 14px; }

/* Data table (Vercel style): quiet header, row hover, numbers right-aligned */
.v3-table-wrap { overflow-x: auto; margin: 0 calc(-1 * var(--v3-pad-card)); }
.v3-table { width: 100%; border-collapse: collapse; font-size: var(--v3-fs-14); }
.v3-table th {
  text-align: left; font-weight: 500; font-size: var(--v3-fs-12); color: var(--v3-text-subtle);
  text-transform: uppercase; letter-spacing: 0.04em; padding: 8px 12px;
  border-bottom: 1px solid var(--v3-border); white-space: nowrap;
}
.v3-table td { padding: 12px; border-bottom: 1px solid var(--v3-border); vertical-align: middle; }
.v3-table th:first-child, .v3-table td:first-child { padding-left: var(--v3-pad-card); }
.v3-table th:last-child, .v3-table td:last-child { padding-right: var(--v3-pad-card); }
.v3-table tr:last-child td { border-bottom: 0; }
.v3-table tbody tr { cursor: pointer; transition: background var(--v3-ease); }
.v3-table tbody tr:hover { background: var(--v3-bg-raised); }
.v3-table .v3-num { text-align: right; }
.v3-table__when { color: var(--v3-text-subtle); white-space: nowrap; }

/* Bar list: simple, decision-led bars */
.v3-bars { display: grid; gap: 12px; margin: 0; padding: 0; list-style: none; }
.v3-bars li { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; font-size: var(--v3-fs-14); }
.v3-bars__track { grid-column: 1 / -1; height: 6px; border-radius: var(--v3-r-pill); background: var(--v3-border); overflow: hidden; }
.v3-bars__fill { display: block; height: 100%; border-radius: inherit; background: var(--v3-accent); }
.v3-bars__fill--info { background: var(--v3-info); }

/* Empty, loading, error */
.v3-empty { text-align: center; padding: 32px 16px; color: var(--v3-text-muted); }
.v3-skeleton { border-radius: 8px; background: linear-gradient(90deg, var(--v3-border), var(--v3-card), var(--v3-border)); background-size: 200% 100%; animation: v3-shimmer 1.2s infinite; }
@keyframes v3-shimmer { to { background-position: -200% 0; } }
