/* =================================================================
   Apotheken-Notdienst Österreich – Styles
   ================================================================= */

:root {
  --c-primary: #0d6efd;
  --c-primary-dark: #0a58ca;
  --c-open: #198754;
  --c-oncall: #fd7e14;
  --c-closed: #dc3545;
  --c-user: #6f42c1;
  --c-bg: #ffffff;
  --c-bg-alt: #f8f9fa;
  --c-border: #e2e8f0;
  --c-text: #1e293b;
  --c-text-muted: #64748b;
  --c-text-light: #94a3b8;
  --header-h: 64px;
  --sidebar-w: 380px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.06);
  --shadow-md: 0 4px 12px rgba(0,0,0,.08);
  --shadow-lg: 0 12px 32px rgba(0,0,0,.16);
  --radius: 10px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
               Arial, "Noto Sans", "Liberation Sans", sans-serif;
  font-size: 15px;
  line-height: 1.5;
  color: var(--c-text);
  background: var(--c-bg);
}

/* ---------- Header ---------- */
.app-header {
  height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  background: linear-gradient(90deg, #0d6efd 0%, #0a58ca 100%);
  color: #fff;
  box-shadow: var(--shadow-md);
  position: relative;
  z-index: 1100;
}
.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}
.brand-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px; height: 40px;
  background: rgba(255,255,255,.18);
  border-radius: 10px;
  color: #fff;
}
.app-header h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -.01em;
}
.subtitle {
  margin: 0;
  font-size: 12px;
  opacity: .85;
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 14px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: var(--c-primary);
  color: #fff;
  font-size: 14px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: background .15s, transform .05s;
}
.btn:hover { background: var(--c-primary-dark); }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--c-primary); color: #fff; }
.btn-primary:hover { background: var(--c-primary-dark); }
.btn-ghost {
  background: rgba(255,255,255,.18);
  color: #fff;
  border-color: rgba(255,255,255,.25);
}
.btn-ghost:hover { background: rgba(255,255,255,.28); }
.btn-icon { padding: 9px 12px; }
.btn-label { display: inline; }

/* ---------- Layout ---------- */
.app-main {
  display: flex;
  height: calc(100% - var(--header-h));
  position: relative;
}
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--c-bg);
  border-right: 1px solid var(--c-border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 1000;
}
.map-wrap {
  flex: 1;
  position: relative;
  min-width: 0;
}
#map {
  width: 100%;
  height: 100%;
}

/* ---------- Search Bar ---------- */
.search-bar {
  display: flex;
  gap: 8px;
  padding: 14px 16px 8px;
  border-bottom: 1px solid var(--c-border);
  background: var(--c-bg-alt);
}
.filter-bar {
  padding: 0 16px 12px;
  border-bottom: 1px solid var(--c-border);
  background: var(--c-bg-alt);
}
.filter-bar .search-input-wrap {
  width: 100%;
}
.filter-bar #filterInput {
  padding: 7px 32px 7px 32px;
  font-size: 13px;
  background: #fff;
  border: 1px solid var(--c-border);
}
.filter-bar .search-icon {
  left: 10px;
  color: var(--c-text-light);
  width: 14px;
  height: 14px;
}
.search-input-wrap {
  position: relative;
  flex: 1;
  display: flex;
  align-items: center;
}
.search-icon {
  position: absolute;
  left: 10px;
  color: var(--c-text-light);
  pointer-events: none;
}
#searchInput {
  width: 100%;
  padding: 9px 32px 9px 34px;
  font-size: 14px;
  border: 1px solid var(--c-border);
  border-radius: 8px;
  font-family: inherit;
  background: #fff;
  color: var(--c-text);
  transition: border-color .15s, box-shadow .15s;
}
#searchInput:focus {
  outline: none;
  border-color: var(--c-primary);
  box-shadow: 0 0 0 3px rgba(13, 110, 253, .18);
}
.search-clear {
  position: absolute;
  right: 6px;
  border: none;
  background: transparent;
  font-size: 22px;
  color: var(--c-text-muted);
  cursor: pointer;
  padding: 0 6px;
  line-height: 1;
}
.search-clear:hover { color: var(--c-text); }

/* ---------- Filter Row ---------- */
.filter-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--c-border);
  background: #fff;
}
.checkbox {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--c-text);
  cursor: pointer;
  user-select: none;
}
.checkbox input { cursor: pointer; }

/* ---------- Status Bar ---------- */
.status-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 16px;
  background: var(--c-bg-alt);
  border-bottom: 1px solid var(--c-border);
  font-size: 13px;
  color: var(--c-text-muted);
  flex-wrap: wrap;
}
.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  background: #fff;
  border: 1px solid var(--c-border);
  border-radius: 999px;
  font-size: 12px;
  color: var(--c-text);
  font-weight: 500;
}
.status-pill.loading::before {
  content: '';
  width: 10px; height: 10px;
  border: 2px solid var(--c-border);
  border-top-color: var(--c-primary);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
.status-pill.ok { background: #d1e7dd; color: #0f5132; border-color: #badbcc; }
.status-pill.err { background: #f8d7da; color: #842029; border-color: #f5c2c7; }
@keyframes spin { to { transform: rotate(360deg); } }
.status-meta { font-size: 12px; }

/* ---------- Pharmacy List ---------- */
.pharmacy-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}
.pharmacy-card {
  padding: 12px;
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  margin-bottom: 8px;
  cursor: pointer;
  transition: border-color .15s, box-shadow .15s, transform .05s;
  background: #fff;
  position: relative;
}
.pharmacy-card:hover {
  border-color: var(--c-primary);
  box-shadow: var(--shadow-sm);
}
.pharmacy-card.active {
  border-color: var(--c-primary);
  box-shadow: 0 0 0 3px rgba(13, 110, 253, .15);
}
.pharmacy-card .name {
  font-weight: 600;
  font-size: 15px;
  color: var(--c-text);
  margin: 0 0 4px;
  padding-right: 90px;
}
.pharmacy-card .addr {
  font-size: 13px;
  color: var(--c-text-muted);
  margin: 0 0 6px;
}
.pharmacy-card .meta {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  flex-wrap: wrap;
}
.pharmacy-card .badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 8px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 11px;
  letter-spacing: .02em;
  text-transform: uppercase;
}
.badge.open  { background: #d1e7dd; color: #0f5132; }
.badge.on_call { background: #fff3cd; color: #664d03; }
.badge.closed { background: #f8d7da; color: #842029; }
.badge.unknown { background: #e2e8f0; color: #475569; }
.pharmacy-card .distance {
  color: var(--c-text-light);
  font-size: 12px;
}
.pharmacy-card .phone {
  color: var(--c-primary);
  text-decoration: none;
  font-size: 12px;
}
.pharmacy-card .phone:hover { text-decoration: underline; }

/* ---------- Map ---------- */
.gps-fab {
  position: absolute;
  top: 16px;
  right: 16px;
  z-index: 800;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: #fff;
  border: 2px solid var(--c-primary);
  color: var(--c-primary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(0,0,0,.2);
  transition: transform .15s, background .15s, color .15s;
  padding: 0;
  -webkit-appearance: none;
  appearance: none;
}
.gps-fab:hover {
  background: var(--c-primary);
  color: #fff;
  transform: scale(1.08);
}
.gps-fab:active { transform: scale(0.96); }
.gps-fab:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  background: #fff;
  color: var(--c-primary);
}
.gps-fab svg { display: block; }

.map-legend {
  position: absolute;
  bottom: 16px;
  right: 16px;
  background: #fff;
  padding: 10px 12px;
  border-radius: 8px;
  box-shadow: var(--shadow-md);
  font-size: 12px;
  z-index: 500;
  border: 1px solid var(--c-border);
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--c-text);
}
.dot {
  width: 12px; height: 12px;
  border-radius: 50%;
  display: inline-block;
}
.dot-open { background: var(--c-open); }
.dot-oncall { background: var(--c-oncall); }
.dot-closed { background: var(--c-closed); }
.dot-user {
  background: var(--c-user);
  border: 2px solid #fff;
  box-shadow: 0 0 0 1px var(--c-user);
}

/* Apotheken-Marker auf der Karte
   Design wie auf apothekerkammer.at: Pin-Form in Statusfarbe mit
   weißem Apotheker-Mörser-Symbol im Inneren.
   Die Pin-Form und Farbe werden komplett im inline SVG gesetzt (siehe app.js pinSVG). */
.pharmacy-marker {
  background: transparent;
  border: none;
}
.pharmacy-pin {
  display: block;
  width: 30px;
  height: 40px;
  position: relative;
  cursor: pointer;
  transition: transform .15s;
  transform-origin: bottom center;
  filter: drop-shadow(0 2px 3px rgba(0,0,0,.35));
}
.pharmacy-pin:hover { transform: scale(1.18); }
.pharmacy-pin svg {
  display: block;
  width: 30px;
  height: 40px;
}

/* MarkerCluster Styling (ersetzt Default-CSS durch unsere Farben) */
.marker-cluster {
  background-color: rgba(13, 110, 253, 0.15);
  border-radius: 50%;
}
.marker-cluster > div {
  background-color: rgba(13, 110, 253, 0.85);
  color: #fff;
  width: 36px;
  height: 36px;
  margin-left: 2px;
  margin-top: 2px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  border: 2px solid #fff;
  box-shadow: 0 2px 4px rgba(0,0,0,.3);
}
.marker-cluster-small { background-color: rgba(25, 135, 84, 0.15); }
.marker-cluster-small > div { background-color: rgba(25, 135, 84, 0.85); }
.marker-cluster-medium { background-color: rgba(253, 126, 20, 0.15); }
.marker-cluster-medium > div { background-color: rgba(253, 126, 20, 0.85); }
.marker-cluster-large { background-color: rgba(220, 53, 69, 0.15); }
.marker-cluster-large > div { background-color: rgba(220, 53, 69, 0.85); }

.user-marker {
  background: transparent;
  border: none;
}
.user-pin {
  width: 20px; height: 20px;
  border-radius: 50%;
  background: var(--c-user);
  border: 3px solid #fff;
  box-shadow: 0 0 0 4px rgba(111, 66, 193, .35), 0 2px 6px rgba(0,0,0,.3);
  animation: pulse 2s infinite;
}
@keyframes pulse {
  0%   { box-shadow: 0 0 0 0 rgba(111, 66, 193, .5), 0 2px 6px rgba(0,0,0,.3); }
  70%  { box-shadow: 0 0 0 14px rgba(111, 66, 193, 0), 0 2px 6px rgba(0,0,0,.3); }
  100% { box-shadow: 0 0 0 0 rgba(111, 66, 193, 0), 0 2px 6px rgba(0,0,0,.3); }
}

/* Leaflet Popup Anpassung */
.leaflet-popup-content-wrapper {
  border-radius: 10px;
  box-shadow: var(--shadow-lg);
}
.leaflet-popup-content {
  margin: 12px 14px;
  font-size: 13px;
  line-height: 1.45;
}
.popup-title {
  font-weight: 600;
  font-size: 14px;
  margin: 0 0 4px;
  color: var(--c-text);
}
.popup-addr { color: var(--c-text-muted); margin: 0 0 6px; }
.popup-actions {
  display: flex;
  gap: 6px;
  margin-top: 8px;
  flex-wrap: wrap;
}
.popup-actions a, .popup-actions button {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 5px 10px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
  text-decoration: none;
  border: 1px solid var(--c-border);
  background: #fff;
  color: var(--c-text);
  cursor: pointer;
  font-family: inherit;
}
.popup-actions a.primary, .popup-actions button.primary {
  background: var(--c-primary);
  color: #fff;
  border-color: var(--c-primary);
}
.popup-actions a:hover, .popup-actions button:hover {
  background: var(--c-bg-alt);
}
.popup-actions a.primary:hover, .popup-actions button.primary:hover {
  background: var(--c-primary-dark);
}

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, .55);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  animation: fadeIn .15s;
}
/* WICHTIG: [hidden] muss display:flex überschreiben, sonst blockiert
   das unsichtbare Modal die ganze Seite. */
.modal-backdrop[hidden] {
  display: none !important;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.modal {
  background: #fff;
  border-radius: 14px;
  max-width: 520px;
  width: 100%;
  max-height: 88vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  position: relative;
  animation: slideUp .2s;
}
@keyframes slideUp { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
.modal-close {
  position: absolute;
  top: 12px; right: 12px;
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--c-bg-alt);
  border: 1px solid var(--c-border);
  cursor: pointer;
  font-size: 24px;
  color: var(--c-text-muted);
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal-close:hover { background: var(--c-border); color: var(--c-text); }
.modal-body {
  padding: 24px 24px 20px;
}
.modal-body .modal-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .03em;
  margin-bottom: 12px;
}
.modal-body h2 {
  margin: 0 0 8px;
  font-size: 22px;
  font-weight: 700;
  color: var(--c-text);
}
.modal-body .modal-addr {
  color: var(--c-text-muted);
  margin: 0 0 16px;
  font-size: 14px;
}
.modal-section {
  margin: 16px 0;
  padding-top: 14px;
  border-top: 1px solid var(--c-border);
}
.modal-section h3 {
  margin: 0 0 8px;
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--c-text-muted);
}
.modal-section dl {
  display: grid;
  grid-template-columns: 32px 1fr;
  gap: 6px 12px;
  margin: 0;
  font-size: 14px;
}
.modal-section dl dt {
  font-weight: 600;
  color: var(--c-text);
}
.modal-section dl dd {
  margin: 0;
  color: var(--c-text-muted);
}
.modal-section ul.svc-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.modal-section ul.svc-list li {
  background: var(--c-bg-alt);
  border: 1px solid var(--c-border);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
  color: var(--c-text);
}
.modal-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 18px;
}
.modal-actions a, .modal-actions button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  text-decoration: none;
  border: 1px solid var(--c-border);
  background: #fff;
  color: var(--c-text);
  cursor: pointer;
  font-family: inherit;
  transition: background .15s, transform .05s;
}
.modal-actions a:hover, .modal-actions button:hover {
  background: var(--c-bg-alt);
}
.modal-actions a.primary {
  background: var(--c-primary);
  color: #fff;
  border-color: var(--c-primary);
}
.modal-actions a.primary:hover { background: var(--c-primary-dark); }
.modal-actions a.success {
  background: var(--c-open);
  color: #fff;
  border-color: var(--c-open);
}
.modal-actions a.success:hover { filter: brightness(.92); }
.modal-actions a:active, .modal-actions button:active { transform: translateY(1px); }

/* ---------- Responsive: Mobile (Karte fullscreen, Sidebar als Slide-In) ---------- */
/* Hamburger-Button: standardmäßig sichtbar, nur auf Desktop ausblenden */
.menu-toggle {
  display: inline-flex;
  background: transparent;
  border: none;
  color: #fff;
  padding: 8px;
  margin-right: 4px;
  cursor: pointer;
  border-radius: 6px;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  -webkit-appearance: none;
  appearance: none;
}
.menu-toggle:hover { background: rgba(255,255,255,.18); }
.menu-toggle svg { width: 22px; height: 22px; display: block; }

.sidebar-backdrop {
  display: none;
}

@media (min-width: 861px) {
  /* Desktop: Hamburger-Button verstecken, Backdrop auch */
  .menu-toggle { display: none; }
  .sidebar-backdrop { display: none !important; }
  /* Auf Desktop: Sidebar wieder in normaler Position */
  .sidebar {
    position: static !important;
    transform: none !important;
    width: var(--sidebar-w) !important;
    height: auto !important;
    box-shadow: none !important;
  }
}

@media (max-width: 860px) {
  :root { --header-h: 56px; --sidebar-w: 88%; }

  /* Header kompakter auf Mobile */
  .app-header {
    padding: 0 8px;
    gap: 4px;
  }
  .brand { gap: 8px; flex: 1; min-width: 0; }
  .app-header h1 {
    font-size: 14px;
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .brand-icon {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    flex-shrink: 0;
  }
  .brand-icon svg {
    width: 22px;
    height: 28px;
  }

  /* Sidebar als Slide-In-Panel von links */
  .sidebar {
    position: fixed;
    top: var(--header-h);
    left: 0;
    bottom: 0;
    width: var(--sidebar-w);
    max-width: 380px;
    height: calc(100vh - var(--header-h));
    background: #fff;
    z-index: 1500;
    transform: translateX(-100%);
    transition: transform .25s ease;
    box-shadow: 4px 0 16px rgba(0,0,0,.15);
    border-right: 1px solid var(--c-border);
  }
  .sidebar.open {
    transform: translateX(0);
  }

  /* Karte über den ganzen Bildschirm */
  .app-main {
    flex-direction: column;
  }
  .map-wrap {
    flex: 1;
    width: 100%;
    height: calc(100vh - var(--header-h));
  }
  #map {
    width: 100%;
    height: 100%;
  }

  /* Backdrop wenn Sidebar offen */
  .sidebar-backdrop {
    position: fixed;
    top: var(--header-h);
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,.4);
    z-index: 1400;
    opacity: 0;
    pointer-events: none;
    transition: opacity .25s ease;
    display: block;
  }
  .sidebar-backdrop.open {
    opacity: 1;
    pointer-events: auto;
  }

  .btn-label { display: none; }
  .map-legend {
    bottom: 12px; right: 12px;
    padding: 6px 10px;
    font-size: 11px;
  }

  /* GPS-FAB auch auf Mobile sichtbar (etwas kleiner) */
  .gps-fab {
    top: 12px;
    right: 12px;
    width: 40px;
    height: 40px;
  }
  .gps-fab svg { width: 20px; height: 20px; }
}

@media (max-width: 480px) {
  .app-header { padding: 0 6px; gap: 2px; }
  .app-header h1 { font-size: 13px; }
  .brand { gap: 6px; }
  .brand-icon { width: 28px; height: 28px; }
  .brand-icon svg { width: 18px; height: 24px; }
  .search-bar { padding: 10px 12px; }
  .filter-bar { padding: 0 12px 10px; }
  .filter-row { padding: 8px 12px; }
  .pharmacy-card { padding: 10px; }
  .map-legend { display: none; }
}
