* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
}

body {
  font-family:
    "Segoe UI",
    system-ui,
    -apple-system,
    sans-serif;
  background: #0f1115;
  color: #e8eaed;
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  background: #151922;
  border-bottom: 1px solid #222836;
  position: sticky;
  top: 0;
  z-index: 20;
}

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

.app-logo-img {
  width: 28px;
  height: 28px;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.3));
}

.topbar h1 {
  font-size: 18px;
  margin: 0;
  font-weight: 600;
}

.status {
  font-size: 13px;
  color: #a9b1bd;
}

main {
  display: grid;
  grid-template-columns: 1fr 280px;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}

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

.panel {
  padding: 16px;
  background: #111521;
  border-left: 1px solid #222836;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  overflow-y: auto;
}

.panel-handle {
  display: none;
  width: 40px;
  height: 4px;
  background: #3c4043;
  border-radius: 2px;
  margin: 0 auto 16px;
  cursor: pointer;
}

.panel h2 {
  font-size: 14px;
  margin: 18px 0 8px;
  color: #cfd6e4;
}

.panel select {
  width: 100%;
  padding: 8px 10px;
  border-radius: 8px;
  background: #0f1320;
  border: 1px solid #2a3140;
  color: #e8eaed;
  font-size: 13px;
}

.panel ul {
  list-style: none;
  padding: 0;
  margin: 0;
  font-size: 13px;
  color: #a9b1bd;
}

.panel ul li {
  padding: 6px 0;
  border-bottom: 1px solid #222836;
}

.legend-list {
  max-height: none;
  overflow: visible;
  padding-right: 4px;
}

.legend-filter {
  width: 100%;
  padding: 8px 10px;
  border-radius: 8px;
  background: #0f1320;
  border: 1px solid #2a3140;
  color: #e8eaed;
  font-size: 13px;
  margin-bottom: 8px;
}

.legend-filter--large {
  padding: 12px 14px;
  font-size: 15px;
}

.legend-item {
  display: grid;
  grid-template-columns: 18px 12px 1fr;
  gap: 6px;
  align-items: center;
}

.legend-item input {
  width: 14px;
  height: 14px;
}

.legend-section {
  margin-top: 10px;
}

.legend-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.legend-header h3 {
  margin: 8px 0 6px;
  font-size: 13px;
  color: #cfd6e4;
}

.legend-toggle {
  all: unset;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: #cfd6e4;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: color 0.2s ease;
}

.legend-toggle:hover {
  color: #ffffff;
}

.legend-toggle:focus-visible {
  outline: 2px solid #1e88e5;
  outline-offset: 2px;
}

.legend-toggle-icon {
  display: inline-block;
  transition: transform 0.2s ease;
}

.legend-toggle[aria-expanded="false"] .legend-toggle-icon {
  transform: rotate(-90deg);
}

.legend-list.is-collapsed {
  display: none;
}

.legend-select {
  font-size: 12px;
  color: #a9b1bd;
  display: flex;
  align-items: center;
  gap: 6px;
}

.legend-select--single {
  margin-bottom: 8px;
}

.legend-swatch {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.35);
}

.panel p {
  font-size: 13px;
  color: #a9b1bd;
  line-height: 1.4;
}

.muted {
  color: #9aa3af;
}

.muted a {
  color: #9aa3af;
}

.muted a:hover {
  color: #c0c7d1;
}

.panel button {
  background: #1e88e5;
  color: #fff;
  border: 0;
  border-radius: 8px;
  padding: 8px 12px;
  cursor: pointer;
}

.panel button:hover {
  background: #1876c7;
}

.city-menu {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 8px;
}

.city-button {
  background: #1b2231;
  color: #e8eaed;
  border: 1px solid #2a3140;
  padding: 10px 12px;
  font-size: 13px;
  border-radius: 10px;
  cursor: pointer;
  text-align: left;
}

.city-button.is-active {
  border-color: #1e88e5;
  box-shadow: 0 0 0 1px rgba(30, 136, 229, 0.6);
}

.mode-menu {
  margin-top: 14px;
}

.mode-menu.is-hidden {
  display: none;
}

.mode-title {
  font-size: 12px;
  color: #a9b1bd;
  margin-bottom: 8px;
}

.mode-buttons {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: 8px;
}

.mode-button {
  background: #141a26;
  color: #e8eaed;
  border: 1px solid #2a3140;
  padding: 10px 12px;
  font-size: 13px;
  border-radius: 10px;
  cursor: pointer;
}

.mode-button.is-active {
  background: #1e88e5;
  border-color: #1e88e5;
}

.routes-section.is-hidden {
  display: none;
}

.city-mode-menu {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

.city-card {
  background: #141a26;
  border: 1px solid #232a38;
  border-radius: 14px;
  padding: 12px 12px 10px;
}

.city-card-title {
  font-size: 14px;
  font-weight: 600;
  color: #e8eaed;
  margin: 0 0 8px;
}

.mode-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: 8px;
}

.mode-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  background: #1b2231;
  color: #e8eaed;
  border: 1px solid #2a3140;
  border-radius: 999px;
  padding: 8px 10px;
  font-size: 12px;
  cursor: pointer;
}

.mode-pill.is-active {
  background: #1e88e5;
  border-color: #1e88e5;
}

.panel::-webkit-scrollbar {
  width: 8px;
}

.panel::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.2);
  border-radius: 8px;
}

.panel::-webkit-scrollbar-track {
  background: transparent;
}

.panel {
  scrollbar-color: rgba(255, 255, 255, 0.25) transparent;
  scrollbar-width: thin;
}



.dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 999px;
  margin-right: 6px;
}

.leaflet-container {
  background: #0b0e14;
  touch-action: pan-x pan-y;
}

/* Adjust Leaflet controls for mobile bottom sheet */
@media (max-width: 900px) {
  .leaflet-bottom {
    bottom: 80px; /* Leave space for the peek sheet */
    transition: bottom 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  }
  
  .panel-is-expanded .leaflet-bottom {
    bottom: 72vh;
    bottom: 72svh;
  }
}

@media (max-width: 900px) {
  .topbar {
    padding: 10px 16px;
  }

  main {
    grid-template-columns: 1fr;
    height: auto;
    flex: 1 1 auto;
    min-height: 0;
    position: relative;
    overflow: hidden;
  }

  #map {
    height: 100%;
    z-index: 1;
  }

  .panel {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 70vh;
    height: 70svh;
    z-index: 1000;
    border-left: none;
    border-top: 1px solid #222836;
    border-radius: 24px 24px 0 0;
    box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.6);
    transform: translateY(calc(70vh - 120px)); /* Peek state: reveal more space for interaction */
    transform: translateY(calc(70svh - 120px));
    display: flex;
    flex-direction: column;
    padding-top: 12px;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    background: rgba(21, 25, 34, 0.9);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
  }

  .panel::-webkit-scrollbar {
    width: 8px;
  }

  .panel.is-expanded {
    transform: translateY(0);
    border-radius: 16px 16px 0 0; /* Slightly less rounded when full */
  }

  .panel-handle {
    display: block;
    flex-shrink: 0;
    width: 36px;
    height: 4px;
    background: #5f6368;
    border-radius: 2px;
    margin: 0 auto 12px;
    cursor: pointer;
    transition: background 0.2s;
  }

  .panel-handle:hover {
    background: #80868b;
  }

  .panel h2:first-of-type {
    margin-top: 0;
  }

  .legend-list {
    max-height: none;
    flex-grow: 1;
  }

  .legend-filter--large {
    padding: 10px 12px;
    font-size: 14px;
  }
}

@media (max-width: 600px) {
  .topbar h1 {
    font-size: 16px;
  }

  .status {
    font-size: 12px;
  }
}

.main-content-area {
  flex-grow: 1;
  position: relative;
  height: 100%;
  overflow: hidden;
}

.view-content {
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
}
.chart-card {
  background: rgba(21, 25, 34, 0.4);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: 12px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  min-height: 320px; /* Force larger size */
}

.chart-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.chart-header h3 {
  margin: 0;
  font-size: 15px;
  color: #ffffff;
  font-weight: 600;
}

.expand-btn {
  background: rgba(255, 255, 255, 0.05);
  border: none;
  color: #a9b1bd;
  cursor: pointer;
  font-size: 14px;
  padding: 6px 10px;
  border-radius: 6px;
  transition: all 0.2s;
}

.expand-btn:hover {
  background: #1e88e5;
  color: #ffffff;
}

.chart-wrapper {
  flex-grow: 1;
  width: 100%;
  min-height: 240px;
}

.chart-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 180px;
  color: #5f6368;
  font-style: italic;
  font-size: 12px;
  border: 1px dashed #2a3140;
  border-radius: 8px;
}

/* Modal */
.modal {
  display: none;
  position: fixed;
  z-index: 2000;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(5px);
}

.modal-content {
  position: relative;
  background-color: #111521;
  margin: 4vh auto;
  padding: 40px;
  border: 1px solid #222836;
  width: 90%;
  max-width: 1000px;
  border-radius: 16px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6);
}

.close-modal {
  position: absolute;
  top: 15px;
  right: 25px;
  color: #a9b1bd;
  font-size: 35px;
  font-weight: bold;
  cursor: pointer;
}

.close-modal:hover {
  color: #ffffff;
}

.modal-chart-container {
  height: 70vh;
}

@media (max-width: 900px) {
  .topbar {
    flex-wrap: nowrap;
    gap: 6px;
    justify-content: space-between;
    align-items: center;
    padding: 8px 10px;
  }
  
  .topbar h1 {
    font-size: 16px;
  }

  .status {
    display: none;
  }

  .chart-card {
    padding: 12px;
    min-height: 280px;
  }

  .chart-header h3 {
    font-size: 13px;
  }

  .chart-wrapper {
    min-height: 200px;
  }

  .leaflet-bottom {
    bottom: 80px;
  }

  .modal-content {
    width: 96%;
    margin: 2vh auto;
    padding: 16px;
  }
  
  .modal-chart-container {
    height: 50vh;
  }
}

