/* ============================================================
   GZT DESIGN TOKENS
   Load order in _Layout.cshtml:
     bootstrap.min.css -> fontawesome -> fonts.css -> tokens.css
     -> components.css -> Gzt.UI.WebApp.styles.css

   Three layers, in order (see docs/DesignSystem.md -> Foundations):
     1. PRIMITIVE  - raw palette / scale values. The ONLY place a raw
                     hex or px literal is allowed to appear.
     2. SEMANTIC   - role tokens (--gz-surface, --gz-accent, ...), one
                     set for light on :root, one for dark. Views and
                     components reference these, never a primitive.
     3. BS BRIDGE  - maps Bootstrap's own --bs-* custom properties to
                     the semantic tokens so stock components re-skin
                     themselves. Plus the handful of component-level
                     re-declarations Bootstrap needs because it bakes
                     literal hex per-variant (.btn-primary etc.).

   Chaos-prevention rules for anyone touching UI:
     - No raw hex/px outside layer 1 here.
     - No inline style="" in views - add a token-based class instead.
     - Every named component class has a spec entry in DesignSystem.md.
   ============================================================ */

/* ============================================================
   LAYER 1 - PRIMITIVES
   ============================================================ */
:root {
  /* ---- Palette ramps (Tailwind-derived, accent centred on #2563EB) ---- */
  --gz-blue-50:  #EFF6FF;
  --gz-blue-100: #DBEAFE;
  --gz-blue-200: #BFDBFE;
  --gz-blue-300: #93C5FD;
  --gz-blue-400: #60A5FA;
  --gz-blue-500: #3B82F6;
  --gz-blue-600: #2563EB;
  --gz-blue-700: #1D4ED8;
  --gz-blue-800: #1E40AF;
  --gz-blue-900: #1E3A8A;

  --gz-red-50:  #FEF2F2;
  --gz-red-100: #FEE2E2;
  --gz-red-300: #FCA5A5;
  --gz-red-400: #F87171;
  --gz-red-500: #EF4444;
  --gz-red-600: #DC2626;
  --gz-red-700: #B91C1C;

  --gz-green-50:  #F0FDF4;
  --gz-green-100: #DCFCE7;
  --gz-green-400: #4ADE80;
  --gz-green-500: #22C55E;
  --gz-green-600: #16A34A;
  --gz-green-700: #15803D;

  --gz-amber-50:  #FFFBEB;
  --gz-amber-100: #FEF3C7;
  --gz-amber-400: #FBBF24;
  --gz-amber-500: #F59E0B;
  --gz-amber-600: #D97706;
  --gz-amber-700: #B45309;

  --gz-slate-0:   #FFFFFF;
  --gz-slate-50:  #F8FAFC;
  --gz-slate-100: #F1F5F9;
  --gz-slate-200: #E2E8F0;
  --gz-slate-300: #CBD5E1;
  --gz-slate-400: #94A3B8;
  --gz-slate-500: #64748B;
  --gz-slate-600: #475569;
  --gz-slate-700: #334155;
  --gz-slate-800: #1E293B;
  --gz-slate-900: #0F172A;
  --gz-slate-950: #020617;

  /* Blue-tinted neutrals used for canvas / muted / border in light mode
     (a straight slate reads colder than the "inbox" feel we want). */
  --gz-mist-canvas: #F7F9FE;
  --gz-mist-muted:  #F1F5FD;
  --gz-mist-border: #E4ECFC;

  /* Blue-tinted dark surfaces (DesignSystem.md colour table). */
  --gz-night-canvas:  #070C16;
  --gz-night-surface: #0B1220;
  --gz-night-raised:  #121A2A;
  --gz-night-muted:   #151C2C;
  --gz-night-border:  #243044;
  --gz-night-border-strong: #33415A;

  /* ---- Spacing scale (4px base) ---- */
  --gz-space-1: 0.25rem;  /* 4  */
  --gz-space-2: 0.5rem;   /* 8  */
  --gz-space-3: 0.75rem;  /* 12 */
  --gz-space-4: 1rem;     /* 16 */
  --gz-space-5: 1.25rem;  /* 20 */
  --gz-space-6: 1.5rem;   /* 24 */
  --gz-space-7: 2rem;     /* 32 */
  --gz-space-8: 2.5rem;   /* 40 */
  --gz-space-9: 3rem;     /* 48 */
  --gz-space-10: 4rem;    /* 64 */
  --gz-space-11: 5rem;    /* 80 */
  --gz-space-12: 6rem;    /* 96 */

  /* ---- Radius ---- */
  --gz-radius-sm: 0.375rem;
  --gz-radius: 0.5rem;
  --gz-radius-lg: 0.75rem;
  --gz-radius-xl: 1rem;
  --gz-radius-pill: 999px;

  /* ---- Type scale ---- */
  --gz-text-xs: 0.75rem;    /* 12 */
  --gz-text-sm: 0.8125rem;  /* 13 */
  --gz-text-md: 0.875rem;   /* 14 */
  --gz-text-base: 1rem;     /* 16 */
  --gz-text-lg: 1.125rem;   /* 18 */
  --gz-text-xl: 1.25rem;    /* 20 */
  --gz-text-2xl: 1.5rem;    /* 24 */
  --gz-text-3xl: 1.875rem;  /* 30 */
  --gz-leading-tight: 1.25;
  --gz-leading-snug: 1.4;
  --gz-leading-normal: 1.6;

  /* impeccable-disable-line overused-font -- deliberate, see DesignSystem.md */
  --gz-font-sans: "Plus Jakarta Sans", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --gz-font-mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;

  /* ---- Elevation (light) ---- */
  --gz-shadow-0: none;
  --gz-shadow-1: 0 1px 2px rgba(15, 23, 42, 0.04), 0 1px 3px rgba(15, 23, 42, 0.06);
  --gz-shadow-2: 0 2px 4px rgba(15, 23, 42, 0.05), 0 6px 16px rgba(15, 23, 42, 0.08);
  --gz-shadow-3: 0 8px 24px rgba(15, 23, 42, 0.12), 0 2px 8px rgba(15, 23, 42, 0.08);
  --gz-shadow-4: 0 16px 48px rgba(15, 23, 42, 0.18);

  /* ---- Motion ---- */
  --gz-dur-fast: 120ms;
  --gz-dur: 180ms;
  --gz-dur-slow: 220ms;
  --gz-ease: cubic-bezier(0.2, 0, 0, 1);          /* standard - decelerate on arrival */
  --gz-ease-out: cubic-bezier(0.16, 1, 0.3, 1);   /* pronounced ease-out for entrances */

  /* ---- Icon sizing ---- */
  --gz-icon-sm: 0.875rem;
  --gz-icon-md: 1rem;
  --gz-icon-lg: 1.25rem;

  /* ---- Z-index scale (aligned with Bootstrap's own) ---- */
  --gz-z-sidebar: 1020;
  --gz-z-sticky: 1020;
  --gz-z-dropdown: 1000;
  --gz-z-modal: 1055;
  --gz-z-toast: 1090;
}

/* ============================================================
   LAYER 2 - SEMANTIC TOKENS
   ============================================================ */
:root {
  --gz-canvas: var(--gz-mist-canvas);
  --gz-surface: var(--gz-slate-0);
  --gz-surface-raised: var(--gz-slate-0);
  --gz-surface-muted: var(--gz-mist-muted);
  --gz-border: var(--gz-mist-border);
  --gz-border-strong: var(--gz-slate-300);

  --gz-text-primary: var(--gz-slate-900);
  --gz-text-secondary: var(--gz-slate-600);
  --gz-text-faint: #8A96A8;
  --gz-text-primary-rgb: 15, 23, 42;
  --gz-text-secondary-rgb: 71, 85, 105;

  --gz-accent: var(--gz-blue-600);
  --gz-accent-hover: var(--gz-blue-700);
  --gz-accent-soft: var(--gz-blue-50);
  --gz-accent-contrast: #FFFFFF;
  --gz-accent-rgb: 37, 99, 235;

  --gz-priority: var(--gz-red-600);
  --gz-priority-soft: var(--gz-red-50);
  --gz-priority-rgb: 220, 38, 38;

  --gz-success: var(--gz-green-600);
  --gz-success-soft: var(--gz-green-50);
  --gz-success-rgb: 22, 163, 74;

  --gz-warning: var(--gz-amber-600);
  --gz-warning-soft: var(--gz-amber-50);
  --gz-warning-rgb: 217, 119, 6;

  --gz-focus-ring: rgba(37, 99, 235, 0.35);

  --gz-elevation-flat: var(--gz-shadow-0);
  --gz-elevation-card: var(--gz-shadow-1);
  --gz-elevation-raised: var(--gz-shadow-2);
  --gz-elevation-overlay: var(--gz-shadow-3);
  --gz-elevation-popover: var(--gz-shadow-4);
}

:root[data-bs-theme="dark"] {
  --gz-canvas: var(--gz-night-canvas);
  --gz-surface: var(--gz-night-surface);
  --gz-surface-raised: var(--gz-night-raised);
  --gz-surface-muted: var(--gz-night-muted);
  --gz-border: var(--gz-night-border);
  --gz-border-strong: var(--gz-night-border-strong);

  --gz-text-primary: var(--gz-slate-100);
  --gz-text-secondary: var(--gz-slate-400);
  --gz-text-faint: #6B7A90;
  --gz-text-primary-rgb: 241, 245, 249;
  --gz-text-secondary-rgb: 148, 163, 184;

  --gz-accent: var(--gz-blue-400);
  --gz-accent-hover: var(--gz-blue-300);
  --gz-accent-soft: rgba(96, 165, 250, 0.14);
  --gz-accent-contrast: var(--gz-night-surface);
  --gz-accent-rgb: 96, 165, 250;

  --gz-priority: var(--gz-red-400);
  --gz-priority-soft: rgba(248, 113, 113, 0.14);
  --gz-priority-rgb: 248, 113, 113;

  --gz-success: var(--gz-green-400);
  --gz-success-soft: rgba(74, 222, 128, 0.14);
  --gz-success-rgb: 74, 222, 128;

  --gz-warning: var(--gz-amber-400);
  --gz-warning-soft: rgba(251, 191, 36, 0.14);
  --gz-warning-rgb: 251, 191, 36;

  --gz-focus-ring: rgba(96, 165, 250, 0.4);

  --gz-shadow-1: 0 1px 2px rgba(0, 0, 0, 0.4), 0 1px 3px rgba(0, 0, 0, 0.5);
  --gz-shadow-2: 0 2px 4px rgba(0, 0, 0, 0.4), 0 6px 16px rgba(0, 0, 0, 0.5);
  --gz-shadow-3: 0 8px 24px rgba(0, 0, 0, 0.55), 0 2px 8px rgba(0, 0, 0, 0.45);
  --gz-shadow-4: 0 16px 48px rgba(0, 0, 0, 0.6);
}

/* No-JS fallback: if the head script never ran, honour the OS setting.
   The head script normally stamps data-bs-theme on <html> before paint,
   so in practice one of the blocks above wins. */
@media (prefers-color-scheme: dark) {
  :root:not([data-bs-theme]) {
    color-scheme: dark;
    --gz-canvas: var(--gz-night-canvas);
    --gz-surface: var(--gz-night-surface);
    --gz-surface-raised: var(--gz-night-raised);
    --gz-surface-muted: var(--gz-night-muted);
    --gz-border: var(--gz-night-border);
    --gz-border-strong: var(--gz-night-border-strong);
    --gz-text-primary: var(--gz-slate-100);
    --gz-text-secondary: var(--gz-slate-400);
    --gz-text-faint: #6B7A90;
    --gz-accent: var(--gz-blue-400);
    --gz-accent-hover: var(--gz-blue-300);
    --gz-accent-soft: rgba(96, 165, 250, 0.14);
    --gz-accent-contrast: var(--gz-night-surface);
    --gz-accent-rgb: 96, 165, 250;
    --gz-priority: var(--gz-red-400);
    --gz-priority-rgb: 248, 113, 113;
    --gz-success: var(--gz-green-400);
    --gz-success-rgb: 74, 222, 128;
    --gz-warning: var(--gz-amber-400);
    --gz-warning-rgb: 251, 191, 36;
    --gz-focus-ring: rgba(96, 165, 250, 0.4);
  }
}

/* ============================================================
   LAYER 3 - BOOTSTRAP BRIDGE
   Bootstrap components read these --bs-* vars in the compiled CSS,
   so remapping them here reskins .card / .btn / .form-control /
   .dropdown-menu / .modal / .table / .nav / .alert / .badge with no
   new selectors. Applied under both themes; Bootstrap 5.3 ships its
   own dark --bs-* values, we override only the ones tied to a
   semantic token.
   ============================================================ */
:root,
:root[data-bs-theme="dark"] {
  --bs-font-sans-serif: var(--gz-font-sans);
  --bs-font-monospace: var(--gz-font-mono);
  --bs-body-font-size: var(--gz-text-base);
  --bs-body-line-height: var(--gz-leading-normal);

  --bs-body-bg: var(--gz-canvas);
  --bs-body-color: var(--gz-text-primary);
  --bs-emphasis-color: var(--gz-text-primary);
  --bs-secondary-color: var(--gz-text-secondary);
  --bs-secondary-bg: var(--gz-surface-muted);
  --bs-tertiary-bg: var(--gz-surface-muted);
  --bs-tertiary-color: var(--gz-text-faint);

  --bs-border-color: var(--gz-border);
  --bs-border-color-translucent: var(--gz-border);
  --bs-border-radius: var(--gz-radius);
  --bs-border-radius-sm: var(--gz-radius-sm);
  --bs-border-radius-lg: var(--gz-radius-lg);
  --bs-border-radius-xl: var(--gz-radius-xl);

  --bs-primary: var(--gz-accent);
  --bs-primary-rgb: var(--gz-accent-rgb);
  --bs-link-color: var(--gz-accent);
  --bs-link-color-rgb: var(--gz-accent-rgb);
  --bs-link-hover-color: var(--gz-accent-hover);

  --bs-success-rgb: var(--gz-success-rgb);
  --bs-warning-rgb: var(--gz-warning-rgb);
  --bs-danger-rgb: var(--gz-priority-rgb);

  --bs-box-shadow: var(--gz-shadow-2);
  --bs-box-shadow-sm: var(--gz-shadow-1);
  --bs-box-shadow-lg: var(--gz-shadow-3);

  --bs-focus-ring-color: var(--gz-focus-ring);
  --bs-focus-ring-width: 0.2rem;
}

/* .btn-primary bakes its colours as literal hex per-variant in the
   compiled CSS (not derived from --bs-primary), so retheming means
   redeclaring the same --bs-btn-* props Bootstrap declares on this
   selector. Same pattern for .btn-warning / .dropdown-menu /
   .pagination below - all confirmed against compiled bootstrap.css. */
.btn-primary {
  --bs-btn-color: var(--gz-accent-contrast);
  --bs-btn-bg: var(--gz-accent);
  --bs-btn-border-color: var(--gz-accent);
  --bs-btn-hover-color: var(--gz-accent-contrast);
  --bs-btn-hover-bg: var(--gz-accent-hover);
  --bs-btn-hover-border-color: var(--gz-accent-hover);
  --bs-btn-focus-shadow-rgb: var(--gz-accent-rgb);
  --bs-btn-active-color: var(--gz-accent-contrast);
  --bs-btn-active-bg: var(--gz-accent-hover);
  --bs-btn-active-border-color: var(--gz-accent-hover);
  --bs-btn-disabled-color: var(--gz-accent-contrast);
  --bs-btn-disabled-bg: var(--gz-accent);
  --bs-btn-disabled-border-color: var(--gz-accent);
}

/* Retry actions (issue #104) use warning, not danger - retry re-queues
   work, it doesn't destroy anything - so the button must read as the
   same gold as the Tier1/Tier2 badges, not Bootstrap's stock #ffc107. */
.btn-warning {
  --bs-btn-color: var(--gz-slate-900);
  --bs-btn-bg: rgb(var(--gz-warning-rgb));
  --bs-btn-border-color: rgb(var(--gz-warning-rgb));
  --bs-btn-hover-color: var(--gz-slate-900);
  --bs-btn-hover-bg: var(--gz-amber-700);
  --bs-btn-hover-border-color: var(--gz-amber-700);
  --bs-btn-focus-shadow-rgb: var(--gz-warning-rgb);
  --bs-btn-active-color: var(--gz-slate-900);
  --bs-btn-active-bg: var(--gz-amber-700);
  --bs-btn-active-border-color: var(--gz-amber-700);
  --bs-btn-disabled-color: var(--gz-slate-900);
  --bs-btn-disabled-bg: rgb(var(--gz-warning-rgb));
  --bs-btn-disabled-border-color: rgb(var(--gz-warning-rgb));
}

.btn-outline-warning {
  --bs-btn-color: rgb(var(--gz-warning-rgb));
  --bs-btn-border-color: rgb(var(--gz-warning-rgb));
  --bs-btn-hover-color: var(--gz-slate-900);
  --bs-btn-hover-bg: rgb(var(--gz-warning-rgb));
  --bs-btn-hover-border-color: rgb(var(--gz-warning-rgb));
  --bs-btn-focus-shadow-rgb: var(--gz-warning-rgb);
  --bs-btn-active-color: var(--gz-slate-900);
  --bs-btn-active-bg: rgb(var(--gz-warning-rgb));
  --bs-btn-active-border-color: rgb(var(--gz-warning-rgb));
  --bs-btn-disabled-color: rgb(var(--gz-warning-rgb));
  --bs-btn-disabled-border-color: rgb(var(--gz-warning-rgb));
}

.dropdown-menu {
  --bs-dropdown-link-active-bg: var(--gz-accent);
  --bs-dropdown-link-active-color: var(--gz-accent-contrast);
  --bs-dropdown-bg: var(--gz-surface-raised);
  --bs-dropdown-border-color: var(--gz-border);
  --bs-dropdown-box-shadow: var(--gz-shadow-3);
}

.pagination {
  --bs-pagination-active-bg: var(--gz-accent);
  --bs-pagination-active-border-color: var(--gz-accent);
  --bs-pagination-hover-color: var(--gz-accent-hover);
  --bs-pagination-color: var(--gz-text-secondary);
  --bs-pagination-bg: var(--gz-surface-raised);
}

/* ============================================================
   SURFACES vs PAGE CANVAS - .card / .modal-content / .dropdown-menu
   / .form-control / .form-select tie their background to --bs-body-bg
   in compiled Bootstrap (no intermediate surface variable). Since we
   remap --bs-body-bg to the canvas above, each needs its own explicit
   raised-surface background or it flattens onto the page.
   ============================================================ */
.card {
  --bs-card-bg: var(--gz-surface-raised);
  --bs-card-border-color: var(--gz-border);
  --bs-card-cap-bg: transparent;
  /* Bootstrap's .card has no shadow by default and exposes no variable for
     one; the design system puts every card at elevation-1 (DesignSystem.md
     -> Elevation), so set it here rather than sprinkling .shadow-sm in markup. */
  box-shadow: var(--gz-shadow-1);
}

.modal-content {
  --bs-modal-bg: var(--gz-surface-raised);
  --bs-modal-border-color: var(--gz-border);
  --bs-modal-box-shadow: var(--gz-shadow-3);
}

.form-control,
.form-select {
  background-color: var(--gz-surface-raised);
}

.list-group {
  --bs-list-group-bg: var(--gz-surface-raised);
  --bs-list-group-border-color: var(--gz-border);
  --bs-list-group-action-hover-bg: var(--gz-surface-muted);
}

.table {
  /* Sits inside a .card which already provides the surface colour -
     transparent so the two don't double up at the edges. */
  --bs-table-bg: transparent;
  --bs-table-hover-bg: var(--gz-surface-muted);
  --bs-table-border-color: var(--gz-border);
}

/* ============================================================
   TYPOGRAPHY - Bootstrap's heading sizes are hardcoded fluid calc()
   in compiled CSS, not variables, so the restrained scale is a raw
   override. Weight carries hierarchy (DesignSystem.md -> Typography).
   ============================================================ */
h1, h2, h3, h4, h5, h6,
.h1, .h2, .h3, .h4, .h5, .h6 {
  color: var(--gz-text-primary);
  font-weight: 700;
  letter-spacing: -0.014em;
  line-height: var(--gz-leading-tight);
}

h1, .h1 { font-size: var(--gz-text-2xl); font-weight: 800; margin-bottom: var(--gz-space-1); }
h2, .h2 { font-size: var(--gz-text-xl); }
h3, .h3 { font-size: var(--gz-text-lg); }
h4, .h4 { font-size: var(--gz-text-md); text-transform: none; }

/* Page subtitle - the muted line under an h1. No Bootstrap equivalent. */
.page-subtitle,
h1 + p:first-of-type {
  color: var(--gz-text-secondary);
  font-size: var(--gz-text-md);
  font-weight: 400;
}

/* Collection-meta / de-emphasised metadata line - smaller than
   Bootstrap's .small, which is as far as utilities go. */
.text-meta {
  font-size: var(--gz-text-xs);
  color: var(--gz-text-faint);
}

code, kbd, samp, pre, .font-monospace {
  font-family: var(--gz-font-mono);
  font-feature-settings: "tnum" 1;
}

/* ============================================================
   TABLES - Bootstrap's default cell padding (0.5rem) reads cramped
   for a data-dense list page and the header lands on a different
   visual scale than the body unless both are set together.
   ============================================================ */
.table thead th {
  font-size: var(--gz-text-xs);
  font-weight: 600;
  color: var(--gz-text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: var(--gz-space-3) var(--gz-space-4);
  vertical-align: middle;
  border-bottom-color: var(--gz-border);
  background: transparent;
}

.table tbody td {
  font-size: var(--gz-text-md);
  padding: var(--gz-space-3) var(--gz-space-4);
  vertical-align: middle;
  border-bottom-color: var(--gz-border);
}

.table > :not(:last-child) > :last-child > * {
  border-bottom-color: var(--gz-border);
}

/* ============================================================
   FORM FOCUS RING - compiled CSS hardcodes a literal border-color
   and rgba() shadow on these, no variable exposed.
   ============================================================ */
.form-control:focus,
.form-select:focus,
.form-check-input:focus {
  border-color: var(--gz-accent);
  box-shadow: 0 0 0 0.2rem var(--gz-focus-ring);
}

/* Crisp keyboard focus for everything else (links, custom controls).
   Bootstrap buttons keep their own box-shadow ring. */
a:focus-visible,
.btn-ghost:focus-visible,
.nav-link:focus-visible,
summary:focus-visible,
[tabindex]:focus-visible {
  outline: 2px solid var(--gz-accent);
  outline-offset: 2px;
  border-radius: var(--gz-radius-sm);
}

/* ============================================================
   MOTION - one shared rhythm. Interactive surfaces ease their
   colour/shadow changes; nothing animates layout.
   ============================================================ */
.btn,
.nav-link,
.card,
.form-control,
.form-select,
.badge,
.page-link,
.dropdown-item {
  transition:
    background-color var(--gz-dur) var(--gz-ease),
    border-color var(--gz-dur) var(--gz-ease),
    color var(--gz-dur) var(--gz-ease),
    box-shadow var(--gz-dur) var(--gz-ease);
}

@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;
  }
}

/* ============================================================
   CHROME - footer is present-but-quiet; the version tag is an
   identifier so it takes the mono face + tabular figures.
   ============================================================ */
footer.footer {
  font-size: var(--gz-text-xs);
  color: var(--gz-text-secondary);
  background: var(--gz-surface);
}

footer.footer a {
  color: var(--gz-text-secondary);
}

footer.footer a:hover {
  color: var(--gz-accent-hover);
}

.version-tag {
  font-family: var(--gz-font-mono);
  font-feature-settings: "tnum" 1;
  color: var(--gz-text-faint);
}
