/* ==========================================================
   Simulador GPS — Design System
   ========================================================== */
:root {
  --color-bg:        #f5f7fa;
  --color-surface:   #ffffff;
  --color-surface-2: #f9fafb;
  --color-surface-3: #f3f4f6;
  --color-border:    #e5e7eb;
  --color-border-2:  #d1d5db;

  --color-text:      #111827;
  --color-text-2:    #374151;
  --color-text-mute: #6b7280;
  --color-text-dim:  #9ca3af;

  --color-primary:       #2563eb;
  --color-primary-hover: #1d4ed8;
  --color-primary-soft:  #eff6ff;
  --color-success:       #10b981;
  --color-success-soft:  #d1fae5;
  --color-warning:       #f59e0b;
  --color-warning-soft:  #fef3c7;
  --color-danger:        #ef4444;
  --color-danger-hover:  #dc2626;
  --color-danger-soft:   #fee2e2;
  --color-info-soft:     #dbeafe;

  --shadow-sm:  0 1px 2px 0 rgba(0,0,0,0.05);
  --shadow:     0 1px 3px 0 rgba(0,0,0,0.08), 0 1px 2px 0 rgba(0,0,0,0.04);
  --shadow-lg:  0 10px 15px -3px rgba(0,0,0,0.08), 0 4px 6px -2px rgba(0,0,0,0.04);

  --radius-sm: 4px;
  --radius:    6px;
  --radius-lg: 8px;

  --header-h:  52px;
  --panel-w:   440px;
  --detail-w:  480px;

  --font:      -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", Monaco, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  height: 100%;
  font-family: var(--font);
  font-size: 14px;
  color: var(--color-text);
  background: var(--color-bg);
  -webkit-font-smoothing: antialiased;
}

body { display: grid; grid-template-rows: var(--header-h) 1fr; height: 100vh; }

/* ==========================================================
   Header
   ========================================================== */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  background: linear-gradient(180deg, #0f172a 0%, #1e293b 100%);
  color: #fff;
  border-bottom: 1px solid #0f172a;
}
header h1 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.2px;
  display: flex;
  align-items: center;
  gap: 8px;
}
header h1::before {
  content: "📡";
  font-size: 18px;
}
.header-right {
  display: flex;
  gap: 8px;
  align-items: center;
  font-size: 12px;
  color: #cbd5e1;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: rgba(255,255,255,0.08);
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 500;
  border: 1px solid rgba(255,255,255,0.1);
}
.badge.ok  { background: rgba(16,185,129,0.2);  color: #6ee7b7; border-color: rgba(16,185,129,0.3); }
.badge.err { background: rgba(239,68,68,0.2);   color: #fca5a5; border-color: rgba(239,68,68,0.3); }
.badge::before {
  content: "";
  width: 6px; height: 6px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.7;
}

/* ==========================================================
   Main layout (detail | map | right panel)
   ========================================================== */
main {
  display: grid;
  grid-template-columns: 0 1fr var(--panel-w);
  transition: grid-template-columns 0.25s ease;
  overflow: hidden;
  min-width: 0;
}
main.detail-open {
  grid-template-columns: var(--detail-w) 1fr var(--panel-w);
}

#map-section { position: relative; min-width: 0; overflow: hidden; }
#map { width: 100%; height: 100%; }

.map-hint {
  position: absolute;
  top: 12px; left: 50%;
  transform: translateX(-50%);
  background: rgba(17,24,39,0.92);
  color: #fff;
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  z-index: 500;
  box-shadow: var(--shadow-lg);
  backdrop-filter: blur(4px);
}
.map-hint.hidden { display: none; }

@media (max-width: 1280px) {
  :root { --panel-w: 400px; --detail-w: 420px; }
}
@media (max-width: 1024px) {
  main.detail-open { grid-template-columns: 0 0 1fr; }
  .detail-panel { position: fixed !important; inset: var(--header-h) 0 0 0 !important; z-index: 900; }
}

/* ==========================================================
   Right panel (tabs + content)
   ========================================================== */
#panel {
  position: relative;
  display: flex;
  flex-direction: column;
  background: var(--color-surface);
  border-left: 1px solid var(--color-border);
  overflow: hidden;
  min-width: 0;
}

.tabs {
  display: flex;
  background: var(--color-surface-2);
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
}
.tab-btn {
  flex: 1;
  padding: 11px 6px;
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 12.5px;
  color: var(--color-text-mute);
  border-bottom: 2px solid transparent;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  font-family: inherit;
  font-weight: 500;
}
.tab-btn:hover { background: var(--color-surface-3); color: var(--color-text-2); }
.tab-btn.active {
  color: var(--color-primary);
  border-bottom-color: var(--color-primary);
  background: var(--color-surface);
  font-weight: 600;
}

.tab-content {
  display: none;
  flex: 1;
  overflow-y: auto;
  padding: 14px;
}
.tab-content.active { display: block; }

/* ==========================================================
   Detail panel (slides in from left)
   ========================================================== */
.detail-panel {
  position: relative;
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
  min-height: 0;
}

/* Contenedor del body renderizado: hace scroll interno correcto */
#detail-body {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
#detail-body > .detail-destino,
#detail-body > .detail-metrics,
#detail-body > .detail-toolbar { flex: 0 0 auto; }
#detail-body > .detail-table-wrap {
  flex: 1;
  min-height: 0;
  overflow: auto;
}
.detail-table-wrap table { width: 100%; }

/* Colorea filas por estado OK/ERR */
.detail-table-wrap tr.row-ok  td { background: rgba(16,185,129,0.05); }
.detail-table-wrap tr.row-err td { background: rgba(239,68,68,0.08); }
.detail-table-wrap tr.row-ok:hover  td { background: rgba(16,185,129,0.12); }
.detail-table-wrap tr.row-err:hover td { background: rgba(239,68,68,0.15); }

/* ==========================================================
   Panel resizers (mouse drag)
   ========================================================== */
.panel-resizer {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 5px;
  cursor: col-resize;
  z-index: 100;
  background: transparent;
  transition: background 0.15s;
}
.panel-resizer:hover,
.panel-resizer.dragging { background: var(--color-primary); opacity: 0.35; }
.panel-resizer-right { right: -2px; }
.panel-resizer-left  { left: -2px; }
body.resizing { cursor: col-resize !important; user-select: none; }
body.resizing * { pointer-events: none; }
body.resizing .panel-resizer { pointer-events: auto; }

/* ==========================================================
   Vehicle arrow marker (rotated by COG)
   ========================================================== */
.veh-arrow { background: transparent !important; border: none !important; }
.veh-arrow-wrap {
  width: 26px; height: 26px;
  transition: transform 0.15s linear;
  filter: drop-shadow(0 1px 2px rgba(0,0,0,0.35));
}

/* ==========================================================
   Searchable event combobox (popup de edición de punto)
   ========================================================== */
.ev-combo { position: relative; }
.ev-combo-input { margin-bottom: 4px; }
.ev-list {
  max-height: 240px;
  overflow-y: auto;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface);
}
.ev-opt {
  padding: 7px 10px;
  cursor: pointer;
  font-size: 12px;
  border-bottom: 1px solid var(--color-surface-3);
  display: flex;
  align-items: center;
  gap: 8px;
}
.ev-opt:last-child { border-bottom: none; }
.ev-opt:hover, .ev-opt.kbd-active { background: var(--color-primary-soft); }
.ev-opt.selected { background: var(--color-primary); color: #fff; }
.ev-opt.selected .ev-opt-meta { color: rgba(255,255,255,0.75); }
.ev-opt-color {
  width: 10px; height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
  border: 1px solid rgba(0,0,0,0.15);
}
.ev-opt-main { flex: 1; min-width: 0; }
.ev-opt-code { font-weight: 600; }
.ev-opt-meta { color: var(--color-text-mute); font-size: 10.5px; }

/* ==========================================================
   Speed control (Simulación)
   ========================================================== */
.speed-control {
  display: flex;
  gap: 4px;
  align-items: center;
  background: var(--color-surface-2);
  padding: 4px 6px;
  border-radius: var(--radius);
  border: 1px solid var(--color-border);
}
.speed-control .label-mini { white-space: nowrap; margin-right: 4px; }
.speed-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 4px 8px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  border: 1px solid transparent;
  background: transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--color-text-mute);
  line-height: 1.1;
  min-width: 38px;
}
.speed-btn .speed-num { font-size: 11px; }
.speed-btn .speed-tick {
  font-size: 9px;
  font-weight: 500;
  opacity: 0.75;
  margin-top: 1px;
}
.speed-btn:hover { background: var(--color-surface); color: var(--color-text); }
.speed-btn.active {
  background: var(--color-primary);
  color: #fff;
  border-color: var(--color-primary);
}
.speed-btn.active .speed-tick { opacity: 0.9; }

/* ==========================================================
   Auto-follow pill (panel de detalle)
   ========================================================== */
.follow-pill {
  position: absolute;
  bottom: 14px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--color-primary);
  color: #fff;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: var(--shadow-lg);
  z-index: 10;
  border: none;
  display: flex;
  align-items: center;
  gap: 6px;
  animation: slideUp 0.2s ease-out;
}
.follow-pill:hover { background: var(--color-primary-hover); }
@keyframes slideUp { from { transform: translate(-50%, 20px); opacity: 0; } to { transform: translate(-50%, 0); opacity: 1; } }

/* ==========================================================
   Menú contextual sobre marker (modo edición de ruta)
   ========================================================== */
.ctx-menu {
  position: fixed;
  z-index: 8000;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  min-width: 200px;
  padding: 4px;
  animation: popIn 0.12s ease-out;
}
.ctx-menu-header {
  padding: 6px 10px 8px;
  font-size: 11px;
  color: var(--color-text-mute);
  border-bottom: 1px solid var(--color-border);
  margin-bottom: 4px;
  font-weight: 500;
}
.ctx-menu-item {
  display: flex;
  align-items: center;
  width: 100%;
  padding: 7px 10px;
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 13px;
  font-family: inherit;
  color: var(--color-text);
  border-radius: var(--radius-sm);
  text-align: left;
  gap: 8px;
  transition: background 0.1s, color 0.1s;
}
.ctx-menu-item:hover {
  background: var(--color-primary-soft);
  color: var(--color-primary);
}
.ctx-menu-item.danger:hover {
  background: var(--color-danger-soft);
  color: var(--color-danger);
}
.ctx-menu-icon {
  width: 18px;
  text-align: center;
  font-size: 13px;
}

/* ==========================================================
   Cards colapsables (editor de ruta, etc.)
   ========================================================== */
.card-collapsible {
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  margin-bottom: 12px;
  overflow: hidden;
  background: var(--color-surface);
}
.card-collapsible .card-header {
  padding: 10px 12px;
  background: var(--color-surface-2);
  border-bottom: 1px solid var(--color-border);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  user-select: none;
  transition: background 0.12s;
}
.card-collapsible .card-header:hover { background: var(--color-surface-3); }
.card-collapsible .card-header strong { font-size: 13px; }
.card-collapsible .card-header .chevron {
  font-size: 9px;
  color: var(--color-text-mute);
  transition: transform 0.2s ease;
  width: 10px;
  text-align: center;
}
.card-collapsible.collapsed .card-header .chevron { transform: rotate(-90deg); }
.card-collapsible.collapsed .card-header { border-bottom: none; }
.card-collapsible.collapsed .card-body { display: none; }
.card-collapsible .card-body { padding: 12px; }

/* Lista de puntos: scroll independiente */
.points-list { max-height: 50vh; overflow-y: auto; border-radius: 0; border: none; }
.punto-item { cursor: pointer; }
.punto-item:hover { background: var(--color-primary-soft); }

/* Filtros sobre la lista de puntos */
.puntos-filters {
  display: flex;
  gap: 6px;
  padding: 8px 10px;
  background: var(--color-surface-2);
  border-bottom: 1px solid var(--color-border);
}
.puntos-filters input { flex: 1; min-width: 0; }
.puntos-filters select { width: 130px; flex-shrink: 0; }

/* Halo expandiéndose al hacer fly-to-punto desde la lista (funciona sobre canvas markers) */
.punto-halo { background: transparent !important; border: none !important; }
.punto-halo .halo-ring {
  position: absolute;
  top: 50%; left: 50%;
  width: 24px; height: 24px;
  margin: -12px 0 0 -12px;
  border-radius: 50%;
  border: 3px solid #2563eb;
  background: rgba(37,99,235,0.18);
  box-shadow: 0 0 12px rgba(37,99,235,0.6);
  transform-origin: center;
  animation: haloPulse 1.4s ease-out forwards;
}
.punto-halo .halo-ring.delay { animation-delay: 0.25s; border-color: #60a5fa; }
@keyframes haloPulse {
  0%   { transform: scale(0.4); opacity: 1; }
  60%  { transform: scale(2.5); opacity: 0.6; }
  100% { transform: scale(3.5); opacity: 0; }
}

/* Flash highlight cuando se agrega un punto nuevo */
@keyframes itemFlash {
  0%   { background-color: var(--color-warning-soft); transform: scale(1.01); }
  60%  { background-color: var(--color-warning-soft); }
  100% { background-color: transparent; transform: scale(1); }
}
.list-item.flash { animation: itemFlash 1.6s ease-out; }

/* Pequeño dot inline para colorear eventotext en la tabla */
.ev-dot {
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 50%;
  margin-right: 5px;
  vertical-align: middle;
  border: 1px solid rgba(0,0,0,0.15);
}
.detail-header {
  padding: 12px 14px;
  border-bottom: 1px solid var(--color-border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--color-surface-2);
  gap: 8px;
  flex-shrink: 0;
}
.detail-header h3 {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--color-text);
}
.detail-header .veh-color {
  display: inline-block;
  width: 10px; height: 10px;
  border-radius: 50%;
  margin-right: 6px;
  vertical-align: middle;
}
.detail-metrics {
  padding: 10px 14px;
  background: linear-gradient(180deg, var(--color-primary-soft) 0%, transparent 100%);
  border-bottom: 1px solid var(--color-border);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  flex-shrink: 0;
}
.metric {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 8px 10px;
  text-align: center;
}
.metric .metric-label {
  font-size: 10px;
  color: var(--color-text-mute);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  font-weight: 500;
}
.metric .metric-value {
  font-size: 18px;
  font-weight: 700;
  color: var(--color-text);
  margin-top: 2px;
  font-variant-numeric: tabular-nums;
}
.metric.ok .metric-value      { color: var(--color-success); }
.metric.err .metric-value     { color: var(--color-danger); }
.metric.warn .metric-value    { color: var(--color-warning); }
.metric.pending .metric-value { color: var(--color-text-mute); }

.detail-toolbar {
  padding: 10px 14px;
  border-bottom: 1px solid var(--color-border);
  display: flex;
  gap: 6px;
  flex-shrink: 0;
  align-items: center;
}
.detail-toolbar input {
  flex: 1;
  margin: 0;
}
.detail-table-wrap table { font-size: 11.5px; }
.detail-table-wrap th {
  background: var(--color-surface-2);
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  color: var(--color-text-mute);
  padding: 6px 8px;
  white-space: nowrap;
  position: sticky;
  top: 0;
  z-index: 1;
  border-bottom: 1px solid var(--color-border);
}
.detail-table-wrap td {
  padding: 5px 8px;
  border-bottom: 1px solid var(--color-surface-3);
  white-space: nowrap;
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.detail-table-wrap tr:hover td { background: var(--color-surface-2); }

/* ==========================================================
   Typography helpers
   ========================================================== */
h2 {
  margin: 0 0 12px;
  font-size: 16px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}
h2 small {
  color: var(--color-text-mute);
  font-size: 12px;
  font-weight: 500;
  background: var(--color-surface-3);
  padding: 2px 8px;
  border-radius: 999px;
}
h3 {
  margin: 16px 0 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--color-text-2);
  text-transform: uppercase;
  letter-spacing: 0.4px;
}
h3:first-child { margin-top: 0; }

.muted  { color: var(--color-text-mute); }
.dim    { color: var(--color-text-dim); }
.right  { text-align: right; }
.mono   { font-family: var(--font-mono); font-size: 11.5px; }

/* ==========================================================
   Forms
   ========================================================== */
label {
  display: block;
  font-size: 11.5px;
  font-weight: 500;
  color: var(--color-text-2);
  margin: 10px 0 4px;
}

input[type="text"],
input[type="number"],
input[type="url"],
input[type="email"],
input[type="password"],
input[type="date"],
input[type="time"],
select,
textarea {
  width: 100%;
  padding: 7px 10px;
  border: 1px solid var(--color-border-2);
  border-radius: var(--radius);
  font-size: 13px;
  font-family: inherit;
  background: var(--color-surface);
  color: var(--color-text);
  transition: border-color 0.15s, box-shadow 0.15s;
}
input[type="color"] {
  width: 40px; height: 32px;
  padding: 2px;
  border: 1px solid var(--color-border-2);
  border-radius: var(--radius);
  cursor: pointer;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}
input:disabled, select:disabled { background: var(--color-surface-3); color: var(--color-text-mute); }

small.hint, .hint { display: block; font-size: 11px; color: var(--color-text-mute); margin-top: 4px; }

.form-row { display: flex; gap: 8px; }
.form-row > * { flex: 1; min-width: 0; }

.field-group {
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 10px 12px 12px;
  margin-top: 14px;
  background: var(--color-surface-2);
}
.field-group-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--color-text-mute);
  margin-bottom: 2px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.field-group-title::before {
  content: "";
  width: 3px; height: 12px;
  background: var(--color-primary);
  border-radius: 2px;
}

/* ==========================================================
   Buttons
   ========================================================== */
button, .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 7px 12px;
  border: 1px solid var(--color-border-2);
  border-radius: var(--radius);
  background: var(--color-surface);
  color: var(--color-text-2);
  cursor: pointer;
  font-size: 12.5px;
  font-family: inherit;
  font-weight: 500;
  transition: background 0.15s, border-color 0.15s, color 0.15s, transform 0.05s;
  white-space: nowrap;
}
button:hover { background: var(--color-surface-2); border-color: var(--color-border-2); }
button:active { transform: translateY(1px); }
button:disabled { opacity: 0.5; cursor: not-allowed; }
button.primary, .btn-primary {
  background: var(--color-primary);
  color: #fff;
  border-color: var(--color-primary);
}
button.primary:hover { background: var(--color-primary-hover); border-color: var(--color-primary-hover); }
button.danger, .btn-danger {
  background: var(--color-danger);
  color: #fff;
  border-color: var(--color-danger);
}
button.danger:hover { background: var(--color-danger-hover); border-color: var(--color-danger-hover); }
button.success {
  background: var(--color-success);
  color: #fff;
  border-color: var(--color-success);
}
button.ghost {
  background: transparent;
  border-color: transparent;
  color: var(--color-text-mute);
}
button.ghost:hover { background: var(--color-surface-3); color: var(--color-text); }
button.sm  { padding: 4px 8px; font-size: 11.5px; }
button.xs  { padding: 3px 6px; font-size: 11px; }
button.icon { padding: 6px; line-height: 1; width: 28px; height: 28px; }

.btn-row {
  display: flex;
  gap: 6px;
  margin: 10px 0;
  flex-wrap: wrap;
}
.btn-row.compact { gap: 4px; margin: 6px 0; }

/* ==========================================================
   Lists (route points, entornos etc.)
   ========================================================== */
.list {
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  max-height: 360px;
  overflow-y: auto;
  background: var(--color-surface);
}
.list-item {
  padding: 10px 12px;
  border-bottom: 1px solid var(--color-surface-3);
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  gap: 10px;
  transition: background 0.12s;
}
.list-item:hover { background: var(--color-surface-2); }
.list-item.selected {
  background: var(--color-primary-soft);
  border-left: 3px solid var(--color-primary);
  padding-left: 9px;
}
.list-item:last-child { border-bottom: none; }
.list-item > div:first-child { flex: 1; min-width: 0; }
.list-item small { color: var(--color-text-mute); font-size: 11px; display: block; margin-top: 2px; }

/* ==========================================================
   Tables
   ========================================================== */
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
table th {
  background: var(--color-surface-2);
  text-align: left;
  padding: 7px 8px;
  border-bottom: 1px solid var(--color-border);
  font-weight: 600;
  color: var(--color-text-2);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  position: sticky;
  top: 0;
  z-index: 1;
  white-space: nowrap;
}
table td {
  padding: 7px 8px;
  border-bottom: 1px solid var(--color-surface-3);
  vertical-align: middle;
}
table tr:hover td { background: var(--color-surface-2); }
table tr:last-child td { border-bottom: none; }

/* ==========================================================
   Status badges (estado)
   ========================================================== */
.estado {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  border: 1px solid transparent;
  white-space: nowrap;
}
.estado::before {
  content: "";
  width: 6px; height: 6px;
  border-radius: 50%;
  background: currentColor;
}
.estado.idle    { background: var(--color-surface-3); color: var(--color-text-mute); }
.estado.queued  { background: var(--color-surface-3); color: var(--color-text-mute); }
.estado.running { background: var(--color-success-soft); color: #065f46; }
.estado.running::before { animation: pulse 1.2s ease-in-out infinite; }
.estado.paused  { background: var(--color-warning-soft); color: #92400e; }
.estado.done    { background: var(--color-info-soft); color: #1e40af; }
.estado.stopped { background: var(--color-surface-3); color: var(--color-text-mute); }
.estado.error   { background: var(--color-danger-soft); color: #991b1b; }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

/* Progress bar */
.progress-bar {
  display: inline-block;
  width: 80px;
  height: 6px;
  background: var(--color-surface-3);
  border-radius: 999px;
  overflow: hidden;
  vertical-align: middle;
  border: 1px solid var(--color-border);
}
.progress-fill {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--color-primary) 0%, #3b82f6 100%);
  transition: width 0.3s;
  border-radius: 999px;
}
.progress-wrap {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  color: var(--color-text-mute);
}

/* Dot indicator for vehicle color */
.dot {
  display: inline-block;
  width: 10px; height: 10px;
  border-radius: 50%;
  margin-right: 6px;
  vertical-align: middle;
  border: 2px solid #fff;
  box-shadow: 0 0 0 1px rgba(0,0,0,0.1);
}

/* ==========================================================
   Pill indicators (ticks, badges)
   ========================================================== */
.pill {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 600;
  background: var(--color-primary-soft);
  color: var(--color-primary);
  border: 1px solid rgba(37,99,235,0.2);
}
.pill.warn { background: var(--color-warning-soft); color: #92400e; border-color: rgba(245,158,11,0.3); }

/* ==========================================================
   Toasts
   ========================================================== */
#toast-container {
  position: fixed;
  bottom: 20px; right: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 9999;
  max-width: 360px;
}
.toast {
  background: #111827;
  color: #fff;
  padding: 10px 14px;
  border-radius: var(--radius);
  min-width: 220px;
  box-shadow: var(--shadow-lg);
  animation: slideIn 0.2s ease-out;
  font-size: 13px;
  border-left: 3px solid var(--color-primary);
}
.toast.error { border-left-color: var(--color-danger); }
.toast.ok    { border-left-color: var(--color-success); }
@keyframes slideIn { from { transform: translateX(120%); } to { transform: translateX(0); } }

/* ==========================================================
   Modals
   ========================================================== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15,23,42,0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 5000;
  backdrop-filter: blur(4px);
  animation: fadeIn 0.15s ease-out;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  width: 90%;
  max-width: 800px;
  max-height: 90%;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  animation: popIn 0.18s ease-out;
}
@keyframes popIn { from { transform: scale(0.96); opacity: 0; } to { transform: scale(1); opacity: 1; } }

.modal-header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--color-border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--color-surface-2);
}
.modal-header strong { font-size: 14px; font-weight: 600; }
.modal-body {
  padding: 16px;
  overflow-y: auto;
  flex: 1;
}
.modal-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--color-border);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  background: var(--color-surface-2);
}

/* ==========================================================
   Toolbar utilities
   ========================================================== */
.toolbar {
  display: flex;
  gap: 6px;
  padding-bottom: 10px;
  align-items: center;
  flex-wrap: wrap;
}
.toolbar > input[type="text"] { flex: 1; min-width: 180px; }

.divider {
  height: 1px;
  background: var(--color-border);
  margin: 14px 0;
}

.hidden { display: none !important; }

pre.payload-view {
  background: #0f172a;
  color: #e2e8f0;
  padding: 12px 14px;
  border-radius: var(--radius);
  overflow: auto;
  max-height: 60vh;
  font-family: var(--font-mono);
  font-size: 11.5px;
  line-height: 1.5;
}

/* ==========================================================
   Detail panel: destination box
   ========================================================== */
.detail-destino {
  padding: 10px 14px;
  background: var(--color-surface-2);
  border-bottom: 1px solid var(--color-border);
}
.detail-destino-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 4px;
}
.label-mini {
  display: block;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--color-text-mute);
  font-weight: 500;
}

/* Detail tabs are denser */
#detail-tabs { min-height: 36px; overflow-x: auto; }
#detail-tabs .tab-btn { flex: 0 0 auto; padding: 8px 10px; font-size: 12px; }
#detail-tabs .tab-btn [data-close-tab]:hover { opacity: 1 !important; color: var(--color-danger); }

/* Compact table in detail body */
.detail-table-wrap table { font-size: 11px; }
.detail-table-wrap td { padding: 4px 6px; max-width: 120px; }
.detail-table-wrap th { font-size: 10px; padding: 5px 6px; }



/* ==========================================================
   Modo oscuro: html[data-theme="dark"] (botón ☀️/🌙 del encabezado; por defecto, la preferencia del sistema).
   ========================================================== */
:root { color-scheme: light; }
:root[data-theme="dark"] {
  color-scheme: dark;
  --color-bg:        #0b1220;
  --color-surface:   #111a2b;
  --color-surface-2: #16213a;
  --color-surface-3: #1c2942;
  --color-border:    #26324a;
  --color-border-2:  #33415e;

  --color-text:      #e5e9f0;
  --color-text-2:    #c3cad6;
  --color-text-mute: #8d98ab;
  --color-text-dim:  #67728a;

  --color-primary:       #3b82f6;
  --color-primary-hover: #60a5fa;
  --color-primary-soft:  #172554;
  --color-success-soft:  #052e1f;
  --color-warning-soft:  #3a2a06;
  --color-danger-soft:   #3b1010;
  --color-info-soft:     #13233f;

  --shadow-sm:  0 1px 2px 0 rgba(0,0,0,0.4);
  --shadow:     0 1px 3px 0 rgba(0,0,0,0.5);
  --shadow-lg:  0 10px 15px -3px rgba(0,0,0,0.5);
}
:root[data-theme="dark"] .estado.running { color: #6ee7b7; }
:root[data-theme="dark"] .estado.paused,
:root[data-theme="dark"] .pill.warn      { color: #fcd34d; }
:root[data-theme="dark"] .estado.done    { color: #93c5fd; }
:root[data-theme="dark"] .estado.error   { color: #fca5a5; }
/* El mapa: mosaicos de OSM invertidos (calles claras sobre fondo oscuro); marcadores y líneas sin tocar. */
:root[data-theme="dark"] .leaflet-tile-pane { filter: invert(1) hue-rotate(180deg) brightness(0.92) contrast(0.88) saturate(0.6); }
:root[data-theme="dark"] .leaflet-container { background: #0b1220; }
:root[data-theme="dark"] .leaflet-bar a,
:root[data-theme="dark"] .leaflet-control-attribution,
:root[data-theme="dark"] .leaflet-tooltip,
:root[data-theme="dark"] .leaflet-popup-content-wrapper,
:root[data-theme="dark"] .leaflet-popup-tip {
  background: var(--color-surface); color: var(--color-text); border-color: var(--color-border);
}
:root[data-theme="dark"] .leaflet-control-attribution a { color: var(--color-primary-hover); }

.btn-tema {
  background: transparent; border: 1px solid rgba(255,255,255,0.15); color: #e2e8f0;
  padding: 3px 8px; margin-left: 10px; font-size: 14px; line-height: 1; cursor: pointer;
}
.btn-tema:hover { background: rgba(255,255,255,0.08); border-color: rgba(255,255,255,0.3); }

/* Aviso de versión nueva (js/version.js) */
.aviso-version {
  position: fixed; top: 10px; left: 50%; transform: translateX(-50%); z-index: 10000;
  display: flex; align-items: center; gap: 10px; padding: 8px 10px 8px 14px;
  background: var(--color-surface); color: var(--color-text); border: 1px solid var(--color-primary);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); font-size: 13px;
}

/* «▶ Simular»: botones de una sola elección (chips) y listas para elegir con un clic */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  padding: 6px 12px; border-radius: 999px; border: 1px solid var(--color-border-2); background: var(--color-surface);
  color: var(--color-text); font-size: 13px; cursor: pointer;
}
.chip:hover { border-color: var(--color-primary); }
.chip.activo { background: var(--color-primary); border-color: var(--color-primary); color: #fff; }
.chip.ghost { border-style: dashed; color: var(--color-text-mute); }
.lista-sel { margin-top: 6px; max-height: 220px; overflow: auto; border: 1px solid var(--color-border); border-radius: var(--radius); }
.lista-sel:empty { display: none; }
.lista-sel .op { padding: 7px 10px; cursor: pointer; border-bottom: 1px solid var(--color-border); font-size: 13px; }
.lista-sel .op:last-child { border-bottom: 0; }
.lista-sel .op:hover { background: var(--color-surface-2); }
.lista-sel .op.activo { background: var(--color-primary-soft); box-shadow: inset 3px 0 0 var(--color-primary); }
.lista-sel .op small { display: block; }
