:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --ink: #1b1f24;
  --muted: #5d6673;
  --line: #e3e6ea;
  --red: #d7263d;
  --red-soft: rgba(215, 38, 61, 0.12);
  --accent: #1f6feb;
  --shadow: 0 6px 24px rgba(20, 28, 40, 0.14);
  --radius: 12px;
  font-family: "IBM Plex Sans", "IBM Plex Sans Thai", system-ui, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111418;
    --panel: #1a1e24;
    --ink: #e8ebef;
    --muted: #9aa4b1;
    --line: #2c323b;
    --red-soft: rgba(255, 90, 110, 0.16);
    --accent: #58a6ff;
    --shadow: 0 6px 24px rgba(0, 0, 0, 0.5);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #111418; --panel: #1a1e24; --ink: #e8ebef; --muted: #9aa4b1; --line: #2c323b;
  --red-soft: rgba(255, 90, 110, 0.16); --accent: #58a6ff; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; background: var(--bg); color: var(--ink); }
#map { position: absolute; inset: 0; }

/* ---------- side panel ---------- */
.panel {
  position: absolute; z-index: 1000; top: 12px; left: 12px; bottom: 12px;
  width: 340px; overflow-y: auto; background: var(--panel); color: var(--ink);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 16px 8px;
  font-size: 13px; line-height: 1.4;
}
.panel-head h1 { font-size: 17px; margin: 0; font-weight: 600; }
.panel-head .sub { margin: 2px 0 0; color: var(--muted); font-size: 12px; }
.block { border-top: 1px solid var(--line); margin-top: 14px; padding-top: 12px; }
.block h2 {
  font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted);
  margin: 0 0 8px; font-weight: 600;
}
.seg { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; }
.seg button {
  font: inherit; padding: 7px 8px; border-radius: 8px; border: 1px solid var(--line);
  background: transparent; color: var(--ink); cursor: pointer; text-align: left;
}
.seg button[aria-pressed="true"] { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); font-weight: 500; }
.overlay-list label, .card-head label { display: flex; align-items: center; gap: 8px; cursor: pointer; padding: 3px 0; }
input[type="checkbox"] { accent-color: var(--red); width: 15px; height: 15px; margin: 0; }
.slider { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 6px; color: var(--muted); }
.slider input { flex: 1; max-width: 150px; accent-color: var(--accent); }

/* ---------- layer summary cards ---------- */
.card {
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin-bottom: 8px;
  transition: opacity .15s;
}
.card.off { opacity: .55; }
.card.off .stats, .card.off .groups { display: none; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.card-head label { font-weight: 600; }
.swatch { width: 14px; height: 14px; border: 2px solid var(--red); background: var(--red-soft); border-radius: 2px; flex: none; }
.zoom-btn {
  font: inherit; font-size: 12px; border: none; background: none; color: var(--accent);
  cursor: pointer; padding: 2px 4px;
}
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 12px; margin-top: 8px; }
.stat .k { color: var(--muted); font-size: 11px; }
.stat .v { font-size: 15px; font-weight: 600; font-variant-numeric: tabular-nums; }
.stat .v small { font-size: 11px; font-weight: 400; color: var(--muted); }
.groups { margin-top: 8px; border-top: 1px dashed var(--line); padding-top: 6px; }
.groups div { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; padding: 2px 0; cursor: pointer; }
.groups div:hover { color: var(--accent); }
.groups span:last-child { font-variant-numeric: tabular-nums; color: var(--muted); white-space: nowrap; }
.note { color: var(--muted); font-size: 11px; margin-top: 6px; }
.panel-foot { color: var(--muted); font-size: 11px; border-top: 1px solid var(--line); margin-top: 14px; padding-top: 8px; }

/* ---------- tooltip / popup ---------- */
.leaflet-tooltip.sq-tip, .leaflet-popup-content-wrapper {
  font-family: "IBM Plex Sans", "IBM Plex Sans Thai", system-ui, sans-serif;
  background: var(--panel); color: var(--ink); border: 1px solid var(--line);
  box-shadow: var(--shadow); border-radius: 10px;
}
.leaflet-popup-tip { background: var(--panel); }
.leaflet-tooltip.sq-tip { padding: 10px 12px; min-width: 240px; max-width: 320px; white-space: normal; }
.leaflet-tooltip.sq-tip::before { display: none; }
.tip h3 { margin: 0 0 2px; font-size: 14px; font-weight: 600; }
.tip .tag { display: inline-block; font-size: 10px; text-transform: uppercase; letter-spacing: .05em; color: var(--red); font-weight: 600; }
.tip .place { color: var(--muted); margin: 0 0 6px; font-size: 12px; }
.tip table { border-collapse: collapse; width: 100%; font-size: 12px; }
.tip td { padding: 1px 0; vertical-align: top; }
.tip td:first-child { color: var(--muted); padding-right: 10px; white-space: nowrap; }
.tip td:last-child { font-variant-numeric: tabular-nums; }
.tip .hint { color: var(--muted); font-size: 11px; margin-top: 6px; }

/* ---------- misc controls ---------- */
.coords {
  position: absolute; z-index: 1000; right: 12px; bottom: 52px; background: var(--panel); color: var(--ink);
  border-radius: 8px; padding: 4px 8px; font-size: 12px; box-shadow: var(--shadow);
  font-variant-numeric: tabular-nums; font-family: "IBM Plex Sans", system-ui, sans-serif;
}
.panel-toggle {
  display: none; position: absolute; z-index: 1001; top: 12px; left: 12px; width: 40px; height: 40px;
  border-radius: 10px; border: none; background: var(--panel); color: var(--ink); box-shadow: var(--shadow); cursor: pointer;
}
.port-icon {
  width: 12px; height: 12px; border-radius: 50%; background: #fff; border: 3px solid #0b3d91;
  box-shadow: 0 0 0 2px rgba(255,255,255,.7);
}
.leaflet-container { background: var(--bg); font-family: "IBM Plex Sans", system-ui, sans-serif; }

@media (max-width: 700px) {
  .panel-toggle { display: grid; place-items: center; }
  .panel { top: 60px; left: 16px; right: 16px; width: auto; bottom: 16px; }
  .panel.hidden { display: none; }
  .coords { display: none; }
}
