:root {
  --bg: #14171c;
  --panel: #1c2027;
  --panel-2: #242a33;
  --line: #333b47;
  --text: #e6e9ee;
  --muted: #9aa4b2;
  --accent: #4f8cff;
  --danger: #ff5a5f;
  --ok: #3cb44b;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
h1 { font-size: 18px; margin: 0; }
h2 { font-size: 14px; margin: 16px 0 6px; }
h3 { font-size: 14px; margin: 18px 0 8px; }
p { margin: 8px 0; }
.fine { color: var(--muted); font-size: 12px; }
.sub { color: var(--muted); font-size: 13px; }
.error { color: var(--danger); }
[hidden] { display: none !important; }

button { font: inherit; color: var(--text); background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 6px; padding: 7px 12px; cursor: pointer; }
button:hover:not(:disabled) { border-color: var(--muted); }
button:disabled { opacity: .45; cursor: not-allowed; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
button.ghost { background: transparent; }
button.small { padding: 4px 9px; font-size: 12px; }
.danger-text { color: var(--danger) !important; }
input, select, textarea { font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line);
  border-radius: 6px; padding: 7px 9px; width: 100%; }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
input.miss { border-color: var(--danger); }
label.t { display: flex; align-items: center; gap: 8px; margin: 8px 0; cursor: pointer; }
label.t input { width: auto; }

/* ---------------------------------------------------------------- login */
.login-body { display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 340px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 10px; padding: 26px 24px 18px; }
.login-card h1 { margin-bottom: 18px; }
.login-card form { display: grid; gap: 6px; }
.login-card label { font-size: 13px; color: var(--muted); margin-top: 6px; }
.login-card button { margin-top: 14px; padding: 9px; }
.login-card .fine { text-align: center; margin-top: 16px; }

/* ---------------------------------------------------------------- map page */
#app { display: flex; height: 100%; }
#side { width: 320px; flex: none; overflow-y: auto; padding: 14px 16px; background: var(--panel);
  border-right: 1px solid var(--line); }
#map { flex: 1; min-width: 0; }
.side-head { display: flex; flex-direction: column; gap: 8px; }
.who { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12px; }
.who span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.upgrade { background: var(--panel-2); border-left: 3px solid var(--accent); padding: 8px 10px; border-radius: 4px; }
#plus-tools { margin-top: 10px; }
.chips { display: flex; flex-wrap: wrap; gap: 5px; }
.chip { display: inline-flex; align-items: center; gap: 5px; padding: 3px 8px; font-size: 12px;
  border-radius: 12px; background: var(--panel-2); border: 1px solid var(--line); }
.chip.muted { color: var(--muted); }
.chip.flash { animation: chipflash 1s ease-in-out infinite alternate; border-color: #fff; color: #fff; }
@keyframes chipflash { from { background: var(--panel-2); } to { background: #5a6170; } }
.live { flex: none !important; display: inline-flex; align-items: center; gap: 5px; font-size: 11px; color: var(--muted); }
.live::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.live.on::before { background: var(--ok); }
.live.off::before { background: var(--danger); }
@media (prefers-reduced-motion: reduce) { .chip.flash { animation: none; background: #5a6170; } }
.sw { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }
.c0 { background: #e6194b; } .c1 { background: #3cb44b; } .c2 { background: #ffe119; } .c3 { background: #4363d8; }
.c4 { background: #f58231; } .c5 { background: #42d4f4; } .c6 { background: #f032e6; } .c7 { background: #bfef45; }
.maplibregl-popup-content { background: var(--panel); color: var(--text); padding: 6px 10px; border-radius: 6px; }
.maplibregl-popup-tip { border-top-color: var(--panel) !important; border-bottom-color: var(--panel) !important; }
.maplibregl-ctrl-attrib { background: rgba(20, 23, 28, .75) !important; color: var(--muted); }
.maplibregl-ctrl-attrib a { color: var(--muted); }

@media (max-width: 700px) {
  #app { flex-direction: column; }
  #side { width: auto; max-height: 42vh; border-right: 0; border-bottom: 1px solid var(--line); }
}

/* ---------------------------------------------------------------- admin drawer */
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(920px, 92vw); z-index: 10;
  background: var(--panel); border-left: 1px solid var(--line); display: flex; flex-direction: column;
  box-shadow: -12px 0 32px rgba(0, 0, 0, .45); }
.drawer-head { display: flex; align-items: center; gap: 14px; padding: 10px 16px; border-bottom: 1px solid var(--line); }
.drawer-head h2 { margin: 0; }
.drawer-head .close { margin-left: auto; font-size: 16px; padding: 4px 10px; }
.tabs { display: flex; gap: 2px; overflow-x: auto; }
.tabs button { background: transparent; border: 0; border-bottom: 2px solid transparent; border-radius: 0; color: var(--muted); }
.tabs button.on { color: var(--text); border-bottom-color: var(--accent); }
.drawer-body { flex: 1; overflow-y: auto; padding: 4px 18px 24px; }
.row { display: flex; align-items: center; gap: 10px; justify-content: space-between; }
.row.end { justify-content: flex-end; margin-top: 14px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { color: var(--muted); font-weight: 500; font-size: 12px; }
tr.off td { color: var(--muted); }
td.acts { display: flex; gap: 2px; flex-wrap: wrap; white-space: normal; }
table.audit td:last-child { white-space: normal; color: var(--muted); }
.tag { margin-left: 6px; font-size: 11px; color: var(--accent); }
.flash { padding: 8px 10px; border-radius: 6px; margin: 12px 0 0; }
.flash.ok { background: rgba(60, 180, 75, .15); border: 1px solid rgba(60, 180, 75, .4); }
.flash.error { background: rgba(255, 90, 95, .12); border: 1px solid rgba(255, 90, 95, .4); color: var(--text); }
.settings { display: grid; gap: 14px; max-width: 560px; }
.setting { display: grid; gap: 4px; }
.setting .lbl { font-weight: 500; }
.setting .check { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.setting .check input { width: auto; margin: 0; }
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; }
.stat { background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; display: grid; gap: 2px; }
.stat .n { font-size: 20px; font-weight: 600; }
.stat .l { font-size: 12px; }
.jobs { display: grid; gap: 8px; }
.job { display: flex; align-items: center; gap: 12px; }
.job button { min-width: 190px; text-align: left; }
.jobstate { font-size: 12px; color: var(--muted); }
.jobstate.running { color: var(--accent); }
.jobstate.failed { color: var(--danger); }

dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 10px;
  padding: 0; width: min(420px, 92vw); }
dialog::backdrop { background: rgba(0, 0, 0, .55); }
.ask { padding: 18px 20px; display: grid; gap: 8px; }
.ask h3 { margin: 0 0 4px; }
.ask label { display: grid; grid-template-columns: 1fr; gap: 4px; }
.ask label > span { font-size: 13px; color: var(--muted); }
.ask label > button { justify-self: start; }
.secret { display: flex; gap: 8px; align-items: center; background: var(--bg); border: 1px solid var(--line);
  border-radius: 6px; padding: 8px 10px; }
.secret code { flex: 1; word-break: break-all; user-select: all; }

@media (max-width: 700px) {
  .drawer { width: 100vw; border-left: 0; }
  .drawer-head { flex-wrap: wrap; }
}
