/* ==========================================================================
   AutoGenius Speed Layer & ETSv2 Field Report — Layout & Responsive Shell
   Mobile-first (375px–412px) to Wide Editorial Desktop (1280px–1440px+)
   ========================================================================== */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
  scroll-padding-top: calc(var(--header-height) + 24px);
  overflow-x: clip;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  background-color: var(--bg-canvas);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: 1.62;
  overflow-x: clip;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background-color var(--transition-fast), color var(--transition-fast);
}

body.is-drawer-open {
  overflow: hidden;
}

img,
svg,
canvas,
video {
  max-width: 100%;
}

a {
  color: var(--accent-cobalt-ink);
  text-decoration: none;
  transition: color var(--transition-fast);
}

a:hover {
  text-decoration: underline;
  text-underline-offset: 3px;
}

button,
input,
select {
  font: inherit;
  color: inherit;
}

:focus-visible {
  outline: 2px solid var(--border-focus);
  outline-offset: 2px;
}

/* Skip Link for Keyboard Accessibility */
.skip-link {
  position: fixed;
  top: -120px;
  left: 16px;
  z-index: 100;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  background: var(--accent-cobalt);
  color: #FFFFFF;
  font-size: var(--text-sm);
  font-weight: 600;
  box-shadow: var(--shadow-md);
  transition: top var(--transition-fast);
}

.skip-link:focus {
  top: 12px;
  text-decoration: none;
}

/* ==========================================================================
   Sticky Top Bar
   ========================================================================== */

.site-header {
  position: sticky;
  top: 0;
  z-index: var(--z-header);
  height: var(--header-height);
  background: var(--bg-header);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border-subtle);
}

.site-header-inner {
  height: 100%;
  max-width: var(--shell-max);
  margin: 0 auto;
  padding: 0 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

/* Mobile Chapters Trigger */
.toc-mobile-trigger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 36px;
  padding: 0 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  color: var(--text-primary);
  font-size: var(--text-xs);
  font-weight: 600;
  cursor: pointer;
  flex-shrink: 0;
  transition: background-color var(--transition-fast), border-color var(--transition-fast);
}

.toc-mobile-trigger:hover {
  background: var(--bg-surface-2);
  border-color: var(--border-strong);
}

.toc-mobile-trigger-label {
  display: none;
}

/* Brand Wordmark */
.brand-mark {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--text-primary);
  font-weight: 700;
  font-size: 0.9375rem;
  letter-spacing: -0.02em;
  white-space: nowrap;
  flex-shrink: 0;
}

.brand-mark:hover {
  text-decoration: none;
  color: var(--text-primary);
}

.brand-icon {
  width: 24px;
  height: 24px;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  border-radius: 6px;
  background: var(--bg-surface-2);
  border: 1px solid var(--border-strong);
  color: var(--accent-emerald);
}

.brand-wordmark {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  flex-shrink: 0;
}

.brand-divider {
  color: var(--text-tertiary);
  font-weight: 400;
}

.brand-sub {
  color: var(--text-secondary);
  font-weight: 500;
  font-size: 0.84375rem;
}

/* Scope Pill */
.scope-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 30px;
  padding: 0 11px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  color: var(--text-secondary);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.scope-pill-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent-emerald);
  box-shadow: 0 0 0 3px var(--accent-emerald-soft);
  flex-shrink: 0;
}

.scope-pill-full {
  display: none;
}

.scope-pill-short {
  display: inline;
}

/* Theme Toggle */
.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 36px;
  padding: 0 11px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  color: var(--text-primary);
  font-size: var(--text-xs);
  font-weight: 600;
  cursor: pointer;
  transition: background-color var(--transition-fast), border-color var(--transition-fast);
}

.theme-toggle:hover {
  background: var(--bg-surface-2);
  border-color: var(--border-strong);
}

.theme-toggle-text {
  display: none;
}

.theme-icon-sun {
  display: none;
}

[data-theme="light"] .theme-icon-moon {
  display: none;
}

[data-theme="light"] .theme-icon-sun {
  display: block;
}

/* Reading Progress Hairline */
.reading-progress {
  position: absolute;
  left: 0;
  right: 0;
  bottom: -1px;
  height: 2px;
  background: transparent;
  pointer-events: none;
}

.reading-progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent-cobalt), var(--accent-emerald));
  transition: width 80ms linear;
}

/* ==========================================================================
   Main Two-Column Editorial Shell
   ========================================================================== */

.report-shell {
  max-width: var(--shell-max);
  margin: 0 auto;
  padding: 20px 16px 72px;
  display: block;
}

.toc-rail {
  display: none;
}

.report-main {
  width: 100%;
  max-width: var(--reading-max);
  min-width: 0;
  margin: 0 auto;
}

/* ==========================================================================
   Table of Contents Links (Shared between Desktop Rail & Mobile Drawer)
   ========================================================================== */

.toc-eyebrow {
  margin: 0 0 12px;
  padding-left: 12px;
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-tertiary);
}

.toc-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  border-left: 1px solid var(--border-subtle);
}

.toc-link {
  display: flex;
  align-items: baseline;
  gap: 9px;
  padding: 7px 10px 7px 12px;
  margin-left: -1px;
  border-left: 2px solid transparent;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  color: var(--text-secondary);
  font-size: 0.8125rem;
  font-weight: 500;
  line-height: 1.35;
  text-decoration: none;
  transition: color var(--transition-fast), background-color var(--transition-fast), border-color var(--transition-fast);
}

.toc-link:hover {
  color: var(--text-primary);
  background: var(--bg-surface);
  text-decoration: none;
}

.toc-link.is-active {
  color: var(--text-primary);
  font-weight: 600;
  border-left-color: var(--accent-emerald);
  background: var(--accent-emerald-soft);
}

.toc-num {
  font-family: var(--font-mono);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  color: var(--text-tertiary);
  flex-shrink: 0;
}

.toc-link.is-active .toc-num {
  color: var(--accent-emerald);
}

.toc-meta-box {
  margin-top: 22px;
  padding: 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  font-size: 12px;
  color: var(--text-secondary);
}

.toc-meta-title {
  margin: 0 0 8px;
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-tertiary);
}

.toc-meta-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-family: var(--font-mono);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.toc-meta-list li {
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.toc-meta-list strong {
  color: var(--text-primary);
  font-weight: 600;
}

.toc-meta-cta {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin-top: 12px;
  font-size: 12px;
  font-weight: 600;
  color: var(--accent-cobalt);
}

/* ==========================================================================
   Mobile TOC Slide-Over Drawer
   ========================================================================== */

.toc-backdrop {
  position: fixed;
  inset: 0;
  z-index: var(--z-backdrop);
  background: rgba(5, 8, 14, 0.64);
  backdrop-filter: blur(4px);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-med);
}

.toc-backdrop.is-open {
  opacity: 1;
  pointer-events: auto;
}

.toc-drawer {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: var(--z-drawer);
  width: min(312px, 86vw);
  background: var(--bg-canvas);
  border-right: 1px solid var(--border-subtle);
  padding: 16px 16px 28px;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  transform: translateX(-100%);
  transition: transform var(--transition-med);
  box-shadow: var(--shadow-lg);
}

.toc-drawer.is-open {
  transform: translateX(0);
}

.toc-drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 14px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--border-subtle);
}

.toc-drawer-title {
  font-size: 0.875rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.toc-drawer-close {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  color: var(--text-primary);
  cursor: pointer;
}

.toc-drawer-close:hover {
  background: var(--bg-surface-2);
}

/* ==========================================================================
   Chapter Structure & Editorial Rhythm
   ========================================================================== */

.report-chapter {
  padding: 44px 0;
  border-top: 1px solid var(--border-subtle);
  min-width: 0;
}

.report-chapter:first-of-type {
  padding-top: 8px;
  border-top: none;
}

.chapter-header {
  margin-bottom: 24px;
}

.chapter-kicker {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 10px;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--accent-cobalt-ink);
}

.chapter-kicker::before {
  content: "";
  width: 14px;
  height: 2px;
  background: currentColor;
  border-radius: 1px;
}

.chapter-title {
  margin: 0 0 10px;
  font-size: clamp(1.5rem, 3.2vw, 2.125rem);
  font-weight: 750;
  line-height: 1.18;
  letter-spacing: -0.028em;
  color: var(--text-primary);
}

.chapter-lead {
  margin: 0;
  max-width: 74ch;
  font-size: var(--text-md);
  line-height: 1.62;
  color: var(--text-secondary);
}

.chapter-stack {
  display: flex;
  flex-direction: column;
  gap: 24px;
  min-width: 0;
}

.mount-slot {
  min-width: 0;
}

/* ==========================================================================
   Site Footer
   ========================================================================== */

.site-footer {
  border-top: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  margin-top: 24px;
}

.site-footer-inner {
  max-width: var(--shell-max);
  margin: 0 auto;
  padding: 28px 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  font-size: var(--text-xs);
  color: var(--text-secondary);
}

.footer-top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.footer-brand {
  font-weight: 700;
  color: var(--text-primary);
}

.footer-meta {
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--text-tertiary);
}

/* ==========================================================================
   Responsive Breakpoints
   ========================================================================== */

@media (max-width: 520px) {
  .site-header-inner {
    padding: 0 12px;
    gap: 8px;
  }

  .header-left,
  .header-right {
    gap: 7px;
  }

  .brand-divider,
  .brand-sub {
    display: none;
  }

  .toc-mobile-trigger,
  .theme-toggle {
    height: 34px;
    padding: 0 9px;
  }

  .scope-pill {
    height: 28px;
    padding: 0 8px;
    gap: 5px;
    font-size: 10.5px;
  }
}

@media (min-width: 640px) {
  .site-header-inner {
    padding: 0 22px;
  }

  .toc-mobile-trigger-label,
  .theme-toggle-text {
    display: inline;
  }

  .scope-pill-full {
    display: inline;
  }

  .scope-pill-short {
    display: none;
  }

  .report-shell {
    padding: 28px 24px 80px;
  }

  .report-chapter {
    padding: 56px 0;
  }

  .chapter-stack {
    gap: 28px;
  }

  .site-footer-inner {
    padding: 32px 24px;
  }
}

@media (min-width: 1120px) {
  .toc-mobile-trigger {
    display: none;
  }

  .report-shell {
    padding: 32px 28px 96px;
    display: grid;
    grid-template-columns: var(--toc-width) minmax(0, 1fr);
    gap: 40px;
    align-items: start;
  }

  .toc-rail {
    display: block;
    position: sticky;
    top: calc(var(--header-height) + 28px);
    max-height: calc(100vh - var(--header-height) - 48px);
    overflow-y: auto;
    padding-right: 6px;
    scrollbar-width: thin;
    scrollbar-color: var(--border-strong) transparent;
  }

  .report-main {
    margin: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ==========================================================================
   Print Stylesheet (Stripe Press Editorial PDF Output)
   ========================================================================== */

@media print {
  :root,
  [data-theme="dark"],
  [data-theme="light"] {
    --bg-canvas: #FFFFFF;
    --bg-surface: #FFFFFF;
    --bg-surface-2: #F8FAFC;
    --bg-surface-3: #F1F5F9;
    --border-subtle: #CBD5E1;
    --border-strong: #94A3B8;
    --text-primary: #0F172A;
    --text-secondary: #334155;
    --text-tertiary: #475569;
    --chart-grid: rgba(15, 23, 42, 0.14);
    --chart-label: #334155;
    --chart-label-strong: #0F172A;
    --shadow-sm: none;
    --shadow-md: none;
    --shadow-lg: none;
  }

  body {
    background: #FFFFFF !important;
    color: #0F172A !important;
    font-size: 11pt;
  }

  .site-header,
  .toc-rail,
  .toc-drawer,
  .toc-backdrop,
  .skip-link,
  .filter-bar,
  .chart-controls,
  .theme-toggle {
    display: none !important;
  }

  .report-shell {
    display: block !important;
    padding: 0 !important;
    max-width: 100% !important;
  }

  .report-main {
    max-width: 100% !important;
  }

  .report-chapter {
    padding: 20pt 0 !important;
    break-inside: auto;
  }

  .chart-card,
  .kpi-card,
  .card,
  .callout,
  .pillar-card,
  .roadmap-card {
    break-inside: avoid;
    page-break-inside: avoid;
    box-shadow: none !important;
  }

  .table-scroll {
    overflow: visible !important;
  }

  a {
    color: #0F172A !important;
    text-decoration: none !important;
  }
}
