:root{
  --bg:#0f172a; --panel:#1e293b; --border:#334155; --text:#e2e8f0;
  --muted:#94a3b8; --accent:#38bdf8; --blue:#2563eb; --green:#16a34a;
  --red:#dc2626; --amber:#f59e0b;
}
*{box-sizing:border-box}
html,body{margin:0;height:100%}
body{font-family:system-ui,"Segoe UI",Arial,sans-serif;background:var(--bg);color:var(--text)}

/* ---- Auth ---- */
.auth-body{display:flex;align-items:center;justify-content:center;min-height:100vh}
.auth-card{background:var(--panel);border:1px solid var(--border);border-radius:16px;
  padding:32px;width:min(360px,92vw);display:flex;flex-direction:column;gap:14px}
.auth-card h1{margin:0;color:var(--accent)}
.auth-card label{display:flex;flex-direction:column;gap:6px;font-size:14px;color:var(--muted)}
.auth-card input{padding:10px 12px;border-radius:8px;border:1px solid var(--border);
  background:var(--bg);color:var(--text);font-size:15px}
button{cursor:pointer;background:var(--blue);color:#fff;border:none;padding:10px 16px;
  border-radius:8px;font-size:15px}
button:hover{filter:brightness(1.1)}

/* ---- Topbar ---- */
.topbar{display:flex;align-items:center;justify-content:space-between;
  background:var(--panel);border-bottom:1px solid var(--border);padding:10px 20px}
.brand{font-weight:700;font-size:18px}
.topbar nav a{color:var(--muted);text-decoration:none;margin-left:18px;font-size:14px}
.topbar nav a:hover,.topbar nav a.active{color:var(--accent)}

/* ---- Layout ---- */
.layout{display:flex;height:calc(100vh - 53px)}
.sidebar{width:300px;background:var(--panel);border-right:1px solid var(--border);
  display:flex;flex-direction:column;padding:16px;overflow-y:auto}
.sidebar-head{display:flex;justify-content:space-between;align-items:baseline}
.sidebar h2{margin:0 0 10px}
#map{flex:1;height:100%}

/* ---- Car list ---- */
.car-list{list-style:none;margin:0;padding:0;flex:1}
.car-item{display:flex;align-items:center;gap:10px;padding:10px;border-radius:10px;
  cursor:pointer;border:1px solid transparent}
.car-item:hover{background:var(--bg)}
.car-item.selected{border-color:var(--accent);background:var(--bg)}
.car-item .swatch{width:12px;height:12px;border-radius:50%;flex:0 0 auto}
.car-item .info{flex:1;min-width:0}
.car-item .name{font-weight:600;font-size:14px}
.car-item .meta{font-size:12px;color:var(--muted);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}

.pulse{display:inline-block;width:9px;height:9px;border-radius:50%;vertical-align:middle}
.pulse.live{background:var(--green);box-shadow:0 0 0 0 rgba(22,163,74,.6);animation:pulse 1.6s infinite}
.pulse.stale{background:#64748b}
@keyframes pulse{to{box-shadow:0 0 0 8px rgba(22,163,74,0)}}

.legend{display:flex;gap:14px;margin-top:12px;padding-top:12px;border-top:1px solid var(--border)}
.legend span{display:flex;align-items:center;gap:6px}

/* ---- Generic pages ---- */
.page{max-width:1000px;margin:24px auto;padding:0 20px}
.panel{background:var(--panel);border:1px solid var(--border);border-radius:14px;padding:20px;margin-bottom:20px}
.panel h2{margin-top:0}
.inline-form{display:flex;gap:10px;flex-wrap:wrap;align-items:center}
.inline-form input[type=text]{flex:1;min-width:160px;padding:10px 12px;border-radius:8px;
  border:1px solid var(--border);background:var(--bg);color:var(--text)}
.inline-form input[type=color]{width:44px;height:40px;border:1px solid var(--border);
  border-radius:8px;background:var(--bg);padding:2px}

.table-wrap{overflow-x:auto}
table{width:100%;border-collapse:collapse;font-size:14px}
th,td{text-align:left;padding:10px;border-bottom:1px solid var(--border);vertical-align:top}
th{color:var(--muted);font-weight:600}
.key{font-size:12px;word-break:break-all;color:var(--accent)}
.dot{display:inline-block;width:16px;height:16px;border-radius:50%}
.badge{padding:2px 8px;border-radius:20px;font-size:12px}
.badge.on{background:rgba(22,163,74,.2);color:#4ade80}
.badge.off{background:rgba(100,116,139,.25);color:#94a3b8}
.actions{display:flex;gap:6px;flex-wrap:wrap}
.actions form{margin:0}
.small-btn{background:var(--bg);border:1px solid var(--border);color:var(--text);
  padding:6px 10px;font-size:12px}
.small-btn.danger{border-color:var(--red);color:#fca5a5}

.alert{background:rgba(220,38,38,.15);border:1px solid var(--red);color:#fca5a5;
  padding:10px 14px;border-radius:8px;margin-bottom:14px}
.alert.ok{background:rgba(22,163,74,.15);border-color:var(--green);color:#86efac}

.muted{color:var(--muted)}
.small{font-size:12px}

/* Leaflet popup dark tweak */
.leaflet-popup-content{font-family:system-ui,sans-serif}
.car-popup b{font-size:14px}
.car-popup .row{font-size:12px;color:#475569;margin-top:2px}

@media(max-width:640px){
  .sidebar{width:100%;height:auto;max-height:38vh}
  .layout{flex-direction:column;height:calc(100vh - 53px)}
}
