:root {
  --bg: #0a0d14;
  --bg-2: #0f141e;
  --panel: #121926;
  --panel-2: #182132;
  --panel-3: #1f2a3e;
  --line: #263248;
  --line-2: #33415c;
  --text: #e7edf6;
  --muted: #8b9ab1;
  --dim: #5d6b82;
  --accent: #ff4d6d;
  --accent-2: #22d3ee;
  --ok: #34d399;
  --warn: #fbbf24;
  --danger: #f87171;
  --radius: 10px;
  --font: "Segoe UI Variable", "Segoe UI", Inter, system-ui, -apple-system, sans-serif;
  --mono: "Cascadia Code", Consolas, ui-monospace, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 13px/1.45 var(--font);
  display: grid;
  grid-template-rows: 52px 1fr 26px;
  overflow: hidden;
}
button, input, select, textarea { font: inherit; color: inherit; }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
code, kbd { font-family: var(--mono); font-size: 12px; }
code { background: var(--panel-3); padding: 1px 5px; border-radius: 4px; }
kbd { background: var(--panel-3); border: 1px solid var(--line-2); border-bottom-width: 2px; padding: 0 5px; border-radius: 4px; }

/* ---------- top bar ---------- */
.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 0 12px;
  background: linear-gradient(180deg, #111827, #0d121c);
  border-bottom: 1px solid var(--line);
  z-index: 1001;
}
.brand { display: flex; align-items: center; gap: 7px; font-weight: 600; white-space: nowrap; }
.logo {
  display: grid; place-items: center; width: 28px; height: 28px; border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), #ff8a4d);
  color: #fff; font-size: 12px; font-weight: 800; letter-spacing: .5px;
  box-shadow: 0 0 18px rgba(255, 77, 109, .35);
}
.brand-os { color: var(--muted); }
.brand-sep { color: var(--dim); }
.project-name {
  width: 170px; background: transparent; border: 1px solid transparent; border-radius: 7px;
  padding: 5px 8px; font-weight: 600;
}
.project-name:hover { border-color: var(--line); }
.project-name:focus { outline: none; border-color: var(--accent-2); background: var(--bg-2); }

.search { position: relative; flex: 1; max-width: 560px; display: flex; align-items: center; }
.search > svg { position: absolute; left: 10px; color: var(--muted); width: 16px; height: 16px; }
.search input {
  width: 100%; height: 34px; padding: 0 12px 0 34px;
  background: var(--bg-2); border: 1px solid var(--line); border-radius: 9px;
}
.search input:focus { outline: none; border-color: var(--accent-2); box-shadow: 0 0 0 3px rgba(34, 211, 238, .15); }
.dropdown {
  position: absolute; top: 40px; left: 0; right: 0; max-height: 360px; overflow: auto;
  background: var(--panel); border: 1px solid var(--line-2); border-radius: 10px;
  box-shadow: 0 16px 40px rgba(0,0,0,.5); padding: 4px; z-index: 2000;
}
.dropdown .res { display: block; width: 100%; text-align: left; background: none; border: 0; padding: 8px 10px; border-radius: 7px; cursor: pointer; }
.dropdown .res:hover, .dropdown .res.active { background: var(--panel-3); }
.dropdown .res b { display: block; font-weight: 600; }
.dropdown .res span { color: var(--muted); font-size: 12px; }
.dropdown .empty { padding: 10px; color: var(--muted); }

.top-actions { display: flex; align-items: center; gap: 6px; margin-left: auto; }
.top-actions select {
  height: 32px; background: var(--bg-2); border: 1px solid var(--line); border-radius: 8px; padding: 0 8px;
}
.toggle { display: flex; align-items: center; gap: 5px; color: var(--muted); cursor: pointer; padding: 0 6px; white-space: nowrap; }
.toggle input { accent-color: var(--accent-2); }

.btn {
  height: 32px; padding: 0 12px; border-radius: 8px; border: 1px solid var(--line-2);
  background: var(--panel-2); cursor: pointer; white-space: nowrap; font-weight: 500;
  transition: background .12s, border-color .12s, transform .05s;
}
.btn:hover { background: var(--panel-3); border-color: #41506d; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .4; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #ff6682; }
.btn.ghost { background: transparent; }
.btn.ghost:hover { background: var(--panel-2); }
.btn.danger { color: var(--danger); }
.btn.danger:hover { background: rgba(248, 113, 113, .12); border-color: var(--danger); }
.btn.icon { width: 32px; padding: 0; font-weight: 700; }
.btn.sm { height: 28px; padding: 0 10px; font-size: 12px; }
.btn.full { width: 100%; }

/* ---------- workspace ---------- */
.workspace { display: grid; grid-template-columns: 52px 1fr 320px; min-height: 0; }

.toolbar {
  display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 8px 0;
  background: var(--panel); border-right: 1px solid var(--line); z-index: 1000;
}
.toolbar button {
  position: relative; width: 38px; height: 38px; display: grid; place-items: center;
  border: 1px solid transparent; border-radius: 9px; background: none; cursor: pointer; color: var(--muted);
}
.toolbar button:hover { background: var(--panel-2); color: var(--text); }
.toolbar button.active {
  background: rgba(255, 77, 109, .14); border-color: rgba(255, 77, 109, .5); color: #fff;
  box-shadow: inset 0 0 12px rgba(255, 77, 109, .2);
}
.toolbar button span {
  position: absolute; right: 3px; bottom: 1px; font-size: 9px; font-family: var(--mono); color: var(--dim);
}
.toolbar svg { width: 20px; height: 20px; }
.tool-sep { width: 26px; height: 1px; background: var(--line); margin: 4px 0; }
.tool-spacer { flex: 1; }

.map-wrap { position: relative; min-width: 0; }
#map { position: absolute; inset: 0; background: #05070b; }
#map[data-tool="wand"], #map[data-tool="origin"], #map.placing { cursor: crosshair; }
#map[data-tool="wand"] .leaflet-interactive { cursor: crosshair; }

.hint {
  position: absolute; top: 12px; left: 50%; transform: translateX(-50%); z-index: 900;
  background: rgba(15, 20, 30, .92); border: 1px solid var(--line-2); border-radius: 999px;
  padding: 6px 14px; font-size: 12px; color: var(--muted); pointer-events: none; white-space: nowrap;
  backdrop-filter: blur(6px);
}
.hint b { color: var(--text); font-weight: 600; }

/* ---------- floating wand panel ---------- */
.floating {
  position: absolute; left: 14px; top: 14px; z-index: 950; width: 300px;
  background: rgba(18, 25, 38, .96); border: 1px solid var(--line-2); border-radius: 12px;
  box-shadow: 0 18px 50px rgba(0,0,0,.55); backdrop-filter: blur(8px);
}
.fp-head { padding: 10px 12px 8px; border-bottom: 1px solid var(--line); }
.fp-title { display: flex; align-items: center; gap: 6px; font-weight: 600; }
.fp-title svg { color: var(--accent-2); width: 16px; height: 16px; }
.fp-status { display: block; color: var(--muted); font-size: 12px; margin-top: 2px; }
.fp-status.busy::before {
  content: ""; display: inline-block; width: 10px; height: 10px; margin-right: 6px; vertical-align: -1px;
  border: 2px solid var(--accent-2); border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.fp-body { padding: 10px 12px 4px; }
.slider { display: block; margin-bottom: 8px; }
.slider span { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); }
.slider b { color: var(--text); font-family: var(--mono); font-weight: 500; }
.slider input { width: 100%; accent-color: var(--accent-2); }
.fp-tip { font-size: 11.5px; color: var(--dim); margin: 2px 0 6px; }
.fp-actions { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px 12px 12px; }

/* ---------- right panel ---------- */
.panel { display: flex; flex-direction: column; background: var(--panel); border-left: 1px solid var(--line); min-height: 0; z-index: 1000; }
.tabs { display: flex; border-bottom: 1px solid var(--line); padding: 0 8px; }
.tab {
  background: none; border: 0; padding: 11px 12px 9px; cursor: pointer; color: var(--muted);
  border-bottom: 2px solid transparent; font-weight: 500;
}
.tab.active { color: var(--text); border-bottom-color: var(--accent); }
.pane { flex: 1; overflow: auto; min-height: 0; display: flex; flex-direction: column; }
.filter { position: relative; padding: 10px; }
.filter svg { position: absolute; left: 20px; top: 19px; width: 14px; height: 14px; color: var(--muted); }
.filter input {
  width: 100%; height: 30px; padding: 0 10px 0 30px; background: var(--bg-2); border: 1px solid var(--line); border-radius: 8px;
}
.filter input:focus { outline: none; border-color: var(--accent-2); }
.layer-list { flex: 1; padding: 0 6px 10px; }

.grp { margin-bottom: 6px; }
.grp-head { display: flex; align-items: center; gap: 6px; padding: 6px 6px; font-weight: 600; }
.grp-head .count { color: var(--dim); font-weight: 500; font-size: 12px; }
.grp-head .grow { flex: 1; }
.grp-head .add { color: var(--muted); }
.eye {
  width: 24px; height: 24px; display: grid; place-items: center; border: 0; background: none; border-radius: 6px;
  cursor: pointer; color: var(--muted); flex: none;
}
.eye:hover { background: var(--panel-3); color: var(--text); }
.eye svg { width: 15px; height: 15px; }
.eye.off { color: var(--dim); }
.chips { display: flex; flex-wrap: wrap; gap: 4px; padding: 0 6px 6px 36px; }
.chip {
  display: inline-flex; align-items: center; gap: 5px; padding: 2px 8px 2px 6px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--bg-2); font-size: 11.5px; cursor: pointer; color: var(--muted);
}
.chip i { width: 8px; height: 8px; border-radius: 50%; background: var(--c); }
.chip.off { opacity: .45; text-decoration: line-through; }
.chip:hover { border-color: var(--line-2); color: var(--text); }
.items { list-style: none; margin: 0; padding: 0; }
.items li {
  display: flex; align-items: center; gap: 8px; padding: 4px 6px 4px 12px; border-radius: 7px; cursor: pointer;
}
.items li:hover { background: var(--panel-2); }
.items li.sel { background: rgba(255, 77, 109, .12); box-shadow: inset 2px 0 0 var(--accent); }
.items li.hid .nm { color: var(--dim); text-decoration: line-through; }
.items .dot { width: 10px; height: 10px; border-radius: 3px; background: var(--c); flex: none; }
.items .glyph { width: 16px; text-align: center; flex: none; font-size: 12px; }
.items .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.items .meta { color: var(--dim); font-size: 11.5px; font-family: var(--mono); white-space: nowrap; }
.empty-list { color: var(--dim); padding: 4px 12px 8px 36px; font-size: 12px; }
.totals { border-top: 1px solid var(--line); padding: 8px 14px; color: var(--muted); font-size: 12px; display: flex; gap: 12px; flex-wrap: wrap; }
.totals b { color: var(--text); font-weight: 600; }

/* properties */
#props { padding: 12px 14px 20px; }
.props-empty { color: var(--muted); padding: 30px 10px; text-align: center; }
.props-empty svg { width: 36px; height: 36px; color: var(--dim); display: block; margin: 0 auto 10px; }
.props-head { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.props-head .kind-badge {
  font-size: 11px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted);
  border: 1px solid var(--line-2); border-radius: 999px; padding: 1px 8px;
}
.field { display: block; margin-bottom: 10px; }
.field > span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.field input[type=text], .field input[type=number], .field select, .field textarea {
  width: 100%; background: var(--bg-2); border: 1px solid var(--line); border-radius: 8px; padding: 6px 9px;
}
.field textarea { resize: vertical; min-height: 60px; }
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--accent-2); }
.row { display: flex; gap: 8px; align-items: flex-end; }
.row > .field { flex: 1; }
.color-row { display: flex; gap: 6px; align-items: center; }
.color-row input[type=color] { width: 38px; height: 32px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg-2); padding: 2px; cursor: pointer; }
.check { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; cursor: pointer; }
.check input { accent-color: var(--accent-2); width: 15px; height: 15px; }
.check small { color: var(--dim); }
.stats {
  display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin: 12px 0;
}
.stat { background: var(--bg-2); border: 1px solid var(--line); border-radius: 8px; padding: 7px 9px; }
.stat span { display: block; font-size: 11px; color: var(--dim); text-transform: uppercase; letter-spacing: .4px; }
.stat b { font-family: var(--mono); font-weight: 500; font-size: 13px; }
.actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.section-title { font-size: 11px; text-transform: uppercase; letter-spacing: .6px; color: var(--dim); margin: 14px 0 6px; }
.station-box { background: var(--bg-2); border: 1px solid var(--line); border-radius: 8px; padding: 8px; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.station-box .st-txt { flex: 1; font-size: 12px; color: var(--muted); }

/* ---------- status bar ---------- */
.statusbar {
  display: flex; align-items: center; gap: 18px; padding: 0 12px;
  background: var(--bg-2); border-top: 1px solid var(--line); color: var(--muted);
  font: 11.5px var(--mono); white-space: nowrap; overflow: hidden;
}
.st-grow { flex: 1; }
#stSave.dirty { color: var(--warn); }

/* ---------- map elements ---------- */
.leaflet-container { font: 12px var(--font); }
.leaflet-control-zoom a, .leaflet-bar a {
  background: var(--panel) !important; color: var(--text) !important; border-color: var(--line) !important;
}
.leaflet-bar { border: 1px solid var(--line-2) !important; box-shadow: 0 6px 18px rgba(0,0,0,.4) !important; }
.leaflet-control-attribution { background: rgba(10, 13, 20, .75) !important; color: var(--dim) !important; font-size: 10px; }
.leaflet-control-attribution a { color: var(--muted) !important; }
.leaflet-control-scale-line { background: rgba(10, 13, 20, .75); color: var(--text); border-color: var(--muted); }

.pin-wrap { background: none; border: 0; }
.pin {
  width: 30px; height: 30px; border-radius: 50% 50% 50% 4px; transform: rotate(-45deg);
  background: var(--c); border: 2px solid #fff; display: grid; place-items: center;
  box-shadow: 0 4px 10px rgba(0,0,0,.5);
}
.pin span { transform: rotate(45deg); font-size: 14px; line-height: 1; }
.pin.sel { box-shadow: 0 0 0 4px rgba(255,255,255,.35), 0 0 18px var(--c); }
.station-icon {
  background: #0b0f17; border: 2px solid var(--c); color: #fff; border-radius: 6px;
  font-size: 11px; font-weight: 700; padding: 1px 5px; white-space: nowrap;
  box-shadow: 0 3px 8px rgba(0,0,0,.5); display: inline-block; transform: translate(-50%, -50%);
}
.origin-icon { background: none; border: 0; }
.origin-mark {
  width: 34px; height: 34px; position: relative; transform: translate(-1px, -1px);
}
.origin-mark::before, .origin-mark::after {
  content: ""; position: absolute; background: var(--accent-2); box-shadow: 0 0 6px rgba(0,0,0,.8);
}
.origin-mark::before { left: 16px; top: 0; width: 2px; height: 34px; }
.origin-mark::after { top: 16px; left: 0; height: 2px; width: 34px; }
.origin-mark i {
  position: absolute; left: 9px; top: 9px; width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid var(--accent-2); background: rgba(34, 211, 238, .25);
}
.origin-mark b {
  position: absolute; left: 22px; top: -14px; font: 600 10px var(--mono); color: var(--accent-2);
  text-shadow: 0 0 4px #000, 0 0 4px #000;
}
.leaflet-tooltip.feat-label {
  background: rgba(10, 13, 20, .82); color: #fff; border: 0; border-radius: 5px; padding: 1px 6px;
  font-size: 11px; font-weight: 600; box-shadow: none;
}
.leaflet-tooltip.feat-label::before { display: none; }
.wand-seed {
  width: 10px; height: 10px; border-radius: 50%; background: var(--accent-2); border: 2px solid #fff;
  box-shadow: 0 0 8px var(--accent-2);
}

/* geoman markers in dark theme */
.marker-icon { background: #fff; border: 2px solid var(--accent) !important; }
.marker-icon-middle { opacity: .6; }

/* ---------- dialogs ---------- */
.dialog {
  background: var(--panel); color: var(--text); border: 1px solid var(--line-2); border-radius: 14px;
  padding: 0; width: min(520px, calc(100vw - 32px)); box-shadow: 0 30px 80px rgba(0,0,0,.6);
}
.dialog.wide { width: min(860px, calc(100vw - 32px)); }
.dialog::backdrop { background: rgba(3, 5, 10, .65); backdrop-filter: blur(2px); }
.dialog form { padding: 18px 20px; }
.dialog h2 { margin: 0 0 6px; font-size: 17px; }
.dialog h3 { font-size: 13px; margin: 14px 0 6px; color: var(--accent-2); }
.dialog p { margin: 0 0 12px; }
.dialog ol { padding-left: 18px; margin: 0; }
.dialog li { margin-bottom: 5px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 12px; }
.grid2 label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.grid2 input, .grid2 select { background: var(--bg-2); border: 1px solid var(--line); border-radius: 8px; padding: 6px 9px; color: var(--text); }
.checks { display: flex; flex-wrap: wrap; gap: 8px 16px; margin: 12px 0; }
.checks label { display: flex; gap: 6px; align-items: center; cursor: pointer; }
.checks input { accent-color: var(--accent-2); }
.ex-info {
  background: var(--bg-2); border: 1px solid var(--line); border-radius: 9px; padding: 9px 11px;
  font: 12px var(--mono); color: var(--muted); white-space: pre-line;
}
.ex-info.warn { border-color: var(--warn); color: var(--warn); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.help-grid { display: grid; grid-template-columns: 1.3fr 1fr; gap: 24px; }
.keys { border-collapse: collapse; width: 100%; }
.keys td { padding: 4px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
.keys td:first-child { white-space: nowrap; }

/* ---------- toasts / drop ---------- */
#toasts { position: fixed; bottom: 40px; left: 50%; transform: translateX(-50%); z-index: 5000; display: flex; flex-direction: column; gap: 6px; align-items: center; pointer-events: none; }
.toast {
  background: var(--panel-2); border: 1px solid var(--line-2); border-left: 3px solid var(--accent-2);
  padding: 8px 14px; border-radius: 9px; box-shadow: 0 10px 30px rgba(0,0,0,.5);
  animation: tin .18s ease-out; max-width: 520px;
}
.toast.err { border-left-color: var(--danger); }
.toast.ok { border-left-color: var(--ok); }
@keyframes tin { from { opacity: 0; transform: translateY(6px); } }
.drop-hint {
  position: fixed; inset: 0; z-index: 6000; display: grid; place-items: center;
  background: rgba(10, 13, 20, .8); border: 3px dashed var(--accent-2); font-size: 20px; font-weight: 600;
  pointer-events: none;
}

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
  .brand-os, .brand-sep, .toggle { display: none; }
  .project-name { width: 120px; }
}
@media (max-width: 860px) {
  body { grid-template-rows: auto 1fr 26px; }
  .topbar { flex-wrap: wrap; padding: 8px; }
  .search { order: 5; flex-basis: 100%; max-width: none; }
  .workspace { grid-template-columns: 48px 1fr; }
  .panel { position: fixed; right: 0; top: 96px; bottom: 26px; width: min(320px, 85vw); box-shadow: -10px 0 30px rgba(0,0,0,.5); }
  .help-grid { grid-template-columns: 1fr; }
  .floating { width: calc(100% - 28px); }
}
