/* EuroMeteo Explorer Shiny App Styles */

/* Enforce strict responsive bounds for mobile iframe embedding */
html, body {
  width: 100%;
  max-width: 100vw;
  overflow-x: hidden;
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
}

/* Make modal title take full width so flexbox alignment works */
.modal-header .modal-title {
  flex: 1 !important;
  width: 100% !important;
}

/* Frozen overlay - blocks all interactions during data loading using native dialog */
.frozen-overlay {
  border: none;
  background: transparent;
  padding: 0;
  margin: 0;
  max-width: unset;
  max-height: unset;
  width: 100%;
  height: 100%;
  z-index: 9999;
  cursor: wait;
  
  display: none;
  align-items: flex-start;
  justify-content: flex-end;
  padding: 80px 30px 30px 30px;
  
  /* Discrete Top-Layer transitions */
  opacity: 0;
  transition-property: opacity, display, overlay;
  transition-duration: 0.3s;
  transition-timing-function: ease-out;
  transition-behavior: allow-discrete;
}

.frozen-overlay[open] {
  display: flex;
  opacity: 1;

  @starting-style {
    opacity: 0;
  }
}

.frozen-overlay::backdrop {
  background-color: rgba(0, 0, 0, 0.3);
  transition-property: background-color, display, overlay;
  transition-duration: 0.3s;
  transition-timing-function: ease-out;
  transition-behavior: allow-discrete;
}

.frozen-overlay[open]::backdrop {
  background-color: rgba(0, 0, 0, 0.3);

  @starting-style {
    background-color: rgba(0, 0, 0, 0);
  }
}

/* Reduced motion preference support */
@media (prefers-reduced-motion: reduce) {
  .frozen-overlay {
    transition-duration: 0.1s;
  }
  .frozen-overlay::backdrop {
    transition-duration: 0.1s;
  }
}

.frozen-overlay-content {
  position: relative;
  background: white;
  width: 400px;
  min-height: 200px;
  padding: 30px;
  border-radius: 10px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.frozen-overlay-content .spinner-border {
  width: 3rem;
  height: 3rem;
  margin-bottom: 15px;
}

.frozen-overlay-content p {
  margin: 0;
  font-size: 1.1rem;
  color: #333;
}

#fetch_progress_container {
  max-width: 320px;
  animation: fadeIn 0.3s ease-out;
}

#fetch_progress_container .progress {
  overflow: hidden;
}

#fetch_progress_status {
  font-weight: 500;
  min-height: 1.2em; /* Prevent layout jump */
}

.progress-bar-animated {
  transition: width 0.4s cubic-bezier(0.4, 0, 0.2, 1) !important;
}

#fetch_progress_bar.progress-bar-indeterminate {
  transition: width 0.35s ease-out !important;
  animation: progress-bar-stripes 0.9s linear infinite;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(5px); }
  to { opacity: 1; transform: translateY(0); }
}

.frozen-overlay-close {
  position: absolute;
  top: 10px;
  right: 15px;
  border: none;
  background: none;
  font-size: 1.5rem;
  color: #666;
  cursor: pointer;
  line-height: 1;
}

.frozen-overlay-close:hover {
  color: #000;
}

/* Disable pointer events on sidebar when frozen */
body.ui-frozen .bslib-sidebar-layout>.sidebar {
  pointer-events: none;
  opacity: 0.6;
}

body.ui-frozen .navbar {
  pointer-events: none;
  opacity: 0.6;
}

/* Ensure date range inputs are wide enough to show full dates */
.input-daterange .form-control {
  font-size: 0.85rem;
  padding: 0.3rem 0.4rem;
  min-width: 0;
  text-align: center;
}

.input-daterange {
  flex-wrap: nowrap;
}

.input-daterange .input-group-text {
  padding: 0.3rem 0.35rem;
  font-size: 0.8rem;
}

/* Progressive plot fade-in animation */
@keyframes plotFadeIn {
  from {
    opacity: 0.3;
    transform: translateY(6px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.js-plotly-plot {
  animation: plotFadeIn 0.4s ease-out forwards;
  opacity: 1;
  /* Ensure visible even if animation fails */
}

div.outer {
  position: relative;
  height: calc(100vh - 100px);
  overflow: hidden; /* Lock map view to viewport — prevents scrollbar in iframe */
}



.close-btn-custom:hover {
  color: #000;
}

#zoom_home_panel {
  z-index: 999 !important;
}

.btn-home {
  background: white;
  border: 2px solid rgba(0, 0, 0, 0.2);
  border-radius: 4px;
  color: #444;
  width: 34px;
  height: 34px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-home:hover {
  background: #f4f4f4;
  color: #000;
}

/* Move plotly modebar to bottom */
.plotly .modebar-container {
  top: auto !important;
  bottom: 10px !important;
}

.plotly .modebar {
  background: rgba(255, 255, 255, 0.9) !important;
  border-radius: 4px;
  padding: 2px 5px;
}

/* Collapsible Map Control Styling using CSS Nesting, :hover, and :focus-within */
.map-layer-control {
  background-color: white;
  border-radius: 4px;
  box-shadow: 0 0 5px rgba(0, 0, 0, 0.3);
  padding: 5px;
  width: 36px;
  height: 36px;
  overflow: hidden;
  transition: width 0.3s ease, height 0.3s ease;
  cursor: pointer;
  display: flex;
  flex-direction: column;

  /* CSS Nesting for Hover and Focus States */
  &:hover,
  &:focus-within {
    width: 200px;
    height: auto;
    padding: 10px;

    .control-content {
      opacity: 1;
      white-space: normal;
    }

    .control-icon {
      display: none !important;
    }
  }
}

/* Keyboard navigation: visible focus ring on map layer control */
.map-layer-control:focus-visible {
  outline: 3px solid var(--bs-primary, #3498db);
  outline-offset: 2px;
}

.control-icon {
  width: 26px;
  height: 26px;
  text-align: center;
  margin-bottom: 5px;
  font-size: 18px;
  color: #333;
  flex-shrink: 0;
}

.control-content {
  opacity: 0;
  transition: opacity 0.3s ease;
  margin-top: 5px;
  white-space: nowrap;
}

.map-layer-control .control-content label {
  font-size: 85%;
}

/* Time Slider Panel */
#time_slider_panel {
  z-index: 999 !important;
}

#time_slider_panel .form-group {
  margin-bottom: 0;
}

#time_slider_panel .irs {
  font-size: 11px;
}

#time_slider_panel .irs-bar,
#time_slider_panel .irs-bar-edge {
  background: #3498db;
  border: none;
}

#time_slider_panel .irs-single,
#time_slider_panel .irs-from,
#time_slider_panel .irs-to {
  background: #3498db;
}

#selected_time_label {
  font-weight: 500;
  color: #333;
  white-space: nowrap;
}

/* Map Legend Styling */
.map-legend-panel {
  background: rgba(255, 255, 255, 0.85);
  padding: 18px 14px;
  border-radius: 12px;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.15);
  border: 1px solid rgba(0, 0, 0, 0.05);
  width: 140px;
  backdrop-filter: blur(8px);
  pointer-events: none;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", "Noto Sans", "Liberation Sans", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji";
}

/* Inline map loading indicator — replaces full-screen overlay after basemap renders */
.map-loading-indicator {
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1001;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  padding: 8px 18px;
  border-radius: 20px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.12);
  font-size: 0.85rem;
  font-weight: 500;
  color: #333;
  display: none;
  align-items: center;
  gap: 8px;
  animation: fadeIn 0.3s ease-out;
  transition: opacity 0.3s ease-out;
  pointer-events: none;
}

.legend-title {
  font-size: 14px;
  font-weight: 500;
  color: #1a1a1a;
  margin-bottom: 15px;
  text-align: center;
  letter-spacing: 0.8px;
  line-height: 1.2;
}

.legend-item {
  display: flex;
  align-items: center;
  height: 15px;
  position: relative;
}

.legend-color {
  width: 40px;
  height: 100%;
}

.legend-label {
  font-size: 13px;
  font-weight: 500;
  color: #2c3e50;
  margin-left: 0;
  position: absolute;
  left: 50px;
  top: -6px;
  white-space: nowrap;
}

@media (max-width: 768px) {

  /* --- Edge-to-edge: remove all left/right padding on mobile --- */
  .container,
  .container-fluid,
  .container-sm,
  .container-md {
    padding-left: 0 !important;
    padding-right: 0 !important;
  }

  .tab-content {
    padding-left: 0 !important;
    padding-right: 0 !important;
  }

  .tab-content>.tab-pane>.card,
  .tab-content>.active>.card {
    border-left: none !important;
    border-right: none !important;
    border-radius: 0 !important;
  }

  .tab-content>.tab-pane>.card>.card-body,
  .tab-content>.active>.card>.card-body {
    padding-left: 4px !important;
    padding-right: 4px !important;
  }

  /* Remove bslib main content padding */
  .bslib-page-fill,
  .bslib-gap-spacing {
    padding-left: 0 !important;
    padding-right: 0 !important;
  }

  .bslib-sidebar-layout>.main {
    padding-left: 0 !important;
    padding-right: 0 !important;
  }

  .map-legend-panel {
    display: none;
  }

  /* Hide MapLibre navigation control (zoom +/-) on mobile */
  .maplibregl-ctrl-top-left .maplibregl-ctrl-group,
  .mapboxgl-ctrl-top-left .mapboxgl-ctrl-group {
    display: none !important;
  }

  /* Hide layer control panel on mobile */
  .map-layer-control {
    display: none !important;
  }

  /* Hide plotly modebar (zoom/pan/download toolbar) on mobile */
  .plotly .modebar-container {
    display: none !important;
  }

  /* Hide info icon annotations on mobile (hover doesn't work on touch) */
  .js-plotly-plot .annotation {
    display: none !important;
  }

  /* Frozen overlay: fit within mobile screen */
  .frozen-overlay[open] {
    padding: 60px 10px 10px 10px !important;
    justify-content: center !important;
  }

  .frozen-overlay-content {
    width: 90% !important;
    max-width: 350px;
    min-height: 150px;
    padding: 20px;
  }

  /* Time slider: tighter margins on mobile */
  .time-slider-panel-outer {
    left: 10px !important;
    right: 10px !important;
    padding: 5px 10px !important;
  }

  /* Map outer height: use dynamic viewport height for mobile browsers */
  div.outer {
    height: calc(100vh - 56px);
    /* fallback for older browsers */
    height: calc(100dvh - 56px);
    /* dynamic viewport height - accounts for mobile browser chrome */
  }

  /* Adjust home button position (navbar is shorter on mobile) */
  #zoom_home_panel {
    top: 60px !important;
  }

  /* Hide fullscreen toggle on mobile (not needed/supported) */
  #fullscreen_toggle {
    display: none !important;
  }

  /* (Dashboard plot padding moved to CSS Container Query context below) */

  /* --- Touch-friendly time slider --- */
  #time_slider_panel .irs-handle {
    width: 28px !important;
    height: 28px !important;
    top: 18px !important;
  }

  #time_slider_panel .irs-line {
    height: 10px !important;
    top: 27px !important;
  }

  #time_slider_panel .irs-bar {
    height: 10px !important;
    top: 27px !important;
  }

  /* --- Compact navbar tabs --- */
  .navbar-nav .nav-link {
    font-size: 0.8rem !important;
    padding: 0.4rem 0.5rem !important;
  }

  /* --- Wider date picker calendar --- */
  .datepicker {
    width: 100% !important;
    max-width: 300px;
  }

  /* --- Smaller table font on mobile --- */
  .dataTables_wrapper {
    font-size: 0.8rem !important;
  }

  .dataTables_wrapper th {
    font-size: 0.75rem !important;
  }

  /* Fixed column background for Dashboard Data table */
  .DTFC_LeftBodyLiner,
  .DTFC_LeftHeadWrapper {
    background: white !important;
  }
}

/* ==========================================================================
   Modern Web Guidance: Rendering Deferral & State Caching
   ========================================================================== */

/* Defer layout and rendering calculations for offscreen Plotly plots to boost scrolling performance */
.js-plotly-plot {
  content-visibility: auto;
  contain-intrinsic-size: auto 350px;
}

/* Cache inactive tab panes natively to speed up tab switching and prevent container height collapsing */
@supports (content-visibility: hidden) {
  .tab-content > .tab-pane {
    display: block !important;
    content-visibility: hidden;
  }
  
  .tab-content > .active {
    content-visibility: visible;
  }
}

/* ==========================================================================
   Modern Web Guidance: Container Queries
   ========================================================================== */

/* Register details_tabs as a container query context */
#details_tabs {
  container-type: inline-size;
}

@container (max-width: 768px) {
  /* Remove card body padding from the Dashboard pills container */
  .tab-content>.tab-pane>.card-body,
  .tab-content>.active>.card-body {
    padding: 4px !important;
  }

  /* Remove wrapper padding and gutters from the plot grid */
  .row.g-3 {
    --bs-gutter-x: 0.25rem;
    --bs-gutter-y: 0.5rem;
    padding: 2px !important;
  }

  /* Reduce Plotly internal margins */
  .js-plotly-plot .plotly .main-svg {
    overflow: visible;
  }

  /* Reduce plotly container margin for the plot output wrappers */
  .col-12.col-lg-6 {
    padding-left: 2px !important;
    padding-right: 2px !important;
  }

  /* Dynamic plot heights based on container width using container width units (cqw) */
  .col-12.col-lg-6 .plotly {
    min-height: 280px;
    height: 45cqw !important;
    max-height: 360px;
  }
}

/* ==========================================================================
   Modern Web Guidance: Fullscreen API Integration
   ========================================================================== */

/* Natively adapt background and layout heights in fullscreen mode */
html:fullscreen {
  background-color: var(--bs-body-bg, #ffffff);
}

html:fullscreen div.outer {
  height: 100dvh !important;
}
