:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f1f0ec;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #76746e;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --accent: #b8431a;
  --bar: #e79556;
  --accent-ink: #ffffff;
  --focus: #2a78d6;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #eda100;
  --series-5: #e87ba4;
  --ink-line: #0b0b0b;
  --good: #0ca30c;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  --nodata: #ecebe6;
  --shadow: 0 1px 2px rgba(11, 11, 11, 0.05);
  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --surface-2: #252523;
    --text: #f0efec;
    --text-2: #c3c2b7;
    --muted: #96948d;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --accent: #ec7f3d;
    --bar: #9a4a22;
    --accent-ink: #0b0b0b;
    --focus: #6da7ec;
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #c98500;
    --series-5: #d55181;
    --ink-line: #f0efec;
    --nodata: #222220;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --surface-2: #252523;
  --text: #f0efec;
  --text-2: #c3c2b7;
  --muted: #96948d;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.10);
  --accent: #ec7f3d;
  --bar: #9a4a22;
  --accent-ink: #0b0b0b;
  --focus: #6da7ec;
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --series-4: #c98500;
  --series-5: #d55181;
  --ink-line: #f0efec;
  --nodata: #222220;
  --shadow: none;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--page);
  color: var(--text);
  font: 15px/1.45 var(--font);
}
h1, h2, h3, p { margin: 0; }
h1 { font-size: 20px; font-weight: 650; letter-spacing: -0.01em; }
h2 { font-size: 16px; font-weight: 650; }
h3 { font-size: 13.5px; font-weight: 600; color: var(--text-2); margin-bottom: 6px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.skip { position: absolute; left: -999px; top: 8px; background: var(--surface); padding: 8px 12px; border-radius: 6px; z-index: 2000; }
.skip:focus { left: 8px; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

.top {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 14px 24px; border-bottom: 1px solid var(--border); background: var(--surface);
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand p { color: var(--muted); font-size: 13px; }
.logo { width: 32px; height: 32px; color: var(--text-2); flex: none; }
.logo .l1 { fill: #f6c08a; } .logo .l2 { fill: #ec8a3a; } .logo .l3 { fill: #c4501b; } .logo .l4 { fill: #7c2410; }
.top-right { display: flex; align-items: center; gap: 12px; }

main { max-width: 1360px; margin: 0 auto; padding: 20px 24px 8px; display: grid; gap: 18px; }
.foot { max-width: 1360px; margin: 0 auto; padding: 8px 24px 28px; }

button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
button.primary {
  background: var(--accent); color: var(--accent-ink); border: 0; border-radius: 8px;
  padding: 10px 16px; font-weight: 600; width: 100%;
}
button.primary:disabled { opacity: 0.45; cursor: not-allowed; }
button.ghost {
  background: transparent; border: 1px solid var(--border); border-radius: 8px; padding: 6px 12px; color: var(--text-2);
}
button.ghost:hover, .chip:hover { background: var(--surface-2); }
button.ghost.icon { padding: 4px 10px; font-size: 16px; line-height: 1.2; }
input, select {
  background: var(--surface); border: 1px solid var(--axis); border-radius: 8px; padding: 7px 10px; min-width: 0;
}
.chip {
  background: transparent; border: 1px solid var(--border); border-radius: 999px; padding: 4px 12px;
  font-size: 12.5px; color: var(--text-2);
}
.chip.on { background: var(--surface-2); color: var(--text); border-color: var(--axis); font-weight: 600; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }

/* -- area selection ----------------------------------------------------------- */
.select { display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(300px, 1fr); gap: 18px; align-items: stretch; }
.map-wrap { position: relative; border: 1px solid var(--border); border-radius: 12px; overflow: hidden; min-height: 460px; background: var(--surface-2); }
#map { position: absolute; inset: 0; }
.map-legend {
  position: absolute; left: 10px; bottom: 22px; z-index: 500; background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; font-size: 12px; max-width: 250px; box-shadow: var(--shadow);
}
.panel {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 18px;
  display: flex; flex-direction: column; gap: 12px; box-shadow: var(--shadow);
}
.panel h2 { margin-top: 2px; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; color: var(--text-2); }
.field.inline { flex-direction: row; align-items: center; gap: 8px; }
.coords { border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px 12px; margin: 0;
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)) auto; gap: 8px; align-items: end; }
.coords legend { font-size: 12.5px; color: var(--text-2); padding: 0 4px; }
.coords label { display: flex; flex-direction: column; gap: 3px; font-size: 11.5px; color: var(--muted); }
.coords input { padding: 6px 8px; width: 100%; }
.aoi-summary { background: var(--surface-2); border-radius: 10px; padding: 10px 12px; display: grid; gap: 4px; }
.progress .bar { height: 8px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.progress #progress-fill { height: 100%; width: 0; background: var(--accent); border-radius: 999px; transition: width 0.3s; }
.progress p { margin-top: 6px; color: var(--text-2); }
.progress-actions { display: flex; gap: 8px; margin-top: 8px; }
.progress-actions .primary { width: auto; }
.error { color: var(--critical); font-size: 13px; }

/* -- results ------------------------------------------------------------------ */
#results { display: grid; gap: 18px; }
#results.loading > *:not(.filters) { opacity: 0.55; transition: opacity 0.15s; }
.filters {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; padding: 10px 14px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
}
.presets { display: flex; gap: 6px; flex-wrap: wrap; }
.check { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-2); }
.check input { width: 16px; height: 16px; padding: 0; accent-color: var(--accent); }
.notes:empty { display: none; }
.notes { display: grid; gap: 6px; }
.note { background: var(--surface); border: 1px solid var(--border); border-left: 3px solid var(--warning);
  border-radius: 8px; padding: 8px 12px; font-size: 13px; color: var(--text-2); }

.tiles { display: grid; grid-template-columns: 1.35fr repeat(4, minmax(0, 1fr)); gap: 12px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px; box-shadow: var(--shadow); min-width: 0; }
.tile .label { font-size: 12.5px; color: var(--muted); }
.tile .value { font-size: 26px; font-weight: 650; letter-spacing: -0.02em; margin: 2px 0; line-height: 1.15; }
.tile.hero .value { font-size: 48px; }
.tile .detail { font-size: 12.5px; color: var(--text-2); }
.status { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; font-size: 13px; margin-top: 4px; }
.status svg { width: 14px; height: 14px; flex: none; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 16px 18px; box-shadow: var(--shadow); min-width: 0; }
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.card-tools { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.seg button { background: transparent; border: 0; padding: 6px 12px; font-size: 13px; color: var(--text-2); }
.seg button + button { border-left: 1px solid var(--border); }
.seg button.on { background: var(--surface-2); color: var(--text); font-weight: 600; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.grid2.inner { gap: 24px; }
.chart { position: relative; width: 100%; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart text { font-family: var(--font); }
.legend-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 16px; margin-top: 10px; font-size: 12.5px; color: var(--text-2); }
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.swatch { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
.swatch.line { width: 16px; height: 0; border-top: 2px solid; border-radius: 0; }
.swatch.band { width: 16px; height: 10px; opacity: 0.25; border-radius: 2px; }
.ramp { display: inline-flex; flex-direction: column; gap: 2px; }
.ramp canvas { width: 220px; height: 10px; border-radius: 3px; display: block; }
.ramp .ticks { position: relative; height: 14px; width: 220px; font-size: 11px; color: var(--muted); }
.ramp .ticks span { position: absolute; transform: translateX(-50%); white-space: nowrap; }
.ramp .ticks span:first-child { transform: none; }
.ramp .ticks span:last-child { transform: translateX(-100%); }
.hatch { background: repeating-linear-gradient(45deg, var(--nodata), var(--nodata) 3px, var(--surface) 3px, var(--surface) 6px); border: 1px solid var(--border); }

/* -- calendar ----------------------------------------------------------------- */
.calendar-scroll { overflow-x: auto; }
table.cal { border-collapse: separate; border-spacing: 2px; width: 100%; min-width: 720px; table-layout: fixed; font-variant-numeric: tabular-nums; }
table.cal th { font-size: 12px; font-weight: 500; color: var(--muted); padding: 2px 4px; text-align: center; }
table.cal th.yr { text-align: right; width: 52px; padding-right: 8px; font-variant-numeric: tabular-nums; }
table.cal th.yr button { background: none; border: 0; padding: 0; color: inherit; font: inherit; }
table.cal th.yr button:hover { color: var(--text); text-decoration: underline; }
table.cal tr.sel th.yr { color: var(--text); font-weight: 700; }
table.cal col.total { width: 150px; }
table.cal td { height: 22px; padding: 0; border-radius: 4px; text-align: center; font-size: 11px; position: relative; }
table.cal td.cell { cursor: pointer; }
table.cal td.cell:hover, table.cal td.cell:focus-visible { outline: 2px solid var(--text); outline-offset: 0; z-index: 1; }
table.cal td.cell.focus { outline: 2px solid var(--text); outline-offset: 0; }
table.cal td.nodata { background: repeating-linear-gradient(45deg, var(--nodata), var(--nodata) 3px, transparent 3px, transparent 6px); }
table.cal td.partial::after {
  content: ""; position: absolute; right: 2px; top: 2px; width: 6px; height: 6px; border-radius: 50%;
  background: var(--surface); border: 1.5px solid var(--text);
}
table.cal td.total { text-align: left; padding-left: 6px; }
table.cal td.total .tbar { display: inline-block; height: 10px; border-radius: 0 4px 4px 0; background: var(--text-2); vertical-align: middle; opacity: 0.55; }
table.cal td.total .tnum { margin-left: 6px; color: var(--text-2); font-size: 11.5px; vertical-align: middle; }
table.cal tr.sel td.total .tbar { opacity: 1; background: var(--accent); }
table.cal tr.era td { height: auto; font-size: 11px; color: var(--muted); text-align: left; padding: 3px 0 3px 2px; border-top: 1px solid var(--axis); border-radius: 0; }
table.cal tfoot th.yr, table.cal tfoot td { font-weight: 600; }
table.cal tfoot tr:first-child td, table.cal tfoot tr:first-child th { border-top: 6px solid transparent; }

/* -- daily calendar ------------------------------------------------------------- */
table.daily { border-collapse: separate; border-spacing: 2px; width: 100%; table-layout: fixed; }
table.daily th { font-size: 11px; font-weight: 500; color: var(--muted); padding: 0; text-align: center; }
table.daily th.mo { text-align: right; padding-right: 6px; width: 34px; }
table.daily td { height: 17px; padding: 0; border-radius: 3px; }
table.daily td.cell:hover { outline: 2px solid var(--text); }
table.daily td.void { background: transparent; }

/* -- tables / method ------------------------------------------------------------ */
.table-wrap { overflow-x: auto; margin-top: 16px; }
table.data { border-collapse: collapse; width: 100%; font-size: 13px; }
table.data th, table.data td { text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--grid); white-space: nowrap; }
table.data th { color: var(--muted); font-weight: 500; font-size: 12px; }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; }
.method { margin-top: 14px; font-size: 13.5px; color: var(--text-2); }
.method summary { cursor: pointer; font-weight: 600; color: var(--text); }
.method ol { padding-left: 20px; display: grid; gap: 6px; max-width: 86ch; }

.tooltip {
  position: fixed; z-index: 3000; pointer-events: none; background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; font-size: 12.5px; max-width: 280px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.18);
}
.tooltip .tt-title { color: var(--text-2); font-size: 12px; margin-bottom: 2px; }
.tooltip .tt-value { font-weight: 650; font-size: 15px; }
.tooltip .tt-row { display: flex; align-items: center; gap: 6px; }
.tooltip .tt-row b { font-weight: 650; }
.tooltip .tt-key { width: 12px; height: 0; border-top: 2px solid; flex: none; }
.tooltip .tt-note { color: var(--muted); font-size: 12px; }

.leaflet-container { font-family: var(--font); background: var(--surface-2); }
.density-overlay { image-rendering: pixelated; }

@media (max-width: 1100px) {
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .tile.hero { grid-column: 1 / -1; }
}
@media (max-width: 900px) {
  .select, .grid2 { grid-template-columns: minmax(0, 1fr); }
  .map-wrap { min-height: 360px; }
  main { padding: 14px 16px 8px; }
  .top { padding: 12px 16px; }
  .brand p { display: none; }
}
@media (max-width: 560px) {
  .tiles { grid-template-columns: minmax(0, 1fr); }
  .coords { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .coords button { grid-column: 1 / -1; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
@media print {
  .select, .filters, .card-tools, .top-right, .skip { display: none !important; }
  body { background: #fff; }
}

/* `hidden` must win over any display rule above. */
[hidden] { display: none !important; }
