/* Luvatec GPS visual system — shared, progressive layer over legacy module CSS. */
:root {
  color-scheme: light;
  --brand-on-primary: #fff;
  --slate-50: #f5f8fc;
  --slate-100: #edf2f8;
  --slate-200: #dce5ef;
  --slate-300: #c4d0df;
  --slate-400: #8494a8;
  --slate-500: #617286;
  --slate-600: #47596d;
  --slate-700: #33465b;
  --slate-800: #243549;
  --slate-900: #162638;
  --slate-950: #0c1725;
  --success: #16804a;
  --danger: #c53f43;
  --warning: #a86409;
  --info: #1878c8;
  --surface: #fff;
  --surface-2: #f5f8fc;
  --ink: #162638;
  --muted: #617286;
  --bg: #f3f6fa;
  --bg-2: #edf2f8;
  --line: #dce5ef;
  --line-2: #c4d0df;
  --border-subtle: rgba(22, 38, 56, .09);
  --radius: 8px;
  --radius-lg: 10px;
  --radius-sm: 6px;
  --ui-radius-control: 6px;
  --ui-radius-panel: 8px;
  --ui-radius-dialog: 10px;
  --shadow-card: 0 1px 2px rgba(17, 39, 63, .035);
  --shadow-card-hover: 0 2px 6px rgba(17, 39, 63, .07);
  --shadow-panel: 0 10px 28px rgba(17, 39, 63, .12);
  --glass-bg: rgba(255, 255, 255, .94);
  --glass-border: rgba(22, 38, 56, .1);
  --ui-space-1: 4px;
  --ui-space-2: 8px;
  --ui-space-3: 12px;
  --ui-space-4: 16px;
  --ui-space-5: 20px;
  --ui-space-6: 24px;
}

.dark {
  color-scheme: dark;
  --slate-50: #eaf1f8;
  --slate-100: #d6e1ed;
  --slate-200: #b7c6d6;
  --slate-300: #8da0b5;
  --slate-400: #8598ad;
  --slate-500: #6c8095;
  --slate-600: #52677d;
  --slate-700: #34495f;
  --slate-800: #24384c;
  --slate-900: #172a3c;
  --slate-950: #0d1b2a;
  --surface: #172a3c;
  --surface-2: #203449;
  --ink: #eaf1f8;
  --muted: #a1b1c2;
  --bg: #0d1b2a;
  --bg-2: #172a3c;
  --line: #2b4055;
  --line-2: #3a526b;
  --border-subtle: rgba(219, 232, 245, .11);
  --glass-bg: rgba(19, 37, 54, .94);
  --glass-border: rgba(219, 232, 245, .12);
  --shadow-card: 0 1px 2px rgba(0, 0, 0, .14);
  --shadow-card-hover: 0 2px 6px rgba(0, 0, 0, .2);
  --shadow-panel: 0 10px 28px rgba(0, 0, 0, .3);
}

html { background: var(--bg); }
body { background: var(--bg); color: var(--ink); }
button, input, select, textarea { font: inherit; }
button, [role="button"], a { -webkit-tap-highlight-color: transparent; }
:where(button, a, input, select, textarea, [tabindex]):focus-visible {
  outline: 3px solid color-mix(in srgb, var(--app-primary-color) 45%, transparent);
  outline-offset: 2px;
}
::selection { background: color-mix(in srgb, var(--app-primary-color) 24%, transparent); }

/* Shared application chrome */
#topbar {
  background: var(--surface);
  border-bottom-color: var(--line);
  box-shadow: 0 1px 4px rgba(17, 39, 63, .035);
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}
#rail {
  background: var(--surface);
  border-right-color: var(--line);
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}
.rail-item { color: var(--muted); border-radius: 10px; }
.rail-item:hover { color: var(--ink); background: var(--bg-2); }
.rail-item.active {
  color: var(--app-primary-color);
  background: color-mix(in srgb, var(--app-primary-color) 10%, var(--surface));
  border-color: color-mix(in srgb, var(--app-primary-color) 20%, transparent);
}
.rail-item.active::before { width: 3px; }
.dark #rail { background: var(--surface); border-right-color: var(--line); }
.dark .rail-item { color: var(--muted); }
.dark .rail-item:hover { color: var(--ink); background: var(--bg-2); }
.dark .rail-item.active { color: var(--brand-300); }
#top-actions > button, #top-actions > a {
  border-radius: var(--ui-radius-control);
  transition: background-color .16s ease, color .16s ease, border-color .16s ease;
}

/* Desktop rail: compact icon navigation with clear tooltips and native drag ordering. */
@media (min-width: 769px) {
  #rail {
    width: 68px;
    padding: 14px 8px;
    gap: 6px;
    background: var(--surface);
  }
  #rail .rail-item {
    width: 48px;
    min-width: 48px;
    height: 48px;
    min-height: 48px;
    margin: 0;
    padding: 0;
    gap: 0;
    border: 1px solid transparent;
    border-radius: 8px;
    cursor: grab;
    touch-action: none;
  }
  #rail .rail-item:active { cursor: grabbing; }
  #rail .rail-label { display: none !important; }
  #rail .rail-icon {
    width: 21px;
    height: 21px;
    stroke-width: 1.9;
    filter: none !important;
    transition: transform .16s ease, stroke-width .16s ease;
  }
  #rail .rail-item:hover .rail-icon { transform: scale(1.06); }
  #rail .rail-item.active .rail-icon { stroke-width: 2.2; }
  #rail .rail-item::before {
    left: -9px;
    width: 3px;
    height: 22px;
    border-radius: 0 2px 2px 0;
    box-shadow: none;
  }
  #rail .rail-divider {
    width: 32px;
    margin: 3px 0;
  }
  .rail-tooltip {
    position: fixed;
    z-index: 12000;
    width: max-content;
    max-width: 230px;
    padding: 7px 10px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: var(--surface);
    color: var(--ink);
    box-shadow: 0 6px 18px rgba(12, 23, 37, .16);
    font: 600 12px/1.2 var(--font-sans);
    white-space: nowrap;
    pointer-events: none;
    animation: rail-tooltip-in .12s ease-out both;
  }
  .rail-tooltip[hidden] { display: none; }
  @keyframes rail-tooltip-in { from { opacity: 0; transform: translateX(-3px); } to { opacity: 1; transform: translateX(0); } }
  #rail .rail-item-dragging { opacity: .38; }
  #rail .rail-item { user-select: none; }
  #rail.rail-order-saved { border-right-color: color-mix(in srgb, var(--app-primary-color) 40%, var(--line)); }
  .dark .rail-tooltip {
    border-color: var(--line-2);
    box-shadow: 0 8px 22px rgba(0, 0, 0, .38);
  }
}

/* Page hierarchy and card surfaces across all authenticated modules */
.db-inner, .rv-inner, .zv-inner, .adm-inner, .mon-inner, .tec-inner {
  color: var(--ink);
}
.db-head, .rv-head, .zv-head, .adm-head, .mon-head, .tec-head {
  gap: 6px;
}
.db-head h1, .rv-head h1, .zv-head h1, .adm-head h1, .mon-head h1, .tec-head h1 {
  color: var(--ink);
  letter-spacing: -.035em;
}
.db-sub, .rv-head p, .zv-head p, .adm-head p, .mon-head p, .tec-head p { color: var(--muted); }
.db-card, .db-kpi, .rv-card, .zv-card, .pf-card, .mon-card, .tec-card,
.inv-table-card, .fuel-kpi-card, .metric-card, .report-card {
  border-color: var(--line);
  border-radius: var(--ui-radius-panel);
  box-shadow: var(--shadow-card);
}
.db-card { padding: 18px; }
.db-kpi { border-radius: var(--ui-radius-panel); }
.db-kpi small { letter-spacing: 0; color: var(--muted); }
.db-card-head h2 { color: var(--ink); }
.db-link { min-height: 36px; }
.page-badge-live { color: var(--brand-700); }
.dark .page-badge-live { color: var(--brand-300); }

/* Dispatch workspace: compact actions, summary and a visible team beside the map. */
#tecnicos-view .tec-head { margin-bottom: 0 !important; }
#tecnicos-view .tec-inner { gap: 14px; }
.tec-head-actions { width: 100%; gap: 8px; }
.tec-head-actions .btn-primary,
.tec-head-actions .btn-secondary {
  height: 34px;
  min-height: 34px;
  padding: 0 12px;
  gap: 6px;
  font-size: 12px;
  text-decoration: none;
  white-space: nowrap;
}
.tec-head-actions svg { width: 16px; height: 16px; }
.tec-kpis { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 10px; }
.tec-kpis .tec-kpi {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  min-width: 0;
  min-height: 58px;
  text-align: left;
  font: inherit;
}
.tec-kpi .muted { font-size: 12px; line-height: 1.35; }
.tec-kpi strong { font-size: 23px; font-weight: 700; line-height: 1.1; }
.tec-kpi-blue { color: var(--brand-600); }
.tec-kpi-warning { color: var(--warning); }
.tec-kpi-purple { color: var(--purple); }
.tec-kpi-success { color: var(--success); }
.tec-kpi-danger { color: var(--danger); }
.tec-kpi-filter { cursor: pointer; }
.tec-kpi-filter:hover { border-color: var(--brand-600); }
.tec-dispatch-workspace { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; }
.tec-dispatch-panel, .tec-team-panel { min-width: 0; display: flex; flex-direction: column; gap: 10px; }
.tec-panel-head { min-width: 0; }
.tec-panel-head h3 { font-size: 14px; line-height: 1.4; }
.tec-map-card { padding: 0; overflow: hidden; height: 320px; position: relative; margin: 0; }
#fs-dispatch-map { width: 100%; height: 100%; }
.tec-team-panel .fs-techs-grid { margin: 0; align-content: start; }
.tec-team-panel .fs-tech-card { padding: 12px; gap: 6px; min-width: 0; }
.tec-team-panel .fs-tech-name { font-size: 13px; overflow-wrap: anywhere; }
.tec-team-panel .fs-tech-sub { overflow-wrap: anywhere; }
.tec-team-panel .fs-tech-sub > * { min-width: 0; max-width: 100%; }
@media (min-width: 1024px) {
  #tecnicos-view .fs-order-filter-row > select { width: auto; height: 34px; flex: 0 1 170px; }
  #tecnicos-view .fs-order-filter-row .adm-search-wrap { width: auto; }
  #tecnicos-view .fs-order-actions .btn-secondary { width: auto; min-height: 34px; padding: 0 10px; font-size: 12px; white-space: nowrap; }
  #tecnicos-view input[type="date"] { width: auto; }
  .tec-dispatch-workspace {
    grid-template-columns: minmax(0, 1fr) minmax(290px, 340px);
    height: clamp(300px, 43vh, 410px);
  }
  .tec-dispatch-panel, .tec-team-panel { min-height: 0; }
  .tec-panel-head { min-height: 42px; display: flex; flex-direction: column; justify-content: center; }
  .tec-team-panel .tec-panel-head > div { width: 100%; }
  .tec-map-card { height: auto; flex: 1; min-height: 0; }
  .tec-team-panel .fs-techs-grid { grid-template-columns: minmax(0, 1fr); overflow-y: auto; min-height: 0; padding: 1px 4px 1px 1px; }
}
@media (max-width: 767px) {
  .tec-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .tec-kpis .tec-kpi { padding: 10px 12px; }
  .tec-kpi-filter { grid-column: 1 / -1; }
}

/* Report and geofence workspaces share one proportion for their tools and canvas. */
.rv-workspace, .zv-workspace {
  grid-template-columns: minmax(300px, min(360px, 36vw)) minmax(0, 1fr);
  gap: 16px;
}
.rv-sidebar, .rv-results, .zv-sidebar, .zv-map-area {
  min-width: 0;
  border-color: var(--line);
  border-radius: var(--ui-radius-panel);
  background: var(--surface);
  box-shadow: var(--shadow-card);
}
.rv-sidebar-content { gap: 16px; }
.rv-section, .zv-tab-panel { min-width: 0; }
.rv-section-head, .zv-pane-toolbar, .mon-logs-head {
  border-bottom-color: var(--line);
}
.zv-pane-toolbar { background: var(--surface); }

/* Admin, monitoring and technician sections share readable data surfaces. */
.adm-section-header, .mon-section-header, .tec-section-header { border-bottom-color: var(--line); }
.adm-table-wrap, .mon-table-wrap, .inv-table-card {
  border-color: var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow-card);
}
.adm-table th, .mon-table th { color: var(--muted); background: var(--bg-2); }
.adm-table td, .adm-table th, .mon-table td, .mon-table th { border-color: var(--line); }
.mon-logs-terminal { border-radius: 10px; }
.inv-kpi-card, .inv-hero-card { border-radius: 14px; }
.fs-tech-card, .fs-card { border-color: var(--line); box-shadow: var(--shadow-card); }

/* Common tabs, buttons, form controls and filters */
.tabs.panel-tabs { gap: 6px; border-bottom-color: var(--line); }
.tabs.panel-tabs .tab {
  border-radius: var(--ui-radius-control) var(--ui-radius-control) 0 0;
  color: var(--muted);
  transition: color .15s ease, background-color .15s ease, border-color .15s ease;
}
.tabs.panel-tabs .tab:hover { background: var(--bg-2); color: var(--ink); }
.tabs.panel-tabs .tab.active { color: var(--app-primary-color); }
.btn-primary, .btn-secondary, .btn-danger, .head-btn, .head-btn.primary,
.head-btn.primary-btn, .btn-icon, .btn-ghost {
  border-radius: var(--ui-radius-control);
  font-weight: 650;
  transition: background-color .15s ease, color .15s ease, border-color .15s ease, box-shadow .15s ease, transform .12s ease;
}
.btn-primary { background: var(--app-primary-color); color: var(--brand-on-primary); }
.btn-primary:hover { filter: brightness(.96); box-shadow: 0 4px 12px color-mix(in srgb, var(--app-primary-color) 23%, transparent); }
.btn-secondary { border-color: var(--line-2); color: var(--ink); background: var(--surface); }
.btn-secondary:hover, .head-btn:hover { border-color: color-mix(in srgb, var(--app-primary-color) 35%, var(--line-2)); background: var(--bg-2); }
.head-btn { border-color: var(--line-2); background: var(--surface); color: var(--ink); }
input:not([type="checkbox"]):not([type="radio"]), select, textarea {
  border-color: var(--line-2);
  border-radius: var(--ui-radius-control);
  color: var(--ink);
  background-color: var(--surface);
}
input::placeholder, textarea::placeholder { color: var(--slate-400); }
input:focus, select:focus, textarea:focus {
  border-color: var(--app-primary-color);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--app-primary-color) 16%, transparent);
}

/* Data grids and reporting tables */
.table-responsive, .adm-table-wrap { max-width: 100%; border-radius: var(--ui-radius-panel); }
table { border-color: var(--line); }
th { color: var(--muted); background: var(--bg-2); }
td, th { border-color: var(--line); }
tbody tr:hover { background: color-mix(in srgb, var(--app-primary-color) 4%, var(--surface)); }
.custom-scroll { scrollbar-color: color-mix(in srgb, var(--ink) 24%, transparent) transparent; scrollbar-width: thin; }
.custom-scroll::-webkit-scrollbar { width: 6px; height: 6px; }
.custom-scroll::-webkit-scrollbar-track { background: transparent; }
.custom-scroll::-webkit-scrollbar-thumb { border-radius: 999px; background: color-mix(in srgb, var(--ink) 22%, transparent); }

/* Dialogs: keep established geometry, improve surface and mobile reach */
#modal-box, #form-modal-box, .modal-box {
  border: 1px solid var(--line);
  border-radius: var(--ui-radius-dialog);
  box-shadow: var(--shadow-panel);
}
.modal-head { border-bottom-color: var(--line); }
.modal-foot { border-top-color: var(--line); }
.modal-close, .modal-close-btn, .btn-close-modal { border-radius: var(--ui-radius-control); }
/* Legacy close controls used forced circular geometry; align them with the system. */
#modal-close, #form-modal-close, #modal-close-btn, #alarm-detail-close,
#device-details-close, #cmd-dialog-close, #bell-pop-close, #fuel-modal-close,
#wb-dns-modal-close, #wb-inv-modal-close, #wb-cfg-modal-close, #vc-modal-close,
#subnav-sheet-close, #main-menu-sheet-close, #rail-close,
#btn-close-adm-tech-modal, #btn-close-adm-order-modal,
#btn-close-adm-edit-order-modal, #btn-close-adm-form-config-modal,
#btn-close-android-modal, #help-modal-close {
  border-radius: var(--ui-radius-control) !important;
}

/* The live map retains its map-first layout while sharing the application palette. */
.panel, #panel-map { border-color: var(--line); border-radius: var(--ui-radius-panel); }
.panel > .panel-head, .panel-head { border-bottom-color: var(--line); }
.panel-search-box input, #db-fleet-search { border-color: var(--line-2); }
.maplibregl-ctrl-group { overflow: hidden; border: 1px solid var(--line) !important; border-radius: var(--ui-radius-control) !important; box-shadow: var(--shadow-card) !important; }
.dark .maplibregl-ctrl-group { background: var(--surface); }

/* Public sign-in and technician web portal keep their own layout but use shared tokens. */
.login-page, body.login-page { background: var(--bg); }
.technician-page, body.technician-page { background: var(--bg); color: var(--ink); }

@media (max-width: 1024px) {
  .db-inner, .rv-inner, .zv-inner, .adm-inner, .mon-inner, .tec-inner { min-width: 0; }
  .db-grid { grid-template-columns: repeat(auto-fit, minmax(min(100%, 300px), 1fr)); }
  .rv-workspace, .zv-workspace { grid-template-columns: minmax(280px, 34vw) minmax(0, 1fr); gap: 12px; }
}

@media (max-width: 768px) {
  body { overflow: hidden; }
  #topbar { padding-left: max(10px, env(safe-area-inset-left)); padding-right: max(10px, env(safe-area-inset-right)); }
  .db-inner, .rv-inner, .zv-inner, .adm-inner, .mon-inner, .tec-inner {
    padding-left: 14px;
    padding-right: 14px;
    padding-bottom: max(104px, calc(88px + env(safe-area-inset-bottom)));
  }
  .db-head h1, .rv-head h1, .zv-head h1, .adm-head h1, .mon-head h1, .tec-head h1 { font-size: 20px; }
  .db-kpis { gap: 10px; }
  .db-kpi { min-height: 70px; }
  .rv-workspace, .zv-workspace { gap: 10px; }
  .rv-sidebar, .rv-results, .zv-sidebar, .zv-map-area { box-shadow: none; }
  .tabs.panel-tabs { max-width: 100%; overflow-x: auto; overscroll-behavior-inline: contain; }
  .tabs.panel-tabs .tab { min-height: 40px; flex: 0 0 auto; }
  .btn-primary, .btn-secondary, .btn-danger, .head-btn, .btn-icon, .btn-ghost { min-height: 40px; }
  .modal-box, #modal-box, #form-modal-box { max-height: calc(100dvh - 24px - env(safe-area-inset-top) - env(safe-area-inset-bottom)); }
  #panel-map { border-radius: var(--ui-radius-panel) var(--ui-radius-panel) 0 0; }
  .modal-body { overscroll-behavior: contain; }
  .table-responsive, .adm-table-wrap { overflow-x: auto; overscroll-behavior-inline: contain; }
}

/* First visual pilot: Dashboard, live map and reports keep their established layout. */
#dashboard .page-badge-live,
#reports-view .page-badge-live { display: none !important; }
#dashboard .db-head h1,
#reports-view .rv-head h1 { font-size: 24px; }
#dashboard .db-card-head > svg,
#panel-map .panel-head-icon { display: none; }
#dashboard .db-kpi,
#dashboard .db-card,
#reports-view .rv-sidebar,
#reports-view .rv-results { border-radius: var(--ui-radius-panel); box-shadow: none; }
#dashboard .db-kpi { padding: 12px 14px; border: 1px solid var(--line); }
#dashboard .db-kpi-icon { width: 24px; height: 24px; background: transparent; }
#dashboard .db-kpi-icon svg { width: 17px; height: 17px; }
#dashboard .db-kpi small { font-size: 12px; font-weight: 600; text-transform: none; letter-spacing: 0; }
#dashboard .db-kpi.clickable:hover { background: var(--surface-2); box-shadow: none; }
#dashboard .db-kpi.clickable:active { transform: none; }
#dashboard .db-card-head { gap: 0; margin-bottom: 12px; }
#dashboard .db-card-head h2 { font-size: 16px; font-weight: 700; }
#dashboard .db-link { font-size: 12px; font-weight: 600; }
#reports-view .rv-label { font-size: 12px; font-weight: 600; text-transform: none; letter-spacing: 0; }
#reports-view .rv-nav .tab { border-radius: var(--ui-radius-control); }
#reports-view #periods button,
#reports-view #report-periods button { border-radius: var(--ui-radius-control); }
#reports-view .rv-generate,
#reports-view .rv-btn-exec { border-radius: var(--ui-radius-control); }
#reports-view {
  overflow: hidden;
}
#reports-view .rv-inner,
#reports-view .rv-workspace { min-height: 0; }
#reports-view .rv-workspace {
  height: auto;
  flex: 1 1 0;
}
#reports-view .rv-sidebar { min-height: 0; overflow: hidden; }
#reports-view .rv-results { min-height: 0; }
#reports-view #tab-recorrido {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  min-height: 0;
  height: 100%;
  gap: 0;
  padding-top: 0;
}
#reports-view #tab-recorrido .rv-map-wrap {
  flex: 1 1 0;
  min-width: 0;
  min-height: 280px;
  height: auto;
  margin: 0;
  border-radius: var(--ui-radius-panel);
  box-shadow: none;
}
#reports-view #summary {
  flex: 0 0 auto;
  min-height: 34px;
  margin: 0;
  padding: 8px 14px;
  box-sizing: border-box;
}
#reports-view .rv-points-card {
  flex: 0 0 auto;
  border: 0;
  border-top: 1px solid var(--line);
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}
#reports-view .rv-points-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  cursor: pointer;
  list-style: none;
  user-select: none;
}
#reports-view .rv-points-head::-webkit-details-marker { display: none; }
#reports-view .rv-points-chevron { width: 15px; height: 15px; margin-left: auto; transition: transform .15s ease; }
#reports-view .rv-points-card[open] .rv-points-chevron { transform: rotate(180deg); }
#reports-view #points-table { padding: 0 14px 6px; }
#reports-view .rv-points-card:not([open]) #points-table { display: none; }
#reports-view #points-table { max-height: 220px; overflow: auto; }
#reports-view .rv-results { overflow-x: hidden; }
#reports-view .rv-sidebar-content {
  gap: 8px;
  padding: 12px;
}
#reports-view .rv-section { gap: 5px; }
#reports-view .rv-range { gap: 4px; padding: 6px 8px; }
#reports-view .rv-export-section { gap: 5px; margin-top: 0; padding-top: 8px; }
#reports-view .rv-btn-exec { margin-bottom: 3px; }
#panel-map .panel-head-title { gap: 6px; }
#panel-map .panel-count-badge { border-radius: 4px; padding: 1px 6px; }
#panel-map .panel-collapse-trigger { border-radius: var(--ui-radius-control); }
#panel-map .maplibregl-ctrl-group { border-radius: var(--ui-radius-control) !important; }
@media (min-width: 769px) {
  #reports-view .rv-nav .tab svg { display: none; }
}
@media (min-width: 1200px) and (max-height: 760px) {
  #reports-view .rv-workspace { grid-template-columns: 400px minmax(0, 1fr); }
  #reports-view .rv-sidebar-content {
    display: grid;
    grid-template-columns: minmax(0, .9fr) minmax(0, 1.1fr);
    align-content: start;
    gap: 6px 10px;
    padding: 6px;
  }
  #reports-view #rv-veh-section,
  #reports-view #rv-period-section { grid-column: span 1; }
  #reports-view #rv-multiselect,
  #reports-view #rv-speeding-section,
  #reports-view #rv-options,
  #reports-view #rv-generate,
  #reports-view .rv-export-section { grid-column: 1 / -1; }
  #reports-view #rv-period-section { gap: 3px; }
  #reports-view .rv-range { gap: 2px; padding: 4px 6px; }
  #reports-view .rv-range-field input[type="datetime-local"] { height: 30px; }
  #reports-view #periods { gap: 4px; margin-bottom: 2px; }
  #reports-view #periods button { height: 28px; padding: 0 4px; font-size: 10px; white-space: nowrap; }
  #reports-view #rv-options-toggle,
  #reports-view .rv-generate,
  #reports-view .rv-btn-exec { height: 34px; }
  #reports-view .rv-btn-exec { margin-bottom: 0; }
  #reports-view #export-wrap button { height: 30px; }
}
@media (max-width: 768px) {
  #reports-view { overflow-y: auto; }
  /* The mobile switch is now inside the workspace, so release the old
     bottom reservation that was cutting the report action off. */
  #reports-view .rv-inner { padding-bottom: 64px; }
  #reports-view .rv-sidebar { overflow-y: auto; }
  #reports-view .rv-results { overflow-y: auto; }
  #reports-view .rv-workspace { height: calc(100dvh - 185px); }
  #reports-view .rv-sidebar-content { display: flex; gap: 12px; padding: 12px; }
  #reports-view .rv-section { gap: 6px; }
  #reports-view .rv-range { gap: 6px; padding: 8px; }
  #reports-view .rv-export-section { gap: 6px; margin-top: 4px; padding-top: 10px; }
  #reports-view .rv-btn-exec { margin-bottom: 8px; }
  #dashboard .db-head h1,
  #reports-view .rv-head h1 { font-size: 20px; }
  #dashboard .db-kpi { padding: 10px 11px; }
  #reports-view #periods button,
  #reports-view #report-periods button { height: 40px; min-height: 40px; }
  #reports-view .rv-generate,
  #reports-view .rv-btn-exec { min-height: 44px; }
  #reports-view .rv-mobile-switch { border-radius: var(--ui-radius-panel); box-shadow: 0 2px 8px rgba(17, 39, 63, .14); }
  #reports-view .rv-mobile-switch button { min-height: 40px; border-radius: var(--ui-radius-control); }
  /* Keep the Reportes view switch in the workspace flow so it never covers
     the export actions, playback summary, or point table. */
  body:not(.rv-fs) #reports-view .rv-workspace {
    display: flex;
    flex-direction: column;
    gap: 8px;
  }
  body:not(.rv-fs) #reports-view .rv-mobile-switch {
    position: static !important;
    order: -1;
    align-self: center;
    flex: 0 0 auto;
    inset: auto !important;
    transform: none !important;
    z-index: auto !important;
    margin: 0 auto;
  }
  body:not(.rv-fs) #reports-view .rv-sidebar,
  body:not(.rv-fs) #reports-view .rv-results,
  body:not(.rv-fs) #reports-view .rv-workspace.show-results .rv-results {
    height: auto !important;
    min-height: 0;
    flex: 1 1 0;
  }
  body:not(.rv-fs) #reports-view .rv-sidebar-content { padding-bottom: 12px !important; }
  #reports-view #summary { padding: 10px 16px; }
  #mobile-dock #menu-toggle,
  #mobile-dock #subnav-toggle,
  #mobile-dock #panel-open { border-radius: var(--ui-radius-control); box-shadow: 0 2px 8px rgba(17, 39, 63, .14); }
  #mobile-dock #menu-toggle:active,
  #mobile-dock #subnav-toggle:active,
  #mobile-dock #panel-open:active { transform: none !important; }
  #subnav-sheet, #main-menu-sheet { border-radius: var(--ui-radius-panel) var(--ui-radius-panel) 0 0; }
  .subnav-sheet-btn { border-radius: var(--ui-radius-panel); }
}

@media (max-width: 390px) {
  .db-inner, .rv-inner, .zv-inner, .adm-inner, .mon-inner, .tec-inner { padding-left: 10px; padding-right: 10px; }
  .db-kpi { padding: 9px 10px; gap: 8px; }
  .db-kpi small { font-size: 8.5px; letter-spacing: .03em; }
}

/* Desktop report panes: show only the selected report and keep its controls
   inside the results surface instead of stacking it under the playback map. */
@media (min-width: 769px) {
  #reports-view .rv-workspace:has(.rv-results > #tab-recorrido.active) {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr);
    gap: 10px;
  }
  #reports-view .rv-workspace:has(.rv-results > #tab-recorrido.active) > .rv-sidebar {
    height: auto;
    max-height: none;
    overflow: visible;
  }
  #reports-view .rv-workspace:has(.rv-results > #tab-recorrido.active) .rv-sidebar-content {
    display: grid;
    grid-template-columns: minmax(170px, .8fr) minmax(360px, 1.8fr) minmax(175px, .8fr) minmax(160px, .7fr);
    grid-template-rows: auto auto;
    align-items: end;
    gap: 8px 12px;
    padding: 10px 12px;
  }
  #reports-view .rv-workspace:has(.rv-results > #tab-recorrido.active) #rv-veh-section { grid-column: 1; grid-row: 1; }
  #reports-view .rv-workspace:has(.rv-results > #tab-recorrido.active) #rv-period-section { grid-column: 2; grid-row: 1; }
  #reports-view .rv-workspace:has(.rv-results > #tab-recorrido.active) #rv-options { grid-column: 3; grid-row: 1; }
  #reports-view .rv-workspace:has(.rv-results > #tab-recorrido.active) #rv-generate { grid-column: 4; grid-row: 1; margin: 0; }
  #reports-view .rv-workspace:has(.rv-results > #tab-recorrido.active) .rv-export-section {
    grid-column: 1 / -1;
    grid-row: 2;
    display: grid;
    grid-template-columns: auto auto minmax(0, 1fr);
    align-items: center;
    gap: 8px 12px;
    margin: 0;
    padding: 8px 0 0;
  }
  #reports-view .rv-workspace:has(.rv-results > #tab-recorrido.active) .rv-export-section > .rv-label { white-space: nowrap; }
  #reports-view .rv-workspace:has(.rv-results > #tab-recorrido.active) .rv-btn-exec { width: auto; height: 34px; margin: 0; padding: 0 12px; white-space: nowrap; }
  #reports-view .rv-workspace:has(.rv-results > #tab-recorrido.active) #export-wrap { grid-column: 3; grid-row: 1; grid-template-columns: repeat(4, minmax(58px, 1fr)); }
  #reports-view .rv-workspace:has(.rv-results > #tab-recorrido.active) .rv-map-wrap { min-height: 360px; }
  #reports-view .rv-workspace:has(.rv-results > #tab-recorrido.active) .rv-map-wrap.rv-fullscreen {
    position: absolute;
    inset: 0;
    z-index: 30;
    width: auto;
    height: auto !important;
    border-radius: var(--ui-radius-panel);
    border: 1px solid var(--border-subtle);
  }
  #reports-view .rv-workspace:has(.rv-results > #tab-recorrido.active) .rv-points-card:not([open]) { min-height: 38px; }
  #reports-view .rv-workspace:has(.rv-results > #tab-recorrido.active) .rv-points-head { padding: 8px 12px; }

  #reports-view .rv-workspace {
    grid-template-columns: minmax(320px, min(400px, 36vw)) minmax(0, 1fr);
    gap: 16px;
  }
  #reports-view .rv-sidebar {
    overflow-x: hidden;
    overflow-y: auto;
    scrollbar-width: thin;
    overscroll-behavior: contain;
  }
  #reports-view .rv-workspace:has(.rv-results > #tab-mantenimiento.active) {
    grid-template-columns: minmax(0, 1fr);
  }
  #reports-view .rv-workspace:has(.rv-results > #tab-mantenimiento.active) > .rv-sidebar {
    display: none;
  }
  #reports-view .rv-results {
    min-height: 0;
    overflow: hidden;
    padding: 0;
    gap: 0;
  }
  #reports-view .rv-results > #tab-recorrido:not(.active) {
    display: none !important;
  }
  #reports-view .rv-results > #tab-recorrido.active {
    display: flex;
    flex: 1 1 0;
    height: auto;
    min-height: 0;
    overflow: hidden;
  }
  #reports-view .rv-results > .tab-pane.active:not(#tab-recorrido) {
    display: flex;
    flex: 1 1 0;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
    overflow: auto;
    gap: 12px;
    padding: 14px;
    box-sizing: border-box;
    overscroll-behavior: contain;
  }
  #reports-view .rv-results > .tab-pane.active:not(#tab-recorrido) .rv-actions-row {
    flex: 0 0 auto;
    margin: 0;
    padding: 2px 0 10px;
    border-bottom: 1px solid var(--line);
  }
  #reports-view .maint-toolbar {
    display: grid;
    grid-template-columns: minmax(220px, .7fr) minmax(0, 1.3fr);
    align-items: center;
    gap: 10px 14px;
    padding: 12px;
    margin-bottom: 12px;
  }
  #reports-view .maint-search-box {
    grid-column: 1;
    width: 100%;
    min-width: 0;
    flex: none;
  }
  #reports-view .maint-filter-chips {
    grid-column: 1 / -1;
    min-width: 0;
    gap: 6px;
  }
  #reports-view .maint-actions-right {
    grid-column: 2;
    grid-row: 1;
    justify-content: flex-end;
    flex-wrap: wrap;
    gap: 6px;
    margin-left: 0;
    min-width: 0;
  }
  #reports-view .maint-actions-right .head-btn {
    min-height: 34px;
    padding: 0 10px;
    white-space: nowrap;
  }
  #reports-view .maint-table-wrap {
    max-width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    overscroll-behavior-inline: contain;
    scrollbar-width: thin;
  }
  #reports-view .maint-desktop-table { min-width: 1050px; }
  #reports-view .maint-desktop-table .btn.btn-xs.btn-outline {
    display: inline-flex;
    min-height: 30px;
    align-items: center;
    justify-content: center;
    padding: 0 10px;
    border: 1px solid var(--line-2);
    border-radius: var(--ui-radius-control);
    background: var(--surface);
    color: var(--app-primary-color);
    font: 650 11px/1 var(--font-sans);
    white-space: nowrap;
    cursor: pointer;
    transition: background-color .15s ease, border-color .15s ease, color .15s ease;
  }
  #reports-view .maint-desktop-table .btn.btn-xs.btn-outline:hover {
    background: color-mix(in srgb, var(--app-primary-color) 8%, var(--surface));
    border-color: var(--app-primary-color);
  }
  #reports-view .fuel-info-chip,
  #reports-view .fuel-kpi-card,
  #reports-view .fuel-chart-section,
  #reports-view .fuel-events-section {
    color: var(--ink);
    background: var(--surface);
    border-color: var(--line);
    border-radius: var(--ui-radius-panel);
  }
  #reports-view .fuel-info-chip { padding: 8px 12px; }
  #reports-view .fuel-info-chip .fuel-badge {
    background: color-mix(in srgb, var(--app-primary-color) 12%, var(--surface));
    color: var(--app-primary-color);
  }
  #reports-view .fuel-kpi-card .kpi-icon { background: var(--bg-2); color: var(--muted); }
  #reports-view .fuel-kpi-card.highlight .kpi-icon { background: color-mix(in srgb, var(--app-primary-color) 12%, var(--surface)); color: var(--app-primary-color); }
  #reports-view .fuel-kpi-card.success .kpi-icon { background: color-mix(in srgb, var(--success) 12%, var(--surface)); }
  #reports-view .fuel-kpi-card.danger .kpi-icon { background: color-mix(in srgb, var(--danger) 12%, var(--surface)); }
  #reports-view .fuel-kpi-card .kpi-label,
  #reports-view .fuel-kpi-card .kpi-sub,
  #reports-view .fuel-legend { color: var(--muted); }
  #reports-view .fuel-kpi-card .kpi-val,
  #reports-view .fuel-section-header h3 { color: var(--ink); }
  #reports-view .fuel-bar-wrap { background: var(--line); }
}

@media (min-width: 769px) and (max-width: 1100px) {
  #reports-view .rv-workspace:has(.rv-results > #tab-recorrido.active) .rv-sidebar-content {
    grid-template-columns: minmax(170px, .8fr) minmax(300px, 1.8fr) minmax(140px, .7fr);
  }
  #reports-view .rv-workspace:has(.rv-results > #tab-recorrido.active) #rv-options { grid-column: 1; grid-row: 2; }
  #reports-view .rv-workspace:has(.rv-results > #tab-recorrido.active) #rv-generate { grid-column: 3; grid-row: 2; }
  #reports-view .rv-workspace:has(.rv-results > #tab-recorrido.active) .rv-export-section { grid-row: 3; }
  #reports-view .maint-toolbar { grid-template-columns: minmax(0, 1fr); }
  #reports-view .maint-search-box,
  #reports-view .maint-filter-chips,
  #reports-view .maint-actions-right {
    grid-column: 1;
    grid-row: auto;
  }
  #reports-view .maint-actions-right { justify-content: flex-start; }
}

/* Recorridos es una herramienta del mapa. Un solo panel, fuera del lienzo. */
body.report-route-mode #map-controls,
body.report-route-mode #zoom-controls,
body.report-route-mode #map-legend,
body.report-route-mode #btn-expand-panel,
body.report-route-mode #panel-map,
body.report-route-mode #map .vehicle-marker:not(.playback-vehicle-marker),
body.report-route-mode #mobile-dock #panel-open,
body.trip-focus-mode #map-controls,
body.trip-focus-mode #zoom-controls,
body.trip-focus-mode #map-legend,
body.trip-focus-mode #btn-expand-panel,
body.trip-focus-mode #panel-map,
body.trip-focus-mode #map .vehicle-marker:not(.playback-vehicle-marker),
body.trip-focus-mode #mobile-dock #panel-open { display: none !important; }
#route-explorer {
  order: -1;
  flex: 0 0 clamp(360px, 30vw, 440px);
  width: clamp(360px, 30vw, 440px);
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  color: var(--ink);
  border-right: 1px solid var(--border-subtle);
  z-index: 12;
}
#route-explorer .route-header {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 14px; border-bottom: 1px solid var(--border-subtle); flex-shrink: 0;
}
#route-explorer .route-header > div { min-width: 0; }
#route-explorer .route-eyebrow { font-size: 11px; color: var(--muted); }
#route-explorer h2 { margin: 3px 0 0; font-size: 14px; line-height: 1.4; overflow-wrap: anywhere; }
#route-panel-toggle { display: none; }
#route-explorer .route-mobile-toggle { place-items: center; width: 34px; height: 34px; flex: 0 0 auto; border: 1px solid var(--border-subtle); border-radius: 8px; background: var(--surface); color: var(--slate-600); cursor: pointer; }
#route-explorer .route-mobile-toggle:hover { border-color: var(--brand-300); color: var(--brand-600); }
#route-explorer .route-mobile-toggle svg { width: 15px; height: 15px; }
#route-close { display: grid; place-items: center; width: 34px; height: 34px; flex-shrink: 0; border: 1px solid var(--border-subtle); border-radius: 8px; background: var(--surface); color: var(--ink); cursor: pointer; }
#route-explorer svg { width: 16px; height: 16px; flex-shrink: 0; }
#route-explorer .route-body { display: flex; flex: 1 1 0; flex-direction: column; padding: 12px; overflow-y: auto !important; overflow-x: hidden; min-height: 0; overscroll-behavior: contain; scrollbar-width: auto; scrollbar-color: #70849b #e8eef5; }
#route-explorer .route-body::-webkit-scrollbar,
#route-explorer #points-table::-webkit-scrollbar { width: 12px; }
#route-explorer .route-body::-webkit-scrollbar-track,
#route-explorer #points-table::-webkit-scrollbar-track { border-radius: 999px; background: #e8eef5; }
#route-explorer .route-body::-webkit-scrollbar-thumb,
#route-explorer #points-table::-webkit-scrollbar-thumb { border: 2px solid #e8eef5; border-radius: 999px; background: #70849b; background-clip: padding-box; }
#route-explorer .route-body::-webkit-scrollbar-thumb:hover,
#route-explorer #points-table::-webkit-scrollbar-thumb:hover { background: #415a75; background-clip: padding-box; }
#route-query { flex: 0 0 auto; border-bottom: 1px solid var(--border-subtle); padding-bottom: 10px; }
#route-query > summary { display: flex; align-items: center; gap: 7px; cursor: pointer; list-style: none; font-size: 12px; font-weight: 700; min-height: 32px; }
#route-query > summary::-webkit-details-marker { display: none; }
#route-query > summary svg:last-child { margin-left: auto; }
#route-query[open] > summary svg:last-child { transform: rotate(180deg); }
#route-explorer .rv-sidebar { position: static; width: 100%; height: auto; max-height: none; overflow: visible; border: 0; border-radius: 0; box-shadow: none; }
#route-explorer .rv-sidebar-content { display: flex; flex-direction: column; gap: 10px; padding: 8px 0 0; }
#route-explorer .rv-section { gap: 5px; }
#route-explorer .rv-label { font-size: 10px; }
#route-explorer #rv-veh-search-box,
#route-explorer #rv-options,
#route-explorer .rv-export-section > .rv-label,
#route-explorer #exec-report-btn { display: none; }
#route-explorer .rv-select { width: 100%; min-width: 0; height: 36px; padding: 0 8px; font-size: 12px; }
#route-explorer .rv-range { display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; padding: 0; background: none; border: 0; }
#route-explorer .rv-range-field { display: grid; grid-template-columns: 40px minmax(0, 1fr); align-items: center; gap: 5px; }
#route-explorer .rv-range-field input { min-width: 0; width: 100%; height: 34px; padding: 4px 6px; font-size: 11px; box-sizing: border-box; }
#route-explorer .rv-period-presets > summary,
#route-explorer .rv-export-disclosure > summary { font-size: 11px; cursor: pointer; color: var(--muted); padding: 4px 0; }
#route-explorer #periods { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 5px; }
#route-explorer #periods button { min-height: 28px; padding: 4px 7px; font-size: 11px; }
#route-explorer #rv-generate { width: 100%; height: 36px; min-height: 36px; font-size: 12px; }
#route-explorer .rv-export-section { padding: 6px 0; margin: 0; }
#route-explorer #export-wrap { display: flex; flex-wrap: wrap; gap: 5px; }
#route-explorer #export-wrap button { font-size: 11px; padding: 6px; }
#route-status { flex: 0 0 auto; font-size: 11px; line-height: 1.5; color: var(--muted); margin: 10px 0; overflow-wrap: anywhere; }
#route-explorer #tab-recorrido { display: flex; flex-direction: column; gap: 12px; padding: 0; min-height: 0; }
#route-explorer #summary { order: -1; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; padding: 0; }
#route-explorer #summary.muted { display: block; font-size: 12px; }
#route-explorer .rv-stat { padding: 8px; border-radius: 8px; box-shadow: none; }
#route-explorer .rv-stat b { font-size: 16px; }
#route-explorer .rv-stat small { font-size: 9px; letter-spacing: 0; }
#route-explorer .rv-player {
  position: static; display: grid; grid-template-columns: 32px 32px 32px 32px 44px 32px 32px; justify-content: center;
  gap: 7px; width: 100%; padding: 10px 0; border: 0; border-top: 1px solid var(--border-subtle);
  border-bottom: 1px solid var(--border-subtle); border-radius: 0; box-shadow: none; background: none; transform: none; box-sizing: border-box;
}
#route-explorer .rv-player button { width: 32px; height: 32px; grid-row: 1; }
#route-explorer .rv-player button::after { display: none; }
#route-explorer #rp-prev { grid-column: 1; }
#route-explorer #play-btn { grid-column: 2; }
#route-explorer #rp-next { grid-column: 3; }
#route-explorer #stop-btn { grid-column: 4; }
#route-explorer #route-speed { grid-column: 5; grid-row: 1; align-self: center; box-sizing: border-box; min-width: 44px; width: 44px; max-width: 44px; min-height: 0 !important; height: 30px !important; margin: 0 !important; padding: 0 13px 0 4px; font-size: 10px; line-height: 1; text-align: left; text-align-last: left; border: 1px solid var(--border-subtle); border-radius: 6px; color: var(--ink); background-color: var(--surface); background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 4px center; background-size: 9px 9px; appearance: none; -webkit-appearance: none; }
#route-explorer #route-fit { grid-column: 6; }
#route-explorer #route-label-toggle { grid-column: 7; }
#route-explorer #route-label-toggle.active { color: var(--brand-600); border-color: var(--brand-600); background: color-mix(in srgb, var(--brand-600) 12%, var(--surface)); }
#route-explorer #rp-progress { grid-row: 2; grid-column: 1 / -1; width: calc(100% - 12px); margin: 10px 6px 4px; }
#route-explorer #playback-time { grid-row: 3; grid-column: 1 / 5; font-size: 10px; }
#route-explorer #playback-count { grid-row: 3; grid-column: 5 / -1; text-align: right; font-size: 10px; }
#route-explorer #rp-speeds { display: none; }
#route-explorer #tab-recorrido { flex: 1 1 auto; min-height: 300px; overflow: visible; }
#route-explorer .rv-points-card { display: flex; flex: 0 0 auto; flex-direction: column; min-height: 0; overflow: hidden; border-radius: 8px; box-shadow: none; }
#route-explorer .rv-points-head { padding: 10px 8px; font-size: 11px; cursor: pointer; }
#route-explorer .rv-points-card:not([open]) { flex: 0 0 auto; }
#route-explorer #points-table { display: block; flex: 0 0 300px; width: 100%; height: 300px; min-height: 300px; max-height: 300px; box-sizing: border-box; overflow-y: auto !important; overflow-x: hidden !important; scrollbar-width: auto; scrollbar-color: #70849b #e8eef5; scrollbar-gutter: stable; overscroll-behavior: contain; }
#route-explorer #points-table:focus-visible { outline: 2px solid var(--brand-600); outline-offset: -2px; }
#route-explorer #points-table table { width: 100%; min-width: 0; table-layout: fixed; }
#route-explorer #points-table th,
#route-explorer #points-table td { min-width: 0; padding: 7px 5px; white-space: normal; overflow-wrap: anywhere; }
#route-explorer #points-table th { font-size: 9px; }
#route-explorer #points-table .pt-col-point { width: 19%; }
#route-explorer #points-table .pt-col-location { width: 31%; }
#route-explorer #points-table .pt-col-motion { width: 21%; }
#route-explorer #points-table .pt-col-coords { width: 29%; }
#route-explorer #points-table .pt-addr { display: block; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#route-explorer #points-table .pt-state { display: flex; font-size: 9px; white-space: normal; overflow-wrap: anywhere; }
#route-explorer #points-table .pt-point,
#route-explorer #points-table .pt-motion,
#route-explorer #points-table .pt-coords { font-size: 10px; }
#route-explorer #points-table .pt-point small,
#route-explorer #points-table .pt-motion small,
#route-explorer #points-table .pt-coords span { display: block; margin-top: 3px; font-size: 9px; line-height: 1.25; color: var(--muted); overflow-wrap: anywhere; }
#route-explorer #points-table .pt-coords span { margin-top: 0; }
@media (max-width: 768px) {
  body.report-route-mode #map-area { flex-direction: column; min-height: 0; }
  body.report-route-mode #mobile-dock { display: none !important; }
  body.report-route-mode #map-wrap { flex: 1 1 auto; min-height: 150px; }
  body.report-route-mode #route-explorer {
    order: 1;
    box-sizing: border-box;
    flex: 0 1 52dvh;
    width: 100%;
    height: 52dvh;
    max-height: 62dvh;
    min-height: 230px;
    border: 0;
    border-top: 1px solid var(--border-subtle);
    border-radius: 14px 14px 0 0;
    box-shadow: 0 -8px 24px rgba(15, 23, 42, .08);
  }
  body.report-route-mode #route-explorer.route-panel-collapsed {
    flex: 0 0 auto;
    height: auto;
    min-height: 54px;
    max-height: 54px;
  }
  #route-explorer .route-header { min-height: 54px; box-sizing: border-box; padding: 7px 12px; }
  #route-explorer .route-header h2 { font-size: 13px; }
  #route-explorer .route-eyebrow { display: none; }
  #route-explorer .route-mobile-toggle { display: grid; }
  #route-explorer .route-body { flex: 1 1 0; padding: 7px 10px max(10px, env(safe-area-inset-bottom)); gap: 7px; }
  body.report-route-mode #route-explorer.route-panel-collapsed .route-body { display: none; }
  #route-explorer #route-query { padding-bottom: 5px; }
  #route-explorer #route-query > summary { min-height: 30px; font-size: 11px; }
  #route-explorer #route-query[open] .rv-sidebar-content { padding-bottom: 8px; }
  #route-explorer #route-status { margin: 3px 0; font-size: 10px; }
  #route-explorer #summary { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 4px; }
  #route-explorer .rv-stat { min-width: 0; padding: 5px 4px; }
  #route-explorer .rv-stat b { font-size: 11px; overflow-wrap: anywhere; }
  #route-explorer .rv-stat small { font-size: 7.5px; }
  #route-explorer #tab-recorrido { flex: 0 0 auto; min-height: 0; gap: 7px; overflow: visible; }
  #route-explorer .rv-player {
    position: static;
    display: grid;
    grid-template-columns: 30px 30px 30px 30px 44px 30px 30px;
    justify-content: center;
    gap: 4px;
    width: 100%;
    padding: 7px 0;
    border: 0;
    border-top: 1px solid var(--border-subtle);
    border-bottom: 1px solid var(--border-subtle);
    border-radius: 0;
    box-shadow: none;
    background: transparent;
    transform: none;
    box-sizing: border-box;
  }
  #route-explorer .rv-player button { grid-row: 1; width: 30px; height: 30px; }
  #route-explorer .rv-player button::after { display: none; }
  #route-explorer #rp-prev { grid-column: 1; }
  #route-explorer #play-btn { grid-column: 2; }
  #route-explorer #rp-next { grid-column: 3; }
  #route-explorer #stop-btn { grid-column: 4; }
  #route-explorer #route-speed { grid-column: 5; grid-row: 1; align-self: center; box-sizing: border-box; width: 44px; min-width: 44px; max-width: 44px; height: 30px !important; min-height: 30px !important; margin: 0 !important; padding: 0 13px 0 4px; font-size: 10px; text-align: left; text-align-last: left; }
  #route-explorer #route-fit { grid-column: 6; }
  #route-explorer #route-label-toggle { display: flex; grid-column: 7; }
  #route-explorer #rp-progress { grid-row: 2; grid-column: 1 / -1; width: calc(100% - 8px); margin: 8px 4px 3px; }
  #route-explorer #playback-time { grid-row: 3; grid-column: 1 / 5; font-size: 9px; }
  #route-explorer #playback-count { grid-row: 3; grid-column: 5 / -1; font-size: 9px; text-align: right; }
  #route-explorer #rp-speeds { display: none; }
  #route-explorer .rv-points-card { flex: 0 0 auto; border: 1px solid var(--border-subtle); border-radius: 9px; background: var(--surface); }
  #route-explorer .rv-points-head { min-height: 36px; box-sizing: border-box; padding: 7px 9px; }
  #route-explorer #points-table { flex: 0 0 220px; height: 220px; min-height: 220px; max-height: 220px; padding: 0 5px 5px; }
  #route-explorer #points-table table { min-width: 0; }
  #route-explorer #points-table th,
  #route-explorer #points-table td { padding: 6px 4px; }
  #route-explorer #points-table th { font-size: 8px; letter-spacing: .03em; }
  #route-explorer #points-table .pt-col-point { width: 20%; }
  #route-explorer #points-table .pt-col-location { width: 29%; }
  #route-explorer #points-table .pt-col-motion { width: 23%; }
  #route-explorer #points-table .pt-col-coords { width: 28%; }
  #route-explorer #points-table .pt-point,
  #route-explorer #points-table .pt-motion,
  #route-explorer #points-table .pt-coords { font-size: 9px; }
}
@media (max-width: 360px) {
  #route-explorer .route-header { gap: 6px; }
  #route-explorer .route-header h2 { max-width: calc(100vw - 130px); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  #route-explorer .rv-player { grid-template-columns: 28px 28px 28px 28px 42px 28px 28px; gap: 3px; }
  #route-explorer .rv-player button { width: 28px; height: 28px; }
  #route-explorer #route-speed { width: 42px; min-width: 42px; max-width: 42px; height: 28px !important; min-height: 28px !important; padding-right: 12px; font-size: 9px; }
  #route-explorer #summary { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}

/* Keep the persistent mobile navigation in its own surface so it never obscures page content. */
@media (max-width: 768px) {
  #mobile-dock {
    right: 0 !important;
    bottom: 0 !important;
    left: 0 !important;
    width: 100% !important;
    max-width: none !important;
    min-height: 62px;
    padding: 8px 12px calc(8px + env(safe-area-inset-bottom, 0px)) !important;
    transform: none !important;
    justify-content: center;
    border-top: 1px solid var(--line);
    background: var(--surface);
    box-shadow: 0 -4px 14px rgba(17, 39, 63, .08);
  }

  #mobile-dock #menu-toggle,
  #mobile-dock #subnav-toggle,
  #mobile-dock #panel-open { box-shadow: none; }

  .fs-order-filter-row { min-width: 0; box-sizing: border-box; }
  .fs-order-actions {
    display: grid !important;
    flex: 0 0 100%;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: 100%;
    min-width: 0;
    gap: 8px !important;
    box-sizing: border-box;
  }
  .fs-order-actions > button {
    width: 100% !important;
    min-width: 0;
    max-width: 100%;
    padding-right: 6px !important;
    padding-left: 6px !important;
    white-space: normal;
  }
}

/* At laptop widths, wrap administration tabs instead of cutting off the last action. */
@media (min-width: 769px) and (max-width: 1500px) {
  #admin-view .adm-nav { flex-wrap: wrap; overflow-x: visible; }
}

/* Alarmas: anclar el desplegable al encabezado y mantener legibles los ajustes en móvil. */
#topbar { position: relative; z-index: 1200; }
#top-actions { position: relative; }
#bell-pop { right: 0; }
#bell[aria-expanded="true"] { color: var(--app-primary-color); border-color: var(--app-primary-color); }
#bell-pop .bp-head { color: var(--text-sub, #475569); }
#bell-pop .bp-action-btn { color: var(--text-sub, #475569); }
#bell-pop-list:empty { min-height: 48px; }
#bell-pop .bp-empty {
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 54px;
  padding: 10px 12px;
  color: var(--text-sub, #475569);
  font-size: 13px;
  font-weight: 600;
}
#bell-pop .bp-empty svg { width: 17px; height: 17px; color: var(--muted); flex: 0 0 auto; }
.alarm-emails-sub, .alarm-whatsapp-sub, .ar-field { color: var(--text-sub, #475569); }
.alarm-head .ar-name { color: var(--ink); }
.ch-btn { color: var(--text-sub, #475569); }

@media (max-width: 768px) {
  #bell-pop {
    position: fixed;
    top: calc(var(--header-height) + env(safe-area-inset-top, 0px) + 8px);
    right: max(8px, env(safe-area-inset-right, 0px));
    width: min(360px, calc(100vw - 16px));
    max-width: none;
    max-height: calc(100dvh - var(--header-height) - 20px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
  }
  #bell-pop-list { min-height: 54px; overscroll-behavior: contain; }

  #form-modal { padding: max(8px, env(safe-area-inset-top, 0px)) 8px max(8px, env(safe-area-inset-bottom, 0px)); }
  #form-modal-box.wide {
    width: 100%;
    max-width: 560px;
    max-height: calc(100dvh - 16px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
    min-width: 0;
  }
  #form-modal-box.wide #form-modal-body {
    flex: 1 1 auto;
    min-height: 0;
    max-height: none;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 12px;
  }
  #form-modal-head { padding: 12px 14px; }
  #form-modal-actions {
    flex: 0 0 auto;
    padding: 10px 12px max(10px, env(safe-area-inset-bottom, 0px));
  }
  #form-modal-box.wide .alarm-row { padding: 10px; }
  #form-modal-box.wide .alarm-head {
    display: grid;
    grid-template-columns: 20px minmax(0, 1fr);
    align-items: center;
    gap: 8px;
  }
  #form-modal-box.wide .alarm-head .ar-name {
    min-width: 0;
    overflow: visible;
    white-space: normal;
    overflow-wrap: anywhere;
    font-size: 13px;
    line-height: 1.3;
  }
  #form-modal-box.wide .seg-channels {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: 100%;
    gap: 6px;
  }
  #form-modal-box.wide .ch-btn {
    width: 100%;
    min-width: 0;
    min-height: 38px;
    justify-content: center;
    padding: 6px 5px;
    color: var(--text-sub, #475569);
    font-size: 11px;
  }
  #form-modal-box.wide .ch-btn.active { color: #fff; }
  #form-modal-box.wide .ar-extra { padding-left: 0; }
  #form-modal-box.wide .ar-field { font-size: 10.5px; line-height: 1.35; }
  #form-modal-box.wide .ar-field input[type="number"],
  #form-modal-box.wide .ar-field input[type="time"] { width: min(42vw, 150px); min-height: 38px; }
  #form-modal-box.wide .ar-days { flex-wrap: wrap; }
  #form-modal-box.wide .ar-times { flex-wrap: wrap; }
}

@media (max-width: 380px) {
  #form-modal-box.wide #form-modal-body { padding: 10px; }
  #form-modal-box.wide .alarm-row { padding: 9px; }
  #form-modal-box.wide .alarm-head { gap: 6px; }
  #form-modal-box.wide .ch-btn { font-size: 10.5px; }
}

/* Escritorio: agrupa los controles del mapa para liberar altura del mapa. */
@media (min-width: 1024px) {
  #map-controls {
    display: grid;
    grid-template-columns: repeat(2, 40px);
    grid-auto-rows: 40px;
    gap: 8px;
    align-items: center;
    justify-content: center;
  }

  #map-controls > button,
  #map-controls #basemap-toggle {
    position: relative;
    width: 40px;
    min-width: 40px;
    height: 40px;
    justify-content: center;
    overflow: visible;
  }

  #map-controls > button svg,
  #map-controls #basemap-toggle svg {
    margin: 0;
  }

  #map-controls > button > span,
  #map-controls #basemap-toggle > span {
    position: absolute;
    z-index: 1100;
    top: 50%;
    right: calc(100% + 8px);
    max-width: 180px;
    margin: 0;
    padding: 6px 9px;
    transform: translateY(-50%);
    border: 1px solid var(--line-2);
    border-radius: 8px;
    background: var(--surface);
    color: var(--ink);
    box-shadow: var(--shadow-card);
    pointer-events: none;
    transition: opacity .15s ease;
  }

  #map-controls > button:hover > span,
  #map-controls > button:focus-visible > span,
  #map-controls #basemap-toggle:hover > span,
  #map-controls #basemap-toggle:focus-visible > span {
    opacity: 1;
  }
}
