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

:root {
  --green: #2E7D32;
  --green-light: #E8F5E9;
  --green-mid: #388E3C;
  --orange: #E65100;
  --orange-light: #FFF3E0;
  --text: #1a1a1a;
  --muted: #666;
  --border: #e0e0e0;
  --bg: #f5f6f8;
  --card-bg: #ffffff;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
  --radius: 10px;
}

html { overflow-x: hidden; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

/* ── Header ── */
header {
  background: var(--green);
  color: #fff;
  padding: 12px 14px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.2);
  flex-shrink: 0;
}

.header-inner {
  max-width: 1100px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.header-title { display: flex; align-items: center; gap: 10px; min-width: 0; }

.cross { font-size: 24px; line-height: 1; opacity: 0.9; flex-shrink: 0; }

h1 {
  font-size: 16px;
  font-weight: 700;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.subtitle { font-size: 11px; opacity: 0.8; margin-top: 1px; white-space: nowrap; }

.header-date {
  font-size: 11px;
  opacity: 0.85;
  text-align: right;
  flex-shrink: 0;
  max-width: 120px;
  line-height: 1.3;
}

@media (min-width: 480px) {
  h1 { font-size: 18px; }
  .header-date { font-size: 13px; max-width: none; }
  .cross { font-size: 28px; }
}

/* ── Nav bar (view toggle + locate) ── */
.nav-bar {
  background: #fff;
  border-bottom: 1px solid var(--border);
  padding: 8px 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.view-toggle {
  display: flex;
  flex: 1;
  background: #f0f2f4;
  border-radius: 12px;
  padding: 3px;
  gap: 3px;
  opacity: 0;
  transition: opacity 0.15s ease;
}

.view-toggle.ready { opacity: 1; }

.view-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 10px;
  border: none;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.18s;
  white-space: nowrap;
  touch-action: manipulation;
}

.view-btn .view-icon { font-size: 15px; line-height: 1; }

.view-btn.active {
  background: #fff;
  color: var(--text);
  font-weight: 600;
  box-shadow: 0 1px 4px rgba(0,0,0,0.12);
}

.view-btn[data-view="duty"].active   { color: var(--orange); }
.view-btn[data-view="open"].active   { color: var(--green); }
.view-btn[data-view="soon"].active   { color: #5C6BC0; }
.view-btn[data-view="closed"].active { color: #757575; }

/* ── Locate button ── */
.locate-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 0;
  width: 38px;
  height: 38px;
  border: 1.5px solid var(--green);
  border-radius: 50%;
  background: var(--green-light);
  color: var(--green);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  flex-shrink: 0;
  touch-action: manipulation;
}

.locate-text { display: none; }

@media (min-width: 540px) {
  .locate-btn { width: auto; height: auto; padding: 8px 14px; border-radius: 20px; }
  .locate-text { display: inline; }
}

.locate-btn:hover  { background: var(--green); color: #fff; }
.locate-btn.active { background: var(--green); color: #fff; }
.locate-btn.loading { opacity: 0.6; cursor: not-allowed; }
.locate-icon { font-size: 18px; }

/* ── District filter ── */
.controls {
  background: #fff;
  border-bottom: 1px solid var(--border);
  padding: 6px 12px;
  flex-shrink: 0;
}

.district-tabs {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  padding: 2px 0;
}

.district-tabs::-webkit-scrollbar { display: none; }

.tab {
  flex-shrink: 0;
  padding: 5px 13px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: #fff;
  color: var(--muted);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
  min-height: 32px;
  touch-action: manipulation;
}

.tab:hover  { border-color: var(--green); color: var(--green); }
.tab.active { background: var(--green); color: #fff; border-color: var(--green); }

/* ── Main layout ── */
.main-layout {
  flex: 1;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 1100px;
  margin: 0 auto;
  min-height: 0;
}

@media (min-width: 768px) {
  .main-layout { flex-direction: row; align-items: flex-start; padding: 16px; gap: 16px; }
}

#map {
  height: 220px;
  width: 100%;
  z-index: 1;
  flex-shrink: 0;
}

/* ── Mobile: collapsing map + internal-scroll list ── */
@media (max-width: 767px) {
  body { overflow: hidden; height: 100dvh; }

  .main-layout { overflow: hidden; }

  #map { flex-shrink: 0; }

  .list-panel {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
}

@media (min-width: 480px) {
  #map { height: 260px; }
}

@media (min-width: 768px) {
  #map {
    height: calc(100vh - 170px);
    width: 42%;
    border-radius: var(--radius);
    position: sticky;
    top: 16px;
  }
}

/* ── List panel ── */
.list-panel {
  flex: 1;
  padding: 8px 8px 16px;
  display: flex;
  flex-direction: column;
  gap: 2px;           /* 2px between cards */
  min-width: 0;
}

@media (min-width: 768px) {
  .list-panel {
    padding: 0;
    overflow-y: auto;
    max-height: calc(100vh - 170px);
    gap: 2px;
  }
}

/* ── Status banner ── */
.status-banner {
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 13px;
  text-align: center;
  margin-bottom: 4px;
}

.status-banner.info   { background: #E3F2FD; color: #0D47A1; }
.status-banner.warn   { background: #FFF8E1; color: #F57F17; }
.status-banner.err    { background: #FFEBEE; color: #B71C1C; }
.status-banner.hidden { display: none; }

#pharmacy-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

/* ── Pharmacy card ── */
.pharmacy-card {
  background: var(--card-bg);
  border-radius: 0;
  box-shadow: none;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  border-left: 4px solid var(--green);
  cursor: default;
  transition: background 0.12s;
  border-bottom: 1px solid #f0f0f0;
}

/* Round corners only on first/last cards */
.pharmacy-card:first-child { border-radius: var(--radius) var(--radius) 0 0; }
.pharmacy-card:last-child  { border-radius: 0 0 var(--radius) var(--radius); border-bottom: none; }
.pharmacy-card:only-child  { border-radius: var(--radius); border-bottom: none; }

.pharmacy-card:hover       { background: #fafafa; }
.pharmacy-card.highlighted { background: #f0f7f0; }

/* On-duty card: amber left border */
.pharmacy-card.is-duty   { border-left-color: var(--orange); }
/* Closed card: neutral gray left border */
.pharmacy-card.is-closed { border-left-color: #bdbdbd; }

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


.pharmacy-name { font-size: 15px; font-weight: 600; line-height: 1.3; }

.distance-badge {
  font-size: 12px;
  font-weight: 600;
  background: var(--green-light);
  color: var(--green);
  padding: 3px 10px;
  border-radius: 12px;
  white-space: nowrap;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 6px;
}

.pharmacy-hours  { font-size: 13px; color: var(--green); font-weight: 500; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.pharmacy-hours--closed {
  color: var(--muted);
  opacity: 0.6;
}

.closed-badge   { white-space: nowrap; }
.open-now-badge { white-space: nowrap; color: var(--green); }

.closing-badge {
  font-size: 11px;
  font-weight: 600;
  background: #FFF3E0;
  color: #E65100;
  border: 1px solid #FFCC80;
  padding: 1px 7px;
  border-radius: 10px;
  white-space: nowrap;
}
.opening-soon-badge { white-space: nowrap; color: #5C6BC0; }
.pharmacy-address   { font-size: 13px; color: var(--text); }
.pharmacy-extra     { font-size: 12px; color: var(--muted); font-style: italic; }
.pharmacy-municipality { font-size: 12px; color: var(--muted); }
.district-inline { color: var(--muted); }

.duty-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  background: var(--orange-light);
  color: var(--orange);
  padding: 2px 8px;
  border-radius: 10px;
  align-self: flex-start;
}

.card-action-icons {
  display: flex;
  gap: 8px;
  align-items: center;
}

.card-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 2px;
  gap: 8px;
}

.phone-link {
  font-size: 14px;
  color: var(--green);
  text-decoration: none;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: 40px;
  touch-action: manipulation;
}

.phone-link:hover { text-decoration: underline; }

.directions-btn,
.share-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  touch-action: manipulation;
  flex-shrink: 0;
}

.directions-btn {
  background: var(--green);
  color: #fff;
  border: none;
}

.directions-btn:hover { background: var(--green-mid); }

.share-btn {
  background: none;
  color: var(--muted);
  border: 1px solid var(--border);
}

.share-btn:hover { border-color: var(--green); color: var(--green); }

@media (max-width: 400px) {
  .card-actions { gap: 6px; }
}

/* ── Empty / loading ── */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--muted);
}

.empty-state h2 { font-size: 18px; margin-bottom: 8px; }
.empty-state p  { font-size: 14px; }

.loading-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.6;
}

/* ── Footer ── */
footer {
  text-align: center;
  padding: 12px 16px;
  font-size: 10px;
  color: var(--muted);
  border-top: 1px solid var(--border);
  background: #fff;
  line-height: 1.7;
  flex-shrink: 0;
}

footer a { color: var(--green); text-decoration: none; }
footer a:hover { text-decoration: underline; }

/* ── Location modal ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 1000;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  backdrop-filter: blur(2px);
}

@media (min-width: 480px) {
  .modal-overlay { align-items: center; padding: 16px; }
}

.modal-overlay.hidden { display: none; }

.modal-card {
  background: #fff;
  border-radius: 18px 18px 0 0;
  padding: 28px 24px 36px;
  width: 100%;
  max-width: 420px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 10px;
  box-shadow: 0 -4px 30px rgba(0,0,0,0.15);
}

@media (min-width: 480px) {
  .modal-card { border-radius: 18px; padding: 32px 28px; box-shadow: 0 8px 40px rgba(0,0,0,0.2); }
}

.modal-icon { font-size: 40px; color: var(--green); line-height: 1; margin-bottom: 4px; }
.modal-card h2 { font-size: 20px; font-weight: 700; color: var(--text); white-space: normal; }
.modal-card p  { font-size: 14px; color: var(--muted); line-height: 1.6; }
.modal-sub     { font-size: 12px !important; opacity: 0.7; }

.modal-actions { display: flex; flex-direction: column; gap: 10px; margin-top: 8px; }

.modal-btn-primary {
  padding: 14px;
  background: var(--green);
  color: #fff;
  border: none;
  border-radius: 12px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
  transition: background 0.15s;
}

.modal-btn-primary:hover { background: var(--green-mid); }

.modal-btn-skip {
  padding: 12px;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 14px;
  cursor: pointer;
  touch-action: manipulation;
}

.modal-btn-skip:hover { color: var(--text); }

/* ── Leaflet tweaks ── */
.leaflet-popup-content { font-size: 13px; line-height: 1.5; min-width: 160px; }
.leaflet-popup-content b { font-weight: 700; }
.leaflet-control-zoom a { min-height: 30px; min-width: 30px; }
