/* GhostTrack v2 design system. Two themes via [data-theme] on <html>. */
:root, html[data-theme="dark"] {
  --bg: #0a100e;
  --panel: #101915;
  --panel-2: #0c130f;
  --card: #152019;
  --card-hover: #1a271f;
  --border: #24382e;
  --border-soft: #1a2921;
  --text: #e9f4ef;
  --muted: #96aca1;
  --faint: #6d857a;
  --accent: #2dd4bf;
  --accent-strong: #5eead4;
  --accent-ink: #04241d;
  --accent-soft: rgba(45, 212, 191, .12);
  --input-bg: #0b120f;
  --warn: #fbbf24;
  --bad: #f87171;
  --ok: #34d399;
  --shadow: 0 12px 32px rgba(0, 0, 0, .45);
  --map-filter: none;
}
html[data-theme="light"] {
  --bg: #eef3f1;
  --panel: #ffffff;
  --panel-2: #f4f8f6;
  --card: #f2f7f4;
  --card-hover: #e9f2ed;
  --border: #cfded6;
  --border-soft: #dde8e2;
  --text: #132019;
  --muted: #50645a;
  --faint: #7b8f85;
  --accent: #0d9488;
  --accent-strong: #0f766e;
  --accent-ink: #ffffff;
  --accent-soft: rgba(13, 148, 136, .1);
  --input-bg: #ffffff;
  --warn: #b45309;
  --bad: #dc2626;
  --ok: #059669;
  --shadow: 0 12px 28px rgba(19, 42, 33, .14);
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px; overflow: hidden;
}
#app { display: flex; flex-direction: column; height: 100dvh; }

/* ---------- header ---------- */
header {
  height: 60px; flex: none; display: flex; align-items: center; gap: 12px;
  padding: 0 16px; background: var(--panel); border-bottom: 1px solid var(--border);
  z-index: 1200; position: relative;
}
.logo { width: 38px; height: 38px; flex: none; display: flex; align-items: center; justify-content: center; }
.logo img { width: 38px; height: 38px; border-radius: 11px; }
.brand { font-size: 17px; font-weight: 700; letter-spacing: .02em; line-height: 1.15; }
.brand small { display: block; font-size: 10px; font-weight: 500; color: var(--muted); letter-spacing: .14em; margin-top: 1px; }
.spacer { flex: 1; }
.pill {
  font-size: 12.5px; font-weight: 600; padding: 8px 16px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--panel-2); color: var(--muted);
  white-space: nowrap;
}
.pill.on { color: var(--accent-ink); background: var(--accent); border-color: var(--accent); font-weight: 700; }
.pill.ok {
  color: var(--accent-strong);
  border-color: color-mix(in srgb, var(--accent) 55%, var(--border));
  background: color-mix(in srgb, var(--accent) 12%, var(--panel-2));
}
.pill.warn {
  color: var(--warn);
  border-color: color-mix(in srgb, var(--warn) 55%, var(--border));
  background: color-mix(in srgb, var(--warn) 10%, var(--panel-2));
}
.iconbtn {
  width: 40px; height: 40px; flex: none; border-radius: 50%; cursor: pointer;
  border: 1px solid var(--border); background: var(--panel-2); color: var(--text);
  display: flex; align-items: center; justify-content: center; transition: .18s;
}
.iconbtn:hover { border-color: var(--accent); color: var(--accent-strong); }
.iconbtn svg { width: 19px; height: 19px; }
html[data-theme="dark"] .icon-sun { display: none; }
html[data-theme="light"] .icon-moon { display: none; }
#inspbtn { display: none; }
.switch { position: relative; width: 56px; height: 30px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch .track { position: absolute; inset: 0; border-radius: 999px; background: var(--border); cursor: pointer; transition: .25s; }
.switch .track:before {
  content: ""; position: absolute; width: 24px; height: 24px; left: 3px; top: 3px;
  border-radius: 50%; background: var(--text); transition: .25s;
}
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track:before { transform: translateX(26px); background: var(--accent-ink); }
.switch input:focus-visible + .track { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- layout ---------- */
main { flex: 1; min-height: 0; display: grid; grid-template-columns: 400px minmax(0, 1fr) 332px; grid-template-areas: "side map insp"; }
#sidebar { grid-area: side; background: var(--panel); border-right: 1px solid var(--border); overflow-y: auto; padding: 16px; min-height: 0; }
#mapwrap { grid-area: map; position: relative; min-width: 0; min-height: 0; }
#map { position: absolute; inset: 0; background: var(--bg); }
#inspector { grid-area: insp; background: var(--panel); border-left: 1px solid var(--border); overflow-y: auto; padding: 16px; min-height: 0; }

/* ---------- sidebar nav ---------- */
.tabs { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-bottom: 16px; }
.scorewrap { display: flex; gap: 14px; align-items: center; margin-bottom: 12px; }
.score {
  width: 74px; height: 74px; flex: none; border-radius: 50%;
  border: 5px solid var(--accent); display: flex; align-items: center; justify-content: center;
  font-size: 21px; font-weight: 800; color: var(--accent-strong); background: var(--panel-2);
}
.score.mid { border-color: var(--warn); color: var(--warn); }
.score.low { border-color: var(--bad); color: var(--bad); }
.scorelabel { font-weight: 700; font-size: 14px; margin-bottom: 2px; }
.idthumb { width: 100%; height: 74px; object-fit: cover; border-radius: 8px; margin-bottom: 8px; background: var(--panel-2); }
.favstar { cursor: pointer; color: var(--faint); font-size: 15px; }
.favstar.on { color: var(--warn); }
#tab-checks a, #tab-identities a { color: var(--accent-strong); }
.tabs button {
  padding: 8px 2px 7px; font-size: 11.5px; font-weight: 600; cursor: pointer;
  background: var(--panel-2); color: var(--muted); border: 1px solid var(--border-soft);
  border-radius: 10px; display: flex; flex-direction: column; align-items: center; gap: 4px;
}
.tabs button svg { width: 17px; height: 17px; }
.tabs button:hover { color: var(--text); border-color: var(--border); }
.tabs button.active { background: var(--accent-soft); color: var(--accent-strong); border-color: var(--accent); }
.tabpage { display: none; }
.tabpage.active { display: block; }
h3 { font-size: 11.5px; letter-spacing: .09em; text-transform: uppercase; color: var(--faint); margin: 18px 0 9px; font-weight: 700; }
h3:first-child { margin-top: 0; }

/* ---------- forms ---------- */
input, select {
  width: 100%; padding: 9px 11px; margin-bottom: 8px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--input-bg); color: var(--text); font-size: 13.5px;
}
input:focus, select:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
input[type="range"] { padding: 0; border: 0; background: transparent; accent-color: var(--accent); }
input[type="checkbox"] { width: auto; }
.row { display: flex; gap: 8px; }
.row > * { flex: 1; }
button.btn {
  width: 100%; padding: 9px 10px; margin-bottom: 8px; border: 1px solid var(--border);
  border-radius: 10px; background: var(--card); color: var(--text); font-size: 13.5px; font-weight: 600; cursor: pointer;
}
button.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
button.btn.ghost { background: transparent; }
button.btn.small { width: auto; padding: 5px 11px; font-size: 12px; margin: 0; }
button.btn:hover { filter: brightness(1.07); }
#status { font-size: 12.5px; color: var(--accent-strong); line-height: 1.55; word-break: break-word; white-space: pre-line; }
.hint { font-size: 12px; color: var(--muted); line-height: 1.55; }
.warn-text { color: var(--warn); font-size: 12.5px; line-height: 1.5; margin-bottom: 8px; }
details.addr { border: 1px solid var(--border-soft); border-radius: 10px; padding: 8px 10px; margin-bottom: 8px; background: var(--panel-2); }
details.addr summary { cursor: pointer; font-size: 12.5px; font-weight: 600; color: var(--muted); margin-bottom: 6px; }

/* autocomplete */
.ac-wrap { position: relative; }
.ac-list {
  position: absolute; top: calc(100% - 4px); left: 0; right: 0; z-index: 1300;
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: var(--shadow); overflow: hidden; display: none;
}
.ac-list.open { display: block; }
.ac-item { padding: 9px 12px; cursor: pointer; border-bottom: 1px solid var(--border-soft); }
.ac-item:last-child { border-bottom: 0; }
.ac-item:hover { background: var(--card-hover); }
.ac-item .t { font-size: 13px; font-weight: 600; }
.ac-item .s { font-size: 11.5px; color: var(--muted); }

/* ---------- cards & data ---------- */
.card { border: 1px solid var(--border-soft); border-radius: 12px; padding: 11px 12px; margin-bottom: 8px; background: var(--card); }
.card .name { font-weight: 600; font-size: 13.5px; }
.card .meta { font-size: 12px; color: var(--muted); line-height: 1.55; word-break: break-word; white-space: pre-line; }
.card .actions { display: flex; gap: 6px; margin-top: 8px; }
.kv { display: flex; justify-content: space-between; gap: 12px; font-size: 12.5px; padding: 5px 0; border-bottom: 1px solid var(--border-soft); }
.kv:last-child { border-bottom: 0; }
.kv span { color: var(--muted); flex: none; }
.kv b { font-weight: 600; text-align: right; word-break: break-all; }
.kv .ok { color: var(--ok); } .kv .bad { color: var(--bad); } .kv .warnv { color: var(--warn); }
progress { width: 100%; height: 10px; accent-color: var(--accent); }

/* ---------- map chrome ---------- */
.leaflet-container { font: inherit; background: var(--bg); }
.leaflet-bar a { background: var(--panel); color: var(--text); border-color: var(--border); }
#map.darktiles .leaflet-tile-pane { filter: invert(0.9) hue-rotate(180deg) saturate(0.65) brightness(0.92) contrast(0.95); }
.maptools {
  position: absolute; z-index: 900; top: 12px; right: 12px; display: flex; gap: 0;
  background: var(--panel); border: 1px solid var(--border); border-radius: 10px; overflow: hidden; box-shadow: var(--shadow);
}
.maptools button { border: 0; background: transparent; color: var(--muted); font-size: 12px; font-weight: 600; padding: 7px 11px; cursor: pointer; }
.maptools button.active { background: var(--accent); color: var(--accent-ink); }
.mapfoot {
  position: absolute; z-index: 900; left: 12px; bottom: 12px; display: flex; gap: 8px; align-items: center;
}
.mapfoot a, .mapfoot .coord {
  color: var(--accent-strong); background: var(--panel); padding: 7px 11px; border-radius: 10px;
  border: 1px solid var(--border); text-decoration: none; font-size: 12px; font-weight: 600;
}
.mapfoot .coord { color: var(--muted); font-weight: 500; }

/* ---------- inspector ---------- */
.idcard {
  border: 1px solid var(--accent); border-radius: 14px; padding: 14px;
  background: linear-gradient(160deg, var(--accent-soft), transparent 65%); margin-bottom: 14px;
}
.idcard .state { font-size: 15px; font-weight: 800; letter-spacing: .05em; color: var(--accent-strong); }
.idcard .state.off { color: var(--muted); }
.idcard .clock { font-size: 30px; font-weight: 700; font-variant-numeric: tabular-nums; margin: 6px 0 0; }
.idcard .clocksub { font-size: 12px; color: var(--muted); }
.idcard .addr { font-size: 13px; line-height: 1.5; margin-top: 8px; }

/* ---------- responsive ---------- */
@media (max-width: 1180px) {
  main { grid-template-columns: 384px minmax(0, 1fr); grid-template-areas: "side map"; }
  #inspbtn { display: flex; }
  #inspector {
    position: fixed; top: 58px; right: 0; bottom: 0; width: 330px; z-index: 1150;
    transform: translateX(105%); transition: transform .22s ease; box-shadow: var(--shadow);
  }
  body.insp-open #inspector { transform: translateX(0); }
}
@media (max-width: 760px) {
  .brand small { display: none; }
  #extpill { display: none; }
  main { grid-template-columns: 1fr; grid-template-rows: 44% minmax(0, 1fr); grid-template-areas: "map" "side"; }
  #sidebar { border-right: 0; border-top: 1px solid var(--border); }
}

/* ---------- scrollbars: custom, auto-hide ---------- */
* { scrollbar-width: thin; scrollbar-color: transparent transparent; }
*:hover, *.gt-scrolling { scrollbar-color: color-mix(in srgb, var(--accent) 70%, transparent) transparent; }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-corner { background: transparent; }
::-webkit-scrollbar-thumb {
  background: transparent; border-radius: 999px;
  border: 2px solid transparent; background-clip: padding-box;
}
*:hover::-webkit-scrollbar-thumb,
.gt-scrolling::-webkit-scrollbar-thumb {
  background: linear-gradient(180deg, var(--accent), var(--accent-strong));
  border: 2px solid transparent; background-clip: padding-box;
}
