/* Paleta Infotrack: rojo, negro, blanco y grises neutros (inspirada en la consola de Hetzner). El color de marca de un cliente
   reemplaza solo --accent. El estado (verde / ámbar / gris) mantiene colores propios porque tiene significado.
   Apariencia: automática (sigue al sistema), clara u oscura. Se elige con data-theme="light|dark" en <html> (theme.js);
   sin data-theme manda el sistema. Los valores oscuros están dos veces a propósito: una para el modo automático y otra para el forzado. */
:root {
  --bg: #f2f2f2; --panel: #ffffff; --panel-2: #f6f6f6; --text: #161616; --muted: #6b6b6b; --line: #e1e1e1;
  --accent: #d50c2d; --accent-text: #c20a28; --on-accent: #ffffff;
  --ok: #16a34a; --warn: #d97706; --bad: #c81e1e; --off: #9a9a9a;
  --top-bg: #ffffff; --top-text: #161616; --top-muted: #5f5f5f; --top-line: #e1e1e1;
  --shadow: 0 1px 2px rgba(0,0,0,.08), 0 4px 16px rgba(0,0,0,.06);
  --radius: 8px; --top: 56px;
  color-scheme: light dark;
}
:root[data-theme="light"] { color-scheme: light; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e0e0e; --panel: #181818; --panel-2: #212121; --text: #f2f2f2; --muted: #9c9c9c; --line: #2c2c2c;
    --accent-text: #ff5169; --bad: #ff6b6b; --top-bg: #161616; --top-text: #f5f5f5; --top-muted: #a8a8a8; --top-line: #2c2c2c;
    --shadow: 0 1px 2px rgba(0,0,0,.5), 0 4px 16px rgba(0,0,0,.4);
  }
}
:root[data-theme="dark"] {
  --bg: #0e0e0e; --panel: #181818; --panel-2: #212121; --text: #f2f2f2; --muted: #9c9c9c; --line: #2c2c2c;
  --accent-text: #ff5169; --bad: #ff6b6b; --top-bg: #161616; --top-text: #f5f5f5; --top-muted: #a8a8a8; --top-line: #2c2c2c;
  --shadow: 0 1px 2px rgba(0,0,0,.5), 0 4px 16px rgba(0,0,0,.4);
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body, #app { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
h1, h2, h3 { margin: 0 0 .5rem; line-height: 1.2; }
h1 { font-size: 1.5rem; } h2 { font-size: 1.15rem; } h3 { font-size: 1rem; }
a { color: var(--accent-text); }
button, input, select { font: inherit; color: inherit; }
.muted { color: var(--muted); } .small { font-size: .85rem; } .right { text-align: right; } .nowrap { white-space: nowrap; }
.hidden { display: none !important; }

/* ---- formularios y botones */
label { display: block; font-size: .85rem; color: var(--muted); margin: 0 0 .25rem; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=search], select {
  width: 100%; padding: .6rem .7rem; border: 1px solid var(--line); border-radius: 8px; background: var(--panel-2); min-height: 40px; }
input:focus-visible, select:focus-visible, button:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.field { margin-bottom: .9rem; }
.row { display: flex; gap: .75rem; flex-wrap: wrap; } .row > * { flex: 1 1 140px; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; padding: .55rem 1rem; min-height: 40px; border-radius: 8px;
       border: 1px solid var(--line); background: var(--panel-2); cursor: pointer; text-decoration: none; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 600; }
.btn.danger { color: var(--bad); }
.btn.small { min-height: 32px; padding: .25rem .6rem; font-size: .85rem; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.error { color: var(--bad); font-size: .9rem; min-height: 1.2em; margin: .25rem 0 .6rem; }
.hint { font-size: .8rem; color: var(--muted); margin-top: .25rem; }

/* ---- tarjetas y tablas */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1rem 1.1rem; }
.stack > * + * { margin-top: 1rem; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .55rem .6rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; }
.table-wrap { overflow-x: auto; }
.chip { display: inline-block; padding: .1rem .5rem; border-radius: 999px; font-size: .75rem; border: 1px solid var(--line); }
.chip.ok { color: var(--ok); border-color: currentColor; } .chip.warn { color: var(--warn); border-color: currentColor; }
.chip.bad { color: var(--bad); border-color: currentColor; } .chip.off { color: var(--off); }

/* ---- pantalla de ingreso */
.auth { --bg: #0e0e0e;          /* la pantalla de ingreso es SIEMPRE oscura: el modo claro / oscuro solo afecta a la plataforma de seguimiento */
        position: relative; overflow: hidden; min-height: 100%; display: grid; place-items: center; padding: 16px;
        background: radial-gradient(circle at 12% 0%, color-mix(in srgb, var(--accent) 14%, transparent), transparent 50%),
                    radial-gradient(circle at 92% 100%, color-mix(in srgb, var(--accent) 24%, transparent), transparent 55%), var(--bg); }
.bg-net { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 0; pointer-events: none; }
.auth .card { position: relative; z-index: 1; width: min(420px, 100%); padding: 1.6rem; text-align: center;
  /* La caja de ingreso es SIEMPRE blanca (sobre el fondo oscuro con la red de puntos), en modo claro y oscuro */
  --panel: #ffffff; --panel-2: #f3f3f3; --text: #161616; --muted: #666666; --line: #dcdcdc; --bad: #c81e1e; --accent-text: var(--accent);
  background: #ffffff; color: #161616; border-color: transparent; box-shadow: 0 10px 40px rgba(0,0,0,.45); }
.auth label { text-align: center; }
.auth input[type=text], .auth input[type=email], .auth input[type=password] { text-align: center; }
.auth input[inputmode=numeric] { font-size: 1.4rem; letter-spacing: .35em; }
.check { display: flex; align-items: center; justify-content: center; gap: .5rem; margin: .2rem 0 .9rem; color: var(--muted); font-size: .9rem; cursor: pointer; }
.check input { width: auto; min-height: 0; margin: 0; accent-color: var(--accent); }
.auth .card h2 { text-align: center; }
.brand-big { display: flex; flex-direction: column; align-items: center; gap: .5rem; margin-bottom: 1.2rem; text-align: center; }
.brand-big img { width: auto; height: auto; max-width: 260px; max-height: 110px; object-fit: contain; border-radius: 10px; }   /* logos rectangulares: ocupan el ancho disponible */
.brand-big .name { font-size: 1.5rem; font-weight: 700; } .brand-big .tag { color: var(--muted); font-size: .9rem; }
.qr { display: grid; place-items: center; padding: 12px; background: #fff; border-radius: 10px; width: fit-content; margin: .5rem auto; }
.qr svg { width: 180px; height: 180px; display: block; }
code.secret { display: block; word-break: break-all; padding: .5rem; background: var(--panel-2); border: 1px dashed var(--line); border-radius: 8px; font-size: .85rem; user-select: all; }

/* ---- estructura de la aplicacion */
.shell { height: 100%; display: flex; flex-direction: column; }
.topbar { height: var(--top); flex: none; display: flex; align-items: center; gap: .75rem; padding: 0 12px; background: var(--top-bg); color: var(--top-text);
          border-bottom: 1px solid var(--top-line); box-shadow: inset 0 -2px 0 var(--accent); }
.topbar .brand { display: flex; align-items: center; gap: .6rem; font-weight: 700; text-decoration: none; color: inherit; min-width: 0; }
.topbar .btn { background: transparent; color: var(--top-text); border-color: var(--top-line); }
.topbar .btn:hover { border-color: var(--accent); }
.topbar .brand img { height: 34px; width: auto; max-width: 160px; object-fit: contain; padding: 3px 6px; background: #f5f5f5; border-radius: 8px; }   /* placa clara: cualquier logo se ve sobre la barra negra */
.topbar .brand span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav { display: flex; gap: .25rem; margin-left: .5rem; overflow-x: auto; }
.nav a { padding: .45rem .75rem; border-radius: 6px; color: var(--top-muted); text-decoration: none; white-space: nowrap; }
.nav a:hover { color: var(--top-text); } .nav a.active { background: var(--accent); color: var(--on-accent); }
.spacer { flex: 1; }
.who { color: var(--top-muted); font-size: .85rem; max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.content { flex: 1; min-height: 0; overflow: auto; padding: 16px; }
.content.flush { padding: 0; overflow: hidden; }
.page { max-width: 1100px; margin: 0 auto; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: .75rem; flex-wrap: wrap; margin-bottom: 1rem; }

/* ---- mapa */
.mapview { display: grid; grid-template-columns: 330px 1fr; height: 100%; }
.mapview .side { background: var(--panel); border-right: 1px solid var(--line); overflow: auto; display: flex; flex-direction: column; }
.mapview .side .filters { padding: 10px; border-bottom: 1px solid var(--line); display: grid; gap: 8px; }
.mapview .map { position: relative; min-height: 300px; isolation: isolate; }   /* las capas internas de Leaflet/Google no pasan por encima de ventanas y avisos */
.mapview .map > .mapbox { position: absolute; inset: 0; }
.vitem { display: block; width: 100%; text-align: left; background: none; border: 0; border-bottom: 1px solid var(--line); padding: 10px 12px; cursor: pointer; }
.vitem:hover, .vitem.sel { background: var(--panel-2); }
.vrow { display: flex; align-items: center; gap: 4px; border-bottom: 1px solid var(--line); padding-right: 10px; }
.vrow:hover { background: var(--panel-2); }
.vrow .vitem { flex: 1; min-width: 0; border-bottom: 0; background: none; }
.vrow .icon-btn { width: 30px; height: 30px; }
.vitem .top { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.vitem .nm { font-weight: 600; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; background: var(--off); }
.dot.ok { background: var(--ok); } .dot.warn { background: var(--warn); }
.detail { padding: 10px 12px 12px; border-bottom: 1px solid var(--line); background: var(--panel-2); }   /* la fila de la unidad elegida, desplegada en la lista */
.kv { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 2px 12px; font-size: .85rem; margin: .5rem 0; }
.kv dt { color: var(--muted); white-space: nowrap; } .kv dd { margin: 0; text-align: right; word-break: break-word; font-variant-numeric: tabular-nums; }
.mapnote { position: absolute; left: 10px; bottom: 10px; z-index: 5; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: .3rem .6rem; font-size: .8rem; box-shadow: var(--shadow); }
.veh-marker { background: none; border: 0; }
.veh-marker svg { display: block; filter: drop-shadow(0 1px 2px rgba(0,0,0,.45)); }
.leaflet-container { font: inherit; }
/* control de capas: un solo botón que despliega la lista */
.layers-ctl { position: absolute; top: 10px; right: 10px; z-index: 1000; }
.layers-btn { width: 42px; height: 42px; display: grid; place-items: center; padding: 0; cursor: pointer; border-radius: 8px;
              background: var(--panel); color: var(--text); border: 1px solid var(--line); box-shadow: var(--shadow); }
.layers-btn:hover, .layers-btn[aria-expanded=true] { color: var(--accent-text); border-color: var(--accent); }
.layers-panel { position: absolute; top: 48px; right: 0; width: 220px; padding: 8px; background: var(--panel); color: var(--text);
                border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); }
.layers-title { font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 6px 6px 4px; }
.layers-opt { display: flex; align-items: center; gap: 8px; padding: 7px 8px; border-radius: 6px; cursor: pointer; font-size: .92rem; color: var(--text); margin: 0; }
.layers-opt:hover { background: var(--panel-2); }
.layers-opt input { width: auto; min-height: 0; margin: 0; accent-color: var(--accent); }
.vname { display: inline-flex; align-items: center; gap: 8px; min-width: 0; }
.vicon { display: inline-flex; flex: none; } .vicon svg { display: block; }
.vicon.has-img { background: #ececec; border-radius: 8px; box-shadow: inset 0 0 0 1px rgba(0,0,0,.12); }   /* placa clara: se ve un ícono gris u oscuro sobre fondo oscuro */

/* ---- selector de ícono */
.icon-preview { flex: none; width: 64px; height: 64px; display: grid; place-items: center; background: var(--panel-2); border: 1px solid var(--line); border-radius: 12px; }
.icon-grid { display: flex; flex-wrap: wrap; gap: 6px; flex: 1 1 200px; }
.icon-opt { width: 46px; height: 46px; padding: 0; display: grid; place-items: center; background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; cursor: pointer; }
.icon-opt:hover { border-color: var(--accent); }
.icon-opt[aria-checked=true] { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }

/* ---- ventanas */
.overlay { position: fixed; inset: 0; background: rgba(2,6,23,.55); display: grid; place-items: center; padding: 16px; z-index: 50; }
.modal { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); width: min(520px, 100%); max-height: 92vh; overflow: auto; padding: 1.2rem; }
.modal.wide { width: min(780px, 100%); }
.modal .actions { display: flex; justify-content: flex-end; gap: .5rem; margin-top: 1rem; }
.state-rows { display: grid; gap: 6px; margin-bottom: 6px; }
.state-row { display: grid; grid-template-columns: 110px 1fr auto; gap: 6px; }
.check.left { justify-content: flex-start; margin: .4rem 0 .6rem; }
tr.row-hidden td { opacity: .6; }
tr.row-hidden td:last-child, tr.row-hidden td:nth-last-child(2) { opacity: 1; }
.drag-handle { white-space: nowrap; width: 1%; cursor: grab; }
.drag-handle .grip { color: var(--muted); margin-right: 6px; font-size: 1.1rem; vertical-align: middle; }
.btn.small.arrow { min-height: 26px; min-width: 26px; padding: 0 6px; font-size: .7rem; margin-right: 2px; }
tr.dragging { opacity: .45; }
tr.drag-over td { box-shadow: inset 0 3px 0 var(--accent); }
.chipbtn { border-radius: 999px; }
.chipbtn.ok { color: var(--ok); border-color: currentColor; }
.chipbtn.off { color: var(--off); }
.chips { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: 0 0 .6rem; }
.sensor-preview { margin: .5rem 0; padding: .55rem .7rem; background: var(--panel-2); border: 1px dashed var(--line); border-radius: 8px; font-size: .9rem; }
.sensor-preview code { background: var(--panel); padding: 0 .3rem; border-radius: 4px; }
details > summary { cursor: pointer; color: var(--muted); }
.toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: .6rem 1rem; border-radius: 8px; z-index: 60; box-shadow: var(--shadow); max-width: 90vw; }
.toast.bad { background: var(--bad); color: #fff; }
.logo-prev { height: 56px; max-width: 160px; object-fit: contain; background: #f5f5f5; border: 1px solid var(--line); border-radius: 8px; padding: 4px; }
/* logo de Falcon (negro sobre transparente): placa clara para que se vea sobre fondos oscuros */
.brand-big img.logo-falcon { height: 84px; max-height: none; }            /* la caja de ingreso es blanca: el logo de Falcon va sin placa */
.swatch { display: inline-block; width: 18px; height: 18px; border-radius: 4px; vertical-align: middle; border: 1px solid var(--line); }

@media (max-width: 560px) {
  .topbar .brand span { display: none; }           /* solo el logo: así caben las secciones del menú */
  .nav { scrollbar-width: none; } .nav::-webkit-scrollbar { display: none; }
}
@media (max-width: 760px) {
  .mapview { grid-template-columns: 1fr; grid-template-rows: 55% 45%; }
  .mapview .map { order: -1; }
  .mapview .side { border-right: 0; border-top: 1px solid var(--line); }
  .who { display: none; } .content { padding: 12px; }
  th, td { padding: .5rem .4rem; }
}
@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; transition: none !important; animation: none !important; } }

/* Último reporte: etiqueta y valor en UNA línea (fecha, hora y tiempo transcurrido con segundos en vivo) */
.lastline { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin: .5rem 0 .25rem; font-size: .85rem; white-space: nowrap; }
.lastline .lbl { color: var(--muted); }
.lastline .val { text-align: right; font-variant-numeric: tabular-nums; }
.since { display: inline-block; min-width: 9.5ch; text-align: left; }      /* ancho estable: el contador no "baila" al cambiar de dígitos */
@media (min-width: 761px) { .mapview { grid-template-columns: 360px 1fr; } }

/* Recorrido: un solo botón con el ícono de ruta (marcado / desmarcado) */
.detail-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.track-ctl { display: flex; align-items: center; gap: 6px; flex: none; }
.icon-btn { width: 34px; height: 34px; display: grid; place-items: center; padding: 0; border-radius: 8px; border: 1px solid var(--line);
            background: var(--panel-2); color: var(--muted); cursor: pointer; }
.icon-btn:hover { color: var(--text); border-color: var(--accent); }
.icon-btn.on { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.period-select { width: auto; min-height: 30px; padding: .15rem .4rem; font-size: .8rem; }

/* Ficha plegable: el ícono y el nombre son un botón que contrae y expande los datos */
.vhead { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; padding: 0; background: none; border: 0; color: inherit; font: inherit; font-weight: 700; font-size: 1rem; text-align: left; cursor: pointer; }
.vhead:hover .vtitle { text-decoration: underline; }
.vhead .vtitle { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.vhead .chev { flex: none; color: var(--muted); transition: transform .15s; margin-left: 2px; }
.vhead[aria-expanded=false] .chev { transform: rotate(-90deg); }
.detail.collapsed { padding-top: 8px; padding-bottom: 8px; }

/* Botón de apariencia (barra superior) y selector en "Cuenta" */
.topbar .icon-btn { background: transparent; color: var(--top-text); border-color: var(--top-line); width: 36px; height: 36px; }
.topbar .icon-btn:hover { border-color: var(--accent); }
.theme-opts { display: flex; flex-wrap: wrap; gap: .5rem 1.2rem; }
.topbar .brand img { box-shadow: inset 0 0 0 1px rgba(0,0,0,.1); }

/* Panel lateral plegable (Seguimiento) */
.side-toggle { position: absolute; left: 0; top: 50%; transform: translateY(-50%); z-index: 1100; width: 20px; height: 60px; padding: 0;
               display: grid; place-items: center; font-size: 1.3rem; line-height: 1; cursor: pointer; color: var(--text);
               background: var(--panel); border: 1px solid var(--line); border-left: 0; border-radius: 0 8px 8px 0; box-shadow: var(--shadow); }
.side-toggle:hover { color: var(--accent-text); border-color: var(--accent); }
.mapview.collapsed { grid-template-columns: 1fr; }          /* el panel oculto no ocupa celda: el mapa pasa a ser la única columna */
.mapview.collapsed .side { display: none; }
@media (max-width: 760px) {
  .mapview.collapsed { grid-template-columns: 1fr; grid-template-rows: 1fr; }
  .side-toggle { left: 50%; top: auto; bottom: 0; transform: translateX(-50%); width: 64px; height: 22px; border: 1px solid var(--line); border-bottom: 0; border-radius: 8px 8px 0 0; }
  .side-toggle { font-size: 1.15rem; }
}

/* Informes */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .75rem; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: .75rem .9rem; box-shadow: var(--shadow); }
.stat-v { font-size: 1.35rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-l { color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; }
.stat-s { font-size: .8rem; }
.tabs { display: flex; gap: .25rem; margin: .5rem 0; border-bottom: 1px solid var(--line); }
.tab { background: none; border: 0; border-bottom: 3px solid transparent; padding: .5rem .9rem; cursor: pointer; color: var(--muted); font: inherit; }
.tab.on { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
.place { max-width: 320px; }
@media print {
  .topbar, .no-print, .side-toggle { display: none !important; }
  body, .content { background: #fff !important; color: #000 !important; overflow: visible !important; }
  .shell, #app { height: auto !important; display: block !important; }
  .card, .stat { box-shadow: none !important; border-color: #bbb !important; background: #fff !important; }
  .table-wrap { overflow: visible !important; }
  a { color: #000; text-decoration: none; }
  .chip { border-color: #888; color: #000 !important; }
}

.detail .kv dd.addr { min-height: 5.5em; }          /* la dirección reserva cuatro líneas: no hay saltos al cambiar de calle ni de largo */

/* Ventana al pasar el puntero sobre una unidad del mapa */
.map-hover { position: absolute; z-index: 1200; width: min(320px, calc(100% - 16px)); pointer-events: none; padding: 10px 12px;
             background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.map-hover .hover-head { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; font-size: .95rem; }
.map-hover .kv { margin: .35rem 0 0; }
.map-hover { width: min(360px, calc(100% - 16px)); }
.map-hover .lastline { flex-wrap: wrap; white-space: normal; row-gap: 0; }   /* en la ventana angosta el "hace X min Y s" baja a otra línea en vez de salirse */

/* Ficha contraída: debajo del nombre, la dirección actual de la unidad */
.vhead .vtext { display: flex; flex-direction: column; min-width: 0; line-height: 1.25; }
.vhead .vaddr { font-weight: 400; font-size: .75rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Fichas desplegadas que no son la elegida: tocarlas las elige */
.detail.other { cursor: pointer; }

/* Recorrido: color fijo o por velocidad, con su leyenda */
.track-style { display: flex; align-items: center; flex-wrap: wrap; gap: 6px 10px; margin: .4rem 0 0; }
.track-style .legend { display: inline-flex; flex-wrap: wrap; gap: 4px 10px; }
.track-style .lg { display: inline-flex; align-items: center; gap: 4px; font-variant-numeric: tabular-nums; }
.track-style .lg i { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }

.track-style .km { flex-basis: 100%; }          /* el kilometraje va en su propia línea, debajo del color y la leyenda */

/* Recorrido: período personalizado */
.track-custom { flex-basis: 100%; display: grid; grid-template-columns: 1fr 1fr auto; gap: 6px; align-items: end; }
.track-custom label { display: grid; gap: 2px; font-size: .75rem; color: var(--muted); min-width: 0; }
.track-custom input.dt { min-height: 30px; padding: .15rem .3rem; font-size: .8rem; min-width: 0; }

.speed-cfg { gap: .6rem; } .speed-cfg .field { margin: 0; display: grid; gap: 4px; align-content: start; } .speed-cfg input[type=number] { width: 100%; }

/* Leyenda de velocidades (también en la tabla de vehículos) */
.legend { display: inline-flex; flex-wrap: wrap; gap: 4px 12px; }
.legend .lg { display: inline-flex; align-items: center; gap: 4px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.legend .lg i { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex: none; }

/* Selectores de color de las velocidades: color sólido con esquinas redondeadas, sin marco */
.speed-cfg input[type=color] { width: 56px; height: 36px; min-height: 36px; padding: 0; border: 0; background: none; border-radius: 8px; overflow: hidden; cursor: pointer; }
.speed-cfg input[type=color]::-webkit-color-swatch-wrapper { padding: 0; }
.speed-cfg input[type=color]::-webkit-color-swatch { border: 0; border-radius: 8px; }
.speed-cfg input[type=color]::-moz-color-swatch { border: 0; border-radius: 8px; }
.speed-cfg .static-val { min-height: 43px; box-sizing: border-box; display: flex; align-items: center; color: var(--muted); }

/* Botón "i" del informe y su ventana */
.info-btn { width: 30px; height: 30px; border-radius: 50%; font: italic 700 .95rem Georgia, serif; }
.criteria { margin: 0 0 .5rem; padding-left: 1.1rem; display: grid; gap: .6rem; line-height: 1.45; }

/* Cámaras: video en vivo y clips */
.live-frame { background: #000; border-radius: 8px; overflow: hidden; aspect-ratio: 16 / 9; display: grid; place-items: center; }
.live-video, .clip-video { width: 100%; height: 100%; object-fit: contain; background: #000; }
.live-status { min-height: 1.4em; margin: .5rem 0; }
.live-status.ok { color: var(--ok, #16a34a); font-weight: 600; } .live-status.error { color: var(--bad, #dc2626); }
.live .row { margin-top: .5rem; }
.modal.wide { width: min(860px, 100%); }

/* Barra superior siempre oscura (opción de Cuenta → Apariencia), también con el resto en modo claro */
:root[data-topbar="dark"] { --top-bg: #161616; --top-text: #f5f5f5; --top-muted: #a8a8a8; --top-line: #2c2c2c; }

:root:has(.auth) body { background: #0e0e0e; }          /* también detrás (al desplazar o en pantallas muy anchas) */

/* ---- panel de control */
.page.dash { max-width: 1400px; }
.dash-tools { display: flex; gap: .6rem; flex-wrap: wrap; align-items: center; }
.dash-tools select { width: auto; min-width: 180px; }
.dash-custom { display: flex; gap: .4rem; align-items: center; } .dash-custom input { width: auto; min-height: 34px; padding: .3rem .5rem; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--panel); }
.seg-btn { border: 0; background: transparent; padding: .42rem .8rem; cursor: pointer; font-size: .85rem; color: var(--muted); border-right: 1px solid var(--line); }
.seg-btn:last-child { border-right: 0; } .seg-btn:hover { color: var(--text); }
.seg-btn.on { background: var(--accent); color: var(--on-accent); font-weight: 600; }
.seg.small .seg-btn { padding: .25rem .6rem; font-size: .8rem; }
.dash-out.stack > * + * { margin-top: 1rem; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: .85rem; }
.kpi { position: relative; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: .9rem 1rem 1rem; overflow: hidden; }
.kpi-l { color: var(--muted); font-size: .76rem; text-transform: uppercase; letter-spacing: .05em; font-weight: 600; }
.kpi-v { font-size: 2rem; font-weight: 750; line-height: 1.15; margin: .2rem 0 .1rem; font-variant-numeric: tabular-nums; }
.kpi-v small { font-size: .9rem; font-weight: 500; color: var(--muted); }
.kpi-s { font-size: .82rem; } .kpi .spark { position: absolute; left: 0; right: 0; bottom: 0; width: 100%; height: 34px; opacity: .3; pointer-events: none; } .kpi:has(.spark) { padding-bottom: 2.3rem; }
.delta { font-size: .82rem; font-weight: 600; } .delta.good { color: var(--ok); } .delta.bad { color: var(--bad); } .delta .muted { font-weight: 400; }
.dash-grid { display: grid; gap: .85rem; } .dash-grid.two { grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr); } .dash-grid.three { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
@media (max-width: 900px) { .dash-grid.two { grid-template-columns: 1fr; } }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: .5rem; flex-wrap: wrap; margin-bottom: .4rem; } .card-head h3 { margin: 0; }
.chart-host { position: relative; } .ch { width: 100%; height: auto; display: block; }
.ch-grid { stroke: var(--line); stroke-width: 1; } .ch-axis { fill: var(--muted); font-size: 11px; } .ch-hit { fill: transparent; } .ch-hit:hover { fill: rgba(127,127,127,.12); } .ch-track { stroke: var(--panel-2); }
.chart-tip { position: absolute; z-index: 5; pointer-events: none; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); padding: .5rem .65rem; font-size: .8rem; min-width: 160px; }
.chart-tip div { display: flex; align-items: center; gap: .4rem; margin-top: .2rem; } .chart-tip div span { margin-left: auto; font-weight: 600; padding-left: .8rem; }
.chart-tip i, .legend i, .donut-key i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; flex: none; }
.legend { display: flex; flex-wrap: wrap; gap: .35rem .5rem; margin-top: .6rem; }
.lg { display: inline-flex; align-items: center; gap: .4rem; border: 1px solid var(--line); background: var(--panel-2); border-radius: 999px; padding: .2rem .65rem; font-size: .8rem; cursor: pointer; }
.lg b { font-weight: 600; color: var(--muted); } .lg.off { opacity: .45; text-decoration: line-through; }
.donut-wrap { display: flex; align-items: center; gap: 1.2rem; flex-wrap: wrap; justify-content: center; margin: .6rem 0; }
.donut-box { position: relative; width: 190px; height: 190px; } .donut-mid { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.donut-mid b { font-size: 2.2rem; line-height: 1; } .donut-mid span { color: var(--muted); font-size: .8rem; }
.donut-key { list-style: none; margin: 0; padding: 0; display: grid; gap: .5rem; } .donut-key li { display: flex; align-items: center; gap: .5rem; } .donut-key b { margin-left: auto; padding-left: 1rem; }
.rank { list-style: none; margin: .5rem 0 0; padding: 0; display: grid; gap: .65rem; }
.rank-top { display: flex; justify-content: space-between; gap: .6rem; font-size: .88rem; } .rank-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank-bar { height: 8px; background: var(--panel-2); border-radius: 99px; overflow: hidden; margin-top: .25rem; } .rank-bar i { display: block; height: 100%; border-radius: 99px; }
.dash-table .num { text-align: right; font-variant-numeric: tabular-nums; } .dash-table th:not(:first-child) { text-align: right; }
.th-btn { all: unset; cursor: pointer; text-transform: inherit; letter-spacing: inherit; } .th-btn:focus-visible { outline: 2px solid var(--accent); }
.dot-state { display: inline-flex; align-items: center; gap: .4rem; } .dot-state i { width: 9px; height: 9px; border-radius: 50%; }
.dash-skel { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: .85rem; } .skel { height: 110px; border-radius: var(--radius); background: var(--panel); border: 1px solid var(--line); animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .5; } } @media (prefers-reduced-motion: reduce) { .skel { animation: none; } }
.arc { cursor: pointer; transition: opacity .15s; } .arc.dim { opacity: .25; }
.key-btn { all: unset; display: flex; align-items: center; gap: .5rem; width: 100%; cursor: pointer; padding: .15rem .4rem; border-radius: 6px; } .key-btn:hover, .key-btn.on { background: var(--panel-2); } .key-btn:focus-visible { outline: 2px solid var(--accent); }
.key-btn b { margin-left: auto; padding-left: 1rem; }
.conn-list { margin-top: .4rem; } .conn-head { display: flex; align-items: center; gap: .5rem; font-weight: 600; margin-bottom: .3rem; } .conn-head i { width: 10px; height: 10px; border-radius: 3px; }
.conn-list ul { list-style: none; margin: 0; padding: 0; max-height: 220px; overflow: auto; } .conn-list li { display: flex; justify-content: space-between; gap: .6rem; padding: .3rem 0; border-bottom: 1px solid var(--line); font-size: .9rem; }

/* Dashboard: las tarjetas conservan el tono oscuro y el fondo de la pantalla queda un poco más claro que ellas (en modo claro ya lo es) */
:root { --dash-bg: var(--bg); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --dash-bg: #262626; } }
:root[data-theme="dark"] { --dash-bg: #262626; }
body:has(.page.dash) { background: var(--dash-bg); }

/* Portada del dashboard (imagen del cliente) */
.hero { display: flex; align-items: center; justify-content: space-between; gap: 1rem; overflow: hidden; padding: 1rem 1.6rem; min-height: 210px; border: 1px solid #2c2c2c; border-radius: var(--radius); box-shadow: var(--shadow);
        color: #f2f2f2; background: linear-gradient(105deg, #181818 35%, color-mix(in srgb, var(--accent) 38%, #181818)); }      /* siempre oscura, también con la aplicación en modo claro */
.hero h2 { font-size: 1.7rem; margin: 0 0 .25rem; } .hero-tag { margin: .2rem 0 0; font-size: 1.1rem; color: #a8a8a8; }
.hero-img { height: 190px; max-width: 55%; object-fit: contain; flex: none; filter: drop-shadow(0 8px 14px rgba(0,0,0,.45)); }
@media (max-width: 700px) { .hero { flex-direction: column-reverse; align-items: flex-start; } .hero-img { height: 130px; max-width: 100%; align-self: center; } }
.cover-prev { display: block; max-height: 120px; max-width: 100%; margin-bottom: .5rem; background: var(--panel-2); border-radius: 6px; padding: .3rem; }
.hero-img.enter { animation: hero-drive 1.3s cubic-bezier(.16, .84, .3, 1) both; }
@keyframes hero-drive { from { transform: translateX(110%); opacity: 0; filter: blur(7px) drop-shadow(0 8px 14px rgba(0,0,0,.45)); } 60% { opacity: 1; } to { transform: none; opacity: 1; filter: blur(0) drop-shadow(0 8px 14px rgba(0,0,0,.45)); } }
@media (prefers-reduced-motion: reduce) { .hero-img.enter { animation: none; } }

/* Animación de entrada de los gráficos del dashboard (solo al abrirlo): columnas que crecen, líneas que se dibujan, anillo que gira y barras que se llenan */
.dash-out.anim .col { transform-box: fill-box; transform-origin: 50% 100%; animation: grow-y .8s cubic-bezier(.2, .8, .2, 1) both; animation-delay: calc(var(--i, 0) * 70ms); }
.dash-out.anim .ch-line { stroke-dasharray: 1; animation: draw-line 1.4s ease-out both; }
.dash-out.anim .ch-dot, .dash-out.anim .spark { animation: fade-in .5s ease-out 1s both; }
.dash-out.anim .donut { transform-origin: 50% 50%; animation: donut-in 1.1s cubic-bezier(.2, .8, .2, 1) both; }
.dash-out.anim .rank-bar i { transform-origin: left center; animation: grow-x .9s cubic-bezier(.2, .8, .2, 1) both; }
.dash-out.anim .rank li:nth-child(2) i { animation-delay: .08s; } .dash-out.anim .rank li:nth-child(3) i { animation-delay: .16s; } .dash-out.anim .rank li:nth-child(4) i { animation-delay: .24s; }
.dash-out.anim .rank li:nth-child(5) i { animation-delay: .32s; } .dash-out.anim .rank li:nth-child(6) i { animation-delay: .4s; } .dash-out.anim .rank li:nth-child(7) i { animation-delay: .48s; } .dash-out.anim .rank li:nth-child(8) i { animation-delay: .56s; }
@keyframes grow-y { from { transform: scaleY(0); } to { transform: none; } }
@keyframes grow-x { from { transform: scaleX(0); } to { transform: none; } }
@keyframes draw-line { from { stroke-dashoffset: 1; } to { stroke-dashoffset: 0; } }
@keyframes fade-in { from { opacity: 0; } }
@keyframes donut-in { from { transform: rotate(-140deg) scale(.7); opacity: 0; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .dash-out.anim .col, .dash-out.anim .ch-line, .dash-out.anim .ch-dot, .dash-out.anim .spark, .dash-out.anim .donut, .dash-out.anim .rank-bar i { animation: none; } }

/* El nombre y el eslogan emergen desde la oscuridad: transparentes y desenfocados al principio, se deslizan un poco y se solidifican */
.hero-text.enter h2 { animation: hero-text-in 1.1s cubic-bezier(.2, .8, .2, 1) .15s both; }
.hero-text.enter .hero-tag { animation: hero-text-in 1.1s cubic-bezier(.2, .8, .2, 1) .55s both; }
@keyframes hero-text-in { from { opacity: 0; transform: translateX(-30px); filter: blur(7px); } to { opacity: 1; transform: none; filter: blur(0); } }
@media (prefers-reduced-motion: reduce) { .hero-text.enter h2, .hero-text.enter .hero-tag { animation: none; } }

/* Fundido entre pantallas: la que sale se desvanece y la que entra aparece suavemente; el fondo del dashboard cambia gradualmente */
body { transition: background-color .75s ease; }
.content { transition: opacity .26s ease-in-out; } .content.leaving { opacity: 0; }
.content > * { animation: view-in .75s cubic-bezier(.25, .1, .25, 1) both; }
.content > .mapview { animation-name: view-fade; }
@keyframes view-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes view-fade { from { opacity: 0; } to { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .content > *, .content { animation: none; transition: none; } }

/* Pantalla Servidor */
.srv-out.stack > * + * { margin-top: 1rem; }
.srv-banner { border: 1px solid var(--line); border-left: 6px solid var(--c); border-radius: var(--radius); background: var(--panel); box-shadow: var(--shadow); padding: 1rem 1.3rem; }
.srv-big { display: flex; align-items: center; gap: 1rem; } .srv-big h2 { margin: 0; font-size: 1.6rem; } .srv-big p { margin: .15rem 0 0; }
.srv-big .st-dot { width: 22px; height: 22px; box-shadow: 0 0 0 6px color-mix(in srgb, var(--c) 25%, transparent); }
.st-dot { display: inline-block; flex: none; width: 11px; height: 11px; border-radius: 50%; margin-top: .3rem; }
.srv-checks { list-style: none; margin: .5rem 0 0; padding: 0; display: grid; gap: .65rem; } .srv-checks li { display: flex; gap: .65rem; align-items: flex-start; }
.srv-list { list-style: none; margin: .4rem 0; padding: 0; } .srv-list li { display: flex; justify-content: space-between; gap: .6rem; padding: .4rem 0; border-bottom: 1px solid var(--line); }
.srv-pair { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; margin: .5rem 0; }
.kpi .rank-bar { margin-top: .5rem; }
/* Pantalla Servidor: títulos y nombres de los controles más finos */
.srv-out h3 { font-size: .82rem; font-weight: 500; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); margin-bottom: .5rem; }
.srv-checks { gap: .5rem; } .srv-checks b { font-weight: 400; font-size: .88rem; } .srv-checks .small { font-size: .78rem; }
.srv-banner h2 { font-size: 1.25rem; font-weight: 500; }
.srv-out .kpi-v { font-weight: 600; }

/* Capas de rutas del mapa */
.layers-swatch { display: inline-block; width: 18px; height: 4px; border-radius: 2px; margin: 0 .1rem; vertical-align: middle; }
.route-info { max-width: 240px; font-size: .85rem; line-height: 1.35; color: #161616; } .route-info b { display: block; margin-bottom: .15rem; }
/* Rutas y zonas: listado compacto en dos columnas */
.layers-panel:has(.layers-routes) { width: 280px; }
.layers-routes { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 4px; max-height: 260px; overflow-x: hidden; overflow-y: auto; }
.layers-routes .layers-opt { padding: 5px 6px; font-size: .88rem; white-space: nowrap; min-width: 0; gap: 6px; }
.layers-actions { display: flex; gap: 14px; margin: 0 6px 4px; }
.layers-clear { all: unset; cursor: pointer; font-size: .8rem; color: #fff; text-decoration: underline; text-underline-offset: 3px; text-decoration-color: rgba(255,255,255,.4); } .layers-clear:hover { text-decoration-color: #fff; } .layers-clear:focus-visible { outline: 2px solid var(--accent); }
/* Desplegable de capas: siempre oscuro y con todos los textos en blanco */
.layers-panel { background: #181818; border-color: #2c2c2c; color: #fff; }
.layers-panel .layers-title, .layers-panel .layers-opt { color: #fff; } .layers-panel .layers-opt:hover { background: #262626; }

/* Recorridos: panel con período, color y casillas de lo que se marca sobre el mapa */
.rec-form { gap: 12px !important; }
.rec-form label { display: block; font-size: .8rem; color: var(--muted); margin-bottom: 3px; }
.rec-form .seg { display: flex; }
.rec-form .seg .seg-btn { flex: 1; padding: .42rem .3rem; }
.rec-custom { display: grid; gap: 8px; }
.rec-colorrow { display: flex; align-items: center; gap: 8px; }
.rec-colorrow .seg { flex: 1; }
.rec-color { width: 42px; height: 36px; padding: 2px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel); cursor: pointer; flex: none; }
.rec-icons { display: flex; gap: 8px; }
.rec-ico { width: 54px; height: 54px; display: grid; place-items: center; padding: 0; border-radius: 12px; border: 1px solid var(--line); background: var(--panel-2); cursor: pointer; transition: opacity .15s, filter .15s, border-color .15s; }
.rec-ico svg { width: 38px; height: 38px; }
.rec-ico:hover { border-color: var(--accent); }
.rec-ico.off { opacity: .35; filter: grayscale(1); }
.rec-sec { border-bottom: 1px solid var(--line); }
.rec-sec-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 0 12px 0 4px; }
.rec-sec-title { flex: 1; display: flex; align-items: center; gap: 6px; text-align: left; background: none; border: 0; padding: 10px 8px; font-weight: 600; color: var(--text); cursor: pointer; }
.rec-sec-title .chev { display: inline-block; transition: transform .15s; font-size: .8rem; color: var(--muted); }
.rec-sec.collapsed .rec-sec-title .chev { transform: rotate(-90deg); }
.rec-sec.collapsed .rec-sec-body { display: none; }
.rec-master { width: 18px; height: 18px; accent-color: var(--accent); cursor: pointer; flex: none; }
.rec-row { display: flex; align-items: center; gap: 10px; padding: 0 12px; border-top: 1px solid var(--line); }
.rec-row:hover { background: var(--panel-2); }
.rec-row input[type=checkbox] { width: 17px; height: 17px; accent-color: var(--accent); flex: none; margin: 0; min-height: 0; }
.rec-trip-ico { width: 18px; height: 18px; border-radius: 4px; flex: none; }
.rec-row-ico { width: 26px; height: 26px; flex: none; display: grid; place-items: center; }
.rec-row-ico svg { width: 26px; height: 26px; }
.rec-row-text { flex: 1; min-width: 0; display: grid; text-align: left; background: none; border: 0; padding: 8px 0; cursor: pointer; color: var(--text); font-size: .85rem; line-height: 1.3; }
.rec-row-val { font-variant-numeric: tabular-nums; font-size: .85rem; white-space: nowrap; }
.rec-summary { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; padding: 4px 10px 12px; }
.rec-summary .stat { padding: .5rem .65rem; box-shadow: none; }
.rec-summary .stat-v { font-size: 1.05rem; }
