/* ---------- Theme tokens ---------- */
:root {
  --bg: #0d0d0d;
  --surface: #1a1a19;
  --surface-2: #222220;
  --border: rgba(255, 255, 255, 0.10);
  --text: #ffffff;
  --text-2: #c3c2b7;
  --muted: #898781;
  --grid: #2c2c2a;
  --axis: #383835;
  --accent: #3987e5;
  --accent-ink: #ffffff;
  --field-bg: #111110;

  /* chart series (dark) */
  --series-contrib: #3987e5; /* blue  */
  --series-growth:  #199e70; /* aqua  */
  --series-real:    #9085e9; /* violet line */
  --shadow: 0 1px 3px rgba(0,0,0,0.5), 0 8px 24px rgba(0,0,0,0.35);
}
:root[data-theme="light"] {
  --bg: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f1f0ec;
  --border: rgba(11, 11, 11, 0.10);
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --field-bg: #ffffff;

  --series-contrib: #2a78d6;
  --series-growth:  #1baf7a;
  --series-real:    #4a3aa7;
  --shadow: 0 1px 2px rgba(11,11,11,0.06), 0 8px 24px rgba(11,11,11,0.08);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; overflow-x: hidden; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  transition: background .2s ease, color .2s ease;
}
.wrap { max-width: 1100px; margin: 0 auto; padding: 24px 20px 64px; }

header.app {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; margin-bottom: 24px;
}
header.app h1 { font-size: 1.5rem; margin: 0; letter-spacing: -0.02em; }
header.app .sub { color: var(--muted); font-size: .85rem; margin-top: 2px; }

.theme-toggle {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: 999px;
  padding: 8px 14px; cursor: pointer; font-size: .85rem; font-weight: 600;
  box-shadow: var(--shadow);
}
.theme-toggle:hover { border-color: var(--accent); }
.theme-toggle .icon { font-size: 1rem; line-height: 1; }

.layout { display: grid; grid-template-columns: 340px 1fr; gap: 24px; align-items: start; }
@media (max-width: 860px) { .layout { grid-template-columns: 1fr; } }

.sidebar { position: sticky; top: 24px; }
@media (max-width: 860px) { .sidebar { position: static; } }

.tables-row { margin-top: 24px; }

.faq { margin-top: 24px; }

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; padding: 20px; box-shadow: var(--shadow);
}
.card + .card { margin-top: 24px; }
.card h2 { font-size: 1rem; margin: 0 0 14px; letter-spacing: -0.01em; }
.card h2.section { display:flex; align-items:center; justify-content:space-between; gap: 12px; }
.section-actions { display: inline-flex; align-items: center; gap: 8px; }

.field { margin-bottom: 14px; }
.field label { display: block; font-size: .8rem; color: var(--text-2); margin-bottom: 5px; font-weight: 600; }
.field .hint { color: var(--muted); font-weight: 400; }
.control { position: relative; display: flex; }
.control .prefix, .control .suffix {
  position: absolute; top: 0; bottom: 0; display: flex; align-items: center;
  color: var(--muted); font-size: .85rem; pointer-events: none;
}
.control .prefix { left: 11px; }
.control .suffix { right: 11px; }
input, select {
  width: 100%; background: var(--field-bg); color: var(--text);
  border: 1px solid var(--border); border-radius: 9px;
  padding: 9px 11px; font-size: .9rem; font-family: inherit;
  appearance: none; transition: border-color .15s ease;
}
input.has-prefix { padding-left: 24px; }
input.has-suffix { padding-right: 26px; }
input:focus, select:focus { outline: none; border-color: var(--accent); }
select {
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%),
                    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: right 14px center, right 9px center;
  background-size: 5px 5px, 5px 5px; background-repeat: no-repeat;
  padding-right: 28px; cursor: pointer;
}
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

details.advanced { margin-top: 6px; border-top: 1px solid var(--border); padding-top: 14px; }
details.advanced > summary {
  cursor: pointer; font-weight: 700; font-size: .85rem; list-style: none;
  display: flex; align-items: center; gap: 8px; color: var(--text);
}
details.advanced > summary::-webkit-details-marker { display: none; }
details.advanced > summary .chev { transition: transform .2s ease; color: var(--muted); }
details.advanced[open] > summary .chev { transform: rotate(90deg); }
details.advanced .body { margin-top: 14px; }

.note { font-size: .78rem; border-radius: 8px; padding: 8px 10px; margin-top: 8px; }
.note.info  { background: rgba(57,135,229,.12); color: var(--text-2); border: 1px solid rgba(57,135,229,.3); }
.note.warn  { background: rgba(250,178,25,.12);  color: var(--text-2); border: 1px solid rgba(250,178,25,.35); }
.note.solved { background: rgba(25,158,112,.14); color: var(--text-2); border: 1px solid rgba(25,158,112,.4); }
.solve-active { border-color: var(--series-real) !important; box-shadow: 0 0 0 2px rgba(144,133,233,.25); }

/* ---------- Results ---------- */
.tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
@media (max-width: 720px) { .tiles { grid-template-columns: repeat(2, 1fr); } }
.tile {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 12px; padding: 14px 16px;
}
.tile .k { font-size: .74rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; font-weight: 700; }
.tile .v { font-size: 1.45rem; font-weight: 700; margin-top: 4px; letter-spacing: -0.02em; }
.tile.accent .v { color: var(--series-growth); }
.tile .swatch { display:inline-block; width:9px; height:9px; border-radius:2px; margin-right:6px; vertical-align: middle; }

.legend { display: flex; flex-wrap: wrap; gap: 16px; margin: 4px 0 12px; font-size: .82rem; color: var(--text-2); }
.legend .item { display: flex; align-items: center; gap: 7px; }
.legend .key { width: 13px; height: 13px; border-radius: 3px; }
.legend .key.line { height: 0; border-top: 3px solid var(--series-real); border-radius: 0; width: 15px; }

.chart-fs {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 999px;
  padding: 5px 12px; cursor: pointer; font-size: .78rem; font-weight: 600;
  font-family: inherit;
}
.chart-fs:hover { border-color: var(--accent); }
.chart-fs .fs-exit { display: none; }

/* view toggle: show "Table" when chart is visible, "Chart" when table is visible */
#viewToggleBtn .view-table { display: none; }
#viewToggleBtn[aria-pressed="true"] .view-chart { display: none; }
#viewToggleBtn[aria-pressed="true"] .view-table { display: inline; }

.chart-wrap { position: relative; width: 100%; }
.chart-hint { margin-top: 8px; font-size: .72rem; color: var(--muted); text-align: center; }
/* Fullscreen chart */
#chartCard:fullscreen {
  background: var(--bg);
  display: flex; flex-direction: column; justify-content: center;
  border-radius: 0; padding: 24px;
}
#chartCard:fullscreen .chart-wrap { flex: 1; min-height: 0; }
#chartCard:fullscreen svg.chart { height: 100%; width: 100%; }
#chartCard:fullscreen .chart-fs .fs-enter { display: none; }
#chartCard:fullscreen .chart-fs .fs-exit { display: inline; }
svg.chart { width: 100%; height: auto; display: block; }
.chart text { fill: var(--muted); font-size: 11px; font-family: inherit; }
.chart .axis-line { stroke: var(--axis); stroke-width: 1; }
.chart .grid-line { stroke: var(--grid); stroke-width: 1; }

.tooltip {
  position: absolute; pointer-events: none; z-index: 5;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 9px; padding: 9px 11px; font-size: .78rem; color: var(--text);
  box-shadow: var(--shadow); min-width: 210px; opacity: 0; transition: opacity .1s ease;
  transform: translate(-50%, -110%);
}
.tooltip .yr { font-weight: 700; margin-bottom: 5px; }
.tooltip .tr { display: flex; justify-content: space-between; gap: 14px; }
.tooltip .tr .lab { color: var(--text-2); display:flex; align-items:center; gap:6px; white-space: nowrap; }
.tooltip .tr .lab .d { width:8px; height:8px; border-radius:2px; }
.tooltip .tr .val { font-variant-numeric: tabular-nums; font-weight: 600; }

.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .85rem; min-width: 380px; }
th, td { text-align: right; padding: 8px 12px; border-bottom: 1px solid var(--border); font-variant-numeric: tabular-nums; color: var(--text); }
th:first-child, td:first-child { text-align: left; }
thead th { color: var(--muted); font-weight: 700; font-size: .74rem; text-transform: uppercase; letter-spacing: .03em; }
tbody tr:hover { background: var(--surface-2); }
tr.current td { background: rgba(57,135,229,.10); font-weight: 700; }
td .badge { font-size: .68rem; color: var(--muted); font-weight: 600; }
