/* Shared dashboard for FloodScope, GeoValidate and AgroSignal.
   One screen, no page scroll on desktop: a light step rail on the left; on the right a header, a strip of key figures, the map,
   and an evidence panel with tabs. Regions are divided by rules, not floating cards. Each app sets --accent. */
@font-face { font-family: 'Satoshi'; src: url(../assets/fonts/Satoshi-400.woff2) format('woff2'); font-weight: 400; font-display: swap; }
@font-face { font-family: 'Satoshi'; src: url(../assets/fonts/Satoshi-500.woff2) format('woff2'); font-weight: 500; font-display: swap; }
@font-face { font-family: 'Satoshi'; src: url(../assets/fonts/Satoshi-700.woff2) format('woff2'); font-weight: 700; font-display: swap; }
@font-face { font-family: 'Zodiak'; src: url(../assets/fonts/Zodiak-700.woff2) format('woff2'); font-weight: 400 800; font-display: swap; }
@font-face { font-family: 'Range Dash'; src: url(../assets/fonts/range-dash.woff) format('woff'); unicode-range: U+2013; font-weight: 100 599; font-display: swap; }

:root {
  --canvas: #f4f5f7; --sheet: #ffffff; --sheet-2: #f4f5f7; --hover: #eef0f3;
  --ink: #15181c; --ink-2: #4a525c; --ink-3: #5f6772; --rule: #e6e8eb; --line: #d5d9de;
  --accent: #1f5fbf; --accent-soft: #eaf1fb; --bad: #b42318; --bad-soft: #fdeeec;
  --text: 'Range Dash', 'Satoshi', system-ui, -apple-system, 'Segoe UI', sans-serif; --display: 'Zodiak', Georgia, serif;
  --bar-h: 44px; --rail-w: 296px; --panel-w: 400px; --r: 8px;
}
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body { font-family: var(--text); font-size: 14px; line-height: 1.45; color: var(--ink); background: var(--canvas); -webkit-font-smoothing: antialiased; font-variant-numeric: tabular-nums; }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 3px; }
.vh { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.small { font-size: 13px; color: var(--ink-2); }
.muted { color: var(--ink-3); }
.warn { color: var(--bad); }
.num { font-variant-numeric: tabular-nums; }

.app { display: grid; grid-template-columns: var(--rail-w) minmax(0, 1fr); height: calc(100vh - var(--bar-h)); }

/* ---------------------------------------------------------------- top bar (same in all three tools) */
.topbar { display: flex; align-items: center; gap: 12px; min-height: var(--bar-h); padding: 6px 16px; background: var(--sheet); border-bottom: 1px solid var(--rule); min-width: 0; }
.topbar .back { display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 10px; margin-left: -10px; border-radius: var(--r); color: var(--ink-2); font-size: 13px; font-weight: 500; text-decoration: none; white-space: nowrap; }
.topbar .back:hover { background: var(--hover); color: var(--ink); }
.topbar .tb-title { display: inline-flex; align-items: center; gap: 8px; font-family: var(--display); font-size: 18px; font-weight: 700; line-height: 1; padding-left: 14px; border-left: 1px solid var(--rule); height: 22px; }
.topbar .tb-title::before { content: ''; width: 9px; height: 9px; border-radius: 50%; background: var(--accent); flex: none; }
.topbar .ver { font-size: 11.5px; font-weight: 500; line-height: 1; color: var(--ink-2); border: 1px solid var(--line); border-radius: 999px; padding: 4px 8px; white-space: nowrap; }
.topbar .hb { margin-left: auto; }

/* ---------------------------------------------------------------- step rail (light) */
.rail { background: var(--sheet); border-right: 1px solid var(--rule); display: flex; flex-direction: column; min-height: 0; }
.steps { flex: 1; overflow-y: auto; padding: 12px 0 4px; }
.step { margin: 0 12px; border-radius: 10px; }
.step.open { background: var(--sheet-2); }
.step-h { all: unset; box-sizing: border-box; width: 100%; display: grid; grid-template-columns: 22px 1fr; gap: 1px 10px; padding: 12px 12px; cursor: pointer; border-radius: 10px; }
.step:not(.open):not(.locked) .step-h:hover { background: var(--hover); }
.step-h:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.step-h .n { grid-row: span 2; width: 20px; height: 20px; border-radius: 50%; background: var(--rule); color: var(--ink-2); display: grid; place-items: center; font-size: 11.5px; font-weight: 700; margin-top: 1px; }
.step-h .t { font-weight: 500; font-size: 14px; color: var(--ink); }
.step-h .s { font-size: 12.5px; color: var(--ink-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.step.open .n { background: var(--accent); color: #fff; }
.step.done .n { background: var(--ink); color: #fff; }
.step.locked .step-h { cursor: default; }
.step.locked .t, .step.locked .s { color: #a3aab2; }
.step-b { padding: 0 12px 14px 44px; }
label.f { display: grid; gap: 4px; font-size: 12.5px; color: var(--ink-3); margin: 10px 0; min-width: 0; }
label.f output { color: var(--ink); }
.in { width: 100%; min-width: 0; height: 34px; border: 1px solid var(--line); background: var(--sheet); color: var(--ink); border-radius: var(--r); padding: 0 10px; font-size: 13.5px; }
.in:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.in::placeholder { color: #9aa1a9; }
.row { display: flex; gap: 6px; align-items: center; }
.row > * { flex: 1; min-width: 0; }
.rb { height: 32px; border: 1px solid var(--line); background: var(--sheet); color: var(--ink); border-radius: var(--r); padding: 0 12px; cursor: pointer; font-size: 13px; font-weight: 500; white-space: nowrap; transition: background .12s, border-color .12s; }
.rb:hover:not(:disabled) { background: var(--hover); }
.rb:disabled { opacity: .45; cursor: not-allowed; }
.rb.go { background: var(--accent); border-color: var(--accent); color: #fff; }
.rb.go:hover:not(:disabled) { background: var(--accent); filter: brightness(1.08); }
.rb.wide { width: 100%; height: 34px; margin-top: 12px; }
.rb[aria-pressed="true"] { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.list { list-style: none; margin: 8px 0 0; padding: 4px; max-height: 210px; overflow: auto; border: 1px solid var(--rule); border-radius: var(--r); background: var(--sheet); }
.list button { all: unset; display: block; width: 100%; box-sizing: border-box; padding: 7px 8px; font-size: 13px; cursor: pointer; border-radius: 6px; }
.list button:hover, .list button:focus-visible { background: var(--hover); }
.list button:focus-visible, .menu-list button:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.list li.small { padding: 7px 8px; }
.chosen { margin-top: 10px; padding: 9px 11px; border-radius: var(--r); background: var(--sheet); border: 1px solid var(--rule); font-size: 13px; display: grid; gap: 2px; }
.rail details { margin: 8px 0; font-size: 13px; }
.rail summary { cursor: pointer; color: var(--ink-2); }
input[type=range] { width: 100%; accent-color: var(--accent); }
.check { display: flex; gap: 8px; align-items: flex-start; font-size: 13px; margin: 8px 0; color: var(--ink); }
.check input { accent-color: var(--accent); margin-top: 3px; }
.status { padding: 12px 22px 16px; border-top: 1px solid var(--rule); font-size: 12.5px; color: var(--ink-3); }
.status .bar { height: 3px; background: var(--rule); border-radius: 2px; overflow: hidden; margin-bottom: 8px; }
.status .bar i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .3s; }
.status .msg { color: var(--ink); }
.status .err { color: var(--bad); }
.log { list-style: none; margin: 6px 0 0; padding: 0; max-height: 150px; overflow-y: auto; font-size: 12px; color: var(--ink-3); }
.log li { padding: 1px 0; }
.log li.now { color: var(--ink); }
.log li.err { color: var(--bad); }

/* ---------------------------------------------------------------- main sheet */
.main { display: grid; grid-template-rows: auto auto minmax(0, 1fr); min-width: 0; min-height: 0; background: var(--sheet); }
.head { display: flex; align-items: center; gap: 8px; padding: 14px 24px; border-bottom: 1px solid var(--rule); min-width: 0; }
.head .title { flex: 1; min-width: 0; }
.head h1 { margin: 0; font-family: var(--display); font-size: 21px; font-weight: 700; line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.head .sub { margin: 2px 0 0; color: var(--ink-3); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hb { height: 32px; display: inline-flex; align-items: center; border: 1px solid var(--line); background: var(--sheet); border-radius: var(--r); padding: 0 12px; cursor: pointer; font-size: 13px; font-weight: 500; color: var(--ink); text-decoration: none; white-space: nowrap; transition: background .12s; }
.hb:hover:not(:disabled) { background: var(--hover); }
.hb.go { background: var(--accent); border-color: var(--accent); color: #fff; }
.hb:disabled { opacity: .4; cursor: not-allowed; }
.menu { position: relative; }
.menu > summary { list-style: none; }
.menu > summary::-webkit-details-marker { display: none; }
.menu-list { position: absolute; right: 0; top: calc(100% + 6px); z-index: 20; background: var(--sheet); border: 1px solid var(--rule); border-radius: 10px; box-shadow: 0 8px 28px rgba(22,25,29,.14); padding: 6px; min-width: 240px; display: grid; }
.menu-list button { all: unset; padding: 8px 10px; border-radius: 5px; cursor: pointer; font-size: 13.5px; display: grid; }
.menu-list button span { font-size: 12px; color: var(--ink-3); }
.menu-list button:hover:not(:disabled), .menu-list button:focus-visible { background: var(--sheet-2); }
.menu-list button:disabled { opacity: .45; cursor: not-allowed; }
.menu-note { margin: 2px 4px 4px; padding: 6px 6px 4px; border-bottom: 1px solid var(--rule); font-size: 12px; color: var(--ink-2); }
.hb[aria-disabled="true"] { opacity: .6; }

/* key figures: one instrument strip divided by rules */
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); border-bottom: 1px solid var(--rule); }
.kpi { padding: 14px 24px 16px; min-width: 0; position: relative; }
.kpi + .kpi::before { content: ''; position: absolute; left: 0; top: 16px; bottom: 16px; border-left: 1px solid var(--rule); }
.kpi:last-child { border-right: 0; }
.kpi .l { font-size: 12.5px; color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi .v { font-family: var(--display); font-size: 28px; font-weight: 700; line-height: 1.15; margin-top: 2px; white-space: nowrap; }
.kpi .v small { font-family: var(--text); font-size: 14px; font-weight: 500; color: var(--ink-2); margin-left: 4px; }
.kpi .d { font-size: 12.5px; color: var(--ink-2); line-height: 1.35; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.kpis.empty .v { color: var(--line); }

.body { display: grid; grid-template-columns: minmax(0, 1fr) var(--panel-w); min-height: 0; }
.mapwrap { position: relative; min-width: 0; min-height: 0; border-right: 1px solid var(--rule); }
#map { position: absolute; inset: 0; }
.mapbar { position: absolute; top: 12px; left: 12px; right: 12px; z-index: 3; display: flex; gap: 8px; align-items: flex-start; pointer-events: none; }
.mapbar > * { pointer-events: auto; }
.seg { display: inline-flex; background: var(--sheet); border: 1px solid var(--rule); border-radius: 7px; padding: 3px; box-shadow: 0 1px 3px rgba(22,25,29,.08); flex-wrap: wrap; }
.seg button, .seg label { border: 0; background: none; border-radius: 5px; padding: 5px 10px; font-size: 13px; cursor: pointer; color: var(--ink-2); display: inline-flex; gap: 6px; align-items: center; }
.seg button[aria-pressed="true"], .seg label:has(input:checked) { background: var(--ink); color: #fff; }
.seg label input { position: absolute; opacity: 0; pointer-events: none; }
.seg label:has(input:disabled) { opacity: .4; cursor: not-allowed; }
.seg label:has(input:focus-visible) { outline: 2px solid var(--accent); }
.legend { position: absolute; left: 12px; bottom: 12px; z-index: 3; background: rgba(255,255,255,.96); border: 1px solid var(--rule); border-radius: 10px; padding: 6px 12px; font-size: 12.5px; box-shadow: 0 2px 10px rgba(21,24,28,.08);
  width: max-content; max-width: min(250px, calc(100% - 152px)); max-height: calc(100% - 96px); overflow-y: auto; }
.legend > summary { cursor: pointer; list-style: none; display: flex; justify-content: space-between; gap: 14px; font-weight: 500; line-height: 24px; }
.legend > summary::-webkit-details-marker { display: none; }
.legend > summary::after { content: 'Hide'; font-weight: 400; color: var(--ink-2); }
.legend:not([open]) > summary::after { content: 'Show'; }
.legend[open] > summary { margin-bottom: 2px; }
.legend .ramp { height: 10px; border-radius: 3px; margin: 6px 0 3px; min-width: 150px; }
.legend .ends { display: flex; justify-content: space-between; color: var(--ink-2); font-size: 11.5px; }
.legend .sw, .legend label { display: flex; align-items: center; gap: 8px; line-height: 1.6; cursor: default; }
.legend label { cursor: pointer; }
.legend i { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.legend input[type=checkbox] { accent-color: var(--ink); margin: 0; }
.legend input[type=range] { width: 100%; accent-color: var(--ink); }
.legend .sep { border-top: 1px solid var(--rule); margin: 6px 0 4px; }
.mapnote { position: absolute; z-index: 3; left: 0; right: 0; top: 0; margin: 0; background: #fff7e6; border-bottom: 1px solid #e8cf9c; padding: 6px 12px; font-size: 12.5px; color: #5c4510; }
.mapnote:not([hidden]) ~ .mapbar { top: 48px; }
.mapnote:not([hidden]) ~ .card { top: 48px; }
.card { position: absolute; z-index: 4; right: 12px; top: 12px; width: 240px; background: var(--sheet); border: 1px solid var(--rule); border-radius: 7px; padding: 10px 12px; font-size: 12.5px; box-shadow: 0 6px 20px rgba(22,25,29,.12); }
.card dl, .tip dl { display: grid; grid-template-columns: auto auto; gap: 2px 12px; margin: 6px 0 0; }
.card dt, .tip dt { color: var(--ink-2); }
.card dd, .tip dd { margin: 0; text-align: right; }
.card .x { float: right; border: 0; background: none; cursor: pointer; color: var(--ink-3); font-size: 12px; padding: 0; }
.tip { position: fixed; z-index: 30; background: var(--sheet); border: 1px solid var(--rule); border-radius: 7px; box-shadow: 0 6px 20px rgba(22,25,29,.14); padding: 8px 10px; font-size: 12px; pointer-events: none; max-width: 250px; }
.maplibregl-ctrl-attrib { font-size: 11px; }
/* map credits: one line beside the controls when open, wrapping only on narrow maps; never over the legend (bottom left) */
.maplibregl-ctrl-bottom-right .maplibregl-ctrl-attrib.maplibregl-compact-show { max-width: min(440px, calc(100vw - 280px)); }
.maplibregl-ctrl-attrib-inner { line-height: 1.35; }
@media (max-width: 860px) { .maplibregl-ctrl-bottom-right .maplibregl-ctrl-attrib.maplibregl-compact-show { max-width: calc(100vw - 48px); } }

/* evidence panel */
.panel { display: grid; grid-template-rows: auto minmax(0, 1fr); min-height: 0; }
.tabs { display: flex; gap: 2px; padding: 8px 16px 0; border-bottom: 1px solid var(--rule); overflow-x: auto; }
.tabs button { border: 0; background: none; padding: 8px 10px 10px; cursor: pointer; font-size: 13.5px; color: var(--ink-3); border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--ink); font-weight: 500; }
.tabs button:disabled { opacity: .4; cursor: not-allowed; }
.tabpane { overflow-y: auto; padding: 16px 20px 24px; }
.tabpane h2 { font-size: 15px; margin: 0 0 4px; }
.tabpane h3 { font-size: 14px; margin: 18px 0 6px; }
.tabpane p { margin: 0 0 10px; color: var(--ink-2); font-size: 13.5px; }
.tabpane .note { font-size: 12.5px; color: var(--ink-3); }
.empty-state { padding: 28px 4px; color: var(--ink-3); font-size: 13.5px; }
canvas.chart { width: 100%; height: auto; display: block; }
table.t { width: 100%; border-collapse: collapse; font-size: 13px; }
table.t th, table.t td { text-align: left; padding: 6px 6px; border-bottom: 1px solid var(--rule); vertical-align: top; }
table.t th { font-weight: 500; color: var(--ink-3); }
table.t td.n, table.t th.n { text-align: right; }
.bars { display: grid; gap: 6px; }
.bars .b { display: grid; grid-template-columns: minmax(0, 1fr) 64px; gap: 4px 10px; font-size: 13px; }
.bars .b .tr { grid-column: 1 / -1; height: 6px; background: var(--sheet-2); border-radius: 3px; overflow: hidden; }
.bars .b .tr i { display: block; height: 100%; background: var(--accent); border-radius: 3px; }
.bars .b .n { text-align: right; }

/* about sheet */
.sheet { position: fixed; inset: 0; z-index: 40; background: rgba(22,25,29,.4); display: flex; justify-content: flex-end; }
.sheet article { width: min(640px, 100%); height: 100%; overflow-y: auto; background: var(--sheet); padding: 28px 32px 48px; }
.sheet h2 { font-family: var(--display); font-size: 26px; margin: 0 0 8px; }
.sheet h3 { font-size: 15px; margin: 22px 0 6px; }
.sheet p, .sheet li { color: var(--ink-2); font-size: 14px; max-width: 66ch; }
.sheet .x { float: right; }
.sheet table { width: 100%; border-collapse: collapse; font-size: 13px; }
.sheet td { border-bottom: 1px solid var(--rule); padding: 7px 6px 7px 0; vertical-align: top; color: var(--ink-2); }
.sheet td:first-child { color: var(--ink); white-space: nowrap; padding-right: 14px; }

/* narrower screens: rail on top, then figures, map, panel; the page scrolls */
@media (max-width: 1100px) { :root { --panel-w: 340px; } .kpi .v { font-size: 26px; } }
@media (max-width: 860px) {
  .app { display: block; height: auto; }
  .rail { position: static; border-right: 0; border-bottom: 1px solid var(--rule); }
  .steps { overflow: visible; }
  .main { display: block; }
  .head { flex-wrap: wrap; padding: 12px 16px; }
  .head .title { flex-basis: 100%; }
  .head h1, .head .sub { white-space: normal; }
  .kpis { grid-template-columns: 1fr 1fr; }
  .kpi { padding: 12px 16px; border-bottom: 1px solid var(--rule); }
  .kpi:nth-child(2n) { border-right: 0; }
  .kpi:nth-child(odd)::before { display: none; }
  .menu-list { right: auto; left: 0; max-width: calc(100vw - 32px); }
  .kpi .d { -webkit-line-clamp: 3; }
  .body { display: block; }
  .mapwrap { height: 62vh; border-right: 0; border-bottom: 1px solid var(--rule); }
  .tabpane { max-height: none; }
  .card { left: 12px; right: 12px; top: 12px; width: auto; }
  .mapwrap { min-height: 320px; }
}
@media (max-width: 560px) {
  .topbar { flex-wrap: wrap; row-gap: 2px; padding: 6px 16px 8px; }
  .topbar .hb { order: 2; }
  .topbar .tb-title { order: 3; flex-basis: auto; border-left: 0; padding-left: 0; }
  .topbar .ver { order: 4; }
}
@media (prefers-reduced-motion: reduce) { .status .bar i { transition: none; } }
@media print {
  body { background: #fff; }
  body > *:not(.report) { display: none !important; }
  .report { display: block !important; color: #000; font-size: 10.5pt; }
  .report h1 { font-family: var(--display); font-size: 20pt; margin: 0 0 4pt; }
  .report h2 { font-size: 12pt; margin: 12pt 0 4pt; }
  .report img { width: 100%; border: 1px solid #999; }
  .report table { width: 100%; border-collapse: collapse; font-size: 9.5pt; }
  .report td, .report th { border-bottom: 1px solid #ccc; padding: 3pt 4pt; text-align: left; }
}
.report { display: none; }
/* slider fields: label and value on one line, the slider below */
label.f:has(> input[type=range]) { grid-template-columns: 1fr auto; }
label.f:has(> input[type=range]) > input[type=range] { grid-column: 1 / -1; }
label.f > output { justify-self: end; }

/* About: a plain summary above the technical tables */
.plain { margin: 6px 0 18px; padding: 14px 18px; background: var(--accent-soft, #f1f4f8); border-radius: var(--r); }
.plain h3 { margin: 0 0 6px; }
.plain ul { margin: 0; padding-left: 18px; }
.plain li { margin: 4px 0; line-height: 1.5; }
.plain b { font-weight: 600; }
