/* ============================================================
   Align ROI Calculator — design tokens
   Palette matches the live ALT Engine app: warm neutral background,
   deep teal primary, warm terracotta accent. Calm, credible, practical.
   ============================================================ */

:root,
[data-theme="light"] {
  color-scheme: light;

  --background: #f7f5f1;
  --surface: #ffffff;
  --surface-raised: #ffffff;
  --foreground: #1b1b18;
  --muted-foreground: #5c5a53;
  --border: #e2ded5;
  --border-strong: #cfc9bb;

  --primary: #01696f;
  --primary-hover: #014f54;
  --primary-foreground: #ffffff;
  --primary-surface: #e5f0ef;

  --ring: #01696f;
  --danger: #a4271b;
  --danger-surface: #fbeae8;
  --warning: #8a6d1a;
  --warning-surface: #faf3d9;
  --success: #0a6b4b;
  --success-surface: #e7f2ec;

  --accent: #b8742f;
  --accent-surface: #f6ead9;

  --shadow-sm: 0 1px 2px rgba(27, 27, 24, 0.06);
  --shadow-md: 0 4px 16px rgba(27, 27, 24, 0.08);
}

[data-theme="dark"] {
  color-scheme: dark;

  --background: #16181a;
  --surface: #1e2124;
  --surface-raised: #24272b;
  --foreground: #f2f0ea;
  --muted-foreground: #a5a29a;
  --border: #34383c;
  --border-strong: #454a4f;

  --primary: #2fb8ae;
  --primary-hover: #4bcabf;
  --primary-foreground: #0c1414;
  --primary-surface: #1c3230;

  --ring: #2fb8ae;
  --danger: #e2857a;
  --danger-surface: #3a2320;
  --warning: #d8b45a;
  --warning-surface: #3a3320;
  --success: #6fcfa8;
  --success-surface: #1c3228;

  --accent: #e0a565;
  --accent-surface: #3a2c18;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.4);
}

:root {
  --text-xs: clamp(0.75rem, 0.72rem + 0.1vw, 0.8125rem);
  --text-sm: clamp(0.875rem, 0.83rem + 0.15vw, 0.9375rem);
  --text-base: clamp(1rem, 0.95rem + 0.2vw, 1.0625rem);
  --text-lg: clamp(1.125rem, 1.05rem + 0.4vw, 1.375rem);
  --text-xl: clamp(1.375rem, 1.2rem + 0.9vw, 1.875rem);
  --text-2xl: clamp(1.75rem, 1.4rem + 1.5vw, 2.5rem);

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

  --radius-sm: 0.375rem;
  --radius-md: 0.625rem;
  --radius-lg: 0.875rem;

  --font-sans: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, "SF Mono", monospace;

  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
}

/* ---------- base ---------- */

body {
  background-color: var(--background);
  color: var(--foreground);
  font-family: var(--font-sans);
  font-size: var(--text-base);
  transition: background-color 0.2s var(--ease-out), color 0.2s var(--ease-out);
}

.container {
  max-width: 78rem;
  margin: 0 auto;
  padding-inline: var(--space-6);
}

@media (max-width: 640px) {
  .container { padding-inline: var(--space-4); }
}

/* ---------- header ---------- */

.site-header {
  border-bottom: 1px solid var(--border);
  padding-block: var(--space-5);
  position: sticky;
  top: 0;
  background: color-mix(in srgb, var(--background) 92%, transparent);
  backdrop-filter: blur(8px);
  z-index: 40;
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
}

.brand {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.brand-mark {
  width: 2.25rem;
  height: 2.25rem;
  color: var(--primary);
  flex-shrink: 0;
}

.brand-text .brand-name {
  font-size: var(--text-base);
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1.1;
}

.brand-text .brand-sub {
  font-size: var(--text-xs);
  color: var(--muted-foreground);
  letter-spacing: 0.02em;
}

.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--foreground);
  transition: border-color 0.15s var(--ease-out), background 0.15s var(--ease-out);
}

.theme-toggle:hover { border-color: var(--border-strong); }
.theme-toggle svg { width: 1.1rem; height: 1.1rem; }
.theme-toggle .icon-moon { display: none; }
[data-theme="dark"] .theme-toggle .icon-sun { display: none; }
[data-theme="dark"] .theme-toggle .icon-moon { display: block; }

/* ---------- hero / intro ---------- */

.hero {
  padding-block: var(--space-10) var(--space-8);
}

.hero-eyebrow {
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--primary);
  margin-bottom: var(--space-3);
}

.hero h1 {
  font-size: var(--text-2xl);
  font-weight: 700;
  letter-spacing: -0.015em;
  line-height: 1.1;
  max-width: 42rem;
}

.hero p {
  margin-top: var(--space-4);
  font-size: var(--text-base);
  color: var(--muted-foreground);
  max-width: 46rem;
  line-height: 1.6;
}

/* ---------- layout ---------- */

.calculator-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: var(--space-8);
  padding-block: var(--space-4) var(--space-16);
  align-items: start;
}

@media (max-width: 900px) {
  .calculator-grid { grid-template-columns: 1fr; }
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

.results-col {
  position: sticky;
  top: 5.5rem;
  display: flex;
  flex-direction: column;
  gap: var(--space-6);
}

@media (max-width: 900px) {
  .results-col { position: static; }
}

/* ---------- form groups ---------- */

.input-panel { padding: var(--space-6); }

.group {
  padding-block: var(--space-5);
  border-bottom: 1px solid var(--border);
}

.group:first-of-type { padding-top: 0; }
.group:last-of-type { border-bottom: none; padding-bottom: 0; }

.group-title {
  font-size: var(--text-sm);
  font-weight: 700;
  letter-spacing: -0.005em;
  margin-bottom: var(--space-1);
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.group-title .dot {
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 999px;
  background: var(--primary);
  flex-shrink: 0;
}

.group-note {
  font-size: var(--text-xs);
  color: var(--muted-foreground);
  margin-bottom: var(--space-4);
  line-height: 1.5;
}

.field {
  margin-top: var(--space-4);
}

.field-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-2);
}

.field-label {
  font-size: var(--text-sm);
  font-weight: 500;
}

.field-value {
  font-size: var(--text-sm);
  font-weight: 700;
  font-family: var(--font-mono);
  color: var(--primary);
  white-space: nowrap;
}

input[type="range"] {
  width: 100%;
  appearance: none;
  height: 0.375rem;
  border-radius: 999px;
  background: var(--border);
  outline: none;
}

input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  width: 1.1rem;
  height: 1.1rem;
  border-radius: 999px;
  background: var(--primary);
  border: 2px solid var(--surface);
  box-shadow: 0 0 0 1px var(--primary);
  cursor: pointer;
  transition: transform 0.1s var(--ease-out);
}

input[type="range"]::-webkit-slider-thumb:hover { transform: scale(1.12); }

input[type="range"]::-moz-range-thumb {
  width: 1.1rem;
  height: 1.1rem;
  border-radius: 999px;
  background: var(--primary);
  border: 2px solid var(--surface);
  box-shadow: 0 0 0 1px var(--primary);
  cursor: pointer;
}

.field-scale {
  display: flex;
  justify-content: space-between;
  font-size: var(--text-xs);
  color: var(--muted-foreground);
  margin-top: var(--space-1);
}

.field-note {
  font-size: var(--text-xs);
  color: var(--muted-foreground);
  margin-top: var(--space-2);
}

.field-note.negative {
  color: var(--danger);
  font-weight: 600;
}

.number-input-row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.number-input-row input[type="number"] {
  width: 100%;
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--background);
  color: var(--foreground);
  font-size: var(--text-sm);
  font-family: var(--font-mono);
}

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}

.switch {
  position: relative;
  width: 2.75rem;
  height: 1.5rem;
  border-radius: 999px;
  background: var(--border-strong);
  flex-shrink: 0;
  transition: background 0.15s var(--ease-out);
}

.switch::after {
  content: "";
  position: absolute;
  top: 0.1875rem;
  left: 0.1875rem;
  width: 1.125rem;
  height: 1.125rem;
  border-radius: 999px;
  background: var(--surface);
  transition: transform 0.15s var(--ease-out);
  box-shadow: var(--shadow-sm);
}

.switch.on { background: var(--primary); }
.switch.on::after { transform: translateX(1.25rem); }

.reset-row {
  padding-top: var(--space-5);
  display: flex;
  justify-content: flex-end;
}

.btn-reset {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--muted-foreground);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: var(--space-2) var(--space-3);
  background: var(--surface);
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
}

.btn-reset:hover { color: var(--foreground); border-color: var(--border-strong); }
.btn-reset svg { width: 0.9rem; height: 0.9rem; }

/* ---------- results ---------- */

.results-panel { padding: var(--space-6); }

.results-heading {
  font-size: var(--text-lg);
  font-weight: 700;
  letter-spacing: -0.01em;
  margin-bottom: var(--space-1);
}

.results-sub {
  font-size: var(--text-xs);
  color: var(--muted-foreground);
  margin-bottom: var(--space-5);
}

.kpi-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-3);
  margin-bottom: var(--space-6);
}

.kpi {
  background: var(--background);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-4);
}

.kpi-label {
  font-size: var(--text-xs);
  color: var(--muted-foreground);
  font-weight: 600;
  letter-spacing: 0.01em;
}

.kpi-value {
  font-size: var(--text-lg);
  font-weight: 700;
  font-family: var(--font-mono);
  margin-top: var(--space-1);
  letter-spacing: -0.01em;
}

.kpi-value.positive { color: var(--success); }
.kpi-value.negative { color: var(--danger); }
.kpi-unit {
  font-size: var(--text-xs);
  font-weight: 500;
  color: var(--muted-foreground);
  margin-left: var(--space-1);
}

.kpi-detail {
  font-size: var(--text-xs);
  color: var(--muted-foreground);
  margin-top: var(--space-2);
  line-height: 1.4;
}

.chart-wrap {
  height: 220px;
  margin-bottom: var(--space-6);
}

.breakdown-title {
  font-size: var(--text-sm);
  font-weight: 700;
  margin-bottom: var(--space-3);
}

.breakdown-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.breakdown-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  font-size: var(--text-xs);
}

.breakdown-row .swatch {
  width: 0.625rem;
  height: 0.625rem;
  border-radius: 999px;
  flex-shrink: 0;
}

.breakdown-row .breakdown-label {
  flex: 1;
  color: var(--muted-foreground);
}

.breakdown-row .breakdown-value {
  font-family: var(--font-mono);
  font-weight: 600;
}

/* ---------- arc cost table (3-year summary) ---------- */

.arc-cost-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-xs);
  margin-top: var(--space-5);
}

.arc-cost-table th, .arc-cost-table td {
  text-align: left;
  padding: var(--space-2) var(--space-3);
  border-bottom: 1px solid var(--border);
}

.arc-cost-table th {
  color: var(--muted-foreground);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  font-size: 0.6875rem;
}

.arc-cost-table td.num, .arc-cost-table th.num { text-align: right; font-family: var(--font-mono); }
.arc-cost-table tr:last-child td { border-bottom: none; }
.arc-cost-table tr.total-row td { font-weight: 700; border-top: 1px solid var(--border-strong); }

/* ---------- table panel ---------- */

.table-panel { padding: var(--space-6); }

.table-panel table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-xs);
}

.table-panel th, .table-panel td {
  text-align: left;
  padding: var(--space-2) var(--space-3);
  border-bottom: 1px solid var(--border);
}

.table-panel th {
  color: var(--muted-foreground);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  font-size: 0.6875rem;
}

.table-panel td.num, .table-panel th.num { text-align: right; font-family: var(--font-mono); }
.table-panel tr:last-child td { border-bottom: none; }
.table-panel tr.total-row td { font-weight: 700; border-top: 1px solid var(--border-strong); }

/* ---------- assumptions / sources ---------- */

.assumptions {
  margin-top: var(--space-8);
  padding: var(--space-6);
}

.assumptions summary {
  cursor: pointer;
  font-size: var(--text-sm);
  font-weight: 700;
  list-style: none;
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.assumptions summary::-webkit-details-marker { display: none; }

.assumptions summary .chev {
  width: 0.9rem;
  height: 0.9rem;
  transition: transform 0.15s var(--ease-out);
  color: var(--muted-foreground);
}

.assumptions[open] summary .chev { transform: rotate(90deg); }

.assumptions-body {
  margin-top: var(--space-4);
  font-size: var(--text-sm);
  color: var(--muted-foreground);
  line-height: 1.65;
}

.assumptions-body h4 {
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--foreground);
  font-weight: 700;
  margin-top: var(--space-5);
  margin-bottom: var(--space-2);
}

.assumptions-body h4:first-child { margin-top: 0; }

.assumptions-body ul { padding-left: var(--space-5); margin: 0; }
.assumptions-body li { margin-bottom: var(--space-1); }
.assumptions-body a { color: var(--primary); text-decoration: underline; text-underline-offset: 2px; }

.honesty-note {
  margin-top: var(--space-6);
  padding: var(--space-4) var(--space-5);
  background: var(--accent-surface);
  border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  color: var(--foreground);
  line-height: 1.55;
}

.honesty-note strong { color: var(--accent); }

/* ---------- footer ---------- */

.site-footer {
  border-top: 1px solid var(--border);
  padding-block: var(--space-6);
  font-size: var(--text-xs);
  color: var(--muted-foreground);
  text-align: center;
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
