
/* =========================================
   UI Overrides: scroll & spacing polish
   (Safe: CSS-only, no functional changes)
   ========================================= */

/* --- Global scrolling polish --- */
html {
  /* prevent layout shift when scrollbars appear */
  scrollbar-gutter: stable both-edges;
  /* if you use anchor links, avoid sticky navbar overlap */
  scroll-padding-top: var(--nav-height, 56px);
}

body {
  -webkit-text-size-adjust: 100%;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* --- Spacing scale fallback (if not defined) --- */
:root {
  --space-2xs: 4px;
  --space-xs: 6px;
  --space-sm: 10px;
  --space-md: 16px;
  --space-lg: 24px;
}

/* --- Panels & common blocks --- */
.panel + .panel { margin-top: var(--space-md); }
@media (max-width: 600px) {
  .panel + .panel { margin-top: var(--space-sm); }
}

/* --- Navbar tweaks (no behavior change) --- */
.navbar {
  margin-bottom: var(--space-sm);
  backdrop-filter: saturate(180%) blur(8px);
  -webkit-backdrop-filter: saturate(180%) blur(8px);
}
@media (max-width: 720px) {
  .navbar { margin-bottom: var(--space-xs); }
  .navbar .nav-links {
    /* allow horizontal scroll if links overflow on tiny screens */
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-gutter: stable;
  }
}

/* --- Grid and weekday spacing consistency --- */
.weekdays { gap: var(--space-xs); margin: var(--space-xs) 0 var(--space-sm); }
.grid { gap: var(--space-sm); margin: var(--space-sm) 0; }

/* --- Map & card polish --- */
.grid-card { overflow: hidden; border-radius: 12px; }
.map { border-radius: 12px; }
.map-image { display: block; width: 100%; height: auto; }

/* --- Dialog (modal) consolidation --- */
.dialog { 
  position: fixed; inset: 0; display: none;
  background: rgba(0,0,0,0.45); z-index: 9999;
  padding: 16px;
}
.dialog.show { display: flex; align-items: center; justify-content: center; }

.dialog .dialog-card {
  background: var(--card, #fff);
  width: min(92vw, 760px);
  max-width: 760px;
  max-height: 90vh;
  margin: 4vh auto;
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0,0,0,.15);
  overflow: hidden;
  display: flex; flex-direction: column;
}

/* Sticky header inside dialog */
.dialog .dialog-card > h2 {
  margin: 0;
  padding: 16px 56px 12px 16px;
  position: sticky; top: 0;
  background: var(--card, #fff);
  z-index: 1;
}

/* Scroll area in dialog content */
#dlgList.activities {
  padding: 16px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

/* Activity items spacing (first/last tidy) */
#dlgList .activity { margin: var(--space-sm) 0; }
#dlgList .activity:first-child { margin-top: 0; }
#dlgList .activity:last-child { margin-bottom: 0; }
#dlgList .activity h3 { margin: 0 0 6px; }
#dlgList .activity p { margin: 4px 0; }
#dlgList .activity p:last-child { margin-bottom: 0; }

/* Close button hit area & focus */
.dialog .dialog-card .close {
  position: absolute; top: 10px; right: 10px;
  width: 36px; height: 36px; border-radius: 10px;
  border: none; background: #111; color: #fff;
  font-size: 20px; line-height: 1;
  display: inline-grid; place-items: center;
  cursor: pointer;
}
.dialog .dialog-card .close:hover { background: #333; }
.dialog .dialog-card .close:focus-visible { outline: 2px solid #94a3b8; outline-offset: 2px; }

/* --- Scrollbar aesthetics (non-invasive) --- */
* {
  scrollbar-width: thin;
  scrollbar-color: rgba(0,0,0,.35) rgba(0,0,0,.08);
}
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-track { background: rgba(0,0,0,.08); }
*::-webkit-scrollbar-thumb { background: rgba(0,0,0,.35); border-radius: 10px; }
*::-webkit-scrollbar-thumb:hover { background: rgba(0,0,0,.45); }

/* --- Focus visibility (keyboard users) --- */
a:focus-visible, button:focus-visible, [role="button"]:focus-visible {
  outline: 2px solid #94a3b8;
  outline-offset: 2px;
}

/* --- iOS safe areas (navbar & dialogs) --- */
@supports (padding: max(0px)) {
  .navbar { padding-top: max(10px, env(safe-area-inset-top)); }
  .dialog { padding: max(16px, env(safe-area-inset-top)) 16px 16px 16px; }
}

/* --- Reduce motion friendliness --- */
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; scroll-behavior: auto !important; }
}


/* ---- Centering correctness pass ---- */
.dialog {
  /* Avoid perceived off-center when a vertical scrollbar is present */
  scrollbar-gutter: stable both-edges;
}

.dialog.show {
  /* Grid centering is robust across scrollbars/zoom */
  display: grid;
  place-items: center;
}

/* Ensure the card itself doesn't inherit weird margins */
.dialog .dialog-card {
  margin-inline: auto;
  box-sizing: border-box;
}


/* =============================================
   Mobile dialog centering & spacing (final pass)
   ============================================= */

/* Reserve space for scrollbars on both sides so the card remains visually centered */
.dialog {
  scrollbar-gutter: stable both-edges;
  padding: 16px;
}

/* Robust centering even when the URL bar resizes the viewport */
.dialog.show {
  display: grid !important;
  place-items: center;
}

/* Respect safe areas on iOS (left/right too) */
@supports (padding: max(0px)) {
  .dialog {
    padding-top: max(16px, env(safe-area-inset-top));
    padding-right: max(16px, env(safe-area-inset-right));
    padding-bottom: max(16px, env(safe-area-inset-bottom));
    padding-left: max(16px, env(safe-area-inset-left));
  }
}

/* Make sure the card never bleeds off the right edge on small screens */
.dialog .dialog-card {
  width: min(100%, 760px) !important;
  max-width: min(100%, 760px);
  max-height: 90vh;
  margin: 0 auto;
  box-sizing: border-box;
}

/* Improve inner scrolling on mobile */
#dlgList.activities {
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

/* Tidy vertical rhythm in the list */
#dlgList .activity { margin: 12px 0; }
#dlgList .activity:first-child { margin-top: 0; }
#dlgList .activity:last-child { margin-bottom: 0; }
