/* ==========================================================================
   VARIABLES & DESIGN SYSTEM
   ========================================================================== */
:root {
  --font-main: 'Plus Jakarta Sans', system-ui, -apple-system, sans-serif;
  
  /* Palette - Light Theme */
  --bg-main: #f4f7fc;
  --surface: #ffffff;
  --surface-subtle: #f8fafc;
  --border-color: #e2e8f0;
  
  --text-main: #0f172a;
  --text-muted: #64748b;
  --text-white: #ffffff;
  
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-light: #eff6ff;
  
  --danger: #ef4444;
  --danger-light: #fef2f2;
  
  --radius-lg: 24px;
  --radius-md: 16px;
  --radius-sm: 12px;
  
  --shadow-sm: 0 2px 8px rgba(15, 23, 42, 0.04);
  --shadow-md: 0 12px 24px -4px rgba(15, 23, 42, 0.08);
  --shadow-lg: 0 20px 32px -8px rgba(15, 23, 42, 0.14);
}

body.dark {
  /* Palette - Dark Theme */
  --bg-main: #090d16;
  --surface: #131b2e;
  --surface-subtle: #1a243d;
  --border-color: #23314d;
  
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  
  --primary: #3b82f6;
  --primary-hover: #60a5fa;
  --primary-light: rgba(59, 130, 246, 0.15);
  
  --danger: #f87171;
  --danger-light: rgba(248, 113, 113, 0.12);
  
  --shadow-md: 0 12px 24px -4px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 20px 32px -8px rgba(0, 0, 0, 0.5);
}

/* ==========================================================================
   RESET & BASE STYLES
   ========================================================================== */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: var(--font-main);
  background-color: var(--bg-main);
  color: var(--text-main);
  min-height: 100vh;
  padding-bottom: 90px; /* Space for bottom nav */
  transition: background-color 0.3s ease, color 0.3s ease;
}

button, input {
  font-family: inherit;
  border: none;
  outline: none;
}

button {
  cursor: pointer;
}

.hidden {
  display: none !important;
}

/* ==========================================================================
   HEADER
   ========================================================================== */
.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(37, 99, 235, 0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  color: var(--text-white);
  padding: 16px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: var(--shadow-md);
}

body.dark .app-header {
  background: rgba(19, 27, 46, 0.9);
  border-bottom: 1px solid var(--border-color);
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-icon {
  width: 40px;
  height: 40px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: var(--radius-sm);
  display: grid;
  place-items: center;
  font-size: 1.2rem;
}

.eyebrow {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  opacity: 0.85;
  font-weight: 700;
  display: block;
}

.header-brand h1 {
  font-size: 1.15rem;
  font-weight: 800;
  line-height: 1.1;
}

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.15);
  color: var(--text-white);
  display: grid;
  place-items: center;
  font-size: 1.1rem;
  transition: background 0.2s ease;
}

.icon-btn:active {
  transform: scale(0.95);
}

/* ==========================================================================
   MAIN CONTAINER & CARDS
   ========================================================================== */
.container {
  max-width: 480px;
  margin: 0 auto;
  padding: 20px 16px;
}

.app-page {
  animation: fadeIn 0.25s ease-out;
}

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

.section-title {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  margin-bottom: 16px;
}

.section-title h2 {
  font-size: 1.35rem;
  font-weight: 800;
}

.subtext {
  color: var(--text-muted);
  font-size: 0.88rem;
  margin-top: 4px;
}

.badge {
  background: var(--primary-light);
  color: var(--primary);
  padding: 6px 12px;
  border-radius: 99px;
  font-size: 0.8rem;
  font-weight: 700;
}

.routes-map-section {
  margin-top: 24px;
}

.map-card {
  background: var(--surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 16px;
  box-shadow: var(--shadow-md);
}

.map-toolbar {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  justify-content: space-between;
  margin-bottom: 12px;
}

.map-select-wrapper {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
  font-size: 0.85rem;
  color: var(--text-muted);
  font-weight: 700;
}

.custom-select {
  width: 100%;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  background: var(--surface-subtle);
  color: var(--text-main);
}

.secondary-btn {
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  background: var(--primary-light);
  color: var(--primary);
  font-weight: 700;
  white-space: nowrap;
}

.routes-map {
  height: 320px;
  border-radius: var(--radius-md);
  overflow: hidden;
  border: 1px solid var(--border-color);
  background: #e5eefb;
}

.route-info {
  margin-top: 12px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  background: var(--surface-subtle);
  color: var(--text-muted);
  font-size: 0.9rem;
  line-height: 1.45;
}

.route-empty {
  color: var(--danger);
}

/* Hero Cards (Forms & Scanner view) */
.hero-card {
  background: var(--surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 24px 20px;
  text-align: center;
  box-shadow: var(--shadow-md);
}

.hero-icon {
  width: 64px;
  height: 64px;
  background: var(--primary-light);
  color: var(--primary);
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 1.8rem;
  margin: 0 auto 16px;
}

/* ==========================================================================
   INPUTS & BUTTONS
   ========================================================================== */
.form-group {
  text-align: left;
  margin: 20px 0;
}

.form-group label {
  display: block;
  font-size: 0.85rem;
  font-weight: 700;
  margin-bottom: 8px;
  color: var(--text-muted);
}

.input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.input-wrapper i {
  position: absolute;
  left: 16px;
  color: var(--text-muted);
  font-size: 1.2rem;
}

.custom-input {
  width: 100%;
  padding: 16px 16px 16px 48px;
  background: var(--surface-subtle);
  border: 1.5px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-main);
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: 1px;
  transition: border-color 0.2s ease;
}

.custom-input:focus {
  border-color: var(--primary);
}

.primary-btn {
  width: 100%;
  padding: 16px;
  background: var(--primary);
  color: var(--text-white);
  border-radius: var(--radius-md);
  font-size: 1rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  box-shadow: 0 8px 20px rgba(37, 99, 235, 0.25);
  transition: transform 0.15s ease, background-color 0.2s;
}

.primary-btn:hover { background: var(--primary-hover); }
.primary-btn:active { transform: scale(0.98); }

/* ==========================================================================
   LISTA DE TARJETAS GUARDADAS
   ========================================================================== */
.cards-grid {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.saved-card-item {
  background: var(--surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: var(--shadow-sm);
  transition: transform 0.2s ease, border-color 0.2s ease;
}

.saved-card-item:active {
  transform: scale(0.99);
}

.card-details {
  display: flex;
  align-items: center;
  gap: 14px;
  flex: 1;
}

.card-thumbnail {
  width: 48px;
  height: 30px;
  object-fit: cover;
  border-radius: 6px;
  box-shadow: 0 4px 8px rgba(0,0,0,0.15);
}

.card-info-text {
  font-weight: 700;
  font-size: 0.95rem;
  letter-spacing: 0.5px;
}

.card-type-label {
  font-size: 0.78rem;
  color: var(--text-muted);
}

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

.action-icon-btn {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-sm);
  background: var(--surface-subtle);
  color: var(--text-muted);
  display: grid;
  place-items: center;
  font-size: 1.1rem;
}

.action-icon-btn.delete:hover {
  background: var(--danger-light);
  color: var(--danger);
}

.empty-state {
  text-align: center;
  padding: 40px 20px;
  background: var(--surface);
  border: 2px dashed var(--border-color);
  border-radius: var(--radius-lg);
  color: var(--text-muted);
}

.empty-state i {
  font-size: 2.5rem;
  margin-bottom: 12px;
  display: block;
}

/* ==========================================================================
   TARJETA FÍSICA VIRTUAL (RENDERIZADO)
   ========================================================================== */
.result-area {
  margin-top: 24px;
  animation: slideUp 0.3s ease;
}

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

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

.close-btn {
  background: none;
  color: var(--text-muted);
  font-size: 1.2rem;
}

.vv-card {
  position: relative;
  width: 100%;
  border-radius: 20px;
  overflow: hidden;
  box-shadow: var(--shadow-lg);
  aspect-ratio: 1.586 / 1;
}

.vv-bg {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.vv-overlay {
  position: absolute;
  inset: 0;
  padding: 22px;
  background: linear-gradient(180deg, rgba(0,0,0,0.1) 0%, rgba(0,0,0,0.82) 100%);
  color: #ffffff;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
}

.vv-chip {
  position: absolute;
  top: 22px;
  left: 22px;
  width: 44px;
  height: 32px;
  background: linear-gradient(135deg, #e0aa3e, #f9f5a6);
  border-radius: 6px;
  opacity: 0.9;
}

.vv-number span, .vv-saldo-wrapper span {
  font-size: 0.68rem;
  letter-spacing: 1.5px;
  opacity: 0.8;
  display: block;
}

.vv-number strong {
  font-family: monospace;
  font-size: 1.25rem;
  letter-spacing: 2px;
  text-shadow: 0 2px 4px rgba(0,0,0,0.5);
}

.vv-saldo-wrapper {
  margin-top: 14px;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
}

.vv-saldo-wrapper strong {
  font-size: 1.8rem;
  font-weight: 800;
  color: #38ef7d;
}

.icon-btn-blur {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.2);
  backdrop-filter: blur(8px);
  color: white;
  display: grid;
  place-items: center;
}

/* Save button & JSON area */
.action-container { margin-top: 16px; }

.json-box {
  margin-top: 16px;
  background: #0d1117;
  color: #e6edf3;
  padding: 16px;
  border-radius: var(--radius-md);
  font-size: 0.82rem;
}

.json-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  color: #8b949e;
  font-weight: 600;
}

.copy-btn {
  background: rgba(255,255,255,0.1);
  color: white;
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 0.75rem;
}

.json-box pre {
  white-space: pre-wrap;
  word-break: break-all;
}

/* Errors & Loaders */
.error-msg {
  margin-top: 20px;
  padding: 16px;
  background: var(--danger-light);
  color: var(--danger);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  gap: 14px;
}

.loader-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(4px);
  z-index: 1000;
  display: grid;
  place-items: center;
}

.loader-card {
  background: var(--surface);
  padding: 24px 32px;
  border-radius: var(--radius-md);
  text-align: center;
  box-shadow: var(--shadow-lg);
}

.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid var(--border-color);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 12px;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* Toast */
.toast {
  position: fixed;
  top: 80px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text-main);
  color: var(--bg-main);
  padding: 12px 20px;
  border-radius: 99px;
  font-size: 0.88rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 10px;
  z-index: 1100;
  box-shadow: var(--shadow-lg);
}

/* ==========================================================================
   BOTTOM NAVIGATION BAR
   ========================================================================== */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 72px;
  background: var(--surface);
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: space-around;
  align-items: center;
  z-index: 90;
  box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.04);
}

.nav-item {
  background: none;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  font-size: 0.75rem;
  font-weight: 600;
  width: 33%;
  transition: color 0.2s ease;
}

.nav-item i {
  font-size: 1.35rem;
}

.nav-item.active {
  color: var(--primary);
}

/* ==========================================================================
   FULLSCREEN MAP & SMART SEARCH STYLES
   ========================================================================== */
.map-page-full {
  position: fixed;
  top: 60px; /* Debajo del Header */
  bottom: 72px; /* Arriba del Nav */
  left: 0;
  right: 0;
  height: calc(100vh - 132px);
  width: 100vw;
  z-index: 10;
  overflow: hidden;
}

.full-screen-map {
  width: 100%;
  height: 100%;
  z-index: 1;
}

/* Floating Search Bar */
.map-search-container {
  position: absolute;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  width: calc(100% - 32px);
  max-width: 440px;
  z-index: 1000;
}

.search-input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  padding: 4px 12px;
}

.search-icon {
  color: var(--text-muted);
  font-size: 1.1rem;
  margin-right: 8px;
}

.map-search-input {
  width: 100%;
  padding: 10px 0;
  background: transparent;
  color: var(--text-main);
  font-size: 0.95rem;
  font-weight: 600;
}

.clear-search-btn {
  background: none;
  color: var(--text-muted);
  font-size: 1.1rem;
  padding: 4px;
}

/* Search Dropdown */
.search-results-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  max-height: 240px;
  overflow-y: auto;
  z-index: 1001;
}

.search-result-item {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-color);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.search-result-item:last-child {
  border-bottom: none;
}

.search-result-item:hover, .search-result-item.active {
  background: var(--primary-light);
}

.search-result-title {
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--text-main);
}

.search-result-sub {
  font-size: 0.78rem;
  color: var(--text-muted);
}

/* Floating Controls & Live Info */
.map-overlay-controls {
  position: absolute;
  bottom: 20px;
  left: 16px;
  right: 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  z-index: 1000;
  pointer-events: none;
}

.map-live-badge {
  pointer-events: auto;
  background: rgba(15, 23, 42, 0.85);
  backdrop-filter: blur(8px);
  color: #ffffff;
  padding: 10px 16px;
  border-radius: 99px;
  font-size: 0.85rem;
  font-weight: 600;
  box-shadow: var(--shadow-md);
  max-width: 80%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: flex;
  align-items: center;
  gap: 8px;
}

.map-fab-btn {
  pointer-events: auto;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--primary);
  color: #ffffff;
  font-size: 1.2rem;
  display: grid;
  place-items: center;
  box-shadow: var(--shadow-lg);
}

/* Custom Marker Styles */
.bus-marker-icon {
  background: #10b981;
  border: 2px solid #ffffff;
  border-radius: 50%;
  color: white;
  text-align: center;
  line-height: 28px;
  box-shadow: 0 4px 10px rgba(0,0,0,0.3);
}

.quay-marker-icon {
  background: var(--primary);
  border: 2px solid #ffffff;
  border-radius: 50%;
  color: white;
  text-align: center;
  line-height: 22px;
}