/* 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. */
: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: #161616; --top-text: #f5f5f5; --top-muted: #a8a8a8; --top-line: #333333;
  --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;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0e0e0e; --panel: #181818; --panel-2: #212121; --text: #f2f2f2; --muted: #9c9c9c; --line: #2c2c2c;
          --accent-text: #ff5169; --bad: #ff6b6b; --top-bg: #161616; --top-line: #2c2c2c;
          --shadow: 0 1px 2px rgba(0,0,0,.5), 0 4px 16px rgba(0,0,0,.4); }
}
* { 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 { 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); } .vitem.sel { box-shadow: inset 3px 0 var(--accent); }
.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); box-shadow: inset 3px 0 var(--accent); }   /* la fila de la unidad elegida, desplegada en la lista */
.kv { display: grid; grid-template-columns: auto 1fr; gap: 2px 12px; font-size: .85rem; margin: .5rem 0; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; text-align: right; word-break: break-word; }
.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; }
