:root {
  --bg: #0f172a;
  --bg-soft: #f1f5f9;
  --panel: #ffffff;
  --ink: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --accent: #2563eb;
  --accent-dark: #1d4ed8;
  --urgent: #dc2626;
  --ok: #059669;
  --warn: #d97706;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.06), 0 8px 24px rgba(15, 23, 42, 0.06);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg-soft);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

button {
  font-family: inherit;
  cursor: pointer;
}

a { color: var(--accent); }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: var(--bg);
  color: white;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  white-space: nowrap;
}

.brand-app-nombre {
  font-weight: 700;
  font-size: 1.05rem;
}

/* Logo VOLVO | LYNK&CO · GRUPO Auto Elia, igual que en la web de la
   empresa: barra azul marino con las marcas, una linea de acento, y debajo
   "GRUPO" en gris pequeño + "Auto Elia" en negrita. */
.brand-logo {
  display: inline-block;
  line-height: 1.1;
  font-family: -apple-system, 'Segoe UI', Roboto, Arial, sans-serif;
}
.brand-logo-bar {
  background: #0a1e42;
  color: #fff;
  padding: 4px 12px;
  font-weight: 700;
  font-size: 0.68rem;
  letter-spacing: 0.04em;
  text-align: center;
  white-space: nowrap;
  border-radius: 4px 4px 0 0;
}
.brand-logo-sep { color: #5b7fb8; font-weight: 400; margin: 0 4px; }
.brand-logo-accent { height: 3px; background: linear-gradient(90deg, #0a1e42, #2f6fed); }
.brand-logo-sub {
  text-align: center;
  padding: 3px 10px 5px;
  background: #fff;
  border-radius: 0 0 4px 4px;
}
.brand-logo-grupo { display: block; font-size: 0.5rem; letter-spacing: 0.1em; color: #94a3b8; }
.brand-logo-nombre { display: block; font-size: 0.85rem; font-weight: 700; color: #0f172a; }

.app-footer {
  text-align: center;
  padding: 18px 10px 26px;
  font-size: 0.75rem;
  color: var(--muted);
}

.tabs {
  display: flex;
  gap: 4px;
  flex: 1;
  overflow-x: auto;
}

.tab {
  background: transparent;
  border: none;
  color: #cbd5e1;
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 0.92rem;
  font-weight: 600;
  white-space: nowrap;
}

.tab.active {
  background: var(--accent);
  color: white;
}

.conn-status {
  font-size: 0.7rem;
  color: var(--ok);
}

.conn-status.off { color: var(--urgent); }

.novedades-btn {
  position: relative;
  white-space: nowrap;
}

.novedades-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--urgent);
  border: 2px solid white;
}

main {
  max-width: 1400px;
  margin: 0 auto;
  padding: 16px;
}

.view { display: none; }
.view.active { display: block; }

/* ---------- Oficina ---------- */

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-bottom: 16px;
}

.btn {
  border: none;
  border-radius: 10px;
  padding: 10px 16px;
  font-weight: 600;
  font-size: 0.92rem;
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--ink);
}

.btn.primary { background: var(--accent); color: white; border-color: var(--accent); }
.btn.primary:hover { background: var(--accent-dark); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--urgent); border-color: #fecaca; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.crane-info {
  margin-left: auto;
  font-size: 0.85rem;
  color: var(--muted);
  background: var(--panel);
  border: 1px solid var(--border);
  padding: 8px 12px;
  border-radius: 10px;
}

.section-title {
  margin: 4px 0 8px;
  font-size: 0.95rem;
  color: var(--muted);
  font-weight: 700;
}

.agenda-toolbar {
  margin-bottom: 6px;
}

.agenda-hint {
  color: var(--muted);
  font-size: 0.8rem;
  margin: -2px 0 8px;
}

.board {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(230px, 1fr);
  gap: 12px;
  overflow-x: auto;
  padding-bottom: 8px;
}

/* Tablero compacto: vive junto a la Agenda en la misma página, así que
   reducimos tarjetas y limitamos la altura con scroll interno por columna. */
.board.board-compact {
  grid-auto-columns: minmax(168px, 1fr);
  gap: 8px;
  padding-bottom: 4px;
  margin-bottom: 20px;
}

.board.board-compact .column-body {
  max-height: 320px;
  overflow-y: auto;
  gap: 6px;
  padding: 6px;
}

.board.board-compact .column-head {
  padding: 6px 8px;
  font-size: 0.78rem;
}

.board.board-compact .card {
  padding: 6px 8px;
  font-size: 0.72rem;
}

.board.board-compact .card.vehicle-card {
  padding-bottom: 12px;
}

.board.board-compact .card.vehicle-card .row1 { font-size: 0.78rem; }

.board.board-compact .card .dest { font-size: 0.66rem; margin-top: 1px; }

.board.board-compact .card .tags { margin-top: 4px; gap: 3px; }

.board.board-compact .tag { font-size: 0.6rem; padding: 1px 5px; }

.board.board-compact .card .actions { margin-top: 4px; gap: 4px; }
.board.board-compact .card .actions button { font-size: 0.66rem; }

.board.board-compact .card.vehicle-card::after {
  bottom: 4px;
  left: 12px;
  width: 5px;
  height: 5px;
  box-shadow: 20px 0 0 var(--muted);
}

/* Bloque "En tránsito": coches cuyo viaje ya está confirmado en la Agenda,
   agrupados por viaje en vez de por centro de origen. */
#transitoWrap { margin-bottom: 20px; }

.column.column-transito {
  border: 1px solid #fca5a5;
}

.column-head-transito {
  background: #fef2f2 !important;
  color: #b91c1c !important;
}

.card.vehicle-transito {
  border-left: 4px solid #dc2626;
  opacity: 1;
}

.column {
  background: var(--panel);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  min-height: 200px;
  display: flex;
  flex-direction: column;
}

.column-head {
  padding: 10px 12px;
  font-weight: 700;
  border-bottom: 1px solid var(--border);
  border-radius: var(--radius) var(--radius) 0 0;
  color: white;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.9rem;
}

.column-body {
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
  min-height: 60px;
}

.column-body.dragover { background: #eef2ff; }

.card {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 0.85rem;
  cursor: grab;
}

.card:active { cursor: grabbing; }

.card.vehicle-card {
  border-left: 4px solid var(--accent);
  position: relative;
  padding-bottom: 16px;
}

.card.vehicle-card .row1 { font-size: 0.95rem; display: flex; justify-content: space-between; align-items: center; }

/* Ya aparece en algun viaje de la Agenda pero todavia no se ha confirmado */
.card.vehicle-card.agenda-tentativa { opacity: 0.55; }

.tag-agenda { font-size: 0.75rem; }

.card.vehicle-card::after {
  content: '';
  position: absolute;
  bottom: 6px;
  left: 16px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--muted);
  opacity: 0.35;
  box-shadow: 26px 0 0 var(--muted);
}

.card .row1 {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
  font-weight: 700;
}

.card .dest {
  font-size: 0.78rem;
  color: var(--muted);
  margin-top: 2px;
}

/* Punto de color junto al destino: mismo color que la franja izquierda de
   la ficha y que la columna de esa sede en Ajustes → Centros. Se repite
   (en vez de fiarse solo del borde) porque en listas sin ese borde (o con
   fondo distinto) sigue dejando claro a que sede va el coche. */
.dest-color-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 5px;
  vertical-align: middle;
}

.card .tags {
  display: flex;
  gap: 4px;
  margin-top: 6px;
  flex-wrap: wrap;
}

.tag {
  font-size: 0.68rem;
  padding: 2px 6px;
  border-radius: 999px;
  font-weight: 700;
  background: #e2e8f0;
  color: var(--muted);
}

.tag.urgente { background: #fee2e2; color: var(--urgent); }
.tag.taller { background: #fef3c7; color: var(--warn); }
.tag.otros { background: #ede9fe; color: #6d28d9; }
.tag.venta { background: #dbeafe; color: var(--accent-dark); }
.tag.incidencia { background: #fee2e2; color: var(--urgent); }

.card .actions {
  display: flex;
  gap: 6px;
  margin-top: 6px;
}

.card .actions button {
  border: none;
  background: none;
  font-size: 0.75rem;
  color: var(--muted);
  padding: 2px 4px;
}
.card .actions button:hover { color: var(--ink); }

.route-drawer {
  margin-top: 4px;
  background: var(--panel);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 10px 16px;
}

.route-drawer > summary {
  cursor: pointer;
  font-weight: 700;
  list-style: none;
}

.route-drawer > summary::-webkit-details-marker { display: none; }

.route-panel {
  margin-top: 14px;
  padding: 0;
}

.route-panel h3 { margin: 0 0 10px; font-size: 1rem; }

.notif-badge {
  display: inline-block;
  background: var(--urgent);
  color: white;
  border-radius: 999px;
  padding: 1px 8px;
  font-size: 0.75rem;
  font-weight: 700;
  margin-left: 6px;
}

.notif-item {
  padding: 8px 10px;
  border-radius: 10px;
  margin-bottom: 6px;
  background: var(--bg-soft);
  font-size: 0.85rem;
}

.notif-item.notif-nueva { background: #eff6ff; border: 1px solid #bfdbfe; cursor: pointer; }

.notif-item[data-detalle-id] { cursor: pointer; transition: background 0.12s ease; }
.notif-item[data-detalle-id]:hover { background: #eef2ff; }

.notif-linea { font-weight: 600; }

.notif-meta { color: var(--muted); font-size: 0.75rem; margin-top: 2px; }

.veh-ficha-linea { font-size: 0.8rem; color: #475569; margin-top: 2px; }

/* Ficha de vehiculo en una sola fila (histórico de altas / preentrega):
   todos los datos en linea con separadores visuales, y solo pasan a la
   linea siguiente si la pantalla es demasiado estrecha para caber. */
.notif-item.veh-fila {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  column-gap: 12px;
  row-gap: 2px;
  padding: 6px 10px;
  font-size: 0.78rem;
}
.veh-fila .veh-dato { white-space: nowrap; }
.veh-fila .veh-dato:first-child { font-size: 0.82rem; }
.veh-fila .veh-dato-meta { color: var(--muted); margin-left: auto; }
.veh-fila .badge-pre { margin-left: 0; }

.badge-pre {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  margin-left: 6px;
  white-space: nowrap;
}
.badge-pre-ok { background: #dcfce7; color: #15803d; }
.badge-pre-warn { background: #fef3c7; color: #b45309; }

.filtro-listado {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 10px;
  padding: 8px;
  background: var(--bg-soft);
  border-radius: 10px;
}
.filtro-listado input[type="text"] {
  flex: 1 1 180px;
  min-width: 140px;
  padding: 6px 10px;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  font-size: 0.82rem;
}
.filtro-listado label {
  font-size: 0.75rem;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 4px;
}
.filtro-listado input[type="date"] {
  padding: 5px 6px;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  font-size: 0.78rem;
}
.filtro-listado .btn { margin-left: auto; font-size: 0.78rem; padding: 6px 12px; }

/* ---- Detalle de vehiculo (modal) ---- */
.detalle-veh-sec { margin-bottom: 14px; }
.detalle-veh-sec h4 { margin: 0 0 6px; font-size: 0.82rem; text-transform: uppercase; letter-spacing: 0.03em; color: var(--muted); }
.detalle-veh-linea { font-size: 0.92rem; margin-bottom: 3px; }
.detalle-veh-linea b { font-weight: 600; }
.detalle-veh-hito { display: flex; gap: 8px; align-items: flex-start; padding: 6px 0; border-bottom: 1px dashed #e2e8f0; }
.detalle-veh-hito:last-child { border-bottom: none; }
.detalle-veh-hito .punto { font-size: 1.1rem; line-height: 1.3; }
.detalle-veh-hito.pendiente { opacity: 0.45; }

#routeList {
  margin: 0;
  padding-left: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

#routeList li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: var(--bg-soft);
  border-radius: 8px;
  font-size: 0.88rem;
}

#routeList li .idx {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.72rem;
  font-weight: 700;
  flex-shrink: 0;
}

.history {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.history-head { font-weight: 600; font-size: 0.88rem; margin-bottom: 6px; }

#historyList { font-size: 0.85rem; color: var(--muted); margin: 0; padding-left: 18px; }

/* ---------- Conductor ---------- */

.driver-wrap {
  max-width: 480px;
  margin: 0 auto;
}

.driver-name {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
}

.driver-name input {
  flex: 1;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
}

.current-task {
  background: var(--panel);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 20px;
  text-align: center;
}

.current-task .kind {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 800;
  color: var(--accent);
}

.current-task.entregar .kind { color: var(--ok); }

.current-task .center {
  font-size: 1.6rem;
  font-weight: 800;
  margin: 6px 0;
}

.current-task .matricula {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--ink);
}

.current-task .modelo {
  color: var(--muted);
  font-size: 0.9rem;
  margin-bottom: 10px;
}

.current-task .notas {
  font-size: 0.85rem;
  background: var(--bg-soft);
  border-radius: 8px;
  padding: 8px;
  margin-top: 10px;
  text-align: left;
}

.big-btn {
  width: 100%;
  padding: 18px;
  font-size: 1.15rem;
  font-weight: 800;
  border-radius: 14px;
  border: none;
  background: var(--ok);
  color: white;
  margin-top: 16px;
}

.big-btn.recoger { background: var(--accent); }

/* ---------- Conductor: grúa (carga en curso + staging) ---------- */

.crane-panel {
  background: var(--panel);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 14px 16px;
  margin-bottom: 16px;
  /* Se queda fijo/visible al hacer scroll: el resto (sedes con coches
     pendientes) se desplaza por debajo. --topbar-h lo calcula app.js segun
     la altura real de la barra superior, para que encaje justo debajo. */
  position: sticky;
  top: var(--topbar-h, 56px);
  z-index: 5;
}

.crane-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}

.crane-panel-head h4 { margin: 0; font-size: 0.95rem; }

.crane-loc { font-weight: 400; color: var(--muted); font-size: 0.82rem; }

.crane-actions { display: flex; gap: 8px; }
.crane-actions .btn { font-size: 0.8rem; padding: 8px 10px; }

.crane-panel-head h4 #btnCambiarUbicacionGrua { font-size: 0.75rem; padding: 3px 7px; vertical-align: middle; }

.viaje-observaciones-input {
  width: 100%;
  box-sizing: border-box;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  margin-bottom: 8px;
  font-size: 0.85rem;
}

.ultimo-albaran { margin-bottom: 10px; }

.modal-firma { max-width: 520px; }

.modal-novedades { max-width: 480px; }

.novedades-lista {
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: 55vh;
  overflow-y: auto;
  margin: 12px 0;
  padding-right: 4px;
}

.novedad-item {
  border-left: 3px solid var(--primary, #2563eb);
  padding: 4px 0 4px 12px;
}

.novedad-fecha {
  font-size: 0.72rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.novedad-titulo {
  font-weight: 700;
  font-size: 0.92rem;
  color: #0f172a;
  margin: 2px 0 3px;
}

.novedad-texto {
  font-size: 0.85rem;
  color: #334155;
  line-height: 1.4;
}

.firma-canvas {
  width: 100%;
  height: 220px;
  display: block;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #ffffff;
  touch-action: none;
  cursor: crosshair;
}

.crane-loc-editor {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  margin: -4px 0 10px;
  padding: 8px;
  background: var(--bg-soft, #f1f5f9);
  border-radius: 8px;
}
.crane-loc-editor select { flex: 1; min-width: 160px; }

.crane-slots {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 8px;
}

.crane-slot {
  border-radius: 12px;
  padding: 8px 10px;
  min-height: 74px;
  border: 1px solid var(--border);
  font-size: 0.78rem;
}

.crane-slot.vacio {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  background: var(--bg-soft);
  border-style: dashed;
}

.crane-slot.lleno { background: #ecfdf5; border-color: #a7f3d0; }
.crane-slot.staged { background: #eff6ff; border-color: #bfdbfe; border-style: dashed; }

.crane-slot .row1 { font-weight: 700; }
.crane-slot .dest { color: var(--muted); margin-top: 2px; }

.crane-slot-actions { display: flex; gap: 6px; margin-top: 6px; }
.crane-slot-actions button {
  border: 1px solid var(--border);
  background: white;
  border-radius: 8px;
  padding: 4px 6px;
  font-size: 0.72rem;
  color: var(--ink);
}

/* ---------- Conductor: sedes con coches pendientes ---------- */

.sedes-panel h4 { margin-bottom: 4px; font-size: 0.95rem; }
.sedes-hint { font-weight: 400; color: var(--muted); font-size: 0.75rem; }

.sede-block {
  background: var(--panel);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 10px 12px;
  margin-bottom: 12px;
}

.sede-block.sede-disabled { opacity: 0.45; }

.sede-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-left: 4px solid var(--border);
  padding-left: 8px;
  font-weight: 700;
  font-size: 0.9rem;
  margin-bottom: 8px;
}

.sede-count { font-weight: 400; color: var(--muted); font-size: 0.78rem; }

.sede-coches {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 8px;
}

.sede-coche {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 0.78rem;
  cursor: pointer;
}

.sede-coche .row1 { font-weight: 700; display: flex; justify-content: space-between; }
.sede-coche .dest { color: var(--muted); margin-top: 2px; }
.sede-coche .tags { margin-top: 4px; display: flex; gap: 4px; flex-wrap: wrap; }

.sede-coche.seleccionado { background: #eff6ff; border-color: var(--accent); }

.sedes-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 4px;
}

.sedes-panel-head h4 { margin: 0; }

#filtroDestinoConductor {
  padding: 6px 8px;
  border-radius: 8px;
  border: 1px solid var(--border);
  font-size: 0.78rem;
  max-width: 220px;
}

/* ---------- Conductor: panel "he llegado a destino" ---------- */

.llegada-panel {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.llegada-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
  font-size: 0.88rem;
}

.llegada-grupo {
  background: var(--bg-soft);
  border-radius: 10px;
  padding: 8px 10px;
  margin-bottom: 8px;
}

.llegada-grupo-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.85rem;
  margin-bottom: 6px;
}

.llegada-grupo-head .btn { font-size: 0.72rem; padding: 4px 8px; }

.llegada-fila {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
  font-size: 0.82rem;
  cursor: pointer;
}

.llegada-fila input { width: auto; }

/* ---------- Conductor: bloquear agenda ---------- */

.bloqueo-conductor {
  max-width: 480px;
  margin: 16px auto 0;
  background: var(--panel);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 14px 16px;
}

.bloqueo-conductor h4 { margin: 0 0 10px; font-size: 0.95rem; }

.alta-urgente-conductor {
  max-width: 480px;
  margin: 16px auto 24px;
  background: #fff7ed;
  border: 1px solid #fed7aa;
  border-radius: 18px;
  padding: 14px 16px;
}
.alta-urgente-conductor .field-hint { margin: 8px 0 0; }

.bloqueo-conductor-quick {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.bloqueo-conductor-quick input[type="date"] {
  padding: 8px;
  border-radius: 8px;
  border: 1px solid var(--border);
  font-size: 0.8rem;
}

.bloqueo-conductor-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-soft);
  border-radius: 8px;
  padding: 6px 10px;
  margin-bottom: 6px;
  font-size: 0.82rem;
}

.bloqueo-conductor-item .btn { font-size: 0.72rem; padding: 4px 8px; }

/* ---------- Oficina: histórico real de viajes ---------- */

.viaje-hist-item {
  background: var(--bg-soft);
  border-radius: 10px;
  padding: 8px 10px;
  margin-bottom: 6px;
  font-size: 0.82rem;
}

.viaje-hist-linea { font-weight: 600; }
.viaje-hist-coches { color: var(--muted); font-size: 0.78rem; margin-top: 2px; }
.viaje-hist-item .btn { margin-top: 6px; font-size: 0.75rem; padding: 4px 8px; }

/* ---------- Añadir vehículo (pestaña simple) ---------- */

.alta-wrap {
  max-width: 480px;
  margin: 0 auto;
}

/* En pantallas de ordenador (la mayoria de usos reales) se aprovecha mas
   ancho para que el formulario respire y los desplegables no queden
   apretados; en movil (por debajo de 700px) se queda en una sola columna
   estrecha como hasta ahora. */
@media (min-width: 700px) {
  .alta-wrap { max-width: 760px; }
}

.alta-wrap #formAlta {
  background: var(--panel);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 20px;
}

.alta-lista { margin-top: 16px; }

.alta-lista-titulo {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--muted);
  margin-bottom: 8px;
}

.alta-lista-item {
  background: var(--panel);
  border-radius: 10px;
  padding: 8px 12px;
  margin-bottom: 6px;
  font-size: 0.88rem;
  box-shadow: var(--shadow);
}

.secondary-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.secondary-actions button {
  flex: 1;
  padding: 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: white;
  font-size: 0.85rem;
  color: var(--muted);
}

.empty-state {
  text-align: center;
  color: var(--muted);
  padding: 40px 20px;
  background: var(--panel);
  border-radius: 18px;
  box-shadow: var(--shadow);
}

.upcoming {
  margin-top: 18px;
}

.upcoming h4 {
  font-size: 0.85rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.upcoming ul {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.upcoming li {
  background: var(--panel);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 0.85rem;
  display: flex;
  justify-content: space-between;
  box-shadow: var(--shadow);
}

/* ---------- Ajustes ---------- */

.settings-grid {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
}

.settings-card {
  background: var(--panel);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
}

.settings-card h3 { margin-top: 0; }

.center-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}

.center-row-top, .center-row-detalle {
  display: flex;
  gap: 8px;
  align-items: center;
}

.center-row-detalle input[type="text"] {
  font-size: 0.8rem;
  padding: 6px 9px;
}

.center-row input[type="text"] {
  flex: 1;
  padding: 7px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
}

.center-row input[type="color"] {
  width: 34px;
  height: 34px;
  border: 2px solid var(--border);
  border-radius: 8px;
  padding: 0;
  cursor: pointer;
}
.center-row input[type="color"]:hover { border-color: var(--muted); }

table.matrix {
  border-collapse: collapse;
  font-size: 0.78rem;
  width: 100%;
}

table.matrix th, table.matrix td {
  border: 1px solid var(--border);
  padding: 4px;
  text-align: center;
}

table.matrix input {
  width: 48px;
  text-align: center;
  border: none;
  background: transparent;
  font-size: 0.78rem;
}

/* ---------- Modal ---------- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 16px;
}

.modal-backdrop.open { display: flex; }

.modal {
  background: white;
  border-radius: 16px;
  padding: 20px;
  width: 100%;
  max-width: 420px;
  max-height: 90vh;
  overflow-y: auto;
}

.modal h3 { margin-top: 0; }

.field { margin-bottom: 12px; }

.field label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  margin-bottom: 4px;
  color: var(--muted);
}

.field input, .field select, .field textarea {
  width: 100%;
  padding: 9px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  font-size: 0.92rem;
}

.field-row { display: flex; gap: 10px; }
.field-row .field { flex: 1; }

.field-hint { color: var(--muted); font-size: 0.76rem; margin: 4px 0 0; }

/* ---------- Ajustes: destinatarios de avisos ---------- */

.switch-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.88rem;
  font-weight: 600;
  margin-bottom: 12px;
  cursor: pointer;
}

.switch-row input { width: auto; }

.destinatarios-lista { margin-bottom: 14px; }

.destinatario-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 10px;
  background: var(--bg-soft);
  margin-bottom: 6px;
}

.destinatario-info { flex: 1; display: flex; flex-direction: column; }
.destinatario-info span { color: var(--muted); font-size: 0.78rem; }

.destinatario-row .btn { padding: 6px 10px; font-size: 0.8rem; }

.usuarios-lista { margin-bottom: 14px; }

.usuario-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 10px;
  background: var(--bg-soft);
  margin-bottom: 6px;
}

.usuario-row.inactivo { opacity: 0.55; }

.usuario-info { flex: 1; display: flex; flex-direction: column; }
.usuario-info span { color: var(--muted); font-size: 0.78rem; }

.usuario-rol-badge {
  font-size: 0.72rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--panel);
  border: 1px solid var(--border);
}
.usuario-rol-badge.admin { color: #2563eb; border-color: #2563eb; }
.usuario-rol-badge.administracion { color: #7c3aed; border-color: #7c3aed; }
.usuario-rol-badge.comercial { color: #d97706; border-color: #d97706; }
.usuario-rol-badge.conductor { color: #059669; border-color: #059669; }

.usuario-row .btn { padding: 6px 10px; font-size: 0.8rem; }

.usuarios-import {
  margin-top: 12px;
  border-top: 1px solid var(--border);
  padding-top: 10px;
}

.usuarios-import summary {
  cursor: pointer;
  font-weight: 600;
  font-size: 0.88rem;
  color: var(--muted);
}

.usuarios-import textarea {
  width: 100%;
  box-sizing: border-box;
  font-family: monospace;
  font-size: 0.78rem;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  margin: 8px 0;
  resize: vertical;
}

#uImportResultado {
  font-size: 0.82rem;
  color: var(--muted);
  margin-top: 8px;
}

/* ---------------- pantalla de acceso (bloquea toda la app) ---------------- */

.auth-gate {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: var(--bg, #0f172a);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  box-sizing: border-box;
}

.auth-gate-box {
  max-width: 420px;
  width: 100%;
  background: var(--panel);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 32px 28px;
  text-align: center;
}

.auth-gate-logo { font-size: 2.6rem; margin-bottom: 6px; }

.auth-gate-box h2 { margin: 0 0 16px; font-size: 1.15rem; }

.auth-gate-box p { color: var(--muted); font-size: 0.9rem; line-height: 1.5; }

.auth-gate-box .btn { width: 100%; margin-top: 10px; }

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}

#toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg);
  color: white;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 0.85rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  z-index: 100;
}

#toast.show { opacity: 1; }

@media (max-width: 640px) {
  .brand { font-size: 0.9rem; }
  .tab { padding: 6px 10px; font-size: 0.82rem; }
}

.route-summary {
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 10px;
  padding: 8px 10px;
  background: var(--bg-soft);
  border-radius: 8px;
}

.route-summary.warn {
  color: var(--urgent);
  background: #fee2e2;
  font-weight: 600;
}

.route-sugerencia-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}
.route-sugerencia-actions .btn { flex: 1; }

/* ---------- Conductor: filtro por sede + sin resultados ---------- */

.sede-filtro {
  width: 100%;
  margin-bottom: 8px;
  padding: 6px 8px;
  border-radius: 8px;
  border: 1px solid var(--border);
  font-size: 0.76rem;
  color: var(--muted);
}

.sede-sin-resultado {
  color: var(--muted);
  font-size: 0.8rem;
  padding: 8px 0;
  text-align: center;
}

.bloqueo-conductor-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}
.bloqueo-conductor-head h4 { margin: 0; }

/* ---------- Alta: identidad del dispositivo ---------- */

.alta-identidad {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--panel);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 10px 14px;
  margin-bottom: 12px;
  font-weight: 600;
  font-size: 0.88rem;
}

.alta-identidad-elegir {
  background: var(--panel);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 14px;
  margin-bottom: 12px;
}

.alta-identidad-login {
  background: var(--panel);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 14px;
  margin-bottom: 12px;
  text-align: center;
}

.alta-identidad-login .btn {
  width: 100%;
}

.alta-identidad-login .field-hint {
  margin-top: 8px;
  margin-bottom: 0;
}

.alta-identidad-elegir label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--muted);
}

.alta-identidad-elegir select {
  padding: 9px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  font-size: 0.92rem;
}

#routeList li .hora {
  font-size: 0.72rem;
  color: var(--muted);
  white-space: nowrap;
}

/* ---------- Descanso (conductor) ---------- */

.descanso-bar {
  background: #fef3c7;
  color: #92400e;
  border-radius: 12px;
  padding: 12px 16px;
  margin-bottom: 14px;
  text-align: center;
  font-size: 0.9rem;
}

.descanso-bar button {
  display: block;
  width: 100%;
  margin-top: 8px;
  padding: 10px;
  border: none;
  border-radius: 10px;
  background: #92400e;
  color: white;
  font-weight: 700;
}

/* ---------- Agenda ---------- */

.agenda-label {
  font-weight: 700;
  font-size: 0.95rem;
  min-width: 160px;
  text-align: center;
  text-transform: capitalize;
}

.agenda-week {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
  overflow-x: auto;
}

.agenda-col {
  background: var(--panel);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  min-height: 200px;
  display: flex;
  flex-direction: column;
}

.agenda-col-head {
  padding: 10px;
  text-align: center;
  font-weight: 700;
  font-size: 0.82rem;
  border-bottom: 1px solid var(--border);
  color: var(--muted);
}

.agenda-col-head span { font-weight: 400; }

.agenda-col.bloqueado { opacity: 0.7; }

.agenda-col-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 6px 8px;
  border-bottom: 1px solid var(--border);
}

.chip {
  border: 1px solid var(--border);
  background: var(--bg-soft);
  color: var(--muted);
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 0.68rem;
  font-weight: 700;
  cursor: pointer;
}

.chip-bloqueo { background: #fee2e2; color: var(--urgent); border-color: #fecaca; }
.chip-externa { background: #dbeafe; color: var(--accent-dark); border-color: #bfdbfe; }

.agenda-col-head.hoy { background: #dbeafe; color: var(--accent-dark); border-radius: var(--radius) var(--radius) 0 0; }

.agenda-col-body {
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
  min-height: 80px;
}

.agenda-col-body.dragover { background: #eef2ff; }

.agenda-empty {
  color: var(--muted);
  font-size: 0.78rem;
  text-align: center;
  padding: 12px 0;
}

/* Agenda compacta: comparte página con el tablero de vehículos */
.agenda-week.agenda-compact {
  gap: 6px;
}

.agenda-week.agenda-compact .agenda-col { min-height: 120px; }

.agenda-week.agenda-compact .agenda-col-body {
  max-height: 320px;
  overflow-y: auto;
  gap: 6px;
  padding: 6px;
  min-height: 60px;
}

.agenda-week.agenda-compact .agenda-col-head { padding: 6px; font-size: 0.72rem; }
.agenda-week.agenda-compact .agenda-col-tools { padding: 4px 6px; }

.agenda-week.agenda-compact .viaje-card { padding: 6px; }
.agenda-week.agenda-compact .viaje-head { font-size: 0.72rem; }
.agenda-week.agenda-compact .viaje-horario { font-size: 0.64rem; margin: 2px 0 4px; }
.agenda-week.agenda-compact .viaje-vehiculo { padding: 4px 6px; font-size: 0.68rem; }
.agenda-week.agenda-compact .viaje-vehiculo .dest { font-size: 0.62rem; }
.agenda-week.agenda-compact .viaje-vehiculos { gap: 4px; }
.agenda-week.agenda-compact .viaje-actions { margin-top: 5px; }
.agenda-week.agenda-compact .btn-viaje-confirmar,
.agenda-week.agenda-compact .btn-viaje-desconfirmar { font-size: 0.62rem; padding: 3px 8px; }

.agenda-card {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 0.82rem;
  cursor: grab;
}

.agenda-card .row1 {
  display: flex;
  justify-content: space-between;
  font-weight: 700;
}

.agenda-card .dest {
  font-size: 0.75rem;
  color: var(--muted);
  margin: 3px 0;
}

.agenda-card .tags {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  margin-bottom: 4px;
}

.agenda-unpin {
  border: none;
  background: none;
  color: var(--muted);
  font-size: 0.72rem;
  padding: 2px 0;
}

.viaje-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px;
  box-shadow: var(--shadow);
}

.viaje-card.viaje-externa { border-color: #bfdbfe; background: #f5f9ff; }
.viaje-card.viaje-manual { border-left: 3px solid var(--accent); }

.viaje-card.viaje-confirmado {
  border-color: #fca5a5;
  border-left: 3px solid #dc2626;
  background: #fef2f2;
}

.viaje-card.viaje-confirmado .viaje-num { color: #b91c1c; }

.viaje-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.8rem;
  font-weight: 700;
}

.viaje-num { color: var(--ink); }

.viaje-ocupacion {
  background: var(--bg-soft);
  border-radius: 999px;
  padding: 1px 8px;
  font-size: 0.72rem;
  color: var(--muted);
}

.viaje-horario {
  font-size: 0.72rem;
  color: var(--muted);
  margin: 3px 0 6px;
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  align-items: center;
}

.viaje-warn {
  color: var(--urgent);
  font-weight: 700;
}

.viaje-ruta-resumen {
  font-size: 0.7rem;
  color: var(--accent-dark);
  font-weight: 700;
  margin: 0 0 4px;
}

.viaje-paradas {
  margin-bottom: 6px;
  font-size: 0.68rem;
  color: var(--muted);
}

.viaje-paradas summary {
  cursor: pointer;
  font-weight: 600;
}

.viaje-paradas ol {
  margin: 4px 0 0;
  padding-left: 16px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.viaje-paradas li b { color: var(--ink); }

.viaje-paradas .parada-recoge,
.viaje-paradas .parada-entrega {
  display: block;
  margin-left: 8px;
}

.viaje-paradas .parada-recoge { color: #059669; }
.viaje-paradas .parada-entrega { color: #b45309; }

.viaje-vehiculos {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.viaje-vehiculo {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 8px;
  font-size: 0.78rem;
  cursor: grab;
}

.viaje-vehiculo .row1 {
  display: flex;
  justify-content: space-between;
  font-weight: 700;
}

.viaje-vehiculo .dest {
  font-size: 0.72rem;
  color: var(--muted);
  margin: 2px 0;
}

.viaje-vehiculo .tags {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.viaje-actions {
  margin-top: 8px;
  display: flex;
  justify-content: flex-end;
}

.btn-viaje-confirmar,
.btn-viaje-desconfirmar {
  border: none;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 0.72rem;
  font-weight: 700;
  cursor: pointer;
}

.btn-viaje-confirmar {
  background: var(--accent);
  color: #fff;
}

.btn-viaje-desconfirmar {
  background: #fff;
  color: #b91c1c;
  border: 1px solid #fca5a5;
}

.agenda-month {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
}

.agenda-month-head {
  text-align: center;
  font-weight: 700;
  font-size: 0.78rem;
  color: var(--muted);
  padding: 4px 0;
}

.agenda-month-cell {
  background: var(--panel);
  border-radius: 10px;
  box-shadow: var(--shadow);
  min-height: 64px;
  padding: 6px;
  font-size: 0.75rem;
}

.agenda-month-cell.finde { background: var(--bg-soft); box-shadow: none; }
.agenda-month-cell.hoy { outline: 2px solid var(--accent); }
.agenda-month-cell.bloqueado { background: #fee2e2; box-shadow: none; }

.agenda-month-cell .daynum { font-weight: 700; color: var(--muted); }

.agenda-month-cell .count {
  margin-top: 4px;
  display: inline-block;
  background: #dbeafe;
  color: var(--accent-dark);
  border-radius: 999px;
  padding: 1px 7px;
  font-weight: 700;
}

.agenda-month-cell .count.bloqueo { background: #fecaca; color: var(--urgent); margin-right: 3px; }
.agenda-month-cell .count.externa { background: #bfdbfe; color: var(--accent-dark); margin-right: 3px; }

@media (max-width: 800px) {
  .agenda-week { grid-template-columns: repeat(5, minmax(150px, 1fr)); }
}
