/* Default to dark mode - prevents white flash */
html:not([data-bs-theme="light"]) {
  background-color: #151f2c !important;
  color-scheme: dark;
}

html:not([data-bs-theme="light"]) body {
  background-color: #151f2c !important;
  color: #ffffff !important;
}

body {
  height: 100vh;
  margin: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.page-wrapper {
  flex-grow: 1;
  overflow-y: auto;
}

/* Dark mode for Tabler components - prevents flash */
html:not([data-bs-theme="light"]) .card {
  background-color: #232e3c !important;
  border-color: #2d3748 !important;
  color: #ffffff !important;
}

html:not([data-bs-theme="light"]) .navbar {
  background-color: #1d273b !important;
  border-color: #2d3748 !important;
}

html:not([data-bs-theme="light"]) .table {
  color: #ffffff !important;
}

html:not([data-bs-theme="light"]) .card-header {
  background-color: transparent !important;
  border-color: #2d3748 !important;
  color: #ffffff !important;
}

html:not([data-bs-theme="light"]) .page-wrapper {
  background-color: #151f2c !important;
  overflow-x: hidden; /* Prevent horizontal scrollbar from content overflow */
}

html:not([data-bs-theme="light"]) .form-control,
html:not([data-bs-theme="light"]) .form-select {
  background-color: #1d273b !important;
  border-color: #2d3748 !important;
  color: #ffffff !important;
}

/* Cross-browser select arrow via wrapper ::after */
.select-wrapper {
  position: relative;
}

.select-wrapper .form-select {
  -webkit-appearance: none !important;
  -moz-appearance: none !important;
  appearance: none !important;
  background-image: none !important;
  padding-right: 2.25rem !important;
}

.select-wrapper::after {
  content: "";
  position: absolute;
  right: 1rem;
  top: 50%;
  transform: translateY(-50%);
  width: 0;
  height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: 6px solid #6c757d;
  pointer-events: none;
}

html:not([data-bs-theme="light"]) .select-wrapper::after {
  border-top-color: #adb5bd;
}

html:not([data-bs-theme="light"]) .dropdown-menu {
  background-color: #232e3c !important;
  border-color: #2d3748 !important;
}

html:not([data-bs-theme="light"]) .dropdown-item {
  color: #ffffff !important;
}

html:not([data-bs-theme="light"]) .list-group-item {
  background-color: transparent !important;
  border-color: #2d3748 !important;
  color: #ffffff !important;
}

html:not([data-bs-theme="light"]) .btn {
  background-color: #1d273b !important;
  border-color: #2d3748 !important;
  color: #ffffff !important;
}

html:not([data-bs-theme="light"]) .btn:hover {
  background-color: #232e3c !important;
}

html:not([data-bs-theme="light"]) .btn-primary {
  background-color: #f59f00 !important;
  border-color: #f59f00 !important;
  color: #000000 !important;
}

html:not([data-bs-theme="light"]) .btn-check:checked + .btn {
  background-color: #f59f00 !important;
  border-color: #f59f00 !important;
  color: #000000 !important;
}

html:not([data-bs-theme="light"]) .page-header {
  background-color: transparent !important;
}

html:not([data-bs-theme="light"]) .page-title {
  color: #ffffff !important;
}

.navbar-brand-image {
  filter: none !important;
}

/* Dynamic Logo Visibility */
/* Default (Dark Mode) */
.logo-light {
  display: none !important;
}
.logo-dark {
  display: block !important;
}

/* Light Mode Override */
html[data-bs-theme="light"] .logo-light {
  display: block !important;
}
html[data-bs-theme="light"] .logo-dark {
  display: none !important;
}

:root {
  --tblr-primary: #f59f00;
}

/* Universal slider style: all native range inputs get the same bar & ball */
input.form-range {
  -webkit-appearance: none;
  appearance: none;
  background: transparent;
}

input.form-range::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 2px;
  background: #dee2e6;
}

input.form-range::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  margin-top: -6px;
  border: none;
  border-radius: 50%;
  background: #f59f00;
  cursor: pointer;
}

input.form-range::-moz-range-track {
  height: 4px;
  border: none;
  border-radius: 2px;
  background: #dee2e6;
}

input.form-range::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border: none;
  border-radius: 50%;
  background: #f59f00;
  cursor: pointer;
}

/* Left-fill override for Max Rain / Max Wind sliders */
input.filled-left {
  --range-progress: 50%;
}

input.filled-left::-webkit-slider-runnable-track {
  background: linear-gradient(
    to right,
    #f59f00 0%,
    #f59f00 var(--range-progress),
    #dee2e6 var(--range-progress),
    #dee2e6 100%
  );
}

input.filled-left::-moz-range-progress {
  height: 4px;
  border-radius: 2px;
  background: #f59f00;
}

#manualControls.controls-disabled {
  opacity: 0.45;
}

/* Keep switch thumb visible in both states */
.form-switch-3 .form-check-input {
  border: none !important;
  background-color: #dee2e6;
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='-4 -4 8 8'%3e%3ccircle r='3' fill='%23adb5bd'/%3e%3c/svg%3e") !important;
  background-position: left 0.125rem center;
  background-size: 1.125rem;
  background-repeat: no-repeat;
  transition: background-position 0.15s ease-in-out, background-color 0.15s ease-in-out, background-image 0.15s ease-in-out;
}

.form-switch-3 .form-check-input:checked {
  border: none !important;
  background-color: #f59f00;
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='-4 -4 8 8'%3e%3ccircle r='3' fill='%23ffffff'/%3e%3c/svg%3e") !important;
  background-position: right 0.125rem center;
  background-size: 1.125rem;
  background-repeat: no-repeat;
}

.history-chart svg {
  width: 100%;
  height: 240px;
  display: block;
}

.history-chart .grid-line {
  stroke: #dfe3e7;
  stroke-dasharray: 4 4;
  stroke-width: 1;
}

.history-chart .axis-label {
  fill: #6c757d;
  font-size: 11px;
}

.history-chart .history-line {
  fill: none;
  stroke: #f59f00;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.history-chart .history-point {
  fill: #f59f00;
}

/* Robust noUiSlider Customization */
html body .noUi-target {
    background: #dee2e6;
    border: none;
    border-radius: 2px;
    box-shadow: none;
    height: 4px;
    /* Remove custom margins to align with native inputs */
    margin: 0;
}

html body .noUi-connect {
    background: #f59f00;
}

/* The handle itself — matches native slider thumbs */
html body .noUi-horizontal .noUi-handle {
    width: 16px;
    height: 16px;
    right: -8px;
    top: -6px;
    border: none;
    border-radius: 50%;
    background: #f59f00;
    cursor: pointer;
    box-shadow: none;
    outline: none;
}

/* Remove default pseudo-elements */
html body .noUi-handle:before,
html body .noUi-handle:after {
    display: none;
}

/* Active/Hover states */
html body .noUi-handle:hover,
html body .noUi-handle:active {
    transform: scale(1.1);
    background: #f59f00;
}

/* Remove any potential tooltips causing layout jumps if not wanted,
   though user didn't complain about them. Kept simple. */
html body .noUi-tooltip {
    display: none; /* Hide internal noUiSlider tooltips if they look ugly; we rely on the text below or simple aesthetics */
}

.chart-tooltip {
  display: none;
  position: absolute;
  background: #ffffff;
  color: #1e293b;
  padding: 4px 8px;
  border: 1px solid #ccc;
  border-radius: 4px;
  z-index: 1000;
  pointer-events: none;
  font-size: 12px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

/* Compact Navbar Overrides */
.navbar {
  min-height: 2.5rem !important;
}

.navbar .nav-link {
  padding-top: 0.15rem !important;
  padding-bottom: 0.15rem !important;
}

.navbar-brand {
  padding-top: 0.15rem !important;
  padding-bottom: 0.15rem !important;
}

.navbar-brand img {
  height: 24px !important;
  width: auto !important;
}

/* Reduce Space Between Cards and Connect Footer */
.card {
  margin-bottom: 0px !important;
}

.page-wrapper {
  display: flex;
  flex-direction: column;
}

.container-xl {
  margin-bottom: 0 !important;
  padding-bottom: 0 !important;
}

.footer {
  margin-top: 0 !important;
  padding-top: 0.5rem !important;
  padding-bottom: 0.5rem !important;
  background-color: transparent !important;
  border-top: none !important;
}

/* RESPONSIVE LAYOUT OPTIMIZATIONS FOR TABLET & MOBILE */
html {
  scroll-behavior: smooth;
}

@media (max-width: 48em) {
  body {
    height: auto !important;
    overflow: auto !important;
  }

  .page-wrapper {
    height: auto !important;
    overflow: visible !important;
    flex-grow: unset !important;
  }

  .container-xl {
    padding-left: 0.75rem !important;
    padding-right: 0.75rem !important;
  }

  /* Stacked cards on mobile need micro-spacing instead of touching */
  .card {
    margin-bottom: 0.75rem !important;
  }

  .card-body {
    padding: 1rem !important;
  }

  /* Compact header & brand logo on small viewports */
  .navbar {
    padding-left: 0.5rem !important;
    padding-right: 0.5rem !important;
  }

  .navbar-brand img {
    height: 22px !important;
  }

  /* Sliders and Range Inputs tap target optimizations */
  input.form-range {
    height: 1.5rem;
  }

  /* Chart spacing and dimension optimizations */
  .history-chart svg {
    height: 252px !important;
  }

  /* Responsive custom date popups to prevent screen boundary overflow */
  #custom-date-popup,
  #weather-sensors-custom-date-popup {
    max-width: calc(100vw - 1.5rem) !important;
    width: 280px !important;
    right: 0 !important;
  }

  /* Make the main navbar header sticky on mobile */
  header.navbar {
    position: sticky !important;
    top: 0;
    z-index: 1030;
    background-color: #ffffff;
    box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  }

  html:not([data-bs-theme="light"]) header.navbar {
    background-color: #1d273b !important;
    border-bottom: 1px solid #2d3748 !important;
  }

  /* Make the page-header sticky on mobile */
  .page-header {
    position: sticky !important;
    top: 3.25rem; /* Compact navbar height is min-height 2.5rem */
    z-index: 1020;
    background-color: #ffffff;
    padding: 0.5rem 0.75rem !important;
    margin-top: 0 !important;
    margin-bottom: 0.75rem !important;
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
  }

  html:not([data-bs-theme="light"]) .page-header {
    background-color: #151f2c !important;
    border-bottom: 1px solid #2d3748 !important;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
  }

  /* Ensure proper spacing under sticky page header so content is not cut off */
  .page-wrapper {
    padding-top: 0 !important;
  }
}

/* ULTRA-SMALL MOBILE VIEWPORTS (< 384px / 24em) */
@media (max-width: 24em) {
  /* Prevent horizontal overflow of date selector buttons */
  .btn-group .btn {
    padding: 0.25rem 0.4rem !important;
    font-size: 0.75rem !important;
  }

  /* Shrink page margins for maximum screen utility */
  .container-xl {
    padding-left: 0.5rem !important;
    padding-right: 0.5rem !important;
  }

  /* Ensure top nav elements fit on one line without overflow or wrapping */
  .navbar {
    padding-left: 0.25rem !important;
    padding-right: 0.25rem !important;
  }

  .navbar-brand {
    margin-right: 0.25rem !important;
  }

  .navbar-brand img {
    height: 18px !important;
  }

  .me-3 {
    margin-right: 0.5rem !important;
  }

  .btn-outline-danger.btn-sm {
    padding: 0.15rem 0.35rem !important;
    font-size: 0.7rem !important;
  }
}


