:root {
  --ink: #18251f;
  --muted: #65726b;
  --paper: #f5f6f1;
  --card: #ffffff;
  --line: #d9ded8;
  --brand: #185c45;
  --event: #9d3a38;
  --missing: #9aa19d;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; min-height: 100%; color: var(--ink); background: var(--paper); font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
body { padding: 0 24px 24px; }

.topbar { min-height: 96px; display: flex; align-items: center; justify-content: space-between; gap: 24px; max-width: 1600px; margin: 0 auto; }
.topbar h1 { margin: 2px 0 0; font-size: clamp(24px, 2.5vw, 38px); letter-spacing: -0.035em; }
.eyebrow { margin: 0; color: var(--brand); font-size: 11px; font-weight: 800; letter-spacing: 0.12em; }
.status { font-size: 12px; color: var(--muted); }
.status::before { content: ""; display: inline-block; width: 8px; height: 8px; margin-right: 7px; border-radius: 50%; background: #2c8a63; }
.status.offline::before { background: #c0852b; }

main { max-width: 1600px; margin: 0 auto; }
.controls { display: grid; grid-template-columns: minmax(210px, 1fr) minmax(210px, 1fr) minmax(280px, 2fr) minmax(190px, auto); gap: 16px; align-items: end; padding: 14px 16px; background: var(--card); border: 1px solid var(--line); border-radius: 14px 14px 0 0; }
label { display: grid; gap: 6px; color: var(--muted); font-size: 12px; font-weight: 700; }
select, button { height: 40px; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--ink); font: inherit; }
select { padding: 0 34px 0 11px; }
input[type="number"] { height: 40px; width: 100%; padding: 0 11px; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--ink); font: inherit; }
.date-control { display: grid; grid-template-columns: 42px 1fr; align-items: center; gap: 10px; }
button { cursor: pointer; color: var(--brand); font-weight: 800; }
button:hover { border-color: var(--brand); }
input[type="range"] { width: 100%; accent-color: var(--brand); }
.date-readout { min-height: 40px; display: flex; flex-direction: column; justify-content: center; align-items: flex-end; }
.date-readout strong { font-size: 17px; }
.date-readout span { color: var(--event); font-size: 12px; font-weight: 700; }

.workspace { display: grid; grid-template-columns: minmax(0, 2.2fr) minmax(320px, 0.8fr); min-height: min(690px, calc(100vh - 220px)); background: var(--card); border: 1px solid var(--line); border-top: 0; }
.map-wrap { position: relative; min-height: 560px; background: #e8ece6; overflow: hidden; }
#map { position: absolute; inset: 0; background: radial-gradient(circle at 35% 40%, #f1f2ed, #e1e5de); }
.leaflet-container { font: inherit; }
.leaflet-control-attribution { font-size: 10px; }
.legend { position: absolute; z-index: 500; left: 16px; bottom: 50px; width: 230px; padding: 12px; border: 1px solid rgba(24,37,31,.15); border-radius: 9px; background: rgba(255,255,255,.94); box-shadow: 0 4px 18px rgba(0,0,0,.08); }
.legend-title { margin-bottom: 8px; font-size: 12px; font-weight: 800; }
.legend-gradient { height: 12px; border-radius: 3px; }
.legend-labels { display: flex; justify-content: space-between; margin-top: 4px; font-size: 11px; color: var(--muted); }
.legend-missing { margin-top: 8px; font-size: 11px; color: var(--muted); }
.legend-missing i { display: inline-block; width: 12px; height: 12px; margin-right: 5px; vertical-align: -2px; background: var(--missing); border: 1px dashed #4c5550; }
.legend-categories { display: grid; gap: 7px; font-size: 11px; color: var(--muted); }
.legend-category i { display: inline-block; width: 13px; height: 13px; margin-right: 6px; vertical-align: -2px; border: 1px solid rgba(0,0,0,.12); }
.legend-category .loss { background: #b43d3d; }
.legend-category .no-loss { background: #2f6fa5; }
.map-caption { position: absolute; z-index: 500; right: 14px; bottom: 12px; max-width: 530px; padding: 7px 10px; border-radius: 6px; background: rgba(255,255,255,.9); color: var(--muted); font-size: 11px; }

.details { padding: 24px; border-left: 1px solid var(--line); overflow-y: auto; }
.details-placeholder { min-height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 7px; text-align: center; color: var(--muted); }
.details-placeholder strong { color: var(--ink); }
.details h2 { margin: 3px 0 20px; font-size: 25px; letter-spacing: -0.03em; }
.metrics { display: grid; grid-template-columns: repeat(3, 1fr); margin: 0 0 25px; border: 1px solid var(--line); border-radius: 10px; }
.metrics div { padding: 11px; border-right: 1px solid var(--line); }
.metrics div:last-child { border-right: 0; }
.metrics dt { color: var(--muted); font-size: 10px; text-transform: uppercase; letter-spacing: .06em; }
.metrics dd { margin: 4px 0 0; font-size: 14px; font-weight: 800; }
.chart { width: 100%; min-height: 260px; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart text { fill: var(--muted); font-size: 10px; }
.chart .axis { stroke: #b8c0ba; }
.chart .grid { stroke: #e7eae6; }
.chart .series { fill: none; stroke: var(--brand); stroke-width: 2.2; }
.chart .point { fill: var(--brand); stroke: #fff; stroke-width: 1.5; }
.chart .selected { fill: #fff; stroke: var(--ink); stroke-width: 2.5; }
.chart .event-line { stroke: var(--event); stroke-width: 1.5; stroke-dasharray: 5 4; }
.chart-note { color: var(--muted); font-size: 11px; line-height: 1.45; }
.disclaimer { margin-top: 14px; padding: 14px 17px; display: flex; gap: 18px; border-left: 4px solid var(--brand); background: #edf2ee; font-size: 12px; line-height: 1.5; }
.disclaimer p { margin: 0; }

.analysis { margin-top: 18px; padding: 24px; border: 1px solid var(--line); border-radius: 14px; background: var(--card); }
.analysis-heading { display: flex; justify-content: space-between; align-items: flex-start; gap: 28px; }
.analysis h2 { margin: 4px 0 7px; font-size: 27px; letter-spacing: -0.03em; }
.analysis h3 { margin: 0 0 14px; font-size: 15px; }
.analysis-method { max-width: 730px; margin: 0; color: var(--muted); font-size: 12px; line-height: 1.5; }
.price-controls { display: grid; grid-template-columns: minmax(250px, 1fr) 150px; gap: 8px 12px; min-width: min(100%, 430px); }
.comparison-method { grid-column: 1 / -1; }
.price-controls a { grid-column: 1 / -1; color: var(--brand); font-size: 11px; font-weight: 700; text-decoration: none; }
.summary-cards { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; margin: 24px 0; }
.summary-cards article { min-height: 90px; padding: 14px; border: 1px solid var(--line); border-radius: 10px; background: #fafbf8; }
.summary-cards span { display: block; min-height: 30px; color: var(--muted); font-size: 11px; line-height: 1.25; }
.summary-cards strong { display: block; margin-top: 7px; font-size: clamp(16px, 1.6vw, 23px); letter-spacing: -0.025em; }
.summary-cards strong.negative { color: var(--event); }
.summary-cards strong.positive { color: var(--brand); }
.analysis-grid { display: grid; grid-template-columns: minmax(340px, .85fr) minmax(600px, 1.55fr); gap: 28px; align-items: start; }
.comparison-bars { display: grid; gap: 7px; }
.bar-row { display: grid; grid-template-columns: 145px 1fr 62px; gap: 8px; align-items: center; font-size: 10px; }
.bar-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); }
.bar-track { position: relative; height: 12px; border-radius: 3px; background: linear-gradient(90deg, #f5e4df 0 49.6%, #c7cdc9 49.6% 50.4%, #dcece5 50.4% 100%); overflow: hidden; }
.bar-fill { position: absolute; top: 2px; bottom: 2px; }
.bar-fill.negative { right: 50%; background: var(--event); }
.bar-fill.positive { left: 50%; background: var(--brand); }
.bar-value { text-align: right; font-variant-numeric: tabular-nums; font-weight: 750; }
.table-wrap { max-height: 530px; overflow: auto; border: 1px solid var(--line); border-radius: 9px; }
table { width: 100%; border-collapse: collapse; font-size: 11px; font-variant-numeric: tabular-nums; }
thead { position: sticky; top: 0; z-index: 1; background: #eef2ed; }
th, td { padding: 9px 10px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
tbody tr:last-child td { border-bottom: 0; }
td.negative { color: var(--event); font-weight: 750; }
td.positive { color: var(--brand); font-weight: 750; }
.financial-note { margin-top: 20px; padding: 13px 15px; border-radius: 9px; background: #f7eee9; color: #6c3c35; font-size: 11px; line-height: 1.5; }
.financial-note p { margin: 3px 0 0; }

.shap-analysis { margin-top: 18px; padding: 24px; border: 1px solid var(--line); border-radius: 14px; background: var(--card); }
.shap-heading { display: flex; justify-content: space-between; align-items: flex-start; gap: 28px; }
.shap-analysis h2 { margin: 4px 0 7px; font-size: 27px; letter-spacing: -0.03em; }
.shap-analysis h3 { margin: 0 0 5px; font-size: 15px; }
.shap-key { display: grid; gap: 7px; padding-top: 7px; color: var(--muted); font-size: 11px; white-space: nowrap; }
.shap-key i { display: inline-block; width: 12px; height: 12px; margin-right: 6px; vertical-align: -2px; border-radius: 2px; }
.shap-positive { background: var(--brand); }
.shap-negative { background: var(--event); }
.shap-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; margin-top: 22px; }
.shap-card { padding: 18px; border: 1px solid var(--line); border-radius: 10px; background: #fafbf8; }
.shap-card > p { min-height: 34px; margin: 0 0 15px; color: var(--muted); font-size: 11px; line-height: 1.45; }
.shap-chart { display: grid; gap: 7px; }
.shap-row { display: grid; grid-template-columns: minmax(145px, 1.3fr) minmax(120px, 1fr) 52px; gap: 9px; align-items: center; font-size: 10px; }
.shap-name { overflow: hidden; color: var(--muted); text-overflow: ellipsis; white-space: nowrap; }
.shap-track { position: relative; height: 12px; overflow: hidden; border-radius: 3px; background: #e7eae6; }
.shap-track i { position: absolute; top: 2px; bottom: 2px; display: block; }
.shap-track.importance i { left: 0; background: #476a6f; }
.shap-track.direction { background: linear-gradient(90deg, #f5e4df 0 49.6%, #c7cdc9 49.6% 50.4%, #dcece5 50.4% 100%); }
.shap-track.direction i.negative { right: 50%; background: var(--event); }
.shap-track.direction i.positive { left: 50%; background: var(--brand); }
.shap-value { text-align: right; font-variant-numeric: tabular-nums; font-weight: 750; }
.shap-value.negative { color: var(--event); }
.shap-value.positive { color: var(--brand); }
.shap-note { margin-top: 18px; padding: 13px 15px; border-radius: 9px; background: #edf2ee; color: #355047; font-size: 11px; line-height: 1.5; }
.shap-note p { margin: 3px 0 0; }

.field-tooltip { font-weight: 750; }

@media (max-width: 980px) {
  body { padding: 0 12px 12px; }
  .controls { grid-template-columns: 1fr 1fr; }
  .workspace { grid-template-columns: 1fr; }
  .map-wrap { min-height: 520px; }
  .details { min-height: 420px; border-left: 0; border-top: 1px solid var(--line); }
  .analysis-heading { flex-direction: column; }
  .price-controls { width: 100%; }
  .summary-cards { grid-template-columns: repeat(2, 1fr); }
  .analysis-grid { grid-template-columns: 1fr; }
  .shap-heading { flex-direction: column; }
  .shap-grid { grid-template-columns: 1fr; }
}

@media (max-width: 600px) {
  .topbar { align-items: flex-start; padding: 18px 0; }
  .status { display: none; }
  .controls { grid-template-columns: 1fr; }
  .date-readout { align-items: flex-start; }
  .metrics { grid-template-columns: 1fr; }
  .metrics div { border-right: 0; border-bottom: 1px solid var(--line); }
  .metrics div:last-child { border-bottom: 0; }
  .legend { width: 200px; }
  .map-caption { display: none; }
  .analysis { padding: 18px 14px; }
  .price-controls { grid-template-columns: 1fr; }
  .price-controls a { grid-column: 1; }
  .summary-cards { grid-template-columns: 1fr; }
  .bar-row { grid-template-columns: 115px 1fr 55px; }
  .shap-analysis { padding: 18px 14px; }
  .shap-row { grid-template-columns: minmax(120px, 1.1fr) minmax(90px, 1fr) 48px; }
}
