/* ===== AdEx Design System — shared tokens, base reset, primitives =====
 *
 * Single source of truth for colors, spacing, type, motion, and a small set
 * of utility classes. Linked from every standalone page (and the explorer
 * via html_renderer.py) to stop the per-page drift that crept in across
 * Waves 1-A. Self-contained, no build step.
 *
 * Pages are still free to add their own component CSS inline; the goal of
 * this file is to make the FOUNDATION identical everywhere, not to dictate
 * every component shape.
 *
 * Theme-bootstrap (data-theme attribute) MUST be set inline in <head>
 * before this file loads to avoid FOUC. See _shared.js for the helper.
 */

/* --- Brand palette (theme-independent) --- */
:root {
  --navy: #0C2D57;
  --magenta: #C30F63;
  --cream: #F6F2EF;
  --magenta-light: #d94a8a;
  --magenta-dark: #9a0c4e;

  /* --- Radii --- */
  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 16px;

  /* --- Type scale (six steps) --- */
  --font-xs:   0.72rem;
  --font-sm:   0.85rem;
  --font-base: 1rem;
  --font-lg:   1.15rem;
  --font-xl:   1.4rem;
  --font-2xl:  1.7rem;

  /* --- Spacing scale (eight steps; 4-px rhythm) --- */
  --space-xs:  4px;
  --space-sm:  8px;
  --space-md:  12px;
  --space-lg:  16px;
  --space-xl:  24px;
  --space-2xl: 32px;
  --space-3xl: 48px;
  --space-4xl: 64px;

  /* --- Motion --- */
  --ease-spring:   cubic-bezier(0.16, 1, 0.3, 1);
  --ease-standard: cubic-bezier(0.25, 0.1, 0.25, 1);
  --dur-fast:   0.15s;
  --dur-normal: 0.25s;
  --dur-slow:   0.5s;

  /* --- Type families --- */
  --font-heading: 'Montserrat', 'Segoe UI', sans-serif;
  --font-body:    'Source Sans 3', 'Segoe UI', sans-serif;
}

/* --- Light theme (default) --- */
[data-theme="light"], :root {
  --bg: #fff;
  --surface: var(--cream);
  --card-bg: #fff;
  --input-bg: #fff;
  --text-primary-sem:   #1a1a2e;
  --text-secondary-sem: #4a4a62;
  --text-muted-sem:     #5c5c78;
  --border-sem: rgba(12, 45, 87, 0.12);
  --hover-bg:   rgba(12, 45, 87, 0.04);
  --shadow-sm: 0 1px 3px rgba(12, 45, 87, 0.08);
  --shadow-md: 0 4px 12px rgba(12, 45, 87, 0.10);
  --shadow-lg: 0 8px 24px rgba(12, 45, 87, 0.14);

  /* --- Semantic state colors (light) --- */
  --state-success-bg:   rgba(34, 197, 94, 0.12);
  --state-success-text: #16a34a;
  --state-warning-bg:   rgba(245, 158, 11, 0.12);
  --state-warning-text: #b45309;
  --state-error-bg:     rgba(239, 68, 68, 0.10);
  --state-error-text:   #b91c1c;
  --state-info-bg:      rgba(12, 45, 87, 0.06);
  --state-info-text:    var(--navy);
}

/* --- Dark theme --- */
[data-theme="dark"] {
  --bg: #060e1a;
  --surface: rgba(12, 45, 87, 0.6);
  --card-bg: rgba(12, 45, 87, 0.35);
  --input-bg: rgba(12, 45, 87, 0.4);
  --text-primary-sem:   #F6F2EF;
  --text-secondary-sem: rgba(246, 242, 239, 0.7);
  --text-muted-sem:     rgba(246, 242, 239, 0.45);
  --border-sem: rgba(246, 242, 239, 0.12);
  --hover-bg:   rgba(246, 242, 239, 0.05);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.25);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.45);

  --state-success-bg:   rgba(34, 197, 94, 0.18);
  --state-success-text: #4ade80;
  --state-warning-bg:   rgba(245, 158, 11, 0.18);
  --state-warning-text: #fbbf24;
  --state-error-bg:     rgba(239, 68, 68, 0.18);
  --state-error-text:   #fca5a5;
  --state-info-bg:      rgba(246, 242, 239, 0.06);
  --state-info-text:    var(--magenta-light);
}

/* --- Base reset (matches the inline copies that will be deleted) --- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-font-smoothing: antialiased; }
body {
  font-family: var(--font-body);
  color: var(--text-primary-sem);
  background: var(--bg);
  line-height: 1.55;
  min-height: 100vh;
}
h1, h2, h3, h4, h5, h6 { font-family: var(--font-heading); }

/* --- Focus ring utility (adopted by Wave 5 on every interactive) --- */
.adex-focus-ring:focus-visible,
*:focus-visible {
  outline: 2px solid var(--magenta);
  outline-offset: 2px;
}

/* --- Skip link primitive (Wave 5) — visually-hidden until focused --- */
.adex-skip-link {
  position: absolute;
  left: var(--space-md);
  top: var(--space-md);
  padding: var(--space-sm) var(--space-lg);
  background: var(--magenta);
  color: #fff;
  font-weight: 600;
  font-size: var(--font-sm);
  border-radius: var(--radius-sm);
  text-decoration: none;
  transform: translateY(-200%);
  transition: transform var(--dur-fast) var(--ease-spring);
  z-index: 9999;
}
.adex-skip-link:focus, .adex-skip-link:focus-visible {
  transform: translateY(0);
  outline: 2px solid #fff;
  outline-offset: 2px;
}
@media (prefers-reduced-motion: reduce) {
  .adex-skip-link { transition: none; }
}

/* --- Visually-hidden utility for screen-reader-only labels --- */
.adex-visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* --- Skeleton loading primitive (Wave 3 will swap "Loading..." text for this) --- */
.adex-skeleton {
  background: linear-gradient(90deg,
    var(--border-sem) 0%,
    var(--hover-bg) 50%,
    var(--border-sem) 100%);
  background-size: 200% 100%;
  border-radius: var(--radius-sm);
  animation: adex-skeleton-shimmer 1.5s ease-in-out infinite;
}
.adex-skeleton-line {
  height: 14px; margin-bottom: var(--space-sm);
}
@keyframes adex-skeleton-shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}
@media (prefers-reduced-motion: reduce) {
  .adex-skeleton { animation: none; }
}

/* --- Breadcrumb primitive (Wave 2) --- */
.adex-breadcrumb {
  max-width: 1100px;
  margin: 0 auto;
  padding: var(--space-md) var(--space-xl) 0;
  font-size: var(--font-xs);
  color: var(--text-muted-sem);
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  flex-wrap: wrap;
}
.adex-breadcrumb a {
  color: var(--text-secondary-sem);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: color var(--dur-fast) var(--ease-standard), border-color var(--dur-fast) var(--ease-standard);
}
.adex-breadcrumb a:hover {
  color: var(--magenta);
  border-bottom-color: var(--magenta);
}
.adex-breadcrumb [aria-current="page"] {
  color: var(--text-primary-sem);
  font-weight: 600;
}
.adex-breadcrumb-sep {
  color: var(--text-muted-sem);
  user-select: none;
}

/* --- Empty / error state primitives (Wave 3) ----------------------- */
.adex-empty, .adex-error {
  display: flex; flex-direction: column; align-items: center; gap: var(--space-md);
  padding: var(--space-3xl) var(--space-xl);
  text-align: center;
  border: 1px dashed var(--border-sem);
  border-radius: var(--radius);
  background: var(--card-bg);
  color: var(--text-secondary-sem);
}
.adex-empty-title, .adex-error-title {
  font-family: var(--font-heading);
  font-size: var(--font-lg);
  font-weight: 600;
  color: var(--text-primary-sem);
}
.adex-empty-hint, .adex-error-hint {
  font-size: var(--font-sm);
  color: var(--text-muted-sem);
  max-width: 480px;
}
.adex-error {
  border-color: var(--state-error-bg);
  background: var(--state-error-bg);
  color: var(--state-error-text);
}
.adex-error-title { color: var(--state-error-text); }
.adex-empty-cta, .adex-error-cta {
  display: inline-flex; align-items: center; gap: var(--space-xs);
  padding: var(--space-sm) var(--space-lg);
  font-size: var(--font-sm);
  font-weight: 600;
  border-radius: var(--radius-sm);
  border: 1px solid var(--magenta);
  background: var(--magenta);
  color: #fff;
  text-decoration: none;
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease-standard), transform var(--dur-fast) var(--ease-standard);
}
.adex-empty-cta:hover, .adex-error-cta:hover {
  background: var(--magenta-dark);
  transform: translateY(-1px);
}
.adex-empty-cta--ghost {
  background: transparent;
  color: var(--magenta);
}
.adex-empty-cta--ghost:hover {
  background: var(--state-info-bg);
  color: var(--magenta-dark);
}

/* --- Responsive breakpoints (Wave 3) -------------------------------- */
@media (max-width: 768px) {
  .adex-breadcrumb { padding-left: var(--space-md); padding-right: var(--space-md); }
  .adex-empty, .adex-error { padding: var(--space-xl) var(--space-md); }
}
@media (max-width: 480px) {
  .adex-empty-title, .adex-error-title { font-size: var(--font-base); }
}

/* --- Badge primitive (consolidates .tag, .opp-stage, .chip variants) --- */
.adex-badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 12px;
  font-size: var(--font-xs);
  font-weight: 600;
  background: var(--surface);
  color: var(--text-secondary-sem);
  white-space: nowrap;
}
.adex-badge--success { background: var(--state-success-bg); color: var(--state-success-text); }
.adex-badge--warning { background: var(--state-warning-bg); color: var(--state-warning-text); }
.adex-badge--danger  { background: var(--state-error-bg);   color: var(--state-error-text); }
.adex-badge--magenta { background: rgba(195, 15, 99, 0.10); color: var(--magenta); }
.adex-badge--info    { background: var(--state-info-bg);    color: var(--state-info-text); }

/* --- Wave 28: keyboard shortcuts help overlay --------------------- */
/* Universal "?" cheat sheet wired by AdExShared.mountShortcutsHelp.
 * Modal dialog with focus trap + Escape + backdrop close. Single
 * design treatment shared by every page so the overlay reads the
 * same on briefing/search/departments. */
.adex-kbd-help-overlay {
  position: fixed; inset: 0; z-index: 1000;
  background: rgba(12, 45, 87, 0.45);
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
  animation: adex-kbd-help-fade var(--dur-fast) var(--ease-standard);
}
[data-theme="dark"] .adex-kbd-help-overlay { background: rgba(0, 0, 0, 0.6); }
.adex-kbd-help-overlay[hidden] { display: none; }
@keyframes adex-kbd-help-fade {
  from { opacity: 0; }
  to   { opacity: 1; }
}
.adex-kbd-help-card {
  background: var(--card-bg);
  border: 1px solid var(--border-sem);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  width: 100%; max-width: 560px;
  max-height: 80vh; overflow: auto;
  font-family: 'Source Sans 3', sans-serif;
}
.adex-kbd-help-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border-sem);
  position: sticky; top: 0;
  background: var(--card-bg);
}
.adex-kbd-help-head h2 {
  margin: 0;
  font-family: 'Montserrat', sans-serif;
  font-size: var(--font-lg, 1.05rem);
  font-weight: 700;
  color: var(--text-primary-sem);
}
.adex-kbd-help-close {
  background: transparent; border: 1px solid var(--border-sem);
  border-radius: var(--radius-sm);
  width: 28px; height: 28px;
  font-size: 1.2rem; line-height: 1;
  cursor: pointer; color: var(--text-secondary-sem);
  display: flex; align-items: center; justify-content: center;
}
.adex-kbd-help-close:hover { border-color: var(--magenta); color: var(--magenta); }
.adex-kbd-help-close:focus-visible { outline: 2px solid var(--magenta); outline-offset: 2px; }
.adex-kbd-help-body { padding: 14px 18px 18px; }
.adex-kbd-help-section + .adex-kbd-help-section { margin-top: 14px; }
.adex-kbd-help-section h3 {
  margin: 0 0 8px;
  font-family: 'Montserrat', sans-serif;
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted-sem);
}
.adex-kbd-help-section dl {
  margin: 0;
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 8px 14px;
  align-items: center;
}
.adex-kbd-help-section dt {
  display: flex; gap: 4px; align-items: center;
  white-space: nowrap;
}
.adex-kbd-help-section dt kbd {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  background: var(--surface);
  border: 1px solid var(--border-sem);
  font-family: 'Source Code Pro', 'SF Mono', Consolas, monospace;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-primary-sem);
  line-height: 1.3;
}
.adex-kbd-help-sep {
  color: var(--text-muted-sem);
  font-size: 0.78rem;
  font-weight: 600;
}
.adex-kbd-help-section dd {
  margin: 0;
  color: var(--text-secondary-sem);
  font-size: 0.88rem;
}
@media (prefers-reduced-motion: reduce) {
  .adex-kbd-help-overlay { animation: none; }
}
@media print {
  .adex-kbd-help-overlay { display: none !important; }
}
@media (max-width: 480px) {
  .adex-kbd-help-card { max-width: 100%; max-height: 92vh; }
  .adex-kbd-help-section dl { grid-template-columns: 1fr; gap: 4px; }
  .adex-kbd-help-section dt { margin-top: 6px; }
}

/* --- Wave 33: visible help button (mounts in page header) --------- */
/* Small "?" pill that opens the keyboard shortcuts modal. Lives in
 * the page header next to the theme toggle so users discover the
 * "?" shortcut without needing to read documentation. Same magenta
 * focus ring as the rest of the app; keyboard-activatable as a
 * native <button>. */
.adex-help-button {
  background: none;
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: #fff;
  border-radius: 6px;
  padding: 4px 10px;
  cursor: pointer;
  font-size: 0.82rem;
  font-family: inherit;
  font-weight: 600;
  line-height: 1;
  transition: background var(--dur-fast) var(--ease-standard),
              border-color var(--dur-fast) var(--ease-standard);
}
.adex-help-button:hover {
  background: rgba(255, 255, 255, 0.06);
  border-color: rgba(255, 255, 255, 0.4);
}
.adex-help-button:focus-visible {
  outline: 2px solid var(--magenta-light, #f4c4d8);
  outline-offset: 2px;
}
@media print {
  .adex-help-button { display: none !important; }
}
