/* ============================================
   Farmacias de Guardia — Premium Design System
   ============================================ */

:root {
  /* Colors */
  --bg-primary: #0a0e1a;
  --bg-secondary: #111827;
  --bg-card: #1a2035;
  --bg-card-hover: #222b45;
  --bg-glass: rgba(17, 24, 39, 0.85);

  --accent: #00d4aa;
  --accent-glow: rgba(0, 212, 170, 0.3);
  --accent-dim: rgba(0, 212, 170, 0.15);
  --accent-secondary: #6366f1;
  --accent-secondary-glow: rgba(99, 102, 241, 0.3);

  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;

  --guardia-24h: #00d4aa;
  --guardia-refuerzo: #6366f1;
  --closest: #f59e0b;

  --border: rgba(255, 255, 255, 0.06);
  --border-active: rgba(0, 212, 170, 0.4);

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;

  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 20px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 40px rgba(0, 0, 0, 0.5);
  --shadow-glow: 0 0 30px var(--accent-glow);

  --sidebar-width: 400px;
  --header-height: 72px;

  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

[data-theme="light"] {
  --bg-primary: #f8fafc;
  --bg-secondary: #ffffff;
  --bg-card: #ffffff;
  --bg-card-hover: #f1f5f9;
  --bg-glass: rgba(255, 255, 255, 0.85);

  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #64748b;

  --border: rgba(0, 0, 0, 0.08);
  --border-active: rgba(0, 212, 170, 0.5);

  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.1);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
  --shadow-glow: 0 0 15px rgba(0, 212, 170, 0.2);
}

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

html,
body {
  height: 100%;
  font-family: var(--font);
  background: var(--bg-primary);
  color: var(--text-primary);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  transition: background-color 0.3s ease, color 0.3s ease;
}

/* ============ LOADING OVERLAY ============ */
.loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 10000;
  background: var(--bg-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.6s ease, visibility 0.6s ease;
}

.loading-overlay.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.loader-container {
  text-align: center;
}

.loader-ring {
  width: 56px;
  height: 56px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  margin: 0 auto 20px;
  animation: spin 1s linear infinite;
}

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

.loader-text {
  color: var(--text-secondary);
  font-size: 0.95rem;
  font-weight: 500;
  letter-spacing: 0.02em;
}

/* ============ HEADER ============ */
.app-header {
  height: var(--header-height);
  background: var(--bg-glass);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border-bottom: 1px solid var(--border);
  position: relative;
  z-index: 100;
}

.header-content {
  max-width: 100%;
  height: 100%;
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-shrink: 0;
}

.brand-icon {
  font-size: 1.8rem;
  filter: drop-shadow(0 0 8px var(--accent-glow));
}

.brand h1 {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, var(--text-primary), var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.brand-subtitle {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 500;
  margin-top: 2px;
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.date-picker-wrapper {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 6px 14px;
}

.date-picker-wrapper label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
}

.date-input {
  background: transparent;
  border: none;
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 0.85rem;
  font-weight: 600;
  outline: none;
  cursor: pointer;
}

.date-input::-webkit-calendar-picker-indicator {
  filter: invert(1) brightness(0.7);
  cursor: pointer;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-card);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.25s ease;
  white-space: nowrap;
}

.btn:hover {
  background: var(--bg-card-hover);
  border-color: var(--border-active);
  box-shadow: var(--shadow-glow);
  transform: translateY(-1px);
}

.btn:active {
  transform: translateY(0);
}

.btn-locate {
  background: linear-gradient(135deg, rgba(0, 212, 170, 0.15), rgba(99, 102, 241, 0.15));
  border-color: var(--accent-dim);
}

.btn-locate:hover {
  background: linear-gradient(135deg, rgba(0, 212, 170, 0.25), rgba(99, 102, 241, 0.25));
}

.btn-icon {
  font-size: 1rem;
}

.btn-nav {
  padding: 8px 12px;
  font-size: 0.9rem;
}

.btn-icon-only {
  padding: 8px;
  width: 36px;
  justify-content: center;
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent), #00b894);
  border: none;
  color: var(--bg-primary);
  font-weight: 700;
  padding: 12px 24px;
  border-radius: var(--radius-md);
  width: 100%;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.25s ease;
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px var(--accent-glow);
}

/* ============ MAIN LAYOUT ============ */
.app-main {
  display: flex;
  height: calc(100vh - var(--header-height));
  min-height: 0;
}

/* ============ SIDEBAR ============ */
.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  flex-shrink: 0;
}

.sidebar-header {
  padding: 20px;
  border-bottom: 1px solid var(--border);
}

.sidebar-header h2 {
  font-size: 0.95rem;
  font-weight: 700;
  margin-bottom: 10px;
  color: var(--text-primary);
}

.sidebar-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
}

.badge {
  background: var(--accent-dim);
  color: var(--accent);
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 0.78rem;
  font-weight: 700;
  min-width: 28px;
  text-align: center;
}

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

.search-input {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 0.82rem;
  outline: none;
  transition: border-color 0.2s ease;
}

.search-input::placeholder {
  color: var(--text-muted);
}

.search-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

/* Pharmacy List */
.pharmacy-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.pharmacy-list::-webkit-scrollbar {
  width: 6px;
}

.pharmacy-list::-webkit-scrollbar-track {
  background: transparent;
}

.pharmacy-list::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

.pharmacy-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  margin-bottom: 6px;
  cursor: pointer;
  transition: all 0.25s ease;
  animation: slideIn 0.3s ease forwards;
  opacity: 0;
  transform: translateX(-10px);
}

@keyframes slideIn {
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

.pharmacy-card:hover {
  background: var(--bg-card-hover);
  border-color: var(--border-active);
  transform: translateX(4px);
}

.pharmacy-card.active {
  border-color: var(--accent);
  background: rgba(0, 212, 170, 0.08);
  box-shadow: inset 0 0 0 1px var(--accent-dim);
}

.pharmacy-card.closest-card {
  border-color: var(--closest);
  background: rgba(245, 158, 11, 0.08);
  box-shadow: inset 0 0 0 1px rgba(245, 158, 11, 0.3);
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 8px;
}

.card-name {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.3;
}

.card-badge {
  flex-shrink: 0;
  font-size: 0.65rem;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 20px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

.badge-24h {
  background: rgba(0, 212, 170, 0.15);
  color: var(--guardia-24h);
}

.badge-refuerzo {
  background: rgba(99, 102, 241, 0.15);
  color: var(--guardia-refuerzo);
}

.card-detail {
  font-size: 0.78rem;
  color: var(--text-secondary);
  margin-bottom: 3px;
  display: flex;
  align-items: flex-start;
  gap: 6px;
}

.card-detail .icon {
  opacity: 0.6;
  flex-shrink: 0;
  width: 14px;
  text-align: center;
}

.card-distance {
  margin-top: 8px;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--closest);
  display: flex;
  align-items: center;
  gap: 4px;
}

/* ============ MAP ============ */
.map-container {
  flex: 1;
  z-index: 1;
}

/* Custom Leaflet Popups */
.leaflet-popup-content-wrapper {
  background: var(--bg-card) !important;
  color: var(--text-primary) !important;
  border: 1px solid var(--border) !important;
  border-radius: var(--radius-md) !important;
  box-shadow: var(--shadow-lg) !important;
  font-family: var(--font) !important;
}

.leaflet-popup-tip {
  background: var(--bg-card) !important;
  border: 1px solid var(--border) !important;
}

.leaflet-popup-close-button {
  color: var(--text-muted) !important;
}

.popup-title {
  font-size: 0.9rem;
  font-weight: 700;
  margin-bottom: 6px;
  color: var(--accent);
}

.popup-detail {
  font-size: 0.78rem;
  color: var(--text-secondary);
  margin-bottom: 3px;
}

.popup-badge {
  display: inline-block;
  font-size: 0.65rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 12px;
  margin-bottom: 8px;
}

/* ============ MODAL ============ */
.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.3s ease, visibility 0.3s ease;
}

.modal.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
}

.modal-content {
  position: relative;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 32px;
  max-width: 420px;
  width: 90%;
  box-shadow: var(--shadow-lg);
  animation: modalIn 0.3s ease;
}

@keyframes modalIn {
  from {
    opacity: 0;
    transform: scale(0.95) translateY(10px);
  }

  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.modal-close {
  position: absolute;
  top: 16px;
  right: 16px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.2rem;
  cursor: pointer;
  transition: color 0.2s;
}

.modal-close:hover {
  color: var(--text-primary);
}

.modal-icon {
  font-size: 2.5rem;
  margin-bottom: 12px;
  text-align: center;
}

.modal-content h3 {
  font-size: 1.1rem;
  font-weight: 700;
  text-align: center;
  margin-bottom: 16px;
  background: linear-gradient(135deg, var(--text-primary), var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.modal-body {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
  margin-bottom: 20px;
}

.modal-body p {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.modal-body p strong {
  color: var(--text-primary);
}

.modal-body .distance-highlight {
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--closest);
  margin-top: 10px;
  text-align: center;
}

/* No data state */
.no-data {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
}

.no-data .no-data-icon {
  font-size: 3rem;
  margin-bottom: 12px;
  opacity: 0.5;
}

.no-data p {
  font-size: 0.9rem;
}

/* ============ MOBILE VIEW TOGGLE ============ */
.mobile-view-toggle {
  display: none;
}

/* ============ RESPONSIVE ============ */
@media (max-width: 768px) {
  :root {
    --sidebar-width: 100%;
    --header-height: auto;
  }

  .app-header {
    height: auto;
    padding: 0;
  }

  .header-content {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 8px;
    padding: 8px 12px;
    justify-content: space-between;
    align-items: center;
  }

  .brand {
    gap: 8px;
  }

  .brand-icon {
    font-size: 1.4rem;
  }

  .brand h1 {
    font-size: 0.95rem;
  }

  .brand-subtitle {
    display: none;
  }

  .header-controls {
    gap: 6px;
    justify-content: flex-end;
    flex: 1;
    min-width: 0;
  }

  .date-picker-wrapper {
    padding: 4px 10px;
    gap: 4px;
  }

  .date-picker-wrapper label {
    display: none;
  }

  .date-input {
    font-size: 0.8rem;
  }

  .btn {
    padding: 6px 10px;
    font-size: 0.78rem;
  }

  .btn-nav {
    padding: 6px 8px;
  }

  .btn-icon-only {
    padding: 6px;
    width: 32px;
  }

  .btn-label {
    display: inline;
    font-size: 0.7rem;
  }

  /* View toggle tabs (list / map) */
  .mobile-view-toggle {
    display: flex;
    width: 100%;
    order: 10;
    gap: 0;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border);
  }

  .view-toggle-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px;
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--text-muted);
    font-family: var(--font);
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
  }

  .view-toggle-btn.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
  }

  html, body {
    overflow: auto;
    height: 100dvh;
  }

  body {
    display: flex;
    flex-direction: column;
  }

  .app-main {
    flex-direction: column;
    flex: 1;
    height: auto;
    min-height: 0;
    overflow: hidden;
  }

  .sidebar {
    width: 100%;
    flex: 1;
    max-height: none;
    border-right: none;
    border-bottom: 1px solid var(--border);
    overflow: hidden;
  }

  .map-container {
    flex: 1;
    min-height: 0;
  }

  /* When map view is active on mobile */
  .app-main.mobile-map-view .sidebar {
    display: none;
  }

  .app-main.mobile-map-view .map-container {
    flex: 1;
  }

  /* When list view is active on mobile */
  .app-main.mobile-list-view .map-container {
    display: none;
  }

  .app-main.mobile-list-view .sidebar {
    flex: 1;
    max-height: none;
  }

  /* Compact sidebar header on mobile */
  .sidebar-header {
    padding: 12px;
  }

  .sidebar-header h2 {
    font-size: 0.85rem;
    margin-bottom: 8px;
  }

  .sidebar-meta {
    margin-bottom: 10px;
  }

  .search-input {
    padding: 8px 12px;
    font-size: 0.8rem;
  }

  /* Compact cards on mobile */
  .pharmacy-card {
    padding: 10px 12px;
    margin-bottom: 4px;
  }

  .card-name {
    font-size: 0.82rem;
  }

  .card-detail {
    font-size: 0.75rem;
    margin-bottom: 2px;
  }

  .card-actions {
    margin-top: 6px;
    padding-top: 6px;
  }

  /* Modal adjustments */
  .modal-content {
    padding: 24px;
    width: 94%;
  }

  /* Footer compact */
  .app-footer {
    padding: 10px 16px;
    font-size: 0.7rem;
  }

  .footer-zones {
    display: none;
  }
}

/* Pulse animation for closest marker */
@keyframes pulse {

  0%,
  100% {
    transform: scale(1);
    opacity: 1;
  }

  50% {
    transform: scale(1.15);
    opacity: 0.85;
  }
}

.closest-marker-icon {
  animation: pulse 1.5s ease-in-out infinite;
}

/* Custom marker styling */
.custom-marker {
  background: none;
  border: none;
}

/* ============ TEL LINKS ============ */
.tel-link {
  color: var(--text-secondary);
  text-decoration: none;
  transition: color 0.2s;
}

.tel-link:hover {
  color: var(--accent);
  text-decoration: underline;
}

/* ============ SHIFT STATUS ============ */
.shift-status {
  font-size: 0.72rem;
  font-weight: 600;
  margin-bottom: 6px;
  padding: 2px 8px;
  border-radius: 12px;
  display: inline-block;
}

.status-open {
  color: #00d4aa;
  background: rgba(0, 212, 170, 0.12);
}

.status-upcoming {
  color: #f59e0b;
  background: rgba(245, 158, 11, 0.12);
}

.status-closed {
  color: #ef4444;
  background: rgba(239, 68, 68, 0.12);
}

/* ============ CARD ACTIONS ============ */
.card-actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

.btn-share {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-family: var(--font);
  font-size: 0.72rem;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-share:hover {
  color: var(--accent);
  border-color: var(--accent-dim);
  background: var(--accent-dim);
}

/* ============ TOAST ============ */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-left: 4px solid #f59e0b;
  padding: 12px 20px;
  border-radius: var(--radius-md);
  font-family: var(--font);
  font-size: 0.82rem;
  box-shadow: var(--shadow-lg);
  z-index: 9999;
  opacity: 0;
  transition: opacity 0.4s ease, transform 0.4s ease;
  max-width: 90vw;
}

.toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ============ FOOTER ============ */
.app-footer {
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  padding: 16px 24px;
  text-align: center;
  font-size: 0.75rem;
  color: var(--text-muted);
  line-height: 1.6;
}

.footer-zones {
  margin-bottom: 8px;
}

.footer-meta {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  flex-wrap: wrap;
}

.footer-sep {
  opacity: 0.4;
}

.report-link {
  color: var(--accent);
  text-decoration: none;
  font-weight: 500;
  transition: opacity 0.2s;
}

.report-link:hover {
  text-decoration: underline;
  opacity: 0.8;
}