/* ===========================================================
   Rutas Tuxtla — Design System
   Paleta: petroleo profundo + ambar calido + neutrals warm
   Tipo:   Inter (system fallback)
   =========================================================== */

:root {
  /* base / neutrals warm */
  --bg: #f6f4ef;
  --surface: #ffffff;
  --surface-soft: #fbf9f5;
  --surface-tint: #f1ede5;
  --border: #e3dfd6;
  --border-soft: #ece8df;

  /* ink */
  --ink: #14201f;
  --ink-soft: #4a5a59;
  --ink-mute: #8a9594;

  /* brand: petroleo profundo */
  --primary: #0d4f4f;
  --primary-strong: #0a3e3e;
  --primary-soft: #d6e4e3;
  --primary-ink: #ffffff;

  /* accent: ambar calido para highlights */
  --accent: #c2410c;
  --accent-soft: #fde7d3;

  /* semantic */
  --success: #047857;
  --danger: #b91c1c;
  --warn: #c2410c;

  /* dots A/B (mantienen identidad pero refinados) */
  --dot-a: #0f7c5b;
  --dot-b: #b6431a;

  /* shadows refinadas */
  --shadow-sm: 0 1px 2px rgba(15, 30, 35, 0.04), 0 1px 3px rgba(15, 30, 35, 0.05);
  --shadow-md: 0 2px 4px rgba(15, 30, 35, 0.04), 0 8px 18px rgba(15, 30, 35, 0.07);
  --shadow-lg: 0 4px 8px rgba(15, 30, 35, 0.05), 0 20px 40px rgba(15, 30, 35, 0.1);

  /* radius */
  --r-xs: 4px;
  --r-sm: 7px;
  --r-md: 10px;
  --r-lg: 14px;
  --r-xl: 20px;

  /* transitions */
  --t-fast: 120ms ease;
  --t-base: 180ms cubic-bezier(0.4, 0, 0.2, 1);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  color: var(--ink);
  background: var(--bg);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body { display: flex; }

/* ===== Sidebar ===== */
.sidebar {
  width: 340px;
  flex: 0 0 340px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: 100vh;
  max-height: 100vh;
  z-index: 1000;
  transition: transform 240ms cubic-bezier(0.4, 0, 0.2, 1);
  overflow: hidden;
}

/* ----- Brand header ----- */
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 18px 20px 16px;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-strong) 100%);
  color: var(--primary-ink);
  position: relative;
}
.brand::after {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.18), transparent);
}
.brand-logo {
  width: 40px;
  height: 40px;
  border-radius: var(--r-md);
  background: rgba(255,255,255,0.12);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.brand-logo svg {
  width: 22px;
  height: 22px;
  color: #fff;
}
.brand-text { line-height: 1.2; }
.brand h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.3px;
}
.brand p {
  margin: 3px 0 0;
  font-size: 12px;
  opacity: 0.78;
  font-weight: 400;
  letter-spacing: 0.2px;
}

/* ----- Controls ----- */
.controls {
  padding: 14px 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 9px;
  border-bottom: 1px solid var(--border-soft);
}

.search-wrap {
  position: relative;
}
.search-wrap .search-ico {
  position: absolute;
  left: 11px;
  top: 50%;
  transform: translateY(-50%);
  width: 15px;
  height: 15px;
  color: var(--ink-mute);
  pointer-events: none;
}
.controls input[type="search"] {
  width: 100%;
  padding: 10px 12px 10px 34px;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  font: inherit;
  font-size: 13.5px;
  outline: none;
  background: var(--surface-soft);
  color: var(--ink);
  transition: border-color var(--t-fast), background var(--t-fast), box-shadow var(--t-fast);
}
.controls input[type="search"]::placeholder { color: var(--ink-mute); }
.controls input[type="search"]:focus {
  border-color: var(--primary);
  background: #fff;
  box-shadow: 0 0 0 3px var(--primary-soft);
}

/* ----- Buttons ----- */
.btn-row { display: flex; gap: 8px; }

.btn {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 12px;
  border: 0;
  border-radius: var(--r-md);
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  background: var(--primary);
  color: var(--primary-ink);
  transition: background var(--t-fast), transform var(--t-fast), box-shadow var(--t-fast);
  letter-spacing: -0.01em;
}
.btn svg { width: 14px; height: 14px; flex-shrink: 0; }
.btn:hover { background: var(--primary-strong); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

.btn.ghost {
  background: transparent;
  color: var(--ink-soft);
  border: 1px solid var(--border);
}
.btn.ghost:hover {
  background: var(--surface-tint);
  color: var(--ink);
}

/* mini buttons (Aqui / Fijar) */
.btn-mini {
  font: inherit;
  font-size: 11.5px;
  font-weight: 500;
  padding: 5px 9px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface);
  cursor: pointer;
  color: var(--ink);
  white-space: nowrap;
  flex-shrink: 0;
  transition: all var(--t-fast);
  letter-spacing: -0.01em;
}
.btn-mini:hover:not(:disabled) {
  background: var(--surface-tint);
  border-color: var(--ink-mute);
}
.btn-mini.armed {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}
.btn-mini:disabled,
.btn-mini.disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.btn-loc {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.btn-loc .ico {
  width: 12px;
  height: 12px;
  flex-shrink: 0;
}

/* ----- Status ----- */
.status {
  padding: 8px 16px;
  font-size: 11.5px;
  color: var(--ink-soft);
  border-bottom: 1px solid var(--border-soft);
  background: var(--surface-soft);
  min-height: 18px;
  letter-spacing: 0.05px;
}
.status.error { color: var(--danger); }

/* ===== Trip panel ===== */
.trip-panel {
  padding: 14px 16px 14px;
  border-bottom: 1px solid var(--border-soft);
  background: linear-gradient(180deg, var(--surface-soft), var(--surface) 50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex-shrink: 0;
}
.trip-header {
  font-size: 11px;
  font-weight: 600;
  color: var(--ink-mute);
  text-transform: uppercase;
  letter-spacing: 0.7px;
  margin-bottom: 4px;
}
.trip-row {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 13px;
}
.trip-dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  flex-shrink: 0;
  border: 2px solid #fff;
  box-shadow: 0 0 0 1px rgba(20, 32, 31, 0.18), 0 1px 2px rgba(20, 32, 31, 0.1);
}
.trip-dot-a { background: var(--dot-a); }
.trip-dot-b { background: var(--dot-b); }
.trip-label {
  flex: 1;
  color: var(--ink);
  font-size: 12.5px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.trip-label.unset {
  color: var(--ink-mute);
  font-style: normal;
  font-weight: 400;
}
.trip-hint {
  font-size: 11.5px;
  color: var(--primary);
  min-height: 14px;
  margin-top: 2px;
  line-height: 1.4;
}
.trip-hint.error { color: var(--danger); }

/* trip results */
.trip-results {
  list-style: none;
  margin: 6px 0 0;
  padding: 0;
  max-height: 240px;
  overflow-y: auto;
  border-top: 1px solid var(--border-soft);
  padding-top: 8px;
}
.trip-results:empty { display: none; }
.trip-result {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 8px;
  cursor: pointer;
  border-radius: var(--r-sm);
  font-size: 13px;
  transition: background var(--t-fast);
  margin: 0 -4px;
}
.trip-result:hover { background: var(--surface-tint); }
.trip-result.active {
  background: var(--primary-soft);
}
.trip-result-color {
  width: 14px;
  height: 14px;
  border-radius: var(--r-xs);
  flex-shrink: 0;
  box-shadow: 0 0 0 1px rgba(20, 32, 31, 0.08);
}
.trip-result-label { font-weight: 600; letter-spacing: -0.01em; }
.trip-result-meta {
  margin-left: auto;
  font-size: 11px;
  color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
}
.trip-result-transfer {
  font-size: 10px;
  color: var(--accent);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-left: 6px;
}

.trip-section-title {
  font-size: 10.5px;
  font-weight: 600;
  color: var(--ink-mute);
  text-transform: uppercase;
  letter-spacing: 0.6px;
  padding: 10px 8px 4px;
}

/* Cursor crosshair cuando estamos esperando un punto */
.leaflet-container.picking { cursor: crosshair !important; }

.hidden { display: none !important; }

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  padding: 11px 18px;
  border-radius: var(--r-md);
  font-size: 13px;
  font-weight: 500;
  z-index: 2000;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  transition: opacity 200ms;
  pointer-events: none;
  max-width: 90vw;
}
.toast.show { opacity: 1; }

/* ===== Ruta list ===== */
.ruta-list {
  list-style: none;
  margin: 0;
  padding: 4px 0;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

.ruta-item {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 9px 16px;
  cursor: pointer;
  border-left: 3px solid transparent;
  transition: background var(--t-fast), border-left-color var(--t-fast);
}
.ruta-item:hover { background: var(--surface-tint); }
.ruta-item.active {
  background: var(--primary-soft);
  border-left-color: var(--primary);
}
.ruta-item.hidden { display: none; }

.ruta-color {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 700;
  font-size: 11.5px;
  letter-spacing: -0.02em;
  box-shadow: inset 0 -2px 0 rgba(0,0,0,0.12), 0 1px 2px rgba(20, 32, 31, 0.1);
}

.ruta-label {
  flex: 1;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--ink);
  letter-spacing: -0.01em;
}

.ruta-meta {
  font-size: 11px;
  color: var(--ink-mute);
  font-variant-numeric: tabular-nums;
}

/* ===== Footer ===== */
.footer {
  padding: 10px 16px;
  font-size: 10.5px;
  color: var(--ink-mute);
  border-top: 1px solid var(--border-soft);
  background: var(--surface-soft);
  letter-spacing: 0.1px;
}
.footer p { margin: 2px 0; }
.footer a { color: var(--primary); text-decoration: none; font-weight: 500; }
.footer a:hover { text-decoration: underline; }
.footer-credit {
  font-style: italic;
  color: var(--ink-soft);
  font-size: 11px;
  font-weight: 500;
  line-height: 1.45;
}
.footer-credit .heart {
  width: 11px;
  height: 11px;
  vertical-align: -1px;
  color: #c2410c;
  animation: heartbeat 2.4s ease-in-out infinite;
}
@keyframes heartbeat {
  0%, 100% { transform: scale(1); }
  10%      { transform: scale(1.18); }
  20%      { transform: scale(1); }
  30%      { transform: scale(1.12); }
  40%      { transform: scale(1); }
}

/* ===== Map ===== */
#map-wrap {
  flex: 1;
  position: relative;
  height: 100vh;
}
#map {
  position: absolute;
  inset: 0;
  background: var(--surface-tint);
}

.sidebar-toggle {
  display: none;
  position: absolute;
  top: 14px;
  right: 14px;
  z-index: 1100;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: var(--r-md);
  background: var(--surface);
  font-size: 22px;
  color: var(--ink);
  cursor: pointer;
  box-shadow: var(--shadow-md);
  transition: transform var(--t-fast), box-shadow var(--t-fast);
}
.sidebar-toggle:hover { transform: translateY(-1px); box-shadow: var(--shadow-lg); }

/* ===== Leaflet popup customization ===== */
.leaflet-popup-content-wrapper {
  border-radius: var(--r-md) !important;
  box-shadow: var(--shadow-md) !important;
}
.leaflet-popup-content {
  margin: 11px 14px !important;
  font-size: 13px !important;
  font-family: inherit !important;
}
.popup-title {
  font-weight: 600;
  font-size: 14px;
  margin-bottom: 4px;
  color: var(--ink);
  letter-spacing: -0.01em;
}
.popup-meta {
  color: var(--ink-soft);
  font-size: 12px;
}
.leaflet-bar a {
  background: var(--surface) !important;
  color: var(--ink) !important;
  border-color: var(--border) !important;
  font-family: inherit !important;
}
.leaflet-bar a:hover { background: var(--surface-tint) !important; }

/* ===== Modal ===== */
.modal {
  position: fixed;
  inset: 0;
  z-index: 5000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  animation: fadeIn 200ms ease;
}
.modal.hidden { display: none; }
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(20, 32, 31, 0.55);
  backdrop-filter: blur(4px);
}
.modal-card {
  position: relative;
  background: var(--surface);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg);
  max-width: 480px;
  width: 100%;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: slideUp 240ms cubic-bezier(0.34, 1.36, 0.64, 1);
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-soft);
}
.modal-head h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.3px;
  color: var(--ink);
}
.modal-close {
  background: transparent;
  border: 0;
  font-size: 24px;
  line-height: 1;
  color: var(--ink-mute);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--r-sm);
  transition: background var(--t-fast), color var(--t-fast);
}
.modal-close:hover { background: var(--surface-tint); color: var(--ink); }
.modal-body {
  padding: 16px 20px;
  overflow-y: auto;
  font-size: 13.5px;
  line-height: 1.55;
  color: var(--ink-soft);
}
.modal-body p { margin: 0 0 10px; }
.modal-body strong { color: var(--ink); font-weight: 600; }
.ios-steps {
  margin: 8px 0 14px;
  padding-left: 22px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.ios-steps li::marker { color: var(--accent); font-weight: 700; }
.ios-figure {
  margin: 12px 0 8px;
  border-radius: var(--r-md);
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--surface-tint);
}
.ios-figure img {
  display: block;
  width: 100%;
  height: auto;
}
.ios-figure figcaption {
  padding: 8px 10px;
  font-size: 11.5px;
  color: var(--ink-mute);
  background: var(--surface-soft);
  border-top: 1px solid var(--border-soft);
}
.modal-note {
  margin-top: 12px !important;
  padding: 10px 12px;
  background: var(--accent-soft);
  border-radius: var(--r-sm);
  border-left: 3px solid var(--accent);
  color: var(--ink) !important;
  font-size: 12.5px;
}
.modal-foot {
  padding: 12px 20px 16px;
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  border-top: 1px solid var(--border-soft);
  background: var(--surface-soft);
}
.modal-foot .btn { flex: 0 0 auto; padding: 9px 18px; }

@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}
@keyframes slideUp {
  from { opacity: 0; transform: translateY(16px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* ===== Mobile ===== */
@media (max-width: 720px) {
  body { display: block; }
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    width: 88%;
    max-width: 360px;
    transform: translateX(-100%);
    box-shadow: var(--shadow-lg);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-toggle { display: block; }
  #map-wrap { height: 100vh; }
  .trip-panel { padding: 12px 14px; gap: 7px; }
  .controls { padding: 12px 14px 10px; }
  .brand { padding: 16px 16px 14px; }
  .ruta-item { padding: 9px 14px; }
  .footer { padding: 9px 14px; }
}

/* Pantallas medianas: solo icono en btn-loc para que entre */
@media (max-width: 480px) {
  .btn-loc-text { display: none; }
  .btn-loc { padding: 5px 8px; }
  .btn-loc .ico { width: 14px; height: 14px; }
}

/* Pantallas muy chicas (iPhone SE etc.) */
@media (max-width: 360px) {
  .btn-mini { padding: 4px 7px; font-size: 11px; }
  .trip-row { gap: 5px; }
  .trip-label { font-size: 12px; }
  .ruta-color { width: 26px; height: 26px; font-size: 11px; }
  .modal-card { max-height: 92vh; }
  .modal-head { padding: 14px 16px; }
  .modal-body { padding: 14px 16px; font-size: 13px; }
  .modal-foot { padding: 12px 16px 14px; }
}
