/* Estilos de la plataforma. Los colores de marca vienen de config.js */
:root {
  --primary: #0D9488;
  --primary-dark: #0E1B2C;
  --accent: #f59e0b;
  --bg: #F8FAFC;
  --surface: #ffffff;
  --surface-2: #f8fafb;
  --text: #0E1B2C;
  --muted: #475569;
  --line: #e2e7ec;
  --ok: #16a34a;
  --warn: #d97706;
  --danger: #dc2626;
  --offline: #94a3b8;
  --radius: 10px;
  --shadow: 0 6px 24px rgba(15, 30, 45, .10);
  --panel-w: 380px;
  --top-h: 56px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1418; --surface: #151d23; --surface-2: #1b252c; --text: #e6edf2; --muted: #93a3b0;
    --line: #26323b; --shadow: 0 6px 24px rgba(0, 0, 0, .4); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0e1418; --surface: #151d23; --surface-2: #1b252c; --text: #e6edf2; --muted: #93a3b0;
  --line: #26323b; --shadow: 0 6px 24px rgba(0, 0, 0, .4); color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; background: var(--bg); color: var(--text); }
[hidden] { display: none !important; }
a { color: var(--primary); }
h2 { font-size: 18px; margin: 0; }
h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 18px 0 8px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.error { color: var(--danger); }
.grow { flex: 1; min-width: 0; }

/* Controles */
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface); width: 100%;
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; outline: none;
}
input:focus, select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 20%, transparent); }
input[type=checkbox] { width: auto; accent-color: var(--primary); }
input[type=color] { padding: 2px; height: 38px; }
input[type=range] { accent-color: var(--primary); padding: 0; border: 0; }
select[multiple] { padding: 4px; }
.field { display: flex; flex-direction: column; gap: 4px; margin: 8px 0; }
.field > span { font-size: 12px; font-weight: 600; color: var(--muted); }
.field small { color: var(--muted); font-size: 11px; }
.check { display: flex; align-items: center; gap: 8px; padding: 4px 0; cursor: pointer; }
.check-list { max-height: 180px; overflow: auto; border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; background: var(--surface-2); }
.check-list.tall { max-height: 220px; }
.grid2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 0 10px; }
.grid2 > *, .grid3 > * { min-width: 0; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1.4fr; gap: 0 16px; align-items: start; }

.btn {
  font: inherit; font-weight: 600; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 14px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); color: var(--text);
  cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { border-color: var(--primary); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dark); }
.btn.danger { color: var(--danger); }
.btn.danger:hover { border-color: var(--danger); }
.modal .btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.small { padding: 5px 10px; font-size: 12px; }
.btn.block { width: 100%; margin-top: 10px; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 10px 0; }
.btn-row.nowrap { flex-wrap: nowrap; margin: 0; }
.icon-btn { background: none; border: 0; font-size: 16px; cursor: pointer; color: var(--muted); padding: 6px; border-radius: 6px; position: relative; }
.icon-btn:hover { background: var(--surface-2); }
.link { background: none; border: 0; padding: 0; font: inherit; color: var(--text); text-align: left; cursor: pointer; font-weight: 600; }
.link:hover { color: var(--primary); }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; }
.note { margin-top: 16px; background: var(--surface-2); font-size: 13px; }

/* Login */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px 16px;
  background: radial-gradient(1200px 600px at 10% -10%, color-mix(in srgb, var(--primary) 28%, transparent), transparent),
              linear-gradient(160deg, var(--primary-dark), #0b1720); }
.login-card { width: 100%; max-width: 380px; background: var(--surface); border-radius: 16px; padding: 32px 28px; box-shadow: var(--shadow); text-align: center; }
.login-card form { text-align: left; margin-top: 18px; }
.login-logo { width: 64px; height: 64px; }
.login-logo.wide { width: 260px; max-width: 100%; height: auto; margin-bottom: 4px; }
.login-card h1 { margin: 12px 0 4px; font-size: 22px; }
.login-foot { margin-top: 20px; }
.setup-note { background: color-mix(in srgb, var(--accent) 18%, transparent); border-radius: 8px; padding: 8px 10px; font-size: 13px; margin: 0 0 6px; }

/* Barra superior */
.topbar { height: var(--top-h); display: flex; align-items: center; gap: 16px; padding: 0 14px;
  background: var(--primary-dark); color: #fff; position: relative; z-index: 1001; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; white-space: nowrap; }
.brand img { width: 32px; height: 32px; border-radius: 8px; }
.brand img.wide { width: auto; height: 40px; border-radius: 0; }
#nav { display: flex; gap: 2px; flex: 1; overflow-x: auto; scrollbar-width: none; }
#nav a { color: rgba(255,255,255,.78); text-decoration: none; padding: 8px 12px; border-radius: 8px; display: flex; gap: 6px; align-items: center; font-weight: 600; white-space: nowrap; }
#nav a:hover { background: rgba(255,255,255,.08); color: #fff; }
#nav a.active { background: rgba(255,255,255,.16); color: #fff; }
.nav-ico { font-size: 15px; }
.top-right { display: flex; align-items: center; gap: 6px; }
.top-right .icon-btn { color: #fff; }
.top-right .icon-btn:hover { background: rgba(255,255,255,.1); }
#bell-count { position: absolute; top: 0; right: -2px; background: var(--accent); color: #111; font-size: 10px; border-radius: 9px; padding: 0 5px; }
.user-btn { background: rgba(255,255,255,.12); color: #fff; border: 0; border-radius: 8px; padding: 6px 10px; font: inherit; font-weight: 600; cursor: pointer; max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conn { width: 9px; height: 9px; border-radius: 50%; background: var(--offline); display: inline-block; }
.conn.ok { background: #4ade80; box-shadow: 0 0 0 3px rgba(74,222,128,.25); }
.conn.off { background: var(--danger); }

/* Distribución principal */
#app { height: 100%; display: flex; flex-direction: column; }
#main { flex: 1; display: flex; min-height: 0; position: relative; }
#panel { width: var(--panel-w); flex: none; background: var(--surface); border-right: 1px solid var(--line); overflow-y: auto; padding: 14px 16px 24px; z-index: 500; }
#map { flex: 1; min-width: 0; background: #dfe5ea; }
#main.wide #panel { width: 100%; border-right: 0; padding: 18px 24px 40px; background: var(--bg); }
#main.wide #map { position: absolute; inset: 0; visibility: hidden; pointer-events: none; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }

/* Lista de unidades */
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0; }
.chip { font: inherit; font-size: 12px; font-weight: 600; border: 1px solid var(--line); background: var(--surface); color: var(--text); border-radius: 999px; padding: 4px 10px; cursor: pointer; display: inline-flex; gap: 6px; align-items: center; }
.chip b { color: var(--muted); font-weight: 700; }
.chip.on { background: var(--primary); border-color: var(--primary); color: #fff; }
.chip.on b { color: rgba(255,255,255,.85); }
.dev-list { display: flex; flex-direction: column; }
.dev-row { display: flex; align-items: center; gap: 10px; padding: 10px 8px; border: 0; border-bottom: 1px solid var(--line); background: none; text-align: left; font: inherit; color: inherit; cursor: pointer; border-radius: 6px; }
.dev-row:hover { background: var(--surface-2); }
.dev-row.sel { background: color-mix(in srgb, var(--primary) 10%, transparent); }
.dev-main { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.dev-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; background: var(--offline); }
.dot.moving { background: var(--ok); }
.dot.stopped { background: var(--accent); }
.ign { color: var(--offline); font-size: 14px; }
.ign.on { color: var(--ok); }
.empty { text-align: center; padding: 24px 8px; }
.detail { margin: 8px 0 12px; box-shadow: var(--shadow); }
.detail-head { display: flex; align-items: center; gap: 8px; }
.detail-head h3 { flex: 1; margin: 0; font-size: 16px; text-transform: none; letter-spacing: 0; color: var(--text); }
.kvs { margin-top: 8px; }
.kv { display: flex; justify-content: space-between; gap: 10px; padding: 5px 0; border-bottom: 1px dashed var(--line); font-size: 13px; }
.kv span { color: var(--muted); }
.kv b { text-align: right; font-weight: 600; }

/* Marcadores */
.veh { filter: drop-shadow(0 2px 3px rgba(0,0,0,.35)); transition: transform .2s; }
.veh .veh-body { fill: var(--offline); stroke: #fff; stroke-width: 2.5; }
.veh.moving .veh-body { fill: var(--ok); }
.veh.stopped .veh-body { fill: var(--accent); }
.veh.sel { transform: scale(1.25); }
.veh.sel .veh-body { stroke: var(--primary-dark); stroke-width: 3; }
.veh-label { font-weight: 600; }
.stop-pin { width: 26px; height: 26px; border-radius: 50%; background: #1e3a8a; color: #fff; font-size: 10px; font-weight: 700; display: grid; place-items: center; border: 2px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.4); }
.leaflet-container.drawing { cursor: crosshair; }

/* Historial */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 14px 0; }
.stat { background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; padding: 8px; }
.stat span { display: block; font-size: 11px; color: var(--muted); }
.stat b { font-size: 15px; }
.player { margin: 8px 0; }
.player-row { display: flex; gap: 8px; align-items: center; }
.player-row input { flex: 1; }
.player-row select { width: auto; }
.play { width: 40px; padding: 8px 0; }
.trip-list { display: flex; flex-direction: column; gap: 6px; }
.trip { display: flex; flex-direction: column; gap: 2px; text-align: left; font: inherit; color: inherit; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; cursor: pointer; }
.trip:hover { border-color: var(--primary); }

/* Listas, tablas, pestañas */
.list { display: flex; flex-direction: column; gap: 2px; }
.list > .btn { align-self: flex-start; margin-bottom: 8px; }
.list-row { display: flex; align-items: center; gap: 8px; padding: 8px 4px; border-bottom: 1px solid var(--line); }
.swatch { width: 14px; height: 14px; border-radius: 4px; flex: none; }
.event-list { list-style: none; margin: 0; padding: 0; }
.event-list li { padding: 8px 0; border-bottom: 1px solid var(--line); }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 14px; overflow-x: auto; }
.tab { padding: 10px 14px; text-decoration: none; color: var(--muted); font-weight: 600; border-bottom: 2px solid transparent; white-space: nowrap; }
.tab.on { color: var(--primary); border-bottom-color: var(--primary); }
.table-wrap { overflow: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { background: var(--surface-2); font-size: 12px; color: var(--muted); position: sticky; top: 0; }
tr:last-child td { border-bottom: 0; }
.pill { font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
.pill.online { background: color-mix(in srgb, var(--ok) 15%, transparent); color: var(--ok); }
.pill.off { background: color-mix(in srgb, var(--danger) 15%, transparent); color: var(--danger); }
.report-form { margin-bottom: 14px; }
.report-out { margin-top: 8px; }
.sticky-foot { position: sticky; bottom: -24px; background: var(--surface); padding: 10px 0; border-top: 1px solid var(--line); }

/* Modales y avisos */
.modal-overlay { position: fixed; inset: 0; background: rgba(10, 18, 25, .5); z-index: 3000; display: grid; place-items: center; padding: 16px; }
.modal { background: var(--surface); border-radius: 14px; width: 100%; max-width: 560px; max-height: calc(100vh - 32px); display: flex; flex-direction: column; box-shadow: var(--shadow); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.modal-head h3 { margin: 0; font-size: 16px; text-transform: none; letter-spacing: 0; color: var(--text); }
.modal-body { padding: 8px 18px 14px; overflow: auto; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--line); }
#toasts { position: fixed; right: 16px; bottom: 16px; z-index: 4000; display: flex; flex-direction: column; gap: 8px; max-width: min(360px, calc(100vw - 32px)); }
.toast { background: #1f2a33; color: #fff; padding: 10px 14px; border-radius: 10px; box-shadow: var(--shadow); border-left: 4px solid var(--primary); transition: opacity .4s, transform .4s; }
.toast.ok { border-left-color: var(--ok); }
.toast.warn { border-left-color: var(--accent); }
.toast.error { border-left-color: var(--danger); }
.toast.out { opacity: 0; transform: translateY(8px); }

/* Celular y tableta */
@media (max-width: 900px) {
  .grid3 { grid-template-columns: 1fr; }
  .brand span { display: none; }
}
@media (max-width: 720px) {
  :root { --top-h: 52px; }
  .topbar { gap: 8px; }
  #nav { position: fixed; bottom: 0; left: 0; right: 0; z-index: 1002; background: var(--primary-dark); justify-content: space-around; padding: 4px 4px calc(4px + env(safe-area-inset-bottom)); }
  #nav a { flex-direction: column; gap: 0; font-size: 10px; padding: 4px 6px; }
  .nav-ico { font-size: 18px; }
  #main { flex-direction: column-reverse; padding-bottom: 58px; }
  #panel { width: 100%; height: 44%; border-right: 0; border-top: 1px solid var(--line); padding: 10px 14px 20px; }
  #panel.has-detail { height: 58%; }
  #main.wide #panel { height: 100%; padding: 14px 16px 30px; }
  .grid2 { grid-template-columns: 1fr; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  #toasts { bottom: 74px; }
  .user-btn { max-width: 110px; }
  .brand img.wide { height: 32px; }
}
