:root {
  color-scheme: light;
  --bg: #f6f5f1;
  --surface: #fcfcfb;
  --border: #e2dfd6;
  --text-primary: #14213d;
  --text-secondary: #52514e;
  --text-muted: #7a786f;
  --accent: #c2410c;
  --series-1: #2a78d6;
  --grid: #ebe9e2;
  --good: #15803d;
  --bad: #b91c1c;
  --input-bg: #ffffff;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #121211;
    --surface: #1a1a19;
    --border: #33332f;
    --text-primary: #f4f2ea;
    --text-secondary: #c3c2b7;
    --text-muted: #8f8d84;
    --accent: #f08a4b;
    --series-1: #3987e5;
    --grid: #2a2a27;
    --good: #4ade80;
    --bad: #f87171;
    --input-bg: #232321;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121211;
  --surface: #1a1a19;
  --border: #33332f;
  --text-primary: #f4f2ea;
  --text-secondary: #c3c2b7;
  --text-muted: #8f8d84;
  --accent: #f08a4b;
  --series-1: #3987e5;
  --grid: #2a2a27;
  --good: #4ade80;
  --bad: #f87171;
  --input-bg: #232321;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text-primary);
  font: 15px/1.5 Inter, "Noto Sans Khmer", system-ui, sans-serif;
}
:lang(km) body, body:lang(km) { font-family: "Noto Sans Khmer", Inter, system-ui, sans-serif; }
header {
  display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between;
  max-width: 1200px; margin: 0 auto; padding: 24px 16px 8px;
}
h1 { font-size: 24px; margin: 0; }
.sub { color: var(--text-secondary); margin: 2px 0 0; font-size: 14px; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; }
button, select {
  font: inherit; font-size: 14px; color: var(--text-primary); background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; padding: 6px 12px; cursor: pointer;
}
button:hover, select:hover { border-color: var(--text-muted); }
button.primary { background: var(--text-primary); color: var(--bg); border-color: var(--text-primary); }
main {
  max-width: 1200px; margin: 0 auto; padding: 8px 16px 48px;
  display: grid; grid-template-columns: 340px 1fr; gap: 20px; align-items: start;
}
@media (max-width: 860px) { main { grid-template-columns: minmax(0, 1fr); } }
main > * { min-width: 0; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 16px; }
.inputs fieldset { border: 0; margin: 0 0 16px; padding: 0; }
.inputs legend { font-weight: 700; font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--accent); margin-bottom: 6px; }
.field { display: grid; grid-template-columns: 1fr 96px; gap: 8px; align-items: center; padding: 4px 0; }
.field label { font-size: 14px; color: var(--text-secondary); }
.num { position: relative; }
.num input {
  width: 100%; font: inherit; font-size: 14px; text-align: right; color: var(--text-primary);
  background: var(--input-bg); border: 1px solid var(--border); border-radius: 6px; padding: 5px 8px;
  font-variant-numeric: tabular-nums;
}
.num.dollar input { padding-left: 18px; }
.num.dollar::before { content: "$"; position: absolute; left: 8px; top: 6px; font-size: 14px; color: var(--text-muted); }
.num.pct input { padding-right: 22px; }
.num.pct::after { content: "%"; position: absolute; right: 8px; top: 6px; font-size: 14px; color: var(--text-muted); }
.presets-caption { font-size: 13px; color: var(--text-secondary); margin: 0 0 6px; }
.presets { display: grid; gap: 6px; margin-bottom: 16px; }
.presets button, .presets .custom {
  display: flex; justify-content: space-between; align-items: baseline; gap: 8px;
  width: 100%; text-align: left; font-size: 14px; padding: 8px 12px; border-radius: 8px;
}
.presets .total { font-size: 13px; color: var(--text-muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.presets button[aria-pressed="true"], .presets .custom { background: var(--text-primary); color: var(--bg); border: 1px solid var(--text-primary); font-weight: 600; }
.presets button[aria-pressed="true"] .total, .presets .custom .total { color: var(--bg); opacity: .8; }
.presets .custom { flex-direction: column; align-items: stretch; gap: 4px; }
.presets .custom .line { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.presets .tag { align-self: flex-start; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; padding: 1px 6px; border-radius: 999px; background: var(--bg); color: var(--text-primary); }
.results { display: grid; gap: 20px; min-width: 0; }
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
@media (max-width: 1050px) { .kpis { grid-template-columns: repeat(2, 1fr); } }
.kpi .label { font-size: 13px; color: var(--text-secondary); }
.kpi .value { font-size: 28px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.2; margin-top: 4px; }
.kpi .hint { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.kpi.hero .value { font-size: 34px; }
.good { color: var(--good); }
.bad { color: var(--bad); }
h2 { font-size: 16px; margin: 0 0 10px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; font-variant-numeric: tabular-nums; }
th, td { padding: 7px 8px; border-bottom: 1px solid var(--border); text-align: left; }
th { color: var(--text-secondary); font-weight: 600; font-size: 13px; }
td.r, th.r { text-align: right; }
tr.total td { font-weight: 700; border-bottom: 0; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
@media (max-width: 1050px) { .two { grid-template-columns: minmax(0, 1fr); } }
@media (max-width: 480px) { .kpis { grid-template-columns: minmax(0, 1fr); } }
.chart-wrap { position: relative; }
.chart-wrap svg { display: block; width: 100%; height: 280px; touch-action: none; }
.tooltip {
  position: absolute; pointer-events: none; background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 10px; font-size: 13px; box-shadow: 0 4px 16px rgba(0,0,0,.12);
  white-space: nowrap; display: none; font-variant-numeric: tabular-nums;
}
.tooltip strong { font-size: 15px; display: block; }
.tooltip span { color: var(--text-secondary); }
.chart-note { font-size: 13px; color: var(--text-muted); margin: 6px 0 0; }
details summary { cursor: pointer; font-size: 13px; color: var(--text-secondary); margin-top: 8px; }
.scen-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.scen-actions input { flex: 1; min-width: 140px; font: inherit; font-size: 14px; color: var(--text-primary); background: var(--input-bg); border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px; }
.link-btn { border: 0; background: none; padding: 2px 6px; color: var(--series-1); }
.empty { color: var(--text-muted); font-size: 14px; }
.scroll { overflow-x: auto; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text-primary); color: var(--bg); padding: 8px 16px; border-radius: 8px; font-size: 14px; display: none; }

/* navigation between pages */
.nav { display: flex; gap: 4px; max-width: 1200px; margin: 0 auto; padding: 16px 16px 0; }
.nav a { color: var(--text-secondary); text-decoration: none; font-size: 14px; padding: 6px 12px; border-radius: 8px; border: 1px solid transparent; }
.nav a:hover { border-color: var(--border); }
.nav a[aria-current="page"] { color: var(--text-primary); background: var(--surface); border-color: var(--border); font-weight: 600; }

/* ⓘ help next to a setting */
.label-wrap { position: relative; display: flex; align-items: center; gap: 6px; min-width: 0; }
.info {
  flex: none; width: 18px; height: 18px; padding: 0; border-radius: 50%;
  font: italic 700 11px/16px Georgia, serif; text-align: center;
  color: var(--text-muted); background: transparent; border: 1px solid var(--text-muted); cursor: help;
}
.info:hover, .info:focus-visible, .info.open { color: var(--bg); background: var(--text-primary); border-color: var(--text-primary); }
.info-tip {
  display: none; position: absolute; z-index: 20; left: 0; top: calc(100% + 6px);
  width: 280px; max-width: calc(100vw - 48px); padding: 10px 12px; border-radius: 8px;
  background: var(--text-primary); color: var(--bg); font-size: 13px; line-height: 1.45;
  box-shadow: 0 6px 20px rgba(0,0,0,.18);
}
.info:hover + .info-tip, .info:focus-visible + .info-tip, .info.open + .info-tip { display: block; }
.field-hint { margin: 0 0 6px; padding: 6px 10px; font-size: 13px; line-height: 1.4; color: var(--text-primary); background: var(--bg); border-left: 3px solid var(--accent); border-radius: 4px; }
