/* One-screen app: header strip, map on the left, field panel on the right; on phones map above, panel below. */
:root {
  --bg: #eef1ea;
  --surface: #fbfcf8;
  --fg: #1c241d;
  --muted: #5d695e;
  --line: #d3d9cd;
  --accent: #2e5d3a;
  --accent-ink: #f4f7f1;
  --map-bg: #e3e8dc;
  --stroke: #f4f7f1;
  --warn: #9a5b12;
  --danger: #a3372b;
  --ok: #3f9a52;
  --rain: #2f6fb0;
  --font: "Segoe UI", Roboto, "Helvetica Neue", Arial, system-ui, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121612; --surface: #1a201b; --fg: #e3e9e0; --muted: #98a596; --line: #2d362e;
    --accent: #8cc79a; --accent-ink: #102014; --map-bg: #161c17; --stroke: #e3e9e0;
    --warn: #e0a557; --danger: #ef8a7c; --ok: #6cc47e; --rain: #7fb2e5; color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--fg); font: 14px/1.4 var(--font); padding: env(safe-area-inset-top, 0px) 0 env(safe-area-inset-bottom, 0px); }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }
.num { font-variant-numeric: tabular-nums; }

.app { height: 100%; display: grid; grid-template-rows: auto 1fr; grid-template-columns: minmax(0, 1fr); }
header.top {
  position: relative; display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px;
  padding-block: 8px; padding-left: max(14px, env(safe-area-inset-left, 0px)); padding-right: max(14px, env(safe-area-inset-right, 0px));
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.brand { display: flex; flex-direction: column; min-width: 0; }
.brand h1 { margin: 0; font-size: 17px; font-weight: 700; }
.brand small { color: var(--muted); font-size: 12px; }
.seg { display: flex; border: 1px solid var(--line); border-radius: 999px; padding: 2px; }
.seg button { border: 0; background: none; border-radius: 999px; padding: 4px 11px; cursor: pointer; font-weight: 600; color: var(--muted); }
.seg button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }
.years { min-width: 0; flex: 0 1 auto; display: flex; gap: 4px; overflow-x: auto; padding-block: 2px; }
.years button { border: 1px solid var(--line); background: transparent; border-radius: 999px; padding: 4px 10px; cursor: pointer; font-weight: 600; white-space: nowrap; font-variant-numeric: tabular-nums; }
.years button[aria-pressed="true"] { background: var(--fg); color: var(--bg); border-color: var(--fg); }
.status { margin-left: auto; font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.status::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.status[data-state="ok"]::before { background: var(--ok); }
.status[data-state="warn"]::before { background: var(--warn); }
.status[data-state="err"]::before { background: var(--danger); }
.iconbtn { border: 1px solid var(--line); background: none; border-radius: 8px; width: 36px; height: 34px; cursor: pointer; font-size: 17px; }
.menu { position: absolute; z-index: 1200; top: calc(100% + 4px); right: max(14px, env(safe-area-inset-right, 0px)); width: min(320px, calc(100vw - 28px));
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 6px; display: grid; box-shadow: 0 8px 24px rgba(0,0,0,.18); }
.menuitem { display: flex; gap: 8px; align-items: center; text-align: left; border: 0; background: none; padding: 10px; border-radius: 7px; cursor: pointer; }
.menuitem:hover { background: var(--bg); }
.menunote { margin: 4px 10px 6px; color: var(--muted); font-size: 12px; }

.main { display: grid; grid-template-columns: minmax(0, 1fr) 410px; min-height: 0; }
.mapwrap { position: relative; min-height: 0; }
#map { position: absolute; inset: 0; background: var(--map-bg); }
.panel { background: var(--surface); border-left: 1px solid var(--line); overflow-y: auto; min-height: 0; min-width: 0;
  padding-block: 14px 28px; padding-left: 18px; padding-right: max(18px, env(safe-area-inset-right, 0px)); }
@media (max-width: 760px) {
  .main { grid-template-columns: minmax(0, 1fr); grid-template-rows: 55% 45%; }
  .panel { border-left: 0; border-top: 1px solid var(--line); padding-left: max(14px, env(safe-area-inset-left, 0px)); padding-right: max(14px, env(safe-area-inset-right, 0px)); }
  .years { flex-basis: 100%; order: 5; }
  .status { margin-left: auto; }
}

/* map */
.leaflet-container { font-family: var(--font); background: var(--map-bg); }
.flabel { background: transparent; border: 0; box-shadow: none; padding: 0; color: #fff; font-weight: 700; font-size: 11px;
  text-shadow: 0 0 3px #000, 0 0 3px #000, 0 0 2px #000; white-space: nowrap; }
.flabel::before { display: none; }
.lowzoom .flabel { display: none; }
.legend { position: absolute; z-index: 500; left: max(10px, env(safe-area-inset-left, 0px)); bottom: 10px; max-width: calc(100% - 20px);
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 12px; }
.legend span { display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; }
.legend .ramp { width: 120px; height: 10px; border-radius: 3px; }
.sw { width: 11px; height: 11px; border-radius: 3px; display: inline-block; border: 1px solid rgba(0,0,0,.2); flex: none; }
.locbtn a { font-size: 18px; line-height: 30px !important; }
.locbtn a.on { color: #1a73e8 !important; }
.here { position: absolute; z-index: 600; top: 10px; left: 50%; transform: translateX(-50%); max-width: calc(100% - 120px);
  background: #1a73e8; color: #fff; border: 0; border-radius: 999px; padding: 7px 14px; font-weight: 600; cursor: pointer; box-shadow: 0 2px 8px rgba(0,0,0,.3);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.drawbar { position: absolute; z-index: 700; top: 10px; left: 50%; transform: translateX(-50%); width: min(94%, 560px);
  background: var(--fg); color: var(--bg); border-radius: 10px; padding: 10px 12px; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.drawbar p { margin: 0; flex: 1 1 100%; font-size: 13px; }
.drawbar button { border: 0; border-radius: 6px; padding: 7px 12px; cursor: pointer; font-weight: 600; }
.drawbar .ok { background: var(--accent); color: var(--accent-ink); }
.drawbar .ok:disabled { opacity: .5; cursor: default; }
.drawbar .cancel { background: transparent; color: var(--bg); border: 1px solid currentColor; }
.drawing #map { cursor: crosshair; }

/* panel */
.banner { border: 1px solid var(--warn); color: var(--warn); border-radius: 8px; padding: 8px 10px; font-size: 12.5px; margin-bottom: 12px; }
.h2 { font-size: 16px; font-weight: 700; margin: 0 0 2px; }
.eyebrow { text-transform: uppercase; letter-spacing: .08em; font-size: 11px; color: var(--muted); font-weight: 700; margin: 18px 0 8px; }
.sub { color: var(--muted); margin: 0; font-size: 13px; }
.bars { display: grid; gap: 6px; }
.bar { display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; font-size: 13px; }
.bar .track { grid-column: 1 / -1; height: 6px; background: var(--bg); border-radius: 3px; overflow: hidden; }
.bar .fill { height: 100%; border-radius: 3px; }
.search { width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }
.flist { list-style: none; margin: 8px 0 0; padding: 0; }
.flist button { width: 100%; min-width: 0; display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 8px; text-align: left;
  border: 0; border-bottom: 1px solid var(--line); background: none; padding: 9px 2px; cursor: pointer; }
.flist button:hover { background: var(--bg); }
.flist .meta { color: var(--muted); font-size: 12px; display: flex; gap: 8px; align-items: center; justify-content: flex-end; }
.chip { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; color: var(--fg); }
.fhead { display: flex; align-items: flex-start; gap: 10px; }
.fhead > div { flex: 1; min-width: 0; }
.close { border: 1px solid var(--line); background: none; border-radius: 6px; padding: 5px 10px; cursor: pointer; color: var(--muted); white-space: nowrap; }
.tabs { display: flex; gap: 2px; margin: 12px 0; border-bottom: 1px solid var(--line); overflow-x: auto; }
.tabs button { border: 0; background: none; padding: 8px 9px; cursor: pointer; color: var(--muted); font-weight: 600; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs button[aria-selected="true"] { color: var(--fg); border-bottom-color: var(--accent); }
.tabs .cnt { font-size: 11px; color: var(--muted); margin-left: 3px; font-weight: 500; }
.yrows { display: grid; gap: 6px; }
.yrow { display: grid; grid-template-columns: 44px 1fr 92px; gap: 6px; align-items: center; }
.yrow.cur .y { color: var(--accent); }
.y { font-weight: 700; font-variant-numeric: tabular-nums; }
.in { width: 100%; min-width: 0; padding: 8px 9px; border: 1px solid var(--line); border-radius: 7px; background: var(--bg); }
textarea.in { resize: vertical; min-height: 64px; }
.hint { font-size: 12px; color: var(--muted); margin: 6px 0 0; }
.form { display: grid; gap: 6px; padding: 10px; border: 1px solid var(--line); border-radius: 9px; background: var(--bg); }
.form .row { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.form .in { background: var(--surface); }
.btn { border: 0; border-radius: 7px; padding: 9px 13px; cursor: pointer; font-weight: 700; background: var(--accent); color: var(--accent-ink); justify-self: start; }
.items { list-style: none; padding: 0; margin: 12px 0 0; }
.items li { border-bottom: 1px solid var(--line); padding: 10px 0; display: grid; gap: 4px; }
.items .top { display: flex; gap: 8px; align-items: baseline; }
.items .top b { font-weight: 700; }
.items .when { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.items .del { margin-left: auto; border: 0; background: none; color: var(--muted); cursor: pointer; font-size: 12px; padding: 2px 4px; }
.items .del.arm { color: var(--danger); font-weight: 700; }
.items p { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.by { color: var(--muted); font-size: 11px; }
.empty { color: var(--muted); font-size: 13px; padding: 10px 0; }

/* rain */
.rainctl { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-bottom: 10px; }
.rainctl .in { width: auto; flex: 1 1 130px; }
.chart { width: 100%; height: auto; display: block; }
.chart text { fill: var(--muted); font-size: 10px; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .bar { fill: var(--rain); }
.kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 10px 0; }
.kpi { border: 1px solid var(--line); border-radius: 8px; padding: 8px; }
.kpi b { display: block; font-size: 17px; font-variant-numeric: tabular-nums; }
.kpi span { color: var(--muted); font-size: 11.5px; }
table.t { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
table.t th { text-align: left; color: var(--muted); font-weight: 600; font-size: 11.5px; padding: 6px 4px; border-bottom: 1px solid var(--line); }
table.t td { padding: 6px 4px; border-bottom: 1px solid var(--line); }
table.t td.r, table.t th.r { text-align: right; }
.tablewrap { overflow-x: auto; }

/* login */
.login { position: fixed; inset: 0; z-index: 2000; background: var(--bg); display: grid; place-items: center; padding: 16px; }
.loginbox { width: min(340px, 100%); display: grid; gap: 8px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 22px; }
.loginbox h2 { margin: 0 0 6px; }
.loginbox label { font-size: 12px; color: var(--muted); }
.loginbox .btn { justify-self: stretch; margin-top: 6px; }
.err { color: var(--danger); margin: 0; font-size: 13px; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
