/* ============================================================
   D.R.I.V.E. — Global design system
   Shared by every page: design tokens, dark-mode theme, reset,
   base typography, universal UI widgets and keyframes.
   Page-specific layout lives in each page's own stylesheet.
   ============================================================ */

/* ---------- Design tokens ---------- */
:root {
  /* Surfaces */
  --bg:          #f8fafc;
  --bg-2:        #f1f5f9;
  --bg-3:        #e8edf5;
  --sidebar:     #ffffff;
  --white:       #ffffff;

  /* Brand */
  --blue:        #2563eb;
  --blue-lt:     #3b82f6;
  --blue-dim:    rgba(37, 99, 235, .07);
  --blue-mid:    rgba(37, 99, 235, .14);
  --blue-bd:     rgba(37, 99, 235, .18);

  /* Semantic — risk / status */
  --rose:        #ef4444;
  --rose-bg:     #fef2f2;
  --rose-bd:     #fecaca;
  --amber:       #f59e0b;
  --amber-bg:    #fffbeb;
  --amber-bd:    #fde68a;
  --emerald:     #10b981;
  --emerald-bg:  #ecfdf5;
  --emerald-bd:  #a7f3d0;

  /* Text */
  --text:        #0f172a;
  --body:        #334155;
  --muted:       #64748b;
  --dim:         #94a3b8;

  /* Lines & elevation */
  --border:      #e2e8f0;
  --border-hi:   #cbd5e1;
  --shadow-sm:   0 1px 3px rgba(15, 23, 42, .06), 0 1px 2px rgba(15, 23, 42, .04);
  --shadow:      0 4px 16px rgba(15, 23, 42, .08), 0 1px 4px rgba(15, 23, 42, .04);
  --shadow-lg:   0 12px 40px rgba(15, 23, 42, .1), 0 4px 12px rgba(15, 23, 42, .06);

  /* Type families */
  --serif: 'Fraunces', Georgia, serif;
  --mono:  'JetBrains Mono', monospace;
  --sans:  'DM Sans', sans-serif;
}

/* ---------- Dark mode ---------- */
[data-theme="dark"] {
  --bg:          #0f172a;
  --bg-2:        #1e293b;
  --bg-3:        #334155;
  --sidebar:     #111827;
  --white:       #1e293b;

  --text:        #f1f5f9;
  --body:        #cbd5e1;
  --muted:       #94a3b8;
  --dim:         #64748b;

  --border:      #334155;
  --border-hi:   #475569;
  --shadow-sm:   0 1px 3px rgba(0, 0, 0, .4);
  --shadow:      0 4px 16px rgba(0, 0, 0, .5);
  --shadow-lg:   0 12px 40px rgba(0, 0, 0, .5);

  --blue-dim:    rgba(37, 99, 235, .15);
  --blue-mid:    rgba(37, 99, 235, .25);
  --blue-bd:     rgba(37, 99, 235, .3);
  --rose-bg:     rgba(239, 68, 68, .12);
  --rose-bd:     rgba(239, 68, 68, .3);
  --amber-bg:    rgba(245, 158, 11, .12);
  --amber-bd:    rgba(245, 158, 11, .3);
  --emerald-bg:  rgba(16, 185, 129, .12);
  --emerald-bd:  rgba(16, 185, 129, .3);
}

/* ---------- Reset & base ---------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
}

/* ---------- Universal widgets ---------- */

/* Dark-mode toggle (sidebar / top-nav pages) */
.dark-toggle {
  background: none;
  border: 1px solid var(--border-hi);
  border-radius: 6px;
  padding: 6px 10px;
  cursor: pointer;
  font-size: 14px;
  color: var(--muted);
  transition: all .15s;
}
.dark-toggle:hover { border-color: var(--blue); color: var(--blue); }

/* Compact dark-mode toggle (focused reading pages) */
.dark-toggle-sm {
  background: none;
  border: 1px solid var(--border-hi);
  border-radius: 6px;
  padding: 5px 9px;
  cursor: pointer;
  font-size: 13px;
  color: var(--muted);
  transition: all .15s;
}
.dark-toggle-sm:hover { border-color: var(--blue); color: var(--blue); }

/* Mobile sidebar trigger — hidden until small screens activate it */
.hamburger {
  display: none;
  background: none;
  border: 1px solid var(--border-hi);
  border-radius: 6px;
  padding: 6px 8px;
  cursor: pointer;
  color: var(--muted);
  font-size: 16px;
  margin-right: 4px;
}

/* Scrim behind the open mobile sidebar */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .4);
  z-index: 49;
}

/* ---------- Keyframes ---------- */
@keyframes blink   { 0%, 100% { opacity: 1; } 50% { opacity: .3; } }
@keyframes fadeSlide { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes up      { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
@keyframes fadein  { from { opacity: 0; } to { opacity: 1; } }

/* ---------- Interaction feedback ---------- */
/* Keyboard focus is always visible; mouse clicks don't get the ring. */
:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; border-radius: 4px; }
input:focus-visible, select:focus-visible, textarea:focus-visible { outline-offset: 0; }

/* Respond on press, not release. */
button:not(:disabled):active,
[class*="btn"]:active,
.tab:active,
.nav-item:active {
  transform: scale(.97);
  transition: transform 100ms ease-out;
}
button, a, [onclick] { -webkit-tap-highlight-color: transparent; }

/* Ease light/dark switches instead of a hard brightness jump. */
body { transition: background-color .25s ease, color .25s ease; }

/* SVG glyph inside the theme toggles */
.dark-toggle svg, .dark-toggle-sm svg { display: block; width: 16px; height: 16px; }
.dark-toggle-sm svg { width: 14px; height: 14px; }

/* Sync status: a static dot — the data is a snapshot, not a live stream. */
.sync-pill .sync-dot { animation: none !important; }

/* ---------- Accessibility preferences ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-delay: 0s !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
    transition-delay: 0s !important;
    scroll-behavior: auto !important;
  }
  .reveal { opacity: 1 !important; transform: none !important; }
}
@media (prefers-reduced-transparency: reduce) {
  nav, .topnav, .cx-nav { backdrop-filter: none !important; background: var(--white) !important; }
}
@media (prefers-contrast: more) {
  :root { --muted: #475569; --dim: #64748b; --border: #94a3b8; }
  [data-theme="dark"] { --muted: #cbd5e1; --dim: #94a3b8; --border: #64748b; }
}

/* Grid children default to min-width:auto, so wide content pushed the main column past the screen on phones. */
.app > .main { min-width: 0; }

/* Sign-out control in the sidebar user block */
.signout-btn { margin-left: auto; background: none; border: 1px solid transparent; border-radius: 6px; padding: 5px; color: var(--muted); cursor: pointer; display: flex; }
.signout-btn:hover { border-color: var(--border-hi); color: var(--text); }
.signout-btn svg { width: 15px; height: 15px; }
.sidebar-user .user-name, .sidebar-user .user-role { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* `hidden` always wins over a component's own display rule */
[hidden] { display: none !important; }
