:root {
  --bg: #f4f6f8; --panel: #ffffff; --line: #dde2e8; --text: #1c2530; --muted: #66727f;
  --accent: #1f6feb; --ok: #1a9c5b; --off: #9aa4af; --warn: #c9770a; --danger: #cc3340;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #12161b; --panel: #1b2129; --line: #2d3641; --text: #e6ebf0; --muted: #93a0ad;
          --accent: #5b9dff; --ok: #3ccf85; --off: #5d6975; --warn: #f0a63a; --danger: #ff6b76; }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { font: 14px/1.45 system-ui, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); }
button, input, select { font: inherit; color: inherit; }
button { background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 6px 12px; cursor: pointer; }
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.danger { color: var(--danger); }
input, select { background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; width: 100%; }
label { display: block; margin: 10px 0 4px; color: var(--muted); font-size: 12px; }
.muted { color: var(--muted); }
.error { color: var(--danger); min-height: 1.4em; margin-top: 8px; }
.hidden { display: none !important; }

/* console layout */
.app { display: grid; grid-template: 52px 1fr / 360px 1fr; height: 100%; }
header { grid-column: 1 / -1; display: flex; align-items: center; gap: 12px; padding: 0 16px;
         background: var(--panel); border-bottom: 1px solid var(--line); }
header h1 { font-size: 16px; margin: 0; }
header .spacer { flex: 1; }
aside { background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.tabs { display: flex; border-bottom: 1px solid var(--line); }
.tabs button { flex: 1; border: 0; border-radius: 0; border-bottom: 2px solid transparent; padding: 10px 2px; background: none; font-size: 13px; white-space: nowrap; }
.tabs button.active { border-bottom-color: var(--accent); color: var(--accent); font-weight: 600; }
.pane { overflow-y: auto; flex: 1; padding: 8px; }
#map { min-height: 0; }

.row { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px; cursor: pointer; }
.row:hover, .row.selected { background: var(--bg); }
.row .grow { flex: 1; min-width: 0; }
.row .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row small { color: var(--muted); display: block; }
.row select { width: auto; }
.row button { flex: none; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--off); flex: none; }
.dot.online { background: var(--ok); }
.dot.paused { background: var(--warn); }

.card { border: 1px solid var(--line); border-radius: 8px; padding: 12px; margin: 8px 2px; }
.card h3 { margin: 0 0 8px; font-size: 15px; }
.kv { display: grid; grid-template-columns: 96px 1fr; gap: 3px 8px; font-size: 13px; }
.kv span:nth-child(odd) { color: var(--muted); }
.actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.inline { display: flex; gap: 6px; align-items: center; margin-top: 8px; }
.inline select, .inline input { width: auto; flex: 1; }
.event { padding: 7px 10px; border-bottom: 1px solid var(--line); font-size: 13px; }
.empty { color: var(--muted); padding: 24px 12px; text-align: center; }

.pin { width: 18px; height: 18px; border-radius: 50%; border: 3px solid #fff; background: var(--off);
       box-shadow: 0 1px 4px rgba(0,0,0,.5); }
.pin.online { background: #1a9c5b; }
.pin.paused { background: #c9770a; }
.pin.selected { outline: 3px solid #1f6feb; }

.overlay { position: fixed; inset: 0; background: var(--bg); display: grid; place-items: center; z-index: 2000; }
.box { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 24px; width: min(380px, 92vw); }
.box h2 { margin: 0 0 6px; }
dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 10px; padding: 20px; width: min(420px, 92vw); }
dialog::backdrop { background: rgba(0,0,0,.45); }
.code { font: 600 26px/1 ui-monospace, Consolas, monospace; letter-spacing: 3px; text-align: center; margin: 12px 0; }
#qr { display: grid; place-items: center; margin: 12px 0; }
#qr img, #qr canvas { background: #fff; padding: 8px; border-radius: 6px; }
.url { word-break: break-all; font-size: 12px; }

/* dashboard (sits over the map) */
#map, #dash { grid-column: 2; grid-row: 2; }
#dash { z-index: 1000; overflow-y: auto; background: var(--bg); padding: 16px; min-height: 0; }
.dhead { display: flex; align-items: baseline; gap: 12px; margin-bottom: 12px; }
.dhead h2 { margin: 0; font-size: 18px; }
#dashGrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; }
.dcard { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 14px; }
.dcard h3 { margin: 0 0 10px; font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 10px; }
.stat .num { font-size: 24px; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat.big .num { font-size: 36px; color: var(--accent); }
.stat.warn .num { color: var(--warn); }
.stat .lbl { color: var(--muted); font-size: 12px; }
.bar { display: grid; grid-template-columns: 96px 1fr 32px; gap: 8px; align-items: center; margin: 6px 0; font-size: 13px; }
.bname { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.track { background: var(--bg); border-radius: 4px; height: 10px; }
.fill { background: var(--accent); border-radius: 4px; height: 10px; }
.bnum { text-align: right; font-variant-numeric: tabular-nums; }

/* android control */
textarea { font: 12px/1.4 ui-monospace, Consolas, monospace; color: inherit; background: var(--bg);
           border: 1px solid var(--line); border-radius: 6px; padding: 8px; width: 100%; resize: vertical; }
dialog.wide { width: min(640px, 94vw); max-height: 92vh; overflow-y: auto; }
.toggles { display: grid; grid-template-columns: 1fr 1fr; gap: 2px 12px; }
label.check { display: flex; gap: 8px; align-items: center; color: var(--text); font-size: 13px; margin: 4px 0; }
label.check input { width: auto; }
.steps { margin: 6px 0; padding-left: 20px; font-size: 13px; }
.steps li { margin: 4px 0; }
.qrbox { display: grid; place-items: center; margin: 12px 0; }
.qrbox img, .qrbox canvas { background: #fff; padding: 10px; border-radius: 6px; }
@media (max-width: 520px) { .toggles { grid-template-columns: 1fr; } }

/* agent */
.agent { max-width: 460px; margin: 0 auto; padding: 16px; }
.agent h1 { font-size: 20px; }
.notice { border-left: 3px solid var(--accent); background: var(--panel); padding: 10px 12px; border-radius: 4px; font-size: 13px; }
.notice.warn { border-left-color: var(--warn); }
.big { font-size: 18px; font-weight: 600; display: flex; align-items: center; gap: 10px; }
.agent button { width: 100%; padding: 11px; margin-top: 10px; }
.msg { border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 10px; margin-top: 8px; }

@media (max-width: 760px) {
  .app { grid-template: 52px 45vh 1fr / 1fr; }
  aside { grid-row: 3; border-right: 0; border-top: 1px solid var(--line); }
  #map, #dash { grid-row: 2; grid-column: 1; }
}
