:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --ink: #1d232b;
  --muted: #5f6b7a;
  --line: #dfe3e8;
  --accent: #0b6fb8;
  --accent-ink: #ffffff;
  --good: #2e9e5b;
  --warn: #d98e04;
  --bad: #c9403a;
  --shadow: 0 2px 10px rgba(20, 30, 40, 0.14);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; font-family: var(--font); color: var(--ink); background: var(--bg); font-size: 14px; }
#app { display: grid; grid-template-rows: 56px 1fr; grid-template-columns: 380px 1fr; height: 100vh; }
#topbar { grid-column: 1 / -1; display: flex; align-items: center; gap: 14px; padding: 0 14px; background: var(--panel); border-bottom: 1px solid var(--line); z-index: 1200; }
#title h1 { font-size: 16px; margin: 0; line-height: 1.15; }
#title .sub { font-size: 12px; color: var(--muted); }
.icon-btn { border: 1px solid var(--line); background: var(--panel); border-radius: 6px; width: 34px; height: 34px; font-size: 18px; cursor: pointer; }
#search-wrap { position: relative; margin-left: auto; width: 320px; }
#search { width: 100%; height: 34px; border: 1px solid var(--line); border-radius: 6px; padding: 0 10px; font: inherit; }
#search-results { position: absolute; top: 36px; left: 0; right: 0; margin: 0; padding: 4px 0; list-style: none; background: var(--panel); border: 1px solid var(--line); border-radius: 6px; box-shadow: var(--shadow); max-height: 320px; overflow: auto; z-index: 1300; }
#search-results li { padding: 6px 10px; cursor: pointer; display: flex; justify-content: space-between; gap: 8px; }
#search-results li:hover { background: #eef4fa; }
#search-results .kind { color: var(--muted); font-size: 12px; }
#basemaps { display: flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
#basemaps button { border: 0; background: var(--panel); padding: 8px 10px; cursor: pointer; font: inherit; font-size: 13px; border-left: 1px solid var(--line); }
#basemaps button:first-child { border-left: 0; }
#basemaps button.active { background: var(--accent); color: var(--accent-ink); }

#panel { background: var(--panel); border-right: 1px solid var(--line); overflow: hidden; display: flex; flex-direction: column; z-index: 1100; }
#panel.hidden { display: none; }
#app.panel-hidden { grid-template-columns: 0 1fr; }
#tabs { display: flex; border-bottom: 1px solid var(--line); }
#tabs button { flex: 1; border: 0; background: transparent; padding: 10px 4px; cursor: pointer; font: inherit; font-size: 13px; color: var(--muted); border-bottom: 2px solid transparent; }
#tabs button.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.tab { display: none; padding: 12px 14px; overflow: auto; flex: 1; }
.tab.active { display: block; }
.hint { color: var(--muted); font-size: 12.5px; margin: 4px 0 10px; }
h3 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); margin: 16px 0 6px; }
.tab p, .tab li { line-height: 1.45; }
code { background: #eef1f4; padding: 1px 4px; border-radius: 3px; font-size: 12px; }

/* layers */
.lgroup { margin-bottom: 10px; }
.lgroup > .ghead { font-weight: 600; font-size: 12.5px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; margin: 10px 0 4px; }
.litem { display: flex; align-items: center; gap: 8px; padding: 5px 4px; border-radius: 6px; }
.litem:hover { background: #f2f5f8; }
.litem input[type="checkbox"] { width: 16px; height: 16px; margin: 0; accent-color: var(--accent); }
.litem .sw { width: 22px; height: 12px; border-radius: 3px; flex: none; border: 1px solid rgba(0,0,0,0.15); }
.litem .sw.line { height: 4px; border-radius: 2px; border: 0; }
.litem .sw.dash { height: 0; border: 0; border-top: 3px dashed; background: none !important; }
.litem .sw.dot { width: 12px; height: 12px; border-radius: 50%; margin: 0 5px; }
.litem .sw.ramp { border: 0; }
.litem label { flex: 1; cursor: pointer; }
.litem .cnt { color: var(--muted); font-size: 11.5px; }
.litem input[type="range"] { width: 70px; }
.sub-items { margin-left: 26px; }
.sub-items .litem { padding: 3px 4px; font-size: 13px; }

/* site result */
#site-result.empty { color: var(--muted); font-style: italic; padding: 8px 0; }
.score-hero { display: flex; align-items: center; gap: 14px; margin: 8px 0 12px; }
.score-ring { width: 64px; height: 64px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: 20px; color: #fff; flex: none; }
.score-hero .loc { font-size: 13px; }
.score-hero .loc b { font-size: 15px; }
.metrics { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.metrics td { padding: 4px 4px; border-bottom: 1px solid var(--line); vertical-align: top; }
.metrics td:first-child { color: var(--muted); white-space: nowrap; }
.metrics td:last-child { text-align: right; white-space: nowrap; }
.metrics .sub { color: var(--muted); font-size: 11.5px; display: block; }
.bar { height: 6px; border-radius: 3px; background: #e6eaef; overflow: hidden; margin-top: 3px; }
.bar > i { display: block; height: 100%; background: var(--accent); }

#presets { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0 10px; }
#presets button, .small { border: 1px solid var(--line); background: var(--panel); border-radius: 14px; padding: 4px 10px; font: inherit; font-size: 12px; cursor: pointer; }
#presets button.active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.wrow { display: grid; grid-template-columns: 1fr 90px 44px; align-items: center; gap: 8px; padding: 4px 0; font-size: 12.5px; }
.wrow .dmax { font-size: 11px; color: var(--muted); }
.wrow .dmax input { width: 48px; font: inherit; font-size: 11px; border: 1px solid var(--line); border-radius: 4px; padding: 1px 3px; }
.wrow input[type="range"] { width: 100%; accent-color: var(--accent); }
.wrow .wv { text-align: right; font-variant-numeric: tabular-nums; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 8px 0; font-size: 12.5px; }
.row select { font: inherit; font-size: 12.5px; border: 1px solid var(--line); border-radius: 4px; padding: 3px; }
.chk { display: flex; align-items: center; gap: 6px; cursor: pointer; }

/* overlap analysis */
.orow { display: grid; grid-template-columns: 16px 1fr 64px auto; align-items: center; gap: 6px; padding: 4px 0; font-size: 12.5px; border-bottom: 1px solid var(--line); }
.orow input[type="checkbox"] { width: 16px; height: 16px; margin: 0; accent-color: var(--accent); }
.orow input[type="number"] { width: 64px; font: inherit; font-size: 12px; border: 1px solid var(--line); border-radius: 4px; padding: 2px 4px; text-align: right; }
.orow .unit { color: var(--muted); font-size: 11.5px; white-space: nowrap; }
.orow.disabled { opacity: 0.5; }
.orow label { cursor: pointer; }
#zone-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
#zone-table th { text-align: left; color: var(--muted); font-weight: 600; padding: 4px; border-bottom: 1px solid var(--line); }
#zone-table td { padding: 4px; border-bottom: 1px solid var(--line); vertical-align: top; }
#zone-table tbody tr[data-i] { cursor: pointer; }
#zone-table tbody tr[data-i]:hover { background: #eef4fa; }
#zone-table td.sc { font-weight: 600; text-align: right; font-variant-numeric: tabular-nums; }
#zone-table .sub { display: block; color: var(--muted); font-size: 11.5px; }
#zone-sums a { color: var(--accent); text-decoration: none; }
#zone-sums a:hover { text-decoration: underline; }
.overlap-pass { font-size: 12.5px; margin: 0 0 10px; padding: 8px 10px; border-radius: 6px; background: #f3f5f7; border-left: 4px solid #b9c2cc; }
.overlap-pass.near { border-left-color: #e8aa1e; }
.overlap-pass.all { border-left-color: var(--good); background: #edf7f0; }
.overlap-pass .chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.chip { font-size: 11px; padding: 1px 6px; border-radius: 10px; background: #e6eaef; color: var(--muted); }
.chip.ok { background: #d9efe1; color: #1e6b3d; }
.chip.no { background: #f6dedc; color: #9b2f2a; }

#rank-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
#rank-table th { text-align: left; color: var(--muted); font-weight: 600; padding: 4px; border-bottom: 1px solid var(--line); }
#rank-table td { padding: 4px; border-bottom: 1px solid var(--line); }
#rank-table tbody tr { cursor: pointer; }
#rank-table tbody tr:hover { background: #eef4fa; }
#rank-table td.sc { font-weight: 600; text-align: right; font-variant-numeric: tabular-nums; }

#map { background: #dfe8ef; }
.leaflet-container { font: inherit; }
.leaflet-popup-content { font-size: 12.5px; line-height: 1.4; margin: 10px 12px; }
.leaflet-popup-content h4 { margin: 0 0 4px; font-size: 13.5px; }
.leaflet-popup-content .kv { color: var(--muted); }
.aimag-label { font-size: 10.5px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: #6b7785; text-shadow: 0 0 3px #fff, 0 0 3px #fff, 0 0 3px #fff; white-space: nowrap; pointer-events: none; transform: translate(-50%, -50%); }
.aimag-label.dark { color: #c9d3dc; text-shadow: 0 0 3px #000, 0 0 3px #000; }
.leaflet-tooltip.city-label { font-size: 11.5px; font-weight: 600; color: #222; background: transparent; border: 0; box-shadow: none; padding: 0 0 0 6px; text-shadow: 0 0 3px #fff, 0 0 3px #fff, 0 0 3px #fff; white-space: nowrap; pointer-events: none; }
.leaflet-tooltip.city-label::before { display: none; }
.leaflet-tooltip.city-label.dark { color: #f2f2f2; text-shadow: 0 0 3px #000, 0 0 3px #000, 0 0 3px #000; }
.plant-icon { display: grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; color: #fff; font-size: 12px; font-weight: 700; border: 2px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,0.4); }
.site-pin { width: 18px; height: 18px; border-radius: 50% 50% 50% 0; transform: rotate(-45deg); background: var(--accent); border: 2px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,0.5); }

#legend { position: absolute; right: 12px; bottom: 24px; background: rgba(255,255,255,0.94); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); padding: 8px 10px; font-size: 12px; max-width: 260px; z-index: 1000; }
#legend:empty { display: none; }
#legend .lt { font-weight: 600; margin: 4px 0 2px; }
#legend .li { display: flex; align-items: center; gap: 6px; margin: 2px 0; }
#legend .ramp { height: 10px; border-radius: 3px; }
#legend .ramp-labels { display: flex; justify-content: space-between; color: var(--muted); font-size: 11px; }
.leaflet-control-attribution { font-size: 10px !important; }

#toast { position: absolute; left: 50%; bottom: 28px; transform: translateX(-50%); background: #1d232b; color: #fff; padding: 8px 14px; border-radius: 6px; font-size: 12.5px; z-index: 1500; box-shadow: var(--shadow); max-width: 80vw; }

@media (max-width: 860px) {
  #app { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  #topbar { flex-wrap: wrap; height: auto; padding: 8px 10px; row-gap: 8px; }
  #search-wrap { width: 100%; margin-left: 0; order: 3; }
  #panel { position: absolute; top: 0; bottom: 0; left: 0; width: min(380px, 92vw); box-shadow: var(--shadow); }
  #app.panel-hidden #panel { display: none; }
  #legend { max-width: 200px; bottom: 30px; }
}
