/* ==========================================================
   FLEET CONTROL — sistema visual unificado
   Tema oscuro · responsive · accesibilidad · componentes
   ========================================================== */

/* 1. Tokens y normalización */
:root {
  color-scheme: dark;
  --bg: #0b1220;
  --bg-app: var(--bg);
  --bg-surface: var(--panel);
  --bg-surface-elevated: var(--panel-2);
  --bg-hover: var(--panel-3);
  --bg-elevated: #0e1828;
  --panel: #111d2e;
  --panel-2: #19283d;
  --panel-3: #20334d;
  --line: #293a52;
  --border-subtle: var(--line-soft);
  --border-strong: #405774;
  --line-soft: rgb(105 132 166 / 18%);
  --text: #edf3fc;
  --text-primary: var(--text);
  --text-secondary: var(--muted-strong);
  --text-muted: var(--muted);
  --muted: #91a2ba;
  --muted-strong: #b3c1d5;
  --blue: #4b8cff;
  --accent: var(--blue);
  --blue-hover: #6aa0ff;
  --green: #35c995;
  --ok: var(--green);
  --warn: var(--amber);
  --danger: var(--red);
  --info: var(--blue);
  --amber: #f2b84b;
  --red: #ff737e;
  --purple: #9b87f5;
  --radius-sm: 9px;
  --radius-md: 13px;
  --radius-lg: 17px;
  --radius-xl: 22px;
  --shadow-sm: 0 3px 12px rgb(0 0 0 / 16%);
  --shadow-md: 0 12px 32px rgb(0 0 0 / 24%);
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-7: 32px;
  --space-8: 40px;
  --z-sidebar: 5;
  --z-overlay: 10000;
  --z-drawer: 10001;
  --z-toast: 30;
  --bp-mobile: 700px;
  --mobile-drawer-width: min(300px, calc(100vw - 72px));
  --bp-tablet: 1100px;
  --font-body: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-family: var(--font-body);
  color: var(--text);
  background: var(--bg);
  font-synthesis: none;
  text-rendering: optimizeLegibility;
  -webkit-text-size-adjust: 100%;
}

*,
*::before,
*::after { box-sizing: border-box; }

html { min-width: 320px; min-height: 100%; scroll-behavior: smooth; }
body { min-width: 320px; min-height: 100vh; margin: 0; background: var(--bg); color: var(--text); }
body, button, input, select, textarea { font-family: var(--font-body); }
button, input, select, textarea { font-size: 14px; }
button { cursor: pointer; touch-action: manipulation; }
button:disabled, input:disabled, select:disabled, textarea:disabled { cursor: not-allowed; opacity: .58; }
img, svg, video, canvas { max-width: 100%; }
::selection { color: #fff; background: rgb(75 140 255 / 42%); }
:focus-visible { outline: 2px solid var(--blue-hover); outline-offset: 3px; }

/* 2. Elementos comunes y texto */
h1, h2, h3, h4, p { overflow-wrap: anywhere; }
h1, h2, h3, h4 { color: var(--text); }
p { line-height: 1.55; }
small { line-height: 1.45; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.eyebrow { margin: 0 0 7px; color: #91a7c8; font-size: 10px; font-weight: 800; letter-spacing: .15em; line-height: 1.4; }
.error { min-height: 18px; margin: 8px 0; color: var(--red); font-size: 12px; }

/* 3. Botones, campos y controles */
button {
  min-height: 38px;
  padding: 9px 13px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--panel-2);
  color: var(--text);
  font-weight: 600;
  line-height: 1.25;
  transition: background .16s ease, border-color .16s ease, color .16s ease, transform .16s ease, box-shadow .16s ease;
}
button:hover:not(:disabled) { border-color: #49658a; background: var(--panel-3); }
button:active:not(:disabled) { transform: translateY(1px); }
button.primary { border-color: var(--blue); background: var(--blue); color: #fff; box-shadow: 0 4px 12px rgb(75 140 255 / 18%); }
button.primary:hover:not(:disabled) { border-color: var(--blue-hover); background: var(--blue-hover); }
button.danger, .danger { color: var(--red); }

input, select, textarea {
  width: 100%;
  min-width: 0;
  min-height: 40px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #0c1727;
  color: var(--text);
  accent-color: var(--blue);
  transition: border-color .16s ease, box-shadow .16s ease, background .16s ease;
}
input::placeholder, textarea::placeholder { color: #71839d; opacity: 1; }
input:hover, select:hover, textarea:hover { border-color: #405774; }
input:focus, select:focus, textarea:focus { border-color: var(--blue); outline: none; box-shadow: 0 0 0 3px rgb(75 140 255 / 14%); }
input[type="checkbox"], input[type="radio"] { width: 16px; min-width: 16px; height: 16px; min-height: 16px; padding: 0; }
input[type="range"] { min-height: 24px; padding: 0; border: 0; background: transparent; box-shadow: none; }
input[type="datetime-local"], input[type="date"] { color-scheme: dark; }
textarea { min-height: 88px; resize: vertical; line-height: 1.5; }
.hidden { display: none !important; }

/* 4. Inicio de sesión */
.login {
  display: grid;
  min-height: 100vh;
  min-height: 100dvh;
  place-items: center;
  padding: 24px;
  background: radial-gradient(ellipse at 50% 0%, #1a3151 0%, transparent 58%), var(--bg);
}
.loginbox {
  width: min(430px, 100%);
  padding: clamp(22px, 5vw, 34px);
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  background: linear-gradient(155deg, #14243a, var(--panel) 58%);
  box-shadow: var(--shadow-md);
}
.loginbox h1 { margin: 5px 0 8px; font-size: clamp(25px, 5vw, 30px); letter-spacing: -.035em; }
.loginbox > p.muted { margin: 0 0 22px; font-size: 13px; }
.loginbox label, .command label { display: grid; gap: 7px; margin: 15px 0; color: var(--muted-strong); font-size: 12px; font-weight: 600; }
.loginbox input { width: 100%; }
.loginbox > button { width: 100%; margin-top: 5px; }
.loginbox > small { display: block; margin-top: 12px; font-size: 11px; }
.loginbox label.remember-session { display: flex; align-items: center; gap: 9px; margin: 13px 0 16px; color: var(--muted); font-size: 12px; font-weight: 500; }
.loginbox label.remember-session input { width: 16px; min-width: 16px; height: 16px; min-height: 16px; margin: 0; }
.logo { display: block; width: 44px; height: 44px; flex: 0 0 44px; border-radius: 13px; background: #38bdf8; object-fit: cover; }

/* 5. Estructura principal y navegación */
#app { min-height: 100vh; }
aside {
  position: fixed;
  z-index: 5;
  inset: 0 auto 0 0;
  display: flex;
  width: 235px;
  flex-direction: column;
  padding: 20px 14px;
  overflow-y: auto;
  border-right: 1px solid var(--line);
  background: var(--bg-elevated);
}
.brand { display: flex; align-items: center; gap: 10px; margin: 0 0 25px; font-weight: 750; }
.brand > span { line-height: 1.25; }
.brand small { display: block; margin-top: 4px; color: var(--muted); font-size: 9px; letter-spacing: .14em; }
nav#nav { display: grid; gap: 5px; }
#nav button, .bottom button { width: 100%; min-height: 41px; padding: 9px 11px; border: 1px solid transparent; background: transparent; color: #aebbd0; text-align: left; font-size: 13px; font-weight: 550; }
#nav button:hover, #nav button.active { border-color: rgb(75 140 255 / 13%); background: #1b2d47; color: #fff; }
#nav button.active { box-shadow: inset 3px 0 0 var(--blue); }
.bottom { display: grid; gap: 6px; margin-top: auto; padding: 12px 7px 5px; color: var(--muted); font-size: 11px; }
.bottom #connection { padding: 4px 5px 8px; }
main { width: min(100% - 235px, 1700px); min-height: 100vh; margin-left: 235px; padding: 28px; }
header { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 25px; }
header h1 { margin: 0; font-size: clamp(22px, 2vw, 27px); font-weight: 750; letter-spacing: -.035em; }
header .eyebrow { margin-bottom: 5px; }
.view { min-width: 0; animation: view-in .18s ease both; }
@keyframes view-in { from { opacity: .65; transform: translateY(3px); } to { opacity: 1; transform: translateY(0); } }
.mobile-menu-toggle, .mobile-menu-backdrop, #mapMenuClose { display: none; }

/* 6. Dashboard y paneles */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 155px), 1fr)); gap: 13px; margin-bottom: 16px; }
.stats article, .panel {
  min-width: 0;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--panel);
  box-shadow: var(--shadow-sm);
}
.stats article { display: flex; min-height: 112px; flex-direction: column; justify-content: space-between; gap: 12px; }
.stats small { display: block; color: var(--muted); font-size: 11px; font-weight: 600; line-height: 1.4; }
.stats strong { display: block; margin-top: auto; font-size: clamp(24px, 2.3vw, 30px); font-weight: 750; letter-spacing: -.04em; line-height: 1.1; font-variant-numeric: tabular-nums; }
.grid { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); gap: 14px; }
.dashboard-mileage-section { margin: 4px 0 18px; }
.dashboard-mileage-heading { margin: 0 0 12px; }
.dashboard-mileage-heading .eyebrow { margin: 0 0 4px; }
.dashboard-mileage-heading h2 { margin: 0 0 5px; font-size: 18px; }
.dashboard-mileage-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 270px), 1fr)); gap: 12px; }
.dashboard-mileage-card { display: grid; min-width: 0; gap: 14px; padding: 15px; border: 1px solid var(--line); border-radius: var(--radius-lg); background: var(--panel); box-shadow: var(--shadow-sm); }
.dashboard-mileage-card-head { display: flex; min-width: 0; align-items: center; gap: 11px; }
.dashboard-mileage-icon { display: grid; width: 42px; height: 42px; flex: 0 0 42px; place-items: center; border: 1px solid rgb(75 140 255 / 25%); border-radius: 12px; background: rgb(75 140 255 / 10%); color: var(--blue); }
.dashboard-mileage-icon svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.dashboard-mileage-title { min-width: 0; flex: 1 1 auto; }
.dashboard-mileage-title .eyebrow { margin: 0 0 3px; font-size: 9px; }
.dashboard-mileage-title h3 { margin: 0; color: var(--text); font-size: 15px; line-height: 1.35; overflow-wrap: anywhere; }
.dashboard-mileage-status { display: grid; flex: 0 0 auto; justify-items: end; gap: 4px; align-self: flex-start; margin-left: auto; }
.dashboard-mileage-status-pill { display: inline-flex; min-height: 23px; align-items: center; justify-content: center; padding: 4px 8px; border: 1px solid transparent; border-radius: 999px; font-size: 9px; font-weight: 800; line-height: 1.1; white-space: nowrap; }
.dashboard-mileage-status-pill.is-moving { border-color: rgb(22 101 52 / 18%); background: #dcfce7; color: #166534; }
.dashboard-mileage-status-pill.is-stopped { border-color: rgb(153 27 27 / 18%); background: #fee2e2; color: #991b1b; }
.dashboard-mileage-status-pill.is-offline { border-color: rgb(180 83 9 / 18%); background: #ffedd5; color: #9a3412; }
.dashboard-mileage-status-pill.is-unknown { border-color: var(--line); background: var(--bg); color: var(--muted-strong); }
.dashboard-mileage-speed { color: #1d4ed8; font-size: 10px; font-weight: 800; line-height: 1.15; font-variant-numeric: tabular-nums; white-space: nowrap; }
:root[data-theme="dark"] .dashboard-mileage-status-pill.is-moving { border-color: rgb(53 201 149 / 26%); background: rgb(53 201 149 / 15%); color: #6ee7b7; }
:root[data-theme="dark"] .dashboard-mileage-status-pill.is-stopped { border-color: rgb(255 115 126 / 28%); background: rgb(255 115 126 / 14%); color: #ff9da5; }
:root[data-theme="dark"] .dashboard-mileage-status-pill.is-offline { border-color: rgb(242 184 75 / 28%); background: rgb(242 184 75 / 13%); color: #f6cb74; }
:root[data-theme="dark"] .dashboard-mileage-speed { color: #9fc2ff; }
.dashboard-mileage-metrics { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 7px; margin: 0; }
.dashboard-mileage-metrics > div { min-width: 0; padding: 9px 8px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); }
.dashboard-mileage-metrics dt { color: var(--muted); font-size: 11px; line-height: 1.3; }
.dashboard-mileage-metrics dd { margin: 6px 0 0; color: var(--green); font-size: clamp(13px, 1.2vw, 16px); font-weight: 750; line-height: 1.25; font-variant-numeric: tabular-nums; white-space: nowrap; }
.dashboard-mileage-empty { margin: 0; padding: 15px; border: 1px dashed var(--line); border-radius: var(--radius-md); }
.dashboard-activity { margin-bottom: 15px; }
.maintenance-device-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 330px), 1fr)); gap: 12px; }
.maintenance-device-card { display: grid; min-width: 0; gap: 13px; padding: 16px; border: 1px solid var(--line); border-radius: var(--radius-lg); background: var(--panel); box-shadow: var(--shadow-sm); }
.maintenance-device-head { display: flex; min-width: 0; align-items: center; gap: 11px; }
.maintenance-device-head .eyebrow { margin: 0 0 3px; font-size: 9px; }
.maintenance-device-head h3 { margin: 0; font-size: 16px; overflow-wrap: anywhere; }
.maintenance-device-metrics { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 7px; margin: 0; }
.maintenance-device-metric { min-width: 0; padding: 9px 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); }
.maintenance-device-metric dt { color: var(--muted); font-size: 11px; line-height: 1.35; }
.maintenance-device-metric dd { margin: 5px 0 0; color: var(--text); font-size: 13px; font-weight: 700; line-height: 1.4; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.maintenance-device-footer { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 8px; padding-top: 11px; border-top: 1px solid var(--line); }
.maintenance-device-footer small { min-width: 0; color: var(--muted); font-size: 11px; overflow-wrap: anywhere; }
.maintenance-device-footer button { min-height: 40px; }
.panel { margin-bottom: 15px; }
.panel h2 { margin: 4px 0 15px; font-size: 16px; font-weight: 700; letter-spacing: -.015em; }
.panel h3 { margin: 4px 0 12px; font-size: 14px; font-weight: 700; }
.mileage { background: linear-gradient(135deg, #17314b, var(--panel) 78%); }
.big { display: flex; align-items: baseline; flex-wrap: wrap; gap: 8px; margin: 20px 0; }
.big strong { font-size: clamp(34px, 4vw, 44px); font-weight: 800; letter-spacing: -.055em; font-variant-numeric: tabular-nums; }
.big span { color: var(--green); font-size: 14px; font-weight: 650; }
.periods { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin: 20px 0; }
.periods > div { min-width: 0; padding: 11px; border: 1px solid rgb(255 255 255 / 7%); border-radius: 11px; background: rgb(5 14 27 / 45%); color: var(--muted); font-size: 11px; }
.periods strong { display: block; margin-top: 7px; color: var(--text); font-size: 18px; font-variant-numeric: tabular-nums; }
.list { display: grid; gap: 8px; }

/* 7. Barras de herramientas, filtros y formularios */
.toolbar { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 10px; margin-bottom: 14px; }
.toolbar input { width: min(350px, 100%); }
.filters { display: flex; align-items: end; flex-wrap: wrap; gap: 12px; }
.filters label { display: grid; min-width: 150px; flex: 1 1 150px; gap: 6px; color: var(--muted-strong); font-size: 12px; font-weight: 600; }
.filters button { flex: 0 0 auto; }
.filters select[multiple] { min-height: 82px; }
.eventfilters { justify-content: flex-start; flex-wrap: wrap; }
.eventfilters select { min-width: 150px; flex: 1 1 150px; }
.eventfilters label { display: grid; min-width: 150px; flex: 1 1 150px; gap: 5px; color: var(--muted); font-size: 11px; }
.command { width: min(100%, 620px); }
.command label { max-width: 100%; }
#commandJson { width: 100%; min-height: 110px; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 12px; }

/* 8. Tablas y listados */
.tablewrap { width: 100%; min-width: 0; overflow: auto; overscroll-behavior: contain; }
.table { width: 100%; min-width: 550px; border-collapse: separate; border-spacing: 0; font-variant-numeric: tabular-nums; }
.table th { position: sticky; top: 0; z-index: 1; padding: 12px; border-bottom: 1px solid var(--line); background: var(--panel); color: var(--muted); font-size: 10px; font-weight: 750; letter-spacing: .06em; text-align: left; text-transform: uppercase; }
.table td { padding: 12px; border-bottom: 1px solid var(--line-soft); color: var(--muted-strong); font-size: 12px; line-height: 1.45; white-space: nowrap; vertical-align: middle; }
.table tbody tr:hover td { background: rgb(75 140 255 / 5%); color: var(--text); }
.table tbody tr:last-child td { border-bottom: 0; }

/* 9. Mapas e historial */
.mapgrid { display: grid; grid-template-columns: minmax(210px, 250px) minmax(0, 1fr); gap: 12px; }
.map { width: 100%; height: 620px; min-height: 380px; overflow: hidden; border: 1px solid var(--line); border-radius: var(--radius-lg); background: #101b2b; }
.vehiclelist { max-height: 620px; overflow: auto; }
.vehicle { display: block; width: 100%; margin-bottom: 6px; text-align: left; }
.vehicle small { display: block; margin-top: 5px; color: var(--muted); }
.map-icon-choice { display: flex; align-items: center; gap: 8px; white-space: nowrap; color: var(--muted-strong); font-size: 12px; }
.map-icon-choice select { max-width: 170px; }
.fleet-map-icon { border: 0; background: transparent; }
.fleet-map-icon span { display: grid; width: 38px; height: 38px; place-items: center; border: 2px solid #fff; border-radius: 50%; background: var(--blue); box-shadow: 0 3px 10px rgb(0 0 0 / 45%); font-size: 22px; line-height: 1; }

/* 10. Tarjetas de vehículos */
.vehicle-cards, #deviceTable.vehicle-cards { display: grid; width: 100%; grid-template-columns: repeat(auto-fill, minmax(min(100%, 280px), 1fr)); align-items: stretch; gap: 15px; }
.vehicle-card, #deviceTable .vehicle-card {
  display: flex;
  min-width: 0;
  flex-direction: column;
  justify-content: space-between;
  gap: 16px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: linear-gradient(145deg, var(--panel-2), var(--panel) 76%);
  box-shadow: var(--shadow-sm);
  transition: border-color .18s ease, transform .18s ease, box-shadow .18s ease;
}
.vehicle-card:hover { border-color: #405c80; transform: translateY(-2px); box-shadow: var(--shadow-md); }
.vehicle-card-main { display: grid; width: 100%; gap: 10px; padding: 2px 0 13px; border: 0; background: transparent; text-align: left; }
.vehicle-card-main:hover { border-color: transparent; background: transparent; }
.vehicle-card-main strong, #deviceTable .vehicle-card-content h3 { margin: 0; color: var(--text); font-size: 16px; font-weight: 750; overflow-wrap: anywhere; }
.vehicle-card-main span { color: var(--green); font-size: 14px; font-weight: 700; font-variant-numeric: tabular-nums; }
#deviceTable .vehicle-card-km { display: flex; align-items: baseline; flex-wrap: wrap; gap: 7px; margin: 0; font-size: 16px; line-height: 1.45; font-variant-numeric: tabular-nums; }
#deviceTable .vehicle-card-km strong { color: var(--green); font-size: 17px; font-weight: 750; }
#deviceTable .vehicle-card-km span { color: var(--muted); }
#deviceTable .vehicle-card-caption { display: block; margin-top: 7px; color: var(--muted); font-size: 11px; line-height: 1.45; }
.vehicle-card-actions, #deviceTable .vehicle-card-actions { display: flex; flex-wrap: wrap; gap: 7px; padding-top: 13px; border-top: 1px solid var(--line); }
.vehicle-card-actions button, #deviceTable .vehicle-card-actions button { min-height: 34px; padding: 7px 10px; font-size: 11px; }
.vehicle-card-actions button.danger { border-color: rgb(180 35 50 / 32%); background: rgb(180 35 50 / 6%); color: var(--red); }
.vehicle-card-actions button.danger:hover:not(:disabled) { border-color: var(--red); background: var(--red); color: #fff; }
:root[data-theme="dark"] .vehicle-card-actions button.danger { border-color: rgb(255 115 126 / 38%); background: rgb(255 115 126 / 8%); color: #ff9da5; }

/* 11. Mantenimiento y diálogos */
dialog { width: min(600px, calc(100% - 24px)); max-height: min(90vh, 900px); padding: 21px; overflow: auto; border: 1px solid var(--line); border-radius: var(--radius-xl); background: var(--panel); color: var(--text); box-shadow: var(--shadow-md); }
dialog::backdrop { background: rgb(0 0 0 / 68%); backdrop-filter: blur(3px); }
.dialoghead, .actions { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.dialoghead h2 { margin: 4px 0 10px; font-size: 18px; }
.dialoghead p { margin: 0 0 10px; font-size: 12px; }
.fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; padding-top: 10px; }
.fields label, .maint-form label { display: grid; min-width: 0; gap: 6px; color: var(--muted-strong); font-size: 12px; font-weight: 600; }
.fields input, .fields select, .fields textarea { width: 100%; }
.actions { justify-content: flex-end; margin-top: 18px; }
.permission-set { grid-column: 1 / -1; max-height: 190px; padding: 10px; overflow: auto; border: 1px solid var(--line); border-radius: var(--radius-sm); }
.permission-set legend { padding: 0 5px; color: var(--muted); }
.checkrow { display: flex !important; align-items: center; gap: 8px !important; margin: 8px 0 !important; }
.checkrow input { width: 16px; min-width: 16px; height: 16px; min-height: 16px; }
.maint-dialog-scroll { max-height: min(78vh, 850px); padding-right: 4px; overflow: auto; overscroll-behavior: contain; }
.maint-form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: end; gap: 11px; }
.maint-form input, .maint-form textarea, .maint-form select { width: 100%; min-width: 0; }
.maint-form .wide, .fields .wide { grid-column: 1 / -1; }
.plan-row { display: grid; grid-template-columns: minmax(0, 1fr); align-items: start; gap: 12px; min-width: 0; padding: 14px 4px; border-bottom: 1px solid var(--line); }
.plan-info { min-width: 0; }
.plan-info > b { display: block; color: var(--text); font-size: 13px; line-height: 1.4; overflow-wrap: anywhere; }
.plan-row small, .maintenance-alert small { display: block; margin-top: 6px; color: var(--muted); line-height: 1.5; }
/* Las acciones ocupan una fila propia: evita que el ancho del diálogo las apile en vertical. */
#vehiclePlans .plan-actions { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); align-items: stretch; justify-content: stretch; gap: 8px; width: 100%; min-width: 0; }
#vehiclePlans .plan-actions button { display: inline-flex; align-items: center; justify-content: center; width: 100%; min-width: 0; min-height: 38px; margin: 0; padding: 8px 5px; font-size: 12px; line-height: 1.2; white-space: nowrap; }
.plan-actions .plan-edit { border-color: #405774; background: #1a2a40; color: var(--text); }
.plan-actions .plan-service { border-color: rgb(75 140 255 / 55%); background: rgb(75 140 255 / 14%); color: #9fc2ff; }
.plan-actions .plan-delete { border-color: rgb(255 115 126 / 38%); background: rgb(255 115 126 / 9%); color: var(--red); }
.plan-actions button:hover:not(:disabled) { filter: brightness(1.14); }
.maintenance-alert { display: block; width: 100%; margin: 6px 0; text-align: left; }
.maintenance-alert small { font-size: 11px; }
.maintUnit { display: inline; white-space: nowrap; }

/* 12. Avisos, toast y estados */
.toast { position: fixed; z-index: 30; right: 20px; bottom: 20px; display: none; width: max-content; max-width: min(550px, calc(100vw - 30px)); padding: 12px 16px; border: 1px solid #405775; border-radius: var(--radius-md); background: #1d2e47; color: var(--text); box-shadow: var(--shadow-md); font-size: 13px; line-height: 1.5; }
.toast.show { display: block; animation: toast-in .18s ease both; }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }

/* 13. Scrollbars: visibles, discretas y funcionales */
* { scrollbar-width: thin; scrollbar-color: #40536d transparent; }
*::-webkit-scrollbar { width: 8px; height: 8px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb { border: 2px solid transparent; border-radius: 20px; background: #40536d; background-clip: padding-box; }
*::-webkit-scrollbar-thumb:hover { background: #607895; background-clip: padding-box; }

/* 14. Tablet */
@media (max-width: 1100px) {
  aside { width: 210px; }
  main { width: calc(100% - 210px); margin-left: 210px; padding: 22px; }
  .grid { grid-template-columns: minmax(0, 1fr); }
  .stats { grid-template-columns: repeat(auto-fit, minmax(145px, 1fr)); }
}

/* 15. Móvil: menú lateral desplegable y contenido adaptable */
@media (max-width: 700px) {
  * { scrollbar-color: transparent transparent; scrollbar-width: none; }
  *::-webkit-scrollbar { display: none; width: 0; height: 0; }
  main { width: 100%; margin: 0; padding: 16px 13px 26px; overflow-x: clip; }
  header { display: grid; grid-template-columns: 44px minmax(0, 1fr) auto; gap: 9px; margin-bottom: 18px; }
  header h1 { font-size: 21px; }
  header > button:last-child { min-height: 44px; padding: 8px 10px; font-size: 12px; }
  #mobileMenuToggle { display: inline-grid; width: 44px; min-height: 44px; place-items: center; padding: 0; font-size: 22px; line-height: 1; box-shadow: none; }
  #sidebar { position: fixed; z-index: 10001; inset: 0 auto 0 0; display: flex; width: var(--mobile-drawer-width); padding: calc(18px + env(safe-area-inset-top)) 14px calc(16px + env(safe-area-inset-bottom)); overflow-y: auto; overscroll-behavior: contain; transform: translateX(-105%); transition: transform .22s ease; border-right: 1px solid rgb(120 165 255 / 30%); border-radius: 0 18px 18px 0; box-shadow: none; }
  body.mobile-menu-open #sidebar { transform: translateX(0); }
  body.mobile-menu-open { overflow: hidden; }
  body.mobile-menu-open #mobileMenuToggle { visibility: hidden; pointer-events: none; }
  #sidebar .brand { position: relative; padding-right: 52px; }
  #mapMenuClose { position: absolute; top: 0; right: 0; display: none; width: 44px; height: 44px; min-height: 44px; place-items: center; padding: 0; border: 1px solid rgb(255 255 255 / 18%); border-radius: 12px; background: #1a2a40; color: #fff; box-shadow: none; font-size: 25px; line-height: 1; }
  body.mobile-menu-open #mapMenuClose { display: grid; }
  #nav { gap: 6px; }
  #nav button { min-height: 48px; }
  button, .bottom button, #nav button, #deviceTable .vehicle-card-actions button, #vehiclePlans .plan-actions button { min-height: 44px; }
  .vehicle-card-actions, #deviceTable .vehicle-card-actions { gap: 8px; }
  .bottom { padding-bottom: 8px; }
  .mobile-menu-backdrop { position: fixed; z-index: 10000; inset: 0; display: none; width: 100vw; height: 100vh; height: 100dvh; min-width: 0; min-height: 0; max-width: none; margin: 0; padding: 0; border: 0; border-radius: 0; appearance: none; -webkit-appearance: none; background: transparent; box-shadow: none; outline: 0; }
  body.mobile-menu-open .mobile-menu-backdrop { display: block; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .stats article { min-height: 96px; padding: 13px; }
  .stats small { font-size: 12px; line-height: 1.45; }
  .stats strong { font-size: 24px; }
  .dashboard-mileage-grid { grid-template-columns: repeat(auto-fill, minmax(min(100%, 260px), 1fr)); gap: 9px; }
  .dashboard-mileage-card { padding: 13px; border-radius: 14px; }
  .maintenance-device-grid { grid-template-columns: minmax(0, 1fr); gap: 9px; }
  .maintenance-device-card { padding: 13px; border-radius: 14px; }
  .maintenance-device-metrics { gap: 6px; }
  .maintenance-device-metric { padding: 8px; }
  .maintenance-device-footer button { min-height: 44px; }
  .dashboard-mileage-metrics { gap: 6px; }
  .dashboard-mileage-metrics > div { padding: 8px 6px; }
  .dashboard-mileage-metrics dt { font-size: 10px; }
  .dashboard-mileage-metrics dd { font-size: clamp(12px, 3.5vw, 15px); }
  .panel { padding: 14px; border-radius: 14px; }
  .mapgrid { grid-template-columns: minmax(0, 1fr); }
  .vehiclelist { display: flex; max-height: none; gap: 6px; overflow-x: auto; }
  .vehicle { min-width: 140px; margin: 0; }
  .map { height: 55vh; min-height: 350px; }
  .filters { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .filters label { min-width: 0; }
  .filters button { grid-column: 1 / -1; }
  .eventfilters > * { width: 100%; min-width: 0; }
  .periods { gap: 5px; }
  .periods > div { padding: 8px; font-size: 12px; line-height: 1.4; }
  .periods strong { font-size: 15px; }
  .big strong { font-size: 35px; }
  .toolbar { align-items: stretch; }
  .toolbar input { width: 100%; max-width: none; flex: 1 1 100%; }
  .toolbar > button { flex: 0 0 auto; }
  .fields, .maint-form { grid-template-columns: minmax(0, 1fr); }
  .fields .wide, .maint-form .wide { grid-column: auto; }
  .maint-dialog-scroll { max-height: 72vh; }
  #vehiclePlans .plan-row { gap: 11px; }
  #vehiclePlans .plan-actions { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
  #vehiclePlans .plan-actions button { min-width: 0; width: 100%; padding-inline: 4px; font-size: 12px; }
  .map-icon-choice { flex: 1 1 auto; }
  .map-icon-choice select { max-width: 145px; }
  #deviceTable.vehicle-cards { grid-template-columns: repeat(auto-fill, minmax(min(100%, 260px), 1fr)); gap: 10px; }
  .toast { right: 12px; bottom: calc(12px + env(safe-area-inset-bottom)); }
  input, select, textarea { font-size: 16px; }
}

@media (max-width: 380px) {
  #vehiclePlans .plan-actions { gap: 5px; }
  #vehiclePlans .plan-actions button { min-height: 44px; padding-inline: 2px; font-size: 12px; }
  header { grid-template-columns: 44px minmax(0, 1fr); }
  header > button:last-child { grid-column: 2; justify-self: start; }
  #mobileMenuToggle { width: 44px; min-height: 44px; }
  .stats { gap: 7px; }
  .stats article { padding: 11px; }
  .stats strong { font-size: 21px; }
  .filters { grid-template-columns: minmax(0, 1fr); }
  .filters button { grid-column: auto; }
  .periods { grid-template-columns: minmax(0, 1fr); }
  .periods > div { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 12px; }
  .periods strong { margin-top: 0; }
}

/* 16. Movimiento reducido y modo impresión */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
@media (max-width: 700px) {
  .table td button { min-height: 44px; padding-block: 10px; font-size: 12px; }
}
@media print {
  :root { color-scheme: light; }
  body { background: #fff !important; color: #111 !important; }
  aside, .mobile, .mobile-menu-toggle, .mobile-menu-backdrop, header button, .toolbar button, .filters button { display: none !important; }
  main { width: 100%; margin: 0; padding: 0; }
  .view.hidden { display: none !important; }
  .panel, .stats article { border: 1px solid #aaa; background: #fff !important; color: #111 !important; box-shadow: none; }
  .table td, .table th, h1, h2, h3, p, small, strong { color: #111 !important; }
  .table { min-width: 0; }
}

/* 17. Identidad SaaS empresarial: superficies claras, navegación estable y datos legibles. */
:root {
  color-scheme: light;
  --bg: #f4f7fb;
  --bg-app: #f4f7fb;
  --bg-surface: #fff;
  --bg-surface-elevated: #fff;
  --bg-hover: #f2f6fc;
  --bg-elevated: #10233f;
  --panel: #fff;
  --panel-2: #f7f9fc;
  --panel-3: #edf3fb;
  --line: #dce4ef;
  --border-subtle: #e8edf4;
  --border-strong: #bac8da;
  --line-soft: #e8edf4;
  --text: #172b4d;
  --text-primary: #172b4d;
  --text-secondary: #435674;
  --text-muted: #667892;
  --muted: #667892;
  --muted-strong: #435674;
  --blue: #1e40af;
  --accent: #1e40af;
  --blue-hover: #3158c7;
  --green: #15805d;
  --ok: #15805d;
  --amber: #a85b05;
  --warn: #a85b05;
  --red: #b42332;
  --danger: #b42332;
  --info: #1e40af;
  --purple: #6552b8;
  --shadow-sm: 0 1px 3px rgb(16 35 63 / 6%), 0 4px 12px rgb(16 35 63 / 3%);
  --shadow-md: 0 18px 48px rgb(16 35 63 / 16%);
  background: var(--bg);
  color: var(--text);
}

body { background: var(--bg); color: var(--text); }
aside { border-color: #203957; background: #10233f; box-shadow: 4px 0 18px rgb(16 35 63 / 7%); }
.brand { color: #f8fbff; }
.brand small { color: #9fb2ca; }
#nav button, .bottom button { color: #c5d1e0; }
#nav button:hover, #nav button.active { border-color: rgb(132 170 255 / 15%); background: #1b3557; color: #fff; }
#nav button.active { box-shadow: inset 3px 0 0 #78a5ff; }
.nav-icon { width: 17px; height: 17px; flex: 0 0 17px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
#nav button { display: flex; align-items: center; gap: 12px; }
#nav button[data-view="alerts"] { gap: 10px; }
.alert-count { display: grid; min-width: 22px; height: 22px; flex: 0 0 auto; place-items: center; margin-left: auto; padding: 0 6px; border-radius: 999px; background: #dc3545; color: #fff; font-size: 11px; font-weight: 800; line-height: 1; font-variant-numeric: tabular-nums; }
.alert-center { width: min(100%, 1050px); }
.alert-center .dialoghead { align-items: center; }
.alert-center .dialoghead h2 { margin: 0; }
.alert-center-count { display: grid; width: 42px; height: 42px; flex: 0 0 42px; place-items: center; border-radius: 50%; background: #dc3545; color: #fff; font-size: 20px; font-weight: 850; }
.system-alert-list { display: grid; gap: 9px; margin: 14px 0; }
.system-alert-card { display: flex; align-items: flex-start; gap: 11px; padding: 13px; border: 1px solid rgb(220 53 69 / 28%); border-radius: 12px; background: rgb(220 53 69 / 8%); }
.system-alert-card b { color: var(--text); }
.system-alert-card p { margin: 4px 0 0; color: var(--muted-strong); font-size: 12px; overflow-wrap: anywhere; }
.alert-dot { width: 10px; height: 10px; flex: 0 0 10px; margin-top: 4px; border-radius: 50%; background: #dc3545; }
.bottom { border-top: 1px solid rgb(207 221 241 / 12%); }
.bottom #connection { color: #a8bad1; }
main { background: var(--bg); }
header { padding-bottom: 17px; border-bottom: 1px solid #e2e8f0; }
header h1, .panel h2, .panel h3 { color: #172b4d; }
header .eyebrow, .eyebrow { color: #617797; }
button { border-color: #d4deeb; background: #fff; color: #263a58; box-shadow: 0 1px 2px rgb(16 35 63 / 3%); }
button:hover:not(:disabled) { border-color: #9eb2d0; background: #f5f8fc; }
button.primary { border-color: #1e40af; background: #1e40af; color: #fff; box-shadow: 0 3px 8px rgb(30 64 175 / 16%); }
button.primary:hover:not(:disabled) { border-color: #3158c7; background: #3158c7; }
input, select, textarea { border-color: #cbd6e4; background: #fff; color: #172b4d; }
input::placeholder, textarea::placeholder { color: #8796aa; }
input:hover, select:hover, textarea:hover { border-color: #9fb0c6; }
input:focus, select:focus, textarea:focus { border-color: #3158c7; box-shadow: 0 0 0 3px rgb(49 88 199 / 13%); }
input[type="datetime-local"], input[type="date"] { color-scheme: light; }
.login { background: radial-gradient(ellipse at 50% 0%, #e3edff 0%, transparent 58%), #f4f7fb; }
.loginbox { border-color: #e0e7f0; background: #fff; box-shadow: 0 22px 60px rgb(16 35 63 / 12%); }
.loginbox h1 { color: #172b4d; }
.loginbox label, .command label { color: #435674; }
.loginbox label.remember-session { color: #667892; }
.logo { background: #38bdf8; box-shadow: none; }
.stats article, .panel { border-color: #e0e7f0; background: #fff; box-shadow: var(--shadow-sm); }
.stats article { border-radius: 14px; }
.stats small { color: #667892; font-size: 12px; }
.stats strong { color: #172b4d; }
.panel h2 { font-size: 16px; }
.mileage { border-color: #d8e4f5; background: linear-gradient(135deg, #edf4ff, #fff 76%); }
.mileage .big strong { color: #1e40af; }
.mileage .big span { color: #15805d; }
.periods > div { border-color: #dbe5f2; background: #f6f9fd; color: #667892; }
.periods strong { color: #172b4d; }
.list { gap: 9px; }
.tablewrap, .vehiclelist { border-radius: 12px; }
.table { min-width: 580px; }
.table th { border-color: #e0e7f0; background: #f7f9fc; color: #60728b; }
.table td { border-color: #edf1f6; color: #435674; }
.table tbody tr:hover td { background: #f4f8ff; color: #172b4d; }
.map { border-color: #dce4ef; background: #e9eef5; }
.vehicle { border-color: #e1e8f1; background: #fff; color: #172b4d; }
.vehicle:hover { border-color: #a9bedf; background: #f6f9ff; }
.vehicle small { color: #667892; }
.map-icon-choice { color: #435674; }
.vehicle-card, #deviceTable .vehicle-card { border-color: #e0e7f0; background: #fff; }
.vehicle-card:hover { border-color: #afc2de; box-shadow: 0 10px 26px rgb(16 35 63 / 9%); }
.vehicle-card-main strong, #deviceTable .vehicle-card-content h3 { color: #172b4d; }
.vehicle-card-main span, #deviceTable .vehicle-card-km strong { color: #15805d; }
.vehicle-card-actions, #deviceTable .vehicle-card-actions { border-color: #e8edf4; }
dialog { border-color: #dce4ef; background: #fff; color: #172b4d; }
.dialoghead h2 { color: #172b4d; }
.fields label, .maint-form label { color: #435674; }
.permission-set { border-color: #dce4ef; }
.permission-set legend { color: #667892; }
.plan-row { border-color: #e5ebf3; }
.plan-info > b { color: #172b4d; }
.plan-row small, .maintenance-alert small { color: #667892; }
.plan-actions .plan-edit { border-color: #d4deeb; background: #fff; color: #263a58; }
.plan-actions .plan-service { border-color: #b9cef1; background: #eef4ff; color: #1e40af; }
.plan-actions .plan-delete { border-color: #f0c5ca; background: #fff4f5; color: #a52231; }
.maintenance-alert { border-color: #e0e7f0; background: #fff; color: #172b4d; }
.maintenance-alert:hover { border-color: #b8c8dd; background: #f7faff; }
.toast { border-color: #263f60; background: #132a49; color: #f8fbff; }
* { scrollbar-color: #b5c1d0 transparent; }
*::-webkit-scrollbar-thumb { background: #b5c1d0; background-clip: padding-box; }
*::-webkit-scrollbar-thumb:hover { background: #899bb1; background-clip: padding-box; }
:focus-visible { outline-color: #3158c7; }

@media (max-width: 700px) {
  header { border-bottom: 0; }
  #sidebar { background: #10233f; }
  body.mobile-menu-open .mobile-menu-backdrop { background: transparent; }
  .stats article { border-radius: 12px; }
  .panel { border-radius: 13px; }
}

@media (prefers-reduced-motion: reduce) {
  .view { animation: none; }
}

/* Acabado operativo: cifras estables y jerarquía visual del mantenimiento. */
:where(.stats,.periods,.vehicle-card-km,.table,.plan-row,.maintenance-alert){font-variant-numeric:tabular-nums}
.stats article{position:relative;overflow:hidden}
.stats article::before{position:absolute;inset:0 auto 0 0;width:3px;background:var(--blue);content:""}
#maintenance .stats article:nth-child(1)::before,#maintenance .stats article:nth-child(3)::before{background:var(--info)}
#maintenance .stats article:nth-child(2)::before{background:var(--ok)}
#maintenance .stats article:nth-child(4)::before{background:var(--warn)}
#maintenance .stats article:nth-child(5)::before{background:var(--danger)}
#maintenance>.panel{padding:clamp(15px,2vw,22px)}
#maintenance>.panel>h2,#maintenance>.panel>.dialoghead h2{margin-bottom:16px}
.table td button{min-height:34px;padding:7px 10px;font-size:11px}
@media(max-width:700px){#maintenance>.panel{padding:14px}}

/* Tema oscuro seleccionable desde el menú; conserva la misma jerarquía y contraste. */
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0b1220;
  --bg-app: #0b1220;
  --bg-surface: #111d2e;
  --bg-surface-elevated: #19283d;
  --bg-hover: #20334d;
  --bg-elevated: #0e1828;
  --panel: #111d2e;
  --panel-2: #19283d;
  --panel-3: #20334d;
  --line: #293a52;
  --border-subtle: rgb(105 132 166 / 18%);
  --border-strong: #405774;
  --line-soft: rgb(105 132 166 / 18%);
  --text: #edf3fc;
  --text-primary: #edf3fc;
  --text-secondary: #b3c1d5;
  --text-muted: #91a2ba;
  --muted: #91a2ba;
  --muted-strong: #b3c1d5;
  --blue: #4b8cff;
  --accent: #4b8cff;
  --blue-hover: #6aa0ff;
  --green: #35c995;
  --ok: #35c995;
  --amber: #f2b84b;
  --warn: #f2b84b;
  --red: #ff737e;
  --danger: #ff737e;
  --info: #4b8cff;
  --purple: #9b87f5;
  --shadow-sm: 0 3px 12px rgb(0 0 0 / 16%);
  --shadow-md: 0 12px 32px rgb(0 0 0 / 24%);
  background: #0b1220;
  color: #edf3fc;
}
:root[data-theme="dark"] body,
:root[data-theme="dark"] main { background: #0b1220; color: #edf3fc; }
:root[data-theme="dark"] aside,
:root[data-theme="dark"] #sidebar { border-color: #293a52; background: #0e1828; }
:root[data-theme="dark"] header { border-color: #293a52; }
:root[data-theme="dark"] header h1,
:root[data-theme="dark"] .panel h2,
:root[data-theme="dark"] .panel h3,
:root[data-theme="dark"] .stats strong,
:root[data-theme="dark"] .vehicle-card-main strong,
:root[data-theme="dark"] #deviceTable .vehicle-card-content h3,
:root[data-theme="dark"] .plan-info > b,
:root[data-theme="dark"] .dialoghead h2 { color: #edf3fc; }
:root[data-theme="dark"] .eyebrow,
:root[data-theme="dark"] header .eyebrow { color: #91a7c8; }
:root[data-theme="dark"] button { border-color: #293a52; background: #19283d; color: #edf3fc; box-shadow: none; }
:root[data-theme="dark"] button:hover:not(:disabled) { border-color: #49658a; background: #20334d; }
:root[data-theme="dark"] button.primary { border-color: #4b8cff; background: #4b8cff; color: #fff; box-shadow: 0 4px 12px rgb(75 140 255 / 18%); }
:root[data-theme="dark"] button.primary:hover:not(:disabled) { border-color: #6aa0ff; background: #6aa0ff; }
:root[data-theme="dark"] input,
:root[data-theme="dark"] select,
:root[data-theme="dark"] textarea { border-color: #293a52; background: #0c1727; color: #edf3fc; }
:root[data-theme="dark"] input::placeholder,
:root[data-theme="dark"] textarea::placeholder { color: #71839d; }
:root[data-theme="dark"] input:hover,
:root[data-theme="dark"] select:hover,
:root[data-theme="dark"] textarea:hover { border-color: #405774; }
:root[data-theme="dark"] input:focus,
:root[data-theme="dark"] select:focus,
:root[data-theme="dark"] textarea:focus { border-color: #4b8cff; box-shadow: 0 0 0 3px rgb(75 140 255 / 14%); }
:root[data-theme="dark"] input[type="datetime-local"],
:root[data-theme="dark"] input[type="date"] { color-scheme: dark; }
:root[data-theme="dark"] .login { background: radial-gradient(ellipse at 50% 0%, #1a3151 0%, transparent 58%), #0b1220; }
:root[data-theme="dark"] .loginbox { border-color: #293a52; background: linear-gradient(155deg, #14243a, #111d2e 58%); box-shadow: 0 12px 32px rgb(0 0 0 / 24%); }
:root[data-theme="dark"] .loginbox h1 { color: #edf3fc; }
:root[data-theme="dark"] .loginbox label,
:root[data-theme="dark"] .command label,
:root[data-theme="dark"] .fields label,
:root[data-theme="dark"] .maint-form label { color: #b3c1d5; }
:root[data-theme="dark"] .loginbox label.remember-session { color: #91a2ba; }
:root[data-theme="dark"] .stats article,
:root[data-theme="dark"] .panel { border-color: #293a52; background: #111d2e; box-shadow: 0 3px 12px rgb(0 0 0 / 16%); }
:root[data-theme="dark"] .stats small,
:root[data-theme="dark"] .table td,
:root[data-theme="dark"] .fields label,
:root[data-theme="dark"] .maint-form label { color: #b3c1d5; }
:root[data-theme="dark"] .mileage { border-color: #293a52; background: linear-gradient(135deg, #17314b, #111d2e 78%); }
:root[data-theme="dark"] .mileage .big strong { color: #edf3fc; }
:root[data-theme="dark"] .mileage .big span,
:root[data-theme="dark"] #deviceTable .vehicle-card-km strong { color: #35c995; }
:root[data-theme="dark"] .periods > div { border-color: rgb(255 255 255 / 7%); background: rgb(5 14 27 / 45%); color: #91a2ba; }
:root[data-theme="dark"] .periods strong { color: #edf3fc; }
:root[data-theme="dark"] .table th { border-color: #293a52; background: #111d2e; color: #91a2ba; }
:root[data-theme="dark"] .table td { border-color: rgb(105 132 166 / 18%); color: #b3c1d5; }
:root[data-theme="dark"] .table tbody tr:hover td { background: rgb(75 140 255 / 5%); color: #edf3fc; }
:root[data-theme="dark"] .map { border-color: #293a52; background: #101b2b; }
:root[data-theme="dark"] .vehicle,
:root[data-theme="dark"] .vehicle-card,
:root[data-theme="dark"] #deviceTable .vehicle-card { border-color: #293a52; background: linear-gradient(145deg, #19283d, #111d2e 76%); color: #edf3fc; }
:root[data-theme="dark"] .vehicle:hover,
:root[data-theme="dark"] .maintenance-alert:hover { border-color: #405c80; background: #19283d; }
:root[data-theme="dark"] .vehicle small,
:root[data-theme="dark"] #deviceTable .vehicle-card-caption,
:root[data-theme="dark"] .plan-row small,
:root[data-theme="dark"] .maintenance-alert small { color: #91a2ba; }
:root[data-theme="dark"] .vehicle-card-actions,
:root[data-theme="dark"] #deviceTable .vehicle-card-actions { border-color: #293a52; }
:root[data-theme="dark"] dialog { border-color: #293a52; background: #111d2e; color: #edf3fc; }
:root[data-theme="dark"] .permission-set { border-color: #293a52; }
:root[data-theme="dark"] .permission-set legend { color: #91a2ba; }
:root[data-theme="dark"] .plan-row { border-color: #293a52; }
:root[data-theme="dark"] .plan-actions .plan-edit { border-color: #405774; background: #1a2a40; color: #edf3fc; }
:root[data-theme="dark"] .plan-actions .plan-service { border-color: rgb(75 140 255 / 55%); background: rgb(75 140 255 / 14%); color: #9fc2ff; }
:root[data-theme="dark"] .plan-actions .plan-delete { border-color: rgb(255 115 126 / 38%); background: rgb(255 115 126 / 9%); color: #ff737e; }
:root[data-theme="dark"] .maintenance-alert { border-color: #293a52; background: #111d2e; color: #edf3fc; }
:root[data-theme="dark"] .map-icon-choice { color: #b3c1d5; }
:root[data-theme="dark"] :focus-visible { outline-color: #6aa0ff; }
:root[data-theme="dark"] .theme-icon-sun { display: block; }
:root[data-theme="dark"] .theme-icon-moon { display: none; }
.theme-icon { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.theme-icon-sun { display: none; }
#themeToggle { display: flex; align-items: center; gap: 10px; text-align: left; }

/* Ficha de mantenimiento: ancho útil, tarjetas alineadas y un único scroll. */
#maintenanceDialog {
  box-sizing: border-box;
  display: none;
  width: min(1040px, calc(100vw - 40px));
  max-width: 1040px;
  max-height: min(92dvh, 920px);
  padding: 0;
  overflow: hidden;
  border-radius: 20px;
}
#maintenanceDialog[open] { display: flex; flex-direction: column; }
#maintenanceDialog::backdrop { background: rgb(8 18 33 / 62%); backdrop-filter: blur(2px); }
#maintenanceDialog > .dialoghead {
  flex: 0 0 auto;
  align-items: flex-start;
  margin: 0;
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}
#maintenanceDialog > .dialoghead > div { flex: 1 1 auto; min-width: 0; }
#maintenanceDialog #maintenanceTitle { margin: 0 0 5px; font-size: clamp(19px, 2.4vw, 24px); line-height: 1.25; }
#maintenanceDialog #maintenanceSummary { margin: 0; font-size: 13px; line-height: 1.5; overflow-wrap: anywhere; }
#maintenanceDialog #closeMaintenance {
  display: grid;
  flex: 0 0 42px;
  place-items: center;
  width: 42px;
  min-width: 42px;
  height: 42px;
  min-height: 42px;
  padding: 0;
  border-radius: 12px;
  font-size: 25px;
  line-height: 1;
}
#maintenanceDialog .maint-dialog-scroll {
  display: grid;
  flex: 1 1 auto;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-content: start;
  align-items: start;
  gap: 14px;
  min-height: 0;
  max-height: none;
  padding: 18px 20px 22px;
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
}
#maintenanceDialog .maint-dialog-scroll > .panel {
  min-width: 0;
  margin: 0;
  padding: 17px;
  border-radius: 15px;
}
#maintenanceDialog .maint-dialog-scroll > .panel:nth-child(3) { grid-column: 1 / -1; }
#maintenanceDialog .maint-dialog-scroll > .panel > h3,
#maintenanceDialog .maint-dialog-scroll > .panel > .dialoghead h3 { margin: 0; font-size: 15px; line-height: 1.4; }
#maintenanceDialog .maint-dialog-scroll > .panel > h3 { margin-bottom: 14px; }
#maintenanceDialog .maint-dialog-scroll > .panel > .dialoghead { align-items: center; margin: 0 0 12px; }
#maintenanceDialog .maint-dialog-scroll > .panel > .dialoghead button { flex: 0 0 auto; min-height: 38px; }
#maintenanceDialog .maint-form { gap: 13px 14px; }
#maintenanceDialog .maint-form label { gap: 7px; line-height: 1.4; }
#maintenanceDialog .maint-form input:not([type="hidden"]):not([type="checkbox"]):not([type="radio"]),
#maintenanceDialog .maint-form select,
#maintenanceDialog .maint-form textarea { box-sizing: border-box; min-height: 42px; }
#maintenanceDialog .maint-form .checkrow input { flex: 0 0 16px; width: 16px; min-width: 16px; height: 16px; min-height: 16px; }
#maintenanceDialog .maint-form textarea { min-height: 76px; resize: vertical; }
#maintenanceDialog .maint-form .checkrow { display: flex !important; align-items: center; align-self: center; min-height: 42px; }
#maintenanceDialog #odometerHistory { margin-top: 15px; padding-top: 12px; border-top: 1px solid var(--line); font-size: 12px; line-height: 1.55; overflow-wrap: anywhere; }
#maintenanceDialog #vehiclePlans:empty { display: none; }
#maintenanceDialog #planForm:not(.hidden) { margin-top: 12px; padding-top: 14px; border-top: 1px solid var(--line); }
#maintenanceDialog .actions { flex-wrap: wrap; gap: 8px; }
#maintenanceDialog .actions button { min-height: 40px; }

@media (max-width: 760px) {
  #maintenanceDialog {
    width: calc(100vw - 20px);
    max-width: 680px;
    max-height: min(92dvh, 900px);
    border-radius: 17px;
  }
  #maintenanceDialog > .dialoghead { padding: 16px 16px 13px; }
  #maintenanceDialog #closeMaintenance { flex-basis: 40px; width: 40px; min-width: 40px; height: 40px; min-height: 40px; }
  #maintenanceDialog .maint-dialog-scroll { grid-template-columns: minmax(0, 1fr); gap: 11px; padding: 12px 12px calc(14px + env(safe-area-inset-bottom)); }
  #maintenanceDialog .maint-dialog-scroll > .panel { padding: 14px; }
  #maintenanceDialog .maint-dialog-scroll > .panel:nth-child(3) { grid-column: auto; }
  #maintenanceDialog .maint-form { grid-template-columns: minmax(0, 1fr); gap: 12px; }
  #maintenanceDialog .maint-form .wide { grid-column: auto; }
  #maintenanceDialog .maint-form .checkrow { align-self: start; }
  #maintenanceDialog .actions { justify-content: stretch; }
  #maintenanceDialog .actions button { flex: 1 1 auto; }
}

@media (max-width: 380px) {
  #maintenanceDialog { width: calc(100vw - 12px); max-height: 94dvh; border-radius: 14px; }
  #maintenanceDialog > .dialoghead { padding: 13px 12px 11px; }
  #maintenanceDialog .maint-dialog-scroll { padding: 9px 9px calc(11px + env(safe-area-inset-bottom)); }
  #maintenanceDialog .maint-dialog-scroll > .panel { padding: 12px; }
}

/* Immersive live map with floating controls */
body:has(#map:not(.hidden)) { overflow: hidden; }
body:has(#map:not(.hidden)) #sidebar { display: none !important; }
body:has(#map:not(.hidden)) main { position: fixed; inset: 0; width: 100vw; height: 100dvh; margin: 0; padding: 0; overflow: hidden; }
body:has(#map:not(.hidden)) main > header { position: absolute; z-index: 800; top: 12px; left: 64px; right: 12px; height: 48px; min-height: 0; padding: 0; border: 0; background: transparent; pointer-events: none; }
body:has(#map:not(.hidden)) main > header > * { pointer-events: auto; }
body:has(#map:not(.hidden)) main > header > div { display: none; }
body:has(#map:not(.hidden)) #mobileMenuToggle { display: inline-grid; position: fixed; z-index: 1200; top: 12px; left: 12px; width: 48px; height: 48px; border: 0; border-radius: 14px; background: var(--primary); color: white; box-shadow: none; }
body:has(#map:not(.hidden)) #map { position: absolute; inset: 0; display: block; width: 100%; height: 100%; padding: 0; }
body:has(#map:not(.hidden)) #map > .toolbar { position: absolute; z-index: 800; top: 12px; left: 72px; right: 72px; display: flex; justify-content: flex-end; gap: 8px; pointer-events: none; }
body:has(#map:not(.hidden)) #map > .toolbar > * { pointer-events: auto; }
body:has(#map:not(.hidden)) #mapSearch { width: min(220px, 38vw); }
body:has(#map:not(.hidden)) .mapgrid { position: absolute; inset: 0; display: block; }
body:has(#map:not(.hidden)) #liveMap { position: absolute; inset: 0; width: 100%; height: 100%; min-height: 0; border-radius: 0; }
body:has(#map:not(.hidden)) #vehicleList { position: absolute; z-index: 800; top: 72px; left: 12px; bottom: 16px; width: min(300px, 32vw); overflow: auto; border: 1px solid #ffffff66; background: color-mix(in srgb, var(--surface) 92%, transparent); box-shadow: 0 10px 32px #0b122044; backdrop-filter: blur(12px); }
@media(max-width:700px) { body:has(#map:not(.hidden)) #vehicleList { top: auto; right: 12px; bottom: 12px; left: 12px; width: auto; max-height: 34dvh; } body:has(#map:not(.hidden)) #map > .toolbar { right: 12px; } }

/* Live map layout refinement: one control row, clear overlays, compact mobile fleet */
body:has(#map:not(.hidden)) main > header { left: 0; right: 0; top: 0; height: 0; z-index: 11002; }
body:has(#map:not(.hidden)) #mobileMenuToggle { top: 14px; left: 14px; width: 46px; height: 46px; border: 1px solid rgb(255 255 255 / 25%); border-radius: 15px; background: #14243a; box-shadow: none; }
body:has(#map:not(.hidden)) #map > .toolbar { top: 14px; left: 72px; right: 14px; align-items: center; justify-content: flex-end; flex-wrap: nowrap; margin: 0; gap: 8px; }
body:has(#map:not(.hidden)) #mapSearch { flex: 0 1 270px; width: 270px; height: 46px; border-color: rgb(255 255 255 / 30%); background: rgb(15 27 44 / 94%); box-shadow: 0 8px 24px rgb(0 0 0 / 20%); }
body:has(#map:not(.hidden)) .map-icon-choice { display: flex; align-items: center; gap: 8px; min-height: 46px; padding: 0 10px; border: 1px solid rgb(255 255 255 / 22%); border-radius: 12px; background: rgb(15 27 44 / 94%); box-shadow: 0 8px 24px rgb(0 0 0 / 18%); color: #eaf1fa; font-size: 12px; }
body:has(#map:not(.hidden)) .map-icon-choice select { width: auto; min-height: 34px; padding: 6px 26px 6px 8px; border: 0; background-color: transparent; font-size: 13px; }
body:has(#map:not(.hidden)) #fit { min-height: 46px; border-color: rgb(255 255 255 / 22%); background: #14243a; color: white; box-shadow: 0 8px 24px rgb(0 0 0 / 18%); white-space: nowrap; }
body:has(#map:not(.hidden)) #vehicleList { top: 76px; bottom: 16px; left: 14px; width: 296px; max-height: none; padding: 12px; border: 1px solid rgb(255 255 255 / 24%); border-radius: 16px; background: rgb(13 24 40 / 94%); box-shadow: 0 12px 36px rgb(0 0 0 / 24%); backdrop-filter: blur(14px); }
body:has(#map:not(.hidden)) #vehicleList .vehicle { width: 100%; min-height: 56px; margin: 0 0 7px; padding: 10px 12px; border-color: rgb(255 255 255 / 12%); border-radius: 12px; background: rgb(255 255 255 / 5%); text-align: left; }
body:has(#map:not(.hidden)) #vehicleList .vehicle:hover { border-color: var(--blue); background: rgb(75 140 255 / 15%); }
body:has(#map:not(.hidden)) #liveMap .leaflet-control-zoom { margin-top: 76px; }
body:has(#map:not(.hidden)) #liveMap .leaflet-control-attribution { margin: 0 8px 8px 0; border-radius: 6px; }
@media(max-width:700px) {
  body:has(#map:not(.hidden)) #mobileMenuToggle { top: calc(10px + env(safe-area-inset-top)); left: 10px; width: 44px; height: 44px; }
  body:has(#map:not(.hidden)) #map > .toolbar { top: calc(10px + env(safe-area-inset-top)); left: 64px; right: 10px; flex-wrap: wrap; justify-content: flex-end; gap: 6px; }
  body:has(#map:not(.hidden)) #mapSearch { flex: 1 1 100%; width: auto; height: 44px; }
  body:has(#map:not(.hidden)) .map-icon-choice { min-height: 40px; padding: 0 8px; font-size: 11px; }
  body:has(#map:not(.hidden)) .map-icon-choice select { max-width: 112px; font-size: 12px; }
  body:has(#map:not(.hidden)) #fit { min-height: 40px; padding: 8px 10px; font-size: 12px; }
  body:has(#map:not(.hidden)) #vehicleList { top: auto; right: 10px; bottom: calc(10px + env(safe-area-inset-bottom)); left: 10px; display: flex; flex-direction: row; align-items: stretch; gap: 8px; width: auto; max-height: 112px; padding: 8px; overflow-x: auto; overflow-y: hidden; border-radius: 14px; }
  body:has(#map:not(.hidden)) #vehicleList .vehicle { flex: 0 0 172px; width: 172px; min-height: 78px; margin: 0; white-space: normal; }
  body:has(#map:not(.hidden)) #vehicleList .vehicle b, body:has(#map:not(.hidden)) #vehicleList .vehicle small { display: block; overflow: hidden; text-overflow: ellipsis; }
  body:has(#map:not(.hidden)) #liveMap .leaflet-control-zoom { margin-top: 118px; }
}
@media(max-width:380px) {
  body:has(#map:not(.hidden)) .map-icon-choice { display: none; }
  body:has(#map:not(.hidden)) #fit { flex: 0 0 auto; }
}

/* Map controls and floating navigation refinements */
body:has(#map:not(.hidden)) #sidebar { display: flex !important; z-index: 11001; width: var(--mobile-drawer-width); transform: translateX(-105%); visibility: hidden; transition: transform .22s ease, visibility .22s; background: #101c2d; box-shadow: none; }
body:has(#map:not(.hidden)).mobile-menu-open #sidebar { transform: translateX(0); visibility: visible; }
body:has(#map:not(.hidden)) #sidebar .brand { position: relative; padding-right: 42px; }
body:has(#map:not(.hidden)) #mapMenuClose { display: none; position: absolute; top: 0; right: 0; width: 44px; height: 44px; min-height: 44px; place-items: center; padding: 0; border: 1px solid #ffffff35; border-radius: 12px; background: #1a2a40; color: #fff; box-shadow: none; font-size: 24px; line-height: 1; }
body:has(#map:not(.hidden)).mobile-menu-open #mapMenuClose { display: grid; }
body:has(#map:not(.hidden)) .mobile-menu-backdrop { position: fixed; z-index: 11000; inset: 0; display: none; background: transparent; box-shadow: none; }
body:has(#map:not(.hidden)).mobile-menu-open .mobile-menu-backdrop { display: block; background: transparent; }
body:has(#map:not(.hidden)) #mobileMenuToggle { z-index: 11003; }
body:has(#map:not(.hidden)) #map > .toolbar { top: 14px; left: 72px; right: 14px; justify-content: flex-end; }
body:has(#map:not(.hidden)) #fit { min-height: 46px; padding: 10px 16px; border: 1px solid #ffffff35; border-radius: 13px; background: #10233b; color: #fff; font-weight: 700; box-shadow: 0 8px 25px #07111f66; }
body:has(#map:not(.hidden)) #vehicleList { color: #f8fafc; }
body:has(#map:not(.hidden)) #vehicleList .vehicle { display: flex; align-items: center; gap: 11px; color: #f8fafc; }
body:has(#map:not(.hidden)) #vehicleList .vehicle b { color: #f8fafc; font-size: 14px; }
body:has(#map:not(.hidden)) #vehicleList .vehicle small { margin-top: 4px; color: #d5e0ef; font-size: 12px; }
.vehicle-list-icon { display: grid; width: 38px; height: 38px; flex: 0 0 38px; place-items: center; border: 1px solid #ffffff55; border-radius: 11px; background: #2864bd; }
.vehicle-list-icon svg { width: 25px; height: 25px; fill: none; stroke: #fff; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.vehicle-list-copy { min-width: 0; display: block; }
.vehicle-list-copy b,.vehicle-list-copy small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fleet-map-icon { border: 0; background: transparent; }
.fleet-map-icon .truck-marker { display: grid; width: 42px; height: 42px; place-items: center; border: 2px solid #fff; border-radius: 14px; background: #2463bd; box-shadow: 0 4px 12px rgb(0 0 0 / 45%); }
.truck-marker svg { width: 27px; height: 27px; fill: none; stroke: #fff; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
@media(min-width:701px) {
  body:has(#map:not(.hidden)) #liveMap .leaflet-top.leaflet-left { top: 74px; right: 14px; left: auto; }
  body:has(#map:not(.hidden)) #liveMap .leaflet-control-zoom { margin: 0; }
}
@media(max-width:700px) {
  body:has(#map:not(.hidden)) #liveMap .leaflet-top.leaflet-left { top: 112px; right: auto; left: 0; }
  body:has(#map:not(.hidden)) #liveMap .leaflet-control-zoom { margin: 0; }
  body:has(#map:not(.hidden)) #sidebar { padding-top: calc(18px + env(safe-area-inset-top)); }
  body:has(#map:not(.hidden)) #vehicleList { display: flex; flex-direction: row; flex-wrap: nowrap; align-items: stretch; gap: 0; max-height: 112px; padding: 8px 0; overflow-x: auto; overflow-y: hidden; overscroll-behavior-x: contain; scroll-snap-type: x mandatory; scroll-padding-inline: 0; -webkit-overflow-scrolling: touch; touch-action: pan-x; }
  body:has(#map:not(.hidden)) #vehicleList .vehicle { flex: 0 0 calc(100% - 24px); width: calc(100% - 24px); min-width: 0; min-height: 82px; margin: 0 12px; gap: 10px; padding: 9px; scroll-snap-align: center; scroll-snap-stop: always; }
  body:has(#map:not(.hidden)) #vehicleList .vehicle-list-icon { width: 38px; height: 38px; flex-basis: 38px; }
  body:has(#map:not(.hidden)) #vehicleList .vehicle-list-copy { min-width: 0; flex: 1 1 0; }
  body:has(#map:not(.hidden)) #vehicleList .vehicle-list-copy b { white-space: nowrap; }
  body:has(#map:not(.hidden)) #vehicleList .vehicle-list-copy small { display: -webkit-box; overflow: hidden; white-space: normal; line-height: 1.3; text-overflow: ellipsis; -webkit-box-orient: vertical; -webkit-line-clamp: 2; }
}

#refresh { display: none; white-space: nowrap; }
main:has(#dashboard:not(.hidden)) > header #refresh { display: inline-flex; align-items: center; justify-content: center; }
@media (max-width: 700px) {
  header { grid-template-columns: 44px minmax(0, 1fr) auto; }
  header > #refresh { grid-column: auto; justify-self: end; min-height: 44px; padding: 8px 10px; }
  body:has(#map:not(.hidden)) #vehicleList { justify-content: flex-start; align-items: stretch; gap: 0; padding: 8px 0; scroll-padding-inline: 0; }
  body:has(#map:not(.hidden)) #vehicleList .vehicle-slide { display: flex; flex: 0 0 100%; align-items: stretch; box-sizing: border-box; width: 100%; min-width: 0; margin: 0; padding: 0 8px; scroll-snap-align: center; scroll-snap-stop: always; }
  body:has(#map:not(.hidden)) #vehicleList .vehicle-slide .vehicle { flex: 1 1 auto; width: 100%; min-width: 0; margin: 0; scroll-snap-align: none; }
}
@media (max-width: 380px) {
  header { grid-template-columns: 44px minmax(0, 1fr) auto; }
  header > button:last-child { grid-column: auto; justify-self: end; }
}

#vehicleList .vehicle-slide { min-width: 0; }


body:has(#map:not(.hidden)) #sidebar,
body:has(#history:not(.hidden)) #sidebar { border-right: 1px solid rgb(255 255 255 / 24%); background: #101c2d; }

/* Shared high-contrast navigation for immersive maps */
body:has(#map:not(.hidden)) #sidebar #nav button,
body:has(#history:not(.hidden)) #sidebar #nav button { color: #e8eff9; }
body:has(#map:not(.hidden)) #sidebar #nav button:hover,
body:has(#history:not(.hidden)) #sidebar #nav button:hover { border-color: rgb(126 170 255 / 42%); background: #1a304d; color: #fff; }
body:has(#map:not(.hidden)) #sidebar #nav button.active,
body:has(#history:not(.hidden)) #sidebar #nav button.active { border-color: rgb(126 170 255 / 55%); background: #24466f; color: #fff; box-shadow: inset 3px 0 0 #80adff; }
body:has(#map:not(.hidden)) #sidebar .bottom,
body:has(#history:not(.hidden)) #sidebar .bottom { border-color: rgb(255 255 255 / 22%); }
body:has(#map:not(.hidden)) #sidebar .bottom #connection,
body:has(#history:not(.hidden)) #sidebar .bottom #connection { color: #d2deee; }
body:has(#map:not(.hidden)) #sidebar .bottom button,
body:has(#history:not(.hidden)) #sidebar .bottom button { border: 1px solid rgb(255 255 255 / 22%); background: #1a2a40; color: #f8fafc; }
body:has(#map:not(.hidden)) #sidebar .bottom button:hover,
body:has(#history:not(.hidden)) #sidebar .bottom button:hover { border-color: #80adff; background: #223b5b; color: #fff; }
