:root {
  --bg: #14181c;
  --panel: #1e242a;
  --panel-2: #262d35;
  --text: #e8ecef;
  --muted: #9aa5b1;
  --accent: #7cb342;
  --accent-2: #558b2f;
  --danger: #c62828;
  --border: #323b45;
  --radius: 8px;
  --sidebar-w: 340px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
#app { display: flex; height: 100%; }
#map { flex: 1; min-width: 0; background: #0b0d10; }

#sidebar {
  width: var(--sidebar-w);
  max-width: 100%;
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  transition: margin-left .2s ease;
}
#sidebar.hidden { margin-left: calc(-1 * var(--sidebar-w)); }
#sidebar header { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--border); }
#sidebar h1 { font-size: 18px; margin: 0; }
#sidebar h2 { font-size: 15px; margin: 0 0 8px; }
.panel { padding: 14px 16px; border-bottom: 1px solid var(--border); }
footer { padding: 12px 16px; margin-top: auto; }

label { display: block; font-size: 13px; color: var(--muted); margin: 6px 0; }
input[type="text"] { width: 100%; margin-top: 4px; padding: 8px 10px; border-radius: var(--radius); border: 1px solid var(--border); background: var(--panel-2); color: var(--text); font-family: ui-monospace, monospace; font-size: 13px; }
input[type="checkbox"] { vertical-align: middle; }
button { cursor: pointer; padding: 8px 12px; border-radius: var(--radius); border: 1px solid var(--border); background: var(--panel-2); color: var(--text); font-size: 14px; }
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent-2); border-color: var(--accent-2); }
button.primary:hover { background: var(--accent); }
button.danger { color: #ffb4ab; }
button.danger:hover { border-color: var(--danger); }
button.link { background: none; border: none; color: var(--accent); padding: 0; }
button.icon-btn { padding: 4px 8px; }
button.floating { position: absolute; top: 12px; left: 12px; z-index: 1000; }
button:disabled { opacity: .5; cursor: default; }

.row { display: flex; gap: 8px; align-items: center; margin-top: 8px; }
.row.between { justify-content: space-between; }
.row.wrap { flex-wrap: wrap; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.units-toggle { margin: 0; font-size: 12px; }

#session-list { list-style: none; margin: 8px 0 0; padding: 0; }
#session-list li { padding: 10px 10px; border-radius: var(--radius); cursor: pointer; border: 1px solid transparent; }
#session-list li:hover { background: var(--panel-2); }
#session-list li.active { border-color: var(--accent); background: var(--panel-2); }
#session-list .name { font-weight: 600; }
#session-list .meta { color: var(--muted); font-size: 12px; }

dl { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 8px 0; font-size: 13px; }
dl:empty { display: none; }
h3.sub { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 12px 0 4px; }
h3.sub:has(+ dl:empty) { display: none; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 8px; }
textarea { width: 100%; margin-top: 4px; padding: 8px 10px; border-radius: var(--radius); border: 1px solid var(--border); background: var(--panel-2); color: var(--text); font: inherit; font-size: 13px; resize: vertical; }
#edit-form input[type="text"] { font-family: inherit; }
#detail-notes { white-space: pre-wrap; }
dt { color: var(--muted); }
dd { margin: 0; }

hr { border: none; border-top: 1px solid var(--border); margin: 14px 0; }
input[type="email"] { width: 100%; margin-top: 4px; padding: 8px 10px; border-radius: var(--radius); border: 1px solid var(--border); background: var(--panel-2); color: var(--text); font-size: 14px; }
details { margin-top: 10px; }
summary { cursor: pointer; }
.warn { color: #ffcc80; }
#device-list { list-style: none; margin: 6px 0 0; padding: 0; font-size: 13px; }
#device-list li { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 6px 0; border-top: 1px solid var(--border); }
#device-list .meta { color: var(--muted); font-size: 12px; }
.token-box { margin-top: 10px; padding: 10px; background: var(--panel-2); border: 1px solid var(--accent-2); border-radius: var(--radius); }
.token-box code { display: block; font-family: ui-monospace, monospace; font-size: 13px; word-break: break-all; user-select: all; }

#toast { position: absolute; bottom: 18px; left: 50%; transform: translateX(-50%); background: #000c; color: #fff; padding: 10px 16px; border-radius: var(--radius); z-index: 2000; font-size: 14px; max-width: 90vw; }

.leaflet-container { font: inherit; }

@media (max-width: 720px) {
  #app { flex-direction: column; }
  #sidebar { width: 100%; max-height: 50vh; border-right: none; border-bottom: 1px solid var(--border); }
  #sidebar.hidden { margin-left: 0; display: none; }
  #map { min-height: 50vh; }
}
