:root {
  --bg: #f3f5f9;
  --surface: #ffffff;
  --surface-2: #f0f3f8;
  --text: #1c2230;
  --muted: #667085;
  --border: #e2e6ee;
  --primary: #1a73e8;
  --primary-ink: #ffffff;
  --ok: #188038;
  --ok-bg: #e6f4ea;
  --warn: #b06000;
  --warn-bg: #fef3e0;
  --bad: #c5221f;
  --bad-bg: #fce8e6;
  --off: #5f6368;
  --off-bg: #eceff3;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 4px 14px rgba(16, 24, 40, .06);
  --radius: 14px;
  --nav-h: 62px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1218; --surface: #181d27; --surface-2: #212836; --text: #e8ebf2; --muted: #9aa3b5;
    --border: #2b3345; --primary: #6ea8fe; --primary-ink: #0b1220;
    --ok: #81c995; --ok-bg: #16301f; --warn: #fdd663; --warn-bg: #3a2f12; --bad: #f28b82; --bad-bg: #3d1a18;
    --off: #aab1bf; --off-bg: #262d3b; --shadow: 0 1px 2px rgba(0, 0, 0, .4);
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
h1 { font-size: 24px; margin: 8px 0; }
h2 { font-size: 17px; margin: 0 0 10px; }
h3 { font-size: 14px; margin: 0 0 8px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
a { color: var(--primary); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.error { color: var(--bad); min-height: 1.4em; }
.center-screen { min-height: 100%; display: flex; align-items: center; justify-content: center; padding: 20px; }
.spinner { width: 34px; height: 34px; border: 3px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- login ---------- */
.login-card { background: var(--surface); border-radius: 20px; box-shadow: var(--shadow); padding: 32px 26px; max-width: 380px; width: 100%; text-align: center; }
.login-card .logo { border-radius: 18px; }
#gbtn { display: flex; justify-content: center; margin: 22px 0 6px; min-height: 44px; }

/* ---------- layout ---------- */
#app { height: 100%; display: flex; flex-direction: column-reverse; }
#nav {
  display: flex; background: var(--surface); border-top: 1px solid var(--border);
  padding-bottom: var(--safe-b); z-index: 5;
}
#nav .brand { display: none; }
#nav a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  height: var(--nav-h); color: var(--muted); text-decoration: none; font-size: 12px; font-weight: 500;
}
#nav a svg { width: 24px; height: 24px; fill: currentColor; }
#nav a.active { color: var(--primary); }

#main { flex: 1; min-height: 0; display: flex; flex-direction: column; }
#mapPane { position: relative; height: 42vh; min-height: 230px; flex: none; background: var(--surface-2); }
#map { position: absolute; inset: 0; }
.map-msg { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; text-align: center; padding: 24px; color: var(--muted); }
#panel { flex: 1; min-height: 0; overflow-y: auto; padding: 14px; -webkit-overflow-scrolling: touch; }
body[data-view="recharge"] #mapPane, body[data-view="settings"] #mapPane { display: none; }

@media (min-width: 900px) {
  #app { flex-direction: row; }
  #nav { flex-direction: column; width: 210px; border-top: 0; border-right: 1px solid var(--border); padding: 14px 10px; gap: 4px; }
  #nav .brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; padding: 6px 10px 18px; }
  #nav .brand img { border-radius: 7px; }
  #nav a { flex: none; flex-direction: row; justify-content: flex-start; gap: 12px; height: 44px; padding: 0 12px; border-radius: 10px; font-size: 15px; }
  #nav a.active { background: color-mix(in srgb, var(--primary) 14%, transparent); }
  #main { flex-direction: row; }
  #mapPane { flex: 1; height: auto; min-height: 0; }
  #panel { flex: none; width: 400px; border-left: 1px solid var(--border); background: var(--bg); padding: 18px; }
  body[data-view="recharge"] #panel, body[data-view="settings"] #panel { width: 100%; max-width: 780px; margin: 0 auto; border: 0; }
}

/* ---------- components ---------- */
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 14px; }
.card.flush { padding: 0; overflow: hidden; }
.row { display: flex; align-items: center; gap: 10px; }
.row.between { justify-content: space-between; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.stack > * + * { margin-top: 10px; }

.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 12px; scrollbar-width: none; }
.chip {
  flex: none; border: 1px solid var(--border); background: var(--surface); color: var(--text);
  border-radius: 999px; padding: 7px 14px; font: inherit; font-size: 14px; cursor: pointer;
}
.chip.active { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }

.badge { display: inline-flex; align-items: center; gap: 5px; border-radius: 999px; padding: 3px 10px; font-size: 12.5px; font-weight: 600; background: var(--off-bg); color: var(--off); white-space: nowrap; }
.badge::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.bad { background: var(--bad-bg); color: var(--bad); }
.badge.plain::before { display: none; }

.speed { font-size: 44px; font-weight: 700; line-height: 1; letter-spacing: -.02em; }
.speed small { font-size: 16px; font-weight: 500; color: var(--muted); letter-spacing: 0; }

dl.kv { margin: 14px 0 0; display: grid; grid-template-columns: auto 1fr; gap: 8px 14px; font-size: 14px; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; text-align: right; overflow-wrap: anywhere; }

.btn {
  appearance: none; border: 1px solid var(--border); background: var(--surface); color: var(--text);
  border-radius: 10px; padding: 9px 14px; font: inherit; font-weight: 600; cursor: pointer; min-height: 40px;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; text-decoration: none;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--bad); }
.btn.sm { min-height: 32px; padding: 4px 10px; font-size: 13px; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.btn.block { width: 100%; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }

label.field { display: block; font-size: 13px; color: var(--muted); font-weight: 600; }
label.field > input, label.field > select, label.field > textarea { margin-top: 5px; }
input[type=text], input[type=number], input[type=date], input[type=datetime-local], input[type=tel], select {
  width: 100%; font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: 9px 12px; min-height: 42px;
}
input:focus, select:focus, .btn:focus-visible, .chip:focus-visible, a:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.grid2.narrow { grid-template-columns: minmax(0, 1fr); } /* date-time inputs need the full width */
input[type=datetime-local] { min-width: 0; }

.switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 9px 0; cursor: pointer; }
.switch input { appearance: none; width: 44px; height: 26px; border-radius: 13px; background: var(--border); position: relative; flex: none; transition: background .15s; cursor: pointer; }
.switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 2px rgba(0, 0, 0, .3); }
.switch input:checked { background: var(--primary); }
.switch input:checked::after { transform: translateX(18px); }

.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.stat { background: var(--surface-2); border-radius: 12px; padding: 10px 12px; }
.stat b { display: block; font-size: 20px; }
.stat span { color: var(--muted); font-size: 12.5px; }

.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; align-items: center; gap: 12px; padding: 11px 16px; border-top: 1px solid var(--border); }
.list li:first-child { border-top: 0; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--off); flex: none; }
.dot.ok { background: var(--ok); } .dot.bad { background: var(--bad); } .dot.warn { background: var(--warn); }

.bar { height: 8px; border-radius: 4px; background: var(--surface-2); overflow: hidden; margin-top: 10px; }
.bar > i { display: block; height: 100%; background: var(--ok); border-radius: 4px; }
.bar.warn > i { background: var(--warn); } .bar.bad > i { background: var(--bad); }
.big-days { font-size: 40px; font-weight: 700; line-height: 1; }

input[type=range] { width: 100%; accent-color: var(--primary); }
.empty { text-align: center; padding: 30px 10px; color: var(--muted); }
.empty h2 { color: var(--text); }
.bars { display: inline-flex; gap: 2px; align-items: flex-end; height: 14px; vertical-align: -2px; }
.bars i { width: 4px; background: var(--border); border-radius: 1px; }
.bars i.on { background: var(--ok); }

/* ---------- map markers ---------- */
.pin { display: flex; flex-direction: column; align-items: center; transform: translateY(0); }
.pin .disc { width: 38px; height: 38px; border-radius: 50%; background: #80868b; border: 3px solid #fff; box-shadow: 0 2px 8px rgba(0, 0, 0, .4); display: flex; align-items: center; justify-content: center; }
.pin.on .disc { background: #1e8e3e; }
.pin.off .disc { background: #f9ab00; }
.pin.off svg { fill: #4a3500; }
.pin.offline .disc { opacity: .65; }
.pin svg { width: 20px; height: 20px; fill: #fff; transition: transform .4s; }
.pin .tag { margin-top: 3px; background: rgba(0, 0, 0, .72); color: #fff; font-size: 11px; font-weight: 600; padding: 1px 7px; border-radius: 8px; white-space: nowrap; }
.dotmark { width: 16px; height: 16px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 1px 5px rgba(0, 0, 0, .5); background: var(--primary); }
.dotmark.start { background: #188038; } .dotmark.end { background: #d93025; }

/* ---------- toasts ---------- */
#toasts { position: fixed; left: 0; right: 0; top: calc(10px + env(safe-area-inset-top, 0px)); display: flex; flex-direction: column; align-items: center; gap: 8px; z-index: 50; pointer-events: none; padding: 0 12px; }
.toast { pointer-events: auto; background: #202634; color: #fff; padding: 11px 16px; border-radius: 12px; box-shadow: 0 6px 24px rgba(0, 0, 0, .3); max-width: 440px; width: fit-content; animation: pop .2s ease-out; }
.toast.error { background: #b3261e; }
.toast.ok { background: #146c2e; }
@keyframes pop { from { opacity: 0; transform: translateY(-8px); } }

@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

.list li.tap { cursor: pointer; }
.list li.tap:hover, .list li.tap:focus-visible { background: var(--surface-2); outline: none; }
.legend { display: flex; gap: 16px; margin-top: 12px; font-size: 13px; color: var(--muted); }
.legend i { display: inline-block; width: 18px; height: 6px; border-radius: 3px; margin-right: 6px; vertical-align: middle; }
.stopmark { background: #f9ab00; color: #3c2a00; font-size: 12px; font-weight: 700; padding: 3px 8px; border-radius: 10px; border: 2px solid #fff; box-shadow: 0 1px 5px rgba(0, 0, 0, .45); white-space: nowrap; }
.stopmark.idle { background: #1e8e3e; color: #fff; }
.dot.warn { background: #f9ab00; }
.dot.ok { background: #1e8e3e; }
