:root {
  --bg: #0f172a;
  --bg-grad-1: #0f2a43;
  --bg-grad-2: #0a1326;
  --card: #ffffff;
  --ink: #0f172a;
  --ink-soft: #475569;
  --ink-faint: #94a3b8;
  --line: #e2e8f0;
  --accent: #0e9f6e;      /* green - nominal / gains */
  --accent-dark: #057a51;
  --real: #2563eb;        /* blue - real */
  --contrib: #cbd5e1;     /* grey - principal */
  --danger: #dc2626;
  --shadow: 0 1px 2px rgba(15,23,42,.06), 0 8px 24px rgba(15,23,42,.08);
  --radius: 16px;
  --maxw: 920px;
  font-synthesis: none;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: #f1f5f9;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.wrap {
  width: 100%;
  max-width: var(--maxw);
  margin-inline: auto;
  padding-inline: 20px;
}

/* ---------- Header ---------- */
.site-header {
  background:
    radial-gradient(1200px 400px at 20% -10%, rgba(14,159,110,.35), transparent 60%),
    linear-gradient(160deg, var(--bg-grad-1), var(--bg-grad-2));
  color: #fff;
  padding: 40px 0 32px;
}
.site-header h1 {
  margin: 0;
  font-size: clamp(1.5rem, 3.4vw, 2.1rem);
  letter-spacing: -0.02em;
  font-weight: 700;
}
.tagline {
  margin: 8px 0 0;
  color: #cbd5e1;
  font-size: clamp(.95rem, 2vw, 1.05rem);
  max-width: 46ch;
}

main.wrap { padding-bottom: 56px; }

/* ---------- Cards ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

/* ---------- Controls ---------- */
.controls {
  margin-top: -22px;
  position: relative;
  z-index: 2;
  padding: 20px;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 18px;
}
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field label {
  font-size: .78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--ink-soft);
}
input[type="text"], select {
  font: inherit;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 11px 12px;
  width: 100%;
  appearance: none;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
input[type="text"]:focus, select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(14,159,110,.18);
}
select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%2394a3b8' d='M1 1l5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
  cursor: pointer;
}
.input-prefix {
  display: flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  transition: border-color .15s, box-shadow .15s;
}
.input-prefix:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(14,159,110,.18);
}
.input-prefix span { padding-left: 12px; color: var(--ink-faint); font-weight: 600; }
.input-prefix input { border: none; box-shadow: none !important; padding-left: 6px; }

.toggle-field { justify-content: flex-start; }
.switch {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  user-select: none;
}
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.track {
  width: 42px; height: 24px;
  border-radius: 999px;
  background: var(--contrib);
  position: relative;
  transition: background .18s;
  flex: none;
}
.thumb {
  position: absolute; top: 3px; left: 3px;
  width: 18px; height: 18px;
  background: #fff; border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0,0,0,.25);
  transition: transform .18s;
}
.switch input:checked + .track { background: var(--real); }
.switch input:checked + .track .thumb { transform: translateX(18px); }
.switch input:focus-visible + .track { box-shadow: 0 0 0 3px rgba(37,99,235,.25); }
.switch-label { font-weight: 600; font-size: .92rem; }
.hint { margin: 6px 0 0; font-size: .8rem; color: var(--ink-faint); }

/* ---------- Headline ---------- */
.headline {
  margin: 24px 0 8px;
  font-size: clamp(1.15rem, 3.2vw, 1.6rem);
  line-height: 1.35;
  font-weight: 500;
  color: var(--ink);
}
.headline .big {
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--accent-dark);
}
.headline .big.neg { color: var(--danger); }
.headline .sub {
  display: block;
  margin-top: 8px;
  font-size: .95rem;
  color: var(--ink-soft);
  font-weight: 400;
}

/* ---------- Stat cards ---------- */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 14px;
  margin: 16px 0 28px;
}
.stat {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px 16px;
}
.stat .k {
  font-size: .74rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--ink-faint);
  font-weight: 600;
}
.stat .v {
  font-size: 1.3rem;
  font-weight: 750;
  letter-spacing: -0.01em;
  margin-top: 4px;
}
.stat .v.pos { color: var(--accent-dark); }
.stat .v.neg { color: var(--danger); }
.stat .x { font-size: .8rem; color: var(--ink-faint); margin-top: 2px; }

/* ---------- Chart ---------- */
.chart-card { padding: 18px 18px 14px; }
.chart-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; flex-wrap: wrap; margin-bottom: 8px;
}
.chart-head h2 { margin: 0; font-size: 1.05rem; }
.seg {
  display: inline-flex; border: 1px solid var(--line); border-radius: 9px; overflow: hidden;
}
.seg button {
  font: inherit; font-size: .82rem; font-weight: 600;
  border: none; background: #fff; color: var(--ink-soft);
  padding: 6px 14px; cursor: pointer;
}
.seg button + button { border-left: 1px solid var(--line); }
.seg button.active { background: var(--ink); color: #fff; }

.chart-wrap { position: relative; width: 100%; }
#chart { width: 100%; height: auto; display: block; touch-action: none; }
.chart-wrap .axis text { fill: var(--ink-faint); font-size: 11px; }
.chart-wrap .grid line { stroke: var(--line); stroke-width: 1; }
.chart-wrap .zero line { stroke: #cbd5e1; }

.tooltip {
  position: absolute;
  pointer-events: none;
  background: var(--ink);
  color: #fff;
  padding: 8px 10px;
  border-radius: 8px;
  font-size: .8rem;
  line-height: 1.45;
  white-space: nowrap;
  transform: translate(-50%, 0);
  box-shadow: 0 6px 20px rgba(0,0,0,.25);
  z-index: 5;
}
.tooltip b { font-size: .86rem; }
.tooltip .tt-row { display: flex; align-items: center; gap: 6px; }
.tooltip .dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }

.legend {
  display: flex; flex-wrap: wrap; gap: 16px;
  margin-top: 10px; padding-top: 10px;
  border-top: 1px solid var(--line);
  font-size: .82rem; color: var(--ink-soft);
}
.legend-item { display: inline-flex; align-items: center; gap: 7px; }
.swatch { width: 14px; height: 3px; border-radius: 2px; display: inline-block; }
.swatch.nominal { background: var(--accent); }
.swatch.real { background: var(--real); }
.swatch.contrib { background: var(--contrib); height: 0; border-top: 2px dashed var(--contrib); }

/* ---------- Table ---------- */
.table-card { margin-top: 22px; overflow: hidden; }
.table-toggle {
  width: 100%; text-align: left;
  display: flex; align-items: center; justify-content: space-between;
  font: inherit; font-weight: 600;
  background: #fff; border: none; padding: 16px 18px; cursor: pointer;
  color: var(--ink);
}
.table-toggle .chev { transition: transform .18s; color: var(--ink-faint); }
.table-toggle[aria-expanded="true"] .chev { transform: rotate(180deg); }
.table-scroll { max-height: 420px; overflow: auto; border-top: 1px solid var(--line); }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { padding: 9px 14px; text-align: right; font-size: .85rem; white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
thead th {
  position: sticky; top: 0; background: #f8fafc;
  color: var(--ink-soft); font-size: .75rem; text-transform: uppercase;
  letter-spacing: .03em; border-bottom: 1px solid var(--line);
}
tbody tr:nth-child(even) { background: #fafbfc; }
tbody td.pos { color: var(--accent-dark); }
tbody td.neg { color: var(--danger); }

/* ---------- Footer ---------- */
.site-footer { background: #fff; border-top: 1px solid var(--line); padding: 28px 0 40px; }
.notes { font-size: .82rem; color: var(--ink-soft); margin: 0 0 10px; }
.notes a { color: var(--accent-dark); }
.disclaimer { font-size: .78rem; color: var(--ink-faint); margin: 0; max-width: 70ch; }

/* ---------- Responsive ---------- */
@media (max-width: 720px) {
  .controls { grid-template-columns: 1fr 1fr; }
  .toggle-field { grid-column: 1 / -1; }
}
@media (max-width: 460px) {
  .controls { grid-template-columns: 1fr; }
  .site-header { padding: 32px 0 28px; }
}
