/* Make the main layout use Flexbox */
html,
body {
  height: 100%;
  margin: 0;
  padding: 0;
  overflow: hidden; /* ✅ Prevent horizontal overflow */
  -webkit-overflow-scrolling: touch; /* ✅ Smooth scroll for iOS */
  font-family: "Roboto", sans-serif;
}

.main-container {
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  align-items: center;
  min-height: 100vh;
  gap: 20px;
  box-sizing: border-box;
}

.map-sidebar-container {
  display: flex;
  justify-content: space-between;
  font-family: "Roboto", sans-serif;
  align-items: flex-start;
  width: 100%; /* ✅ Ensure full width */
  height: 100%; /* ✅ Keep it tall */
}
#map-info {
  width: 100%;
  margin: 0 auto;
  background-color: rgba(128, 128, 128, 0.2);
  padding: 20px;
  font-family: "Roboto", sans-serif;
  font-size: 18px;
  font-weight: bold;
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  box-sizing: border-box;
  gap: 10px;
}

#map-info h2 {
  font-size: 1.5rem;
  margin: 0;
}

#map-info p {
  font-size: 1rem;
  font-weight: normal;
  margin: 0;
  color: #333;
}

#map-info img {
  width: 120px;
  max-width: 60%;
  height: auto;
  margin-top: 10px;
}

/* Map container styling */
#map {
  flex-grow: 1; /* ✅ Ensures map fills available space */
  width: 60vw; /* ✅ Makes map take full width */
  height: 77vh; /* ✅ Makes map take full height */
  min-height: 74vh; /* ✅ Prevents it from shrinking too much */
}

/* Sidebar styling */
.sensor-sidebar {
  width: 250px;
  background-color: #e0e0e0;
  padding: 15px;
  border-radius: 0px;
  text-align: center;
  flex-shrink: 0;
  min-height: 74vh;
  max-height: 77vh;
  overflow-y: auto;
  box-sizing: border-box;
}

/* Customize headings */
h1,
h2,
h3 {
  font-family: "Montserrat", sans-serif;
  font-weight: bold;
}

/* Sidebar and sensor labels */
.sensor-sidebar,
.sensor .label {
  font-family: "Roboto", sans-serif;
  font-weight: 700;
}

/* Copyright text */
#copyright {
  width: 100%;
  text-align: center; /* ✅ fix casing */
  background-color: rgba(128, 128, 128, 0.2);
  padding: 10px;
  font-size: 14px;
  font-weight: bold;
  border-radius: 5px;
  position: fixed;
  bottom: 0;
  left: 0;
  z-index: 999;
  box-sizing: border-box;
}

/* Individual sensor readings */
.sensor {
  padding: 8px;
  margin: 5px 0;
  border-radius: 5px;
}

.label {
  font-size: 0.8rem;
  font-weight: bold;
  text-align: Center;
}

.value {
  font-size: 1rem;
  color: #0078d7;
  text-align: Center;
}

.value.inactive {
  color: #cc0000 !important;
  font-weight: bold;
}

.leaflet-popup-content {
  font-size: 12px;
}
#copyright {
  width: 100%;
  text-align: Center; /* ✅ Aligns text like the main section */
  background-color: rgba(128, 128, 128, 0.2); /* ✅ Light gray background */
  padding: 10px;
  font-size: 14px;
  font-weight: bold;
  border-radius: 5px;
  position: fixed; /* ✅ Keeps it at the bottom */
  bottom: 0; /* ✅ Positions it at the bottom of the page */
  left: 0;
  z-index: 999;
}

.pm-label div {
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: none;
  color: white;
  font-size: 1em;
  text-align: center;
  line-height: 1;
  box-sizing: border-box;
  overflow: hidden;
  transform-origin: center;
}

.pm-text-above div {
  background: rgba(128, 128, 128, 0.6);
  padding: 5px 5px;
  border-radius: 5px;
  text-align: center;
  font-size: 8px;
  font-weight: bold;
  color: white;
}

.legend {
  background: rgba(128, 128, 128, 0.2);
  text-align: center;
  border-radius: 0;
  width: 100%;
  padding: 10px 0;
  font-family: "Roboto", sans-serif;
}

.legend-box {
  display: block;
  margin: 0 auto;
  max-width: 270px;
}

.legend-box h3 {
  font-size: 16px;
  font-weight: bold;
  margin-bottom: 8px;
}

.legend-box ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

.legend-box li {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 6px 10px;
  font-size: 14px;
  text-align: left;
  word-break: break-word;
  color: black; /* ✅ text always black */
  position: relative;
  padding-left: 32px;
}

.legend-box li::before {
  content: "";
  position: absolute;
  left: 0;
  width: 24px;
  height: 24px;
  border-radius: 3px;
  flex-shrink: 0;
}

/* ✅ Custom box colors */
.box-good::before {
  background-color: #377e22;
}
.box-moderate::before {
  background-color: #ffff54;
}
.box-sensitive::before {
  background-color: #f2a93b;
}
.box-unhealthy::before {
  background-color: #ea3323;
}
.box-very-unhealthy::before {
  background-color: #75147c;
}
.box-hazardous::before {
  background-color: #75140c;
}

.low-zoom-labels-hidden .pm-text-above {
  opacity: 0 !important;
  transition: opacity 0.3s ease;
}

/* Modal styles */
.modal {
  display: none;
  position: fixed;
  z-index: 9999;
  padding-top: 100px;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  overflow: auto;
  background-color: rgba(0, 0, 0, 0.6);
}

.modal-content {
  background-color: #fefefe;
  margin: auto;
  padding: 20px;
  border-radius: 8px;
  width: 90%;
  max-width: 800px;
  text-align: center;
}

.close {
  color: #aaa;
  float: right;
  font-size: 28px;
  font-weight: bold;
  cursor: pointer;
}

.close:hover {
  color: #000;
}

#graphImage {
  max-width: 100%;
  max-height: 400px;
  object-fit: contain;
  border-radius: 8px;
  margin-top: 10px;
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
}

/* Graph button style */
.graph-btn {
  margin-top: 5px;
  background-color: #0078d7;
  color: white;
  border: none;
  padding: 6px 10px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.9rem;
}

.graph-btn:hover {
  background-color: #005a9e;
}

.reset-map-btn {
  position: absolute;
  bottom: 20px;
  right: 20px;
  z-index: 999;
  background-color: rgba(0, 120, 215, 0.95);
  color: white;
  border: none;
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: bold;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
  transition: opacity 0.3s ease, transform 0.3s ease;
  opacity: 0;
  pointer-events: none;
}

.reset-map-btn.show {
  opacity: 1;
  pointer-events: auto;
  transform: scale(1);
}

.reset-map-btn:hover {
  background-color: rgba(0, 100, 180, 0.95);
}

.pollutant-toggle {
  display: flex;
  justify-content: center;
  flex-wrap: wrap; /* allow wrap on smaller screens */
  gap: 10px;
  margin-bottom: 15px;
}

.toggle-btn {
  padding: 6px 12px;
  border: none;
  border-radius: 6px;
  background-color: #ccc;
  font-weight: bold;
  cursor: pointer;
  transition: background-color 0.2s ease;
}

.toggle-btn.active {
  background-color: #0078d7;
  color: white;
}

.modal-toggle {
  margin: 10px 0;
  display: flex;
  justify-content: center;
  gap: 10px;
}

.modal-toggle-btn {
  padding: 6px 12px;
  border: none;
  border-radius: 6px;
  background-color: #ccc;
  font-weight: bold;
  cursor: pointer;
}

.modal-toggle-btn.active {
  background-color: #0078d7;
  color: white;
}

.sensor .value {
  transition: opacity 0.3s ease;
  opacity: 1;
}

.sensor .value.fade-out {
  opacity: 0;
}

.pm-label {
  transition: opacity 0.4s ease;
  opacity: 1;
}

.pm-label.fade-out {
  opacity: 0;
}

/* ========== RESPONSIVE STYLES ========== */
@media (max-width: 1024px) {
  html,
  body {
    overflow-y: auto;
  }

  .map-sidebar-container {
    flex-direction: column;
    align-items: center;
    gap: 20px;
    padding: 10px;
    overflow-y: auto;
  }

  #map {
    width: 90vw;
    height: 50vh;
    min-height: 40vh;
  }

  .sensor-sidebar {
    width: 90vw;
    min-height: auto;
    padding: 10px;
  }

  #map-info h2 {
    font-size: 1.2rem;
  }

  .legend {
    font-size: 0.9rem;
  }

  #copyright {
    position: relative;
    bottom: unset;
    z-index: 0;
    text-align: center;
  }
}

@media (max-width: 600px) {
  html,
  body {
    overflow-y: auto !important;
    height: auto !important;
  }

  .main-container {
    gap: 10px;
    padding: 10px;
  }

  #map {
    width: 100%;
    height: 45vh;
  }

  .sensor-sidebar {
    width: 100%;
    padding: 8px;
  }

  #map-info h2 {
    font-size: 1rem;
  }

  @media (max-width: 600px) {
    .legend-box {
      max-width: 90%;
      margin: 0 auto;
    }

    .legend-box li {
      font-size: 13px;
      margin: 6px 12px;
    }

    .legend-box li::before {
      width: 20px;
      height: 20px;
    }
  }

  .color-box {
    width: 24px;
    height: 24px;
  }

  .label,
  .value {
    font-size: 0.9rem;
  }

  .sensor-sidebar {
    max-height: unset !important;
    overflow: visible !important;
  }

  .map-sidebar-container {
    flex-direction: column;
    align-items: center;
    padding: 10px;
  }

  #copyright {
    font-size: 12px;
  }
}
