:root {
  color-scheme: light;
  --ink: #17211b;
  --muted: #5b665f;
  --line: #cdd5cf;
  --surface: #ffffff;
  --surface-soft: #edf2ee;
  --page: #f5f7f4;
  --green: #176b45;
  --green-dark: #105236;
  --red: #ef233c;
  --amber: #d97706;
  --sidebar-width: 286px;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--page);
}
button, input, select { font: inherit; }
button { cursor: pointer; }

.topbar {
  height: 64px;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 22px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 1200;
}
.brand-block { display: flex; flex-direction: column; min-width: 180px; }
.brand-block strong { font-size: 16px; }
.brand-block span { color: var(--muted); font-size: 12px; }
.run-badge {
  padding: 5px 8px;
  border: 1px solid #a9cdb8;
  border-radius: 4px;
  color: var(--green-dark);
  background: #dcefe4;
  font-size: 12px;
  font-weight: 800;
}
.header-status { margin-left: auto; display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 13px; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--amber); }
.status-dot.ready { background: var(--green); }
.status-dot.error { background: var(--red); }
.icon-button {
  width: 36px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--surface);
  color: var(--ink);
  display: none;
}

.workspace { display: grid; grid-template-columns: var(--sidebar-width) minmax(0, 1fr); min-height: calc(100vh - 64px); }
.sidebar {
  border-right: 1px solid var(--line);
  background: var(--surface-soft);
  padding: 18px;
  overflow-y: auto;
  max-height: calc(100vh - 64px);
  position: sticky;
  top: 64px;
}
.sidebar section { padding: 0 0 18px; margin: 0 0 18px; border-bottom: 1px solid var(--line); }
.sidebar section:last-child { border: 0; }
.sidebar h2, .data-band h2 { font-size: 14px; margin: 0 0 12px; letter-spacing: 0; }
.control-label, fieldset legend { display: block; color: var(--muted); font-size: 12px; font-weight: 700; margin: 12px 0 7px; }
fieldset { border: 0; padding: 0; margin: 0; }
fieldset label { display: flex; align-items: center; gap: 7px; padding: 4px 0; font-size: 13px; }
input[type="checkbox"] { accent-color: var(--green); }
.text-input, .select-input {
  width: 100%;
  min-height: 38px;
  padding: 8px 10px;
  border: 1px solid #bfc9c1;
  border-radius: 5px;
  background: var(--surface);
  color: var(--ink);
}
.range-input { width: 100%; accent-color: var(--green); }
.toggle-row { display: flex; gap: 8px; align-items: center; margin-top: 12px; font-size: 13px; }
.export-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
.export-grid button {
  min-height: 36px;
  border: 1px solid #9fb0a4;
  border-radius: 5px;
  background: var(--surface);
  color: var(--green-dark);
  font-weight: 700;
}
.export-grid button:last-child { grid-column: 1 / -1; }
.export-grid button:hover { background: #e0eee5; }

.histogram { height: 126px; display: flex; align-items: end; gap: 3px; padding-top: 10px; border-bottom: 1px solid #8e9c92; }
.histogram-bar { flex: 1; min-width: 2px; background: var(--green); opacity: .84; position: relative; }
.histogram-bar:hover { opacity: 1; }
.histogram-bar span {
  display: none;
  position: absolute;
  left: 50%;
  bottom: calc(100% + 5px);
  transform: translateX(-50%);
  padding: 3px 5px;
  background: #17211be8;
  color: white;
  font-size: 10px;
  white-space: nowrap;
  border-radius: 3px;
  z-index: 2;
}
.histogram-bar:hover span { display: block; }

.main-content { min-width: 0; }
.summary-band { padding: 18px 22px; display: flex; align-items: center; gap: 28px; background: var(--surface); border-bottom: 1px solid var(--line); }
.title-block { min-width: 310px; }
.title-block h1 { font-size: 22px; margin: 0 0 5px; letter-spacing: 0; }
.title-block p, .section-heading p { margin: 0; color: var(--muted); font-size: 13px; }
.metrics { flex: 1; display: grid; grid-template-columns: repeat(4, minmax(110px, 1fr)); border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.metrics div { padding: 10px 13px; background: #fbfcfb; border-right: 1px solid var(--line); }
.metrics div:last-child { border: 0; }
.metrics span { display: block; font-size: 11px; color: var(--muted); margin-bottom: 4px; }
.metrics strong { font-size: 17px; }

.map-section { height: min(68vh, 720px); min-height: 520px; position: relative; background: #dbe1dc; border-bottom: 1px solid var(--line); }
#map { width: 100%; height: 100%; }
.north-arrow {
  position: absolute;
  right: 14px;
  bottom: 88px;
  z-index: 700;
  width: 42px;
  height: 58px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: #fffffff2;
  border: 1px solid #2e3831;
  border-radius: 4px;
  box-shadow: 0 1px 4px #0004;
  font-size: 13px;
}
.north-arrow span { font-size: 23px; line-height: 24px; }
.map-legend {
  position: absolute;
  left: 12px;
  bottom: 58px;
  z-index: 700;
  min-width: 176px;
  padding: 9px 11px;
  background: #fffffff2;
  border: 1px solid #9aa39d;
  border-radius: 4px;
  box-shadow: 0 1px 4px #0003;
  font-size: 12px;
}
.map-legend strong { display: block; margin-bottom: 5px; }
.legend-row { display: flex; align-items: center; gap: 7px; margin: 4px 0; }
.legend-swatch { width: 17px; height: 9px; border: 1px solid #555; }
.map-legend small { display: block; margin-top: 6px; color: var(--muted); }
.coordinates {
  position: absolute;
  right: 66px;
  bottom: 8px;
  z-index: 700;
  padding: 4px 6px;
  border-radius: 3px;
  background: #ffffffe6;
  color: #39433c;
  font: 11px ui-monospace, SFMono-Regular, Menlo, monospace;
}
.leaflet-popup-content { margin: 14px 16px; min-width: 230px; }
.popup-title { font-weight: 800; font-size: 15px; margin-bottom: 8px; }
.popup-grid { display: grid; grid-template-columns: 1fr auto; gap: 5px 12px; font-size: 12px; }
.popup-grid b { text-align: right; }
.maps-link { display: block; margin-top: 11px; padding: 8px; text-align: center; color: white !important; background: var(--green); border-radius: 4px; font-weight: 800; text-decoration: none; }

.data-band { background: var(--surface); padding: 18px 22px 28px; }
.section-heading { display: flex; justify-content: space-between; align-items: end; margin-bottom: 12px; }
.section-heading h2 { margin-bottom: 3px; }
#table-count { color: var(--muted); font-size: 12px; }
.table-wrap { overflow: auto; max-height: 310px; border: 1px solid var(--line); border-radius: 5px; }
table { width: 100%; border-collapse: collapse; font-size: 12px; }
th { position: sticky; top: 0; background: #e8ede9; text-align: left; color: #48534b; padding: 9px 11px; border-bottom: 1px solid var(--line); }
td { padding: 9px 11px; border-bottom: 1px solid #e1e6e2; white-space: nowrap; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: #edf6f0; }
td a { color: var(--green-dark); font-weight: 700; }

.loading { position: fixed; inset: 0; z-index: 3000; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 13px; background: #f5f7f4f2; }
.loading.hidden { display: none; }
.loader { width: 34px; height: 34px; border: 3px solid #c9d4cc; border-top-color: var(--green); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.toast { position: fixed; right: 18px; bottom: 18px; z-index: 2500; padding: 10px 13px; background: #17211bee; color: white; border-radius: 5px; transform: translateY(90px); transition: transform .2s ease; font-size: 13px; }
.toast.visible { transform: translateY(0); }

@media (max-width: 980px) {
  .summary-band { align-items: stretch; flex-direction: column; gap: 14px; }
  .metrics { width: 100%; }
}

@media (max-width: 760px) {
  .topbar { height: 58px; padding: 0 12px; gap: 9px; }
  .icon-button { display: inline-grid; place-items: center; }
  .brand-block { min-width: 0; }
  .brand-block span, .header-status span:last-child { display: none; }
  .workspace { display: block; min-height: calc(100vh - 58px); }
  .sidebar { position: fixed; top: 58px; bottom: 0; left: 0; z-index: 1600; width: min(310px, 88vw); max-height: none; transform: translateX(-102%); transition: transform .2s ease; box-shadow: 8px 0 22px #0002; }
  .sidebar.open { transform: translateX(0); }
  .summary-band, .data-band { padding-left: 14px; padding-right: 14px; }
  .title-block { min-width: 0; }
  .title-block h1 { font-size: 19px; }
  .metrics { grid-template-columns: 1fr 1fr; }
  .metrics div:nth-child(2) { border-right: 0; }
  .metrics div:nth-child(-n+2) { border-bottom: 1px solid var(--line); }
  .map-section { height: 64vh; min-height: 460px; }
  .map-legend { bottom: 54px; max-width: 165px; }
  .coordinates { display: none; }
  .north-arrow { bottom: 72px; }
  th, td { padding: 8px; }
}
