/*
 * Hoja de estilos principal de la aplicación.
 *
 * Reúne layout, componentes, formularios, mapa, ayudas y variantes
 * de tema claro / oscuro para toda la interfaz.
 *
 * Aviso de autoría:
 * Diseño y propiedad intelectual del Dr. Sergio Velasquez.
 */
:root {
  --avante-teal: #0076a3;
  --avante-red: #c1272d;
  --avante-gray: #808285;
  --bg: #f4f7f9;
  --card: #ffffff;
  --text: #1a1d21;
  --border: #dde3ea;
  --radius: 10px;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.06);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, Cantarell, "Noto Sans", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

a {
  color: var(--avante-teal);
}

.topbar {
  background: linear-gradient(90deg, #005f87 0%, var(--avante-teal) 55%, #0090c5 100%);
  color: #fff;
  box-shadow: var(--shadow);
}

/* ---- Topbar: dos filas (brand+acciones / nav) ---- */
.topbar-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0;
  display: flex;
  flex-direction: column;
}

/* Fila 1 */
.topbar-row1 {
  display: flex;
  align-items: center;
  padding: 0.65rem 1.25rem 0.55rem;
  gap: 0.75rem;
  min-width: 0;
}

/* Fila 2 */
.topbar-row2 {
  padding: 0 0.85rem 0.45rem;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  text-decoration: none;
  color: inherit;
  min-width: 0;
  flex-shrink: 0;
}

.brand img {
  height: 40px;
  width: auto;
  display: block;
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
  min-width: 0;
}

.brand-text strong {
  font-size: 1.05rem;
  letter-spacing: 0.04em;
}

.brand-text span {
  font-size: 0.68rem;
  opacity: 0.9;
  letter-spacing: 0.1em;
  color: rgba(255, 255, 255, 0.85);
  white-space: nowrap;
}

.topbar-end {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 0.45rem;
  flex-shrink: 0;
}

.topbar-end--solo {
  flex-shrink: 0;
}

.topbar-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.18rem 0.18rem;
  align-items: center;
  padding: 0;
}

.topbar-nav a {
  color: rgba(255, 255, 255, 0.88);
  text-decoration: none;
  padding: 0.32rem 0.7rem;
  border-radius: 6px;
  font-size: 0.84rem;
  font-weight: 500;
  letter-spacing: 0.01em;
  transition: background 0.15s ease, color 0.15s ease;
}

.topbar-nav a:hover {
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
}

.topbar-nav a.active {
  background: rgba(255, 255, 255, 0.18);
  color: #fff;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.2);
}

/* ---- compact (login) ---- */
.topbar--compact .topbar-inner {
  flex-direction: row;
  align-items: center;
  padding: 0.65rem 1.25rem;
  gap: 0.75rem;
}

.topbar--compact .topbar-end {
  margin-left: auto;
}

/* ---- dark-mode topbar rows ---- */
html[data-theme="dark"] .topbar-row2 {
  border-top-color: rgba(255, 255, 255, 0.07);
}

main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.25rem;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.1rem 1.25rem;
  margin-bottom: 1rem;
}

/* ----- Formulario vehículo (compacto) ----- */
.card.vehicle-form-card {
  padding: 1rem 1.1rem 1rem;
}

.vehicle-form-title {
  margin: 0 0 0.85rem;
  font-size: 1.35rem;
  letter-spacing: -0.02em;
}

.vehicle-form .form-section {
  margin: 0 0 0.85rem;
  padding: 0.65rem 0.75rem;
  background: #fafcfd;
  border: 1px solid #e8eef4;
  border-radius: 8px;
}

.vehicle-form .form-section--last {
  margin-bottom: 0.65rem;
}

.vehicle-form .form-section-title {
  margin: 0 0 0.55rem;
  padding: 0;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--avante-gray);
  border: none;
}

.vehicle-form .form-section-hint {
  font-weight: 500;
  text-transform: none;
  letter-spacing: 0;
  color: var(--avante-gray);
  font-size: 0.68rem;
}

.vehicle-form .form-grid {
  display: grid;
  gap: 0.45rem 0.65rem;
}

.vehicle-form .form-grid--4 {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.vehicle-form .field-span-2 {
  grid-column: span 2;
}

.vehicle-form .field-span-3 {
  grid-column: span 3;
}

.vehicle-form .field-span-4 {
  grid-column: 1 / -1;
}

@media (max-width: 960px) {
  .vehicle-form .form-grid--4 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .vehicle-form .field-span-3 {
    grid-column: span 2;
  }
}

@media (max-width: 520px) {
  .vehicle-form .form-grid--4 {
    grid-template-columns: 1fr;
  }

  .vehicle-form .field-span-2,
  .vehicle-form .field-span-3 {
    grid-column: span 1;
  }
}

.vehicle-form label {
  font-size: 0.76rem;
  margin-bottom: 0.12rem;
  color: #3d4450;
}

.vehicle-form input[type="text"],
.vehicle-form input[type="number"],
.vehicle-form input[type="email"],
.vehicle-form input[type="date"],
.vehicle-form select,
.vehicle-form textarea {
  padding: 0.36rem 0.5rem;
  font-size: 0.9rem;
  border-radius: 5px;
}

.vehicle-form .textarea-compact {
  min-height: 52px;
  line-height: 1.35;
}

.vehicle-form .form-hint-inline {
  display: flex;
  align-items: flex-end;
  font-size: 0.78rem;
  line-height: 1.35;
  padding-bottom: 0.15rem;
}

.vehicle-form .checkbox-row {
  display: flex;
  align-items: flex-start;
  gap: 0.45rem;
  margin: 0.5rem 0 0;
  font-size: 0.82rem;
  color: #444;
  cursor: pointer;
}

.vehicle-form .checkbox-row input {
  margin-top: 0.2rem;
  flex-shrink: 0;
}

.vehicle-form-footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.65rem 1rem;
  margin-top: 0.35rem;
  padding-top: 0.65rem;
  border-top: 1px solid var(--border);
}

.vehicle-form-footer-start {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 0.65rem;
  align-items: center;
}

.vehicle-form-footer-delete {
  margin: 0 0 0 auto;
  display: flex;
  align-items: center;
}

.vehicle-form-footer-delete .btn-danger {
  white-space: nowrap;
}

.card h1,
.card h2 {
  margin-top: 0;
  color: var(--avante-teal);
  font-weight: 650;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

@media (max-width: 900px) {
  .grid-2 {
    grid-template-columns: 1fr;
  }
}

label {
  display: block;
  font-size: 0.85rem;
  color: #444;
  margin-bottom: 0.2rem;
}

input[type="text"],
input[type="number"],
input[type="email"],
input[type="date"],
input[type="file"],
textarea,
select {
  width: 100%;
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font: inherit;
}

textarea {
  min-height: 72px;
  resize: vertical;
}

.row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.btn {
  display: inline-block;
  padding: 0.45rem 0.9rem;
  border-radius: 6px;
  border: none;
  cursor: pointer;
  font: inherit;
  text-decoration: none;
}

.btn-primary {
  background: var(--avante-teal);
  color: #fff;
}

.btn-primary:hover {
  filter: brightness(1.05);
}

.btn-danger {
  background: var(--avante-red);
  color: #fff;
}

.btn-ghost {
  background: #eef3f7;
  color: var(--text);
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

th,
td {
  border-bottom: 1px solid var(--border);
  padding: 0.45rem 0.35rem;
  text-align: left;
}

th {
  color: var(--avante-gray);
  font-weight: 600;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.badge {
  display: inline-block;
  padding: 0.12rem 0.45rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
}

.badge-warn {
  background: #fff3cd;
  color: #856404;
}

.badge-ok {
  background: #d4edda;
  color: #155724;
}

.badge-bad {
  background: #f8d7da;
  color: #721c24;
}

.plan-rule-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 0.22rem 0.32rem;
  align-items: center;
  max-width: 28rem;
}

.badge-rule-abbr {
  font-size: 0.62rem;
  font-weight: 750;
  letter-spacing: 0.04em;
  padding: 0.06rem 0.3rem;
  line-height: 1.15;
  cursor: help;
  white-space: nowrap;
}

/* ----- Mapa + filtros ------------------------------------------------- */
.map-card {
  padding: 0;
  overflow: hidden;
}

.map-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 0.75rem 1.25rem;
  padding: 1rem 1.25rem 0.85rem;
}

.map-header__title {
  flex: 1 1 200px;
}

.map-header__title h1 {
  margin: 0 0 0.15rem;
}

.map-header__title p {
  margin: 0;
}

.map-drag-help {
  margin-top: 0.35rem;
  font-size: 0.83rem;
}

.map-type-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  align-items: center;
  flex: 9999 1 auto;
  justify-content: flex-end;
}

.map-type-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.38rem 0.75rem 0.38rem 0.55rem;
  border-radius: 999px;
  border: 2px solid color-mix(in srgb, var(--btn-stroke) 60%, transparent);
  background: color-mix(in srgb, var(--btn-fill) 10%, var(--card));
  color: var(--text);
  font: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition:
    background 0.17s ease,
    opacity 0.2s ease,
    transform 0.12s ease;
  user-select: none;
}

.map-type-btn:hover {
  background: color-mix(in srgb, var(--btn-fill) 18%, var(--card));
}

.map-type-btn:active {
  transform: scale(0.97);
}

/* estado: activo */
.map-type-btn--active {
  background: color-mix(in srgb, var(--btn-fill) 14%, var(--card));
  border-color: var(--btn-stroke);
}

/* estado: inactivo (oculto) */
.map-type-btn:not(.map-type-btn--active) {
  opacity: 0.42;
  background: transparent;
  border-style: dashed;
}

.map-type-btn__dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--btn-fill);
  border: 2px solid var(--btn-stroke);
  flex-shrink: 0;
}

.map-type-btn__label {
  line-height: 1;
}

.map-type-btn__count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.35rem;
  height: 1.35rem;
  padding: 0 0.3rem;
  border-radius: 999px;
  background: color-mix(in srgb, var(--btn-fill) 22%, var(--card));
  border: 1px solid color-mix(in srgb, var(--btn-stroke) 40%, transparent);
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--btn-stroke);
  line-height: 1;
}

/* badge tipo en tabla */
.type-badge {
  display: inline-block;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  background: color-mix(in srgb, var(--badge-fill) 15%, transparent);
  color: var(--badge-fill);
  border: 1px solid color-mix(in srgb, var(--badge-fill) 40%, transparent);
  white-space: nowrap;
}

/* Indicador activo (semáforo) — usuarios */
.user-status {
  display: inline-flex;
  align-items: center;
  gap: 0.28rem;
  padding: 0.18rem 0.32rem;
  border-radius: 999px;
  border: 1px solid rgba(0, 0, 0, 0.08);
  background: linear-gradient(180deg, #f9fbfd 0%, #edf3f7 100%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.7);
  vertical-align: middle;
}

.user-status__lamp {
  display: block;
  width: 0.55rem;
  height: 0.55rem;
  border-radius: 50%;
  background: #c9d3dd;
  box-shadow: inset 0 1px 1px rgba(255, 255, 255, 0.35);
}

.user-status__lamp--red {
  background: #d9a6a9;
}

.user-status__lamp--green {
  background: #a9d5b5;
}

.user-status--on .user-status__lamp--green {
  background: radial-gradient(circle at 35% 35%, #6de28f 0%, #1e8e3e 62%, #166c2f 100%);
  box-shadow:
    0 0 0 1px rgba(20, 108, 47, 0.12),
    0 0 8px rgba(30, 142, 62, 0.28);
}

.user-status--on .user-status__lamp--red {
  opacity: 0.28;
}

.user-status--off .user-status__lamp--red {
  background: radial-gradient(circle at 35% 35%, #ff8a8f 0%, #c1272d 60%, #8f1d22 100%);
  box-shadow:
    0 0 0 1px rgba(143, 29, 34, 0.12),
    0 0 8px rgba(193, 39, 45, 0.24);
}

.user-status--off .user-status__lamp--green {
  opacity: 0.28;
}

/* link de posición en tabla */
.map-focus-link {
  font-family: 'Menlo', 'Consolas', monospace;
  font-size: 0.8rem;
  color: var(--avante-teal);
}

.map-focus-link:hover {
  text-decoration: underline;
}

#map {
  width: 100%;
  min-height: 480px;
  height: 480px;
  background: #e8eef2;
  z-index: 0;
  border-top: 1px solid var(--border);
}

/* Leaflet */
.leaflet-container {
  font-family: inherit;
}

/* ----- Modo oscuro: mapa y filtros ----- */
html[data-theme="dark"] #map {
  background: #141920;
  border-color: var(--border);
}

html[data-theme="dark"] .map-type-btn--active {
  background: color-mix(in srgb, var(--btn-fill) 22%, var(--card));
}

html[data-theme="dark"] .map-type-btn:hover {
  background: color-mix(in srgb, var(--btn-fill) 28%, var(--card));
}

html[data-theme="dark"] .type-badge {
  background: color-mix(in srgb, var(--badge-fill) 18%, transparent);
}

@media (max-width: 680px) {
  .map-type-filters {
    justify-content: flex-start;
  }

  .map-type-btn__label {
    display: none;
  }
}

.flash {
  padding: 0.65rem 0.85rem;
  border-radius: 8px;
  margin-bottom: 1rem;
}

main > .flash:first-child {
  display: flex;
  align-items: flex-start;
  gap: 0.55rem;
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  font-weight: 500;
}

main > .flash:first-child::before {
  content: '';
  width: 1.35rem;
  height: 1.35rem;
  flex-shrink: 0;
  margin-top: 0.06rem;
  border-radius: 50%;
  background-repeat: no-repeat;
  background-position: center;
  background-size: 0.85rem;
}

main > .flash-ok:first-child::before {
  background-color: rgba(21, 87, 36, 0.15);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23155724' stroke-width='2.5'%3E%3Cpath d='M20 6L9 17l-5-5'/%3E%3C/svg%3E");
}

main > .flash-err:first-child::before {
  background-color: rgba(114, 28, 36, 0.12);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23721c24' stroke-width='2'%3E%3Ccircle cx='12' cy='12' r='10'/%3E%3Cpath d='M12 8v4M12 16h.01'/%3E%3C/svg%3E");
}

.flash-ok {
  background: #d4edda;
  color: #155724;
  border: 1px solid #c3e6cb;
}

.flash-err {
  background: #f8d7da;
  color: #721c24;
  border: 1px solid #f5c6cb;
}

.muted {
  color: var(--avante-gray);
  font-size: 0.88rem;
}

.alert-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 1.25rem;
  align-items: center;
}

.alert-stat {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  min-width: 120px;
}

.alert-stat strong {
  font-size: 1.35rem;
  color: var(--avante-teal);
}

.alert-vehicle-card h3.alert-sub {
  margin: 0.85rem 0 0.35rem;
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--avante-gray);
}

.alert-vehicle-head {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.75rem;
}

ul.alert-list {
  margin: 0;
  padding-left: 1.1rem;
}

ul.alert-list li {
  margin-bottom: 0.35rem;
}

footer {
  max-width: 1200px;
  margin: 2rem auto 1rem;
  padding: 0 1.25rem;
  font-size: 0.82rem;
  color: var(--avante-gray);
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 0.65rem;
}

.kpi-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.7rem 0.85rem;
  background: linear-gradient(135deg, #fafcfd 0%, #f0f5f8 100%);
  border-left: 3px solid var(--avante-teal);
  transition: transform 0.15s, box-shadow 0.15s;
}
.kpi-card:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0,118,163,0.08);
}
.kpi-card--red { border-left-color: var(--avante-red); }
.kpi-card--red .kpi-value { color: var(--avante-red); }
.kpi-card--amber { border-left-color: #e07b00; }
.kpi-card--amber .kpi-value { color: #c06800; }
.kpi-card--green { border-left-color: #0f7c3a; }
.kpi-card--green .kpi-value { color: #0f7c3a; }

.kpi-label {
  display: block;
  font-size: 0.76rem;
  color: var(--avante-gray);
  line-height: 1.25;
  margin-bottom: 0.3rem;
  letter-spacing: 0.01em;
}

.kpi-value {
  font-size: 1.2rem;
  color: var(--avante-teal);
  font-weight: 700;
  letter-spacing: -0.01em;
}

.chart-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 1.25rem;
  margin-top: 0.75rem;
}

.chart-block-title {
  margin: 0 0 0.5rem;
  font-size: 0.95rem;
  color: var(--text);
  font-weight: 600;
}

.chart-canvas-wrap {
  position: relative;
  height: 260px;
  max-width: 100%;
}

.btn-chart-png {
  font-size: 0.85rem;
}

.historial-pdf-toolbar {
  margin: 0 0 0.75rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem 0.75rem;
}

.historial-pdf-toolbar-hint {
  flex: 1 1 220px;
  font-size: 0.82rem;
  margin: 0;
  min-width: 12rem;
}

.historial-preview-modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 10000;
  align-items: center;
  justify-content: center;
  padding: 0.75rem;
}

.historial-preview-modal.historial-preview-modal--open {
  display: flex;
}

.historial-preview-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(26, 29, 33, 0.48);
}

.historial-preview-dialog {
  position: relative;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.2);
  border: 1px solid var(--border);
  max-width: min(920px, 96vw);
  width: 100%;
  max-height: min(92vh, 920px);
  min-height: 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  z-index: 1;
}

.historial-preview-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 0.9rem 1rem 0.5rem;
  border-bottom: 1px solid var(--border);
}

.historial-preview-header h2 {
  margin: 0;
  font-size: 1.12rem;
  color: var(--avante-teal);
}

.historial-preview-hint {
  margin: 0;
  padding: 0.45rem 1rem 0.65rem;
  font-size: 0.82rem;
}

.historial-preview-scroll {
  flex: 1;
  min-height: 180px;
  min-width: 0;
  max-height: calc(92vh - 240px);
  overflow: auto;
  overflow-x: hidden;
  padding: 0.6rem 0.65rem 1rem;
  background: var(--bg);
  display: block;
  width: 100%;
  box-sizing: border-box;
  -webkit-overflow-scrolling: touch;
}

.historial-preview-footer {
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--border);
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: flex-end;
}

#historial-pdf-root {
  background: #fff;
}

/* Ancho fijo ~A4 solo en la página (el nodo con #historial-pdf-root al generar PDF) */
#historial-pdf-root.historial-pdf-export-layout {
  width: 794px !important;
  max-width: 794px !important;
  margin-left: auto !important;
  margin-right: auto !important;
  box-sizing: border-box;
  padding-left: 14px !important;
  padding-right: 14px !important;
}

/* Mismo layout de informe con o sin id (vista previa = clon sin id) */
.historial-pdf-export-layout .historial-pdf-inner-card {
  width: 100% !important;
  max-width: none !important;
  box-shadow: none !important;
}

.historial-pdf-export-layout .kpi-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
}

.historial-pdf-export-layout .chart-grid {
  grid-template-columns: 1fr !important;
  max-width: none !important;
}

.historial-pdf-export-layout .chart-canvas-wrap {
  max-width: none !important;
  height: 240px !important;
}

.historial-pdf-export-layout .table-wrap {
  overflow: visible !important;
  max-width: none !important;
}

.historial-pdf-export-layout .historial-pdf-table {
  width: 100% !important;
  table-layout: fixed;
}

.historial-pdf-export-layout .historial-pdf-table th,
.historial-pdf-export-layout .historial-pdf-table td {
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.historial-pdf-chart-snapshot {
  image-rendering: auto;
}

.historial-pdf-export-layout .historial-pdf-chart-snapshot {
  width: 100% !important;
  max-width: 100% !important;
  height: auto !important;
}

/* Vista previa modal: contenido fluido al ancho disponible (evita columna estrecha o desborde) */
.historial-preview-scroll .historial-pdf-export-layout {
  width: 100% !important;
  max-width: 100% !important;
  min-width: 0 !important;
  margin-left: 0 !important;
  margin-right: 0 !important;
  padding-left: 10px !important;
  padding-right: 10px !important;
}

.historial-preview-scroll .historial-pdf-export-layout .historial-pdf-letterhead-meta,
.historial-preview-scroll .historial-pdf-export-layout .historial-pdf-letterhead-brand {
  word-break: break-word;
}

.historial-preview-scroll .historial-pdf-export-layout .kpi-grid {
  grid-template-columns: repeat(auto-fit, minmax(min(11rem, 100%), 1fr)) !important;
}

@media (min-width: 640px) {
  .historial-preview-scroll .historial-pdf-export-layout .kpi-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
  }
}

.historial-preview-scroll .historial-pdf-export-layout .chart-canvas-wrap {
  height: min(240px, 42vw) !important;
  max-height: 280px;
}

/* Legacy letterhead — kept for backward compat */
.historial-pdf-letterhead { display: none; }

.historial-pdf-inner-card {
  margin-bottom: 0.65rem;
  padding: 0.85rem 1rem;
}

.historial-pdf-inner-card:last-child {
  margin-bottom: 0;
}

.historial-pdf-table {
  font-size: 0.82rem;
}

.historial-pdf-table th,
.historial-pdf-table td {
  padding: 0.35rem 0.3rem;
}

/* Modal opciones PDF (papel / márgenes) */
.historial-pdf-options-modal {
  z-index: 10001;
}

.historial-pdf-options-dialog {
  max-width: min(440px, 96vw);
  max-height: min(88vh, 640px);
}

.historial-pdf-options-intro {
  margin: 0;
  padding: 0 1rem 0.65rem;
  font-size: 0.82rem;
  line-height: 1.45;
}

.historial-pdf-options-form {
  padding: 0 1rem 1rem;
  display: grid;
  gap: 0.85rem;
}

.historial-pdf-options-row {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.historial-pdf-options-row label {
  font-size: 0.86rem;
  font-weight: 600;
  color: var(--text);
}

.historial-pdf-options-row select {
  font: inherit;
  font-size: 0.92rem;
  padding: 0.45rem 0.55rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  max-width: 100%;
}

.historial-pdf-options-footer {
  flex-wrap: wrap;
}

/* ----- Barra superior: tema, usuario y sesión ----- */
.topbar-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.45rem 0.55rem;
}

.topbar-actions__divider {
  display: inline-block;
  width: 1px;
  height: 1.35rem;
  background: rgba(255, 255, 255, 0.2);
  flex-shrink: 0;
}

.topbar-user-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  max-width: min(15rem, 38vw);
  padding: 0.15rem 0.55rem 0.15rem 0.15rem;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.14);
  border: 1px solid rgba(255, 255, 255, 0.14);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}

.topbar-user-chip__avatar {
  width: 1.75rem;
  height: 1.75rem;
  border-radius: 50%;
  background: linear-gradient(145deg, rgba(255, 255, 255, 0.28), rgba(255, 255, 255, 0.08));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.02em;
  color: #fff;
  flex-shrink: 0;
}

.topbar-user-chip__name {
  font-size: 0.78rem;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.96);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar-logout-form {
  display: flex;
  margin: 0;
}

.topbar-pill-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.4rem 0.9rem 0.4rem 0.65rem;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  background: rgba(0, 0, 0, 0.12);
  color: #fff;
  font: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
  transition:
    background 0.18s ease,
    border-color 0.18s ease,
    transform 0.12s ease,
    box-shadow 0.18s ease;
}

.topbar-pill-btn:hover {
  background: rgba(255, 255, 255, 0.14);
  border-color: rgba(255, 255, 255, 0.35);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
}

.topbar-pill-btn:active {
  transform: scale(0.98);
}

.topbar-pill-btn__icons {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 1.35rem;
  height: 1.35rem;
  flex-shrink: 0;
}

.topbar-pill-btn .tb-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.topbar-pill-btn .tb-icon--sun {
  display: none;
}

.topbar-pill-btn.is-dark-mode .tb-icon--moon {
  display: none;
}

.topbar-pill-btn.is-dark-mode .tb-icon--sun {
  display: block;
}

.topbar-pill-btn--theme .tb-icon {
  stroke: currentColor;
  fill: none;
}

.topbar-pill-btn--logout {
  border-color: rgba(255, 200, 200, 0.28);
  background: rgba(193, 39, 45, 0.28);
}

.topbar-pill-btn--logout:hover {
  background: rgba(193, 39, 45, 0.42);
  border-color: rgba(255, 210, 210, 0.45);
}

.topbar-pill-btn--logout .tb-icon {
  stroke: currentColor;
  fill: none;
}

.btn-sm {
  padding: 0.28rem 0.55rem;
  font-size: 0.82rem;
}

.topbar--compact .topbar-inner {
  justify-content: space-between;
}

@media (max-width: 720px) {
  .topbar-user-chip__name {
    max-width: 6.5rem;
  }

  .topbar-pill-btn__text {
    display: none;
  }

  .topbar-pill-btn {
    padding: 0.45rem;
  }

  .topbar-pill-btn__icons {
    width: 1.5rem;
    height: 1.5rem;
  }
}

/* ----- Banner modo sin login obligatorio ----- */
.auth-relaxed-wrap {
  background: rgba(255, 193, 7, 0.12);
  border-bottom: 1px solid rgba(180, 140, 0, 0.22);
}

.auth-relaxed-banner {
  max-width: 1200px;
  margin: 0 auto;
  box-sizing: border-box;
}

.flash-warn {
  background: #fff3cd;
  color: #856404;
  border: 1px solid #ffeeba;
}

/* ----- Pantalla de ingreso ----- */
.login-body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  margin: 0;
  background: var(--bg);
}

.login-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  box-sizing: border-box;
}

.login-shell {
  width: 100%;
  max-width: 420px;
}

.login-card {
  margin: 0 auto;
}

.login-title {
  margin-top: 0;
}

.login-lead {
  margin: 0 0 1rem;
}

.login-form .login-actions {
  margin-top: 0.25rem;
}

.login-footer {
  text-align: center;
  padding: 1rem 1.25rem 1.35rem;
}

.login-relaxed {
  margin-bottom: 1rem;
}

.login-seed-hint {
  margin: 1rem 0 0;
  font-size: 0.8rem;
}

.login-seed-hint code {
  font-size: 0.78rem;
}

/* ----- Modo oscuro ----- */
html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f1216;
  --card: #181c22;
  --text: #e6e9ee;
  --border: #2c323c;
  --shadow: 0 8px 28px rgba(0, 0, 0, 0.35);
}

html[data-theme="dark"] .topbar {
  background: linear-gradient(90deg, #003d57 0%, #004d6e 55%, #006286 100%);
}

html[data-theme="dark"] .flash-ok {
  background: #1e3d2a;
  color: #b8e6c8;
  border-color: #2d5a40;
}

html[data-theme="dark"] .flash-err {
  background: #3d2226;
  color: #f0c2c8;
  border-color: #5c3038;
}

html[data-theme="dark"] .flash-warn {
  background: #3d3420;
  color: #f0e0a8;
  border-color: #5c4f28;
}

html[data-theme="dark"] .auth-relaxed-wrap {
  background: rgba(255, 193, 7, 0.07);
  border-bottom-color: rgba(255, 200, 80, 0.18);
}

html[data-theme="dark"] .vehicle-form .form-section {
  background: #1e232b;
  border-color: var(--border);
}

html[data-theme="dark"] .vehicle-form label {
  color: #b4bac6;
}

html[data-theme="dark"] label {
  color: #c8ced8;
}

html[data-theme="dark"] .btn-ghost {
  background: #2a303a;
  color: var(--text);
}

html[data-theme="dark"] .btn-ghost:hover {
  background: #353b48;
}

html[data-theme="dark"] main > .flash-ok:first-child::before {
  background-color: rgba(88, 200, 120, 0.18);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23b8e6c8' stroke-width='2.5'%3E%3Cpath d='M20 6L9 17l-5-5'/%3E%3C/svg%3E");
}

html[data-theme="dark"] main > .flash-err:first-child::before {
  background-color: rgba(240, 130, 140, 0.12);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23f0c2c8' stroke-width='2'%3E%3Ccircle cx='12' cy='12' r='10'/%3E%3Cpath d='M12 8v4M12 16h.01'/%3E%3C/svg%3E");
}

html[data-theme="dark"] #map {
  background: #141920;
  border-color: var(--border);
}

html[data-theme="dark"] .card h1,
html[data-theme="dark"] .card h2 {
  color: #5bc0eb;
}

html[data-theme="dark"] a {
  color: #7dcdf0;
}

html[data-theme="dark"] th {
  color: #9aa3b0;
}

html[data-theme="dark"] input[type="text"],
html[data-theme="dark"] input[type="number"],
html[data-theme="dark"] input[type="email"],
html[data-theme="dark"] input[type="date"],
html[data-theme="dark"] input[type="file"],
html[data-theme="dark"] input[type="password"],
html[data-theme="dark"] textarea,
html[data-theme="dark"] select {
  background: #12161c;
  color: var(--text);
  border-color: var(--border);
}

/* ================================================================
   AYUDA / HELP
   ================================================================ */
.help-page {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

/* Hero */
.help-hero {
  display: flex;
  align-items: flex-start;
  gap: 1.1rem;
  padding: 1.25rem 1.4rem;
}

.help-hero__icon {
  flex-shrink: 0;
  width: 3rem;
  height: 3rem;
  border-radius: 50%;
  background: linear-gradient(135deg, #e6f4fb 0%, #c8e9f7 100%);
  display: flex;
  align-items: center;
  justify-content: center;
}

.help-hero__icon svg {
  width: 1.55rem;
  height: 1.55rem;
  stroke: var(--avante-teal);
}

.help-hero__title {
  margin: 0 0 0.25rem;
  font-size: 1.3rem;
  color: var(--avante-teal);
}

.help-hero__lead {
  margin: 0;
}

/* Índice rápido */
.help-toc {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 0.65rem;
  padding: 0.85rem 1rem;
}

.help-toc__item {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.3rem 0.7rem 0.3rem 0.5rem;
  border-radius: 999px;
  border: 1.5px solid color-mix(in srgb, var(--toc-color) 35%, transparent);
  background: color-mix(in srgb, var(--toc-color) 8%, var(--card));
  color: var(--toc-color);
  text-decoration: none;
  font-size: 0.8rem;
  font-weight: 600;
  transition: background 0.15s ease, transform 0.1s ease;
}

.help-toc__item:hover {
  background: color-mix(in srgb, var(--toc-color) 15%, var(--card));
  transform: translateY(-1px);
}

.help-toc__icon svg {
  width: 14px;
  height: 14px;
  stroke: currentColor;
  fill: none;
  flex-shrink: 0;
}

/* Secciones <details> */
.help-section {
  padding: 0;
  overflow: hidden;
}

.help-section__summary {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.9rem 1.1rem;
  cursor: pointer;
  list-style: none;
  user-select: none;
  border-left: 4px solid var(--sec-color);
  background: color-mix(in srgb, var(--sec-color) 5%, var(--card));
  transition: background 0.15s ease;
}

.help-section__summary::-webkit-details-marker { display: none; }

.help-section__summary:hover {
  background: color-mix(in srgb, var(--sec-color) 10%, var(--card));
}

.help-section__summary-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  border-radius: 8px;
  background: color-mix(in srgb, var(--sec-color) 14%, var(--card));
  flex-shrink: 0;
}

.help-section__summary-icon svg {
  width: 1.1rem;
  height: 1.1rem;
  stroke: var(--sec-color);
  fill: none;
  flex-shrink: 0;
}

.help-section__summary-title {
  flex: 1;
  font-size: 0.97rem;
  font-weight: 700;
  color: var(--sec-color);
  letter-spacing: -0.01em;
}

.help-section__chevron {
  width: 1.1rem;
  height: 1.1rem;
  stroke: var(--sec-color);
  opacity: 0.7;
  transition: transform 0.2s ease;
  flex-shrink: 0;
}

.help-section[open] .help-section__chevron {
  transform: rotate(180deg);
}

.help-section__list {
  margin: 0;
  padding: 0.85rem 1.4rem 1rem 3rem;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  border-left: 4px solid color-mix(in srgb, var(--sec-color) 20%, transparent);
}

.help-section__list li {
  font-size: 0.9rem;
  line-height: 1.55;
  color: var(--text);
}

.help-section__list code {
  font-size: 0.82rem;
  padding: 0.1rem 0.38rem;
  border-radius: 4px;
  background: color-mix(in srgb, var(--sec-color) 10%, var(--card));
  color: var(--sec-color);
  border: 1px solid color-mix(in srgb, var(--sec-color) 22%, transparent);
}

/* Datos técnicos */
.help-tech {
  padding: 1rem 1.25rem 1.1rem;
}

.help-tech__title {
  margin: 0 0 0.85rem;
  font-size: 0.9rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--avante-gray);
}

.help-tech__grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 0.55rem 1.25rem;
}

.help-tech__item {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

.help-tech__label {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--avante-gray);
}

.help-tech__value {
  font-size: 0.88rem;
  color: var(--text);
  word-break: break-all;
}

/* Dark mode adjustments */
html[data-theme="dark"] .help-hero__icon {
  background: linear-gradient(135deg, #0d2d3d 0%, #0d3d52 100%);
}

html[data-theme="dark"] .help-section__summary {
  background: color-mix(in srgb, var(--sec-color) 8%, var(--card));
}

html[data-theme="dark"] .help-section__summary:hover {
  background: color-mix(in srgb, var(--sec-color) 14%, var(--card));
}

html[data-theme="dark"] .help-section__summary-icon {
  background: color-mix(in srgb, var(--sec-color) 18%, var(--card));
}

@media (max-width: 540px) {
  .help-hero {
    flex-direction: column;
    gap: 0.75rem;
  }

  .help-section__list {
    padding-left: 1.25rem;
  }
}

/* ============================================================
   REPORT STYLES — Professional PDF/print report layout
   ============================================================ */

/* Header / Letterhead */
.rpt-header {
  background: linear-gradient(135deg, #004d6b 0%, #0076a3 60%, #0090c5 100%);
  border-radius: var(--radius);
  padding: 1.1rem 1.25rem 1rem;
  margin-bottom: 0.85rem;
  color: #fff;
}
.rpt-header-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 0.85rem;
}
.rpt-header-brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}
.rpt-header-logo {
  flex-shrink: 0;
}
.rpt-header-company {
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}
.rpt-header-app {
  font-size: 0.82rem;
  opacity: 0.85;
}
.rpt-header-meta {
  text-align: right;
  flex-shrink: 0;
}
.rpt-header-date {
  font-size: 0.85rem;
  font-weight: 600;
}
.rpt-header-ref {
  font-size: 0.72rem;
  opacity: 0.7;
  font-family: monospace;
  letter-spacing: 0.04em;
}
.rpt-header-title-row {
  border-top: 1px solid rgba(255,255,255,0.2);
  padding-top: 0.75rem;
}
.rpt-title {
  margin: 0 0 0.2rem;
  font-size: 1.2rem;
  font-weight: 700;
  color: #fff;
  letter-spacing: 0.01em;
}
.rpt-subtitle {
  margin: 0;
  font-size: 0.85rem;
  opacity: 0.88;
  line-height: 1.4;
}

/* Section headers */
.rpt-section { margin-bottom: 0.75rem; }
.rpt-section-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.65rem;
  padding-bottom: 0.45rem;
  border-bottom: 2px solid var(--avante-teal);
}
.rpt-section-header h2 {
  margin: 0;
  font-size: 1.05rem;
  color: var(--avante-teal);
  font-weight: 700;
}
.rpt-section-icon,
.rpt-section-header svg {
  width: 20px !important;
  height: 20px !important;
  max-width: 20px !important;
  max-height: 20px !important;
  min-width: 20px;
  min-height: 20px;
  color: var(--avante-teal);
  flex-shrink: 0;
  display: inline-block;
}
.rpt-header-logo svg {
  width: 40px !important;
  height: 40px !important;
  max-width: 40px !important;
  max-height: 40px !important;
  display: block;
}

/* Report table */
.rpt-table {
  font-size: 0.82rem;
  border-collapse: collapse;
  width: 100%;
}
.rpt-table th {
  background: #f0f4f7;
  font-weight: 650;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: #4a5568;
  padding: 0.55rem 0.5rem;
  border-bottom: 2px solid var(--border);
}
.rpt-table td {
  padding: 0.45rem 0.5rem;
  border-bottom: 1px solid #edf1f5;
  vertical-align: middle;
}
.rpt-table tbody tr:nth-child(even) {
  background: #fafcfd;
}
.rpt-table tbody tr:hover {
  background: rgba(0,118,163,0.03);
}
.rpt-table-totals {
  border-top: 2px solid var(--avante-teal);
  background: #f0f7fa !important;
}
.rpt-table-totals td {
  font-weight: 700;
  padding-top: 0.6rem;
  padding-bottom: 0.6rem;
  border-bottom: none;
}

/* Tags / badges */
.rpt-tag {
  display: inline-block;
  font-size: 0.72rem;
  padding: 2px 8px;
  border-radius: 10px;
  background: rgba(0,118,163,0.1);
  color: var(--avante-teal);
  font-weight: 550;
  white-space: nowrap;
}
.rpt-tag--ok {
  background: rgba(15,124,58,0.1);
  color: #0f7c3a;
}
.rpt-tag--muted {
  background: rgba(128,130,133,0.1);
  color: var(--avante-gray);
}
.rpt-tag--red {
  background: rgba(193,39,45,0.1);
  color: var(--avante-red);
}

/* Report footer */
.rpt-footer {
  margin-top: 1rem;
  padding: 0 0.25rem;
}
.rpt-footer-line {
  height: 2px;
  background: linear-gradient(90deg, var(--avante-teal) 0%, transparent 100%);
  margin-bottom: 0.65rem;
}
.rpt-footer-content {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  font-size: 0.72rem;
  color: var(--avante-gray);
}

/* Dark mode adjustments for report */
[data-theme="dark"] .rpt-header {
  background: linear-gradient(135deg, #003548 0%, #005a7d 60%, #006e99 100%);
}
[data-theme="dark"] .rpt-table th {
  background: #2a2e35;
  color: #9ca3af;
}
[data-theme="dark"] .rpt-table tbody tr:nth-child(even) {
  background: rgba(255,255,255,0.02);
}
[data-theme="dark"] .rpt-table-totals {
  background: rgba(0,118,163,0.08) !important;
}
[data-theme="dark"] .kpi-card {
  background: linear-gradient(135deg, #1e2228 0%, #252a32 100%);
}
[data-theme="dark"] .rpt-tag {
  background: rgba(0,118,163,0.15);
}
[data-theme="dark"] .rpt-tag--ok {
  background: rgba(15,124,58,0.15);
}
[data-theme="dark"] .rpt-tag--muted {
  background: rgba(128,130,133,0.15);
}

/* PDF export overrides for new report elements */
.historial-pdf-export-layout .rpt-header {
  border-radius: 0 !important;
}
.historial-pdf-export-layout .kpi-grid {
  grid-template-columns: repeat(5, minmax(0, 1fr)) !important;
}
.historial-pdf-export-layout .chart-grid {
  grid-template-columns: repeat(2, 1fr) !important;
  max-width: none !important;
}
.historial-pdf-export-layout .chart-canvas-wrap {
  max-width: none !important;
  height: 220px !important;
}

/* Preview modal overrides for responsive KPIs */
.historial-preview-scroll .historial-pdf-export-layout .kpi-grid {
  grid-template-columns: repeat(auto-fit, minmax(min(10rem, 100%), 1fr)) !important;
}
@media (min-width: 640px) {
  .historial-preview-scroll .historial-pdf-export-layout .kpi-grid {
    grid-template-columns: repeat(5, minmax(0, 1fr)) !important;
  }
}

@media (max-width: 640px) {
  .rpt-header-top { flex-direction: column; gap: 0.5rem; }
  .rpt-header-meta { text-align: left; }
  .rpt-title { font-size: 1rem; }
  .kpi-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
}

@media print {
  .historial-pdf-exclude { display: none !important; }
  .rpt-header { print-color-adjust: exact; -webkit-print-color-adjust: exact; }
  .rpt-table th { print-color-adjust: exact; -webkit-print-color-adjust: exact; }
  .kpi-card { break-inside: avoid; }
  .rpt-section { break-inside: avoid; }
}
