* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: #333;
  background: #f8f9fa;
}

header {
  background: #fff;
  border-bottom: 1px solid #dee2e6;
  padding: 16px 24px;
}

header h1 {
  font-size: 1.4rem;
  font-weight: 600;
}

.app-container {
  display: flex;
  min-height: calc(100vh - 60px);
}

/* Sidebar */
.sidebar {
  width: 280px;
  min-width: 280px;
  background: #fff;
  border-right: 1px solid #dee2e6;
  padding: 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  position: relative;
  transition: width 0.2s ease, min-width 0.2s ease, padding 0.2s ease;
}

.sidebar-toggle {
  align-self: flex-end;
  width: 26px;
  height: 26px;
  margin-bottom: 8px;
  padding: 0;
  border: 1px solid #ced4da;
  border-radius: 4px;
  background: #fff;
  color: #6c757d;
  font-size: 0.9rem;
  line-height: 1;
  cursor: pointer;
  flex-shrink: 0;
}

.sidebar-toggle:hover {
  background: #f0f0f0;
  color: #333;
}

.app-container.sidebar-collapsed .sidebar {
  width: 44px;
  min-width: 44px;
  padding: 12px 8px;
  overflow: visible;
}

.app-container.sidebar-collapsed .sidebar > *:not(.sidebar-toggle) {
  display: none;
}

.app-container.sidebar-collapsed .sidebar-toggle {
  align-self: center;
}

.sidebar label {
  display: block;
  font-size: 0.85rem;
  font-weight: 500;
  margin-bottom: 4px;
  color: #495057;
}

.sidebar select {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid #ced4da;
  border-radius: 4px;
  font-size: 0.85rem;
  margin-bottom: 8px;
}

.sidebar hr {
  border: none;
  border-top: 1px solid #dee2e6;
  margin: 16px 0;
}

.sidebar h3 {
  font-size: 1rem;
  margin-bottom: 12px;
}

.slider-group {
  margin-bottom: 14px;
}

.slider-group label {
  margin-bottom: 2px;
}

.slider-group input[type="range"] {
  width: calc(100% - 66px);
  vertical-align: middle;
}

.slider-value {
  display: inline-block;
  width: 58px;
  text-align: right;
  font-size: 0.82rem;
  font-family: monospace;
  color: #495057;
  border: 1px solid #ced4da;
  border-radius: 3px;
  padding: 2px 4px;
  background: #fff;
  -moz-appearance: textfield;
}

.slider-value::-webkit-outer-spin-button,
.slider-value::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.btn {
  display: block;
  width: 100%;
  padding: 8px 12px;
  border: 1px solid #ced4da;
  border-radius: 4px;
  font-size: 0.9rem;
  cursor: pointer;
  margin-bottom: 8px;
}

.btn-default {
  background: #fff;
  color: #333;
}

.btn-default:hover { background: #f0f0f0; }

.btn-primary {
  background: #0d6efd;
  color: #fff;
  border-color: #0d6efd;
}

.btn-primary:hover { background: #0b5ed7; }

.repo-link {
  display: inline-flex;
  align-items: center;
  margin-top: auto;
  padding-top: 14px;
  border-top: 1px solid #dee2e6;
  width: 100%;
  color: #6c757d;
  text-decoration: none;
}

.repo-link svg {
  display: block;
}

.repo-link:hover {
  color: #333;
}

/* Main panel */
.main-panel {
  flex: 1;
  padding: 20px;
  position: relative;
  overflow: hidden;
}

/* Tabs */
.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  border-bottom: 2px solid #dee2e6;
  margin-bottom: 16px;
}

.tab {
  padding: 8px 14px;
  border: 1px solid transparent;
  border-bottom: none;
  background: none;
  cursor: pointer;
  font-size: 0.85rem;
  color: #6c757d;
  border-radius: 4px 4px 0 0;
}

.tab:hover { color: #333; }

.tab.active {
  color: #333;
  border-color: #dee2e6;
  background: #fff;
  font-weight: 500;
  position: relative;
  top: 2px;
  border-bottom: 2px solid #fff;
}

.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
}

.chart-container {
  width: 100%;
  height: 550px;
}

/* X-axis caption with info tooltip */
.axis-caption {
  text-align: center;
  font-size: 0.85rem;
  color: #495057;
  margin-top: 12px;
}

.caption-above {
  margin-top: 0;
  margin-bottom: 12px;
}

.help-link {
  position: relative;
  color: #6c757d;
  cursor: help;
  text-decoration: underline dotted;
  text-underline-offset: 2px;
}

.help-link:hover,
.help-link:focus {
  color: #333;
  outline: none;
}

.tooltip-text {
  visibility: hidden;
  opacity: 0;
  position: absolute;
  bottom: 130%;
  left: 50%;
  transform: translateX(-50%);
  width: 240px;
  background: #333;
  color: #fff;
  text-align: left;
  font-size: 0.78rem;
  font-weight: 400;
  line-height: 1.4;
  padding: 8px 10px;
  border-radius: 5px;
  z-index: 200;
  transition: opacity 0.12s ease;
}

.tooltip-wide {
  width: 340px;
}

.help-link:hover .tooltip-text,
.help-link:focus .tooltip-text {
  visibility: visible;
  opacity: 1;
}

/* Sub-tabs for city-level charts */
.subtab {
  padding: 5px 10px;
  margin-right: 4px;
  margin-bottom: 10px;
  border: 1px solid #ced4da;
  border-radius: 4px;
  background: #fff;
  cursor: pointer;
  font-size: 0.8rem;
  color: #6c757d;
}

.subtab.active {
  background: #0d6efd;
  color: #fff;
  border-color: #0d6efd;
}

/* Loading overlay */
.loading-overlay {
  position: absolute;
  inset: 0;
  background: rgba(255,255,255,0.85);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid #dee2e6;
  border-top-color: #0d6efd;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-bottom: 12px;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* Responsive */
@media (max-width: 768px) {
  .app-container { flex-direction: column; }
  .sidebar {
    width: 100%;
    min-width: unset;
    border-right: none;
    border-bottom: 1px solid #dee2e6;
  }
  .tabs { font-size: 0.75rem; }
}
