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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: #334155;
  background: #f8fafc;
  min-height: 100vh;
}

.container {
  max-width: 1300px;
  margin: 0 auto;
  padding: 2rem 1.5rem 4rem;
}

/* ── Header ── */
header {
  margin-bottom: 1.75rem;
}

.header-main {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
}

.btn-help {
  flex-shrink: 0;
  width: 1.75rem;
  height: 1.75rem;
  border: 1px solid #e2e8f0;
  border-radius: 50%;
  background: #fff;
  font-size: 0.85rem;
  font-weight: 600;
  color: #64748b;
  cursor: pointer;
  line-height: 1;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}

.btn-help:hover {
  background: #f1f5f9;
  border-color: #cbd5e1;
  color: #1e40af;
}

/* ── Modal ── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.35);
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

.modal {
  background: #fff;
  border-radius: 10px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.14);
  width: 100%;
  max-width: 640px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  overflow-x: hidden;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem 0.875rem;
  border-bottom: 1px solid #f1f5f9;
}

.modal-header h3 {
  font-size: 0.95rem;
  font-weight: 600;
  color: #0f172a;
}

.modal-close {
  width: 1.75rem;
  height: 1.75rem;
  border: none;
  background: none;
  font-size: 1.1rem;
  color: #94a3b8;
  cursor: pointer;
  border-radius: 4px;
  line-height: 1;
  transition: background 0.1s, color 0.1s;
}

.modal-close:hover {
  background: #f1f5f9;
  color: #334155;
}

.modal-body {
  overflow-y: auto;
  overflow-x: hidden;
  padding: 1rem 1.25rem 1.25rem;
}

.glossary {
  font-size: 0.8125rem;
}

.glossary > div {
  padding: 0.55rem 0;
  border-bottom: 1px solid #f1f5f9;
}

.glossary > div:last-child {
  border-bottom: none;
}

.glossary dt {
  font-weight: 600;
  color: #1e293b;
  margin-bottom: 0.2rem;
}

.glossary dd {
  color: #475569;
  line-height: 1.55;
  margin: 0;
}

.modal-source {
  margin-top: 1rem;
  font-size: 0.72rem;
  color: #94a3b8;
}

.modal-source a {
  color: #3b82f6;
  text-decoration: none;
}

.modal-source a:hover {
  text-decoration: underline;
}

h1 {
  font-size: 1.25rem;
  font-weight: 600;
  color: #0f172a;
  letter-spacing: -0.01em;
}

.subtitle {
  font-size: 0.8rem;
  color: #94a3b8;
  margin-top: 0.2rem;
}

/* ── Search section ── */
.search-section {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 1.25rem 1.5rem 1rem;
  margin-bottom: 1.5rem;
}

.search-row {
  display: flex;
  gap: 1rem;
  align-items: flex-end;
  flex-wrap: wrap;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.field label {
  font-size: 0.7rem;
  font-weight: 600;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.search-field {
  flex: 1;
  min-width: 220px;
}

.autocomplete-wrap {
  position: relative;
}

input[type="text"],
input[type="date"] {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  font-size: 0.875rem;
  color: #1e293b;
  background: #fff;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

input[type="text"]:focus,
input[type="date"]:focus {
  border-color: #3b82f6;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.12);
}

/* ── Suggestions ── */
.suggestions {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.08);
  z-index: 200;
  list-style: none;
  max-height: 260px;
  overflow-y: auto;
}

.suggestions li {
  padding: 0.55rem 0.75rem;
  cursor: pointer;
  transition: background 0.1s;
  border-bottom: 1px solid #f1f5f9;
}

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

.suggestions li:hover,
.suggestions li.active {
  background: #f1f5f9;
}

.sug-name {
  font-weight: 500;
  color: #1e293b;
  font-size: 0.875rem;
}

.sug-meta {
  font-size: 0.72rem;
  color: #94a3b8;
  margin-top: 0.1rem;
}

/* ── Presets ── */
.presets {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.75rem;
  flex-wrap: wrap;
}

.preset-label {
  font-size: 0.72rem;
  color: #94a3b8;
}

.preset-btn {
  padding: 0.2rem 0.6rem;
  border: 1px solid #e2e8f0;
  border-radius: 4px;
  background: #fff;
  font-size: 0.75rem;
  color: #64748b;
  cursor: pointer;
  transition: background 0.1s, border-color 0.1s;
}

.preset-btn:hover {
  background: #f1f5f9;
  border-color: #cbd5e1;
}

/* ── Button ── */
.btn {
  padding: 0.5rem 1.25rem;
  border: none;
  border-radius: 6px;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
  white-space: nowrap;
}

.btn-primary {
  background: #1e40af;
  color: #fff;
}

.btn-primary:hover:not(:disabled) {
  background: #1d3faa;
}

.btn-primary:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ── Results header ── */
.results-header {
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.results-header h2 {
  font-size: 1.05rem;
  font-weight: 600;
  color: #0f172a;
}

.btn-export {
  margin-left: auto;
  padding: 0.3rem 0.8rem;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  background: #fff;
  font-size: 0.78rem;
  font-weight: 500;
  color: #334155;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
}

.btn-export:hover {
  background: #f1f5f9;
  border-color: #cbd5e1;
}

.commune-code {
  font-size: 0.72rem;
  color: #94a3b8;
  background: #f1f5f9;
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  font-variant-numeric: tabular-nums;
}

/* ── Status messages ── */
.status {
  padding: 0.75rem 1rem;
  border-radius: 6px;
  font-size: 0.85rem;
  margin-bottom: 1rem;
}

.status-loading {
  background: #f1f5f9;
  color: #64748b;
}

.status-error {
  background: #fef2f2;
  color: #b91c1c;
  border: 1px solid #fecaca;
}

/* ── Table ── */
.table-wrap {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  overflow: hidden;
}

.table-scroll {
  overflow-x: auto;
  max-height: 65vh;
  overflow-y: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8125rem;
  white-space: nowrap;
}

/* Sticky header */
thead {
  position: sticky;
  top: 0;
  z-index: 10;
}

thead tr.group-row th {
  background: #f1f5f9;
  padding: 0.4rem 0.75rem;
  font-size: 0.65rem;
  font-weight: 700;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  border-bottom: 1px solid #e2e8f0;
  text-align: left;
}

thead tr.group-row th.group-date {
  position: sticky;
  left: 0;
  z-index: 30;
  background: #f1f5f9;
}

thead tr.col-row th {
  background: #f8fafc;
  padding: 0.45rem 0.75rem;
  font-size: 0.72rem;
  font-weight: 600;
  color: #475569;
  border-bottom: 2px solid #e2e8f0;
  text-align: right;
  vertical-align: bottom;
}

thead tr.col-row th.col-date {
  position: sticky;
  left: 0;
  z-index: 30;
  background: #f8fafc;
  text-align: left;
}

thead tr.col-row th .unit {
  display: block;
  font-weight: 400;
  color: #94a3b8;
  font-size: 0.65rem;
  margin-top: 0.1rem;
}

/* Body */
tbody tr {
  border-bottom: 1px solid #f1f5f9;
  transition: background 0.08s;
}

tbody tr:last-child {
  border-bottom: none;
}

tbody tr:hover {
  background: #f8fafc;
}

tbody tr:hover td.sticky-date {
  background: #f8fafc;
}

td {
  padding: 0.45rem 0.75rem;
  color: #334155;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

td.sticky-date {
  position: sticky;
  left: 0;
  background: #fff;
  text-align: left;
  font-weight: 500;
  color: #1e293b;
  border-right: 1px solid #e2e8f0;
  z-index: 5;
  font-variant-numeric: tabular-nums;
}

td.null-val {
  color: #cbd5e1;
  text-align: right;
}

/* Table footer */
.table-info {
  padding: 0.6rem 0.75rem;
  font-size: 0.72rem;
  color: #94a3b8;
  border-top: 1px solid #f1f5f9;
  text-align: right;
}

/* ── Toolbar ── */
.toolbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

/* Bascule tableau / graphique */
.view-toggle {
  display: flex;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  overflow: hidden;
  flex-shrink: 0;
}

.view-btn {
  padding: 0.375rem 0.875rem;
  border: none;
  background: #fff;
  font-size: 0.8125rem;
  font-weight: 500;
  color: #64748b;
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
}

.view-btn + .view-btn {
  border-left: 1px solid #e2e8f0;
}

.view-btn.active {
  background: #1e40af;
  color: #fff;
}

.view-btn:not(.active):hover {
  background: #f1f5f9;
}

/* Barres de contrôle (filtres & sélecteur graphique) */
.ctrl-bar {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.ctrl-label {
  font-size: 0.72rem;
  color: #94a3b8;
  white-space: nowrap;
}

/* Boutons tag (filtres / groupes) */
.tag-btn {
  padding: 0.25rem 0.7rem;
  border: 1px solid #cbd5e1;
  border-radius: 20px;
  background: #fff;
  font-size: 0.75rem;
  font-weight: 500;
  color: #334155;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, color 0.12s, opacity 0.12s;
  white-space: nowrap;
}

.tag-btn:hover {
  background: #f1f5f9;
}

.tag-btn.off {
  background: #fff;
  border-color: #e2e8f0;
  color: #94a3b8;
  text-decoration: line-through;
  opacity: 0.6;
}

/* ── Graphique ── */
.chart-outer {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 1.25rem 1.25rem 1rem;
  height: 420px;
}

.chart-outer canvas {
  width: 100% !important;
  height: 100% !important;
}

/* ── Utility ── */
.hidden {
  display: none !important;
}

/* ── Responsive ── */
@media (max-width: 640px) {
  .container {
    padding: 1.25rem 1rem 3rem;
  }

  .search-row {
    flex-direction: column;
    align-items: stretch;
  }

  .field-btn {
    align-self: flex-start;
  }
}
