:root {
  --bg: #f4f7fa; --panel: #ffffff; --ink: #14263a; --muted: #5d6b7a; --line: #d9e1e8;
  --accent: #2366c8; --accent-ink: #ffffff; --ok: #198f5b; --warn: #c9811f; --danger: #c0392b; --purple: #8237b2;
  font-family: "Segoe UI", Tahoma, "Noto Naskh Arabic", system-ui, sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font-size: 15px; line-height: 1.5; }
a { color: var(--accent); }
#topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 16px; background: #123344; color: #fff; flex-wrap: wrap; }
#topbar .brand { color: #fff; text-decoration: none; font-weight: 700; font-size: 18px; }
#nav { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
#nav a, #nav button { color: #fff; background: transparent; border: 1px solid rgba(255,255,255,.35); border-radius: 8px; padding: 6px 12px; text-decoration: none; font-size: 14px; cursor: pointer; }
#nav a.active { background: #42d6b1; color: #123344; border-color: #42d6b1; }
#view { padding: 16px; max-width: 1400px; margin: 0 auto; }
.grid { display: grid; gap: 16px; }
.grid.dash { grid-template-columns: 340px 1fr; }
@media (max-width: 900px) { .grid.dash { grid-template-columns: 1fr; } }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px; }
.panel h2, .panel h3 { margin: 0 0 10px; font-size: 17px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: 10px; }
button, .btn { background: var(--accent); color: var(--accent-ink); border: 0; border-radius: 8px; padding: 8px 14px; font-size: 14px; cursor: pointer; font-family: inherit; }
button.secondary { background: #e9eef3; color: var(--ink); }
button.danger { background: var(--danger); }
button.ok { background: var(--ok); }
button:disabled { opacity: .5; cursor: default; }
input, select, textarea { font-family: inherit; font-size: 15px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; width: 100%; background: #fff; color: var(--ink); }
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.field { margin-bottom: 10px; }
.card.auth { max-width: 420px; margin: 40px auto; }
.map { height: 520px; border-radius: 12px; border: 1px solid var(--line); background: #e7eef1; }
.map.tall { height: 440px; }
.device-list { list-style: none; margin: 0; padding: 0; max-height: 520px; overflow: auto; }
.device-list li { padding: 10px; border-bottom: 1px solid var(--line); cursor: pointer; display: flex; gap: 10px; align-items: flex-start; }
.device-list li:hover, .device-list li.selected { background: #eef4fb; }
.dot { width: 12px; height: 12px; border-radius: 50%; margin-top: 6px; flex: none; background: #9aa5b1; }
.dot.online { background: var(--ok); }
.dot.alert { background: var(--danger); box-shadow: 0 0 0 3px rgba(192,57,43,.25); }
.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; background: #e9eef3; color: var(--ink); }
.badge.admin { background: #fde9c4; } .badge.sos { background: #f8d7d3; color: var(--danger); } .badge.offline { background: #e3e6ea; } .badge.low_battery { background: #fff0c2; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { text-align: right; padding: 6px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; }
.table-wrap { overflow: auto; max-height: 420px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.stat { background: #eef4fb; border-radius: 10px; padding: 10px; }
.stat b { font-size: 24px; display: block; }
#toast { position: fixed; bottom: 20px; inset-inline-start: 20px; background: #123344; color: #fff; padding: 10px 16px; border-radius: 10px; max-width: 420px; z-index: 2000; box-shadow: 0 6px 20px rgba(0,0,0,.25); }
#toast.error { background: var(--danger); }
dialog { border: 0; border-radius: 14px; padding: 20px; max-width: 460px; width: 92vw; }
dialog::backdrop { background: rgba(0,0,0,.4); }
.code { font-family: Consolas, monospace; font-size: 34px; letter-spacing: 3px; text-align: center; direction: ltr; background: #eef4fb; border-radius: 10px; padding: 12px; }
.alert-item { border-inline-start: 4px solid var(--danger); padding: 8px 10px; background: #fff6f5; border-radius: 8px; margin-bottom: 8px; }
.alert-item.offline { border-color: #9aa5b1; background: #f4f6f8; }
.alert-item.low_battery { border-color: var(--warn); background: #fff9e8; }
.legend { font-size: 12px; color: var(--muted); }
.leaflet-container { font-family: inherit; }
.note { background: #fff9e8; border: 1px solid #f3dca0; border-radius: 10px; padding: 10px; font-size: 13px; }
