:root {
  --bg: oklch(96.5% 0.006 245);
  --surface: oklch(99% 0.004 245);
  --surface-muted: oklch(94.5% 0.008 245);
  --ink: oklch(20% 0.025 245);
  --muted: oklch(45% 0.028 245);
  --subtle: oklch(60% 0.025 245);
  --line: oklch(86% 0.012 245);
  --line-strong: oklch(76% 0.018 245);
  --accent: oklch(43% 0.085 172);
  --accent-strong: oklch(31% 0.078 172);
  --accent-soft: oklch(92% 0.045 172);
  --warning: oklch(45% 0.12 48);
  --warning-soft: oklch(94% 0.035 62);
  --free: oklch(72% 0.085 225);
  --flat: oklch(70% 0.11 11);
  --percentage: oklch(74% 0.105 70);
  --minimum: oklch(79% 0.09 105);
  --shadow: 0 18px 46px oklch(30% 0.03 245 / 0.1);
  --radius: 8px;
  --radius-sm: 6px;
}

* {
  box-sizing: border-box;
}

html {
  color-scheme: light;
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100vh;
  font-family:
    -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  color: var(--ink);
  background:
    linear-gradient(180deg, oklch(98% 0.005 245) 0%, var(--bg) 34rem),
    var(--bg);
}

button,
input {
  font: inherit;
}

button {
  color: inherit;
}

.page-shell {
  width: min(1240px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 24px 0 48px;
}

.app-header {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  padding: 18px 0 22px;
  border-bottom: 1px solid var(--line);
}

.eyebrow,
.section-kicker {
  margin: 0 0 8px;
  color: var(--accent-strong);
  font-size: 0.72rem;
  font-weight: 750;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 8px;
  font-size: 2rem;
  line-height: 1.12;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 0;
  font-size: 1.08rem;
  line-height: 1.24;
  letter-spacing: 0;
}

.lede {
  max-width: 64ch;
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.55;
}

.header-note {
  display: grid;
  gap: 2px;
  min-width: 210px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 1px 0 oklch(100% 0 0 / 0.75) inset;
}

.header-note span,
.meta-row {
  color: var(--subtle);
  font-size: 0.78rem;
  font-weight: 650;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.header-note strong {
  font-size: 0.92rem;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(300px, 390px) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
  padding-top: 18px;
}

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

.form-panel {
  position: sticky;
  top: 18px;
  padding: 18px;
}

.results-panel,
.structure-panel,
.prose-panel {
  padding: 18px;
}

.structure-panel,
.content-stack {
  margin-top: 18px;
}

.panel-heading {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.ghost-button {
  min-height: 36px;
  padding: 0 12px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--accent-strong);
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
}

.ghost-button:hover {
  background: var(--accent-soft);
  border-color: oklch(72% 0.045 172);
}

.ghost-button:focus-visible,
.info-trigger:focus-visible,
input:focus-visible,
summary:focus-visible,
a:focus-visible {
  outline: 2px solid oklch(64% 0.11 172 / 0.55);
  outline-offset: 2px;
}

.field-grid {
  display: grid;
  gap: 14px;
}

.field {
  display: grid;
  gap: 7px;
}

.field-label {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--ink);
  font-size: 0.88rem;
  font-weight: 680;
  line-height: 1.25;
}

.input-wrap {
  position: relative;
  display: block;
}

.currency-mark {
  position: absolute;
  left: 12px;
  top: 50%;
  color: var(--subtle);
  font-weight: 700;
  transform: translateY(-50%);
  pointer-events: none;
}

.field input[type="number"] {
  width: 100%;
  height: 42px;
  padding: 0 12px 0 28px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: oklch(98% 0.004 245);
  color: var(--ink);
  font-weight: 650;
}

.field input[type="number"]:hover {
  border-color: var(--subtle);
}

.info-tooltip {
  position: relative;
  display: inline-flex;
}

.info-trigger {
  display: inline-grid;
  width: 18px;
  height: 18px;
  place-items: center;
  border: 1px solid oklch(74% 0.04 172);
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: 0.7rem;
  font-weight: 800;
  line-height: 1;
  cursor: help;
}

.tooltip-bubble {
  position: absolute;
  left: 50%;
  top: calc(100% + 9px);
  z-index: 20;
  width: min(300px, calc(100vw - 48px));
  padding: 10px 11px;
  border: 1px solid oklch(31% 0.03 245);
  border-radius: var(--radius-sm);
  background: oklch(22% 0.025 245);
  color: oklch(96% 0.006 245);
  box-shadow: 0 16px 32px oklch(20% 0.025 245 / 0.22);
  font-size: 0.82rem;
  font-weight: 500;
  line-height: 1.45;
  opacity: 0;
  visibility: hidden;
  transform: translateX(-50%) translateY(-3px);
  transition:
    opacity 160ms ease,
    transform 160ms ease,
    visibility 160ms ease;
}

.info-tooltip:hover .tooltip-bubble,
.info-tooltip:focus-within .tooltip-bubble {
  opacity: 1;
  visibility: visible;
  transform: translateX(-50%) translateY(0);
}

.toggle-group {
  display: grid;
  gap: 10px;
  margin: 16px 0 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-muted);
}

.toggle-group legend {
  padding: 0 6px;
  color: var(--subtle);
  font-size: 0.76rem;
  font-weight: 750;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.toggle {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr);
  gap: 10px;
  align-items: start;
}

.toggle input {
  width: 16px;
  height: 16px;
  margin: 2px 0 0;
  accent-color: var(--accent);
}

.toggle-copy {
  min-width: 0;
}

.form-error {
  margin: 14px 0 0;
  padding: 11px 12px;
  border: 1px solid oklch(78% 0.07 48);
  border-radius: var(--radius-sm);
  background: var(--warning-soft);
  color: var(--warning);
  font-size: 0.9rem;
  font-weight: 650;
  line-height: 1.45;
}

.results-heading {
  align-items: center;
}

.summary-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 34px;
  padding: 0 11px;
  border: 1px solid oklch(80% 0.035 172);
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: 0.86rem;
  font-weight: 750;
  white-space: nowrap;
}

.results-summary {
  margin: -6px 0 14px;
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.5;
}

.results-list {
  display: grid;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}

.result-card {
  display: grid;
  gap: 12px;
  padding: 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.result-card:last-child {
  border-bottom: 0;
}

.result-card:first-child {
  background: linear-gradient(90deg, var(--accent-soft), var(--surface) 38%);
}

.result-top {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 14px;
  align-items: start;
}

.provider-name {
  font-size: 1rem;
  font-weight: 780;
  line-height: 1.25;
}

.plan-name {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.35;
}

.price {
  min-width: 142px;
  text-align: right;
}

.price strong {
  display: block;
  margin-top: 2px;
  font-size: 1.35rem;
  line-height: 1;
  letter-spacing: 0;
}

.fee-breakdown {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.fee-pill {
  display: grid;
  gap: 4px;
  min-height: 52px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: oklch(97.6% 0.006 245);
}

.fee-pill span {
  color: var(--subtle);
  font-size: 0.7rem;
  font-weight: 750;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.fee-pill strong {
  font-size: 0.94rem;
}

.warning-list,
.note-list {
  display: grid;
  gap: 4px;
  margin: 0;
  padding-left: 18px;
}

.warning-list {
  color: var(--warning);
}

.warning-list li,
.result-note {
  line-height: 1.45;
}

.result-note,
.source-row {
  color: var(--muted);
  font-size: 0.88rem;
}

.source-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  padding-top: 2px;
  line-height: 1.35;
}

.source-row a {
  color: var(--accent-strong);
  font-weight: 750;
  text-decoration-color: oklch(69% 0.05 172);
  text-underline-offset: 3px;
}

.structure-heading {
  align-items: end;
}

.structure-note {
  max-width: 42ch;
  margin-bottom: 0;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.45;
}

.structure-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 9px 16px;
  margin-bottom: 16px;
  color: var(--muted);
  font-size: 0.86rem;
}

.structure-legend span {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.legend-swatch {
  display: inline-block;
  width: 28px;
  height: 8px;
  border-radius: 999px;
}

.legend-free {
  background: var(--free);
}

.legend-flat {
  background: var(--flat);
}

.legend-percentage {
  background: var(--percentage);
}

.legend-minimum {
  background: var(--minimum);
}

.structure-chart {
  display: grid;
  gap: 9px;
}

.structure-row {
  display: grid;
  grid-template-columns: minmax(150px, 220px) minmax(0, 1fr) 88px;
  gap: 12px;
  align-items: center;
}

.structure-label,
.structure-total {
  color: var(--muted);
  font-size: 0.9rem;
}

.structure-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.structure-track {
  position: relative;
  height: 22px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background:
    repeating-linear-gradient(
      90deg,
      transparent 0,
      transparent calc(20% - 1px),
      oklch(86% 0.012 245) calc(20% - 1px),
      oklch(86% 0.012 245) 20%
    ),
    oklch(96.8% 0.006 245);
  overflow: hidden;
}

.structure-bar {
  display: flex;
  height: 100%;
  overflow: hidden;
  border-radius: 999px;
}

.structure-segment {
  height: 100%;
  min-width: 0;
}

.structure-segment-free {
  background: var(--free);
}

.structure-segment-flat {
  background: var(--flat);
}

.structure-segment-percentage {
  background: var(--percentage);
}

.structure-segment-minimum {
  background: var(--minimum);
}

.structure-zero {
  position: absolute;
  left: 8px;
  top: 50%;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: oklch(70% 0.018 245);
  transform: translateY(-50%);
}

.structure-total {
  text-align: right;
  white-space: nowrap;
}

.content-stack {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 18px;
}

.prose-panel p,
.prose-panel details p {
  max-width: 72ch;
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.6;
}

.prose-panel p:last-child {
  margin-bottom: 0;
}

.freshness-note {
  margin-top: 16px;
  padding: 10px 12px;
  border: 1px solid oklch(82% 0.036 172);
  border-radius: var(--radius-sm);
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-weight: 650;
}

.prose-panel details {
  padding: 12px 0;
  border-top: 1px solid var(--line);
}

.prose-panel details:first-of-type {
  margin-top: 12px;
}

.prose-panel summary {
  cursor: pointer;
  font-weight: 720;
  line-height: 1.35;
}

.prose-panel details p {
  margin: 10px 0 0;
}

.empty-state {
  padding: 22px;
  color: var(--muted);
  background: var(--surface-muted);
  text-align: center;
}

@media (max-width: 920px) {
  .page-shell {
    width: min(100vw - 24px, 760px);
    padding-top: 16px;
  }

  .app-header,
  .workspace,
  .content-stack {
    grid-template-columns: 1fr;
  }

  .app-header {
    display: grid;
    align-items: start;
  }

  .header-note {
    min-width: 0;
  }

  .form-panel {
    position: static;
  }

  .structure-heading,
  .panel-heading {
    align-items: start;
  }

  .structure-row {
    grid-template-columns: 1fr;
    gap: 6px;
  }

  .structure-total {
    text-align: left;
  }
}

@media (max-width: 620px) {
  .page-shell {
    width: min(100vw - 16px, 760px);
    padding-bottom: 28px;
  }

  h1 {
    font-size: 1.65rem;
  }

  .results-panel,
  .structure-panel,
  .prose-panel,
  .form-panel {
    padding: 14px;
  }

  .panel-heading,
  .result-top {
    grid-template-columns: 1fr;
  }

  .panel-heading {
    display: grid;
  }

  .price {
    min-width: 0;
    text-align: left;
  }

  .fee-breakdown {
    grid-template-columns: 1fr;
  }

  .tooltip-bubble {
    left: auto;
    right: 0;
    transform: translateY(-3px);
  }

  .info-tooltip:hover .tooltip-bubble,
  .info-tooltip:focus-within .tooltip-bubble {
    transform: translateY(0);
  }
}
