/* ===== CSS VARIABLES ===== */
:root {
  --bg-primary: #0a0f1a;
  --bg-secondary: #111827;
  --bg-tertiary: #1f2937;
  --glass: rgba(17, 24, 39, 0.82);
  --glass-border: rgba(55, 65, 81, 0.45);
  --accent: #10b981;
  --accent-hover: #059669;
  --accent-glow: rgba(16, 185, 129, 0.15);
  --accent-secondary: #06b6d4;
  --text: #f9fafb;
  --text-secondary: #d1d5db;
  --text-muted: #6b7280;
  --danger: #ef4444;
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-full: 9999px;
  --shadow: 0 8px 32px rgba(0,0,0,0.4);
  --transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  --header-h: 56px;
  --search-h: 48px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

html, body {
  height: 100%; width: 100%;
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg-primary);
  color: var(--text);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

button { cursor: pointer; border: none; background: none; font-family: inherit; color: inherit; }
input { font-family: inherit; color: inherit; border: none; outline: none; background: none; }
a { color: inherit; text-decoration: none; }
ul { list-style: none; }

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

/* ===== HEADER (compact for mobile) ===== */
#app-header {
  position: fixed; top: 0; left: 0; right: 0; z-index: 1000;
  height: var(--header-h);
  background: var(--glass);
  backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--glass-border);
}

.header-inner {
  display: flex; align-items: center; justify-content: space-between;
  height: 100%; padding: 0 12px; max-width: 1200px; margin: 0 auto;
}

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

.brand-icon {
  width: 36px; height: 36px; border-radius: var(--radius-sm);
  background: linear-gradient(135deg, var(--accent), #059669);
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 0 16px var(--accent-glow);
}
.brand-icon svg { width: 18px; height: 18px; color: #fff; }

.brand-text h1 { font-size: 15px; font-weight: 700; letter-spacing: -0.3px; line-height: 1.2; }
.brand-subtitle { font-size: 10px; color: var(--text-muted); font-weight: 500; }

.btn-locate {
  width: 44px; height: 44px; border-radius: var(--radius-md);
  background: var(--bg-tertiary); border: 1px solid var(--glass-border);
  display: flex; align-items: center; justify-content: center;
  transition: var(--transition);
  -webkit-tap-highlight-color: transparent;
}
.btn-locate svg { width: 20px; height: 20px; color: var(--text-secondary); transition: var(--transition); }
.btn-locate:active { transform: scale(0.92); }
.btn-locate.active { background: var(--accent); border-color: var(--accent); }
.btn-locate.active svg { color: #fff; }
.btn-locate.locating { animation: pulse-btn 1.5s infinite; }

@keyframes pulse-btn {
  0%, 100% { box-shadow: 0 0 0 0 var(--accent-glow); }
  50% { box-shadow: 0 0 0 10px transparent; }
}

/* ===== SEARCH (mobile-first) ===== */
#search-container {
  position: fixed; top: calc(var(--header-h) + 8px); left: 10px; right: 10px;
  z-index: 999; max-width: 560px;
  margin: 0 auto;
}

.search-bar {
  display: flex; align-items: center; gap: 8px;
  height: var(--search-h); padding: 0 14px;
  background: var(--glass); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--glass-border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow); transition: var(--transition);
}
.search-bar:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow), var(--shadow); }
.search-bar.highlight { animation: searchHighlight 2s ease; }

@keyframes searchHighlight {
  0%, 100% { border-color: var(--glass-border); }
  25%, 75% { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-glow), var(--shadow); }
}

.search-icon { width: 18px; height: 18px; flex-shrink: 0; color: var(--text-muted); }

#search-input {
  flex: 1; height: 100%; font-size: 15px; color: var(--text);
  background: transparent;
}
#search-input::placeholder { color: var(--text-muted); }

.btn-clear {
  width: 32px; height: 32px; border-radius: var(--radius-full);
  display: flex; align-items: center; justify-content: center;
  background: var(--bg-tertiary); transition: var(--transition);
  -webkit-tap-highlight-color: transparent;
}
.btn-clear svg { width: 14px; height: 14px; color: var(--text-muted); }
.btn-clear:active { background: var(--danger); }
.btn-clear:active svg { color: #fff; }

.search-dropdown {
  margin-top: 6px; max-height: 50vh; overflow-y: auto;
  background: var(--glass); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--glass-border); border-radius: var(--radius-md);
  box-shadow: var(--shadow); display: none;
  -webkit-overflow-scrolling: touch;
}
.search-dropdown.open { display: block; animation: fadeSlideDown 0.2s ease; }

.search-item {
  padding: 14px 16px; cursor: pointer; font-size: 15px;
  color: var(--text-secondary); transition: background 0.15s;
  border-bottom: 1px solid rgba(55, 65, 81, 0.2);
  display: flex; align-items: center; justify-content: space-between;
}
.search-item:last-child { border-bottom: none; }
.search-item:active { background: var(--accent-glow); color: var(--text); }
.search-item .city-name { font-weight: 600; color: var(--text); }
.search-item .city-count { font-size: 12px; color: var(--text-muted); }

@keyframes fadeSlideDown {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ===== MAP ===== */
#map {
  position: absolute; top: 0; left: 0; right: 0; bottom: 0;
  z-index: 1; background: var(--bg-primary);
}

.leaflet-control-zoom { border: none !important; box-shadow: var(--shadow) !important; }
.leaflet-control-zoom a {
  background: var(--glass) !important; color: var(--text) !important;
  border: 1px solid var(--glass-border) !important;
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  width: 40px !important; height: 40px !important; line-height: 40px !important;
  font-size: 20px !important;
}
.leaflet-control-zoom a:active { background: var(--bg-tertiary) !important; }
.leaflet-control-attribution { display: none; }

/* Custom markers — reset Leaflet defaults */
.pharmacy-marker-wrap {
  background: none !important;
  border: none !important;
  box-shadow: none !important;
}

.pharmacy-marker {
  width: 36px; height: 44px; position: relative;
}
.pharmacy-marker-inner {
  width: 34px; height: 34px; border-radius: 50% 50% 50% 4px;
  background: linear-gradient(135deg, var(--accent), #059669);
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 3px 12px rgba(16, 185, 129, 0.5);
  transform: rotate(-45deg);
  transition: transform 0.2s;
  border: 2px solid rgba(255,255,255,0.3);
}
.pharmacy-marker-inner svg {
  width: 16px; height: 16px; color: #fff; transform: rotate(45deg);
}

.pharmacy-marker .distance-badge {
  position: absolute; top: -6px; right: -16px;
  background: var(--bg-secondary); color: var(--accent);
  font-size: 10px; font-weight: 700; padding: 2px 6px;
  border-radius: var(--radius-full); border: 1px solid var(--glass-border);
  white-space: nowrap;
}

/* Nearest pharmacy — golden highlight */
.pharmacy-marker-nearest .pharmacy-marker-inner {
  background: linear-gradient(135deg, #f59e0b, #d97706);
  box-shadow: 0 3px 16px rgba(245, 158, 11, 0.6);
  width: 40px; height: 40px;
  border: 2px solid #fbbf24;
}
.pharmacy-marker-nearest .pharmacy-marker-inner svg {
  width: 18px; height: 18px;
}
.pharmacy-marker-nearest .distance-badge {
  background: #f59e0b; color: #000; font-weight: 800;
  border-color: #d97706;
}
.pharmacy-marker-nearest .nearest-flag {
  position: absolute; top: -20px; left: 50%; transform: translateX(-50%);
  background: #f59e0b; color: #000; font-size: 10px; font-weight: 800;
  padding: 2px 8px; border-radius: var(--radius-full);
  white-space: nowrap; box-shadow: 0 2px 8px rgba(245, 158, 11, 0.4);
}

.user-marker {
  width: 20px; height: 20px; position: relative;
}
.user-marker-dot {
  width: 20px; height: 20px; border-radius: 50%;
  background: #3b82f6; border: 3px solid #fff;
  box-shadow: 0 2px 8px rgba(59, 130, 246, 0.5);
}
.user-marker-pulse {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  width: 20px; height: 20px; border-radius: 50%;
  background: rgba(59, 130, 246, 0.3); animation: userPulse 2s infinite;
}

@keyframes userPulse {
  0% { width: 20px; height: 20px; opacity: 0.6; }
  100% { width: 60px; height: 60px; opacity: 0; }
}

/* Leaflet popup override — mobile friendly */
.leaflet-popup-content-wrapper {
  background: var(--bg-secondary) !important; color: var(--text) !important;
  border-radius: var(--radius-md) !important; border: 1px solid var(--glass-border) !important;
  box-shadow: var(--shadow) !important; padding: 0 !important;
}
.leaflet-popup-content { margin: 0 !important; font-family: 'Inter', sans-serif !important; min-width: 240px !important; }
.leaflet-popup-tip { background: var(--bg-secondary) !important; border: 1px solid var(--glass-border) !important; }
.leaflet-popup-close-button { color: var(--text-muted) !important; font-size: 22px !important; top: 8px !important; right: 10px !important; width: 32px !important; height: 32px !important; }

.popup-content { padding: 16px; }
.popup-name { font-size: 15px; font-weight: 700; margin-bottom: 4px; padding-right: 24px; }
.popup-address { font-size: 12px; color: var(--text-secondary); margin-bottom: 8px; line-height: 1.4; }
.popup-distance { font-size: 12px; color: var(--accent); font-weight: 600; margin-bottom: 10px; }
.popup-actions { display: flex; gap: 8px; }
.popup-btn {
  flex: 1; padding: 10px 0; border-radius: var(--radius-sm); font-size: 13px; font-weight: 600;
  text-align: center; transition: var(--transition);
  min-height: 44px; display: flex; align-items: center; justify-content: center;
}
.popup-btn-directions { background: var(--accent); color: #fff; }
.popup-btn-directions:active { background: var(--accent-hover); }
.popup-btn-call { background: var(--bg-tertiary); color: var(--text); border: 1px solid var(--glass-border); }
.popup-btn-call:active { border-color: var(--accent); color: var(--accent); }

/* Radius circle */
.radius-circle { stroke: var(--accent); fill: var(--accent-glow); }

/* ===== LIST FAB BUTTON ===== */
.fab-list {
  position: fixed; bottom: calc(24px + var(--safe-bottom)); right: 16px;
  z-index: 998; width: 56px; height: 56px;
  border-radius: 50%; background: var(--accent);
  display: none; align-items: center; justify-content: center;
  box-shadow: 0 4px 20px rgba(16, 185, 129, 0.4);
  transition: var(--transition);
  -webkit-tap-highlight-color: transparent;
}
.fab-list.visible { display: flex; }
.fab-list svg { width: 24px; height: 24px; color: #fff; }
.fab-list:active { transform: scale(0.9); }
.fab-count {
  position: absolute; top: -4px; right: -4px;
  background: #ef4444; color: #fff; font-size: 11px; font-weight: 700;
  min-width: 22px; height: 22px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  border: 2px solid var(--bg-primary);
}

/* ===== BOTTOM SHEET (hidden by default, FAB toggles) ===== */
.bottom-sheet {
  position: fixed; bottom: 0; left: 0; right: 0;
  z-index: 999; height: 55vh;
  background: var(--bg-secondary);
  border-top: 1px solid var(--glass-border);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  transform: translateY(100%);
  transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 -8px 40px rgba(0,0,0,0.5);
  padding-bottom: var(--safe-bottom);
  will-change: transform;
}
.bottom-sheet.open { transform: translateY(0); }

.sheet-handle-area {
  display: flex; justify-content: center; padding: 10px 0 6px; cursor: grab;
  touch-action: none;
}
.sheet-handle-bar {
  width: 40px; height: 5px; border-radius: var(--radius-full);
  background: var(--text-muted); opacity: 0.5;
}

.sheet-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px 10px;
}
.sheet-header h2 { font-size: 15px; font-weight: 700; }
.sheet-count {
  font-size: 12px; font-weight: 600; color: var(--accent);
  background: var(--accent-glow); padding: 4px 12px;
  border-radius: var(--radius-full);
}

.pharmacy-list {
  overflow-y: auto; height: calc(55vh - 90px);
  padding: 0 10px 24px; -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

/* Ad slots */
.ad-slot {
  margin: 0 10px 10px; padding: 0; min-height: 50px;
  border-radius: var(--radius-md); overflow: hidden;
  background: rgba(31, 41, 55, 0.3);
}
.ad-slot .adsbygoogle { display: block; }
.ad-slot-inline {
  margin: 0 0 6px; min-height: 100px;
  border-radius: var(--radius-sm);
  background: rgba(31, 41, 55, 0.2);
  border: 1px dashed rgba(55, 65, 81, 0.3);
}
/* Hide empty ad slots when AdSense hasn't loaded */
.ad-slot:empty, .ad-slot-inline:empty { display: none; }
.ad-slot ins[data-ad-status="unfilled"] { display: none !important; }
.ad-slot-inline ins[data-ad-status="unfilled"] { display: none !important; }

/* Pharmacy card — touch-optimized */
.pharmacy-card {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 14px 12px; margin-bottom: 6px;
  background: var(--bg-tertiary); border-radius: var(--radius-md);
  border: 1px solid transparent; cursor: pointer;
  transition: var(--transition);
  -webkit-tap-highlight-color: transparent;
  min-height: 72px;
}
.pharmacy-card:active { border-color: var(--accent); background: rgba(16, 185, 129, 0.08); transform: scale(0.98); }

.card-icon {
  width: 40px; height: 40px; border-radius: var(--radius-sm); flex-shrink: 0;
  background: var(--accent-glow);
  display: flex; align-items: center; justify-content: center;
}
.card-icon svg { width: 18px; height: 18px; color: var(--accent); }

.card-info { flex: 1; min-width: 0; }
.card-name { font-size: 14px; font-weight: 600; margin-bottom: 2px; line-height: 1.3; }
.card-address {
  font-size: 12px; color: var(--text-muted); line-height: 1.3;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.card-meta { display: flex; align-items: center; gap: 10px; margin-top: 4px; }
.card-distance { font-size: 12px; font-weight: 700; color: var(--accent); }
.card-phone { font-size: 11px; color: var(--text-muted); }

/* ===== PHARMACY DETAIL (full-screen mobile) ===== */
.pharmacy-detail {
  position: fixed; inset: 0; z-index: 1100;
  pointer-events: none; opacity: 0; transition: opacity 0.3s;
}
.pharmacy-detail.open { pointer-events: auto; opacity: 1; }

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

.detail-panel {
  position: absolute; bottom: 0; left: 0; right: 0;
  max-height: 85vh; background: var(--bg-secondary);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  border-top: 1px solid var(--glass-border);
  transform: translateY(100%);
  transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  overflow-y: auto; padding: 0 0 calc(24px + var(--safe-bottom));
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}
.pharmacy-detail.open .detail-panel { transform: translateY(0); }

.detail-handle-bar {
  width: 40px; height: 5px; border-radius: var(--radius-full);
  background: var(--text-muted); opacity: 0.5;
  margin: 12px auto 8px;
}

.detail-close {
  position: absolute; top: 12px; right: 14px;
  width: 36px; height: 36px; border-radius: var(--radius-full);
  background: var(--bg-tertiary); display: flex; align-items: center; justify-content: center;
  transition: var(--transition); z-index: 1;
}
.detail-close svg { width: 16px; height: 16px; color: var(--text-muted); }
.detail-close:active { background: var(--danger); }
.detail-close:active svg { color: #fff; }

.detail-content { padding: 8px 16px 0; }

.detail-header { margin-bottom: 16px; }
.detail-name { font-size: 20px; font-weight: 700; padding-right: 44px; margin-bottom: 4px; line-height: 1.3; }
.detail-district { font-size: 13px; color: var(--accent); font-weight: 600; }

.detail-info-grid { display: flex; flex-direction: column; gap: 10px; margin-bottom: 20px; }

.detail-info-row {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 12px; background: var(--bg-tertiary); border-radius: var(--radius-md);
}
.detail-info-icon {
  width: 36px; height: 36px; border-radius: var(--radius-sm); flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
}
.detail-info-icon svg { width: 18px; height: 18px; }
.detail-info-icon.green { background: var(--accent-glow); color: var(--accent); }
.detail-info-icon.blue { background: rgba(6, 182, 212, 0.15); color: var(--accent-secondary); }
.detail-info-icon.orange { background: rgba(245, 158, 11, 0.15); color: #f59e0b; }

.detail-info-label { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; font-weight: 600; }
.detail-info-value { font-size: 14px; font-weight: 500; margin-top: 2px; line-height: 1.4; }

.detail-actions { display: flex; gap: 10px; }
.detail-btn {
  flex: 1; padding: 14px; border-radius: var(--radius-md);
  font-size: 15px; font-weight: 600; text-align: center;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  transition: var(--transition); min-height: 50px;
  -webkit-tap-highlight-color: transparent;
}
.detail-btn svg { width: 18px; height: 18px; }
.detail-btn-primary { background: var(--accent); color: #fff; }
.detail-btn-primary:active { background: var(--accent-hover); transform: scale(0.97); }
.detail-btn-secondary { background: var(--bg-tertiary); color: var(--text); border: 1px solid var(--glass-border); }
.detail-btn-secondary:active { border-color: var(--accent-secondary); color: var(--accent-secondary); }

/* ===== LOADING ===== */
.loading-overlay {
  position: fixed; inset: 0; z-index: 2000;
  background: var(--bg-primary);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 20px; transition: opacity 0.5s;
}
.loading-overlay.hidden { opacity: 0; pointer-events: none; }

.loading-spinner { position: relative; width: 56px; height: 56px; }
.spinner-ring {
  width: 56px; height: 56px; border-radius: 50%;
  border: 3px solid var(--bg-tertiary);
  border-top-color: var(--accent); animation: spin 1s linear infinite;
}
.spinner-icon {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%);
}
.spinner-icon svg { width: 20px; height: 20px; color: var(--accent); }
.loading-text { font-size: 14px; color: var(--text-muted); font-weight: 500; }

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

/* ===== RESPONSIVE ===== */
/* Desktop overrides */
@media (min-width: 768px) {
  :root { --header-h: 64px; --search-h: 56px; }
  .header-inner { padding: 0 16px; }
  .brand-icon { width: 40px; height: 40px; }
  .brand-icon svg { width: 22px; height: 22px; }
  .brand-text h1 { font-size: 17px; }
  .brand-subtitle { font-size: 11px; }
  #search-container { left: 12px; right: 12px; }
  .fab-list { bottom: calc(24px); right: 20px; }
  .bottom-sheet { left: auto; right: 16px; width: 400px; height: 60vh; border-radius: var(--radius-lg) var(--radius-lg) 0 0; }
  .pharmacy-list { height: calc(60vh - 90px); }
  .detail-panel { left: auto; right: 0; width: 420px; }
  .search-item:hover { background: var(--accent-glow); color: var(--text); }
  .pharmacy-card:hover { border-color: var(--accent); background: rgba(16, 185, 129, 0.05); }
  .popup-btn-directions:hover { background: var(--accent-hover); }
  .popup-btn-call:hover { border-color: var(--accent); color: var(--accent); }
  .btn-locate:hover { background: var(--accent); border-color: var(--accent); }
  .btn-locate:hover svg { color: #fff; }
  .btn-clear:hover { background: var(--danger); }
  .btn-clear:hover svg { color: #fff; }
  .detail-close:hover { background: var(--danger); }
  .detail-close:hover svg { color: #fff; }
  .detail-btn-primary:hover { background: var(--accent-hover); transform: translateY(-1px); }
  .detail-btn-secondary:hover { border-color: var(--accent-secondary); color: var(--accent-secondary); }
}

/* Very small phones */
@media (max-width: 374px) {
  .brand-text h1 { font-size: 13px; }
  .brand-subtitle { font-size: 9px; }
  .brand-icon { width: 32px; height: 32px; }
  .brand-icon svg { width: 16px; height: 16px; }
  .detail-name { font-size: 18px; }
}

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar { width: 3px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--text-muted); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-secondary); }
