/* ═══════════════════════════════════════════════════════════
   FarmaMap — Verde Farmacia Branding
   Primary: #059669 (emerald-600)  
   Accent:  #10b981 (emerald-500)  
   Light:   #d1fae5 (emerald-100)
   Dark:    #064e3b (emerald-900)
   ═══════════════════════════════════════════════════════════ */

:root {
  --fm-primary: #059669;
  --fm-primary-dark: #047857;
  --fm-primary-darker: #064e3b;
  --fm-accent: #10b981;
  --fm-accent-light: #34d399;
  --fm-light: #d1fae5;
  --fm-lighter: #ecfdf5;
  --fm-surface: #ffffff;
  --fm-surface-2: #f8faf9;
  --fm-text: #1a1a2e;
  --fm-text-secondary: #6b7280;
  --fm-text-muted: #9ca3af;
  --fm-border: #e5e7eb;
  --fm-shadow: 0 4px 24px rgba(5, 150, 105, 0.08);
  --fm-shadow-lg: 0 12px 40px rgba(5, 150, 105, 0.12);
  --fm-radius: 16px;
  --fm-radius-sm: 10px;
  --fm-header-h: 56px;
  --fm-search-h: 112px;
  --fm-panel-peek: 140px;
  --fm-safe-bottom: env(safe-area-inset-bottom, 0px);
  --fm-safe-top: env(safe-area-inset-top, 0px);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  height: 100%; width: 100%;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  color: var(--fm-text);
  background: var(--fm-surface);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ═══ SPLASH ═══ */
.splash {
  position: fixed; inset: 0; z-index: 9999;
  background: linear-gradient(135deg, #059669 0%, #047857 50%, #064e3b 100%);
  display: flex; align-items: center; justify-content: center;
  flex-direction: column;
  transition: opacity 0.5s ease, transform 0.5s ease;
}
.splash.hide {
  opacity: 0; transform: scale(1.05);
  pointer-events: none;
}
.splash-content { text-align: center; }
.splash-cross {
  width: 72px; height: 72px; position: relative; margin: 0 auto 20px;
  animation: pulse-cross 2s ease-in-out infinite;
}
.cross-v, .cross-h {
  position: absolute; background: white; border-radius: 6px;
}
.cross-v { width: 20px; height: 72px; left: 26px; top: 0; }
.cross-h { width: 72px; height: 20px; top: 26px; left: 0; }
@keyframes pulse-cross {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.08); opacity: 0.9; }
}
.splash-title {
  font-size: 2.2rem; font-weight: 800; color: white;
  letter-spacing: -0.5px; margin-bottom: 8px;
}
.splash-sub {
  font-size: 0.95rem; color: rgba(255,255,255,0.8);
  font-weight: 500;
}
.splash-dots {
  display: flex; gap: 8px; justify-content: center; margin-top: 24px;
}
.splash-dots span {
  width: 8px; height: 8px; border-radius: 50%; background: rgba(255,255,255,0.5);
  animation: dot-bounce 1.4s ease-in-out infinite;
}
.splash-dots span:nth-child(2) { animation-delay: 0.2s; }
.splash-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes dot-bounce {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.5; }
  40% { transform: scale(1); opacity: 1; background: white; }
}

/* ═══ HEADER ═══ */
header {
  position: fixed; top: 0; left: 0; right: 0;
  z-index: 1000; height: var(--fm-header-h);
  padding-top: var(--fm-safe-top);
  background: var(--fm-primary);
  box-shadow: 0 2px 12px rgba(0,0,0,0.1);
}
.header-inner {
  display: flex; align-items: center; justify-content: space-between;
  height: 100%; padding: 0 16px;
}
.logo {
  display: flex; align-items: center; gap: 10px; cursor: pointer;
  user-select: none;
}
.logo-cross {
  width: 28px; height: 28px; position: relative;
}
.cross-v-sm, .cross-h-sm {
  position: absolute; background: white; border-radius: 3px;
}
.cross-v-sm { width: 8px; height: 28px; left: 10px; top: 0; }
.cross-h-sm { width: 28px; height: 8px; top: 10px; left: 0; }
.logo-text {
  font-size: 1.25rem; font-weight: 800; color: white;
  letter-spacing: -0.5px;
}
.header-stats {
  font-size: 0.75rem; color: rgba(255,255,255,0.75);
  font-weight: 500;
}
.btn-locate {
  width: 40px; height: 40px; border: none; border-radius: 12px;
  background: rgba(255,255,255,0.15); color: white;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; transition: all 0.2s;
  backdrop-filter: blur(8px);
}
.btn-locate:hover { background: rgba(255,255,255,0.25); transform: scale(1.05); }
.btn-locate:active { transform: scale(0.95); }
.btn-locate.locating {
  animation: locate-pulse 1s ease-in-out infinite;
}
@keyframes locate-pulse {
  0%, 100% { background: rgba(255,255,255,0.15); }
  50% { background: rgba(255,255,255,0.35); }
}

/* ═══ SEARCH ═══ */
.search-container {
  position: fixed;
  top: calc(var(--fm-header-h) + var(--fm-safe-top));
  left: 0; right: 0; z-index: 999;
  padding: 10px 12px 8px;
  background: linear-gradient(to bottom, var(--fm-surface) 70%, transparent);
}
.search-bar {
  display: flex; align-items: center;
  background: var(--fm-surface);
  border: 2px solid var(--fm-border);
  border-radius: var(--fm-radius);
  padding: 0 14px; height: 48px;
  box-shadow: var(--fm-shadow);
  transition: border-color 0.2s, box-shadow 0.2s;
}
.search-bar:focus-within {
  border-color: var(--fm-accent);
  box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.15), var(--fm-shadow);
}
.search-icon { color: var(--fm-text-muted); flex-shrink: 0; margin-right: 10px; }
#searchInput {
  flex: 1; border: none; outline: none; background: none;
  font-size: 0.95rem; font-family: inherit; color: var(--fm-text);
}
#searchInput::placeholder { color: var(--fm-text-muted); }
.search-clear {
  width: 28px; height: 28px; border: none; border-radius: 50%;
  background: var(--fm-border); color: var(--fm-text-secondary);
  cursor: pointer; font-size: 14px; display: flex; align-items: center; justify-content: center;
  transition: background 0.2s;
}
.search-clear:hover { background: #d1d5db; }
.search-clear.hidden { display: none; }

/* Filters */
.filters {
  display: flex; gap: 8px; padding-top: 8px;
  overflow-x: auto; -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.filters::-webkit-scrollbar { display: none; }
.filter-chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 6px 14px; border-radius: 20px;
  border: 1.5px solid var(--fm-border);
  background: var(--fm-surface);
  font-size: 0.8rem; font-weight: 600;
  color: var(--fm-text-secondary);
  cursor: pointer; white-space: nowrap;
  transition: all 0.2s;
  font-family: inherit;
}
.filter-chip:hover { border-color: var(--fm-accent); color: var(--fm-primary); }
.filter-chip.active {
  background: var(--fm-light);
  border-color: var(--fm-accent);
  color: var(--fm-primary);
}
.filter-chip svg { flex-shrink: 0; }

/* ═══ MAP ═══ */
#map {
  position: fixed;
  top: calc(var(--fm-header-h) + var(--fm-safe-top));
  left: 0; right: 0;
  bottom: 0;
  z-index: 1;
}
/* Custom leaflet controls styling */
.leaflet-control-zoom a {
  background: var(--fm-surface) !important;
  color: var(--fm-primary) !important;
  border-color: var(--fm-border) !important;
  width: 36px !important; height: 36px !important;
  line-height: 36px !important; font-size: 18px !important;
  border-radius: 10px !important;
  box-shadow: var(--fm-shadow) !important;
}
.leaflet-control-zoom { border: none !important; border-radius: 12px !important; overflow: hidden; }

/* Custom pharmacy markers */
.pharmacy-marker {
  width: 36px; height: 36px;
  background: var(--fm-primary);
  border: 3px solid white;
  border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
  box-shadow: 0 3px 10px rgba(0,0,0,0.2);
  display: flex; align-items: center; justify-content: center;
  transition: transform 0.2s, box-shadow 0.2s;
}
.pharmacy-marker:hover {
  transform: rotate(-45deg) scale(1.15);
  box-shadow: 0 5px 15px rgba(0,0,0,0.3);
}
.pharmacy-marker.selected {
  background: #dc2626;
  transform: rotate(-45deg) scale(1.2);
}
.pharmacy-marker-inner {
  transform: rotate(45deg);
  font-size: 14px; font-weight: 800; color: white;
  line-height: 1;
}
.pharmacy-marker.guardia { background: #f59e0b; }
.pharmacy-marker.h24 { background: #3b82f6; }

/* Cluster markers */
.cluster-marker {
  width: 44px; height: 44px;
  background: var(--fm-primary);
  border: 3px solid white;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.85rem; font-weight: 700; color: white;
  box-shadow: 0 3px 12px rgba(5, 150, 105, 0.3);
}

/* User location marker */
.user-marker {
  width: 16px; height: 16px;
  background: #3b82f6;
  border: 3px solid white;
  border-radius: 50%;
  box-shadow: 0 0 0 6px rgba(59, 130, 246, 0.2), 0 2px 8px rgba(0,0,0,0.2);
}

/* Map popup */
.leaflet-popup-content-wrapper {
  border-radius: var(--fm-radius-sm) !important;
  box-shadow: var(--fm-shadow-lg) !important;
  padding: 0 !important;
}
.leaflet-popup-content {
  margin: 0 !important; width: 260px !important;
}
.popup-card {
  padding: 16px;
}
.popup-name {
  font-size: 0.95rem; font-weight: 700; color: var(--fm-text);
  margin-bottom: 4px;
}
.popup-address {
  font-size: 0.8rem; color: var(--fm-text-secondary);
  margin-bottom: 8px;
}
.popup-tags { display: flex; gap: 4px; margin-bottom: 10px; flex-wrap: wrap; }
.popup-tag {
  font-size: 0.65rem; font-weight: 600; padding: 2px 8px;
  border-radius: 10px; text-transform: uppercase; letter-spacing: 0.5px;
}
.popup-tag.province { background: var(--fm-light); color: var(--fm-primary-dark); }
.popup-tag.distance { background: #dbeafe; color: #1d4ed8; }
.popup-tag.guardia { background: #fef3c7; color: #92400e; }
.popup-tag.h24 { background: #d1fae5; color: #065f46; }
.popup-actions { display: flex; gap: 8px; }
.popup-btn {
  flex: 1; padding: 8px; border: none; border-radius: 8px;
  font-size: 0.78rem; font-weight: 600; cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 4px;
  transition: all 0.2s; font-family: inherit;
}
.popup-btn-primary {
  background: var(--fm-primary); color: white;
}
.popup-btn-primary:hover { background: var(--fm-primary-dark); }
.popup-btn-secondary {
  background: var(--fm-lighter); color: var(--fm-primary);
  border: 1px solid var(--fm-light);
}
.popup-btn-secondary:hover { background: var(--fm-light); }

/* ═══ RESULTS PANEL ═══ */
.results-panel {
  position: fixed; bottom: 0; left: 0; right: 0;
  z-index: 998;
  background: var(--fm-surface);
  border-radius: 20px 20px 0 0;
  box-shadow: 0 -4px 30px rgba(0,0,0,0.1);
  max-height: 65vh;
  transform: translateY(calc(100% - var(--fm-panel-peek)));
  transition: transform 0.35s cubic-bezier(0.22, 1, 0.36, 1);
  padding-bottom: var(--fm-safe-bottom);
}
.results-panel.expanded {
  transform: translateY(0);
}
.results-panel.collapsed {
  transform: translateY(calc(100% - var(--fm-panel-peek)));
}
.results-panel.hidden-panel {
  transform: translateY(100%);
}
.panel-handle {
  display: flex; justify-content: center; padding: 10px 0 6px;
  cursor: grab;
}
.handle-bar {
  width: 40px; height: 4px; border-radius: 2px;
  background: var(--fm-border);
}
.panel-header {
  display: flex; align-items: baseline; justify-content: space-between;
  padding: 0 16px 8px;
}
.panel-header h2 {
  font-size: 1rem; font-weight: 700; color: var(--fm-text);
}
.results-count {
  font-size: 0.8rem; color: var(--fm-text-muted); font-weight: 500;
}
.results-list {
  overflow-y: auto; max-height: calc(65vh - 80px);
  padding: 0 12px 12px;
  -webkit-overflow-scrolling: touch;
}

/* Pharmacy card in list */
.pharmacy-card {
  display: flex; gap: 12px; padding: 12px;
  border-radius: var(--fm-radius-sm);
  background: var(--fm-surface);
  border: 1px solid var(--fm-border);
  margin-bottom: 8px;
  cursor: pointer;
  transition: all 0.2s;
}
.pharmacy-card:hover {
  border-color: var(--fm-accent);
  box-shadow: 0 2px 12px rgba(16, 185, 129, 0.1);
  transform: translateY(-1px);
}
.pharmacy-card:active { transform: translateY(0) scale(0.99); }
.card-icon {
  width: 42px; height: 42px; flex-shrink: 0;
  background: var(--fm-lighter);
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
}
.card-icon-cross {
  width: 18px; height: 18px; position: relative;
}
.card-cross-v {
  position: absolute; width: 5px; height: 18px; left: 6.5px; top: 0;
  background: var(--fm-primary); border-radius: 2px;
}
.card-cross-h {
  position: absolute; width: 18px; height: 5px; top: 6.5px; left: 0;
  background: var(--fm-primary); border-radius: 2px;
}
.card-body { flex: 1; min-width: 0; }
.card-name {
  font-size: 0.88rem; font-weight: 600; color: var(--fm-text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.card-address {
  font-size: 0.78rem; color: var(--fm-text-secondary);
  margin-top: 2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.card-meta {
  display: flex; gap: 8px; margin-top: 6px; align-items: center;
}
.card-distance {
  font-size: 0.72rem; font-weight: 600; color: #2563eb;
  background: #dbeafe; padding: 2px 8px; border-radius: 8px;
}
.card-province {
  font-size: 0.72rem; font-weight: 500; color: var(--fm-text-muted);
}
.card-phone {
  font-size: 0.72rem; font-weight: 500; color: var(--fm-primary);
}
.card-badges {
  display: flex; gap: 4px; margin-top: 3px; flex-wrap: wrap;
}
.card-badge {
  font-size: 0.68rem; font-weight: 600; padding: 2px 8px;
  border-radius: 8px; white-space: nowrap;
}
.card-badge.guardia {
  background: #fef3c7; color: #92400e;
}
.card-badge.h24 {
  background: #d1fae5; color: #065f46;
}
.pharmacy-card.on-guard {
  border-left: 3px solid #f59e0b;
}

/* ═══ PHARMACY DETAIL OVERLAY ═══ */
.pharmacy-detail {
  position: fixed; inset: 0; z-index: 2000;
  background: var(--fm-surface);
  transform: translateX(100%);
  transition: transform 0.35s cubic-bezier(0.22, 1, 0.36, 1);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.pharmacy-detail.show {
  transform: translateX(0);
}
.pharmacy-detail.hidden { pointer-events: none; }
.detail-close {
  position: fixed; top: 12px; right: 12px; z-index: 2001;
  width: 44px; height: 44px; border-radius: 50%;
  border: none; background: var(--fm-surface);
  box-shadow: var(--fm-shadow);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; color: var(--fm-text-secondary);
  transition: background 0.2s;
}
.detail-close:hover { background: var(--fm-lighter); }

.detail-hero {
  height: 180px;
  background: linear-gradient(135deg, var(--fm-primary), var(--fm-primary-darker));
  display: flex; align-items: flex-end; padding: 20px;
}
.detail-hero h1 {
  font-size: 1.4rem; font-weight: 800; color: white;
  text-shadow: 0 2px 8px rgba(0,0,0,0.2);
}
.detail-body { padding: 20px; }
.detail-section { margin-bottom: 20px; }
.detail-section h3 {
  font-size: 0.85rem; font-weight: 700; color: var(--fm-text-muted);
  text-transform: uppercase; letter-spacing: 0.5px;
  margin-bottom: 8px;
}
.detail-row {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 8px 0;
}
.detail-row svg { flex-shrink: 0; color: var(--fm-primary); margin-top: 2px; }
.detail-row-text { font-size: 0.9rem; color: var(--fm-text); }
.detail-actions {
  display: flex; gap: 10px; padding: 20px; position: sticky; bottom: 0;
  background: var(--fm-surface); border-top: 1px solid var(--fm-border);
}
.detail-btn {
  flex: 1; padding: 14px; border: none; border-radius: var(--fm-radius-sm);
  font-size: 0.9rem; font-weight: 700; cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 6px;
  font-family: inherit; transition: all 0.2s;
}
.detail-btn-call {
  background: var(--fm-primary); color: white;
}
.detail-btn-call:hover { background: var(--fm-primary-dark); }
.detail-btn-directions {
  background: var(--fm-lighter); color: var(--fm-primary);
  border: 1.5px solid var(--fm-light);
}
.detail-btn-directions:hover { background: var(--fm-light); }

/* ═══ FOOTER ═══ */
.footer {
  position: fixed; bottom: 8px; left: 50%;
  transform: translateX(-50%);
  z-index: 500;
  background: rgba(255,255,255,0.92);
  backdrop-filter: blur(8px);
  padding: 6px 16px; border-radius: 20px;
  font-size: 0.7rem; color: var(--fm-text-muted);
  display: flex; gap: 6px; align-items: center;
  box-shadow: var(--fm-shadow);
  white-space: nowrap;
}
.footer a { color: var(--fm-primary); text-decoration: none; font-weight: 600; }

/* ═══ EMPTY / LOADING STATES ═══ */
.state-empty {
  text-align: center; padding: 30px 20px;
}
.state-empty-icon {
  width: 56px; height: 56px; margin: 0 auto 12px;
  background: var(--fm-lighter); border-radius: 16px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.5rem;
}
.state-empty h3 { font-size: 1rem; font-weight: 700; margin-bottom: 4px; }
.state-empty p { font-size: 0.85rem; color: var(--fm-text-secondary); }

.skeleton-card {
  display: flex; gap: 12px; padding: 12px;
  border-radius: var(--fm-radius-sm);
  border: 1px solid var(--fm-border);
  margin-bottom: 8px;
}
.skeleton { background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
  background-size: 200% 100%; animation: shimmer 1.5s infinite;
  border-radius: 6px;
}
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* ═══ RESPONSIVE ═══ */
@media (min-width: 768px) {
  .results-panel {
    width: 380px; left: 12px; right: auto;
    border-radius: var(--fm-radius);
    bottom: 12px;
    max-height: calc(100vh - var(--fm-header-h) - var(--fm-search-h) - 24px);
    transform: translateY(0);
    box-shadow: var(--fm-shadow-lg);
  }
  .results-panel.collapsed { transform: translateY(0); }
  .panel-handle { display: none; }
  .footer { bottom: 12px; }
  .search-container { max-width: 500px; }
}

@media (max-width: 767px) {
  .footer { display: none; }
  .header-stats { display: none; }
}
