/* India Weather page styles. Reuses CSS vars from styles.css. */

/* Quarto auto-injects `page-columns page-full` onto top-level divs in raw HTML
   blocks under page-layout: full, then auto-places children in the page-columns
   slots — map ends up in body-content (narrower than the title) and the
   leaderboard in the right page margin (~215px). Force our two rows back to
   the column-page slot so they line up with the title and span the full page
   width. */
.iw-root.page-columns > .iw-meta,
.iw-root.page-columns > .iw-grid {
  grid-column: page-start / page-end !important;
}

.iw-root {
  margin-top: 0.25rem;
}

.iw-meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  margin: 0 0 0.75rem;
  min-height: 1.25rem;
}

.iw-updated {
  color: var(--text-muted);
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.01em;
}

.iw-grid,
.iw-grid.page-columns,
.iw-grid.page-columns.page-full {
  display: grid !important;
  grid-template-columns: minmax(0, 1fr) clamp(380px, 30%, 460px) !important;
  gap: 1rem;
  align-items: stretch;
}
/* Quarto's page-columns rule otherwise places the leaderboard in the right
   margin column instead of the second cell of our template. */
.iw-grid > * {
  grid-column: auto !important;
}

.iw-map-wrap {
  position: relative;
  height: calc(100vh - 260px);
  min-height: 460px;
  max-height: 760px;
  border: 1px solid var(--border-color);
  border-radius: 10px;
  overflow: hidden;
  background: var(--bg-secondary);
}

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

.iw-status {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-secondary);
  color: var(--text-muted);
  font-size: 0.95rem;
  text-align: center;
  padding: 1rem;
  z-index: 2;
  pointer-events: none;
}

.iw-status.iw-hidden {
  display: none;
}

.iw-status.iw-error {
  color: #ff8b8b;
}

/* Leaderboard */
.iw-leaderboard {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  height: calc(100vh - 260px);
  min-height: 460px;
  max-height: 760px;
}

.iw-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0;
  border-bottom: 1px solid var(--border-color);
  margin-bottom: 0.5rem;
}

.iw-tab {
  background: transparent;
  border: none;
  color: var(--text-muted);
  padding: 0.5rem 0.25rem;
  font-size: 0.82rem;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  white-space: nowrap;
  text-align: center;
}

.iw-tab:hover {
  color: var(--text-primary);
}

.iw-tab.iw-active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.iw-list {
  list-style: none;
  margin: 0;
  padding: 0;
  flex: 1;
  overflow-y: auto;
}

.iw-list li {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.5rem;
  align-items: center;
  padding: 0.5rem 0.4rem;
  border-bottom: 1px solid var(--border-color);
  cursor: pointer;
  transition: background 120ms;
}

.iw-list li:hover {
  background: var(--bg-tertiary);
}

.iw-list li:last-child {
  border-bottom: none;
}

.iw-list .iw-row-name {
  color: var(--text-primary);
  font-weight: 500;
  font-size: 0.9rem;
}

.iw-list .iw-row-sub {
  color: var(--text-muted);
  font-size: 0.75rem;
  margin-top: 2px;
}

.iw-list .iw-row-value {
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
  font-size: 0.95rem;
  font-weight: 600;
  text-align: right;
}

.iw-list .iw-row-value-sub {
  color: var(--text-muted);
  font-size: 0.7rem;
  text-align: right;
  margin-top: 2px;
}

/* Mapbox markers */
.iw-marker {
  background: var(--bg-secondary);
  color: var(--text-primary);
  border: 1px solid var(--accent);
  border-radius: 14px;
  padding: 3px 8px;
  font-size: 0.78rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
  transition: transform 120ms, border-color 120ms;
}

.iw-marker:hover {
  transform: translateY(-1px);
  border-color: var(--text-primary);
}

.iw-marker .iw-marker-temp {
  color: var(--accent);
  margin-left: 4px;
}

/* Custom reset-view button. Mirrors the look of Mapbox's built-in zoom
   controls so the two stacked groups read as one cohesive widget. */
.iw-reset-ctrl .iw-reset-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 29px;
  height: 29px;
  padding: 0;
  border: 0;
  background: #fff;
  color: #333;
  cursor: pointer;
  border-radius: 4px;
}

.iw-reset-ctrl .iw-reset-btn:hover {
  background: #f3f3f3;
  color: #000;
}

.iw-reset-ctrl .iw-reset-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* Mapbox popup overrides for dark theme */
.mapboxgl-popup-content {
  background: var(--bg-secondary) !important;
  color: var(--text-primary) !important;
  border: 1px solid var(--border-color) !important;
  border-radius: 8px !important;
  padding: 0.75rem 0.9rem !important;
  font-family: inherit;
  min-width: 220px;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.5) !important;
}

.mapboxgl-popup-tip {
  border-top-color: var(--border-color) !important;
  border-bottom-color: var(--border-color) !important;
}

.mapboxgl-popup-anchor-top .mapboxgl-popup-tip,
.mapboxgl-popup-anchor-top-left .mapboxgl-popup-tip,
.mapboxgl-popup-anchor-top-right .mapboxgl-popup-tip {
  border-bottom-color: var(--bg-secondary) !important;
}

.mapboxgl-popup-anchor-bottom .mapboxgl-popup-tip,
.mapboxgl-popup-anchor-bottom-left .mapboxgl-popup-tip,
.mapboxgl-popup-anchor-bottom-right .mapboxgl-popup-tip {
  border-top-color: var(--bg-secondary) !important;
}

.mapboxgl-popup-close-button {
  color: var(--text-muted) !important;
  font-size: 1.25rem !important;
  padding: 0 6px !important;
}

.mapboxgl-popup-close-button:hover {
  color: var(--text-primary) !important;
  background: transparent !important;
}

.mapboxgl-ctrl-attrib,
.mapboxgl-ctrl-attrib a {
  background: rgba(46, 46, 51, 0.7) !important;
  color: var(--text-muted) !important;
}

/* Popup card content */
.iw-popup-name {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 0.4rem;
}

.iw-popup-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 12px;
  font-size: 0.85rem;
}

.iw-popup-grid dt {
  color: var(--text-muted);
}

.iw-popup-grid dd {
  margin: 0;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}

.iw-popup-aqi {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 4px;
  font-weight: 600;
  font-size: 0.78rem;
  color: #111;
}

.iw-popup-aqi-label {
  margin-left: 6px;
  color: var(--text-secondary);
  font-size: 0.78rem;
}

/* CPCB AQI band colors */
.iw-aqi-good        { background: #9CC93C; }
.iw-aqi-satisfactory{ background: #A3C853; color: #111; }
.iw-aqi-moderate    { background: #FFD500; color: #111; }
.iw-aqi-poor        { background: #FF9933; color: #111; }
.iw-aqi-very-poor   { background: #FF3333; color: #fff; }
.iw-aqi-severe      { background: #800026; color: #fff; }
.iw-aqi-unknown     { background: var(--bg-tertiary); color: var(--text-muted); }

/* History section */
.iw-history {
  margin-top: 1.75rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--border-color);
}

.iw-history-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.iw-history-header h3 {
  margin: 0;
  color: var(--text-primary);
  font-size: 1.1rem;
}

.iw-history-sub {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-top: 2px;
}

.iw-history-controls {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.iw-sr {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.iw-city-picker select {
  background: var(--bg-secondary);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 0.35rem 0.6rem;
  font-size: 0.85rem;
  font-family: inherit;
  cursor: pointer;
}

.iw-city-picker select:focus {
  outline: none;
  border-color: var(--accent);
}

.iw-range {
  display: inline-flex;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  overflow: hidden;
}

.iw-range-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  padding: 0.35rem 0.75rem;
  font-size: 0.85rem;
  cursor: pointer;
  font-variant-numeric: tabular-nums;
  border-left: 1px solid var(--border-color);
  transition: color 120ms, background 120ms;
}

.iw-range-btn:first-child {
  border-left: none;
}

.iw-range-btn:hover {
  color: var(--text-primary);
}

.iw-range-btn.iw-active {
  color: var(--bg-primary);
  background: var(--accent);
}

.iw-charts {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.75rem;
}

.iw-chart-card {
  margin: 0;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 0.75rem;
}

.iw-chart-card figcaption {
  color: var(--text-primary);
  font-size: 0.9rem;
  font-weight: 500;
  margin-bottom: 0.5rem;
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
}

.iw-chart-source {
  color: var(--text-muted);
  font-weight: 400;
  font-size: 0.75rem;
}

.iw-chart {
  width: 100%;
  min-height: 180px;
  position: relative;
}

.iw-history-status {
  margin-top: 0.75rem;
  color: var(--text-muted);
  font-size: 0.85rem;
  min-height: 1em;
}

.iw-history-status.iw-error {
  color: #ff8b8b;
}

.iw-footnote {
  color: var(--text-muted);
  font-size: 0.78rem;
  margin-top: 1.25rem;
  line-height: 1.55;
}

/* Floating tooltip on charts */
.iw-chart-tooltip {
  position: absolute;
  top: 0;
  left: 0;
  pointer-events: none;
  background: rgba(29, 30, 32, 0.82);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 0.4rem 0.55rem;
  font-size: 0.76rem;
  line-height: 1.35;
  font-variant-numeric: tabular-nums;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.45);
  white-space: nowrap;
  z-index: 5;
  transition: opacity 80ms;
}

.iw-chart-tooltip.iw-hidden {
  opacity: 0;
  visibility: hidden;
}

.iw-chart-tooltip .iw-tt-time {
  color: var(--text-muted);
  font-size: 0.72rem;
  margin-bottom: 4px;
}

.iw-chart-tooltip .iw-tt-row {
  display: grid;
  grid-template-columns: 10px auto 1fr;
  gap: 6px;
  align-items: center;
}

.iw-chart-tooltip .iw-tt-row.iw-tt-sub {
  grid-template-columns: 10px auto 1fr;
  color: var(--text-muted);
  font-size: 0.74rem;
}

.iw-chart-tooltip .iw-tt-row.iw-tt-sub .iw-tt-label {
  grid-column: 2;
}

.iw-chart-tooltip .iw-tt-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}

.iw-chart-tooltip .iw-tt-label {
  color: var(--text-secondary);
}

.iw-chart-tooltip .iw-tt-val {
  text-align: right;
  font-weight: 600;
  color: var(--text-primary);
  margin-left: 8px;
}

.iw-chart-tooltip .iw-tt-cat {
  margin-top: 4px;
  font-size: 0.72rem;
  color: var(--text-muted);
}

/* uPlot dark-theme tweaks */
.iw-chart .u-legend {
  display: none;
}

.iw-chart .u-axis {
  color: var(--text-muted);
}

.iw-chart .uplot,
.iw-chart .u-wrap,
.iw-chart .u-over {
  background: transparent;
}

.iw-chart .u-cursor-pt {
  border-color: var(--accent) !important;
}

/* Mobile */
@media (max-width: 900px) {
  .iw-grid {
    grid-template-columns: 1fr;
  }
  .iw-map-wrap {
    height: 60vh;
    min-height: 360px;
  }
  .iw-leaderboard {
    height: auto;
    min-height: 0;
    max-height: 420px;
  }
  .iw-charts {
    grid-template-columns: 1fr;
  }
}
