/* =========================================================
   LEAKFINDER — Lead-Funnel Audit
   Concept: clinical diagnostic tool for local service owners.
   Warm neutral surfaces (approachable, not cold SaaS-blue),
   amber/copper accent for "leak" urgency, teal for "healthy".
   ========================================================= */

/* ---------- Design tokens ---------- */
:root, [data-theme='light'] {
  /* Surfaces */
  --color-bg: #f6f4f0;
  --color-surface: #ffffff;
  --color-surface-2: #fbfaf7;
  --color-surface-offset: #eeebe4;
  --color-surface-offset-2: #e6e2d8;
  --color-divider: #ddd8cd;
  --color-border: #d3ccbe;

  /* Text */
  --color-text: #211c14;
  --color-text-muted: #6f6659;
  --color-text-faint: #a89e8d;
  --color-text-inverse: #fbf9f5;

  /* Primary accent — deep copper/amber (urgency, diagnostic) */
  --color-primary: #b5501f;
  --color-primary-hover: #953d13;
  --color-primary-active: #7a300f;
  --color-primary-highlight: #f1ddcf;

  /* Healthy / success — teal-green */
  --color-success: #2f6f5e;
  --color-success-hover: #24564a;
  --color-success-highlight: #d8e6e0;

  /* Warning — gold */
  --color-warning: #a97c14;
  --color-warning-highlight: #ecdfbd;

  /* Error / critical leak — deep red-copper */
  --color-error: #9c3b2e;
  --color-error-hover: #7d2f24;
  --color-error-highlight: #ecd6cf;

  /* Chart series (harmonized with accent) */
  --chart-1: #b5501f;
  --chart-2: #d98c3d;
  --chart-3: #2f6f5e;
  --chart-track: #e6e2d8;

  --radius-sm: 0.375rem;
  --radius-md: 0.625rem;
  --radius-lg: 1rem;
  --radius-xl: 1.5rem;
  --radius-full: 9999px;

  --shadow-sm: 0 1px 2px rgba(33, 28, 20, 0.06);
  --shadow-md: 0 6px 20px rgba(33, 28, 20, 0.08);
  --shadow-lg: 0 20px 48px rgba(33, 28, 20, 0.14);

  --transition-interactive: 180ms cubic-bezier(0.16, 1, 0.3, 1);

  --font-display: 'Cabinet Grotesk', 'Satoshi', system-ui, sans-serif;
  --font-body: 'Satoshi', 'Inter', system-ui, sans-serif;

  --content-max: 880px;
}

[data-theme='dark'] {
  --color-bg: #17140f;
  --color-surface: #1e1a13;
  --color-surface-2: #221e16;
  --color-surface-offset: #262117;
  --color-surface-offset-2: #2d271b;
  --color-divider: #332c1f;
  --color-border: #443a27;

  --color-text: #ede8de;
  --color-text-muted: #a89d8a;
  --color-text-faint: #6f6552;
  --color-text-inverse: #211c14;

  --color-primary: #e0813f;
  --color-primary-hover: #ec9a5e;
  --color-primary-active: #f0aa77;
  --color-primary-highlight: #3a2a1a;

  --color-success: #5da690;
  --color-success-hover: #7abfa9;
  --color-success-highlight: #223129;

  --color-warning: #d3ab5c;
  --color-warning-highlight: #3a301c;

  --color-error: #d97b68;
  --color-error-hover: #e5988a;
  --color-error-highlight: #3d241e;

  --chart-1: #e0813f;
  --chart-2: #d3ab5c;
  --chart-3: #5da690;
  --chart-track: #2d271b;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 6px 20px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 20px 48px rgba(0, 0, 0, 0.5);
}

/* ---------- Type scale ---------- */
:root {
  --text-xs: clamp(0.75rem, 0.7rem + 0.25vw, 0.875rem);
  --text-sm: clamp(0.875rem, 0.8rem + 0.35vw, 1rem);
  --text-base: clamp(1rem, 0.95rem + 0.25vw, 1.125rem);
  --text-lg: clamp(1.125rem, 1rem + 0.75vw, 1.5rem);
  --text-xl: clamp(1.5rem, 1.2rem + 1.25vw, 2.25rem);
  --text-2xl: clamp(2rem, 1.2rem + 2.5vw, 3.25rem);

  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.25rem;
  --space-6: 1.5rem;
  --space-8: 2rem;
  --space-10: 2.5rem;
  --space-12: 3rem;
  --space-16: 4rem;
  --space-20: 5rem;
  --space-24: 6rem;
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  -webkit-text-size-adjust: none;
  text-size-adjust: none;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  scroll-behavior: smooth;
}

body {
  min-height: 100dvh;
  line-height: 1.6;
  font-family: var(--font-body);
  font-size: var(--text-base);
  color: var(--color-text);
  background-color: var(--color-bg);
  background-image:
    radial-gradient(circle at 15% 0%, color-mix(in srgb, var(--color-primary) 6%, transparent), transparent 45%),
    radial-gradient(circle at 85% 20%, color-mix(in srgb, var(--color-success) 5%, transparent), transparent 40%);
}

h1, h2, h3, h4 { text-wrap: balance; line-height: 1.15; font-family: var(--font-display); }
p, li { text-wrap: pretty; }

input, button, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: none; }

::selection { background: color-mix(in srgb, var(--color-primary) 25%, transparent); }

:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 3px;
  border-radius: var(--radius-sm);
}

a { color: var(--color-primary); text-decoration: none; }
a:hover { text-decoration: underline; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

.noise-overlay { display: none; }

/* ---------- Header ---------- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: color-mix(in srgb, var(--color-bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--color-divider);
}
.header-inner {
  max-width: var(--content-max);
  margin: 0 auto;
  padding: var(--space-4) var(--space-6);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.brand { display: flex; align-items: center; gap: var(--space-2); }
.brand-logo { color: var(--color-primary); flex-shrink: 0; }
.brand-name {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: var(--text-lg);
  letter-spacing: -0.01em;
}
.brand-accent { color: var(--color-primary); }
.theme-toggle {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-text-muted);
  transition: background var(--transition-interactive), color var(--transition-interactive);
}
.theme-toggle:hover { background: var(--color-surface-offset); color: var(--color-text); }

/* ---------- Hero ---------- */
.hero { padding: var(--space-16) var(--space-6) var(--space-10); }
.hero-inner { max-width: var(--content-max); margin: 0 auto; text-align: center; }
.eyebrow {
  display: inline-block;
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--color-primary);
  background: var(--color-primary-highlight);
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-full);
  margin-bottom: var(--space-5);
}
.hero-title {
  font-size: var(--text-2xl);
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: var(--space-5);
}
.br-desktop { display: none; }
@media (min-width: 720px) { .br-desktop { display: inline; } }
.hero-sub {
  font-size: var(--text-base);
  color: var(--color-text-muted);
  max-width: 620px;
  margin: 0 auto;
}

/* ---------- Panels ---------- */
.panel { padding: 0 var(--space-6) var(--space-16); }
.panel-inner {
  max-width: var(--content-max);
  margin: 0 auto;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-xl);
  padding: var(--space-8) var(--space-8) var(--space-10);
  box-shadow: var(--shadow-md);
}
@media (max-width: 640px) {
  .panel-inner { padding: var(--space-6) var(--space-5) var(--space-8); }
}
.panel-head { margin-bottom: var(--space-8); }
.panel-title { font-size: var(--text-xl); font-weight: 700; margin-bottom: var(--space-2); }
.panel-desc { color: var(--color-text-muted); font-size: var(--text-sm); max-width: 60ch; }

/* ---------- Form ---------- */
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--space-6);
  margin-bottom: var(--space-6);
}
.form-grid-3 { grid-template-columns: repeat(3, 1fr); }
@media (max-width: 640px) {
  .form-grid, .form-grid-3 { grid-template-columns: 1fr; }
}
.field-wide { grid-column: 1 / -1; }

.field { display: flex; flex-direction: column; gap: var(--space-2); }
.field label {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-text);
}
.optional-tag {
  font-size: var(--text-xs);
  font-weight: 500;
  color: var(--color-text-faint);
  text-transform: none;
}
.input-wrap {
  position: relative;
  display: flex;
  align-items: center;
  background: var(--color-surface-2);
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-md);
  transition: border-color var(--transition-interactive), box-shadow var(--transition-interactive);
}
.input-wrap:has(input:focus) {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-highlight);
}
.input-wrap input {
  width: 100%;
  background: transparent;
  border: none;
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-base);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--color-text);
}
.input-wrap input:focus { outline: none; }
.input-prefix, .input-suffix {
  padding: 0 var(--space-3);
  color: var(--color-text-muted);
  font-weight: 600;
  flex-shrink: 0;
}
.input-prefix { padding-right: 0; }
.input-suffix { padding-left: 0; }
.field-hint { font-size: var(--text-xs); color: var(--color-text-muted); }
.field-hint a { color: var(--color-text-muted); text-decoration: underline; }

/* ---------- Disclosure ---------- */
.disclosure-toggle {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-text-muted);
  padding: var(--space-2) 0;
  margin-bottom: var(--space-4);
  transition: color var(--transition-interactive);
}
.disclosure-toggle:hover { color: var(--color-primary); }
.disclosure-toggle .chevron { transition: transform var(--transition-interactive); flex-shrink: 0; }
.disclosure-toggle[aria-expanded="true"] .chevron { transform: rotate(90deg); }

.targets-drawer {
  background: var(--color-surface-offset);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  margin-bottom: var(--space-6);
  overflow: hidden;
}
.targets-note {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  margin-bottom: var(--space-5);
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  font-size: var(--text-sm);
  font-weight: 700;
  padding: var(--space-4) var(--space-6);
  border-radius: var(--radius-md);
  transition: background var(--transition-interactive), transform var(--transition-interactive), box-shadow var(--transition-interactive);
}
.btn-primary {
  background: var(--color-primary);
  color: var(--color-text-inverse);
  box-shadow: var(--shadow-sm);
}
.btn-primary:hover { background: var(--color-primary-hover); box-shadow: var(--shadow-md); }
.btn-primary:active { transform: scale(0.98); }
.btn-run { width: 100%; padding: var(--space-5); font-size: var(--text-base); }
.btn-run svg { transition: transform var(--transition-interactive); }
.btn-run:hover svg { transform: translateX(3px); }

/* ---------- Funnel chart ---------- */
.funnel-chart-wrap {
  background: var(--color-surface-2);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  margin-bottom: var(--space-8);
  border: 1px solid var(--color-divider);
}

/* ---------- Stage cards ---------- */
.stage-cards {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-4);
  margin-bottom: var(--space-8);
}
@media (max-width: 720px) { .stage-cards { grid-template-columns: 1fr; } }

.stage-card {
  background: var(--color-surface-2);
  border: 1.5px solid var(--color-divider);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  position: relative;
  overflow: hidden;
}
.stage-card.is-bottleneck {
  border-color: var(--color-error);
  background: color-mix(in srgb, var(--color-error-highlight) 55%, var(--color-surface-2));
}
.stage-card-label {
  font-size: var(--text-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-text-muted);
}
.stage-card.is-bottleneck .stage-card-label { color: var(--color-error); }
.stage-card-rate {
  font-size: var(--text-xl);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  display: flex;
  align-items: baseline;
  gap: var(--space-2);
}
.stage-card-target {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  font-weight: 500;
}
.stage-bar-track {
  height: 8px;
  border-radius: var(--radius-full);
  background: var(--color-divider);
  overflow: hidden;
  position: relative;
}
.stage-bar-fill {
  height: 100%;
  border-radius: var(--radius-full);
  background: var(--color-success);
  transition: width 700ms cubic-bezier(0.16,1,0.3,1);
}
.stage-bar-target-tick {
  position: absolute;
  top: -3px;
  bottom: -3px;
  width: 2px;
  background: var(--color-text);
  opacity: 0.35;
}
.stage-card.is-bottleneck .stage-bar-fill { background: var(--color-error); }
.stage-card-dropoff {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
  font-variant-numeric: tabular-nums;
}
.stage-card-status {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--color-success);
}
.stage-card.is-bottleneck .stage-card-status { color: var(--color-error); }

/* ---------- Leak callout ---------- */
.leak-callout {
  border-radius: var(--radius-lg);
  padding: var(--space-6) var(--space-6) var(--space-6) var(--space-6);
  border: 1.5px solid var(--color-error);
  background: color-mix(in srgb, var(--color-error-highlight) 45%, var(--color-surface));
  display: flex;
  gap: var(--space-4);
  align-items: flex-start;
}
.leak-callout.is-healthy {
  border-color: var(--color-success);
  background: color-mix(in srgb, var(--color-success-highlight) 45%, var(--color-surface));
}
.leak-icon {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-full);
  background: var(--color-error);
  color: var(--color-text-inverse);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.leak-callout.is-healthy .leak-icon { background: var(--color-success); }
.leak-body h3 { font-size: var(--text-lg); margin-bottom: var(--space-2); }
.leak-body p { color: var(--color-text-muted); font-size: var(--text-sm); margin-bottom: var(--space-1); }
.leak-body .leak-figure {
  font-family: var(--font-display);
  font-size: var(--text-xl);
  font-weight: 700;
  color: var(--color-error);
  font-variant-numeric: tabular-nums;
  margin: var(--space-2) 0;
}
.leak-callout.is-healthy .leak-figure { color: var(--color-success); }

/* ---------- Roadmap ---------- */
.roadmap-timeline {
  display: flex;
  flex-direction: column;
  gap: var(--space-6);
  margin-bottom: var(--space-8);
}
.roadmap-item {
  display: grid;
  grid-template-columns: 96px 1fr;
  gap: var(--space-5);
  padding: var(--space-6);
  border-radius: var(--radius-lg);
  background: var(--color-surface-2);
  border: 1.5px solid var(--color-divider);
  position: relative;
}
.roadmap-item.priority-1 { border-color: var(--color-primary); background: color-mix(in srgb, var(--color-primary-highlight) 40%, var(--color-surface-2)); }
@media (max-width: 560px) {
  .roadmap-item { grid-template-columns: 1fr; }
}
.roadmap-phase {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}
.roadmap-phase-num {
  font-family: var(--font-display);
  font-size: var(--text-xl);
  font-weight: 700;
  color: var(--color-primary);
}
.roadmap-phase-label {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.roadmap-badge {
  display: inline-flex;
  align-self: flex-start;
  margin-top: var(--space-2);
  font-size: var(--text-xs);
  font-weight: 700;
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-full);
  background: var(--color-primary);
  color: var(--color-text-inverse);
}
.roadmap-content h3 { font-size: var(--text-lg); margin-bottom: var(--space-2); }
.roadmap-content p { color: var(--color-text-muted); font-size: var(--text-sm); margin-bottom: var(--space-3); }
.roadmap-tags { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.roadmap-tag {
  font-size: var(--text-xs);
  font-weight: 600;
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-full);
  background: var(--color-surface-offset);
  color: var(--color-text-muted);
  border: 1px solid var(--color-divider);
}

.method-note {
  border-top: 1px solid var(--color-divider);
  padding-top: var(--space-6);
}
.method-note h3 { font-size: var(--text-base); margin-bottom: var(--space-3); }
.method-note p { color: var(--color-text-muted); font-size: var(--text-sm); margin-bottom: var(--space-3); }
.method-sources { font-size: var(--text-xs); }

/* ---------- Footer ---------- */
.site-footer {
  padding: var(--space-8) var(--space-6) var(--space-16);
  text-align: center;
}
.site-footer p { color: var(--color-text-muted); font-size: var(--text-xs); max-width: 50ch; margin: 0 auto; }

/* ---------- Utility: fade-in for results ---------- */
.panel[hidden] { display: none; }
.fade-in {
  animation: fadeInUp 500ms cubic-bezier(0.16,1,0.3,1);
}
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}
