/* Trackmex Control de Flota — identidad provisional (sustituible por el manual de marca) */
:root {
  --brand: #1D6FE8; --brand-strong: #0B2E63; --brand-soft: #E8F0FD; --accent: #FF8A1F;
  --bg: #F3F6FA; --surface: #FFFFFF; --surface-2: #F7F9FC; --border: #E2E8F0; --border-strong: #CBD5E1;
  --text: #0F172A; --text-2: #475569; --text-3: #64748B;
  --driving: #12A150; --stopped: #3B82F6; --nosignal: #8A94A6; --prealert: #E39A0B; --exceeded: #DC2626; --rest: #0E9F9A; --stale: #B7791F; --stale-bg: #FBF1E0; --change: #7C3AED;
  --driving-bg: #E7F6EE; --stopped-bg: #EAF2FE; --nosignal-bg: #EEF0F4; --prealert-bg: #FDF3DD; --exceeded-bg: #FDECEC; --rest-bg: #E2F5F4;
  --chart-grid: rgba(15, 23, 42, .08);
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 4px 16px rgba(15, 23, 42, .05);
  --radius: 14px; --radius-sm: 9px;
  --font: "Inter", "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --brand: #4C8DF6; --brand-strong: #9CC0FF; --brand-soft: #14233D; --accent: #FF9B3D;
    --bg: #0B1220; --surface: #111A2B; --surface-2: #0F1726; --border: #1F2A3D; --border-strong: #2C3A52;
    --text: #E6ECF5; --text-2: #A9B4C6; --text-3: #8391A7;
    --driving: #2FBF71; --stopped: #5B9BFF; --nosignal: #8F9BB0; --prealert: #F5B13D; --exceeded: #F25757; --rest: #2CC1BB; --stale: #E0A24A; --stale-bg: #2A2112; --change: #A78BFA;
    --driving-bg: #11291E; --stopped-bg: #13233F; --nosignal-bg: #1A2232; --prealert-bg: #2E2410; --exceeded-bg: #331517; --rest-bg: #0F2A2A;
    --chart-grid: rgba(230, 236, 245, .08); --shadow: 0 1px 2px rgba(0,0,0,.4); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --brand: #4C8DF6; --brand-strong: #9CC0FF; --brand-soft: #14233D; --accent: #FF9B3D;
  --bg: #0B1220; --surface: #111A2B; --surface-2: #0F1726; --border: #1F2A3D; --border-strong: #2C3A52;
  --text: #E6ECF5; --text-2: #A9B4C6; --text-3: #8391A7;
  --driving: #2FBF71; --stopped: #5B9BFF; --nosignal: #8F9BB0; --prealert: #F5B13D; --exceeded: #F25757; --rest: #2CC1BB; --stale: #E0A24A; --stale-bg: #2A2112; --change: #A78BFA;
  --driving-bg: #11291E; --stopped-bg: #13233F; --nosignal-bg: #1A2232; --prealert-bg: #2E2410; --exceeded-bg: #331517; --rest-bg: #0F2A2A;
  --chart-grid: rgba(230, 236, 245, .08); --shadow: 0 1px 2px rgba(0,0,0,.4); color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 14px/1.5 var(--font); color: var(--text); background: var(--bg); font-feature-settings: "tnum" 1; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.25; letter-spacing: -.01em; }
h1 { font-size: 22px; font-weight: 700; }
h2 { font-size: 15px; font-weight: 650; }
.muted { color: var(--text-3); }
.small { font-size: 12px; }
.num { font-variant-numeric: tabular-nums; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; border-radius: 4px; }

/* ---------- Estructura ---------- */
.app { display: grid; grid-template-columns: 236px 1fr; min-height: 100vh; }
.sidebar { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 4px;
  padding: 20px 14px; background: var(--brand-strong); color: #DCE6F7; }
:root[data-theme="dark"] .sidebar { background: #0A1424; border-right: 1px solid var(--border); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .sidebar { background: #0A1424; border-right: 1px solid var(--border); } }
.brand { display: flex; align-items: center; gap: 10px; padding: 0 6px 18px; color: #fff; }
.brand img { width: 36px; height: 36px; }
.brand-name { font-weight: 800; letter-spacing: .08em; font-size: 15px; }
.brand-sub { display: block; font-size: 11px; font-weight: 500; letter-spacing: .02em; color: #9FB4D6; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 9px; color: #C9D6EC; font-weight: 550; }
.nav a:hover { background: rgba(255,255,255,.07); text-decoration: none; color: #fff; }
.nav a[aria-current="page"] { background: rgba(255,255,255,.13); color: #fff; box-shadow: inset 3px 0 0 var(--accent); }
.nav svg, .tabbar svg { width: 18px; height: 18px; flex: none; }
.sidebar-foot { margin-top: auto; display: grid; gap: 10px; font-size: 12px; color: #9FB4D6; }
.sidebar-foot form { margin: 0; }
.link-btn { all: unset; cursor: pointer; color: #C9D6EC; display: inline-flex; gap: 6px; align-items: center; }
.link-btn:hover { color: #fff; }
.link-btn:focus-visible { outline: 2px solid var(--accent); }
.main { min-width: 0; padding: 22px 28px 40px; }
.topbar { display: none; }
.sim-banner { display: flex; align-items: center; gap: 8px; margin: -6px 0 18px; padding: 8px 12px; border-radius: var(--radius-sm);
  background: var(--prealert-bg); color: var(--text); border: 1px solid color-mix(in srgb, var(--prealert) 35%, transparent); font-size: 12.5px; }
.sim-banner strong { color: var(--prealert); }
.sim-banner svg { width: 16px; height: 16px; flex: none; color: var(--prealert); }
.historic-banner { align-items: flex-start; line-height: 1.45; }
@media print { .historic-banner { display: flex !important; } }
.link-btn svg, .btn svg, .icon { flex: none; }
.link-btn svg { width: 16px; height: 16px; }
.page-head { display: flex; flex-wrap: wrap; align-items: end; justify-content: space-between; gap: 12px; margin-bottom: 18px; }
.page-head p { margin: 4px 0 0; color: var(--text-3); }
.crumbs { font-size: 12px; color: var(--text-3); margin-bottom: 4px; }

/* ---------- Componentes ---------- */
.card { min-width: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; padding: 14px 16px 0; }
.card-body { padding: 14px 16px 16px; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); }
.grid-2-even { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.stack { display: grid; gap: 16px; }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(122px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { position: relative; padding: 14px 16px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); color: var(--text); overflow: hidden; }
a.kpi:hover { text-decoration: none; border-color: var(--border-strong); }
.kpi::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 4px; background: var(--kpi, var(--brand)); }
.kpi-label { display: flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; color: var(--text-2); }
.kpi-label svg { width: 15px; height: 15px; color: var(--kpi, var(--brand)); }
.kpi-value { font-size: 28px; font-weight: 750; letter-spacing: -.02em; margin-top: 4px; }
.kpi-note { font-size: 12px; color: var(--text-3); }
.k-driving { --kpi: var(--driving); } .k-stopped { --kpi: var(--stopped); } .k-nosignal { --kpi: var(--nosignal); }
.k-prealert { --kpi: var(--prealert); } .k-exceeded { --kpi: var(--exceeded); } .k-rest { --kpi: var(--rest); } .k-brand { --kpi: var(--brand); }

.chip { display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px 2px 8px; border-radius: 999px; font-size: 12px;
  font-weight: 600; white-space: nowrap; background: var(--nosignal-bg); color: var(--text-2); }
.chip::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.chip.driving { background: var(--driving-bg); color: var(--driving); }
.chip.stopped { background: var(--stopped-bg); color: var(--stopped); }
.chip.no_signal { background: var(--nosignal-bg); color: var(--nosignal); }
.chip.prealert, .chip.warning { background: var(--prealert-bg); color: var(--prealert); }
.chip.exceeded, .chip.violation { background: var(--exceeded-bg); color: var(--exceeded); }
.chip.ok, .chip.info { background: var(--surface-2); color: var(--text-3); border: 1px solid var(--border); }
.chip.rest { background: var(--rest-bg); color: var(--rest); }
.chip.complement { background: transparent; color: var(--text-3); border: 1px dashed var(--border); }
.chip.complement-info { background: var(--surface-2); color: var(--text-3); border: 1px solid var(--border); }
.complement .block { margin-top: 2px; }
.chip.plain::before { display: none; }
.pulse::before { animation: pulse 1.8s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .35; } }
@media (prefers-reduced-motion: reduce) { .pulse::before { animation: none; } }

.tabs { display: flex; gap: 6px; flex-wrap: wrap; }
.tab { padding: 6px 12px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); color: var(--text-2); font-weight: 600; font-size: 12.5px; }
.tab:hover { text-decoration: none; border-color: var(--border-strong); color: var(--text); }
.tab[aria-current="true"] { background: var(--brand); border-color: var(--brand); color: #fff; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 7px; height: 36px; padding: 0 14px; border-radius: 9px;
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); font: 600 13px var(--font); cursor: pointer; }
.btn:hover { text-decoration: none; border-color: var(--brand); }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { filter: brightness(1.07); }
.btn svg { width: 16px; height: 16px; }

/* Barras de progreso (SVG: sin estilos en linea por la CSP) */
.meter { display: grid; gap: 3px; min-width: 120px; }
.meter-top { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; }
.meter-top b { font-weight: 650; }
.meter-top b, .meter-top span { white-space: nowrap; }
.bar { display: block; width: 100%; height: 7px; }
.bar .bg { fill: var(--border); }
.bar .fill { fill: var(--driving); }
.bar .fill.prealert { fill: var(--prealert); }
.bar .fill.exceeded { fill: var(--exceeded); }
.bar .mark { stroke: var(--text-3); stroke-width: 1.5; }

/* Tablas */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 11.5px; font-weight: 650; text-transform: uppercase; letter-spacing: .04em; color: var(--text-3);
  padding: 10px 12px; border-bottom: 1px solid var(--border); background: var(--surface-2); white-space: nowrap; }
td { padding: 11px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: color-mix(in srgb, var(--brand-soft) 45%, transparent); }
td.right, th.right { text-align: right; }
.unit-cell a { font-weight: 650; color: var(--text); white-space: nowrap; }
th:first-child, td.unit-cell { min-width: 140px; }
.unit-cell .muted { display: block; font-size: 12px; }
.delta-pos { color: var(--exceeded); font-weight: 650; } .delta-neg { color: var(--driving); font-weight: 650; }

/* Alertas */
.alert-list { list-style: none; margin: 0; padding: 0; display: grid; }
.alert-list li { display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--border); }
.alert-list li:last-child { border-bottom: 0; }
.alert-ico { width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center; }
.alert-ico svg { width: 16px; height: 16px; }
.alert-ico.exceeded { background: var(--exceeded-bg); color: var(--exceeded); }
.alert-ico.prealert { background: var(--prealert-bg); color: var(--prealert); }
.alert-ico.no_signal { background: var(--nosignal-bg); color: var(--nosignal); }
.alert-ico.speed { background: var(--exceeded-bg); color: var(--exceeded); }
.empty { padding: 18px 0; text-align: center; color: var(--text-3); }

/* Mapa y graficas */
.map { height: 380px; border-radius: 0 0 var(--radius) var(--radius); background: var(--surface-2); z-index: 0; }
.map.tall { height: 440px; }
.map-card { display: flex; flex-direction: column; }
.map-card .card-head { padding-bottom: 12px; }
.map-card .map { flex: 1 1 auto; min-height: 380px; }
.map-note { padding: 8px 16px; font-size: 12px; color: var(--text-3); border-top: 1px solid var(--border); }
.chart-box { position: relative; height: 260px; }
.legend { display: flex; flex-wrap: wrap; gap: 12px; font-size: 12px; color: var(--text-2); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.lg-moving { background: var(--driving); } .lg-stopped { background: var(--stopped); } .lg-unknown { background: var(--nosignal); }
.lg-violation { background: var(--exceeded); } .lg-warning { background: var(--prealert); } .lg-rest { background: var(--rest); }
.leaflet-container { font: 12.5px var(--font); }
.leaflet-popup-content { margin: 10px 12px; }
.leaflet-popup-content a { font-weight: 650; }

/* Linea de tiempo */
.timeline { width: 100%; height: 86px; display: block; overflow: visible; }
.timeline .seg.moving { fill: var(--driving); } .timeline .seg.stopped { fill: var(--stopped); opacity: .55; }
.timeline .seg.unknown { fill: var(--nosignal); opacity: .5; }
.timeline .track { fill: var(--surface-2); stroke: var(--border); }
.timeline .tick { stroke: var(--border-strong); } .timeline .tick.midnight { stroke: var(--brand); stroke-dasharray: 3 3; }
.timeline text { font-size: 11px; fill: var(--text-3); }
.timeline text.day { fill: var(--brand); font-weight: 650; }
.timeline .mk { stroke: var(--surface); stroke-width: 1.5; }
.timeline .mk.violation { fill: var(--exceeded); } .timeline .mk.warning { fill: var(--prealert); } .timeline .mk.info { fill: var(--rest); }
.timeline .now { stroke: var(--text); stroke-width: 1.5; }

/* Detalle de unidad */
.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.fact { padding: 14px 16px; }
.fact-label { font-size: 12px; font-weight: 600; color: var(--text-2); }
.fact-value { font-size: 20px; font-weight: 720; margin: 2px 0 6px; }

/* Formularios */
.filters { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; align-items: end; }
label.field { display: grid; gap: 5px; font-size: 12px; font-weight: 600; color: var(--text-2); }
input, select { height: 36px; padding: 0 10px; border-radius: 9px; border: 1px solid var(--border-strong); background: var(--surface);
  color: var(--text); font: 14px var(--font); width: 100%; }
input:focus, select:focus { outline: 2px solid color-mix(in srgb, var(--brand) 40%, transparent); border-color: var(--brand); }
.check { display: flex; gap: 8px; align-items: center; font-size: 13px; font-weight: 550; color: var(--text-2); height: 36px; }
.check input { width: 16px; height: 16px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.rules-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; }
.rule { display: grid; grid-template-columns: 1fr 120px; gap: 6px 12px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--border); }
.rule:last-child { border-bottom: 0; }
.rule-desc { font-size: 13px; }
.rule-key { font: 11px var(--mono); color: var(--text-3); }
.rule-input { display: flex; align-items: center; gap: 6px; }
.rule-input span { font-size: 12px; color: var(--text-3); min-width: 30px; }
.badge-prov { font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--prealert); margin-left: 6px; }
.notice { padding: 12px 14px; border-radius: var(--radius-sm); background: var(--brand-soft); color: var(--text); font-size: 13px; }
.notice.error { background: var(--exceeded-bg); }
.notice ul { margin: 6px 0 0; padding-left: 18px; }
.htmx-request .spinner, .spinner.htmx-request { opacity: 1; }
.spinner { opacity: 0; transition: opacity .2s; font-size: 12px; color: var(--text-3); }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px;
  background: radial-gradient(1200px 600px at 10% -10%, color-mix(in srgb, var(--brand) 22%, transparent), transparent), var(--bg); }
.login-card { width: min(400px, 100%); padding: 28px; }
.login-card .brand { color: var(--text); padding: 0 0 20px; }
.login-card .brand-sub { color: var(--text-3); }
.login-card form { display: grid; gap: 14px; }

/* Barra inferior movil */
.tabbar { display: none; }

@media (max-width: 1100px) { .grid-2 { grid-template-columns: minmax(0, 1fr); } }
@media (max-width: 960px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .topbar { display: flex; align-items: center; justify-content: space-between; padding: 10px 16px; background: var(--brand-strong); color: #fff;
    position: sticky; top: 0; z-index: 20; }
  .topbar .brand { padding: 0; } .topbar .brand img { width: 30px; height: 30px; }
  .topbar form { margin: 0; }
  .main { padding: 16px 16px 92px; }
  .tabbar { display: grid; grid-template-columns: repeat(3, 1fr); position: fixed; inset: auto 0 0 0; z-index: 30;
    background: var(--surface); border-top: 1px solid var(--border); padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); }
  .tabbar a { display: grid; justify-items: center; gap: 2px; padding: 6px 0; font-size: 11px; font-weight: 600; color: var(--text-3); }
  .tabbar a[aria-current="page"] { color: var(--brand); }
  .grid-2-even { grid-template-columns: minmax(0, 1fr); }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpi-value { font-size: 24px; }
  .map, .map-card .map { height: 300px; min-height: 300px; }
  .tick-minor { display: none; }
  /* Tabla de flota como tarjetas */
  table.cards thead { display: none; }
  table.cards, table.cards tbody, table.cards tr, table.cards td { display: block; width: 100%; }
  table.cards tr { padding: 12px 14px; border-bottom: 1px solid var(--border); display: grid; grid-template-columns: 1fr 1fr; gap: 8px 14px; }
  table.cards td { padding: 0; border: 0; }
  table.cards td.span { grid-column: 1 / -1; }
  table.cards td[data-label]::before { content: attr(data-label); display: block; font-size: 11px; font-weight: 600; color: var(--text-3); text-transform: uppercase; letter-spacing: .03em; }
  table.cards tbody tr:hover td { background: none; }
  td.right { text-align: left; }
  .rule { grid-template-columns: 1fr; }
}
@media print { .sidebar, .tabbar, .topbar, .sim-banner, .actions { display: none; } .app { display: block; } }

/* ---------- Fase de mejoras: claridad operativa ---------- */
.block { display: block; }
.txt-exceeded { color: var(--exceeded); font-weight: 650; }
.txt-prealert { color: var(--prealert); font-weight: 650; }
.meter-foot { display: flex; flex-wrap: wrap; gap: 4px 8px; align-items: center; font-size: 12px; }
.badge-min { display: inline-block; padding: 0 6px; border-radius: 6px; font-size: 10.5px; font-weight: 650; letter-spacing: .02em;
  color: var(--stale); background: var(--stale-bg); border: 1px solid color-mix(in srgb, var(--stale) 30%, transparent); white-space: nowrap; }
.k-stale { --kpi: var(--stale); }
.lg-stale { background: var(--stale); }
.chip.stale, .chip.no_position { background: var(--stale-bg); color: var(--stale); }
.alert-ico.stale { background: var(--stale-bg); color: var(--stale); }
.alert-ico.speeding { background: var(--exceeded-bg); color: var(--exceeded); }
.alert-ico.prolonged_stop { background: var(--prealert-bg); color: var(--prealert); }
.alert-ico.ok { background: var(--driving-bg); color: var(--driving); }
.chip.st-active { background: var(--exceeded-bg); color: var(--exceeded); }
.chip.st-resolved { background: var(--driving-bg); color: var(--driving); }
.chip.st-historical { background: var(--surface-2); color: var(--text-3); border: 1px solid var(--border); }
.chip.st-informative { background: var(--stopped-bg); color: var(--stopped); }
.sub-head { margin: 14px 0 2px; font-size: 12px; font-weight: 650; text-transform: uppercase; letter-spacing: .04em; color: var(--text-3); }
.alert-list.compact li { padding: 7px 0; }
.alert-list.compact .alert-ico { width: 24px; height: 24px; }
.table-note { margin: 10px 0 0; }
.notice.warn { background: var(--stale-bg); border: 1px solid color-mix(in srgb, var(--stale) 30%, transparent); margin-bottom: 16px; }
.notice + .notice, .notice + form { margin-top: 12px; }
.detail-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; margin-bottom: 16px; }
.kv { display: grid; grid-template-columns: minmax(110px, 42%) 1fr; gap: 6px 12px; margin: 0 0 10px; font-size: 13px; }
.kv dt { color: var(--text-3); font-weight: 550; }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.kv-title { font-weight: 650; margin-bottom: 6px; }
.stack-sm { display: grid; gap: 16px; }
.tl-wrap { display: grid; grid-template-columns: 62px minmax(0, 1fr); gap: 8px; }
/* Filas alineadas con el SVG: actividad y=22..48, bloque y=56..65, ciclo y=70..79 */
.tl-labels { display: grid; grid-template-rows: 22px 26px 8px 9px 5px 9px; align-items: center; line-height: 1; font-size: 11px; }
.tl-labels span:first-child { grid-row: 2; } .tl-labels span:nth-child(2) { grid-row: 4; } .tl-labels span:nth-child(3) { grid-row: 6; }
.timeline { height: 106px; }
.timeline .seg, .timeline .band { cursor: pointer; }
.timeline .seg.rest { fill: var(--rest); }
.timeline .band.prealert { fill: var(--prealert); } .timeline .band.exceeded { fill: var(--exceeded); }
.timeline .seg:hover, .timeline .band:hover { opacity: .8; }
.timeline .seg:focus-visible, .timeline .band:focus-visible, .timeline .selected { outline: none; stroke: var(--text); stroke-width: 2; }
.timeline .change { stroke: var(--change); stroke-width: 2; stroke-dasharray: 4 2; }
.period-detail { margin-top: 8px; padding: 10px 12px; border-radius: var(--radius-sm); background: var(--surface-2); border: 1px solid var(--border); font-size: 13px; min-height: 42px; }
.period-detail b { font-weight: 650; }
details.periods { margin-top: 10px; }
details.periods summary { cursor: pointer; font-weight: 600; color: var(--brand); font-size: 13px; }
details.periods table { margin-top: 8px; }
.seg-chip.moving { background: var(--driving-bg); color: var(--driving); } .seg-chip.stopped { background: var(--stopped-bg); color: var(--stopped); }
.seg-chip.rest { background: var(--rest-bg); color: var(--rest); } .seg-chip.unknown { background: var(--nosignal-bg); color: var(--nosignal); }
.btn-xs { height: 28px; padding: 0 8px; }
.btn-xs svg { width: 14px; height: 14px; }
.events-table tr[hidden] { display: none !important; }
.events-table td .block { margin-top: 4px; }
.events-table tr.focused td { background: color-mix(in srgb, var(--brand-soft) 80%, transparent); }
button.tab { font: 600 12.5px var(--font); cursor: pointer; }
button.tab[aria-pressed="true"] { background: var(--brand); border-color: var(--brand); color: #fff; }
.badge-cat { display: inline-block; margin-left: 6px; padding: 0 6px; border-radius: 6px; font-size: 10.5px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .04em; vertical-align: 1px; }
.cat-preliminar { background: var(--brand-soft); color: var(--brand); }
.cat-provisional { background: var(--prealert-bg); color: var(--prealert); }
.cat-supuesto { background: var(--exceeded-bg); color: var(--exceeded); }
.cat-tecnico { background: var(--surface-2); color: var(--text-3); border: 1px solid var(--border); }
.rule-note { margin-top: 4px; font-size: 12px; color: var(--text-2); }
.report-tabs { margin-bottom: 16px; }
.page-head .btn { white-space: nowrap; }
@media (max-width: 1100px) { .detail-grid { grid-template-columns: minmax(0, 1fr); } }
@media (max-width: 960px) {
  .tl-wrap { grid-template-columns: minmax(0, 1fr); }
  .tl-labels { display: none; }
  .kv { grid-template-columns: minmax(100px, 40%) 1fr; }
}
/* Origen de los datos (fase de validacion) */
.origin-badge { display: inline-block; font-size: 10.5px; font-weight: 700; letter-spacing: .02em; padding: 1px 7px; border-radius: 99px; white-space: nowrap; vertical-align: middle; }
.origin-badge.real { background: color-mix(in srgb, var(--brand) 14%, transparent); color: var(--brand); border: 1px solid color-mix(in srgb, var(--brand) 35%, transparent); }
.origin-badge.sim { background: var(--surface-2); color: var(--text-3); border: 1px dashed var(--border-strong); }
.finding { border-left: 3px solid var(--exceeded); padding: 8px 10px; margin: 0 0 8px; background: var(--exceeded-bg); border-radius: 0 8px 8px 0; font-size: 13px; }
.finding.insufficient { border-left-color: var(--prealert); background: var(--prealert-bg); }
.finding b { display: block; }
.reasons { margin: 4px 0 0; padding-left: 18px; font-size: 12.5px; color: var(--text-2); }
.asof { font-size: 12.5px; color: var(--text-2); background: var(--brand-soft); border-radius: var(--radius-sm); padding: 6px 10px; margin: 0 0 12px; }
#live table.cards th, #live table.cards td { padding-left: 8px; padding-right: 8px; }
.events-table .chip { white-space: normal; text-align: left; }
@media (min-width: 961px) {
  .events-table { table-layout: fixed; width: 100%; }
  .events-table th:nth-child(1) { width: 84px; }
  .events-table th:nth-child(2) { width: 40%; }
  .events-table th:nth-child(4) { width: 52px; }
  .events-table td:nth-child(3) { overflow-wrap: anywhere; }
}
details.inventory { margin: 12px 0 4px; padding: 10px 12px; border: 1px dashed var(--border-strong); border-radius: var(--radius-sm); font-size: 13px; }
details.inventory summary { cursor: pointer; }
details.inventory table { margin-top: 8px; }
details.episode { border: 1px solid var(--border); border-left: 3px solid var(--exceeded); border-radius: 0 8px 8px 0; padding: 6px 10px; margin: 0 0 6px; font-size: 13px; }
details.episode.brief { border-left-color: var(--border-strong); }
details.episode summary { cursor: pointer; }
details.episode table { margin-top: 6px; }
.cutoff { display: flex; gap: 8px; align-items: flex-start; padding: 8px 12px; margin: 0 0 12px; border-radius: var(--radius-sm); background: var(--surface); border: 1px solid var(--border); font-size: 13px; }
.cutoff.historic { background: var(--brand-soft); border-color: color-mix(in srgb, var(--brand) 35%, transparent); }
.cutoff svg { width: 16px; height: 16px; flex: none; margin-top: 2px; }
.section-title { font-size: 15px; margin: 22px 0 10px; padding-bottom: 6px; border-bottom: 2px solid var(--border); }
table.generic th { white-space: normal; vertical-align: bottom; min-width: 72px; }
table.generic td { overflow-wrap: anywhere; }
/* ---------- Semaforo de atencion (tabla de Flota) ---------- */
:root { --att-rojo: var(--exceeded); --att-rojo-bg: var(--exceeded-bg); --att-amarillo: var(--prealert); --att-amarillo-bg: var(--prealert-bg);
  --att-gris: var(--nosignal); --att-gris-bg: var(--nosignal-bg); --att-verde: var(--driving); --att-verde-bg: var(--driving-bg); }
.att-asof { display: inline-flex; gap: 6px; align-items: center; font-size: 12.5px; color: var(--text-2); background: var(--brand-soft); border-radius: 999px; padding: 3px 10px; }
.att-asof svg { width: 14px; height: 14px; }
.att-bar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 0 18px 10px; }
.att-filter { display: inline-flex; align-items: center; gap: 7px; padding: 6px 12px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font-size: 13px; font-weight: 600; }
.att-filter:hover { text-decoration: none; border-color: var(--border-strong); }
.att-filter b { font-size: 15px; }
.att-filter[aria-current="true"] { outline: 2px solid var(--brand); outline-offset: 1px; }
.att-filter.rojo { background: var(--att-rojo-bg); } .att-filter.amarillo { background: var(--att-amarillo-bg); }
.att-filter.gris { background: var(--att-gris-bg); } .att-filter.verde { background: var(--att-verde-bg); }
.att-sub { font-size: 11px; font-weight: 600; color: var(--att-amarillo); }
.att-sort { margin-left: auto; display: inline-flex; gap: 6px; align-items: center; font-size: 12.5px; color: var(--text-3); }
.att-more { padding: 0 18px 8px; align-items: center; }
.att-dot { display: inline-block; width: 11px; height: 11px; border-radius: 50%; flex: none; background: var(--att-gris); box-shadow: 0 0 0 2px var(--surface); }
.att-dot.rojo { background: var(--att-rojo); } .att-dot.amarillo { background: var(--att-amarillo); }
.att-dot.gris { background: var(--att-gris); } .att-dot.verde { background: var(--att-verde); }
.att-row td:first-child { border-left: 4px solid var(--att-gris); }
.att-row.rojo td:first-child { border-left-color: var(--att-rojo); } .att-row.amarillo td:first-child { border-left-color: var(--att-amarillo); }
.att-row.verde td:first-child { border-left-color: var(--att-verde); }
.att-cell { min-width: 170px; max-width: 215px; }
.att-cell .badge-min { margin-top: 4px; }
.antecedent-tag { display: block; width: fit-content; margin: 4px 0 2px; font-size: 11.5px; font-weight: 700; padding: 2px 8px; border-radius: 6px;
  color: var(--prealert); background: var(--prealert-bg); border-left: 3px solid var(--exceeded); }
.att-table .unit-cell { min-width: 110px; }
.att-chip { display: inline-flex; align-items: center; gap: 7px; font-weight: 700; font-size: 12.5px; padding: 2px 10px 2px 7px; border-radius: 999px; white-space: nowrap; }
.att-chip.rojo { background: var(--att-rojo-bg); color: var(--att-rojo); } .att-chip.amarillo { background: var(--att-amarillo-bg); color: var(--att-amarillo); }
.att-chip.gris { background: var(--att-gris-bg); color: var(--text-2); } .att-chip.verde { background: var(--att-verde-bg); color: var(--att-verde); }
.att-reason { display: block; font-size: 12.5px; margin-top: 4px; color: var(--text); }
.pending-tag { display: inline-block; margin: 4px 0 0; font-size: 10.5px; font-weight: 700; letter-spacing: .02em; padding: 1px 7px; border-radius: 6px; border: 1px dashed var(--att-amarillo); color: var(--att-amarillo); }
.rest-cell { display: grid; gap: 3px; min-width: 140px; max-width: 190px; font-size: 12.5px; }
.bar .fill.rest { fill: var(--rest); }
.txt-muted { color: var(--text-2); font-weight: 650; } .txt-rest { color: var(--rest); font-weight: 650; }
.inc-cell { min-width: 130px; }
.att-legend { white-space: nowrap; } .att-legend .att-dot { width: 9px; height: 9px; margin-right: 4px; vertical-align: -1px; }
@media (max-width: 960px) {
  .att-bar, .att-more { padding: 0 14px 10px; } .att-sort { margin-left: 0; }
  table.cards tr.att-row { border-left: 5px solid var(--att-gris); }
  table.cards tr.att-row.rojo { border-left-color: var(--att-rojo); } table.cards tr.att-row.amarillo { border-left-color: var(--att-amarillo); }
  table.cards tr.att-row.verde { border-left-color: var(--att-verde); }
  .att-row td:first-child { border-left: 0; } .att-cell { max-width: none; }
}

/* Mapa base local: rótulo de corte junto al título del mapa */
.map-cutoff { display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px; border-radius: 999px; font-size: 12px;
  font-weight: 600; background: var(--prealert-bg, var(--surface-2)); color: var(--text-2); white-space: nowrap; }
.map-cutoff svg { width: 13px; height: 13px; }
@media (max-width: 700px) { .map-cutoff { white-space: normal; } }
/* El portal candidato añade Supervisión/Consolidados: evitar una segunda fila móvil. */
.tabbar { grid-template-columns: repeat(auto-fit, minmax(64px, 1fr)); }
