/* ============================================================================
   Elevadores MEGA · Helper de Mantenimiento
   Estilos generales — diseño moderno, responsive (desktop + mobile)
   ============================================================================ */

:root {
  --bg-app:        #0f172a;
  --bg-panel:      #1e293b;
  --bg-panel-2:    #273548;
  --bg-elev:       #334155;
  --border:        #334155;
  --text:          #e2e8f0;
  --text-mute:     #94a3b8;
  --text-dim:      #64748b;

  --accent:        #f59e0b;   /* naranja MEGA */
  --accent-hover:  #fbbf24;
  --primary:       #3b82f6;
  --success:       #10b981;
  --danger:        #ef4444;
  --warning:       #f59e0b;

  --pendiente:     #ef4444;
  --realizado:     #10b981;
  --seleccionado:  #f59e0b;
  --partida:       #3b82f6;

  --radius:        8px;
  --radius-sm:     6px;
  --shadow:        0 4px 12px rgba(0,0,0,0.25);
  --shadow-lg:     0 8px 24px rgba(0,0,0,0.35);

  --topbar-h:      72px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen,
               Ubuntu, Cantarell, sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg-app);
  overflow: hidden;
}
/* U2: shell en columna flex → el topbar crece con los filtros y #main llena el resto */
body { display: flex; flex-direction: column; }

button { font-family: inherit; cursor: pointer; }
input, select { font-family: inherit; }

/* ===================== TOPBAR ===================== */
#topbar {
  min-height: var(--topbar-h);
  flex-shrink: 0;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 16px;
  z-index: 1000;
  position: relative;
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-right: 12px;
  border-right: 1px solid var(--border);
  flex-shrink: 0;
}

.brand-mark {
  width: 40px; height: 40px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), #d97706);
  color: #1a1a1a;
  display: grid; place-items: center;
  font-weight: 900;
  font-size: 22px;
  box-shadow: 0 2px 6px rgba(245, 158, 11, 0.3);
}

/* Logo real si existe assets/logo.png */
.brand-logo {
  max-height: 44px;
  max-width: 180px;
  object-fit: contain;
  display: block;
}

.brand-title { font-weight: 700; font-size: 14px; line-height: 1.2; }
.brand-sub   { font-size: 11px; color: var(--text-mute); line-height: 1; margin-top: 2px; }

/* ===================== FILTROS ===================== */
.filters {
  flex: 1;
  display: flex;
  align-items: flex-end;
  gap: 12px;
  flex-wrap: wrap;
  min-width: 0;
}

.filter-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.filter-group label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-mute);
  font-weight: 600;
}

.filter-inline {
  display: flex;
  align-items: center;
  gap: 6px;
}

.filter-inline .dash { color: var(--text-dim); font-weight: 700; }

.filters input[type=time],
.filters input[type=date],
.filters input[type=number],
.filters input[type=text],
.filters select {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  color-scheme: dark;   /* picker nativo en oscuro */
  font-family: inherit;
}

.filters input[type=number] { width: 56px; }
.filters input[type=time]   { width: 95px; }
.filters input[type=date]   { width: 130px; }
.filters select             { min-width: 110px; }

.filters input:focus,
.filters select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(245, 158, 11, 0.2);
}

/* GLOBAL: todos los date/time/datetime-local heredan el tema dark.
   Esto cubre modales, formularios de admin, picker de fechas excluidas, etc. */
input[type="date"],
input[type="time"],
input[type="datetime-local"],
input[type="month"],
input[type="week"] {
  color-scheme: dark;
}
/* Icono del calendario blanco en webkit (Chrome/Safari) */
input[type="date"]::-webkit-calendar-picker-indicator,
input[type="time"]::-webkit-calendar-picker-indicator,
input[type="datetime-local"]::-webkit-calendar-picker-indicator {
  filter: invert(0.7) hue-rotate(180deg);
  cursor: pointer;
  opacity: 0.7;
}
input[type="date"]::-webkit-calendar-picker-indicator:hover,
input[type="time"]::-webkit-calendar-picker-indicator:hover,
input[type="datetime-local"]::-webkit-calendar-picker-indicator:hover {
  opacity: 1;
}
/* Forzar el color del valor en webkit */
input[type="date"]::-webkit-datetime-edit-text,
input[type="time"]::-webkit-datetime-edit-text,
input[type="date"]::-webkit-datetime-edit-month-field,
input[type="date"]::-webkit-datetime-edit-day-field,
input[type="date"]::-webkit-datetime-edit-year-field,
input[type="time"]::-webkit-datetime-edit-hour-field,
input[type="time"]::-webkit-datetime-edit-minute-field {
  color: var(--text);
}

/* Stats compactos en la barra de filtros (sitios + máquinas) */
.filter-stats {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-left: 12px;
  padding: 6px 12px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  min-width: 110px;
}
/* Overlay arriba-izquierda del mapa (movido fuera del header de filtros). */
.filter-stats.filter-stats-overlay {
  position: absolute;
  top: 16px;
  left: 16px;
  z-index: 500;
  margin-left: 0;
  background: #fff;
  color: #1f2937;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.18);
}
.filter-stats.filter-stats-overlay .stat-label,
.filter-stats.filter-stats-overlay .stat-value { color: #1f2937; }
.filter-stats .stat-row {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  line-height: 1;
}
.filter-stats .stat-icon { font-size: 12px; opacity: 0.7; width: 14px; text-align: center; }
.filter-stats .stat-value {
  font-weight: 700;
  color: var(--text);
  min-width: 28px;
  font-variant-numeric: tabular-nums;
}
.filter-stats .stat-label { color: var(--text-mute); font-size: 11px; }

/* Contador de máquinas en cada chip de zona */
.zona-chip .zona-maq-count {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 6px;
  font-size: 10px;
  font-weight: 700;
  background: rgba(255, 255, 255, 0.12);
  border-radius: 10px;
  font-variant-numeric: tabular-nums;
}
.zona-chip.active .zona-maq-count {
  background: rgba(0, 0, 0, 0.2);
}

.filter-group-actions {
  justify-content: flex-end;
}

/* Stats flotantes sobre el mapa (esquina superior derecha) */
.map-stats {
  position: absolute;
  top: 16px;
  right: 16px;
  z-index: 500;
  background: white;
  color: #1f2937;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  font-size: 13px;
  display: flex;
  gap: 6px;
  align-items: center;
}
.map-stats strong { font-weight: 700; color: #1f2937; }
.map-stats .stat-sep { color: #9ca3af; }

/* Indicador de conexión backend */
.conn-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  background: var(--bg-elev);
  border-radius: 999px;
  font-size: 11px;
  color: var(--text-mute);
  white-space: nowrap;
}
.conn-status .conn-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--text-dim);
}
.conn-status.online .conn-dot {
  background: var(--success);
  box-shadow: 0 0 6px var(--success);
}
.conn-status.online .conn-label { color: var(--success); }
.conn-status.offline .conn-dot { background: var(--warning); }
.conn-status.offline .conn-label { color: var(--warning); }

/* Pill de write mode (al lado del conn-status, solo cuando hay Planado) */
.write-mode-pill {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  transition: opacity 0.15s;
}
.write-mode-pill:hover { opacity: 0.85; }
.write-mode-pill.mode-disabled { background: rgba(16,185,129,0.2);  color: var(--success); }
.write-mode-pill.mode-dryrun   { background: rgba(59,130,246,0.2);  color: var(--primary); }
.write-mode-pill.mode-enabled  { background: rgba(239,68,68,0.25);  color: #fca5a5; animation: pulse-warn 2s ease-in-out infinite; }
@keyframes pulse-warn { 0%,100% { box-shadow: 0 0 0 0 rgba(239,68,68,0.4); } 50% { box-shadow: 0 0 0 4px rgba(239,68,68,0); } }

/* User badge en el header (cuando está logueado) */
.user-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 6px 4px 12px;
  background: var(--bg-elev);
  border-radius: 999px;
  font-size: 11px;
  color: var(--text);
}
.user-email { color: var(--text); font-weight: 600; }
.user-rol {
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  background: var(--accent);
  color: #1a1a1a;
  padding: 2px 6px;
  border-radius: 999px;
  font-weight: 700;
}
.user-rol.rol-admin        { background: var(--danger); color: white; }
.user-rol.rol-coordinadora { background: var(--primary); color: white; }
.user-rol.rol-recepcionista { background: var(--accent); color: #1a1a1a; }

/* Botón icono solo (admin, etc) */
.btn-icon-only {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  color: var(--text-mute);
  width: 36px; height: 36px;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}
.btn-icon-only:hover {
  background: var(--border);
  color: var(--text);
}

/* Botón hamburguesa de sidebar (solo mobile) */
.toggle-sidebar {
  display: none;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  width: 44px; height: 40px;
  position: relative;
  font-size: 18px;
}
.toggle-sidebar .badge {
  position: absolute;
  top: -6px; right: -6px;
  background: var(--accent);
  color: #1a1a1a;
  border-radius: 999px;
  padding: 0 6px;
  font-size: 11px;
  font-weight: 700;
  min-width: 18px; height: 18px;
  display: grid; place-items: center;
}
.toggle-sidebar .badge:empty,
.toggle-sidebar .badge[data-empty="1"] { display: none; }

/* ===================== MAIN ===================== */
#main {
  display: flex;
  flex: 1;
  min-height: 0;
  position: relative;
}

/* ===================== MAPA ===================== */
#map-wrap {
  flex: 1;
  position: relative;
  background: #1a202c;
}
#map {
  width: 100%;
  height: 100%;
}

/* Toolbar flotante del mapa */
.map-toolbar {
  position: absolute;
  top: 16px;
  left: 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  z-index: 500;
}
.map-tool {
  background: white;
  color: #1f2937;
  border: 1px solid #d1d5db;
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow);
  transition: all 0.15s;
}
.map-tool:hover { background: #f3f4f6; }
.map-tool.active {
  background: var(--accent);
  color: #1a1a1a;
  border-color: var(--accent);
}

/* Leyenda */
.map-legend {
  position: absolute;
  bottom: 16px;
  left: 16px;
  background: white;
  color: #1f2937;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  font-size: 11px;
  z-index: 500;
  display: flex;
  gap: 16px;
  max-width: calc(100vw - 200px);
}
.legend-section { display: flex; flex-direction: column; gap: 3px; }
.legend-title {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #6b7280;
  font-weight: 700;
  margin-bottom: 2px;
}
.legend-item { display: flex; align-items: center; gap: 6px; }
.dot { width: 12px; height: 12px; border-radius: 50%; display: inline-block; flex-shrink: 0; }
.dot-seleccionado { background: var(--seleccionado); border: 2px solid white; box-shadow: 0 0 0 1px var(--seleccionado); }
.dot-partida      { background: var(--partida); }

.badge-check {
  background: var(--realizado);
  color: white;
  font-size: 9px;
  width: 14px; height: 14px;
  border-radius: 50%;
  display: inline-grid; place-items: center;
  font-weight: 700;
  flex-shrink: 0;
}
.badge-coord {
  font-size: 11px;
  flex-shrink: 0;
}

/* ===================== MARKERS PERSONALIZADOS ===================== */
/* El color del marker viene de la variable --zona-color (inline style) */
.mega-marker {
  background: var(--zona-color, #6b7280);
  width: 28px; height: 28px;
  border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
  border: 2px solid white;
  box-shadow: 0 2px 4px rgba(0,0,0,0.4);
  display: grid;
  place-items: center;
  position: relative;
  transition: transform 0.15s;
}
.mega-marker::before {
  content: '';
  width: 10px; height: 10px;
  background: white;
  border-radius: 50%;
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
}
/* Seleccionado: borde naranja + scale up + z-index alto */
.mega-marker.seleccionado {
  transform: rotate(-45deg) scale(1.25);
  z-index: 1000 !important;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.4), 0 4px 8px rgba(0,0,0,0.4);
}
.mega-marker.partida {
  background: var(--partida);
  border-radius: 50%;
  transform: none;
}
.mega-marker.partida::before { background: white; }

/* Number badge (orden en ruta) */
.mega-marker .num {
  position: absolute;
  top: -8px; left: -8px;
  background: #1a1a1a;
  color: var(--accent);
  font-weight: 700;
  font-size: 11px;
  width: 18px; height: 18px;
  border-radius: 50%;
  display: grid; place-items: center;
  transform: rotate(45deg);
  border: 2px solid white;
  z-index: 2;
}
.mega-marker.partida .num { transform: none; top: -6px; right: -6px; left: auto; }

/* Tilde verde para sitios realizados */
.mega-marker .ok-check {
  position: absolute;
  bottom: -6px; right: -6px;
  background: var(--realizado);
  color: white;
  font-weight: 700;
  font-size: 10px;
  width: 16px; height: 16px;
  border-radius: 50%;
  display: grid; place-items: center;
  transform: rotate(45deg);
  border: 2px solid white;
  z-index: 2;
  line-height: 1;
}

/* Ícono de coordinación (📞) — pendiente vs con fecha cargada */
.mega-marker .coord-badge {
  position: absolute;
  top: -10px; right: -10px;
  background: var(--warning);    /* naranja: necesita coordinación */
  color: white;
  font-size: 11px;
  width: 20px; height: 20px;
  border-radius: 50%;
  display: grid; place-items: center;
  transform: rotate(45deg);      /* contra-rotación del marker padre */
  border: 2px solid white;
  z-index: 3;
  box-shadow: 0 0 0 1px rgba(0,0,0,0.3);
  line-height: 1;
}
.mega-marker .coord-badge.has-fecha {
  background: var(--success);    /* verde: ya hay coordinación cargada */
  box-shadow: 0 0 0 1px rgba(0,0,0,0.3), 0 0 8px rgba(16,185,129,0.5);
}

/* Popup del marker */
.leaflet-popup-content-wrapper {
  background: var(--bg-panel);
  color: var(--text);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
}
.leaflet-popup-tip { background: var(--bg-panel); }
.leaflet-popup-content { margin: 12px 14px; min-width: 220px; }

.popup-title { font-weight: 700; font-size: 14px; margin-bottom: 4px; }
.popup-dir   { font-size: 12px; color: var(--text-mute); margin-bottom: 8px; }
.popup-meta  { display: flex; gap: 8px; font-size: 11px; color: var(--text-mute); margin-bottom: 10px; flex-wrap: wrap; }
.popup-meta .chip { background: var(--bg-elev); padding: 2px 8px; border-radius: 10px; }
.popup-meta .chip.ok  { background: rgba(16, 185, 129, 0.2); color: #6ee7b7; }
.popup-meta .chip.pen { background: rgba(239, 68, 68, 0.2);  color: #fca5a5; }

.popup-actions { display: flex; gap: 6px; }
.popup-btn {
  flex: 1;
  background: var(--accent);
  color: #1a1a1a;
  border: none;
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  font-weight: 600;
  font-size: 12px;
}
.popup-btn:hover { background: var(--accent-hover); }
.popup-btn.secondary { background: var(--bg-elev); color: var(--text); }
.popup-btn.secondary:hover { background: var(--border); }

/* ===================== SIDEBAR ===================== */
#sidebar {
  width: 360px;
  background: var(--bg-panel);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transition: transform 0.25s ease, width 0.25s ease;
  flex-shrink: 0;
}

.sidebar-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
}
.tab-btn {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-mute);
  padding: 12px 16px;
  font-size: 13px;
  font-weight: 600;
  border-bottom: 2px solid transparent;
  transition: all 0.15s;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.tab-panel { display: none; flex-direction: column; flex: 1; min-height: 0; }
.tab-panel.active { display: flex; }

/* Header de la ruta */
.ruta-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}
#ruta-nombre {
  width: 100%;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  outline: none;
  margin-bottom: 8px;
}
#ruta-nombre:focus { border-color: var(--accent); }
.ruta-meta { font-size: 12px; color: var(--text-mute); display: flex; gap: 4px; }
.ruta-meta strong { color: var(--text); }
.ruta-eta-total {
  margin-top: 4px;
  font-size: 11px;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

/* Bloque ETA dentro de cada item de ruta */
.ruta-item .ruta-eta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  min-width: 52px;
  padding: 0 6px;
  border-right: 1px solid var(--border);
  margin-right: 4px;
}
.ruta-item .ruta-eta .eta-arribo {
  font-size: 13px;
  font-weight: 700;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}
.ruta-item .ruta-eta .eta-dur {
  font-size: 9px;
  color: var(--text-dim);
  line-height: 1;
  margin-top: 2px;
}

.ruta-actions {
  display: flex;
  gap: 6px;
  padding: 8px 16px;
  border-bottom: 1px solid var(--border);
}

/* Lista de sitios en la ruta */
.ruta-list {
  list-style: none;
  margin: 0;
  padding: 8px;
  flex: 1;
  overflow-y: auto;
}

.ruta-item {
  background: var(--bg-elev);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 9px 10px;
  margin-bottom: 6px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  cursor: grab;
  transition: all 0.15s;
}
.ruta-item:hover { border-color: var(--accent); }
.ruta-item.dragging { opacity: 0.5; }
.ruta-item.drag-over { border-top: 2px solid var(--accent); }

.ruta-item .ri-top { display: flex; align-items: center; gap: 8px; }
.ruta-item .handle { color: var(--text-dim); padding: 0 2px; cursor: grab; }

.ruta-item .num {
  background: var(--accent);
  color: #1a1a1a;
  font-weight: 700;
  border-radius: 50%;
  width: 24px; height: 24px;
  display: grid; place-items: center;
  font-size: 12px;
  flex-shrink: 0;
}
.ruta-item .info-nombre {
  flex: 1;
  min-width: 0;
  font-weight: 600;
  font-size: 13px;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.ruta-item .info-meta {
  font-size: 11px;
  color: var(--text-mute);
  display: flex;
  flex-wrap: wrap;
  gap: 5px 9px;
  align-items: center;
  padding-left: 32px;
}
.ruta-item .eta-inline { color: var(--accent); font-weight: 700; font-variant-numeric: tabular-nums; }
.ruta-item .eta-inline small { font-weight: 400; color: var(--text-dim); }

.ruta-item .item-actions { display: flex; gap: 2px; flex-shrink: 0; }
.ruta-item .icon-btn {
  background: transparent;
  border: none;
  color: var(--text-mute);
  padding: 4px;
  border-radius: 4px;
  font-size: 14px;
  line-height: 1;
}
.ruta-item .icon-btn:hover { background: var(--border); color: var(--text); }
.ruta-item .icon-btn.danger:hover { background: var(--danger); color: white; }

.ruta-empty {
  color: var(--text-mute);
  font-size: 13px;
  text-align: center;
  padding: 32px 16px;
  list-style: none;
}

.ruta-footer {
  display: flex;
  gap: 6px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
}

/* Rutas guardadas */
.rutas-guardadas-list {
  list-style: none;
  margin: 0;
  padding: 8px;
  flex: 1;
  overflow-y: auto;
}
.ruta-guardada {
  background: var(--bg-elev);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  margin-bottom: 6px;
  border: 1px solid transparent;
  transition: border-color 0.15s;
}
.ruta-guardada:hover { border-color: var(--accent); }
.ruta-guardada-nombre { font-weight: 600; font-size: 13px; }
.ruta-guardada-meta { font-size: 11px; color: var(--text-mute); margin: 4px 0 8px; }
.ruta-guardada-actions { display: flex; gap: 4px; }
.ruta-guardada-actions .btn { flex: 1; }

/* ===================== BOTONES ===================== */
.btn {
  border: none;
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: all 0.15s;
  white-space: nowrap;
}
.btn-sm { padding: 6px 10px; font-size: 12px; flex: 1; }
.btn-primary   { background: var(--accent); color: #1a1a1a; }
.btn-primary:hover   { background: var(--accent-hover); }
.btn-secondary { background: var(--bg-elev); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--border); }
.btn-ghost     { background: transparent; color: var(--text-mute); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--bg-elev); color: var(--text); }
.btn-success   { background: var(--success); color: white; }
.btn-success:hover { background: #059669; }
.btn-danger    { background: var(--danger); color: white; }

/* ===================== MODALES DRAGGABLES ===================== */
.modal {
  position: fixed;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  min-width: 320px;
  max-width: 500px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  max-height: 80vh;
}
.modal-header {
  background: var(--bg-panel-2);
  padding: 10px 14px;
  border-radius: var(--radius) var(--radius) 0 0;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: move;
  user-select: none;
}
.modal-title { font-weight: 700; font-size: 13px; }
.modal-close {
  background: transparent;
  border: none;
  color: var(--text-mute);
  font-size: 18px;
  line-height: 1;
  padding: 4px 8px;
  border-radius: 4px;
}
.modal-close:hover { background: var(--border); color: var(--text); }

.modal-body { padding: 14px; overflow-y: auto; flex: 1; }
.modal-footer {
  padding: 10px 14px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 6px;
  justify-content: flex-end;
}

.form-row { margin-bottom: 12px; }
.form-row label {
  display: block;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-mute);
  font-weight: 600;
  margin-bottom: 4px;
}
.form-row input,
.form-row select,
.form-row textarea {
  width: 100%;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  outline: none;
}
.form-row input:focus,
.form-row select:focus,
.form-row textarea:focus { border-color: var(--accent); }
.form-row textarea { resize: vertical; min-height: 60px; }

.form-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* ===================== ZONAS — Chips y badges ===================== */
/* ===== Botón dropdown de zonas (en el header) ===== */
.zonas-dropdown-btn {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 110px;
  justify-content: space-between;
}
.zonas-dropdown-btn:hover { border-color: var(--accent); }
.zonas-dropdown-btn .caret { color: var(--text-mute); font-size: 10px; }

.zonas-dropdown-panel {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 8px;
  min-width: 220px;
  max-width: 320px;
  max-height: 320px;
  overflow-y: auto;
  z-index: 1000;
}
.zonas-dropdown-panel[hidden] { display: none; }

.zonas-dropdown-actions {
  display: flex;
  gap: 4px;
  margin-bottom: 6px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}
.zonas-dropdown-actions button {
  flex: 1;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-mute);
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 11px;
  cursor: pointer;
}
.zonas-dropdown-actions button:hover { background: var(--bg-elev); color: var(--text); }

/* Adentro del dropdown los chips son verticales (uno por fila) */
.zonas-dropdown-panel .zonas-chips {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.zonas-dropdown-panel .zona-chip {
  width: 100%;
  justify-content: flex-start;
  padding: 6px 10px;
}

.zona-chip {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  color: var(--text-mute);
  padding: 5px 8px 5px 6px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  transition: all 0.15s;
  cursor: pointer;
  white-space: nowrap;
}
.zona-chip:hover { border-color: var(--zona-color); color: var(--text); }
.zona-chip.active {
  background: var(--zona-color);
  color: white;
  border-color: var(--zona-color);
}
.zona-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--zona-color);
  display: inline-block;
}
.zona-chip.active .zona-dot { background: rgba(255,255,255,0.6); }

/* Badge de zona usado en sidebar / popup / modal */
.zona-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
  background: var(--zona-color);
  color: white;
  white-space: nowrap;
}
.zona-badge .dot {
  width: 6px; height: 6px;
  background: rgba(255,255,255,0.7);
}

/* Versión refinada para la lista de ruta: punto de color + nombre tenue (no un pill brillante) */
.zona-tag {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 10.5px;
  font-weight: 600;
  color: var(--text-mute);
  text-transform: uppercase;
  letter-spacing: .3px;
  white-space: nowrap;
}
.zona-tag .zona-tag-dot {
  width: 9px; height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* ===================== DÍAS — Chips L M X J V S D ===================== */
.dias-chips {
  display: inline-flex;
  gap: 2px;
}
.dia-chip {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  color: var(--text-mute);
  width: 24px; height: 28px;
  font-size: 11px;
  font-weight: 700;
  border-radius: 4px;
  display: grid; place-items: center;
  cursor: pointer;
  transition: all 0.15s;
}
.dia-chip.active {
  background: var(--accent);
  color: #1a1a1a;
  border-color: var(--accent);
}
.dia-chip:hover { border-color: var(--accent); }

/* Días en sidebar/popup (read-only) */
.dias-display {
  display: inline-flex;
  gap: 2px;
}
.dias-display .d {
  background: var(--bg-elev);
  color: var(--text-mute);
  width: 16px; height: 16px;
  font-size: 9px;
  font-weight: 700;
  border-radius: 3px;
  display: inline-grid; place-items: center;
}
.dias-display .d.on {
  background: var(--accent);
  color: #1a1a1a;
}

/* ===================== FECHAS — Picker + Chips acumulables ===================== */
.fecha-picker {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.fecha-picker-input {
  display: flex;
  gap: 6px;
  align-items: center;
}
.fecha-picker-input input[type="date"] {
  flex: 1;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 6px 8px;
  border-radius: 6px;
  font-size: 12px;
  color-scheme: dark;
}
.fecha-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  min-height: 22px;
  padding: 4px 0;
}
.fecha-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 4px 3px 8px;
  background: rgba(96, 165, 250, 0.15);
  color: #93c5fd;
  border: 1px solid rgba(96, 165, 250, 0.4);
  border-radius: 12px;
  font-size: 11px;
  font-weight: 500;
}
.fecha-chip-x {
  background: transparent;
  border: 0;
  color: inherit;
  cursor: pointer;
  padding: 0 4px;
  font-size: 10px;
  opacity: 0.7;
  border-radius: 50%;
  width: 16px; height: 16px;
  display: inline-grid; place-items: center;
}
.fecha-chip-x:hover {
  background: rgba(239, 68, 68, 0.3);
  color: #fca5a5;
  opacity: 1;
}

/* ===================== COORDINACIÓN — Badges ===================== */
.coord-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
  background: rgba(245, 158, 11, 0.2);
  color: var(--accent);
  border: 1px dashed var(--accent);
}
.coord-chip.tiene-fecha {
  background: rgba(16, 185, 129, 0.2);
  color: #6ee7b7;
  border-style: solid;
  border-color: var(--success);
}

/* ===================== ENVÍO A PLANADO — Preview + progreso ===================== */
.preview-header {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px 14px;
  padding: 10px 12px;
  background: var(--bg-elev);
  border-radius: 6px;
  margin-bottom: 12px;
  font-size: 12px;
}
.preview-header .pi {
  display: flex; justify-content: space-between; gap: 8px;
}
.preview-header .pi-l { color: var(--text-mute); }
.preview-header .pi-v { color: var(--text); font-weight: 500; }
.preview-warning {
  background: rgba(245, 158, 11, 0.15);
  color: var(--accent);
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 12px;
  margin-bottom: 12px;
  border-left: 3px solid var(--accent);
}
.preview-jobs {
  max-height: 320px;
  overflow-y: auto;
  background: var(--bg-elev);
  border-radius: 6px;
  padding: 4px;
}
.preview-job {
  display: grid;
  grid-template-columns: 24px 1fr auto 24px;
  gap: 8px;
  align-items: center;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
}
.preview-job:last-child { border-bottom: none; }
.preview-job .pj-orden {
  background: var(--bg-panel);
  border-radius: 50%;
  width: 22px; height: 22px;
  display: grid; place-items: center;
  font-weight: 700; font-size: 11px;
  color: var(--text-mute);
}
.preview-job .pj-nombre { font-weight: 600; color: var(--text); }
.preview-job .pj-meta { font-size: 10px; color: var(--text-dim); margin-top: 2px; }
.preview-job .pj-time {
  font-family: monospace; font-size: 11px; color: var(--text-mute);
  white-space: nowrap;
}
.preview-job .pj-status { text-align: center; font-size: 14px; }
.preview-job .pj-error {
  color: var(--danger); font-size: 10px; margin-top: 3px;
}
.preview-progress {
  margin-top: 12px;
  padding: 10px 12px;
  background: var(--bg-elev);
  border-radius: 6px;
}
.preview-progress .pp-bar {
  height: 6px;
  background: var(--bg-panel);
  border-radius: 3px;
  overflow: hidden;
}
.preview-progress .pp-fill {
  height: 100%; width: 0%;
  background: var(--primary);
  transition: width 0.25s ease, background 0.25s ease;
}

/* ===================== ADMIN GRID (Modal Planado) ===================== */
.admin-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.admin-card {
  background: var(--bg-elev);
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}
.admin-card-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-mute);
  font-weight: 600;
  margin-bottom: 4px;
}
.admin-card-value {
  font-size: 16px;
  font-weight: 700;
}

/* ===================== TOASTS ===================== */
#toast-root {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 3000;
  pointer-events: none;
}
.toast {
  background: var(--bg-panel);
  color: var(--text);
  padding: 10px 16px;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  border-left: 4px solid var(--accent);
  font-size: 13px;
  animation: toast-in 0.25s ease;
  pointer-events: auto;
}
.toast.success { border-left-color: var(--success); }
.toast.error   { border-left-color: var(--danger); }
.toast.info    { border-left-color: var(--primary); }
@keyframes toast-in {
  from { transform: translateY(10px); opacity: 0; }
  to   { transform: translateY(0); opacity: 1; }
}

/* ===================== LEAFLET-LASSO STYLE OVERRIDE ===================== */
.leaflet-lasso-polygon {
  stroke: var(--accent);
  fill: var(--accent);
  fill-opacity: 0.1;
  stroke-width: 2;
  stroke-dasharray: 6 4;
}

/* ===================== RESPONSIVE ===================== */
/* U2: banda notebook — filtros flexibles para que envuelvan prolijo en el topbar flex */
@media (max-width: 1366px) {
  #topbar { padding: 8px 14px; gap: 8px 14px; }
  .filters { gap: 8px 12px; }
  .filters input[type=number] { width: 56px; }
  .filters input[type=time]   { width: 94px; }
  .filters input[type=date]   { width: 120px; }
  .filters select             { min-width: 100px; }
}

@media (max-width: 1024px) {
  .filter-stats { display: none; }
}

@media (max-width: 1024px) {
  #topbar {
    flex-wrap: wrap;
    padding: 8px;
    gap: 8px;
  }
  .topbar-brand { border-right: none; padding-right: 0; }
  .brand-text { display: none; }

  .filters {
    order: 3;
    width: 100%;
    flex-wrap: wrap;
    padding-bottom: 4px;
  }
  .filter-group { flex-shrink: 0; }

  .toggle-sidebar {
    display: flex;
    align-items: center;
    justify-content: center;
    margin-left: auto;
  }

  #sidebar {
    position: absolute;
    right: 0;
    top: 0;
    height: 100%;
    width: 100%;
    max-width: 380px;
    transform: translateX(100%);
    z-index: 1500;
    box-shadow: -4px 0 16px rgba(0,0,0,0.4);
  }
  #sidebar:not(.closed) { transform: translateX(0); }

  .map-toolbar { top: 12px; left: 12px; }
  .map-tool { padding: 10px; }
  .map-tool span { display: none; }
  .map-legend { font-size: 11px; padding: 8px 10px; }
}

@media (min-width: 1025px) {
  #sidebar.closed { transform: translateX(0); } /* en desktop/notebook siempre visible */
}
