/* ==========================================================================
   Fontaines Paris — styles
   ========================================================================== */

:root {
  color-scheme: light;

  --bg: #eef3f8;
  --surface: rgba(255, 255, 255, 0.86);
  --surface-solid: #ffffff;
  --text: #10192b;
  --muted: #5b6b7f;
  --border: rgba(16, 25, 43, 0.08);

  --primary: #0B63C5;
  --primary-strong: #084a94;
  --primary-soft: rgba(11, 99, 197, 0.12);
  --available: #1791c8;
  --unavailable: #97a2b0;

  --shadow-sm: 0 2px 10px rgba(16, 30, 60, 0.10);
  --shadow-md: 0 10px 30px rgba(16, 30, 60, 0.16);
  --shadow-lg: 0 18px 48px rgba(16, 30, 60, 0.22);

  --radius-lg: 22px;
  --radius-md: 16px;
  --radius-sm: 12px;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

html[data-theme='dark'] {
  color-scheme: dark;

  --bg: #0a1220;
  --surface: rgba(22, 31, 46, 0.82);
  --surface-solid: #16202e;
  --text: #eef3fb;
  --muted: #93a3b8;
  --border: rgba(255, 255, 255, 0.08);

  --primary: #59a8ee;
  --primary-strong: #8cc4f5;
  --primary-soft: rgba(89, 168, 238, 0.16);
  --available: #4fb9e8;
  --unavailable: #6c7889;

  --shadow-sm: 0 2px 10px rgba(0, 0, 0, 0.35);
  --shadow-md: 0 10px 30px rgba(0, 0, 0, 0.45);
  --shadow-lg: 0 18px 48px rgba(0, 0, 0, 0.55);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  /* Do NOT put `position: fixed` on html/body. In an iOS standalone PWA with
     viewport-fit=cover that is exactly what breaks full-height layout: WebKit
     leaves a gap at the bottom the size of the home-indicator safe area, and
     no height unit (100vh / 100% / 100dvh / -webkit-fill-available) closes it
     (WebKit bug 237961). The full-screen layers below are `position: fixed`
     CHILDREN of <body> instead — a fixed *child* stretched with
     top/right/bottom/left:0 DOES fill the whole physical screen (incl. safe
     areas) per StackOverflow 79902310. Rubber-band bounce is prevented with
     overflow:hidden + overscroll-behavior, not by pinning html/body. */
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
}

#map {
  /* Full-bleed map. Stretch a position:fixed CHILD to all four viewport edges
     (top/right/bottom/left:0, no explicit width/height). In an iOS standalone
     PWA with viewport-fit=cover this is the ONE approach that reaches the true
     physical screen edges incl. the home-indicator safe area — provided
     html/body are NOT position:fixed (see the html/body rule + WebKit bug
     237961 / StackOverflow 79902310). Sizing a fixed element with 100vh/100dvh
     or env() insets all leave a bottom gap on cold start; inset:0 does not.
     app.js also calls map.invalidateSize() so Leaflet's tiles fill the box. */
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  background: var(--bg);
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: none;
  cursor: pointer;
}
input { font: inherit; color: inherit; }

/* ---------------------------------------------------------------------- */
/* Loading overlay                                                          */
/* ---------------------------------------------------------------------- */
.loading-overlay {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 900;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  transition: opacity .35s ease, visibility .35s ease;
}
.loading-overlay[hidden] { display: none; }
.loading-overlay.is-fading { opacity: 0; visibility: hidden; }

.loading-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 28px 32px;
  border-radius: var(--radius-lg);
  background: var(--surface-solid);
  box-shadow: var(--shadow-md);
  color: var(--muted);
  font-size: 14px;
  max-width: 260px;
  text-align: center;
}

.spinner {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 3px solid var(--primary-soft);
  border-top-color: var(--primary);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------------------------------------------------------------------- */
/* Theme toggle — standalone corner button (kept out of the sheet so it's  */
/* reachable regardless of expand/collapse state)                          */
/* ---------------------------------------------------------------------- */
.theme-fab {
  position: fixed;
  top: calc(var(--safe-top) + 12px);
  right: calc(var(--safe-right) + 12px);
  z-index: 500;
  width: 40px;
  height: 40px;
  flex-shrink: 0;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface);
  backdrop-filter: blur(20px) saturate(160%);
  -webkit-backdrop-filter: blur(20px) saturate(160%);
  color: var(--primary);
  box-shadow: var(--shadow-md);
  border: 1px solid var(--border);
  transition: background .15s ease, transform .15s ease;
}
.theme-fab:active { transform: scale(0.92); }

/* ---------------------------------------------------------------------- */
/* Brand row — now lives inside the sheet body                             */
/* ---------------------------------------------------------------------- */
.brand-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
.brand-row strong { font-size: 14.5px; letter-spacing: -0.01em; color: var(--text); }

.brand-logo {
  border-radius: 7px;
  display: block;
  flex-shrink: 0;
}

.search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 9px 12px;
  color: var(--muted);
  flex-shrink: 0;
}
html[data-theme='dark'] .search-box { background: rgba(255,255,255,0.05); }

.search-box svg { flex-shrink: 0; }

.search-box input {
  border: none;
  outline: none;
  background: transparent;
  flex: 1;
  min-width: 0;
  font-size: 15px;
  color: var(--text);
}
.search-box input::placeholder { color: var(--muted); }

.search-box input::-webkit-search-cancel-button { display: none; }

.clear-btn {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--border);
  color: var(--muted);
  flex-shrink: 0;
}

.chip-row {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
  overflow-x: auto;
  scrollbar-width: none;
}
.chip-row::-webkit-scrollbar { display: none; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 13px;
  border-radius: 999px;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  transition: background .15s ease, color .15s ease, border-color .15s ease;
}
html[data-theme='dark'] .chip { background: rgba(255,255,255,0.05); }

.chip-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--unavailable);
  transition: background .15s ease;
}

.chip[aria-pressed='true'] {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}
.chip[aria-pressed='true'] .chip-dot { background: #fff; }

/* ---------------------------------------------------------------------- */
/* Floating action buttons — nested inside the sheet, anchored just above  */
/* its top edge, so they slide up/down together with it automatically.     */
/* ---------------------------------------------------------------------- */
.fab-stack {
  position: absolute;
  right: 14px;
  bottom: 100%;
  margin-bottom: 14px;
  z-index: 480;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.fab {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: var(--surface-solid);
  color: var(--primary);
  box-shadow: var(--shadow-md);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform .15s ease;
}
.fab:active { transform: scale(0.92); }
.fab.is-loading svg { animation: spin 1s linear infinite; }

#zoom-out-btn { color: var(--text); }
#zoom-in-btn { color: var(--text); }

/* ---------------------------------------------------------------------- */
/* Bottom sheet                                                             */
/* ---------------------------------------------------------------------- */
.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 490;
  background: var(--surface);
  backdrop-filter: blur(20px) saturate(160%);
  -webkit-backdrop-filter: blur(20px) saturate(160%);
  border-radius: 20px 20px 0 0;
  box-shadow: 0 -8px 30px rgba(16, 30, 60, 0.16);
  border-top: 1px solid var(--border);
  padding-bottom: calc(var(--safe-bottom) + 10px);
  transform: translateY(calc(100% - var(--sheet-peek, 64px) - var(--safe-bottom)));
  transition: transform .32s cubic-bezier(.32,.72,0,1);
  max-height: 68vh;
  display: flex;
  flex-direction: column;
}

.sheet[data-state='expanded'] {
  transform: translateY(0);
}

.sheet-header {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  flex-shrink: 0;
  padding: 10px 18px 8px;
  text-align: left;
  position: relative;
  z-index: 1;
  background: transparent;
}
.sheet-handle-bar {
  width: 38px;
  height: 5px;
  border-radius: 3px;
  background: var(--border);
  margin-bottom: 10px;
}
.sheet-peek-row {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}
.sheet-peek-row .chevron {
  flex-shrink: 0;
  color: var(--muted);
  transition: transform .3s ease;
}
.sheet[data-state='expanded'] .sheet-peek-row .chevron {
  transform: rotate(180deg);
}

.sheet-body {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
  flex: 1 1 auto;
  padding: 2px 18px 0;
}

.sheet-content {
  padding: 6px 0 18px;
  margin: 0 -2px;
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.sheet-empty {
  margin: 6px 0 4px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
  text-align: center;
}

.sheet-title {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
  margin: 4px 0 10px;
}

.result-row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 10px 6px;
  border-radius: var(--radius-sm);
  text-align: left;
  border-bottom: 1px solid var(--border);
}
.result-row:last-child { border-bottom: none; }
.result-row:active { background: var(--primary-soft); }

.result-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--available);
}
.result-dot.is-off { background: var(--unavailable); }

.result-text {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.result-addr {
  display: block;
  font-size: 14.5px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.result-sub {
  display: block;
  font-size: 12.5px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.result-dist {
  font-size: 13px;
  font-weight: 600;
  color: var(--primary);
  flex-shrink: 0;
}

/* ---------------------------------------------------------------------- */
/* Toast                                                                    */
/* ---------------------------------------------------------------------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--safe-bottom) + 76px);
  transform: translate(-50%, 0);
  z-index: 700;
  background: #1c2431;
  color: #fff;
  padding: 11px 18px;
  border-radius: 999px;
  font-size: 13.5px;
  box-shadow: var(--shadow-md);
  max-width: 88vw;
  text-align: center;
  animation: toast-in .25s ease;
}
@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, 8px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

/* ---------------------------------------------------------------------- */
/* Leaflet overrides                                                        */
/* ---------------------------------------------------------------------- */
.leaflet-container {
  font-family: inherit;
  background: var(--bg);
}

.leaflet-control-attribution {
  background: var(--surface) !important;
  color: var(--muted) !important;
  backdrop-filter: blur(8px);
  border-radius: 8px 0 0 0;
  padding: 2px 8px !important;
}
.leaflet-control-attribution a { color: var(--muted) !important; }

.leaflet-popup-content-wrapper {
  background: var(--surface-solid);
  color: var(--text);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
}
.leaflet-popup-tip { background: var(--surface-solid); }
.leaflet-popup-content { margin: 14px 16px; min-width: 200px; }
.leaflet-popup-close-button {
  color: var(--muted) !important;
  top: 10px !important;
  right: 10px !important;
}

.popup-title {
  font-size: 15px;
  font-weight: 700;
  margin: 0 0 2px;
}
.popup-sub {
  font-size: 12.5px;
  color: var(--muted);
  margin: 0 0 10px;
}
.popup-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 8px;
}
.popup-badge.is-ok { background: rgba(23, 145, 200, 0.14); color: var(--available); }
.popup-badge.is-off { background: rgba(151, 162, 176, 0.18); color: var(--muted); }
.popup-badge::before {
  content: '';
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
}
.popup-meta {
  font-size: 12.5px;
  color: var(--muted);
  line-height: 1.5;
  margin: 0;
}
.popup-meta strong { color: var(--text); font-weight: 600; }

/* Fountain markers */
.fp-marker {
  display: flex;
  align-items: center;
  justify-content: center;
  filter: drop-shadow(0 2px 4px rgba(10, 20, 40, 0.35));
}
.fp-marker svg { display: block; }

/* User location marker */
.fp-user-marker {
  width: 20px;
  height: 20px;
  position: relative;
}
.fp-user-marker::before,
.fp-user-marker::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 50%;
}
.fp-user-marker::before {
  background: rgba(11, 99, 197, 0.35);
  animation: pulse 2.2s ease-out infinite;
}
.fp-user-marker::after {
  background: #0B63C5;
  border: 3px solid #fff;
  box-shadow: 0 1px 6px rgba(0,0,0,0.4);
  transform: scale(0.45);
}
@keyframes pulse {
  0% { transform: scale(0.45); opacity: 1; }
  100% { transform: scale(2.2); opacity: 0; }
}

/* Marker cluster overrides */
.marker-cluster-small,
.marker-cluster-medium,
.marker-cluster-large {
  background: rgba(11, 99, 197, 0.18);
}
.marker-cluster-small div,
.marker-cluster-medium div,
.marker-cluster-large div {
  background: var(--primary);
  color: #fff;
  font-weight: 700;
  font-size: 12px;
}
.marker-cluster div { width: 30px; height: 30px; line-height: 30px; margin-left: 5px; margin-top: 5px; }

/* ---------------------------------------------------------------------- */
/* Responsive: wider screens                                                */
/* ---------------------------------------------------------------------- */
@media (min-width: 620px) {
  .sheet { left: calc(var(--safe-left) + 16px); right: auto; width: 380px; bottom: calc(var(--safe-bottom) + 16px); border-radius: var(--radius-lg); max-height: 60vh; }
  .sheet:not([data-state='expanded']) { transform: translateY(calc(100% - var(--sheet-peek, 64px))); }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}
