/* ── Theme: Gouvernement du Québec blue ─────────────── */
:root {
  --primary:            rgb(9 87 151);   /* #095797 */
  --primary-foreground: rgb(255 255 255);
  --ring:               rgb(9 87 151);
}
@media (prefers-color-scheme: dark) {
  :root {
    --primary:            rgb(41 121 193);
    --primary-foreground: rgb(255 255 255);
    --ring:               rgb(41 121 193);
  }
}

/* ── Layout ─────────────────────────────────────────── */
html, body { height: 100%; margin: 0; padding: 0; }

/* ── Top nav ─────────────────────────────────────────── */
#topnav {
  display: flex; align-items: center; gap: 0;
  height: 44px; padding: 0 16px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  z-index: 2000;
}
#topnav .brand {
  font-weight: 700; font-size: 15px; letter-spacing: -0.2px;
  margin-right: 24px; color: var(--foreground);
  text-decoration: none;
}
#topnav nav { display: flex; gap: 2px; }
#topnav nav a {
  display: flex; align-items: center; gap: 6px;
  padding: 5px 12px; border-radius: 6px;
  text-decoration: none; color: var(--muted-foreground);
  font-size: 13px; font-weight: 500;
  transition: background 0.12s, color 0.12s;
  cursor: pointer;
}
#topnav nav a:hover {
  background: var(--muted);
  color: var(--foreground);
}
#topnav nav a[aria-current="page"] {
  background: var(--primary);
  color: var(--primary-foreground);
}
#topnav nav a svg { flex-shrink: 0; }

/* ── App shell ───────────────────────────────────────── */
#app {
  display: flex; flex-direction: column;
  height: 100%;
}
#content {
  flex: 1; min-height: 0;
  display: flex; flex-direction: column;
}

/* ── Map page ────────────────────────────────────────── */
#page-map { display: flex; flex-direction: column; flex: 1; position: relative; }
#map { flex: 1; min-height: 0; }

/* Slider + fuel panel */
#slider-panel {
  position: absolute; top: 12px; left: 12px;
  padding: 10px 14px;
  z-index: 1000; font-size: 13px; min-width: 280px;
}
#slider-panel .fuel-btns { display: flex; gap: 6px; margin-bottom: 10px; }
#region-select {
  width: 100%; margin-bottom: 10px;
  padding: 5px 8px; font-size: 12px;
  border: 1px solid var(--border); border-radius: 4px;
  background: var(--secondary); color: var(--secondary-foreground);
  cursor: pointer;
}
#slider-panel label { display: block; margin-bottom: 6px; font-weight: 600; }
#price-slider { width: 100%; cursor: pointer; }
#slider-value {
  display: flex; justify-content: space-between;
  margin-top: 4px; font-size: 11px;
  color: var(--muted-foreground);
}
#visible-count { margin-top: 6px; font-size: 11px; color: var(--muted-foreground); }

/* Map overlay panels — sit above the Leaflet tiles */
.map-panel {
  background: var(--card);
  color: var(--card-foreground);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

/* Legend (inline inside slider-panel) */
#legend {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
  font-size: 11px;
  color: var(--muted-foreground);
}
.legend-header {
  margin-bottom: 4px;
  font-weight: 500;
}
.legend-gradient {
  height: 8px; border-radius: 3px;
  background: linear-gradient(to right, #16a34a, #65a30d, #ca8a04, #ea580c, #dc2626);
  margin-bottom: 2px;
  opacity: 0.85;
}
.legend-labels {
  display: flex; justify-content: space-between;
  font-size: 10px; color: var(--muted-foreground);
}

#last-updated {
  position: absolute; bottom: 24px; right: 8px;
  padding: 5px 10px;
  z-index: 1000; font-size: 11px;
  color: var(--muted-foreground);
}

.pin-icon { filter: drop-shadow(0 1px 3px rgba(0,0,0,0.35)); }

.cluster-info-tip {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px; height: 16px;
  border-radius: 50%;
  border: 1px solid var(--muted-foreground);
  color: var(--muted-foreground);
  font-size: 10px; font-weight: 700;
  cursor: default;
  flex-shrink: 0;
}
.cluster-info-tip:hover .cluster-info-tooltip { display: block; }
.cluster-info-tooltip {
  display: none;
  position: absolute;
  left: 22px; top: 50%;
  transform: translateY(-50%);
  background: var(--card);
  color: var(--card-foreground);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
  padding: 10px 12px;
  font-size: 12px; font-weight: 400;
  white-space: nowrap;
  z-index: 2000;
  pointer-events: none;
  line-height: 1.6;
}

.cluster-hint {
  display: none;
  font-size: 11px;
  color: var(--muted-foreground);
  margin-bottom: 10px;
}

.fuel-btn {
  padding: 4px 12px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--secondary);
  color: var(--secondary-foreground);
  cursor: pointer; font-size: 12px;
  transition: all 0.15s;
}
.fuel-btn:hover { background: var(--muted); }
.fuel-btn.active {
  background: var(--primary);
  color: var(--primary-foreground);
  border-color: var(--primary);
}

/* ── Loading overlay ─────────────────────────────────── */
#loading {
  position: fixed; inset: 0;
  background: var(--background);
  opacity: 0.92;
  display: flex; align-items: center; justify-content: center;
  z-index: 10000; font-size: 1.1em;
  color: var(--foreground);
  gap: 12px;
}

/* ── Stats page ──────────────────────────────────────── */
#page-stats { display: flex; padding: 24px; overflow-y: auto; flex: 1; flex-direction: column; }
#page-stats h2 { margin-bottom: 20px; }

.stat-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}
.stat-cards .card { margin: 0; }
.stat-cards .card header { padding-bottom: 4px; }
.stat-cards .card header p { font-size: 12px; color: var(--muted-foreground); margin: 0; }
.stat-value { font-size: 28px; font-weight: 700; margin: 4px 0 0; }
.stat-sub { font-size: 12px; color: var(--muted-foreground); margin-top: 2px; }

.chart-wrap {
  background: var(--card);
  color: var(--card-foreground);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 20px;
  margin-bottom: 28px;
}
.chart-wrap h3 { margin-bottom: 4px; }
.chart-wrap .chart-subtitle {
  font-size: 12px; color: var(--muted-foreground); margin-bottom: 16px;
}

.range-btns { display: flex; gap: 6px; margin-bottom: 16px; }
.range-btn {
  padding: 4px 12px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--secondary);
  color: var(--secondary-foreground);
  cursor: pointer; font-size: 12px;
}
.range-btn:hover { background: var(--muted); }
.range-btn.active {
  background: var(--primary);
  color: var(--primary-foreground);
  border-color: var(--primary);
}

#stats-chart-canvas { width: 100% !important; max-height: 320px; }

.no-data { color: var(--muted-foreground); font-size: 14px; padding: 24px 0; text-align: center; }

.table-wrap { overflow-x: auto; }

/* ── htmx loading indicator ──────────────────────────── */
.htmx-request #stats-content { opacity: 0.5; transition: opacity 0.2s; }

/* ── Filter toggle button (mobile only) ─────────────── */
#filter-toggle {
  display: none;             /* hidden on desktop */
  position: absolute;
  bottom: 24px; left: 12px;
  z-index: 1001;
  padding: 8px 14px;
  font-size: 13px; font-weight: 600;
  cursor: pointer;
  align-items: center; gap: 6px;
  border: none;
  color: var(--card-foreground);
}
#filter-toggle svg { flex-shrink: 0; }

/* ── Mobile layout ──────────────────────────────────── */
@media (max-width: 768px) {
  #filter-toggle { display: flex; }

  #slider-panel {
    position: fixed;
    top: auto; left: 0; right: 0; bottom: 0;
    min-width: 0; width: 100%;
    border-radius: 16px 16px 0 0;
    max-height: 70vh;
    overflow-y: auto;
    padding: 16px 16px 20px;
    transform: translateY(100%);
    transition: transform 0.3s ease;
    z-index: 1100;
  }
  #slider-panel.open { transform: translateY(0); }

  /* Drag handle hint at top of the panel */
  #slider-panel::before {
    content: '';
    display: block;
    width: 36px; height: 4px;
    background: var(--muted-foreground);
    border-radius: 2px;
    margin: 0 auto 12px;
    opacity: 0.4;
  }

  /* Semi-transparent backdrop when panel is open */
  #filter-backdrop {
    display: none;
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.3);
    z-index: 1099;
  }
  #filter-backdrop.visible { display: block; }

  /* Hide the toggle when panel is open */
  #filter-toggle.hidden { display: none; }

  /* Fuel & cluster toggle buttons: full-width on mobile */
  #slider-panel .fuel-btns {
    width: 100%;
  }
  .fuel-btn {
    flex: 1;
    text-align: center;
    padding: 8px 6px;
    font-size: 13px;
  }

  /* Cluster tooltip: hide icon, show hint text on mobile */
  .cluster-info-tip { display: none; }
  .cluster-hint { display: block; }
  .cluster-row { margin-bottom: 0; }
}
