/* ===================== Variables & reset ===================== */
:root {
  --bg: #f2f4f9;
  --bg-elevated: #ffffff;
  --bg-inset: #eef1f8;
  --text: #10182b;
  --text-muted: #64748b;
  --border: #e2e6f0;
  --primary: #2563eb;
  --primary-contrast: #ffffff;
  --accent: #0d9488;
  --danger: #dc2626;
  --danger-bg: #fee2e2;
  --shadow: rgba(15, 23, 42, 0.08);
  --radius-lg: 18px;
  --radius-md: 12px;
  --radius-sm: 8px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

/* Modo oscuro automático (sigue al sistema) cuando el usuario no ha elegido
   uno explícitamente con el botón del icono de tema del encabezado. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0a0f1c;
    --bg-elevated: #141c2e;
    --bg-inset: #101827;
    --text: #e7ebf3;
    --text-muted: #8b96ab;
    --border: #232e47;
    --primary: #3b82f6;
    --primary-contrast: #071021;
    --accent: #2dd4bf;
    --danger: #f87171;
    --danger-bg: #3a1414;
    --shadow: rgba(0, 0, 0, 0.45);
  }
}

/* Modo oscuro/claro forzado explícitamente por el usuario, gane o no al sistema. */
:root[data-theme="dark"] {
  --bg: #0a0f1c;
  --bg-elevated: #141c2e;
  --bg-inset: #101827;
  --text: #e7ebf3;
  --text-muted: #8b96ab;
  --border: #232e47;
  --primary: #3b82f6;
  --primary-contrast: #071021;
  --accent: #2dd4bf;
  --danger: #f87171;
  --danger-bg: #3a1414;
  --shadow: rgba(0, 0, 0, 0.45);
}

:root[data-theme="light"] {
  --bg: #f2f4f9;
  --bg-elevated: #ffffff;
  --bg-inset: #eef1f8;
  --text: #10182b;
  --text-muted: #64748b;
  --border: #e2e6f0;
  --primary: #2563eb;
  --primary-contrast: #ffffff;
  --accent: #0d9488;
  --danger: #dc2626;
  --danger-bg: #fee2e2;
  --shadow: rgba(15, 23, 42, 0.08);
}

* { box-sizing: border-box; }

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

/* Transición suave de colores al cambiar de tema (claro/oscuro/automático). */
html, body, .app-header, .tabbar, .card, .day-card, .day-card-header, .history-item,
.modal-box, .modal-header, .item-row, .trip-row, .input, .checkbox-row, .theme-toggle-btn,
.wizard-option, .wizard-chip, .wizard-dot, .summary-item, .debt-item, .multi-select-bar {
  transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease;
}

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

body {
  padding-top: calc(var(--safe-top) + 64px);
  padding-bottom: calc(var(--safe-bottom) + 78px);
  min-height: 100vh;
  overflow-x: hidden;
  /* Fondo con un poco de profundidad: un resplandor suave del color de marca
     arriba (fijo, no se mueve al hacer scroll) sobre el color de fondo plano. */
  background-color: var(--bg);
  background-image:
    radial-gradient(900px 480px at 50% -8%, color-mix(in srgb, var(--primary) 16%, transparent), transparent 65%),
    radial-gradient(700px 420px at 100% 110%, color-mix(in srgb, var(--accent) 10%, transparent), transparent 60%);
  background-repeat: no-repeat;
  background-attachment: fixed, fixed;
}

h1, h2, h3 { margin: 0; }

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

.hidden { display: none !important; }

/* ===================== Header ===================== */
.app-header {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: calc(var(--safe-top) + 10px) 16px 10px;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
}

.app-header-title { display: flex; align-items: center; gap: 8px; }
.app-logo { font-size: 22px; }
.app-header h1 { font-size: 18px; font-weight: 700; }

.app-header-actions { display: flex; align-items: center; gap: 8px; }

.theme-toggle-btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--bg-inset);
  color: var(--text);
  font-size: 16px;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: transform 0.2s ease, background-color 0.2s ease;
}
.theme-toggle-btn:active { transform: scale(0.88) rotate(-10deg); }

.lock-now-btn { width: 34px; height: 34px; font-size: 15px; border: 1px solid var(--border); }

.period-badge {
  font-size: 12px;
  font-weight: 600;
  color: var(--primary);
  background: color-mix(in srgb, var(--primary) 14%, transparent);
  padding: 5px 10px;
  border-radius: 999px;
  white-space: nowrap;
  transition: background-color 0.2s ease, color 0.2s ease;
}

.ios-banner {
  position: sticky;
  top: calc(var(--safe-top) + 64px);
  z-index: 15;
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--accent);
  color: #06251f;
  padding: 10px 14px;
  font-size: 13px;
  line-height: 1.4;
}
.ios-banner .icon-btn { color: #06251f; }

.update-banner {
  /* position: static (no sticky) para que nunca se solape con el aviso de iOS
     si ambos llegaran a mostrarse a la vez: cada uno "sticky" a igual `top`
     se dibujaría encima del otro en vez de apilarse. */
  position: static;
  background: #1e40af;
  color: #fff;
  justify-content: space-between;
}
.update-banner .btn { flex-shrink: 0; }
.backup-banner { background: #92400e; }
.backup-banner .row-inline { flex-shrink: 0; align-items: center; }
.backup-banner .icon-btn { color: #fff; }

/* ===================== Main / layout ===================== */
main { padding: 12px 14px 24px; max-width: 640px; margin: 0 auto; }

.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* Transición direccional al cambiar de pestaña: la pestaña saliente se
   desliza/desvanece y, justo después, la entrante llega desde el lado
   contrario (según si la nueva pestaña queda a la derecha o la izquierda
   de la actual en la barra inferior). Ver switchTab() en app.js. */
@keyframes tabExitToLeft { from { opacity: 1; transform: translateX(0); } to { opacity: 0; transform: translateX(-18px); } }
@keyframes tabExitToRight { from { opacity: 1; transform: translateX(0); } to { opacity: 0; transform: translateX(18px); } }
@keyframes tabEnterFromRight { from { opacity: 0; transform: translateX(18px); } to { opacity: 1; transform: translateX(0); } }
@keyframes tabEnterFromLeft { from { opacity: 0; transform: translateX(-18px); } to { opacity: 1; transform: translateX(0); } }

.tab-panel.tab-exit-left { animation: tabExitToLeft 0.16s ease forwards; }
.tab-panel.tab-exit-right { animation: tabExitToRight 0.16s ease forwards; }
.tab-panel.active.tab-enter-right { animation: tabEnterFromRight 0.24s cubic-bezier(0.22, 1, 0.36, 1); }
.tab-panel.active.tab-enter-left { animation: tabEnterFromLeft 0.24s cubic-bezier(0.22, 1, 0.36, 1); }

@keyframes fadeSlideIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ===================== Cards ===================== */
.card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
  margin-bottom: 14px;
  box-shadow: 0 1px 3px var(--shadow);
  animation: fadeSlideIn 0.3s ease;
}

.card h2 { font-size: 15px; font-weight: 700; margin-bottom: 10px; }

.card-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.card-header-row h2 { margin-bottom: 0; }

.hint { font-size: 12.5px; color: var(--text-muted); line-height: 1.5; margin: 6px 0 0; }

/* ===================== Buttons ===================== */
.btn {
  appearance: none;
  border: none;
  border-radius: var(--radius-md);
  padding: 13px 18px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  min-height: 46px;
  touch-action: manipulation;
  transition: transform 0.08s ease, opacity 0.15s ease, background-color 0.2s ease, box-shadow 0.2s ease;
}
.btn:active { transform: scale(0.96); }

.btn-primary { background: var(--primary); color: var(--primary-contrast); }
.btn-secondary { background: var(--bg-inset); color: var(--text); border: 1px solid var(--border); }
.btn-danger { background: var(--danger-bg); color: var(--danger); width: 100%; margin-top: 10px; }
.btn-sm { padding: 8px 14px; min-height: 36px; font-size: 13px; }
.btn-block { width: 100%; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.icon-btn {
  background: transparent;
  border: none;
  font-size: 18px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  cursor: pointer;
  color: var(--text-muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.icon-btn:active { background: var(--bg-inset); }
.icon-btn.danger { color: var(--danger); }

.chip-btn {
  border: 1.5px solid var(--border);
  background: var(--bg-inset);
  color: var(--text);
  border-radius: 999px;
  padding: 10px 0;
  width: 44px;
  height: 44px;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  transition: background-color 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease, transform 0.1s ease, color 0.2s ease;
}
.chip-btn:active { transform: scale(0.9); }
.chip-btn.active { background: var(--primary); border-color: var(--primary); color: var(--primary-contrast); }
.chip-btn.taken { opacity: 0.45; }
.chip-btn.picked { box-shadow: 0 0 0 3px var(--accent); }

.multi-select-bar {
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--bg-inset);
  border: 1.5px dashed var(--primary);
  border-radius: var(--radius-md);
  padding: 12px;
  margin-top: 10px;
  font-size: 13.5px;
  font-weight: 600;
}
.multi-select-bar .row-inline .btn { flex: 1; }

.quick-days { display: flex; gap: 8px; margin-bottom: 4px; }

/* ===================== Forms ===================== */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; font-size: 13px; font-weight: 600; color: var(--text-muted); }
.field:last-child { margin-bottom: 0; }

.input, select.input {
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 12px;
  font-size: 16px;
  background: var(--bg-inset);
  color: var(--text);
  width: 100%;
  min-height: 46px;
}
.input:focus, select.input:focus { outline: 2px solid var(--primary); outline-offset: 1px; }

.field-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
}
.field-toggle input[type="checkbox"] { width: 20px; height: 20px; accent-color: var(--primary); flex-shrink: 0; }

.row-inline { display: flex; gap: 8px; align-items: center; }
.row-inline.wrap { flex-wrap: wrap; }
.row-inline .input { flex: 1; }

.checkbox-grid { display: flex; flex-direction: column; gap: 2px; }
.checkbox-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 4px;
  border-bottom: 1px solid var(--border);
  font-size: 15px;
}
.checkbox-row:last-child { border-bottom: none; }
.checkbox-row input[type="checkbox"] { width: 22px; height: 22px; accent-color: var(--primary); flex-shrink: 0; }
.checkbox-row .driver-tag {
  font-size: 11px;
  font-weight: 700;
  color: var(--primary);
  background: color-mix(in srgb, var(--primary) 14%, transparent);
  padding: 2px 8px;
  border-radius: 999px;
  margin-left: auto;
}

.weight-checkbox-row span { flex: 1; }
.weight-input {
  width: 52px;
  flex-shrink: 0;
  text-align: center;
  padding: 6px 4px;
  font-size: 14px;
}
.weight-input:disabled { opacity: 0.4; }

/* ===================== Item list (personas/coches/trayectos) ===================== */
.item-list { display: flex; flex-direction: column; gap: 8px; }
.item-row {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-inset);
  border-radius: var(--radius-sm);
  padding: 10px 8px 10px 14px;
}
.item-row-main { flex: 1; min-width: 0; }
.item-row-title { font-weight: 700; font-size: 14.5px; }
.item-row-sub { font-size: 12.5px; color: var(--text-muted); margin-top: 2px; }
.item-row-actions { display: flex; gap: 2px; flex-shrink: 0; }

/* Personas y coches eliminados (archivados) */
.archived-tag {
  display: inline-block;
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-muted);
  background: var(--bg-inset);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 1px 7px;
  margin-left: 4px;
  vertical-align: middle;
}
.archived-section { margin-top: 12px; }

.close-reminder-card { border-left: 4px solid var(--accent); font-size: 14px; }

.subheading { font-size: 13.5px; font-weight: 700; color: var(--text-muted); margin: 16px 0 8px; }
.archived-section summary {
  cursor: pointer;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-muted);
  padding: 4px 0;
}
.archived-section .item-row { opacity: 0.8; }

.empty-state {
  font-size: 13.5px;
  color: var(--text-muted);
  text-align: center;
  padding: 18px 10px;
  line-height: 1.5;
}

/* ===================== Registro: días y trayectos ===================== */
.add-day-card .quick-days { justify-content: flex-start; }

.day-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  margin-bottom: 12px;
  overflow: hidden;
  box-shadow: 0 1px 3px var(--shadow);
  animation: fadeSlideIn 0.3s ease;
}
.day-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 14px;
  background: var(--bg-inset);
}
.day-card-title { font-weight: 700; font-size: 14.5px; }
.day-card-subtitle { font-size: 12px; color: var(--text-muted); margin-top: 1px; }
.day-card-actions { display: flex; align-items: center; gap: 2px; }

.day-card-body { padding: 10px 14px 14px; }

.trip-row {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  margin-bottom: 8px;
}
.trip-row:last-child { margin-bottom: 0; }
.trip-row-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.trip-row-car { font-weight: 700; font-size: 14px; }
.trip-row-meta { font-size: 12.5px; color: var(--text-muted); margin-top: 2px; }
.trip-row-cost { font-weight: 700; color: var(--primary); font-size: 14px; white-space: nowrap; }
.trip-row-people { font-size: 12.5px; color: var(--text-muted); margin-top: 6px; line-height: 1.5; }
.trip-row-buttons { display: flex; gap: 4px; margin-top: 8px; flex-wrap: wrap; align-items: center; }
.trip-row-buttons .btn { flex: 1; min-width: 90px; }
.reorder-btn { width: 30px; height: 30px; font-size: 12px; border: 1.5px solid var(--border); flex-shrink: 0; }
.reorder-btn:disabled { opacity: 0.3; cursor: not-allowed; }
.reorder-btn:disabled:active { background: transparent; }

.add-trip-btn { margin-top: 4px; }

/* ===================== Resumen ===================== */
.summary-hero {
  /* Colores fijos (no ligados a --primary/--accent): en modo oscuro esas variables
     se aclaran y el texto blanco pierde contraste contra el extremo del degradado. */
  background: linear-gradient(135deg, #1e40af, #115e59);
  color: #fff;
  border-radius: var(--radius-lg);
  padding: 20px 18px;
  margin-bottom: 14px;
}
.summary-hero-label { font-size: 12.5px; opacity: 0.85; font-weight: 600; }
.summary-hero-value { font-size: 32px; font-weight: 800; margin-top: 4px; }
.summary-hero-sub { font-size: 12.5px; opacity: 0.9; margin-top: 6px; }

.dashboard-link-btn {
  appearance: none;
  border: none;
  background: rgba(255, 255, 255, 0.16);
  color: #fff;
  font-size: 12.5px;
  font-weight: 700;
  padding: 8px 14px;
  border-radius: 999px;
  margin-top: 12px;
  cursor: pointer;
}
.dashboard-link-btn:active { background: rgba(255, 255, 255, 0.28); }

.dashboard-stale-notice {
  margin-top: 12px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.14);
  border-left: 3px solid #fbbf24;
  font-size: 12px;
  line-height: 1.4;
}

.summary-list { display: flex; flex-direction: column; gap: 8px; }
.summary-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: var(--bg-inset);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}
.summary-item-name { font-weight: 700; font-size: 14px; }
.summary-item-sub { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.summary-item-value { font-weight: 700; font-size: 14.5px; white-space: nowrap; }

.summary-item-bar { flex-direction: column; align-items: stretch; gap: 0; }
.summary-item-row { flex: 1; display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.person-bar-track { height: 6px; background: var(--bg-elevated); border-radius: 999px; margin-top: 8px; overflow: hidden; }
.person-bar-fill { height: 100%; border-radius: 999px; background: linear-gradient(90deg, var(--primary), var(--accent)); }

.debt-item {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-inset);
  border-radius: var(--radius-sm);
  padding: 12px;
  font-size: 14px;
}
.debt-arrow { color: var(--text-muted); }
.debt-amount { margin-left: auto; font-weight: 800; color: var(--danger); white-space: nowrap; }

.settle-btn {
  flex-shrink: 0;
  width: 30px;
  height: 30px;
  font-size: 14px;
  border: 1.5px solid var(--border);
  color: var(--accent);
  background: var(--bg-elevated);
}
.settle-btn:active { background: var(--accent); color: #fff; border-color: var(--accent); }

.summary-actions { display: flex; flex-direction: column; gap: 10px; margin-top: 4px; }

/* ===================== Modal de confirmación ===================== */
.confirm-message { font-size: 14.5px; line-height: 1.5; white-space: pre-line; margin: 0 0 16px; }
.confirm-actions { display: flex; flex-direction: column; gap: 10px; }

/* ===================== Gráfico de evolución (Historial) ===================== */
.chart-bars {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  height: 150px;
  padding-top: 22px;
  overflow-x: auto;
}
.chart-bar-col {
  flex: 0 0 auto;
  width: 38px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  height: 100%;
}
.chart-bar {
  width: 100%;
  min-height: 4px;
  border-radius: 6px 6px 3px 3px;
  background: linear-gradient(180deg, var(--primary), var(--accent));
}
.chart-bar-value { font-size: 10px; margin-bottom: 4px; color: var(--text-muted); white-space: nowrap; }
.chart-bar-label { font-size: 10.5px; margin-top: 6px; color: var(--text-muted); white-space: nowrap; }

.stats-grid { display: flex; gap: 10px; }
.stat-box {
  flex: 1;
  text-align: center;
  background: var(--bg-inset);
  border-radius: var(--radius-sm);
  padding: 12px 6px;
}
.stat-value { font-size: 16px; font-weight: 800; color: var(--primary); }
.stat-label { font-size: 11px; color: var(--text-muted); margin-top: 3px; }

/* ===================== Historial ===================== */
.section-heading { font-size: 15px; font-weight: 700; margin: 4px 2px 10px; }
#clearHistoryBtn { margin-bottom: 14px; }

.history-item {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px;
  margin-bottom: 10px;
  animation: fadeSlideIn 0.3s ease;
}
.history-item-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; cursor: pointer; }
.history-item-title { font-weight: 700; font-size: 14.5px; }
.history-item-sub { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.history-item-total { font-weight: 800; color: var(--primary); font-size: 15px; white-space: nowrap; }
.history-item-detail { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border); }
.history-item-detail.hidden { display: none; }

/* ===================== Tabbar ===================== */
.tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 20;
  display: flex;
  background: var(--bg-elevated);
  border-top: 1px solid var(--border);
  padding: 6px 4px calc(6px + var(--safe-bottom));
}
.tab-btn {
  flex: 1;
  background: none;
  border: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px 2px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: color 0.2s ease, transform 0.1s ease;
}
.tab-btn:active { transform: scale(0.92); }
.tab-btn .tab-icon { font-size: 20px; display: inline-block; transition: transform 0.2s ease; }
.tab-btn.active { color: var(--primary); }
.tab-btn.active .tab-icon { transform: scale(1.15); }

/* ===================== Modal ===================== */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(8, 12, 22, 0.55);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: overlayFadeIn 0.2s ease;
}
@keyframes overlayFadeIn {
  from { background-color: rgba(8, 12, 22, 0); }
  to { background-color: rgba(8, 12, 22, 0.55); }
}
.modal-box {
  background: var(--bg-elevated);
  width: 100%;
  max-width: 640px;
  max-height: 86vh;
  overflow-y: auto;
  border-radius: 20px 20px 0 0;
  padding-bottom: calc(16px + var(--safe-bottom));
  animation: slide-up 0.22s cubic-bezier(0.22, 1, 0.36, 1);
}
@keyframes slide-up {
  from { transform: translateY(28px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 16px 8px;
  position: sticky;
  top: 0;
  background: var(--bg-elevated);
}
.modal-header h2 { font-size: 17px; }
.modal-body { padding: 6px 16px 16px; }
.modal-body .btn-primary { margin-top: 6px; }
.modal-footer-actions { display: flex; gap: 8px; margin-top: 14px; }
.modal-footer-actions .btn { flex: 1; }

/* ---- Asistente paso a paso (añadir/editar trayecto) ---- */
.wizard-steps { display: flex; justify-content: center; gap: 10px; margin-bottom: 18px; }
.wizard-dot {
  width: 32px; height: 32px; border-radius: 50%;
  border: 2px solid var(--border);
  background: var(--bg-inset); color: var(--text-muted);
  font-weight: 700; font-size: 14px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  padding: 0;
  transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease, transform 0.15s ease;
}
.wizard-dot.done { border-color: var(--primary); color: var(--primary); }
.wizard-dot.active { background: var(--primary); border-color: var(--primary); color: var(--primary-contrast); transform: scale(1.1); }

/* Se reinicia (quitando y añadiendo la clase) en cada cambio de paso del asistente. */
.step-anim { animation: fadeSlideIn 0.22s ease; }

.wizard-title { font-size: 17px; font-weight: 700; margin: 0 0 14px; text-align: center; }

.wizard-options { display: flex; flex-direction: column; gap: 10px; margin-bottom: 6px; }
.wizard-option {
  display: flex; flex-direction: column; align-items: flex-start; gap: 3px;
  text-align: left; width: 100%; padding: 14px 16px;
  border-radius: var(--radius-md); border: 2px solid var(--border);
  background: var(--bg-inset); cursor: pointer;
  transition: border-color 0.2s ease, background-color 0.2s ease, transform 0.1s ease;
}
.wizard-option:active { transform: scale(0.98); }
.wizard-option.selected { border-color: var(--primary); background: color-mix(in srgb, var(--primary) 14%, var(--bg-inset)); }
.wizard-option-title { font-weight: 700; font-size: 15px; color: var(--text); }
.wizard-option-sub { font-size: 12.5px; color: var(--text-muted); }

.wizard-chip-row { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 6px; }
.wizard-chip {
  border: 1.5px solid var(--border); background: var(--bg-inset); color: var(--text);
  border-radius: 999px; padding: 9px 14px; font-size: 13.5px; font-weight: 600; cursor: pointer;
  transition: background-color 0.2s ease, border-color 0.2s ease, transform 0.1s ease;
}
.wizard-chip:active { transform: scale(0.94); }
.wizard-chip.selected { background: var(--primary); border-color: var(--primary); color: var(--primary-contrast); }

/* ===================== Toast ===================== */
.toast {
  position: fixed;
  bottom: calc(90px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--text);
  color: var(--bg);
  padding: 10px 10px 10px 18px;
  border-radius: 999px;
  font-size: 13.5px;
  font-weight: 600;
  z-index: 60;
  box-shadow: 0 4px 14px var(--shadow);
  max-width: 90vw;
  text-align: center;
  animation: toastIn 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes toastIn {
  from { opacity: 0; transform: translate(-50%, 14px) scale(0.92); }
  to { opacity: 1; transform: translate(-50%, 0) scale(1); }
}

.toast-undo-btn {
  /* Mismo color que el mensaje (var(--bg) sobre var(--text)): es el par con
     más contraste garantizado del sistema de color, en los dos temas. */
  appearance: none;
  border: none;
  background: transparent;
  color: var(--bg);
  text-decoration: underline;
  font-weight: 700;
  font-size: 13.5px;
  padding: 6px 10px;
  border-radius: 999px;
  cursor: pointer;
  flex-shrink: 0;
}
.toast-undo-btn:active { opacity: 0.6; }

/* ===================== Utility ===================== */
.text-muted { color: var(--text-muted); }
.text-center { text-align: center; }
.mt-8 { margin-top: 8px; }

/* ===================== Vista de escritorio ===================== */
/* En pantallas anchas, la cabecera y la barra de pestañas (position: fixed,
   left/right: 0) se estiraban a todo el ancho del viewport mientras que
   <main> ya iba centrado con max-width. Aquí las alineamos con esa misma
   columna de 640px, en vez de dejarlas estiradas de borde a borde. */
@media (min-width: 700px) {
  .app-header, .tabbar {
    left: 50%;
    right: auto;
    transform: translateX(-50%);
    width: 100%;
    max-width: 640px;
  }
  .app-header, main, .tabbar {
    box-shadow: -1px 0 0 var(--border), 1px 0 0 var(--border);
  }
  .ios-banner {
    max-width: 640px;
    margin: 0 auto;
  }
}

/* ===================== Pantalla de bloqueo ===================== */
.lock-screen {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.lock-box { width: 100%; max-width: 300px; text-align: center; }
.lock-icon { font-size: 40px; margin-bottom: 8px; }
.lock-box h2 { font-size: 19px; margin-bottom: 4px; }
.lock-pin-input {
  text-align: center;
  font-size: 26px;
  letter-spacing: 12px;
  margin: 18px 0 10px;
  padding-left: 22px;
}
.lock-error { color: var(--danger); font-size: 13px; margin: 0 0 12px; min-height: 16px; }
.lock-error.hidden { display: none; }
@keyframes lockShake {
  10%, 90% { transform: translateX(-2px); }
  20%, 80% { transform: translateX(4px); }
  30%, 50%, 70% { transform: translateX(-8px); }
  40%, 60% { transform: translateX(8px); }
}
.lock-box.shake { animation: lockShake 0.4s; }

/* ===================== Iconos (SVG de trazo fino) ===================== */
.icon {
  width: 1.2em;
  height: 1.2em;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex-shrink: 0;
}
button > i, .app-logo > i, .tab-icon > i, .lock-icon > i { display: inline-flex; font-style: normal; }
.icon-inline { display: inline-flex; font-style: normal; vertical-align: -0.2em; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
.btn .icon { width: 18px; height: 18px; }

.app-logo {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 10px;
  color: #fff;
  background: linear-gradient(135deg, var(--primary), #1e3a8a);
  box-shadow: 0 2px 8px rgba(30, 64, 175, 0.35);
}
.app-logo .icon { width: 19px; height: 19px; stroke-width: 1.7; }

.theme-toggle-btn .icon, .lock-now-btn .icon { width: 18px; height: 18px; }
.icon-btn .icon { width: 19px; height: 19px; }
.tab-btn .tab-icon { display: inline-flex; }
.tab-btn .tab-icon .icon { width: 23px; height: 23px; stroke-width: 1.6; }
.lock-icon { color: var(--primary); display: flex; justify-content: center; }
.lock-icon .icon { width: 40px; height: 40px; stroke-width: 1.5; }

.item-row-title .icon, .trip-row-car .icon, .summary-item-name .icon, .wizard-option-title .icon, .field-toggle .icon {
  width: 16px; height: 16px; margin-right: 4px; vertical-align: -0.2em; color: var(--text-muted);
}
.dashboard-stale-notice .icon { width: 15px; height: 15px; margin-right: 6px; vertical-align: -0.2em; color: #fbbf24; }
.empty-state .icon { width: 18px; height: 18px; margin-right: 6px; vertical-align: -0.25em; color: var(--primary); }

.step-num {
  display: inline-grid;
  place-items: center;
  width: 22px;
  height: 22px;
  margin-right: 4px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.25);
  font-size: 12.5px;
  font-weight: 700;
}

/* Pestaña activa: píldora suave detrás del icono. */
.tab-btn .tab-icon { padding: 3px 16px; border-radius: 14px; transition: background-color 0.2s ease, transform 0.2s ease; }
.tab-btn.active .tab-icon { background: color-mix(in srgb, var(--primary) 16%, transparent); transform: none; }
.tab-btn.active .tab-icon .icon { stroke-width: 2.1; }
#exportHistoryCsvBtn { margin-bottom: 0; }

/* ===================== Registro rápido ===================== */
.quick-label { font-weight: 700; font-size: 13.5px; margin: 0 0 6px; }
.quick-label-hint { font-weight: 500; font-size: 12px; color: var(--text-muted); }
.quick-km { font-size: 22px; font-weight: 700; text-align: center; margin-bottom: 8px; }
.chip-step { min-width: 46px; text-align: center; }
.btn-warning { background: #f59e0b; color: #1c1100; }
.dup-warning {
  margin: 12px 0 0;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, #f59e0b 18%, transparent);
  border-left: 3px solid #f59e0b;
  font-size: 13px;
  line-height: 1.4;
}

/* "Lo de siempre": trayectos sugeridos en cada día. */
.suggest-block { margin: 10px 0 12px; }
.suggest-label { font-size: 12px; font-weight: 700; color: var(--text-muted); margin-bottom: 6px; letter-spacing: 0.02em; }
.suggest-row { display: flex; flex-direction: column; gap: 6px; }
.suggest-chip {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 1px;
  width: 100%;
  text-align: left;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  border: 1px dashed color-mix(in srgb, var(--primary) 55%, transparent);
  background: color-mix(in srgb, var(--primary) 8%, transparent);
  color: var(--text);
  cursor: pointer;
  transition: transform 0.08s ease, background-color 0.15s ease;
}
.suggest-chip:active { transform: scale(0.98); background: color-mix(in srgb, var(--primary) 16%, transparent); }
.suggest-chip-title { font-weight: 700; font-size: 14px; }
.suggest-chip-sub { font-size: 12.5px; color: var(--text-muted); }
