:root {
  --surface-1:    #fcfcfb;
  --page:         #f9f9f7;
  --text-primary: #0b0b0b;
  --text-secondary:#52514e;
  --text-muted:   #898781;
  --grid:         #e1e0d9;
  --baseline:     #c3c2b7;
  --border:       rgba(11,11,11,0.10);

  --series-1: #2a78d6; /* blue   - median line / primary series */
  --series-2: #1baf7a; /* aqua   */
  --series-6: #e34948; /* red    - risk / negative */
  --band-fill: rgba(42,120,214,0.14);

  --good: #0ca30c;
  --warning: #fab219;
  --critical: #d03b3b;

  --radius: 10px;
  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --surface-1:    #1a1a19;
    --page:         #0d0d0d;
    --text-primary: #ffffff;
    --text-secondary:#c3c2b7;
    --text-muted:   #898781;
    --grid:         #2c2c2a;
    --baseline:     #383835;
    --border:       rgba(255,255,255,0.10);

    --series-1: #3987e5;
    --series-2: #199e70;
    --series-6: #e66767;
    --band-fill: rgba(57,135,229,0.20);

    --good: #0ca30c;
    --warning: #fab219;
    --critical: #d03b3b;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--page);
  color: var(--text-primary);
  font-variant-numeric: proportional-nums;
}

.topbar {
  background: var(--surface-1);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px 24px 16px;
}
.topbar h1 { margin: 0 0 4px; font-size: 1.5rem; }
.subtitle { margin: 0; color: var(--text-secondary); font-size: 0.9rem; }

.layout {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px 24px 60px;
  display: grid;
  grid-template-columns: 380px 1fr;
  gap: 20px;
  align-items: start;
}
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
}

.panel {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
}
.panel h2 { margin: 0 0 12px; font-size: 1.05rem; }
.panel h3 { margin: 24px 0 10px; font-size: 0.95rem; color: var(--text-secondary); font-weight: 600; }

.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }

details { border-top: 1px solid var(--grid); padding: 10px 0; }
details:first-of-type { border-top: none; }
summary {
  cursor: pointer;
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--text-secondary);
  padding: 4px 0;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 12px;
  margin-top: 8px;
}
.field { display: flex; flex-direction: column; gap: 2px; }
.field label { font-size: 0.72rem; color: var(--text-muted); }
.field input {
  font-family: var(--font);
  font-size: 0.85rem;
  padding: 5px 7px;
  border: 1px solid var(--baseline);
  border-radius: 6px;
  background: var(--page);
  color: var(--text-primary);
  width: 100%;
}
.field input:focus { outline: 2px solid var(--series-1); outline-offset: 1px; }

.table-wrap { overflow-x: auto; margin-top: 8px; }
table { border-collapse: collapse; width: 100%; font-size: 0.8rem; }
.editable-table th, .editable-table td, .data-table th, .data-table td {
  padding: 5px 7px;
  border-bottom: 1px solid var(--grid);
  text-align: right;
  white-space: nowrap;
}
.editable-table th:first-child, .editable-table td:first-child,
.data-table th:first-child, .data-table td:first-child { text-align: left; }
th { color: var(--text-muted); font-weight: 600; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.02em; }
.editable-table input {
  width: 64px;
  font-family: var(--font);
  font-size: 0.8rem;
  padding: 3px 5px;
  border: 1px solid var(--baseline);
  border-radius: 5px;
  background: var(--page);
  color: var(--text-primary);
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.data-table td { font-variant-numeric: tabular-nums; }
.comps-cell { color: var(--text-muted); font-size: 0.75rem; white-space: normal; text-align: left; max-width: 220px; }

.presets { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  font-family: var(--font);
  font-size: 0.75rem;
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid var(--baseline);
  background: var(--page);
  color: var(--text-secondary);
  cursor: pointer;
}
.chip-active { background: var(--series-1); border-color: var(--series-1); color: #fff; }

.run-row { display: flex; align-items: center; gap: 10px; margin-top: 16px; flex-wrap: wrap; }
.btn-primary, .btn-secondary {
  font-family: var(--font);
  font-size: 0.85rem;
  font-weight: 600;
  padding: 9px 16px;
  border-radius: 8px;
  cursor: pointer;
  border: 1px solid transparent;
}
.btn-primary { background: var(--series-1); color: #fff; }
.btn-secondary { background: transparent; color: var(--text-secondary); border-color: var(--baseline); }
.run-status { font-size: 0.8rem; color: var(--text-muted); }

.kpi-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-bottom: 14px; }
.kpi-tile {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  background: var(--page);
}
.kpi-tile .kpi-label { font-size: 0.72rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.02em; }
.kpi-tile .kpi-value { font-size: 1.35rem; font-weight: 700; margin: 4px 0 2px; font-variant-numeric: tabular-nums; }
.kpi-tile .kpi-range { font-size: 0.72rem; color: var(--text-secondary); font-variant-numeric: tabular-nums; }

.callout {
  border: 1px solid var(--border);
  border-left: 3px solid var(--series-1);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 0.85rem;
  color: var(--text-secondary);
  background: var(--page);
  margin-bottom: 6px;
}
.callout strong { color: var(--text-primary); }
.callout.risk { border-left-color: var(--critical); }

.chart-card { border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; background: var(--page); }
.chart-toolbar { display: flex; justify-content: flex-end; margin-bottom: 4px; }
.chart-wrap { position: relative; width: 100%; height: 260px; }
.chart-wrap-bar { height: 340px; }
canvas { width: 100%; height: 100%; display: block; }

.tooltip {
  position: absolute;
  pointer-events: none;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 9px;
  font-size: 0.75rem;
  color: var(--text-primary);
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
  white-space: nowrap;
  transform: translate(-50%, -110%);
  z-index: 5;
}
.tooltip .t-week { color: var(--text-muted); margin-bottom: 2px; }
.tooltip .t-row { display: flex; gap: 8px; justify-content: space-between; }

.totals-line { font-size: 0.8rem; color: var(--text-secondary); margin: 8px 0 0; }

.foot { max-width: 1200px; margin: 0 auto; padding: 0 24px 40px; color: var(--text-muted); font-size: 0.78rem; }

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