:root {
  --bg: #0b1220;
  --panel: #101c2e;
  --panel2: #16243a;
  --line: #22314a;
  --line2: #2a3b55;
  --text: #e8eef8;
  --muted: #93a4bd;
  --green: #22c55e;
  --blue: #38bdf8;
  --amber: #facc15;
  --red: #f87171;
  --purple: #a855f7;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  overflow: hidden;
}
.hidden { display: none !important; }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: #2e4066; border-radius: 8px; }
::-webkit-scrollbar-track { background: transparent; }

/* ---------- login ---------- */
.login {
  height: 100%; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(900px 500px at 50% 0%, #14233a 0%, var(--bg) 70%);
  padding: 20px;
}
.login-card {
  width: min(380px, 94vw); background: var(--panel); border: 1px solid var(--line);
  border-radius: 18px; padding: 28px; box-shadow: 0 24px 70px rgba(0,0,0,.55);
}
.brandmark {
  width: 46px; height: 46px; border-radius: 14px;
  background: radial-gradient(circle at 30% 30%, #7dd3fc, #1d4ed8);
  box-shadow: 0 0 0 6px rgba(56,189,248,.10); margin-bottom: 16px;
}
.login-card h1 { font-size: 24px; margin: 0 0 4px; letter-spacing: .2px; }
.login-card p { color: var(--muted); font-size: 12.5px; margin: 0 0 20px; }
.field { display: block; font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; margin-bottom: 12px; }
.field input {
  display: block; width: 100%; margin-top: 5px; padding: 10px 11px;
  background: #0b1729; border: 1px solid var(--line2); border-radius: 9px;
  color: var(--text); font: inherit; font-size: 14px;
}
.field input:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px rgba(56,189,248,.15); }
.login-error { color: var(--red); font-size: 12px; min-height: 18px; margin-top: 10px; }

/* ---------- botones ---------- */
.btn {
  border: 1px solid var(--line2); border-radius: 8px; background: #14233a;
  color: #dbe6f7; padding: 8px 11px; font: inherit; font-size: 12px; font-weight: 700;
  cursor: pointer;
}
.btn:hover { background: #1b2d49; }
a.btn { text-decoration: none; display: inline-flex; align-items: center; }
.btn.primary { background: var(--green); border-color: var(--green); color: #052e16; }
.btn.primary:hover { background: #16a34a; }
.btn.ghost { background: transparent; color: var(--muted); }
.btn.ghost:hover { color: #fff; background: #14233a; }
.btn.wide { width: 100%; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.mini {
  border: 1px solid var(--line2); border-radius: 7px; background: #0e1b2e;
  color: #c7d3e6; padding: 5px 8px; font: inherit; font-size: 11px; font-weight: 700;
  cursor: pointer; white-space: nowrap;
}
.mini:hover { background: #1a2c46; }
.mini.ok { border-color: #166534; color: #86efac; background: #052e16; }
.mini.danger { border-color: #5a3a3a; color: var(--red); background: transparent; }
.x { background: transparent; border: 0; color: var(--muted); font-size: 20px; line-height: 1; cursor: pointer; padding: 0 4px; }
.x:hover { color: #fff; }

/* ---------- estructura ---------- */
.app { height: 100vh; display: flex; flex-direction: column; }
.topbar {
  height: 60px; flex: none; display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px; background: #0d1727; border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 11px; }
.dotlogo { width: 32px; height: 32px; border-radius: 50%; background: radial-gradient(circle at 30% 30%, #38bdf8, #1d4ed8); box-shadow: 0 0 0 4px rgba(56,189,248,.12); }
.t1 { font-size: 18px; font-weight: 800; letter-spacing: .3px; }
.t2 { font-size: 12px; color: var(--muted); margin-top: 1px; }
.top-actions { display: flex; align-items: center; gap: 14px; }
.clock { font-size: 18px; font-weight: 800; font-variant-numeric: tabular-nums; color: var(--muted); }
.layout { flex: 1; display: grid; grid-template-columns: 430px minmax(0, 1fr); min-height: 0; }
.side { display: flex; flex-direction: column; min-height: 0; background: var(--panel); border-right: 1px solid var(--line); }

/* ---------- tabs y vistas ---------- */
.tabs { display: flex; gap: 6px; padding: 8px 10px 0; flex: none; }
.tab {
  flex: 1; padding: 9px 4px; border: 1px solid transparent; border-radius: 8px 8px 0 0;
  background: transparent; color: #8fa1bb; font: inherit; font-size: 12px; font-weight: 700; cursor: pointer;
}
.tab.active { background: var(--panel2); border-color: var(--line); border-bottom-color: var(--panel2); color: #fff; }
.view { flex: 1; min-height: 0; overflow: auto; padding: 0 0 12px; }
.view-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 14px 10px; }
.view-head h2 { font-size: 16px; margin: 0; }

/* ---------- cola ---------- */
.next-card {
  padding: 13px 14px 14px;
  background: linear-gradient(180deg, #14281f 0%, var(--panel) 100%);
  border-bottom: 1px solid var(--line);
}
.eyebrow { font-size: 10.5px; letter-spacing: 1.4px; font-weight: 800; color: #7dd3a8; }
.next-car { font-size: 32px; font-weight: 900; line-height: 1.1; margin-top: 2px; }
.next-sub { font-size: 12.5px; color: #a9b8cf; margin-top: 2px; min-height: 18px; }
.queue-list { background: var(--panel); }
.queue-row {
  display: grid; grid-template-columns: 52px 1fr auto; gap: 10px; align-items: center;
  padding: 9px 12px; border-bottom: 1px solid #1b2a41;
}
.queue-row.first { background: #122a1e; border-left: 4px solid var(--green); }
.pos { font-size: 24px; font-weight: 900; color: #4ade80; text-align: center; font-variant-numeric: tabular-nums; }
.qcar { font-size: 17px; font-weight: 800; }
.qsub { font-size: 11.5px; color: var(--muted); margin-top: 2px; }
.qbtns { display: flex; flex-direction: column; gap: 5px; }
.section-title { font-size: 10.5px; letter-spacing: 1.3px; color: #7c8ca6; font-weight: 800; padding: 12px 14px 6px; }
.out-row {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 7px 14px; border-bottom: 1px solid #17253a; font-size: 12px;
}
.out-row .onum { font-weight: 800; font-size: 13px; margin-right: 7px; }
.chip { font-size: 10px; font-weight: 800; padding: 2px 7px; border-radius: 99px; border: 1px solid; white-space: nowrap; }
.chip.q { color: #86efac; border-color: #166534; background: #052e16; }
.chip.o { color: #94a3b8; border-color: #334155; background: #0f172a; }
.chip.s { color: #fcd34d; border-color: #b45309; background: #3b2506; }
.chip.b { color: #fca5a5; border-color: #991b1b; background: #3b0a0a; }
.alerts { padding: 10px 14px; }
.alert { font-size: 11.5px; color: #fcd34d; background: #2a1f06; border: 1px solid #4a3a0a; border-radius: 8px; padding: 7px 9px; margin-top: 6px; }
.alert.gray { color: var(--muted); background: #0f1a2b; border-color: var(--line); }
.empty { color: #5b6b85; font-size: 12px; padding: 14px; font-style: italic; }

/* ---------- conductores ---------- */
.driver-row { display: flex; align-items: center; gap: 10px; padding: 9px 14px; border-bottom: 1px solid #17253a; }
.dnum { width: 46px; font-size: 15px; font-weight: 900; color: var(--blue); font-variant-numeric: tabular-nums; }
.dinfo { flex: 1; min-width: 0; }
.dname { font-size: 13.5px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dsub { font-size: 10.5px; color: var(--muted); margin-top: 2px; }
.dbtns { display: flex; gap: 5px; }

/* ---------- bases ---------- */
.base-row { display: flex; align-items: center; gap: 10px; padding: 9px 14px; border-bottom: 1px solid #17253a; }
.bdot { width: 13px; height: 13px; border-radius: 50%; border: 2px solid rgba(255,255,255,.6); flex: none; }
.binfo { flex: 1; min-width: 0; }
.bname { font-size: 13.5px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bsub { font-size: 10.5px; color: var(--muted); margin-top: 2px; }
.bbtns { display: flex; gap: 5px; }

/* ---------- historial ---------- */
.hist-row { display: flex; gap: 8px; padding: 6px 14px; border-bottom: 1px solid #17253a; font-size: 11.5px; }
.hist-time { color: #6b7d97; flex: 0 0 58px; font-variant-numeric: tabular-nums; }
.hist-text { color: #c7d3e6; }

/* ---------- mapa ---------- */
.map-wrap { position: relative; min-width: 0; min-height: 0; }
#map { position: absolute; inset: 0; background: var(--bg); }
.leaflet-popup-content-wrapper, .leaflet-popup-tip { background: #16243a; color: var(--text); border: 1px solid var(--line2); }
.leaflet-container a.leaflet-popup-close-button { color: var(--muted); }

.base-tag {
  display: flex; align-items: center; justify-content: center; gap: 5px;
  height: 24px; background: #1e3a8a; border: 1px solid #60a5fa; color: #e0f2fe;
  font-size: 11px; font-weight: 800; padding: 2px 7px; border-radius: 6px;
  white-space: nowrap; box-shadow: 0 2px 6px rgba(0,0,0,.45);
}
.base-tag .dot { width: 7px; height: 7px; border-radius: 50%; flex: none; }
.base-icon { background: transparent !important; border: 0 !important; }

.car-mark { background: transparent !important; border: 0 !important; }
.car-marker { position: relative; width: 42px; height: 42px; }
.car-dot {
  width: 42px; height: 42px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
  font-weight: 900; font-size: 17px; color: #fff; border: 3px solid #fff;
  box-shadow: 0 2px 8px rgba(0,0,0,.55); font-variant-numeric: tabular-nums;
}
.car-marker.q .car-dot { background: #16a34a; }
.car-marker.o .car-dot { background: #64748b; }
.car-marker.s .car-dot { background: #d97706; }
.car-badge {
  position: absolute; top: -7px; right: -7px; min-width: 22px; height: 22px; padding: 0 4px;
  border-radius: 11px; background: var(--amber); color: #111827; font-weight: 900; font-size: 11px;
  display: flex; align-items: center; justify-content: center; border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,.5);
}

/* ---------- dibujo de bases ---------- */
body.drawing #map { cursor: crosshair; }
body.drawing .leaflet-interactive { pointer-events: none; }
body.drawing .vertex-marker { pointer-events: auto; cursor: grab; }
.vertex { width: 15px; height: 15px; border-radius: 50%; border: 2.5px solid #fff; box-shadow: 0 1px 5px rgba(0,0,0,.7); cursor: grab; }
.vertex:active { cursor: grabbing; }
.vertex-marker { background: transparent !important; border: 0 !important; }
.draw-panel {
  position: absolute; top: 12px; right: 12px; width: 300px; z-index: 1200;
  background: rgba(22,36,58,.98); border: 1px solid var(--line2); border-radius: 12px;
  padding: 12px; box-shadow: 0 12px 32px rgba(0,0,0,.55);
}
.draw-head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.draw-head span:first-child { font-size: 13px; font-weight: 800; }
.count { margin-left: auto; font-size: 10.5px; font-weight: 800; color: var(--amber); background: rgba(250,204,21,.13); border: 1px solid rgba(250,204,21,.35); border-radius: 99px; padding: 2px 8px; white-space: nowrap; }
.field-label { font-size: 10.5px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; margin: 8px 0 4px; }
.palette { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 4px; }
.swatch { width: 22px; height: 22px; border-radius: 50%; border: 2px solid transparent; cursor: pointer; padding: 0; }
.swatch.active { border-color: #fff; box-shadow: 0 0 0 2px rgba(255,255,255,.25); }
.hint { font-size: 10.5px; line-height: 1.45; color: var(--muted); margin: 7px 0; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; margin-top: 7px; }

/* ---------- modal ---------- */
.modal { position: fixed; inset: 0; z-index: 3000; display: flex; align-items: center; justify-content: center; padding: 20px; background: rgba(3,8,16,.72); backdrop-filter: blur(3px); }
.modal-card { width: min(400px, 94vw); background: var(--panel); border: 1px solid var(--line2); border-radius: 15px; padding: 18px; box-shadow: 0 24px 70px rgba(0,0,0,.7); }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.modal-head h3 { font-size: 16px; margin: 0; }

/* ---------- toast ---------- */
.toast {
  position: absolute; left: 14px; bottom: 22px; z-index: 1400; width: min(340px, calc(100% - 28px));
  background: rgba(22,36,58,.98); border: 1px solid var(--line2); border-left: 4px solid var(--blue);
  border-radius: 10px; padding: 10px 13px; box-shadow: 0 14px 38px rgba(0,0,0,.6);
  opacity: 0; transform: translateY(10px); pointer-events: none; transition: opacity .18s ease, transform .18s ease;
}
.toast.visible { opacity: 1; transform: none; }
.toast.ok { border-left-color: var(--green); }
.toast.bad { border-left-color: var(--red); }
.toast-title { font-weight: 800; font-size: 12.5px; }
.toast-msg { font-size: 11.5px; color: var(--muted); line-height: 1.4; margin-top: 2px; }

@media (max-width: 1100px) {
  .layout { grid-template-columns: 380px minmax(0, 1fr); }
}
@media (max-width: 820px) {
  html, body { overflow: auto; }
  .app { height: auto; min-height: 100vh; }
  .layout { grid-template-columns: 1fr; }
  .side { border-right: 0; border-bottom: 1px solid var(--line); }
  .map-wrap { min-height: 480px; }
}
