/* ----------------------------------------------------------------------------
   Bendar.app — mobile-first styles, tuned for iPhone / Safari.

   Layout: a full-screen Leaflet map with a floating top bar, a bottom control
   bar, and a slide-up alerts sheet. All fixed UI is padded away from the
   notch / home indicator using env(safe-area-inset-*).
---------------------------------------------------------------------------- */

:root {
  --bg: #0b1220;
  --panel: rgba(17, 25, 40, 0.82);
  --panel-solid: #111928;
  --border: rgba(255, 255, 255, 0.12);
  --text: #f3f6fb;
  --muted: #aab4c5;
  --accent: #3b82f6;
  --accent-press: #2563eb;
  --warn: #f59e0b;
  --warn-strong: #ef4444;
  --radius: 16px;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.45);
  /* Real usable viewport height. app.js overwrites this with
     window.innerHeight (in px) so full-screen surfaces fill the screen even
     where iOS standalone/fullscreen mis-measures the fixed viewport. Falls
     back to the dynamic viewport height before/without the script. */
  --vh: 100dvh;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  /* Match the measured screen height so the fixed viewport that bottom-anchored
     UI (.controls, attribution) resolves against reaches the true bottom edge,
     not the short one iOS reports in standalone/fullscreen mode. */
  height: var(--vh, 100%);
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI",
    Roboto, Helvetica, Arial, sans-serif;
  /* Stop iOS from bouncing/scrolling the page behind the map. */
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
}

body {
  position: fixed;
  inset: 0;
  /* height wins over the over-constrained inset:0, so body is exactly the
     measured screen height and becomes the positioning context for the overlay
     UI below (which is position:absolute, not fixed). Anchoring that UI to body
     instead of the fixed viewport is what keeps the control bar + copyright on
     the true bottom edge in iOS standalone/web-app mode, where the fixed
     viewport is shorter than the real screen. */
  height: var(--vh, 100dvh);
  overflow: hidden;
}

/* Kill the grey tap flash on iOS and stop long-press callouts on buttons. */
button,
.alert-pill,
.slider {
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
}

/* --- Map ------------------------------------------------------------------ */

#map {
  /* absolute (not fixed) so it fills body — which is the measured screen
     height (var(--vh)) — rather than the iOS fixed viewport, which renders
     shorter than the real screen in standalone/web-app mode and left a blank
     strip along the bottom. inset:0 fills body edge-to-edge. */
  position: absolute;
  inset: 0;
  background: #0b1220;
  z-index: 0;
}

/* Attribution sits at the very bottom of the screen, below the control panel
   (the panel is lifted to leave room for it just above the home indicator). */
.leaflet-bottom.leaflet-right {
  left: 0;
  right: 0;
  margin-bottom: calc(env(safe-area-inset-bottom, 0px) + 4px);
  display: flex;
  justify-content: center;
}
.leaflet-right .leaflet-control {
  float: none;
  margin: 0;
}
.leaflet-control-attribution {
  font-size: 10px;
  background: rgba(0, 0, 0, 0.4) !important;
  color: #cbd5e1 !important;
}
.leaflet-control-attribution a {
  color: #93c5fd !important;
}

/* --- Top bar -------------------------------------------------------------- */

.topbar {
  /* absolute so it anchors to body (the measured full-height box), matching
     the map and bottom controls. See the #map / body notes above. */
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: calc(env(safe-area-inset-top, 0px) + 10px) 14px 10px;
  padding-left: calc(env(safe-area-inset-left, 0px) + 14px);
  padding-right: calc(env(safe-area-inset-right, 0px) + 14px);
  background: linear-gradient(
    to bottom,
    rgba(11, 18, 32, 0.92),
    rgba(11, 18, 32, 0)
  );
  pointer-events: none; /* let map gestures pass through the gradient */
}

.title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 17px;
  letter-spacing: 0.2px;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.6);
}

.title .dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 10px var(--accent);
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Compact top-bar button that reopens the location controls once collapsed. */
.pin-btn {
  pointer-events: auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--panel);
  -webkit-backdrop-filter: blur(18px);
  backdrop-filter: blur(18px);
  color: var(--text);
  font-size: 18px;
  line-height: 1;
  box-shadow: var(--shadow);
}
.pin-btn:active {
  background: rgba(255, 255, 255, 0.14);
}
.pin-btn:disabled {
  opacity: 0.5;
}

.alert-pill {
  pointer-events: auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: none;
  border-radius: 999px;
  padding: 9px 14px;
  font-size: 13px;
  font-weight: 700;
  color: #1a1204;
  background: var(--warn);
  box-shadow: var(--shadow);
  min-height: 36px;
}
.alert-pill.severe {
  background: var(--warn-strong);
  color: #fff;
}

/* --- Bottom controls ------------------------------------------------------ */

.controls {
  /* absolute → anchored to body's true bottom (var(--vh)), not the short iOS
     fixed viewport, so the panel sits just above the home indicator instead of
     floating up with dead space beneath it. */
  position: absolute;
  left: 12px;
  right: 12px;
  /* Lifted to leave room for the map attribution line beneath the panel. */
  bottom: calc(env(safe-area-inset-bottom, 0px) + 28px);
  z-index: 500;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px;
  background: var(--panel);
  -webkit-backdrop-filter: blur(18px);
  backdrop-filter: blur(18px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.control-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.btn {
  -webkit-appearance: none;
  appearance: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px; /* comfortable 48px tap target */
  padding: 0 16px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  font-size: 16px;
  font-weight: 600;
  transition: transform 0.08s ease, background 0.15s ease;
}
.btn:active {
  transform: scale(0.97);
  background: rgba(255, 255, 255, 0.12);
}
.btn.primary {
  flex: 1;
  background: var(--accent);
  border-color: transparent;
}
.btn.primary:active {
  background: var(--accent-press);
}
.btn .btn-ico {
  font-size: 18px;
  line-height: 1;
}
.btn#refreshBtn,
.btn#installBtn {
  flex: none;
  width: 44px;
  min-height: 44px; /* match the toggle buttons it shares the row with */
  padding: 0;
}
.btn.spin .btn-ico {
  animation: spin 0.8s linear infinite;
}

/* Toggle buttons (Clouds / Loop) share the row evenly.
   Install is icon-only next to Refresh. Share lives in the top bar. */
.toggles {
  gap: 8px;
}
.btn.toggle {
  flex: 1;
  min-height: 44px;
  padding: 0 10px;
  font-size: 14px;
}
.btn.toggle .btn-ico {
  font-size: 16px;
}
/* Active/pressed toggle state. */
.btn.toggle[aria-pressed="true"] {
  background: var(--accent);
  border-color: transparent;
  color: #fff;
}
.btn.toggle[aria-pressed="true"]:active {
  background: var(--accent-press);
}
.btn.toggle:disabled,
.btn.toggle[aria-disabled="true"] {
  opacity: 0.4;
  cursor: not-allowed;
}
.btn.toggle:disabled:active,
.btn.toggle[aria-disabled="true"]:active {
  transform: none;
  background: rgba(255, 255, 255, 0.06);
}

/* --- ZIP fallback input --------------------------------------------------- */

.zip-row {
  gap: 10px;
}
.zip-input {
  -webkit-appearance: none;
  appearance: none;
  flex: 1;
  min-width: 0;
  min-height: 44px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  font-size: 16px; /* ≥16px keeps iOS Safari from zooming on focus */
  font-variant-numeric: tabular-nums;
  letter-spacing: 1px;
}
.zip-input::placeholder {
  color: var(--muted);
  letter-spacing: normal;
}
.zip-input:focus {
  outline: none;
  border-color: var(--accent);
  background: rgba(255, 255, 255, 0.1);
}
.btn.zip-go {
  flex: none;
  min-height: 44px;
  padding: 0 18px;
}

/* --- Radar loop timeline -------------------------------------------------- */

.loop-row {
  gap: 10px;
}
.loop-row .icon-btn {
  flex: none;
  background: rgba(255, 255, 255, 0.1);
}
.loop-time {
  width: 62px;
  font-size: 12px;
}

.slider-row {
  gap: 12px;
}
.slider-label {
  font-size: 13px;
  color: var(--muted);
  width: 42px;
  flex: none;
}
.slider {
  -webkit-appearance: none;
  appearance: none;
  flex: 1;
  height: 30px; /* tall hit area for thumbs */
  background: transparent;
}
.slider::-webkit-slider-runnable-track {
  height: 6px;
  border-radius: 3px;
  background: linear-gradient(
    to right,
    var(--accent) 0%,
    var(--accent) var(--fill, 70%),
    rgba(255, 255, 255, 0.18) var(--fill, 70%),
    rgba(255, 255, 255, 0.18) 100%
  );
}
.slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  margin-top: -10px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.5);
}
.slider::-moz-range-thumb {
  width: 26px;
  height: 26px;
  border: none;
  border-radius: 50%;
  background: #fff;
}
.slider-val {
  font-size: 13px;
  color: var(--muted);
  width: 42px;
  text-align: right;
  flex: none;
  font-variant-numeric: tabular-nums;
}

.status {
  font-size: 12px;
  color: var(--muted);
  text-align: center;
  min-height: 15px;
  line-height: 1.3;
}
.status.error {
  color: #fca5a5;
}

/* --- Alert sheet ---------------------------------------------------------- */

.sheet {
  /* absolute → pinned to body's true bottom, in step with the controls. */
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 700;
  max-height: 70vh;
  max-height: 70dvh;
  padding: 8px 16px calc(env(safe-area-inset-bottom, 0px) + 20px);
  background: var(--panel-solid);
  border-top-left-radius: 22px;
  border-top-right-radius: 22px;
  border-top: 1px solid var(--border);
  box-shadow: 0 -12px 40px rgba(0, 0, 0, 0.55);
  transform: translateY(0);
  transition: transform 0.28s cubic-bezier(0.2, 0.8, 0.2, 1);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.sheet.hidden {
  transform: translateY(110%);
}

.sheet-handle {
  width: 42px;
  height: 5px;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.25);
  margin: 6px auto 12px;
}
.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.sheet-head h2 {
  margin: 0;
  font-size: 18px;
}
.icon-btn {
  border: none;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  width: 34px;
  height: 34px;
  border-radius: 50%;
  font-size: 15px;
  cursor: pointer;
}

.alert-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.alert-card {
  border: 1px solid var(--border);
  border-left: 4px solid var(--warn);
  border-radius: 12px;
  padding: 12px 14px;
  background: rgba(255, 255, 255, 0.03);
}
.alert-card.sev-extreme,
.alert-card.sev-severe {
  border-left-color: var(--warn-strong);
}
.alert-card h3 {
  margin: 0 0 4px;
  font-size: 15px;
}
.alert-card .meta {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 8px;
}
.alert-card p {
  margin: 0;
  font-size: 13px;
  line-height: 1.45;
  color: #dbe3ef;
  white-space: pre-line;
}

/* --- Settings sheet (radar products) -------------------------------------- */

.settings-intro {
  margin: 0 0 12px;
  font-size: 13px;
  color: var(--muted);
  line-height: 1.4;
}

.settings-options {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.settings-option {
  -webkit-appearance: none;
  appearance: none;
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 56px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.03);
  color: var(--text);
  text-align: left;
  cursor: pointer;
  font: inherit;
}
.settings-option:active {
  background: rgba(255, 255, 255, 0.08);
}
.settings-option[aria-checked="true"] {
  border-color: var(--accent);
  background: rgba(59, 130, 246, 0.14);
}
.settings-option-text {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.settings-option-title {
  font-size: 15px;
  font-weight: 600;
}
.settings-option-desc {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.35;
}
.settings-check {
  flex: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 1px solid var(--border);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  color: transparent;
  background: transparent;
}
.settings-option[aria-checked="true"] .settings-check {
  color: #fff;
  background: var(--accent);
  border-color: transparent;
}

/* Gear button: slightly larger glyph so it reads at pin-btn size. */
#settingsBtn {
  font-size: 20px;
}

/* Navigation row under the radar-product list (e.g. Tropics). */
.settings-link {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 56px;
  margin-top: 14px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.03);
  color: var(--text);
  text-decoration: none;
  text-align: left;
  font: inherit;
  box-sizing: border-box;
}
.settings-link:active {
  background: rgba(255, 255, 255, 0.08);
}
.settings-link-chevron {
  flex: none;
  font-size: 22px;
  line-height: 1;
  color: var(--muted);
}

/* --- Install instructions sheet ------------------------------------------- */

.install-steps p {
  margin: 0 0 12px;
  font-size: 14px;
  color: var(--muted);
  line-height: 1.45;
}
.install-steps ol {
  margin: 0;
  padding-left: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.install-steps li {
  font-size: 15px;
  line-height: 1.45;
  color: #dbe3ef;
}
.install-steps strong {
  color: var(--text);
}
.ios-share {
  color: var(--accent);
  font-size: 17px;
  vertical-align: -2px;
}

/* --- Location marker ------------------------------------------------------ */

.me-marker {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent);
  border: 3px solid #fff;
  box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.35), 0 2px 6px rgba(0, 0, 0, 0.5);
}

/* --- Utilities ------------------------------------------------------------ */

.hidden {
  display: none !important;
}

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

/* Respect users who ask for reduced motion. */
@media (prefers-reduced-motion: reduce) {
  .sheet {
    transition: none;
  }
  .btn.spin .btn-ico {
    animation: none;
  }
}

/* A touch more breathing room on larger phones / small tablets. */
@media (min-width: 480px) {
  .controls {
    left: auto;
    right: 12px;
    width: 380px;
  }
}
