:root {
  --bg: #0e1217;
  --panel: #151b22;
  --panel-2: #1b232c;
  --line: #2a3440;
  --text: #e3e8ee;
  --muted: #8b97a5;
  --accent: #e0a63a;
  --accent-2: #f2c063;
  --ok: #4cc38a;
  --warn: #e6b450;
  --bad: #e5534b;
  --radius: 8px;
  --sidebar: 340px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
button, input, select { font: inherit; color: inherit; }
a { color: var(--accent-2); }
[hidden] { display: none !important; }

/* ── layout ─────────────────────────────────────────────────────────────── */
#app { display: flex; height: 100vh; height: 100dvh; overflow: hidden; }
#sidebar {
  width: var(--sidebar); flex: none; display: flex; flex-direction: column; gap: 10px;
  padding: 12px; background: var(--panel); border-right: 1px solid var(--line); overflow-y: auto;
}
#mapWrap { position: relative; flex: 1; min-width: 0; isolation: isolate; }
#map { position: absolute; inset: 0; background: #0b0f13; }
#sidebarToggle { position: fixed; top: 10px; right: 10px; z-index: 1100; display: none; }

.sb-head { display: flex; align-items: center; justify-content: space-between; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 650; letter-spacing: .2px; }
.brand-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 10px var(--accent); }

.field { display: flex; flex-direction: column; gap: 4px; }
.label { font-size: 11px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); }
select, input[type=text], input[type=search], input[type=password], input[type=number], input[type=datetime-local] {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px; padding: 7px 9px; width: 100%;
  min-width: 0;
}
select:focus, input:focus { outline: 2px solid color-mix(in srgb, var(--accent) 60%, transparent); outline-offset: 0; }
input[type=checkbox] { accent-color: var(--accent); }
input[type=range] { accent-color: var(--accent); width: 100%; }

.btn {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px; padding: 6px 10px; cursor: pointer;
  text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 6px; white-space: nowrap;
}
.btn:hover { border-color: #3b4756; background: #212b35; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #1a1406; font-weight: 600; }
.btn.primary:hover { background: var(--accent-2); }
.btn.ghost { background: transparent; }
.btn.sm { padding: 3px 8px; font-size: 12px; }
.btn.icon { width: 34px; height: 34px; padding: 0; }
.btn:disabled { opacity: .5; cursor: default; }

.tabs { display: grid; grid-template-columns: repeat(auto-fit, minmax(0, 1fr)); gap: 4px; background: var(--bg); padding: 4px; border-radius: var(--radius); }
.tabs button { background: transparent; border: 0; border-radius: 6px; padding: 7px 4px; cursor: pointer; color: var(--muted); }
.tabs button.active { background: var(--panel-2); color: var(--text); box-shadow: inset 0 0 0 1px var(--line); }

.panel { display: flex; flex-direction: column; gap: 10px; min-height: 0; }
.section { display: flex; flex-direction: column; gap: 6px; }
.row { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.row > .grow { flex: 1; min-width: 0; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.hint { font-size: 12px; color: var(--muted); line-height: 1.4; }
.error { color: var(--bad); min-height: 1em; margin: 0; }
.status-line { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; min-height: 16px; }
.pill { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; }
.pill.ok { background: var(--ok); box-shadow: 0 0 6px var(--ok); }
.pill.warn { background: var(--warn); }
.pill.bad { background: var(--bad); }
.check { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; user-select: none; }

/* segmented buttons (range presets) */
.seg { display: flex; flex-wrap: wrap; gap: 4px; }
.seg button { flex: 1 0 auto; background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px; padding: 4px 6px; cursor: pointer; font-size: 12px; }
.seg button.active { border-color: var(--accent); color: var(--accent-2); }
.range-inputs { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.range-inputs input { font-size: 12px; padding: 5px 6px; }

/* player list */
.plist { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 1px; overflow-y: auto; max-height: 46vh; border: 1px solid var(--line); border-radius: var(--radius); background: var(--bg); }
.plist li { display: flex; align-items: center; gap: 8px; padding: 5px 8px; background: var(--panel); }
.plist li:hover { background: var(--panel-2); }
.plist .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; cursor: pointer; }
.plist .meta { font-size: 11px; color: var(--muted); white-space: nowrap; }
.plist .empty { color: var(--muted); justify-content: center; padding: 14px; }
.swatch { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.info-btn { background: none; border: 0; color: var(--muted); cursor: pointer; padding: 0 2px; font-size: 13px; }
.info-btn:hover { color: var(--text); }

/* area results */
.results { display: flex; flex-direction: column; gap: 6px; overflow-y: auto; max-height: 52vh; }
.result { background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px; display: flex; flex-direction: column; gap: 4px; }
.result-head { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.result-head .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.visit { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; padding: 4px 6px; border-radius: 5px; cursor: pointer; color: var(--muted); }
.visit:hover { background: var(--panel); color: var(--text); }

/* ── map overlays ───────────────────────────────────────────────────────── */
.hud {
  position: absolute; left: 10px; bottom: 10px; z-index: 800; background: rgba(14, 18, 23, .85); border: 1px solid var(--line);
  border-radius: 6px; padding: 4px 8px; font: 12px ui-monospace, SFMono-Regular, Consolas, monospace; pointer-events: none;
}
#mapWrap:has(.timeline:not([hidden])) .hud { bottom: 104px; }
.timeline {
  position: absolute; left: 10px; right: 10px; bottom: 10px; z-index: 800; background: rgba(21, 27, 34, .95);
  border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 10px; display: flex; flex-direction: column; gap: 6px;
}
.tl-controls { display: flex; align-items: center; gap: 8px; }
.tl-time { font: 13px ui-monospace, SFMono-Regular, Consolas, monospace; margin-left: auto; }
.tl-track { position: relative; height: 40px; }
.tl-track canvas { position: absolute; top: 0; left: 0; width: 100%; height: 28px; cursor: pointer; }
.tl-track input[type=range] { position: absolute; left: 0; right: 0; bottom: 0; margin: 0; }
.tl-bounds { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); }

.leaflet-container { background: #0b0f13; font: inherit; }
.leaflet-bar a { background: var(--panel); color: var(--text); border-color: var(--line) !important; }
.leaflet-bar a:hover { background: var(--panel-2); }
.leaflet-tooltip.plabel {
  background: rgba(14, 18, 23, .8); border: 0; color: #fff; box-shadow: none; padding: 1px 5px; font-size: 11px; border-radius: 4px;
}
.leaflet-tooltip.plabel::before { display: none; }
.leaflet-popup-content-wrapper, .leaflet-popup-tip { background: var(--panel); color: var(--text); }
.leaflet-popup-content { margin: 10px 12px; line-height: 1.5; }
.grid-label { color: rgba(255, 255, 255, .45); font: 11px ui-monospace, Consolas, monospace; text-align: center; }
.map-crosshair .leaflet-container { cursor: crosshair; }

/* legend */
.legend { height: 10px; border-radius: 3px; background: linear-gradient(90deg, #1d3b8a, #1fa6c9, #6ad16a, #f2d43a, #e5534b); }
.legend-labels { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); }

/* ── drawer ─────────────────────────────────────────────────────────────── */
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(380px, 100vw); z-index: 1200; background: var(--panel);
  border-left: 1px solid var(--line); box-shadow: -10px 0 30px rgba(0, 0, 0, .4); padding: 14px; overflow-y: auto;
  display: flex; flex-direction: column; gap: 12px;
}
.drawer h2 { margin: 0; font-size: 17px; display: flex; align-items: center; gap: 8px; word-break: break-word; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-all; }
.mono { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 12px; }
.list-rows { display: flex; flex-direction: column; gap: 2px; }
.list-rows .r { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; padding: 5px 6px; border-radius: 5px; background: var(--panel-2); }
.list-rows .r.click { cursor: pointer; }
.list-rows .r.click:hover { background: #222c37; }

/* ── login ──────────────────────────────────────────────────────────────── */
.login-body { display: grid; place-items: center; padding: 16px; }
.login-card { width: min(360px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 22px; display: flex; flex-direction: column; gap: 14px; }

/* ── small screens ──────────────────────────────────────────────────────── */
@media (max-width: 800px) {
  #sidebar { position: absolute; z-index: 1000; top: 0; bottom: 0; left: 0; width: min(var(--sidebar), 90vw); transform: translateX(-100%); transition: transform .2s; box-shadow: 10px 0 30px rgba(0,0,0,.4); }
  #app.sidebar-open #sidebar { transform: none; }
  #sidebarToggle { display: inline-flex; }
  .timeline { left: 6px; right: 6px; bottom: 6px; }
}
