/* App Conductor — hoja de estilos única (PWA mobile, modo oscuro).
   Tokens y lenguaje visual del canvas "Rediseño ScoreCard" / ds-v2.css
   html.dark. Autónoma: no depende de tailwind.css ni de style.css del
   panel de staff. Ver PLAN_MIGRACION_V2.md Fase 4 y app/README.md. */

/* ── Tipografías self-hosted (mismas que ds-v2.css) ───────────────────── */
@font-face {
    font-family: 'Manrope';
    font-style: normal;
    font-weight: 400 700;
    font-display: swap;
    src: url('../fonts/manrope-latin.woff2') format('woff2');
    unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC,
        U+0304, U+0308, U+0329, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193,
        U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
    font-family: 'Manrope';
    font-style: normal;
    font-weight: 400 700;
    font-display: swap;
    src: url('../fonts/manrope-latin-ext.woff2') format('woff2');
    unicode-range: U+0100-02AF, U+0304, U+0308, U+0329, U+1E00-1E9F, U+1EF2-1EFF, U+2020,
        U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
    font-family: 'Space Grotesk';
    font-style: normal;
    font-weight: 400 700;
    font-display: swap;
    src: url('../fonts/spacegrotesk-latin.woff2') format('woff2');
    unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC,
        U+0304, U+0308, U+0329, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193,
        U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
    font-family: 'Space Grotesk';
    font-style: normal;
    font-weight: 400 700;
    font-display: swap;
    src: url('../fonts/spacegrotesk-latin-ext.woff2') format('woff2');
    unicode-range: U+0100-02AF, U+0304, U+0308, U+0329, U+1E00-1E9F, U+1EF2-1EFF, U+2020,
        U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

/* ── Tokens ──────────────────────────────────────────────────────────── */
:root {
    --bg: #0A1012;
    --surface: #10171A;
    --surface-2: #141D20;
    --border: #1D2529;
    --border-2: #2A343A;
    --text: #EEF4F6;
    --text-2: #8B979D;
    --text-3: #7D8A91;
    --accent: #1FC9A8;
    --accent-hi: #5EE0C6;
    --accent-fg: #04120E;
    --accent-bg: rgba(31, 201, 168, 0.12);
    --accent-soft: #7ADBC7;
    --telemetria: #4CC2FF;
    --atencion: #F5A524;
    --critico: #F2545B;
    /* Color propio para "Reversa" en el mapa de Mis Desvíos (01/10/2026)
       -- separado de --accent/--atencion/--critico, que ya están tomados
       por la rampa de severidad de exceso de velocidad (ver
       colorPunto() en mapa.html). */
    --reversa: #B18CFF;
    /* Radios: escala propia de la App Conductor, distinta a propósito de
       --sc-radius/--sc-radius-sm (16/12px) de frontend/css/ds-v2.css (la
       consola de staff) -- son dos apps con lenguaje visual afinado por
       separado (esta es una PWA mobile con tarjetas/CTAs más redondeadas),
       no un descuido de consistencia; no fusionar ambas escalas. */
    --r-ctrl: 12px;
    --r-card: 20px;
    --r-feat: 26px;
    --r-pill: 999px;
    --font: 'Manrope', system-ui, -apple-system, 'Segoe UI', sans-serif;
    --font-num: 'Space Grotesk', 'Manrope', ui-monospace, system-ui, sans-serif;
}

/* ── Base ────────────────────────────────────────────────────────────── */
* { box-sizing: border-box; }
html, body { background: var(--bg); overflow-x: hidden; }
body {
    margin: 0;
    color: var(--text);
    font-family: var(--font);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    color-scheme: dark;
}
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hi); }
button { font-family: inherit; cursor: pointer; }
:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--accent-bg); border-radius: 8px; }
.sg { font-family: var(--font-num); font-feature-settings: 'tnum' 1; font-variant-numeric: tabular-nums; }
[hidden] { display: none !important; }

/* ── Shell ──────────────────────────────────────────────────────────── */
/* height (no min-height) fija el alto EXACTO del shell al viewport: con
   min-height, si el contenido de .app__scroll era más alto que la
   pantalla, .app crecía por encima de 100dvh (su altura era solo un piso,
   no un techo) y el <nav> de abajo quedaba empujado al final de esa caja
   larga -- el usuario tenía que hacer scroll de TODA la página para
   llegar a él en vez de verlo siempre fijo. Con height:100dvh + overflow
   hidden, .app__scroll es la ÚNICA zona que hace scroll y <nav>/#appbar
   quedan flotando, siempre visibles, en su lugar. */
.app {
    width: 100%;
    max-width: 430px;
    height: 100dvh;
    margin: 0 auto;
    background: var(--bg);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.app__scroll {
    flex: 1;
    /* min-height:0 es necesario: por default un ítem flex no se encoge
       por debajo de la altura de su contenido ("min-height: auto"), lo
       que anulaba el overflow-y de acá y volvía a estirar .app. */
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 20px 20px calc(16px + env(safe-area-inset-bottom));
}
.app__scroll--flush { padding: 0; }
.app__bar {
    flex: none;
    padding: 12px 20px calc(12px + env(safe-area-inset-bottom));
    background: linear-gradient(180deg, rgba(10, 16, 18, 0) 0%, var(--bg) 42%);
}
.app__nav {
    flex: none;
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    border-top: 1px solid var(--border);
    background: var(--surface);
    padding-bottom: env(safe-area-inset-bottom);
}

/* ── Barra de filtros de período (Año/Período/Mes/Semana/Día) ──────── */
/* Grilla que se acomoda al ancho del teléfono en vez de una fila que se
   sale de la pantalla: Año+Período arriba, Mes+Semana debajo, el date
   picker y "Limpiar" a lo ancho. Nunca desborda el contenedor. */
.pbar {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    padding: 2px 0;
}
.field {
    appearance: none;
    -webkit-appearance: none;
    font: inherit;
    font-size: 13px;
    color: var(--text);
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--r-ctrl, 12px);
    padding: 8px 10px;
    min-width: 0;
    width: 100%;
}
.field:focus { border-color: var(--accent); }
.pbar .field--dia { grid-column: 1 / -1; }
.pbar__clear {
    grid-column: 1 / -1;
    justify-self: start;
    font: inherit;
    font-size: 13px;
    color: var(--text-3);
    background: transparent;
    border: 0;
    padding: 6px 2px;
    cursor: pointer;
}

/* ── Mapa (Leaflet) ──────────────────────────────────────────────── */
#mapa {
    flex: 1;
    min-height: 0;
    width: 100%;
    background: var(--surface);
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
}
.leaflet-container { background: #0d1417; font: inherit; }
.leaflet-popup-content-wrapper, .leaflet-popup-tip { background: var(--surface); color: var(--text); border: 1px solid var(--border); }
.leaflet-popup-content { margin: 10px 12px; font-size: 12px; line-height: 1.5; }
.leaflet-popup-content b { color: var(--text); }
.leaflet-bar a { background: var(--surface); color: var(--text-2); border-color: var(--border); }
.mapnota {
    flex: none;
    display: flex;
    gap: 8px;
    align-items: flex-start;
    padding: 12px 20px calc(12px + env(safe-area-inset-bottom));
    font-size: 12px;
    color: var(--text-3);
    background: var(--surface);
}
.mapnota svg { flex: none; margin-top: 1px; }

/* ── Lista clave/valor del detalle de un desvío ──────────────────── */
.kvlist > div {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    padding: 9px 0;
    border-bottom: 1px solid var(--border);
}
.kvlist > div:last-child { border-bottom: 0; }
.kvlist .k { font-size: 13px; color: var(--text-3); flex: none; }
.kvlist .v { font-size: 13px; font-weight: 600; text-align: right; color: var(--text); font-family: var(--font-num); }
.app__nav a {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 10px 0 14px;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-3);
}
.app__nav a[aria-current="page"] { color: var(--accent); font-weight: 600; }

/* ── Topbar (pantallas de detalle) ──────────────────────────────────── */
.topbar {
    flex: none;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: max(18px, env(safe-area-inset-top)) 16px 14px;
}
.topbar h1 { margin: 0; font-size: 15px; font-weight: 600; }
.iconbtn {
    width: 44px;
    height: 44px;
    border-radius: var(--r-ctrl);
    border: 1px solid var(--border);
    background: var(--surface);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-2);
}

/* ── Tipografía utilitaria ─────────────────────────────────────────── */
.lbl {
    margin: 0;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--text-3);
}
.h1 { margin: 0; font-family: var(--font-num); font-size: 26px; font-weight: 600; letter-spacing: -0.01em; }
.muted { color: var(--text-2); }
.dim { color: var(--text-3); }

/* ── Tarjetas ──────────────────────────────────────────────────────── */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-card);
    padding: 16px;
}
.card--feat {
    border-radius: var(--r-feat);
    padding: 24px;
    background: radial-gradient(140% 90% at 15% 0%, #123430 0%, #0C1614 55%);
    border: 1px solid #1F2C29;
}

/* ── Botones ───────────────────────────────────────────────────────── */
.btn {
    width: 100%;
    height: 56px;
    border-radius: var(--r-ctrl);
    border: none;
    font-family: var(--font-num);
    font-size: 16px;
    font-weight: 600;
    background: var(--accent);
    color: var(--accent-fg);
}
.btn:disabled { background: #12201D; color: #4A565C; }
.btn--ghost {
    height: 48px;
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-2);
    font-family: var(--font);
    font-size: 14px;
    font-weight: 600;
}

/* ── Segmentado (píldora) ──────────────────────────────────────────── */
.seg {
    display: inline-flex;
    padding: 4px;
    border-radius: var(--r-pill);
    background: var(--surface);
    border: 1px solid var(--border);
    gap: 4px;
}
.seg button {
    height: 44px;
    padding: 0 18px;
    border: none;
    border-radius: var(--r-pill);
    font-size: 13px;
    font-weight: 600;
    background: transparent;
    color: var(--text-2);
}
.seg button[aria-pressed="true"] { background: var(--accent); color: var(--accent-fg); }
.seg--fill { display: flex; }
.seg--fill button { flex: 1; }

/* ── Chips de filtro (scroll horizontal) ───────────────────────────── */
.chiprow {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}
.chip {
    flex: none;
    height: 40px;
    padding: 0 16px;
    border-radius: var(--r-pill);
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text-2);
    font-size: 13px;
    font-weight: 600;
}
.chip[aria-pressed="true"] { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }

/* ── Filas de lista ────────────────────────────────────────────────── */
.row {
    display: flex;
    gap: 12px;
    align-items: center;
    padding: 13px 4px;
    width: 100%;
    text-align: left;
    background: transparent;
    border: none;
    border-top: 1px solid #12181B;
    color: inherit;
}
.row:first-child { border-top: none; }
.row__dot { flex: none; width: 8px; height: 8px; border-radius: var(--r-pill); }
.row__body { flex: 1; min-width: 0; }
.row__title { display: block; font-size: 14px; font-weight: 500; }
.row__meta { display: block; font-size: 12px; color: var(--text-3); margin-top: 2px; }
.row__delta { flex: none; font-family: var(--font-num); font-size: 13px; font-weight: 600; }

.sev-bueno { color: var(--accent); background: var(--accent); }
.sev-leve { color: var(--atencion); background: var(--atencion); }
.sev-atencion { color: var(--atencion); background: var(--atencion); }
.sev-critico { color: var(--critico); background: var(--critico); }

/* ── Barra de nivel 1–7 ────────────────────────────────────────────── */
.level { display: flex; gap: 5px; }
.level i { flex: 1; height: 8px; border-radius: var(--r-pill); background: #1D2529; }
.level i.on { background: var(--accent); }
.level i.on.warn { background: var(--atencion); }
.level i.on.crit { background: var(--critico); }

/* ── Badge de severidad ────────────────────────────────────────────── */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px 6px 10px;
    border-radius: var(--r-pill);
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}
.badge--atencion { background: rgba(245, 165, 36, 0.12); color: var(--atencion); }
.badge--critico { background: rgba(242, 84, 91, 0.12); color: var(--critico); }
.badge--bueno { background: var(--accent-bg); color: var(--accent-soft); }

/* ── Keypad (acceso) ───────────────────────────────────────────────── */
.keypad { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.keypad button {
    height: 72px;
    border-radius: var(--r-ctrl);
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    font-family: var(--font-num);
    font-size: 24px;
    font-weight: 500;
    display: flex;
    align-items: center;
    justify-content: center;
}
.dots { display: flex; gap: 14px; justify-content: center; }
.dots i { width: 12px; height: 12px; border-radius: var(--r-pill); border: 1.5px solid var(--border-2); }
.dots i.on { background: var(--accent); border-color: var(--accent); }

/* ── Toggle ────────────────────────────────────────────────────────── */
.toggle {
    flex: none;
    width: 46px;
    height: 28px;
    border-radius: var(--r-pill);
    background: var(--border);
    padding: 4px;
    display: flex;
    border: none;
}
.toggle i { width: 20px; height: 20px; border-radius: var(--r-pill); background: var(--text); transition: transform 0.15s ease; }
.toggle[aria-pressed="true"] { background: var(--accent); }
.toggle[aria-pressed="true"] i { transform: translateX(18px); }

/* ── Ítems de settings ─────────────────────────────────────────────── */
.list { border-radius: var(--r-card); background: var(--surface); border: 1px solid var(--border); overflow: hidden; }
.item {
    display: flex;
    gap: 14px;
    align-items: center;
    width: 100%;
    text-align: left;
    padding: 15px 16px;
    border: none;
    background: transparent;
    color: inherit;
    font-size: 15px;
}
.item + .item { border-top: 1px solid #12181B; }
.item__body { flex: 1; min-width: 0; }

/* ── Mapa mini (detalle de desvío) ─────────────────────────────────── */
.minimap {
    height: 140px;
    border-radius: var(--r-card) var(--r-card) 0 0;
    background: radial-gradient(60% 90% at 50% 50%, #13211F 0%, #0C1416 70%);
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}
.minimap::before {
    content: "";
    position: absolute;
    inset: 0;
    background-image: linear-gradient(#18242700 0.5px, #182427 1px), linear-gradient(90deg, #18242700 0.5px, #182427 1px);
    background-size: 30px 30px;
    opacity: 0.5;
}
.minimap i {
    width: 16px;
    height: 16px;
    border-radius: var(--r-pill);
    background: var(--accent);
    box-shadow: 0 0 0 6px rgba(31, 201, 168, 0.18);
    position: relative;
}

/* ── Estado de carga / error ──────────────────────────────────────── */
.state { padding: 40px 24px; text-align: center; color: var(--text-2); font-size: 14px; }

@media (prefers-reduced-motion: reduce) {
    * { transition: none !important; animation: none !important; }
}

/* ── Barra superior global (#appbar: marca + tema + salir) ──────────── */
.appbar {
    flex: none;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: max(12px, env(safe-area-inset-top)) 16px 10px;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
}
.appbar__brand { display: flex; align-items: center; gap: 7px; }
.appbar__brand .sg { font-size: 15px; font-weight: 600; letter-spacing: -0.01em; color: var(--text); }
.appbar__brand b { color: var(--accent); font-weight: 600; }
.appbar__sp { flex: 1; }
.appbar__btn {
    flex: none;
    width: 38px;
    height: 38px;
    border-radius: var(--r-ctrl);
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text-2);
    display: flex;
    align-items: center;
    justify-content: center;
}
.appbar__btn:active { background: var(--surface-2); }

/* ── Tema claro ────────────────────────────────────────────────────────
   Mismos roles que el default oscuro, invertidos. Solo se activa con
   data-tema="light" en <html> (lo pone app.js / el snippet del <head>). */
:root[data-tema="light"] {
    --bg: #F4F7F8;
    --surface: #FFFFFF;
    --surface-2: #EDF2F4;
    --border: #DBE3E6;
    --border-2: #C3D0D4;
    --text: #0E1719;
    --text-2: #55636A;
    --text-3: #6C7B82;
    /* 22/09/2026 -- el #0E9C83 anterior daba 3.44:1 de contraste contra
       blanco (fórmula de luminancia relativa de WCAG 2.1), y --accent se
       usa como fondo de botones/chips (.btn, .seg button[aria-pressed],
       .chip[aria-pressed]) con texto blanco encima -- no pasaba AA
       (4.5:1). #0B7A66 da 5.26:1, verificado con el mismo cálculo.
       --accent-hi/--accent-soft bajan en la misma proporción que antes
       (~85% de --accent) para seguir siendo un tono más oscuro de hover
       y dan 6.71:1. */
    --accent: #0B7A66;
    --accent-hi: #096857;
    --accent-fg: #FFFFFF;
    --accent-bg: rgba(11, 122, 102, 0.12);
    --accent-soft: #096857;
    --telemetria: #1E86C4;
    --atencion: #B26A00;
    --critico: #C6343B;
    --reversa: #6D28D9;
}
:root[data-tema="light"] body { color-scheme: light; }
:root[data-tema="light"] .card--feat {
    background: linear-gradient(160deg, #E6F4F0 0%, #F5FAF9 62%);
    border-color: #CFE7E1;
}
:root[data-tema="light"] .btn:disabled { background: #E3E9EA; color: #9AA7AD; }
:root[data-tema="light"] .row { border-top-color: var(--border); }
:root[data-tema="light"] .row:first-child { border-top: none; }
:root[data-tema="light"] .item + .item { border-top-color: var(--border); }
:root[data-tema="light"] .level i { background: var(--border); }
:root[data-tema="light"] .minimap {
    background: radial-gradient(60% 90% at 50% 50%, #E6F3EF 0%, #F1F6F5 70%);
}
:root[data-tema="light"] .minimap::before {
    background-image: linear-gradient(#0000 0.5px, #DBE7E4 1px), linear-gradient(90deg, #0000 0.5px, #DBE7E4 1px);
    opacity: 0.7;
}
:root[data-tema="light"] .leaflet-container { background: #E7EEF0; }
:root[data-tema="light"] .leaflet-bar a { background: var(--surface); color: var(--text-2); border-color: var(--border); }
