/* One water-glass material for dialogs, menus, analysis and map popups. */
:root {
    --interface-tint: rgba(244,250,255,.72);
    --interface-glint: rgba(255,255,255,.24);
    --interface-edge: rgba(255,255,255,.58);
    --interface-edge-dim: rgba(255,255,255,.10);
    --interface-edge-bottom: rgba(139,172,191,.14);
    --interface-shadow: 0 12px 32px rgba(19,47,66,.12), 0 2px 8px rgba(19,47,66,.05);
    --interface-ink: #153047;
    --interface-muted: #526b7f;
    --interface-inset: rgba(229,240,249,.42);
    --interface-line: rgba(123,156,181,.18);
    --interface-blur: 2px;
    --interface-radius: 18px;
}
[data-theme='dark'] {
    --interface-tint: rgba(16,34,50,.72);
    --interface-glint: rgba(220,241,255,.09);
    --interface-edge: rgba(218,241,255,.25);
    --interface-edge-dim: rgba(190,221,240,.05);
    --interface-edge-bottom: rgba(190,221,240,.08);
    --interface-shadow: 0 12px 32px rgba(0,10,20,.25), 0 2px 8px rgba(0,10,20,.10);
    --interface-ink: #edf7ff;
    --interface-muted: #b6cada;
    --interface-inset: rgba(66,105,137,.20);
    --interface-line: rgba(170,205,230,.15);
}
:root .interface-glass,
:root #floating-controls.interface-glass,
:root #rain-alert-box.interface-glass {
    position: relative;
    background: transparent !important;
    border-color: transparent !important;
    color: var(--interface-ink);
    box-shadow: var(--interface-shadow) !important;
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
}
:root .interface-glass::before,
:root #floating-controls.interface-glass::before,
:root #rain-alert-box.interface-glass::before {
    content: '';
    display: block;
    position: absolute;
    inset: 0;
    border: 0;
    border-radius: inherit;
    pointer-events: none;
    z-index: 0;
    background: linear-gradient(145deg, var(--interface-glint), transparent 42%), var(--interface-tint);
    backdrop-filter: var(--interface-refraction, blur(var(--interface-blur, 5px))) saturate(1.12);
    -webkit-backdrop-filter: blur(var(--interface-blur, 5px)) saturate(1.12);
    box-shadow: none;
}
:root :is(.interface-glass, #rain-alert-box, #weather-modal .wi-header, #weather-modal .wi-card, #weather-modal .wi-glass)::after {
    content: '';
    display: block;
    position: absolute;
    inset: 0;
    border-radius: inherit;
    padding: 1px;
    pointer-events: none;
    background: linear-gradient(145deg, var(--interface-edge), var(--interface-edge-dim) 30%, transparent 52%, var(--interface-edge-bottom) 78%, var(--interface-edge-dim));
    -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
    mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
    -webkit-mask-composite: xor;
    mask-composite: exclude;
    z-index: 0;
}
/* Only normal-flow children get relative positioning; absolute controls keep their geometry. */
.interface-glass > .interface-glass-content { position: relative; z-index: 1; }
.interface-glass > .interface-glass-positioned { z-index: 1; }
:root :is(#rain-alert-box, #weather-modal .wi-header, #weather-modal .wi-card, #weather-modal .wi-glass) { border-color: transparent; box-shadow: var(--interface-shadow); }
:root :is(#rain-alert-box, #weather-modal .wi-header, #weather-modal .wi-card, #weather-modal .wi-glass)::before { border: 0; box-shadow: none; }
/* Keep alert positioning independent from the shared surface and animation. */
:root #rain-alert-box.interface-glass {
    position: fixed;
    border-radius: var(--interface-radius);
    --ra-text: var(--interface-ink);
    --ra-muted: var(--interface-muted);
}

/* Settings and places float over the map with a light scrim. */
:root :is(#settings-modal, #saved-places-modal) {
    padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
    background: rgba(15, 23, 42, .26);
    box-sizing: border-box;
}
[data-theme='dark'] :is(#settings-modal, #saved-places-modal) { background: rgba(2, 6, 23, .52); }
:root :is(#settings-modal, #saved-places-modal, #place-delete-dialog) .modal-content {
    display: flex;
    flex-direction: column;
    padding: 20px;
    width: min(420px, 100%);
    max-width: 420px;
    max-height: calc(100dvh - 24px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
    box-sizing: border-box;
    border-radius: var(--interface-radius);
}
:root .modal .modal-header { flex-shrink: 0; align-items: center; margin-bottom: 14px; gap: 12px; }
:root .modal .modal-header h2 { color: var(--interface-ink); font-size: 17px; }
:root .modal .modal-body { min-height: 0; overflow: auto; margin-bottom: 10px; padding: 2px; scrollbar-width: thin; overscroll-behavior: contain; }
:root .modal .modal-footer {
    flex-shrink: 0;
    margin-top: 0;
    padding-top: 10px;
    border-top: 1px solid var(--interface-line);
    background: transparent;
}
:root .modal .close-modal {
    display: grid;
    place-items: center;
    flex-shrink: 0;
    width: 40px;
    height: 40px;
    border: 0;
    border-radius: 50%;
    padding: 0;
    background: var(--interface-inset);
    color: var(--interface-muted);
    font: 24px/1 Arial,sans-serif;
}
:root .modal :is(button, [tabindex='0']):focus-visible { outline: 2px solid #60a5fa; outline-offset: 2px; }
:root .modal .setting-item { gap: 5px; }
:root .modal .setting-item label { color: var(--interface-muted); font-size: 12px; font-weight: 500; }
:root .modal .custom-dropdown-trigger {
    min-height: 44px;
    box-sizing: border-box;
    padding: 10px 12px;
    font-size: 13px;
    border-color: var(--interface-line);
    background: var(--interface-inset);
    color: var(--interface-ink);
}
:root .modal .custom-dropdown-arrow { color: var(--interface-muted); }
:root .modal .custom-dropdown.open .custom-dropdown-trigger { border-color: rgba(96,165,250,.55); }
:root .modal .custom-dropdown-menu {
    position: relative;
    top: auto;
    left: auto;
    right: auto;
    margin-top: 6px;
    --interface-tint: rgba(244,250,255,.80);
}
[data-theme='dark'] .modal .custom-dropdown-menu { --interface-tint: rgba(16,34,50,.88); }
:root .modal .custom-dropdown-option { color: var(--interface-ink); font-size: 13px; min-height: 40px; box-sizing: border-box; }
:root .modal .custom-dropdown-option:hover { background: var(--interface-inset); }
:root .modal .custom-dropdown-option.selected { color: #2563eb; background: rgba(59,130,246,.10); }
[data-theme='dark'] .modal .custom-dropdown-option.selected { color: #93c5fd; }
:root .modal .btn-primary { min-height: 44px; border-radius: 12px; font-size: 13px; background: #2563eb; color: #fff; }
:root .modal :is(.theme-label, .saved-places-helper, .saved-places-empty, .saved-place-row-meta) { color: var(--interface-muted); }
:root .modal :is(.saved-place-row-name, .saved-place-row-status) { color: var(--interface-ink); }
:root .modal .saved-place-row { background: var(--interface-inset); border-color: var(--interface-line); }
:root .modal .saved-place-row-btn { background: var(--interface-inset); border-color: var(--interface-line); }
/* A Leaflet popup has one lens on its wrapper, not another solid plate inside. */
:root .cell-tooltip-popup { background: transparent !important; border: 0 !important; box-shadow: none !important; backdrop-filter: none !important; -webkit-backdrop-filter: none !important; }
:root :is(.saved-place-popup-card, .saved-place-form-card) { background: transparent !important; }
:root :is(.saved-place-popup, .saved-place-form-popup) {
    --place-line: var(--interface-line);
    --place-subtle: var(--interface-inset);
}
:root :is(.saved-place-popup,.saved-place-form-popup) .saved-place-popup-btn.secondary,
:root .saved-place-form-popup .saved-place-quick-btn,
:root .saved-place-form-popup .saved-place-form-actions { background: var(--interface-inset); }
:root .leaflet-popup-tip { background: var(--interface-tint) !important; box-shadow: none; }
:root .leaflet-popup-content-wrapper.interface-glass { border-radius: 18px !important; --interface-blur: 2px; }
:root .cell-tooltip-popup .leaflet-popup-close-button { z-index: 100 !important; }
:root .saved-place-popup .leaflet-popup-close-button,
:root .saved-place-form-popup .leaflet-popup-close-button { z-index: 3; }
/* Place and rain-detail popups share the same lens tint, blur and perimeter. */
:root :is(.saved-place-popup,.saved-place-form-popup) {
    --place-text: var(--interface-ink);
    --place-muted: var(--interface-muted);
    --place-line: var(--interface-line);
    --place-subtle: var(--interface-inset);
}
:root .saved-place-popup .saved-place-popup-banner {
    background: color-mix(in srgb, var(--place-status-bg) 62%, transparent);
    border: 1px solid color-mix(in srgb, var(--place-status) 12%, transparent);
    box-shadow: 0 1px 0 rgba(255,255,255,.16) inset;
}
:root .saved-place-popup .saved-place-popup-banner-icon {
    background: color-mix(in srgb, var(--place-status-icon) 55%, transparent);
}
:root .saved-place-popup .saved-place-popup-sources summary {
    background: var(--interface-inset);
    border-color: var(--interface-line);
}
:root :is(.saved-place-popup,.saved-place-form-popup) :is(.saved-place-popup-location,.saved-place-quick-btn,.saved-place-form-input) {
    background: var(--interface-inset);
    border-color: var(--interface-line);
}
:root .saved-place-popup .saved-place-popup-btn.primary,
:root .saved-place-form-popup .saved-place-form-save {
    background: #2563eb;
    color: #fff;
}
:root :is(.saved-place-popup,.saved-place-form-popup) .leaflet-popup-close-button {
    background: var(--interface-inset);
    color: var(--interface-muted);
}
/* A single shared lens wraps the right rail; selected tools are light washes. */
:root #floating-controls.interface-glass {
    --tools-surface: rgba(244,250,255,.82);
    --tools-ink: var(--interface-muted);
    --tools-rule: var(--interface-line);
    --tools-hover: rgba(96,165,250,.12);
    --tools-selected: rgba(59,130,246,.16);
    padding: 5px;
    border-radius: var(--interface-radius);
}
[data-theme='dark'] #floating-controls.interface-glass {
    --tools-surface: rgba(16,34,50,.88);
    --tools-hover: rgba(147,197,253,.10);
    --tools-selected: rgba(96,165,250,.18);
}
:root #floating-controls .float-btn { position: relative; }
:root #floating-controls .float-btn:hover { background: var(--tools-hover) !important; color: var(--tools-blue); }
:root #floating-controls :is(#gps-btn.active,#saved-places-btn.has-places,.float-btn:active),
body:has(#saved-places-modal[style*='display: flex']) #floating-controls #saved-places-btn,
body:has(#settings-modal[style*='display: flex']) #floating-controls #settings-btn,
body:has(#weather-modal.open) #floating-controls #weather-info-btn {
    background: var(--tools-selected) !important;
    box-shadow: 0 1px 0 rgba(255,255,255,.16) inset !important;
}
:root #floating-controls :is(#gps-btn.active,#saved-places-btn.has-places) { color: var(--tools-blue); }
:root #floating-controls #alert-bell-btn.has-warning { color: #d97706; }
:root #floating-controls #alert-bell-btn.has-danger { color: #ef4444; }
:root #floating-controls #alert-bell-btn.has-safe { color: #10b981; }
:root #floating-controls #map-tools-toggle[aria-expanded='true'] {
    border-top: 0 !important;
    border-radius: 12px !important;
}
:root #floating-controls #map-tools-toggle::before {
    content: '';
    position: absolute;
    inset: 0 9px auto;
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--tools-rule), transparent);
    pointer-events: none;
}
:root #floating-controls #map-tools-toggle[aria-expanded='false']::before { display: none; }
@media (hover: hover) {
    :root #floating-controls .float-btn:hover::after,
    :root #floating-controls .float-btn:focus-visible::after {
        background: var(--tools-surface);
        backdrop-filter: blur(8px);
        -webkit-backdrop-filter: blur(8px);
        border-color: var(--interface-line);
        box-shadow: 0 4px 12px rgba(19,47,66,.10);
    }
}
:root .analysis-card.interface-glass { --interface-tint: rgba(246,251,255,.38); box-shadow: 0 3px 12px rgba(19,47,66,.06) !important; }
[data-theme='dark'] .analysis-card.interface-glass { --interface-tint: rgba(26,48,68,.42); }
:root .analysis-card.interface-glass.active { background: transparent !important; border-color: transparent !important; animation: none !important; transform: none !important; }
:root .analysis-card.interface-glass.active::after { background: linear-gradient(145deg, var(--ring-color,#60a5fa), rgba(96,165,250,.12) 50%, var(--interface-edge-bottom)); }
:root .toast.interface-glass { color: var(--interface-ink); max-width: calc(100vw - 48px); }
:root .toast.success i { color: #10b981; }
:root .toast.error i { color: #ef4444; }
:root .toast.info i { color: #3b82f6; }
@media (max-width: 600px) {
    :root :is(#settings-modal, #saved-places-modal, #place-delete-dialog) .modal-content { padding: 16px; }
    :root .modal .modal-header { margin-bottom: 12px; }
}
@media (prefers-reduced-transparency: reduce), (prefers-contrast: more) {
    :root .interface-glass::before, :root #floating-controls.interface-glass::before, :root #rain-alert-box.interface-glass::before { background: #f4faff; backdrop-filter: none; -webkit-backdrop-filter: none; }
    [data-theme='dark'] .interface-glass::before, [data-theme='dark'] #floating-controls.interface-glass::before, [data-theme='dark'] #rain-alert-box.interface-glass::before { background: #102232; }
}
@supports not ((mask-composite: exclude) or (-webkit-mask-composite: xor)) {
    :root .interface-glass { border-color: var(--interface-edge-dim) !important; }
    :root :is(.interface-glass, #rain-alert-box, #weather-modal .wi-header, #weather-modal .wi-card, #weather-modal .wi-glass)::after { display: none; }
}

:root dialog.interface-confirm { display: none; position: fixed; inset: 0; margin: auto; width: min(420px, calc(100vw - 24px)); max-width: none; height: fit-content; max-height: calc(100dvh - 24px); padding: 0; border: 0; background: transparent; color: var(--interface-ink); overflow: visible; }
:root dialog.interface-confirm[open] { display: block; }
:root dialog.interface-confirm::backdrop { background: rgba(24,48,68,.18); }
[data-theme='dark'] dialog.interface-confirm::backdrop { background: rgba(0,12,23,.32); }
:root .interface-confirm .modal-header { align-items: center; gap: 12px; margin-bottom: 12px; }
:root .interface-confirm .modal-header h2 { font-size: 17px; color: var(--interface-ink); }
:root .interface-confirm .modal-body { font-size: 13px; color: var(--interface-muted); overflow-wrap: anywhere; margin-bottom: 18px; }
:root .interface-confirm .close-modal { display: grid; place-items: center; width: 40px; height: 40px; border: 0; border-radius: 50%; color: var(--interface-muted); background: var(--interface-inset); font: 24px/1 Arial,sans-serif; }
:root .interface-confirm .modal-footer { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 0; }
:root .interface-confirm .modal-footer button { min-height: 44px; border: 0; border-radius: 12px; font-size: 13px; font-weight: 600; }
:root .interface-confirm .glass-confirm-cancel { background: var(--interface-inset); color: var(--interface-ink); }
:root .interface-confirm .glass-confirm-delete { background: #dc2626; color: #fff; }
:root .interface-confirm button:focus-visible { outline: 2px solid #60a5fa; outline-offset: 2px; }

body.interface-modal-open :is(#sidebar, #show-sidebar-btn, #floating-controls, #forecastTimeline, #rain-alert-box, #toast-container, .leaflet-popup-pane) { visibility: hidden !important; }
@media (max-width: 480px) {
    :root .analysis-card .ctp-table { table-layout: fixed; }
    :root .analysis-card :is(.ctp-td-label,.ctp-td-val) { white-space: normal; overflow-wrap: anywhere; }
}

body.interface-modal-open > .absolute.inset-0.z-10 { visibility: hidden !important; opacity: 0 !important; }
body.interface-modal-open :is(.leaflet-marker-icon,.leaflet-tooltip) { visibility: hidden !important; }
@media (max-width: 768px) {
    body:has(.leaflet-popup) > .absolute.inset-0.z-10 { visibility: hidden !important; opacity: 0 !important; }
}

:root #radar-data-notice.interface-glass { position: fixed; --interface-tint: rgba(255,248,230,.78); color: #92400e; }
[data-theme='dark'] #radar-data-notice.interface-glass { --interface-tint: rgba(48,39,25,.80); color: #fde68a; }
body.interface-modal-open #radar-data-notice { visibility: hidden !important; }
:root .cell-tooltip-popup .leaflet-popup-close-button { top: 8px !important; right: 8px !important; width: 32px !important; height: 32px !important; border-radius: 50% !important; border: 0 !important; background: var(--interface-inset) !important; color: var(--interface-muted) !important; font-size: 22px !important; }

@media (max-width: 768px) and (max-height: 600px) {
    #tab-tracker { overflow-y: auto !important; }
    #tab-tracker #cell-list { flex: 0 0 auto !important; overflow: visible !important; }
}

/* Short landscape phones: the sidebar is taller than the viewport.  Keep the
   weather controls and analysis cards usable by removing the large brand/clock
   block and letting the content area breathe. */
@media (orientation: landscape) and (max-height: 560px) {
  #sidebar .sidebar-brand,
  #sidebar .sidebar-clock {
    display: none !important;
  }
  #sidebar {
    gap: 8px !important;
  }
  #sidebar .sidebar-header-panel {
    padding-top: 8px !important;
  }
}

/* Short landscape phones: when the side panel is open, use the full height
   for its scrollable content and do not let the fixed timeline cover the
   analysis cards. Closing the panel restores the timeline. */
@media (orientation: landscape) and (max-height: 560px) {
  body:has(#sidebar.sidebar-visible) #forecastTimeline {
    display: none !important;
  }
  body:has(#sidebar.sidebar-visible) #sidebar,
  body:has(#sidebar:not(.sidebar-hidden)) #sidebar {
    height: calc(100dvh - 16px) !important;
    max-height: calc(100dvh - 16px) !important;
    overflow-y: auto !important;
    overscroll-behavior: contain;
    padding-bottom: 8px;
  }
  body:has(#sidebar.sidebar-visible) #radar-sidebar-content,
  body:has(#sidebar:not(.sidebar-hidden)) #radar-sidebar-content {
    flex: 0 0 auto !important;
    min-height: auto !important;
    overflow: visible !important;
  }
  body:has(#sidebar.sidebar-visible) #feature-sat-analysis,
  body:has(#sidebar:not(.sidebar-hidden)) #feature-sat-analysis {
    height: auto !important;
    min-height: 0 !important;
  }
  body:has(#sidebar.sidebar-visible) #fs-card-list,
  body:has(#sidebar:not(.sidebar-hidden)) #fs-card-list {
    min-height: 140px;
  }
}

/* Desktop keyboard/mouse widths use the hidden class instead of sidebar-visible. */
@media (orientation: landscape) and (max-height: 560px) and (min-width: 769px) {
  body:has(#sidebar:not(.sidebar-hidden)) #forecastTimeline { display: none !important; }
}

/* Short landscape phones: keep every toolbar control inside the viewport. */
@media (orientation: landscape) and (max-height: 560px) {
  #floating-controls {
    max-height: calc(100dvh - 16px);
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 4px;
  }
  #floating-controls .float-btn {
    width: 40px !important; height: 40px !important;
    min-width: 40px !important; min-height: 40px !important;
  }
}

/* Very narrow phones: leave a clear lane for the map tool column. */
@media (max-width: 360px) {
  #sidebar {
    width: calc(100vw - 72px) !important;
    min-width: 0 !important;
    max-width: calc(100vw - 72px) !important;
  }
}
