:root {
  --bg: rgba(255, 255, 255, 0.94);
  --bg-solid: #ffffff;
  --bg-muted: #f1f5f9;
  --text: #0f172a;
  --text-muted: #475569;
  --border: rgba(15, 23, 42, 0.12);
  --accent: #0f766e;
  --accent-text: #ffffff;
  --shadow: 0 8px 28px rgba(15, 23, 42, 0.18);
  --radius: 16px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: rgba(15, 23, 42, 0.92);
    --bg-solid: #0f172a;
    --bg-muted: #1e293b;
    --text: #f8fafc;
    --text-muted: #94a3b8;
    --border: rgba(248, 250, 252, 0.14);
    --accent: #14b8a6;
    --accent-text: #042f2e;
    --shadow: 0 8px 28px rgba(0, 0, 0, 0.45);
  }
}

*, *::before, *::after {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: #0b1320;
  -webkit-tap-highlight-color: transparent;
}

#app {
  position: relative;
  width: 100%;
  height: 100dvh;
  overflow: hidden;
}

#map {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

/* Bottom sheet móvil */
.panel {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 15;
  display: flex;
  flex-direction: column;
  height: calc(100dvh - env(safe-area-inset-top, 0px) - 12px);
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--bg);
  border-top: 1px solid var(--border);
  border-radius: var(--radius) var(--radius) 0 0;
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
  transform: translateY(var(--panel-y, calc(48dvh - env(safe-area-inset-top, 0px) - 12px)));
  transition: transform 280ms cubic-bezier(0.2, 0.8, 0.2, 1);
  will-change: transform;
}

.panel[hidden] {
  display: none !important;
}

.panel.is-dragging {
  transition: none;
}

@media (prefers-reduced-motion: reduce) {
  .panel {
    transition: transform 160ms ease-out;
  }
}

.panel[data-state="collapsed"] .day-detail {
  pointer-events: none;
}

.panel-handle-wrap {
  display: flex;
  justify-content: center;
  touch-action: none;
}

.panel-handle {
  min-width: 64px;
  min-height: 44px;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
}

.panel-handle::before {
  content: "";
  width: 40px;
  height: 4px;
  border-radius: 999px;
  background: var(--text-muted);
  opacity: 0.45;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 2px 14px 8px;
  touch-action: none;
}

.panel-title-wrap {
  min-width: 0;
}

.trip-title {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.trip-subtitle {
  margin: 2px 0 0;
  font-size: 0.8rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.panel-actions {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-logout {
  width: 44px;
  height: 44px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg-muted);
  color: var(--text-muted);
  display: grid;
  place-items: center;
  cursor: pointer;
}

.btn-logout:hover {
  color: var(--text);
}

.btn-today {
  flex-shrink: 0;
  min-height: 44px;
  min-width: 56px;
  padding: 0 14px;
  border: 0;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-text);
  font: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
}

/* Chips de días */
.chips {
  display: flex;
  gap: 8px;
  padding: 0 14px 10px;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scrollbar-width: none;
  flex-shrink: 0;
}

.chips::-webkit-scrollbar {
  display: none;
}

.chip {
  flex: 0 0 auto;
  min-height: 44px;
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg-muted);
  color: var(--text);
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.chip-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.chip[aria-pressed="true"] {
  background: var(--day-color, var(--accent));
  border-color: transparent;
  color: #ffffff;
}

.chip[aria-pressed="true"] .chip-dot {
  background: #ffffff !important;
}

.chip-today {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 1px 6px;
  border-radius: 999px;
  background: rgba(15, 118, 110, 0.14);
  color: var(--accent);
}

.chip[aria-pressed="true"] .chip-today {
  background: rgba(255, 255, 255, 0.24);
  color: #ffffff;
}

/* Ficha del día */
.day-detail {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 6px 14px 16px;
  border-top: 1px solid var(--border);
}

@media (max-width: 899px) {
  .panel[data-state="half"] .day-detail {
    padding-bottom: calc(16px + var(--panel-half-y, 0px));
  }
}

.day-zone {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin: 6px 0 4px;
}

.day-zone h2 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
}

.day-zone span {
  font-size: 0.8rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.day-summary {
  margin: 0 0 12px;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.stay-card {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 12px;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg-muted);
}

.stay-main {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 2px 4px;
  border: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  text-align: left;
}

button.stay-main {
  min-height: 44px;
  cursor: pointer;
}

button.stay-main:active {
  transform: scale(0.99);
}

.stay-icon {
  flex-shrink: 0;
  font-size: 1.2rem;
  line-height: 1;
}

.stay-info {
  min-width: 0;
  flex: 1;
}

.stay-label {
  display: block;
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}

.stay-name {
  display: block;
  font-size: 0.88rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stay-place {
  display: block;
  font-size: 0.76rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.timeline {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
}

.timeline-origin {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 0 2px 10px;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-muted);
}

.timeline-origin-text {
  flex: 1;
  min-width: 0;
}

.timeline-origin-dot {
  flex-shrink: 0;
  width: 24px;
  display: grid;
  place-items: center;
}

.timeline-origin-dot::before {
  content: "";
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 2px solid var(--day-color, var(--accent));
  background: var(--bg-solid);
}

.timeline-connector {
  display: flex;
  align-items: stretch;
  padding: 0 10px;
  gap: 10px;
}

.timeline-axis {
  flex-shrink: 0;
  width: 24px;
  display: flex;
  justify-content: center;
}

.timeline-line {
  width: 0;
  min-height: 16px;
  border-left: 2px solid var(--day-color, var(--accent));
}

.timeline-line--dashed {
  border-left-style: dashed;
}

.timeline-leg-btn {
  flex: 1;
  min-height: 44px;
  margin: 4px 0;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-muted);
  color: var(--text);
  font: inherit;
  text-align: left;
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  transition: background-color 150ms ease, border-color 150ms ease;
}

.timeline-leg-btn.is-active,
.timeline-leg-btn[aria-pressed="true"] {
  border-color: #2563eb;
  background: rgba(37, 99, 235, 0.12);
}

@media (prefers-color-scheme: dark) {
  .timeline-leg-btn.is-active,
  .timeline-leg-btn[aria-pressed="true"] {
    border-color: #3b82f6;
    background: rgba(37, 99, 235, 0.24);
  }
}

.timeline-leg-btn:active {
  transform: scale(0.99);
}

.timeline-leg-icon {
  flex-shrink: 0;
  font-size: 1rem;
  line-height: 1;
}

.timeline-leg-duration {
  font-size: 0.88rem;
  font-weight: 700;
}

.timeline-leg-km {
  font-size: 0.76rem;
  color: var(--text-muted);
}

.timeline-leg-target {
  margin-left: auto;
  font-size: 0.74rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 45%;
}

.stop-item {
  display: flex;
  align-items: stretch;
  gap: 6px;
}

.stop-btn {
  flex: 1;
  min-width: 0;
  min-height: 44px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg-solid);
  color: var(--text);
  font: inherit;
  text-align: left;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  cursor: pointer;
}

.go-btn {
  flex-shrink: 0;
  min-width: 44px;
  min-height: 44px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg-solid);
  color: var(--accent);
  font: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
  white-space: nowrap;
}

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

.go-btn-icon {
  font-size: 0.85rem;
  line-height: 1;
}

.stop-btn:active {
  transform: scale(0.99);
}

.stop-num {
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--day-color, var(--accent));
  color: #ffffff;
  font-size: 0.78rem;
  font-weight: 700;
  display: grid;
  place-items: center;
  margin-top: 1px;
}

.stop-info {
  min-width: 0;
  flex: 1;
}

.stop-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 4px 8px;
  font-size: 0.92rem;
  font-weight: 600;
}

.stop-time {
  flex-shrink: 0;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-muted);
}

.stop-time--layover {
  flex-shrink: 1;
}

.stop-note {
  margin: 3px 0 0;
  font-size: 0.82rem;
  color: var(--text-muted);
  line-height: 1.35;
}

/* Marcadores en mapa */
.map-marker {
  width: 28px;
  height: 28px;
  padding: 0;
  border-radius: 50%;
  border: 2px solid #ffffff;
  color: #ffffff;
  font-size: 0.8rem;
  font-weight: 700;
  display: grid;
  place-items: center;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
  cursor: pointer;
}

.map-marker::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 44px;
  height: 44px;
  transform: translate(-50%, -50%);
  border-radius: 50%;
}

.map-marker--stay {
  width: 24px;
  height: 24px;
  background: #ffffff;
  border: 1.5px solid rgba(15, 23, 42, 0.2);
  color: #0f172a;
  font-size: 0.76rem;
}

/* Escritorio >= 900px: panel lateral izquierdo */
@media (min-width: 900px) {
  .panel {
    top: 12px;
    left: 12px;
    bottom: 12px;
    right: auto;
    width: 360px;
    height: auto;
    max-height: none;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding-bottom: 0;
    transform: none !important;
  }

  .panel[data-state="collapsed"] .day-detail {
    pointer-events: auto;
  }

  .panel-handle-wrap {
    display: none;
  }

  .chips {
    flex-wrap: wrap;
    overflow-x: visible;
    padding-bottom: 10px;
  }

  .chip {
    min-height: 38px;
    padding: 4px 12px;
    font-size: 0.82rem;
  }
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Pantalla de contraseña */
.lock-screen {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 20px;
  padding-top: max(20px, env(safe-area-inset-top));
  padding-bottom: max(20px, env(safe-area-inset-bottom));
  background: rgba(11, 19, 32, 0.45);
  backdrop-filter: blur(6px);
}

.lock-screen[hidden] {
  display: none;
}

.lock-card {
  width: 100%;
  max-width: 360px;
  padding: 24px 20px 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.lock-badge {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: rgba(15, 118, 110, 0.14);
  color: var(--accent);
  display: grid;
  place-items: center;
  align-self: center;
}

.lock-title {
  margin: 0;
  font-size: 1.2rem;
  font-weight: 700;
  text-align: center;
}

.lock-desc {
  margin: 0;
  font-size: 0.86rem;
  color: var(--text-muted);
  text-align: center;
}

.lock-field {
  display: block;
}

.lock-input {
  width: 100%;
  min-height: 46px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg-solid);
  color: var(--text);
  font: inherit;
  font-size: 1rem;
}

.lock-input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.lock-remember {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 36px;
  font-size: 0.88rem;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
}

.lock-remember input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.lock-error {
  margin: 0;
  padding: 8px 10px;
  border-radius: 10px;
  background: rgba(220, 38, 38, 0.12);
  color: #dc2626;
  font-size: 0.84rem;
  font-weight: 500;
}

@media (prefers-color-scheme: dark) {
  .lock-error {
    color: #fca5a5;
  }
}

.lock-submit {
  min-height: 46px;
  padding: 0 16px;
  border: 0;
  border-radius: 12px;
  background: var(--accent);
  color: var(--accent-text);
  font: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
}

.lock-submit:disabled {
  opacity: 0.65;
  cursor: wait;
}
