/* =====================================================================
   FLOTIKRONOS — sistema de diseño
   --brand / --brand-ink los inyecta el layout con el color de la empresa.
   ===================================================================== */
:root {
    --brand: #2563eb;
    --brand-ink: #ffffff;
    --brand-soft: color-mix(in srgb, var(--brand) 10%, white);
    --brand-line: color-mix(in srgb, var(--brand) 28%, white);

    --bg: #f4f6fa;
    --surface: #ffffff;
    --surface-2: #f8fafc;
    --border: #e4e8ef;
    --border-strong: #cfd6e1;
    --text: #0f172a;
    --text-2: #475569;
    --text-3: #64748b;

    /* Estados (reservados, siempre con icono + texto) */
    --ok: #16a34a;      --ok-soft: #dcfce7;
    --warn: #d97706;    --warn-soft: #fef3c7;
    --off: #64748b;     --off-soft: #e2e8f0;
    --danger: #dc2626;  --danger-soft: #fee2e2;

    --radius: 12px;
    --radius-sm: 8px;
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, .06);
    --shadow: 0 1px 3px rgba(15, 23, 42, .08), 0 4px 16px rgba(15, 23, 42, .06);
    --shadow-lg: 0 12px 40px rgba(15, 23, 42, .18);
    --sidebar-w: 248px;
    --topbar-h: 60px;
    --font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
    margin: 0;
    font-family: var(--font);
    font-size: 14px;
    line-height: 1.5;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.25; letter-spacing: -.01em; }
small { color: var(--text-3); }
code, .mono { font-family: ui-monospace, 'SFMono-Regular', Menlo, Consolas, monospace; font-size: .92em; }
.muted { color: var(--text-3); }
.nowrap { white-space: nowrap; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------- Layout ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar {
    width: var(--sidebar-w);
    flex-shrink: 0;
    background: #0f172a;
    color: #cbd5e1;
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    z-index: 1200;
}
.sidebar-brand {
    display: flex; align-items: center; gap: 10px;
    padding: 18px 18px 14px;
    min-height: 72px;
    text-decoration: none !important;
}
.sidebar-logo {
    max-width: 100%; max-height: 52px; object-fit: contain;
    background: #fff; border-radius: 10px; padding: 6px 10px;
}
.sidebar-mark {
    width: 36px; height: 36px; border-radius: 10px;
    background: var(--brand); color: var(--brand-ink);
    display: grid; place-items: center; font-size: 17px; flex-shrink: 0;
}
.sidebar-name { color: #fff; font-weight: 700; font-size: 15px; line-height: 1.2; }

.tenant-switch { margin: 0 14px 10px; padding: 10px; background: rgba(255,255,255,.06); border-radius: var(--radius-sm); }
.tenant-switch label { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: #94a3b8; margin-bottom: 6px; }
.tenant-switch select {
    width: 100%; background: #1e293b; color: #fff; border: 1px solid #334155;
    border-radius: 6px; padding: 7px 8px; font: inherit; font-size: 13px;
}

.nav { padding: 6px 10px; flex: 1; overflow-y: auto; }
.nav-section { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: #64748b; padding: 16px 10px 6px; }
.nav-item {
    display: flex; align-items: center; gap: 12px;
    padding: 10px 12px; margin: 2px 0;
    border-radius: var(--radius-sm);
    color: #cbd5e1; font-weight: 500;
    text-decoration: none !important;
    transition: background .15s, color .15s;
}
.nav-item i { width: 18px; text-align: center; color: #94a3b8; }
.nav-item:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav-item.active { background: var(--brand); color: var(--brand-ink); }
.nav-item.active i { color: var(--brand-ink); }

.sidebar-user {
    display: flex; align-items: center; gap: 10px;
    margin: 10px; padding: 10px;
    background: rgba(255,255,255,.05); border-radius: var(--radius-sm);
}
.sidebar-user-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.sidebar-user-text strong { color: #fff; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-user-text small { color: #94a3b8; font-size: 12px; }
.sidebar-user .icon-btn { color: #94a3b8; }
.sidebar-user .icon-btn:hover { color: #fff; background: rgba(255,255,255,.08); }
.sidebar-powered { font-size: 11px; color: #475569; text-align: center; padding: 0 0 12px; }
.avatar {
    width: 34px; height: 34px; border-radius: 50%;
    background: var(--brand); color: var(--brand-ink);
    display: grid; place-items: center; font-weight: 700; flex-shrink: 0;
}

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
    height: var(--topbar-h);
    display: flex; align-items: center; gap: 14px;
    padding: 0 28px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky; top: 0; z-index: 1000;
}
.topbar-title { font-size: 18px; font-weight: 700; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-actions { display: flex; gap: 8px; align-items: center; }
.menu-toggle { display: none; }
.content { padding: 24px 28px 40px; flex: 1; }
.sidebar-backdrop { display: none; }

/* ---------- Componentes ---------- */
.icon-btn {
    width: 34px; height: 34px; border-radius: 8px;
    border: 0; background: transparent; color: var(--text-2);
    display: inline-grid; place-items: center; cursor: pointer; font-size: 15px;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    height: 38px; padding: 0 16px;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    background: var(--brand); color: var(--brand-ink);
    font: inherit; font-weight: 600; font-size: 14px;
    cursor: pointer; white-space: nowrap;
    text-decoration: none !important;
    transition: filter .15s, background .15s, box-shadow .15s;
}
.btn:hover { filter: brightness(.94); }
.btn:focus-visible, .input:focus-visible, select:focus-visible { outline: 3px solid var(--brand-line); outline-offset: 1px; }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.btn-secondary:hover { background: var(--surface-2); filter: none; }
.btn-ghost { background: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-2); filter: none; }
.btn-danger { background: var(--surface); color: var(--danger); border-color: #fecaca; }
.btn-danger:hover { background: var(--danger-soft); filter: none; }
.btn-sm { height: 32px; padding: 0 12px; font-size: 13px; }
.btn-block { width: 100%; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}
.card-pad { padding: 20px; }
.card-header {
    display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
    padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.card-header h2 { font-size: 15px; font-weight: 600; flex: 1; }
.card-body { padding: 20px; }
.section-gap { margin-top: 20px; }

.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

/* KPIs */
.kpi { padding: 16px 18px; display: flex; gap: 14px; align-items: center; }
.kpi-icon {
    width: 42px; height: 42px; border-radius: 10px;
    display: grid; place-items: center; font-size: 17px; flex-shrink: 0;
    background: var(--brand-soft); color: var(--brand);
}
.kpi-label { font-size: 12px; color: var(--text-3); font-weight: 500; }
.kpi-value { font-size: 22px; font-weight: 700; letter-spacing: -.02em; line-height: 1.2; }
.kpi-value small { font-size: 13px; font-weight: 500; }

/* Formularios */
.form-grid { display: grid; gap: 16px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-grid .full { grid-column: 1 / -1; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label, .label { font-size: 13px; font-weight: 600; color: var(--text-2); }
.field .hint { font-size: 12px; color: var(--text-3); }
.input, .field input[type=text], .field input[type=password], .field input[type=email], .field input[type=date],
.field input[type=tel], .field input[type=search], .field select, .field textarea, select.input {
    width: 100%; height: 40px; padding: 0 12px;
    border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
    background: var(--surface); color: var(--text);
    font: inherit; font-size: 14px;
    transition: border-color .15s, box-shadow .15s;
}
.field textarea { height: auto; min-height: 80px; padding: 10px 12px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus, .input:focus {
    outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-line);
}
.field input[type=color] { width: 56px; height: 40px; padding: 3px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: #fff; }
.check { display: inline-flex; align-items: center; gap: 8px; font-weight: 500; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--brand); }
.form-actions { display: flex; gap: 10px; justify-content: flex-end; padding-top: 4px; }
.input-group { display: flex; }
.input-group .addon {
    display: flex; align-items: center; padding: 0 10px;
    background: var(--surface-2); border: 1px solid var(--border-strong); border-right: 0;
    border-radius: var(--radius-sm) 0 0 var(--radius-sm); color: var(--text-3); font-size: 13px; white-space: nowrap;
}
.input-group input { border-radius: 0 var(--radius-sm) var(--radius-sm) 0 !important; }

.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 16px; }
.toolbar .spacer { flex: 1; }
.search-box { position: relative; min-width: 240px; }
.search-box i { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--text-3); }
.search-box input { padding-left: 36px !important; }

/* Pestañas de filtro */
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
    display: inline-flex; align-items: center; gap: 6px;
    height: 32px; padding: 0 12px; border-radius: 999px;
    border: 1px solid var(--border-strong); background: var(--surface);
    color: var(--text-2); font-weight: 500; font-size: 13px; cursor: pointer;
    text-decoration: none !important;
}
.chip:hover { background: var(--surface-2); }
.chip.active { background: var(--text); border-color: var(--text); color: #fff; }
.chip .count { font-weight: 700; }

/* Estado */
.status {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 3px 10px 3px 8px; border-radius: 999px;
    font-size: 12px; font-weight: 600; white-space: nowrap;
}
.status i { font-size: 10px; }
.status-moving { background: var(--ok-soft); color: #166534; }
.status-stopped { background: var(--warn-soft); color: #92400e; }
.status-idle { background: #ede9fe; color: #5b21b6; }
.engine { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.engine i { font-size: 10px; }
.engine-on { color: #166534; }
.engine-off { color: var(--text-3); }
.status-offline { background: var(--off-soft); color: #334155; }
.status-nodata { background: #f1f5f9; color: #64748b; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 6px; font-size: 12px; font-weight: 600; background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border); }
.badge-brand { background: var(--brand-soft); color: var(--brand); border-color: var(--brand-line); }
.badge-ok { background: var(--ok-soft); color: #166534; border-color: #bbf7d0; }
.badge-danger { background: var(--danger-soft); color: #991b1b; border-color: #fecaca; }

/* Tablas */
.table-wrap { overflow-x: auto; }
table.table { width: 100%; border-collapse: collapse; }
.table th {
    text-align: left; font-size: 12px; font-weight: 600; color: var(--text-3);
    text-transform: uppercase; letter-spacing: .04em;
    padding: 10px 16px; background: var(--surface-2); border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
.table td { padding: 12px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: #fafbfd; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table .actions { text-align: right; white-space: nowrap; }
.table .actions form { display: inline; }
.cell-main { display: flex; align-items: center; gap: 12px; }
.cell-icon {
    width: 36px; height: 36px; border-radius: 9px; flex-shrink: 0;
    display: grid; place-items: center; background: var(--brand-soft); color: var(--brand);
}
.cell-main strong { display: block; }
.cell-main small { display: block; }
.plate {
    display: inline-block; font-family: ui-monospace, Menlo, Consolas, monospace; font-weight: 600;
    font-size: 12px; letter-spacing: .04em; padding: 2px 7px; border-radius: 5px;
    background: #fff; border: 1.5px solid #1e3a8a; color: #1e3a8a;
}

.empty {
    text-align: center; padding: 48px 20px; color: var(--text-3);
}
.empty i { font-size: 34px; color: var(--border-strong); margin-bottom: 12px; display: block; }
.empty strong { display: block; color: var(--text); font-size: 15px; margin-bottom: 4px; }

/* Avisos */
.flash {
    display: flex; align-items: center; gap: 10px;
    margin: 16px 28px 0; padding: 12px 14px;
    border-radius: var(--radius-sm); font-weight: 500;
    border: 1px solid;
}
.flash span { flex: 1; }
.flash-success { background: var(--ok-soft); border-color: #bbf7d0; color: #166534; }
.flash-error { background: var(--danger-soft); border-color: #fecaca; color: #991b1b; }
.flash-close { background: none; border: 0; color: inherit; cursor: pointer; opacity: .6; font-size: 15px; }
.alert { padding: 12px 14px; border-radius: var(--radius-sm); background: var(--brand-soft); border: 1px solid var(--brand-line); color: var(--text); }
.alert-warn { background: var(--warn-soft); border-color: #fde68a; }

/* Copiar enlace */
.copy-field { display: flex; gap: 8px; }
.copy-field input { flex: 1; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px; background: var(--surface-2) !important; }

/* Modal */
.modal-backdrop {
    position: fixed; inset: 0; background: rgba(15,23,42,.5);
    display: none; align-items: center; justify-content: center; z-index: 3000; padding: 16px;
}
.modal-backdrop.open { display: flex; }
.modal { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow-lg); width: 100%; max-width: 460px; }
.modal .card-header { border-bottom: 1px solid var(--border); }

/* =====================================================================
   MAPA EN VIVO
   ===================================================================== */
.page-map .content, .page-history .content { padding: 0; display: flex; flex-direction: column; }
.page-map .flash, .page-history .flash { margin: 12px 16px 0; }
.fleet-layout { flex: 1; display: flex; min-height: 0; height: calc(100vh - var(--topbar-h)); }
.fleet-panel {
    width: 360px; flex-shrink: 0; background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex; flex-direction: column; min-height: 0;
}
.fleet-kpis { display: grid; grid-template-columns: repeat(4, 1fr); border-bottom: 1px solid var(--border); }
.fleet-kpi { padding: 12px 10px; text-align: center; border: 0; background: none; cursor: pointer; font: inherit; border-right: 1px solid var(--border); }
.fleet-kpi:last-child { border-right: 0; }
.fleet-kpi:hover { background: var(--surface-2); }
.fleet-kpi.active { box-shadow: inset 0 -3px 0 var(--brand); background: var(--brand-soft); }
.fleet-kpi b { display: block; font-size: 20px; font-weight: 700; line-height: 1.2; }
.fleet-kpi span { font-size: 11px; color: var(--text-3); font-weight: 600; display: inline-flex; align-items: center; gap: 5px; }
.fleet-search { padding: 12px; border-bottom: 1px solid var(--border); }
.fleet-list { flex: 1; overflow-y: auto; }
.vehicle {
    display: flex; gap: 12px; align-items: flex-start;
    padding: 12px 14px; border-bottom: 1px solid var(--border);
    cursor: pointer; transition: background .12s;
}
.vehicle:hover { background: var(--surface-2); }
.vehicle.selected { background: var(--brand-soft); box-shadow: inset 3px 0 0 var(--brand); }
.vehicle-icon {
    width: 40px; height: 40px; border-radius: 10px; flex-shrink: 0;
    display: grid; place-items: center; font-size: 16px; color: #fff;
}
.vehicle-body { flex: 1; min-width: 0; }
.vehicle-top { display: flex; align-items: center; gap: 8px; justify-content: space-between; }
.vehicle-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.vehicle-meta { display: flex; gap: 10px; align-items: center; margin-top: 4px; font-size: 12px; color: var(--text-3); flex-wrap: wrap; }
.vehicle-actions { display: flex; gap: 6px; margin-top: 8px; }
.vehicle-speed { font-weight: 700; color: var(--text); font-variant-numeric: tabular-nums; }
.fleet-map-wrap { flex: 1; position: relative; min-width: 0; }
#fleetMap, #historyMap { position: absolute; inset: 0; background: #e5e7eb; }
.map-overlay-btns { position: absolute; top: 12px; right: 12px; z-index: 900; display: flex; flex-direction: column; gap: 8px; }
.map-btn {
    width: 38px; height: 38px; border-radius: 9px; border: 0;
    background: #fff; box-shadow: var(--shadow); color: var(--text-2);
    cursor: pointer; display: grid; place-items: center; font-size: 15px;
}
.map-btn:hover { color: var(--text); }
.map-btn.active { background: var(--brand); color: var(--brand-ink); }
.live-pill {
    position: absolute; left: 12px; bottom: 24px; z-index: 900;
    background: rgba(15,23,42,.85); color: #fff; padding: 6px 12px; border-radius: 999px;
    font-size: 12px; font-weight: 600; display: flex; align-items: center; gap: 8px;
}
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: #22c55e; box-shadow: 0 0 0 0 rgba(34,197,94,.7); animation: pulse 2s infinite; }
.live-pill.stale .live-dot { background: #f59e0b; animation: none; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(34,197,94,.6); } 70% { box-shadow: 0 0 0 8px rgba(34,197,94,0); } 100% { box-shadow: 0 0 0 0 rgba(34,197,94,0); } }

/* Marcador de vehículo */
.vmarker { position: relative; width: 40px; height: 40px; }
.vmarker-body {
    position: absolute; inset: 4px; border-radius: 50%;
    display: grid; place-items: center; color: #fff; font-size: 13px;
    border: 2.5px solid #fff; box-shadow: 0 2px 8px rgba(0,0,0,.35);
}
.vmarker-label {
    position: absolute; top: 40px; left: 50%; transform: translateX(-50%);
    background: #fff; color: #0f172a; font-size: 11px; font-weight: 700;
    padding: 1px 6px; border-radius: 4px; white-space: nowrap; box-shadow: 0 1px 4px rgba(0,0,0,.25);
}
.vmarker.selected .vmarker-body { box-shadow: 0 0 0 4px var(--brand), 0 2px 8px rgba(0,0,0,.35); }

.leaflet-popup-content-wrapper { border-radius: 12px; box-shadow: var(--shadow-lg); }
.leaflet-popup-content { margin: 14px 16px; font-family: var(--font); font-size: 13px; line-height: 1.5; }
.pop-title { font-weight: 700; font-size: 14px; margin-bottom: 2px; }
.pop-row { display: flex; justify-content: space-between; gap: 16px; color: var(--text-2); }
.pop-row b { color: var(--text); }
.pop-actions { display: flex; gap: 6px; margin-top: 10px; }
.pop-actions { flex-wrap: wrap; }
.pop-actions .btn { height: 34px; font-size: 13px; padding: 0 12px; flex: 1 1 auto; }
/* Leaflet pinta todos los enlaces de dentro del mapa en azul: los botones mantienen su color */
.leaflet-container a.btn { color: var(--brand-ink); text-decoration: none; }
.leaflet-container a.btn-secondary { color: var(--text); }
.leaflet-container a.btn-ghost { color: var(--text-2); }
.leaflet-container a.btn-danger { color: var(--danger); }
.leaflet-control-layers { border-radius: 10px !important; border: 0 !important; box-shadow: var(--shadow) !important; }
.leaflet-control-layers-toggle { background-image: none !important; width: 40px !important; height: 40px !important; display: grid !important; place-items: center; }
.leaflet-control-layers-toggle::before { content: "\f279"; font-family: "Font Awesome 6 Free"; font-weight: 900; font-size: 17px; color: var(--text-2); }
.leaflet-control-layers-toggle:hover::before { color: var(--brand); }

/* Historial: más espacio para el mapa */
.hist-chart-hidden .speed-profile { display: none !important; }
.fs-btn, .panel-mobile-head { display: none; }
.map-full .history-filters, .map-full .filters-summary, .map-full .history-panel, .map-full .speed-profile,
.map-full .topbar, .map-full .sidebar, .map-full .flash { display: none !important; }
/* Pantalla completa: alto VISIBLE (dvh) y el reproductor se mantiene */
.map-full .history-layout { height: 100vh !important; height: 100dvh !important; }
.map-full .player-legend { display: none; }
.map-full #btnPanel, .map-full #btnBottom { display: none; }
.map-full .fleet-panel { display: none !important; }
.map-full .fleet-layout { height: 100vh !important; height: 100dvh !important; }

/* Etiqueta de zona sobre el polígono */
.zone-label { background: rgba(255,255,255,.85); border: 0; box-shadow: none; font-weight: 700; font-size: 11px; color: #0f172a; padding: 1px 6px; border-radius: 4px; }
.zone-label::before { display: none; }
.tl-zone { display: inline-flex; align-items: center; gap: 5px; font-weight: 600; }
.tl-zone i { font-size: 10px; }
.tl-addr { color: var(--text-3); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.idle-badge { display: inline-flex; align-items: center; gap: 4px; color: #b45309; font-weight: 600; }
.stop-cluster { min-width: 30px; height: 30px; border-radius: 15px; padding: 0 8px; background: #0f172a; color: #fff; display: flex; align-items: center; justify-content: center; gap: 4px; font-weight: 700; font-size: 12px; border: 2px solid #fff; box-shadow: 0 2px 6px rgba(0,0,0,.4); }
.time-mark { background: #0f172a; color: #fff; font-size: 10px; font-weight: 700; padding: 1px 5px; border-radius: 4px; white-space: nowrap; box-shadow: 0 1px 3px rgba(0,0,0,.4); }
.player-track { position: relative; flex: 1; min-width: 160px; display: flex; align-items: center; }
.player-track .player-slider { width: 100%; }
.player-ticks { position: absolute; left: 0; right: 0; top: -14px; height: 12px; pointer-events: none; }
.player-tick { position: absolute; transform: translateX(-50%); pointer-events: auto; cursor: pointer; font-size: 9px; font-weight: 700; background: #fff; border: 1.5px solid #0f172a; color: #0f172a; border-radius: 3px; padding: 0 3px; line-height: 10px; }
.player-tick:hover { background: #0f172a; color: #fff; }

/* Panel lateral plegable (botón de lista en el mapa) */
.fleet-panel, .history-panel { transition: margin-left .2s ease; }
.panel-hidden .fleet-panel { margin-left: -360px; }
.panel-hidden .history-panel { margin-left: -380px; }

/* =====================================================================
   HISTORIAL
   ===================================================================== */
.history-filters {
    display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap;
    padding: 12px 16px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.history-filters .field { gap: 4px; }
.history-filters .field label { font-size: 12px; }
.history-filters .field select, .history-filters .field input { height: 36px; }
.history-filters .presets { display: flex; gap: 4px; }
.history-filters .presets .chip { height: 36px; border-radius: 8px; }
.history-layout { flex: 1; display: flex; min-height: 0; }
/* El historial ocupa exactamente la pantalla: la lista de trayectos hace
   scroll por dentro y el reproductor queda siempre visible abajo. */
.page-history .main { height: 100vh; overflow: hidden; }
.page-history .content { min-height: 0; }
.page-history .history-panel, .page-history .history-map-wrap { min-height: 0; }
.history-panel {
    width: 380px; flex-shrink: 0; background: var(--surface);
    border-right: 1px solid var(--border); display: flex; flex-direction: column; min-height: 0;
}
.history-summary { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1px; background: var(--border); border-bottom: 1px solid var(--border); }
.hs { background: var(--surface); padding: 12px 14px; }
.hs-label { font-size: 11px; color: var(--text-3); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.hs-value { font-size: 18px; font-weight: 700; letter-spacing: -.01em; font-variant-numeric: tabular-nums; }
.history-tools { display: flex; gap: 6px; align-items: center; padding: 10px 12px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.seg { display: inline-flex; border: 1px solid var(--border-strong); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: var(--surface); padding: 6px 10px; font: inherit; font-size: 12px; font-weight: 600; color: var(--text-2); cursor: pointer; }
.seg button + button { border-left: 1px solid var(--border-strong); }
.seg button.active { background: var(--text); color: #fff; }
.timeline { flex: 1; overflow-y: auto; padding: 8px 0 16px; }
.tl-item { position: relative; display: flex; gap: 12px; padding: 10px 14px 10px 14px; cursor: pointer; }
.tl-item:hover { background: var(--surface-2); }
.tl-item.selected { background: var(--brand-soft); }
.tl-rail { position: relative; width: 30px; flex-shrink: 0; display: flex; justify-content: center; }
.tl-rail::after { content: ''; position: absolute; top: 34px; bottom: -14px; width: 2px; background: var(--border); }
.tl-item:last-child .tl-rail::after { display: none; }
.tl-num {
    position: relative; z-index: 1;
    width: 30px; height: 30px; border-radius: 50%;
    display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 13px;
    border: 2px solid #fff; box-shadow: 0 0 0 1px rgba(15,23,42,.15);
}
.tl-stop .tl-num { background: #fff; color: var(--text-2); border: 2px solid var(--border-strong); box-shadow: none; font-size: 11px; }
.tl-body { flex: 1; min-width: 0; }
.tl-title { display: flex; justify-content: space-between; gap: 8px; font-weight: 600; }
.tl-time { font-variant-numeric: tabular-nums; }
.tl-meta { display: flex; gap: 10px; flex-wrap: wrap; font-size: 12px; color: var(--text-3); margin-top: 2px; }
.tl-meta b { color: var(--text-2); font-weight: 600; }
.tl-stop .tl-title { font-weight: 500; color: var(--text-2); }
.tl-day { padding: 14px 14px 6px; font-size: 12px; font-weight: 700; color: var(--text-3); text-transform: uppercase; letter-spacing: .05em; }

.history-map-wrap { flex: 1; position: relative; min-width: 0; display: flex; flex-direction: column; }
.history-map-wrap .map-area { flex: 1; position: relative; }
.history-empty {
    position: absolute; inset: 0; z-index: 800; display: grid; place-items: center;
    background: rgba(244,246,250,.85); text-align: center; padding: 20px;
}
.history-empty .empty { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); max-width: 380px; }
.history-loading { position: absolute; inset: 0; z-index: 850; display: none; place-items: center; background: rgba(255,255,255,.5); }
.history-loading.on { display: grid; }
.spinner { width: 36px; height: 36px; border: 3px solid var(--border); border-top-color: var(--brand); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.player {
    background: var(--surface); border-top: 1px solid var(--border);
    padding: 10px 16px; display: flex; gap: 14px; align-items: center; flex-wrap: wrap;
}
.player-btns { display: flex; gap: 4px; }
.player-btns .icon-btn { border: 1px solid var(--border-strong); }
.player-btns .play { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.player-slider { flex: 1; min-width: 160px; accent-color: var(--brand); }
.player-readout { display: flex; gap: 14px; font-variant-numeric: tabular-nums; font-size: 13px; }
.player-readout b { font-size: 15px; }
.speed-profile { height: 64px; padding: 6px 16px 4px; background: var(--surface); border-top: 1px solid var(--border); position: relative; }
.speed-profile svg { width: 100%; height: 100%; display: block; overflow: visible; }
.sp-tip {
    position: absolute; top: -6px; transform: translate(-50%, -100%); pointer-events: none;
    background: #0f172a; color: #fff; font-size: 12px; padding: 4px 8px; border-radius: 6px; white-space: nowrap; display: none;
}

/* Marcadores del historial */
.trip-start {
    width: 28px; height: 28px; border-radius: 50%; color: #fff;
    display: grid; place-items: center; font-weight: 800; font-size: 13px;
    border: 2.5px solid #fff; box-shadow: 0 2px 6px rgba(0,0,0,.4);
}
.trip-stop {
    min-width: 26px; height: 26px; border-radius: 7px; background: #fff; color: #0f172a;
    display: flex; align-items: center; justify-content: center; gap: 3px; padding: 0 5px;
    font-weight: 700; font-size: 11px; border: 2px solid #0f172a; box-shadow: 0 2px 6px rgba(0,0,0,.35);
    white-space: nowrap;
}
.trip-end { width: 30px; height: 30px; border-radius: 50%; background: #0f172a; color: #fff; display: grid; place-items: center; border: 2.5px solid #fff; box-shadow: 0 2px 6px rgba(0,0,0,.4); }
.pt-num {
    min-width: 18px; height: 18px; border-radius: 9px; padding: 0 4px;
    background: #fff; color: #0f172a; font-size: 10px; font-weight: 700;
    display: flex; align-items: center; justify-content: center;
    border: 1.5px solid currentColor; box-shadow: 0 1px 3px rgba(0,0,0,.3);
}
.dir-arrow { color: #fff; font-size: 11px; text-shadow: 0 0 2px rgba(0,0,0,.9), 0 0 4px rgba(0,0,0,.6); line-height: 1; }
.event-pin { width: 24px; height: 24px; border-radius: 50%; background: #fff; border: 2px solid var(--danger); color: var(--danger); display: grid; place-items: center; font-size: 10px; box-shadow: 0 1px 4px rgba(0,0,0,.35); }
.pm-wrap { position: relative; width: 44px; height: 44px; }
.pm-wrap .player-marker { position: absolute; inset: 4px; width: auto; height: auto; }
.player-marker { width: 36px; height: 36px; border-radius: 50%; background: #0f172a; color: #fff; display: grid; place-items: center; border: 3px solid #fff; box-shadow: 0 2px 10px rgba(0,0,0,.45); font-size: 14px; }
.pm-heading { position: absolute; inset: -9px; display: flex; justify-content: flex-end; align-items: flex-start; pointer-events: none; transition: transform .15s linear; }
.pm-heading i { color: #0f172a; font-size: 15px; text-shadow: 0 0 3px #fff, 0 0 3px #fff; }
.pm-label { background: #0f172a; color: #fff; border: 0; border-radius: 8px; padding: 5px 9px; font-size: 12px; font-weight: 500; box-shadow: 0 2px 8px rgba(0,0,0,.35); white-space: nowrap; }
.pm-label::before { border-right-color: #0f172a !important; }
.pm-label b { font-variant-numeric: tabular-nums; margin-right: 6px; }
.pm-label small { color: #94a3b8; }
.pm-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 5px; vertical-align: middle; }
.player-strip { position: absolute; left: 0; right: 0; top: 50%; height: 6px; margin-top: -3px; border-radius: 3px; overflow: hidden; background: #e2e8f0; pointer-events: none; }
.player-strip span { position: absolute; top: 0; bottom: 0; }
.player-progress { position: absolute; left: 0; top: 50%; height: 6px; margin-top: -3px; border-radius: 3px; background: rgba(15,23,42,.35); pointer-events: none; }
.player-track .player-slider { position: relative; z-index: 1; background: transparent; -webkit-appearance: none; appearance: none; height: 22px; }
.player-track .player-slider::-webkit-slider-runnable-track { background: transparent; height: 6px; }
.player-track .player-slider::-moz-range-track { background: transparent; height: 6px; }
.player-track .player-slider::-webkit-slider-thumb { -webkit-appearance: none; width: 16px; height: 16px; border-radius: 50%; background: #0f172a; border: 3px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.4); margin-top: -5px; cursor: pointer; }
.player-track .player-slider::-moz-range-thumb { width: 12px; height: 12px; border-radius: 50%; background: #0f172a; border: 3px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.4); cursor: pointer; }
.player-opts { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.player-legend { width: 100%; display: flex; gap: 14px; font-size: 11px; color: var(--text-3); margin-top: -4px; }
.player-legend i { display: inline-block; width: 10px; height: 4px; border-radius: 2px; margin-right: 5px; vertical-align: middle; }

/* =====================================================================
   INFORMES
   ===================================================================== */
.chart-box { position: relative; height: 260px; }
.chart-box svg { width: 100%; height: 100%; display: block; overflow: visible; }
.chart-tip {
    position: absolute; pointer-events: none; display: none;
    background: #0f172a; color: #fff; font-size: 12px; padding: 6px 10px; border-radius: 8px;
    transform: translate(-50%, -110%); white-space: nowrap; box-shadow: var(--shadow);
}
.bar-inline { height: 6px; border-radius: 3px; background: var(--brand); min-width: 2px; }
.bar-track { background: var(--surface-2); border-radius: 3px; width: 120px; }

/* =====================================================================
   LOGIN
   ===================================================================== */
.login-page { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(380px, 1fr); background: var(--surface); }
.login-hero {
    position: relative; overflow: hidden;
    background: linear-gradient(150deg, color-mix(in srgb, var(--brand) 88%, #000) 0%, var(--brand) 55%, color-mix(in srgb, var(--brand) 70%, #fff) 100%);
    color: var(--brand-ink); padding: 48px; display: flex; flex-direction: column; justify-content: space-between;
}
.login-hero::before {
    content: ''; position: absolute; inset: 0; opacity: .14;
    background-image: radial-gradient(currentColor 1px, transparent 1px);
    background-size: 22px 22px;
}
.login-hero > * { position: relative; }
.login-hero h2 { font-size: 34px; font-weight: 700; max-width: 460px; letter-spacing: -.02em; }
.login-hero p { font-size: 16px; opacity: .85; max-width: 440px; }
.login-features { display: grid; gap: 14px; margin-top: 28px; }
.login-features div { display: flex; gap: 12px; align-items: center; font-weight: 500; }
.login-features i { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; background: rgba(255,255,255,.16); }
.login-hero-brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; }
.login-side { display: flex; align-items: center; justify-content: center; padding: 40px 24px; }
.login-box { width: 100%; max-width: 380px; }
.login-logo { display: block; max-width: 240px; max-height: 96px; object-fit: contain; margin-bottom: 28px; }
.login-mark { width: 52px; height: 52px; border-radius: 14px; background: var(--brand); color: var(--brand-ink); display: grid; place-items: center; font-size: 22px; margin-bottom: 24px; }
.login-box h1 { font-size: 26px; font-weight: 700; letter-spacing: -.02em; }
.login-box .lead { color: var(--text-3); margin: 6px 0 26px; }
.login-box form { display: grid; gap: 16px; }
.login-box .btn { height: 46px; font-size: 15px; }
.pw-wrap { position: relative; }
.pw-wrap .icon-btn { position: absolute; right: 4px; top: 3px; }
.login-msg { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: var(--radius-sm); margin-bottom: 18px; font-weight: 500; }
.login-msg.error { background: var(--danger-soft); color: #991b1b; }
.login-msg.info { background: var(--ok-soft); color: #166534; }
.login-foot { margin-top: 32px; color: var(--text-3); font-size: 12px; display: flex; align-items: center; gap: 8px; }

/* Página pública de seguimiento */
.share-page { height: 100vh; display: flex; flex-direction: column; }
.share-head { display: flex; align-items: center; gap: 14px; padding: 12px 20px; background: #fff; border-bottom: 3px solid var(--brand); }
.share-head img { max-height: 44px; max-width: 180px; object-fit: contain; }
.share-head .grow { flex: 1; min-width: 0; }
.share-head h1 { font-size: 16px; }
.share-map { flex: 1; position: relative; }
.share-card {
    position: absolute; left: 16px; bottom: 24px; z-index: 900; background: #fff;
    border-radius: var(--radius); box-shadow: var(--shadow-lg); padding: 14px 16px; min-width: 240px;
}
.share-card .big { font-size: 22px; font-weight: 700; }
.share-head .plate { white-space: nowrap; }
.share-head h1 { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
@media (max-width: 520px) {
    .share-head { gap: 10px; padding: 10px 12px; }
    .share-head img { max-height: 34px; max-width: 96px; }
    .share-head h1 { font-size: 14px; gap: 6px; }
    .share-head small { font-size: 11px; }
    .share-head .live-pill { padding: 4px 9px; font-size: 11px; }
    .share-card { left: 12px; right: 62px; bottom: 16px; min-width: 0; padding: 12px 14px; }
}

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
    .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .history-panel { width: 320px; }
    .fleet-panel { width: 320px; }
    .panel-hidden .fleet-panel, .panel-hidden .history-panel { margin-left: -320px; }
}
@media (max-width: 860px) {
    .sidebar { position: fixed; left: 0; top: 0; transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow-lg); }
    .sidebar.open { transform: none; }
    .sidebar-backdrop.open { display: block; position: fixed; inset: 0; background: rgba(15,23,42,.45); z-index: 1100; }
    .menu-toggle { display: inline-grid; }
    .topbar { padding: 0 12px; }
    .content { padding: 16px; }
    .flash { margin: 12px 16px 0; }
    .grid-2, .grid-3, .form-grid { grid-template-columns: 1fr; }
    /* Móvil: mapa a pantalla completa y la lista como panel que sube desde abajo */
    .fleet-layout, .history-layout { position: relative; height: calc(100vh - var(--topbar-h)); overflow: hidden; }
    .history-layout { height: 78vh; min-height: 420px; }
    .page-history .main { height: auto; overflow: visible; }
    .fleet-panel, .history-panel {
        position: absolute; left: 0; right: 0; bottom: 0; width: auto; z-index: 1100;
        max-height: 62%; border-right: 0; border-radius: 16px 16px 0 0;
        box-shadow: 0 -8px 30px rgba(15, 23, 42, .25);
        transition: transform .22s ease;
    }
    .fleet-panel::before, .history-panel::before {
        content: ''; display: block; width: 40px; height: 4px; border-radius: 2px;
        background: var(--border-strong); margin: 8px auto 4px; flex-shrink: 0;
    }
    .panel-hidden .fleet-panel, .panel-hidden .history-panel { margin-left: 0; transform: translateY(105%); }
    .fleet-panel, .history-panel { margin-left: 0; }
    .history-filters { gap: 8px; }
    .history-filters .field { flex: 1 1 140px; }
    /* Reproductor compacto en móvil: que no se coma el mapa.
       dvh = alto visible real (descuenta la barra del navegador). */
    .history-layout { height: calc(100vh - var(--topbar-h)); height: calc(100dvh - var(--topbar-h)); }
    .filters-collapsed .history-filters { display: none; }
    .filters-collapsed.filters-open .history-filters {
        display: flex; position: fixed; left: 0; right: 0; top: var(--topbar-h); z-index: 1150;
        box-shadow: 0 12px 30px rgba(15, 23, 42, .25); border-bottom: 1px solid var(--border);
        max-height: calc(100dvh - var(--topbar-h)); overflow-y: auto;
    }
    /* Botón vehículo/fechas en la cabecera */
    .page-history .fs-btn { display: inline-flex; max-width: 62vw; gap: 6px; }
    .fs-btn span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
    .fs-caret { font-size: 10px; transition: transform .15s; }
    .filters-open .fs-caret { transform: rotate(180deg); }
    .page-history .topbar-title { font-size: 16px; }
    /* Listas (trayectos / vehículos) a pantalla completa en móvil */
    .fleet-panel, .history-panel { top: 0 !important; max-height: none !important; border-radius: 0 !important; }
    .fleet-panel::before, .history-panel::before { display: none !important; }
    .panel-mobile-head {
        display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-shrink: 0;
        padding: 8px 8px 8px 14px; border-bottom: 1px solid var(--border); background: var(--surface-2);
    }
    /* Página fija tipo app: nada se desplaza al tocar el reproductor (iPhone) */
    .filters-collapsed.page-history .main { height: 100vh; height: 100dvh; overflow: hidden; }
    .filters-collapsed .history-layout { height: calc(100vh - var(--topbar-h)); height: calc(100dvh - var(--topbar-h)); }
    .page-history { overscroll-behavior: none; }
    .history-map-wrap .map-area { min-height: 200px; }
    .player { padding: 8px 10px; gap: 6px 8px; }
    .player-legend { display: none; }
    .player-ticks { display: none; } /* con muchos trayectos se amontonan */
    .player-btns .icon-btn { width: 32px; height: 32px; }
    .player-track { min-width: 0; flex: 1 1 140px; }
    .player-readout { font-size: 12px; gap: 8px; }
    .player-readout b { font-size: 13px; }
    .player-opts { width: 100%; gap: 6px 10px; }
    .player-opts .seg button { padding: 5px 8px; }
    .player-opts .check { font-size: 12px; }
    .login-page { grid-template-columns: 1fr; }
    .login-hero { display: none; }
    .table .hide-sm { display: none; }
}
@media (max-width: 520px) {
    .grid-4 { grid-template-columns: 1fr 1fr; }
    .kpi { padding: 12px; }
    .kpi-icon { display: none; }
    .search-box { min-width: 0; flex: 1; }
}

@media print {
    .sidebar, .topbar, .history-filters, .player, .map-overlay-btns, .flash { display: none !important; }
    .app, .main { display: block; }
}
