:root {
  color-scheme: light;
  --bg:             #f4f6f7;
  --surface-1:      #ffffff;
  --surface-2:      #eef1f3;
  --text-primary:   #10151c;
  --text-secondary: #4b525d;
  --text-muted:     #838a95;
  --border:         rgba(16,21,28,0.09);
  --border-strong:  rgba(16,21,28,0.16);
  --accent:         #2a78d6;
  --accent-soft:    #e6f0fc;
  --good:           #0ca30c;
  --critical:       #d03b3b;
  --warning:        #b3760a;
  --grid-line:      #e1e0d9;
  --shadow: 0 1px 2px rgba(16,21,28,0.04), 0 8px 24px -12px rgba(16,21,28,0.12);

  /* category identity colors (fixed order, categorical) */
  --cat-growth:   #2a78d6; /* blue */
  --cat-prices:   #eb6834; /* orange */
  --cat-external: #1baf7a; /* aqua */
  --cat-property: #e87ba4; /* magenta */
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg:             #0d1013;
    --surface-1:      #171b20;
    --surface-2:      #1e2329;
    --text-primary:   #f2f4f6;
    --text-secondary: #aeb4bd;
    --text-muted:     #767d87;
    --border:         rgba(255,255,255,0.08);
    --border-strong:  rgba(255,255,255,0.16);
    --accent:         #3987e5;
    --accent-soft:    #16273f;
    --good:           #2fbf4f;
    --critical:       #e66767;
    --warning:        #d99a2b;
    --grid-line:      #2a2f36;
    --shadow: 0 1px 2px rgba(0,0,0,0.3), 0 8px 24px -12px rgba(0,0,0,0.5);

    --cat-growth:   #3987e5;
    --cat-prices:   #d95926;
    --cat-external: #199e70;
    --cat-property: #d55181;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg:             #0d1013;
  --surface-1:      #171b20;
  --surface-2:      #1e2329;
  --text-primary:   #f2f4f6;
  --text-secondary: #aeb4bd;
  --text-muted:     #767d87;
  --border:         rgba(255,255,255,0.08);
  --border-strong:  rgba(255,255,255,0.16);
  --accent:         #3987e5;
  --accent-soft:    #16273f;
  --good:           #2fbf4f;
  --critical:       #e66767;
  --warning:        #d99a2b;
  --grid-line:      #2a2f36;
  --shadow: 0 1px 2px rgba(0,0,0,0.3), 0 8px 24px -12px rgba(0,0,0,0.5);

  --cat-growth:   #3987e5;
  --cat-prices:   #d95926;
  --cat-external: #199e70;
  --cat-property: #d55181;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text-primary);
  font-family: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
}
a { color: inherit; }

.wrap { max-width: 1280px; margin: 0 auto; padding: 24px clamp(16px, 4vw, 40px) 64px; }

/* ---------- Masthead ---------- */
.masthead {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 20px;
  flex-wrap: wrap;
  border-bottom: 1px solid var(--border-strong);
  padding-bottom: 18px;
  margin-bottom: 20px;
}
.masthead h1 {
  font-family: "Archivo", "IBM Plex Sans", sans-serif;
  font-weight: 700;
  font-size: clamp(24px, 3.2vw, 34px);
  letter-spacing: -0.01em;
  margin: 0 0 4px;
  text-wrap: balance;
}
.kicker {
  font-family: "IBM Plex Mono", monospace;
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent);
  font-weight: 600;
  margin: 0 0 10px;
}
.masthead .sub { color: var(--text-secondary); font-size: 14.5px; max-width: 58ch; }
.asof {
  text-align: right;
  font-family: "IBM Plex Mono", monospace;
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.7;
}
.asof strong { color: var(--text-secondary); font-weight: 600; }
.live-dot {
  display: inline-block;
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--good);
  margin-right: 6px;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--good) 20%, transparent);
}

/* ---------- Filter row ---------- */
.filter-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}
.range-group {
  display: inline-flex;
  background: var(--surface-2);
  border-radius: 8px;
  padding: 3px;
  gap: 2px;
}
.range-btn {
  font-family: "IBM Plex Mono", monospace;
  font-size: 12px;
  font-weight: 600;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
}
.range-btn:hover { color: var(--text-primary); }
.range-btn.active { background: var(--surface-1); color: var(--text-primary); box-shadow: var(--shadow); }
.range-btn:focus-visible, .tab:focus-visible, .idx-link:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Layout: content + news rail ---------- */
.layout {
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 20px;
  align-items: start;
}
@media (max-width: 980px) {
  .layout { grid-template-columns: 1fr; }
}

/* ---------- Tabs ---------- */
.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 20px;
  overflow-x: auto;
}
.tab {
  font-family: "IBM Plex Mono", monospace;
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: 0.02em;
  background: transparent;
  border: none;
  color: var(--text-muted);
  padding: 10px 14px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
}
.tab[data-cat="growth"].active { color: var(--cat-growth); border-color: var(--cat-growth); }
.tab[data-cat="prices_credit"].active { color: var(--cat-prices); border-color: var(--cat-prices); }
.tab[data-cat="external"].active { color: var(--cat-external); border-color: var(--cat-external); }
.tab[data-cat="property_labor"].active { color: var(--cat-property); border-color: var(--cat-property); }

.panel { display: none; }
.panel.active { display: block; }

/* ---------- KPI row ---------- */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 10px;
  margin-bottom: 18px;
}
.tile {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 13px 15px;
  box-shadow: var(--shadow);
  min-width: 0;
}
.tile .label { font-size: 11.5px; color: var(--text-secondary); font-weight: 600; margin-bottom: 4px; }
.tile .value-row { display: flex; align-items: baseline; gap: 7px; flex-wrap: wrap; }
.tile .value { font-family: "IBM Plex Mono", monospace; font-variant-numeric: tabular-nums; font-size: 22px; font-weight: 600; letter-spacing: -0.01em; }
.tile .period { font-size: 11px; color: var(--text-muted); margin-top: 3px; }
.chip { font-family: "IBM Plex Mono", monospace; font-size: 10.5px; font-weight: 600; padding: 1px 6px; border-radius: 100px; }
.chip.good { color: var(--good); background: color-mix(in srgb, var(--good) 14%, transparent); }
.chip.bad  { color: var(--critical); background: color-mix(in srgb, var(--critical) 14%, transparent); }
.chip.neutral { color: var(--text-muted); background: var(--surface-2); }

/* ---------- Chart grid ---------- */
.chart-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 14px;
}
.chart-card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px 18px 12px;
  box-shadow: var(--shadow);
  position: relative;
}
.chart-card h3 {
  font-family: "Archivo", sans-serif;
  font-size: 14px;
  font-weight: 700;
  margin: 0 0 1px;
}
.chart-card .chart-sub { font-size: 11.5px; color: var(--text-muted); margin-bottom: 8px; }
.chart-flag {
  font-size: 10.5px;
  color: var(--warning);
  background: color-mix(in srgb, var(--warning) 12%, transparent);
  border-radius: 6px;
  padding: 3px 7px;
  margin-bottom: 8px;
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  cursor: help;
}
.chart-card .chart-latest {
  position: absolute;
  top: 16px; right: 18px;
  font-family: "IBM Plex Mono", monospace;
  font-size: 15px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.chart-svg-wrap { position: relative; }
.chart-svg { width: 100%; height: 130px; overflow: visible; display: block; }
.chart-line { fill: none; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.chart-area { opacity: 0.14; }
.chart-grid-line { stroke: var(--grid-line); stroke-width: 1; }
.chart-axis-label { font-family: "IBM Plex Mono", monospace; font-size: 9.5px; fill: var(--text-muted); }
.chart-dot-end { stroke-width: 2.2; }
.crosshair-line { stroke: var(--text-muted); stroke-width: 1; stroke-dasharray: 3 3; opacity: 0; pointer-events: none; }
.crosshair-dot { stroke-width: 2; pointer-events: none; opacity: 0; }
.hover-capture { fill: transparent; cursor: crosshair; }
.tooltip {
  position: absolute;
  pointer-events: none;
  background: var(--surface-1);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 11.5px;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translate(-50%, -100%);
  white-space: nowrap;
  z-index: 5;
}
.tooltip .tt-date { color: var(--text-muted); font-family: "IBM Plex Mono", monospace; font-size: 10.5px; margin-bottom: 2px; }
.tooltip .tt-value { font-family: "IBM Plex Mono", monospace; font-weight: 700; font-variant-numeric: tabular-nums; }

.no-data { font-size: 12.5px; color: var(--text-muted); padding: 20px 0; text-align: center; }

/* ---------- News rail ---------- */
.news-rail {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px 16px 8px;
  box-shadow: var(--shadow);
  position: sticky;
  top: 20px;
}
.news-rail h2 {
  font-family: "Archivo", sans-serif;
  font-size: 14px;
  font-weight: 700;
  margin: 0 0 2px;
}
.news-rail .panel-sub { font-size: 11.5px; color: var(--text-muted); margin: 0 0 12px; }
.news-item {
  display: block;
  padding: 10px 0;
  border-top: 1px solid var(--border);
  text-decoration: none;
  color: inherit;
}
.news-item:first-of-type { border-top: none; }
.news-item .n-head { font-size: 13px; font-weight: 600; line-height: 1.35; margin-bottom: 3px; }
.news-item:hover .n-head { color: var(--accent); }
.news-item .n-sum { font-size: 12px; color: var(--text-secondary); line-height: 1.4; margin-bottom: 4px; }
.news-item .n-meta { font-size: 10.5px; color: var(--text-muted); font-family: "IBM Plex Mono", monospace; }

footer {
  margin-top: 28px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  font-size: 11.5px;
  color: var(--text-muted);
  line-height: 1.7;
}
footer a { color: var(--text-muted); }

.section-label {
  font-family: "IBM Plex Mono", monospace;
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin: 0 0 10px;
}
