:root {
  --bg: #ffffff;
  --bg-soft: #f4f6f8;
  --fg: #1d2329;
  --muted: #66707a;
  --line: #dde2e7;
  --accent: #0b6bcb;
  --brand-green: #2a8a3c;
  --accent-fg: #ffffff;
  --danger: #d03b3b;
  --panel-w: 400px;
  /* chart tokens */
  --viz-surface: #fcfcfb;
  --viz-grid: #e1e0d9;
  --viz-axis: #c3c2b7;
  --viz-muted: #898781;
  --viz-series: #2a78d6;
  font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15191d;
    --bg-soft: #1f252b;
    --fg: #e6e9ec;
    --muted: #98a2ad;
    --line: #2e363e;
    --accent: #4c9eff;
    --brand-green: #40b856;
    --accent-fg: #0b1622;
    --danger: #ff6b6b;
    --viz-surface: #1a1a19;
    --viz-grid: #2c2c2a;
    --viz-axis: #383835;
    --viz-series: #3987e5;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--fg); font-size: 14px; line-height: 1.45; display: flex; overflow: hidden; }

#panel {
  width: var(--panel-w);
  flex: none;
  height: 100%;
  overflow-y: auto;
  border-right: 1px solid var(--line);
  background: var(--bg);
  z-index: 2;
}
#map { flex: 1; height: 100%; position: relative; }

.brand { padding: 18px 18px 6px; }
.brand h1 { margin: 0 0 4px; font-size: 18px; letter-spacing: -0.01em; }
.brand p { margin: 0; color: var(--muted); }
.brand .byline { margin-top: 6px; font-size: 12px; }
.brand-lockup { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.brand-lockup img { flex: none; width: 52px; height: 52px; border-radius: 10px; background: #fff; }
.brand .brand-lockup h1 { margin: 0; font-size: 24px; font-weight: 700; letter-spacing: -0.01em; line-height: 1.1; }
.brand .brand-lockup .tagline { margin: 2px 0 0; font-size: 12px; color: var(--muted); line-height: 1.3; }
.w-open { color: var(--fg); }
.w-hvra { color: var(--brand-green); }
.help-logo { display: block; width: min(300px, 70%); height: auto; margin: 0 auto 12px; border-radius: 8px; }

section { padding: 12px 18px; border-bottom: 1px solid var(--line); }
details { border-bottom: 1px solid var(--line); }
summary {
  list-style: none; cursor: pointer; padding: 12px 18px; font-size: 13px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); display: flex; align-items: center; gap: 8px;
}
summary::-webkit-details-marker { display: none; }
summary::after { content: '▸'; margin-left: auto; transition: transform 0.15s; }
details[open] > summary::after { transform: rotate(90deg); }
summary:hover { color: var(--fg); }
details > .body { padding: 0 18px 14px; }
.step { display: inline-grid; place-items: center; width: 20px; height: 20px; border-radius: 50%; background: var(--accent); color: var(--accent-fg); font-size: 11px; }
footer { padding: 14px 18px 24px; }
a { color: var(--accent); }

.muted { color: var(--muted); }
.small { font-size: 12px; }
.hidden { display: none !important; }

.row { display: flex; gap: 8px; flex-wrap: wrap; }
.row > input { flex: 1; min-width: 0; }
.grid2 { display: grid; grid-template-columns: 1fr 110px; gap: 0 8px; }
.grid2.even { grid-template-columns: 1fr 1fr; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0 8px; }

input[type=search], input[type=number], input[type=text], select {
  font: inherit; color: var(--fg); background: var(--bg-soft);
  border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; width: 100%;
}
input[type=range] { width: 100%; accent-color: var(--accent); }
input[type=checkbox], input[type=radio] { accent-color: var(--accent); }
.field { display: block; margin-bottom: 8px; }
.field > span { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); margin-bottom: 3px; }
.field output { color: var(--fg); font-weight: 600; }
.field.check { display: flex; gap: 6px; align-items: center; padding-top: 16px; }
.field.check > span { margin: 0; color: var(--fg); }

.btn {
  font: inherit; font-weight: 500; cursor: pointer; border-radius: 6px; padding: 6px 12px;
  border: 1px solid var(--line); background: var(--bg-soft); color: var(--fg);
}
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.primary { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
.btn.ghost { background: transparent; }
.btn.block { width: 100%; margin-top: 4px; }
.btn.active { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
#downloads { margin-top: 8px; }

.seg { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.seg .btn { padding: 6px 4px; font-size: 13px; }
.upload-row { display: grid; grid-template-columns: auto 1fr; gap: 8px; align-items: center; margin-top: 8px; }
.upload-row .btn { white-space: nowrap; }
#upload-feature { margin-top: 8px; }
#map.dropping::after {
  content: 'Drop a boundary file to use it as the area'; position: absolute; inset: 0; z-index: 5; display: grid; place-items: center;
  background: rgb(112 72 232 / 0.18); border: 3px dashed #7048e8; color: #1d2329; font: 600 16px 'Inter', system-ui, sans-serif; pointer-events: none;
}
.radio-row { display: grid; gap: 4px; margin: 6px 0 8px; font-size: 13px; }
.radio-row label { cursor: pointer; }

.progress { height: 4px; background: var(--bg-soft); border-radius: 2px; overflow: hidden; margin-top: 8px; }
.progress > div { height: 100%; width: 30%; background: var(--accent); animation: indet 1.2s ease-in-out infinite; }
@keyframes indet { from { transform: translateX(-100%); } to { transform: translateX(340%); } }

.stats { margin-top: 8px; }
.stats p { margin: 4px 0; }
.kpis { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin: 6px 0 10px; }
.kpi { background: var(--bg-soft); border-radius: 8px; padding: 8px 10px; }
.kpi b { display: block; font-size: 20px; line-height: 1.2; }
.kpi span { font-size: 12px; color: var(--muted); }
.kpi.alert b { color: var(--danger); }

table.list { width: 100%; border-collapse: collapse; font-size: 13px; }
table.list th { text-align: left; font-weight: 500; font-size: 12px; color: var(--muted); padding: 3px 0; border-bottom: 1px solid var(--line); }
table.list th.num { text-align: right; }
table.list td { padding: 3px 0; border-bottom: 1px solid var(--line); vertical-align: top; }
table.list .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; padding-left: 8px; }
table.inputs { width: 100%; border-collapse: collapse; font-size: 12px; }
table.inputs th { text-align: left; font-weight: 500; color: var(--muted); padding-bottom: 3px; }
table.inputs td { padding: 2px 4px 2px 0; }
.sub { font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); margin: 12px 0 4px; }
.sub .muted { text-transform: none; letter-spacing: 0; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; vertical-align: baseline; flex: none; }
.warn { background: color-mix(in srgb, var(--danger) 12%, transparent); border-radius: 6px; padding: 6px 8px; }
.note { font-size: 12px; color: var(--muted); margin: 6px 0; }

#hz-table td { vertical-align: middle; }
#hz-table td:first-child label { display: flex; gap: 6px; align-items: center; cursor: pointer; font-size: 13px; }
#hz-table input[type=number] { padding: 4px 6px; }
#hz-table .setting { font-size: 11px; color: var(--muted); }
.matrix { border-collapse: separate; border-spacing: 2px; width: 100%; font-size: 11px; table-layout: fixed; }
.matrix th { font-weight: 500; color: var(--muted); padding: 2px; text-align: center; }
.matrix th.rowh { text-align: right; padding-right: 4px; width: 62px; }
.matrix td { height: 38px; border-radius: 4px; text-align: center; vertical-align: middle; padding: 2px; line-height: 1.2; }
.matrix td b { display: block; font-size: 10px; font-weight: 600; opacity: 0.85; }
.matrix .r-low { background: #0ca30c; color: #0b0b0b; }
.matrix .r-medium { background: #fab219; color: #0b0b0b; }
.matrix .r-high { background: #ec835a; color: #0b0b0b; }
.matrix .r-extreme { background: #d03b3b; color: #fff; }
.check-list { display: grid; gap: 4px; font-size: 13px; }
.check-list label { display: flex; gap: 6px; align-items: flex-start; cursor: pointer; }
.check-list input { margin-top: 3px; }
.check-list .muted { font-size: 11px; display: block; }
.toggles { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-bottom: 8px; }
.toggles label { display: flex; align-items: center; gap: 5px; cursor: pointer; }
.ramp { display: flex; height: 10px; border-radius: 2px; overflow: hidden; margin-top: 4px; }
.ramp span { flex: 1; }

/* Chart */
.viz { position: relative; background: var(--viz-surface); border-radius: 8px; margin: 8px 0; }
.viz svg { display: block; }
.viz .grid { stroke: var(--viz-grid); stroke-width: 1; }
.viz .axis { stroke: var(--viz-axis); stroke-width: 1; }
.viz .tick { fill: var(--viz-muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.viz .label { fill: var(--fg); font-size: 12px; font-weight: 600; }
.viz .line { fill: none; stroke: var(--viz-series); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.viz .area { fill: var(--viz-series); opacity: 0.1; }
.viz .dot { fill: var(--viz-series); stroke: var(--viz-surface); stroke-width: 2; }
.viz .hit { fill: transparent; cursor: default; }
.viz .pt:focus { outline: none; }
.viz .pt:focus .dot, .viz .pt:hover .dot { r: 5.5; }
.viz-tip {
  position: absolute; pointer-events: none; background: var(--bg); color: var(--fg); border: 1px solid var(--line);
  border-radius: 6px; padding: 6px 8px; font-size: 12px; box-shadow: 0 2px 8px rgb(0 0 0 / 0.15); width: 150px;
}

/* Map controls */
.ctrl-icon { display: grid !important; place-items: center; }
.ctrl-icon svg { width: 18px; height: 18px; fill: none; stroke: #333; stroke-width: 1.8; stroke-linejoin: round; stroke-linecap: round; }
.ctrl-icon.active { background: #e7f1fc !important; }
.ctrl-icon.active svg { stroke: #0b6bcb; }
/* Layers box (bottom-left of the map) */
.layer-ctrl {
  background: #fff; color: #1d2329; border-radius: 8px; box-shadow: 0 1px 6px rgb(0 0 0 / 0.25);
  font: 13px/1.35 'Inter', system-ui, sans-serif; width: 236px; display: flex; flex-direction: column;
  /* Stay below the drawing toolbar at the top-left. */
  max-height: calc(100vh - 240px); color-scheme: light;
}
.layer-ctrl.closed { width: auto; }
.layer-head {
  display: flex; align-items: center; gap: 8px; width: 100%; padding: 8px 10px; border: 0; background: none; cursor: pointer;
  font: 600 13px 'Inter', system-ui, sans-serif; color: #1d2329;
}
.layer-head svg { width: 18px; height: 18px; fill: none; stroke: #333; stroke-width: 1.8; stroke-linejoin: round; }
.layer-head .chev { margin-left: auto; transition: transform 0.15s; }
.layer-ctrl.closed .layer-head .chev { transform: rotate(-90deg); }
.layer-body { overflow-y: auto; padding: 0 10px 10px; border-top: 1px solid #e9ecef; }
.layer-sec { font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; color: #66707a; margin: 10px 0 4px; }
.layer-row { display: flex; align-items: center; gap: 7px; padding: 3px 0; cursor: pointer; }
.layer-row input { margin: 0; accent-color: #0b6bcb; }
.layer-row .name { flex: 1; }
.layer-row .swatch { width: 18px; height: 13px; border-radius: 3px; border: 1px solid rgb(0 0 0 / 0.15); flex: none; }
.layer-item.unavailable .layer-row { color: #98a2ad; cursor: default; }
.layer-hint { display: none; font-size: 11px; color: #98a2ad; margin: -2px 0 2px 22px; }
.layer-item.unavailable .layer-hint { display: block; }
.layer-row .more { border: 0; background: none; cursor: pointer; color: #66707a; font-size: 12px; padding: 0 2px; }
.sym { flex: none; display: inline-block; }
.sym-fill { width: 13px; height: 11px; border-radius: 2px; background: var(--c); }
.sym-line { width: 14px; height: 3px; border-radius: 2px; background: var(--c); }
.sym-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--c); box-shadow: 0 0 0 1.5px #fff, 0 0 0 2.5px rgb(0 0 0 / 0.15); }
.layer-items { list-style: none; margin: 0 0 4px 22px; padding: 0; font-size: 12px; color: #4a5663; }
.layer-items li { display: flex; align-items: center; gap: 6px; padding: 1px 0; }
.layer-ramp { display: none; margin: 0 0 6px 22px; }
.layer-item.on .layer-ramp { display: block; }
.layer-ramp .ramp { margin-top: 2px; }
.ramp-labels { display: flex; justify-content: space-between; font-size: 11px; color: #66707a; }

.draw-hint {
  position: absolute; top: 10px; left: 50%; transform: translateX(-50%); z-index: 3; background: #1d2329; color: #fff;
  padding: 6px 12px; border-radius: 6px; font-size: 13px; max-width: calc(100% - 120px); text-align: center; pointer-events: none;
}

.maplibregl-popup-content { font: 12px/1.4 'Inter', system-ui, sans-serif; color: #1d2329; padding: 8px 10px; }
.maplibregl-ctrl-attrib { font-size: 11px; }

.linklike { background: none; border: 0; padding: 0; font: inherit; color: var(--accent); text-decoration: underline; cursor: pointer; }

#help {
  width: min(680px, calc(100vw - 32px)); max-height: calc(100vh - 48px); padding: 0; border: 1px solid var(--line);
  border-radius: 12px; background: var(--bg); color: var(--fg); box-shadow: 0 12px 40px rgb(0 0 0 / 0.3);
  display: none; flex-direction: column;
}
#help[open] { display: flex; }
#help::backdrop { background: rgb(13 17 22 / 0.55); }
.help-body { overflow-y: auto; padding: 22px 26px 8px; font-size: 14px; }
.help-body h2 { margin: 0; font-size: 22px; }
.help-body h3 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); margin: 18px 0 6px; }
.help-body .help-tag { margin: 2px 0 12px; font-weight: 500; color: var(--muted); }
.help-body ul, .help-body ol { padding-left: 20px; margin: 0; }
.help-body li { margin: 5px 0; }
.help-body .help-credit { font-size: 12px; color: var(--muted); border-top: 1px solid var(--line); padding-top: 10px; margin-top: 16px; }
.help-foot { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 26px; border-top: 1px solid var(--line); font-size: 13px; }
.help-foot label { display: flex; gap: 6px; align-items: center; cursor: pointer; }

#panel-toggle { display: none; }

@media (max-width: 760px) {
  body { flex-direction: column-reverse; }
  #panel { width: 100%; height: 48%; border-right: 0; border-top: 1px solid var(--line); }
  #panel.collapsed { height: 0; overflow: hidden; border: 0; }
  #map { min-height: 0; }
  .layer-ctrl { max-height: calc(52vh - 190px); }
  #panel-toggle { display: block; position: absolute; left: 50px; top: 10px; z-index: 3; box-shadow: 0 1px 4px rgb(0 0 0 / 0.2); }
  section, .brand, footer, summary, details > .body { padding-left: 16px; padding-right: 16px; }
  .draw-hint { top: 52px; max-width: calc(100% - 32px); }
  .help-body { padding: 16px 16px 6px; }
  .help-foot { padding: 10px 16px; }
}
.report-list { list-style: none; padding: 0; margin: 6px 0 8px; font-size: 13px; display: grid; gap: 3px; }
.report-list li { display: flex; gap: 8px; align-items: baseline; }
.report-list .mark { width: 14px; flex: none; font-weight: 700; }
.report-list .done .mark { color: #0ca30c; }
.report-list .todo { color: var(--muted); }
.table-scroll { overflow-x: auto; max-width: 100%; }
table.calc { font-size: 12px; min-width: 560px; }
table.calc th { white-space: normal; vertical-align: bottom; }
#panel { overflow-x: hidden; }
.report-list .label { flex: 1; }
.btn.mini { padding: 1px 8px; font-size: 12px; }

/* Beta notice */
.beta-note {
  position: relative; margin-top: 10px; padding: 8px 10px; border-radius: 6px; font-size: 12px; line-height: 1.45;
  background: color-mix(in srgb, #fab219 14%, transparent); border-left: 3px solid #fab219; color: var(--fg);
}
.beta-note p { margin: 0; }
.beta-note.in-help { margin: 10px 0 12px; font-size: 13px; }

/* Map and chart exports */
.exports { margin-top: 12px; padding-top: 10px; border-top: 1px dashed var(--line); }
.charts > summary { cursor: pointer; font-size: 13px; color: var(--accent); padding: 4px 0; text-transform: none; letter-spacing: 0; font-weight: 500; display: list-item; }
.charts > summary::after { content: none; }
.chart-card { background: #fff; border-radius: 8px; padding: 6px; margin: 8px 0; }
.chart-card .chart-svg svg { width: 100%; height: auto; display: block; }
.chart-card .row { padding: 4px 2px 2px; }

/* GLOF marks */
.mark-row { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0; }
.inline-field { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.inline-field > span { margin: 0; }
.inline-field input { width: 90px; }
#mark-list:empty { display: none; }
.lake-actions { white-space: nowrap; }
.lake-actions .linklike { font-size: 12px; margin-left: 6px; }

/* 3D toggle */
.threed-ctrl { position: relative; }
.threed-btn { font: 700 12px 'Inter', system-ui, sans-serif !important; color: #333; width: 29px; }
.threed-btn.active { background: #e7f1fc !important; color: #0b6bcb; }
.threed-panel {
  position: absolute; right: 36px; top: 0; background: #fff; border-radius: 6px; box-shadow: 0 2px 10px rgb(0 0 0 / 0.25);
  padding: 6px 10px; width: 160px; display: grid; gap: 2px; font: 12px 'Inter', system-ui, sans-serif; color: #1d2329; color-scheme: light;
}
.threed-panel[hidden] { display: none; }
.threed-panel input { width: 100%; accent-color: #0b6bcb; }
