/* Styles — simple, lisible, responsive. Aucune dépendance. */
:root {
  --bg: #f5f7fa;
  --card: #ffffff;
  --ink: #1f2933;
  --muted: #6b7280;
  --line: #e4e7eb;
  --accent: #2563eb;
  --green: #15803d;
  --green-bg: #dcfce7;
  --amber: #b45309;
  --amber-bg: #fef3c7;
  --red: #b91c1c;
  --red-bg: #fee2e2;
  --gray-bg: #eef2f7;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.5;
}

.topbar {
  background: var(--accent);
  color: #fff;
  padding: 1.2rem 1rem;
  text-align: center;
}
.topbar h1 { margin: 0; font-size: 1.5rem; }
.subtitle { margin: .3rem 0 0; opacity: .9; font-size: .95rem; }

.container { max-width: 100%; margin: 0 auto; padding: 1rem 1.5rem; }

/* --- Filtres --- */
.filters {
  display: flex; flex-wrap: wrap; gap: .6rem; align-items: center;
  background: var(--card); padding: 1rem; border-radius: 10px;
  border: 1px solid var(--line); margin-bottom: 1rem;
}
.filters input[type="search"], .filters input[type="text"],
.filters input[type="number"], .filters select {
  flex: 1 1 160px; min-width: 130px;
  padding: .55rem .7rem; border: 1px solid var(--line); border-radius: 8px;
  font-size: .95rem; background: #fff; color: var(--ink);
}
.filters input[type="number"] { flex: 1 1 120px; min-width: 110px; }
.filters .check { display: flex; align-items: center; gap: .35rem; font-size: .9rem; color: var(--muted); }
.period-ctl { display: inline-flex; align-items: center; gap: .35rem; font-size: .82rem; color: var(--muted); white-space: nowrap; }
.period-ctl input[type="month"] {
  padding: .45rem .5rem; border: 1px solid var(--line); border-radius: 8px;
  font-size: .85rem; background: #fff; color: var(--ink);
}
.filters button {
  padding: .55rem 1.1rem; border: 0; border-radius: 8px;
  background: var(--accent); color: #fff; font-weight: 600; cursor: pointer;
}
.filters button:hover { background: #1d4ed8; }
.filters .reset { background: #e5e7eb; color: var(--ink); }
.filters .reset:hover { background: #d1d5db; }
.filters .cnt { color: var(--accent); font-weight: 600; }
.filters .check.disabled { opacity: .45; cursor: not-allowed; }
.filters .check.disabled .cnt { color: var(--muted); }

/* --- Menu déroulant financeurs (select à cases à cocher) --- */
.dropdown { position: relative; display: inline-block; }
.dropdown-btn {
  padding: .55rem .7rem; border: 1px solid var(--line); border-radius: 8px;
  background: #fff; cursor: pointer; font-size: .95rem; color: var(--ink); white-space: nowrap;
}
.dropdown-btn:hover { background: var(--bg); }
.dropdown-panel {
  position: absolute; z-index: 30; top: calc(100% + 4px); left: 0; min-width: 230px;
  background: var(--card); border: 1px solid var(--line); border-radius: 8px;
  box-shadow: 0 6px 20px rgba(0,0,0,.12); padding: .4rem; display: grid; gap: .1rem;
}
.dropdown-panel[hidden] { display: none; }   /* sinon `display:grid` écrase l'attribut hidden */
.dropdown-panel label {
  display: flex; align-items: center; gap: .5rem; padding: .4rem .55rem;
  border-radius: 6px; cursor: pointer; font-size: .9rem;
}
.dropdown-panel label:hover { background: var(--bg); }
.dropdown-panel .f-fin-cnt { margin-left: auto; color: var(--muted); font-size: .8rem; }

/* --- Stats --- */
.stats { display: flex; flex-wrap: wrap; gap: .5rem; margin-bottom: .8rem; }
.stat-pill {
  background: var(--card); border: 1px solid var(--line); border-radius: 999px;
  padding: .3rem .8rem; font-size: .82rem; color: var(--muted);
}
.stat-pill strong { color: var(--ink); }

.meta { color: var(--muted); font-size: .88rem; margin-bottom: .6rem; }

/* --- Légende (explication des statuts) --- */
.legend {
  background: var(--card); border: 1px solid var(--line); border-radius: 10px;
  margin-bottom: .8rem; padding: .2rem .9rem; font-size: .9rem;
}
.legend summary { cursor: pointer; font-weight: 600; color: var(--accent); padding: .55rem 0; }
.legend-body { padding: .2rem 0 .7rem; }
.legend-body p { margin: .5rem 0; }
.legend-h { font-weight: 700; color: var(--ink); margin: 1.1rem 0 .25rem; font-size: .95rem; }

/* Liste des statuts : badge coloré + explication alignés */
.legend-statuts { list-style: none; padding: 0; margin: .6rem 0; display: grid; gap: .55rem; }
.legend-statuts > li { display: flex; flex-wrap: wrap; align-items: center; gap: .4rem .6rem; }
.legend-statuts > li > span:last-child { flex: 1 1 280px; color: var(--muted); }
.legend-statuts .statut { white-space: nowrap; }

/* Listes provenance / fiabilité : puces classiques */
.legend-src, .legend-rel { list-style: disc; padding-left: 1.25rem; margin: .5rem 0; }
.legend-src li, .legend-rel li { margin: .4rem 0; }
.tag-real, .tag-calc {
  display: inline-block; font-size: .66rem; font-weight: 700; letter-spacing: .03em;
  padding: .08rem .42rem; border-radius: 4px; margin-right: .35rem;
}
.tag-real { background: var(--green-bg); color: var(--green); }
.tag-calc { background: var(--amber-bg); color: var(--amber); }
.legend-note { color: var(--muted); font-style: italic; font-size: .85rem; margin-top: .8rem; }

/* --- Barre d'outils résultats + bascule de vue --- */
.results-toolbar {
  display: flex; justify-content: space-between; align-items: center;
  gap: .6rem; flex-wrap: wrap; margin-bottom: .6rem;
}
.view-toggle { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.view-toggle button {
  border: 0; background: var(--card); padding: .4rem .85rem; cursor: pointer;
  font-size: .85rem; color: var(--muted);
}
.view-toggle button.active { background: var(--accent); color: #fff; }
.toolbar-left, .toolbar-right { display: inline-flex; align-items: center; gap: .8rem; flex-wrap: wrap; }
.preset-btn {
  border: 1px solid var(--green); background: var(--green-bg); color: var(--green);
  padding: .4rem .8rem; border-radius: 8px; cursor: pointer; font-size: .85rem; font-weight: 600;
}
.preset-btn:hover { background: #bbf7d0; }

/* --- Synthèse (accueil) --- */
#home-link { cursor: pointer; }
.synth-head { margin: .3rem 0 1.1rem; }
.synth-head h2 { margin: 0 0 .2rem; }
.synth-head p { color: var(--muted); font-size: .92rem; margin: 0; }
.link-btn { background: none; border: 0; color: var(--accent); cursor: pointer; font-size: .92rem; font-weight: 600; }
.link-btn:hover { text-decoration: underline; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: .8rem; margin-bottom: 1.3rem; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 1rem; text-align: center; }
.kpi.green { border-color: var(--green); background: var(--green-bg); }
.kpi-n { font-size: 1.8rem; font-weight: 700; color: var(--ink); }
.kpi.green .kpi-n { color: var(--green); }
.kpi-l { font-size: .82rem; color: var(--muted); margin-top: .2rem; }
.synth-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(290px, 1fr)); gap: 1rem; }
.synth-card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 1rem; display: flex; flex-direction: column; gap: .6rem; }
.synth-card-h { display: flex; gap: .6rem; align-items: flex-start; }
.synth-ico { font-size: 1.5rem; line-height: 1; }
.synth-card-t { font-weight: 700; }
.synth-card-s { font-size: .82rem; color: var(--muted); }
.synth-count { font-size: 1.3rem; font-weight: 700; color: var(--accent); }
.synth-preview { display: grid; gap: .3rem; }
.synth-row { display: flex; justify-content: space-between; gap: .5rem; padding: .35rem .5rem; border-radius: 6px; background: var(--bg); cursor: pointer; font-size: .85rem; }
.synth-row:hover { background: #eef4ff; }
.synth-titre { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 62%; }
.synth-meta { color: var(--muted); white-space: nowrap; }
.preset-btn.full { width: 100%; text-align: center; margin-top: auto; }
.sort-ctl { font-size: .85rem; color: var(--muted); display: inline-flex; align-items: center; gap: .35rem; }
.sort-ctl select {
  padding: .35rem .5rem; border: 1px solid var(--line); border-radius: 6px;
  background: var(--card); font-size: .85rem; color: var(--ink); cursor: pointer;
}

/* --- Résultats --- */
.results { display: grid; gap: .8rem; }
body.table-mode .results { display: block; }   /* le tableau gère sa propre largeur */

/* --- Vue tableau dense, pleine largeur (full-bleed hors du conteneur centré) --- */
.table-wrap {
  width: 100%;
  overflow-x: auto;                 /* défilement horizontal si trop étroit */
}
table.grid {
  width: 100%; min-width: 1000px; border-collapse: collapse;
  background: var(--card); border: 1px solid var(--line); border-radius: 8px;
  font-size: .85rem; overflow: hidden;
}
table.grid th, table.grid td {
  padding: .5rem .65rem; border-bottom: 1px solid var(--line);
  text-align: left; vertical-align: middle;
}
table.grid thead th {
  position: sticky; top: 0; z-index: 1; background: var(--gray-bg);
  font-size: .72rem; text-transform: uppercase; letter-spacing: .02em; color: var(--muted);
}
table.grid th.sortable { cursor: pointer; user-select: none; white-space: nowrap; }
table.grid th.sortable:hover { background: #e2e8f0; color: var(--ink); }
table.grid th.sorted { color: var(--accent); }
table.grid .sort-ind { opacity: .35; font-size: .7rem; }
table.grid th.sorted .sort-ind { opacity: 1; }
table.grid tbody tr { cursor: pointer; }
table.grid tbody tr:nth-child(even) { background: #fafbfd; }
table.grid tbody tr:hover { background: #eef4ff; }
table.grid td.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.grid td.t-titre { font-weight: 600; min-width: 240px; max-width: 360px; }
table.grid td.t-org { color: var(--muted); max-width: 200px; }
table.grid .badges { margin: 0; gap: .25rem; }
table.grid .badge { font-size: .68rem; padding: .12rem .4rem; }
table.grid .statut { font-size: .72rem; white-space: nowrap; }
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: 10px;
  padding: 1rem; cursor: pointer; transition: box-shadow .15s, transform .15s;
}
.card:hover { box-shadow: 0 4px 14px rgba(0,0,0,.08); transform: translateY(-1px); }
.card h3 { margin: 0 0 .3rem; font-size: 1.05rem; }
.card .org { color: var(--muted); font-size: .9rem; margin: 0 0 .5rem; }
.card .loc { font-size: .85rem; color: var(--muted); }
.card .price { float: right; font-weight: 700; color: var(--ink); }

/* --- Badges --- */
.badges { display: flex; flex-wrap: wrap; gap: .35rem; margin: .6rem 0 .2rem; }
.badge {
  font-size: .75rem; font-weight: 600; padding: .2rem .55rem; border-radius: 6px;
  background: var(--gray-bg); color: var(--ink);
}
.badge.cpf { background: #dbeafe; color: #1e40af; }
.badge.region { background: #ede9fe; color: #5b21b6; }
.badge.ft { background: #ffedd5; color: #9a3412; }
.badge.emp { background: #f0fdf4; color: #166534; }
.badge.opco { background: #cffafe; color: #155e75; }
.badge.etat { background: #e2e8f0; color: #334155; }
.badge.cec { background: #fce7f3; color: #9d174d; }
.badge.zero { background: var(--green); color: #fff; }   /* "0 € région probable" */

.statut { display: inline-block; font-size: .78rem; font-weight: 600; padding: .25rem .6rem; border-radius: 6px; margin-top: .5rem; }
.statut.s-100 { background: var(--green-bg); color: var(--green); }
.statut.s-abond { background: var(--amber-bg); color: var(--amber); }
.statut.s-reste { background: var(--red-bg); color: var(--red); }
.statut.s-verif { background: var(--gray-bg); color: var(--muted); }

/* --- Pagination --- */
.pagination {
  display: flex; justify-content: center; align-items: center;
  gap: 1.4rem; flex-wrap: wrap; margin: 1.4rem 0;
}
.pg-nav { display: inline-flex; gap: .25rem; flex-wrap: wrap; align-items: center; }
.pg-btn {
  min-width: 2.2rem; padding: .4rem .55rem; border: 1px solid var(--line);
  border-radius: 6px; background: var(--card); cursor: pointer; font-size: .9rem;
  color: var(--ink); text-align: center;
}
.pg-btn:hover:not(:disabled):not(.active) { background: var(--bg); }
.pg-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); font-weight: 600; }
.pg-btn:disabled { opacity: .4; cursor: default; }
.pg-ellipsis { padding: 0 .15rem; color: var(--muted); align-self: center; }
.pg-jump, .pg-perpage {
  display: inline-flex; align-items: center; gap: .4rem;
  font-size: .88rem; color: var(--muted);
}
.pg-jump input {
  width: 4.5rem; padding: .35rem .5rem; border: 1px solid var(--line);
  border-radius: 6px; font-size: .9rem;
}
.pg-jump button, .pg-perpage select {
  padding: .35rem .6rem; border: 1px solid var(--line); border-radius: 6px;
  background: var(--card); cursor: pointer; font-size: .88rem; color: var(--ink);
}

/* --- Détail --- */
.back { background: none; border: 0; color: var(--accent); cursor: pointer; font-size: .95rem; margin-bottom: 1rem; }
.detail-card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 1.5rem; }
.detail-card h2 { margin-top: 0; }
.detail-card .org { color: var(--muted); }
.detail-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: .6rem; margin: 1rem 0; }
.detail-grid .item { background: var(--bg); border-radius: 8px; padding: .6rem .8rem; }
.detail-grid .item .k { font-size: .75rem; color: var(--muted); text-transform: uppercase; }
.detail-grid .item .v { font-weight: 600; }

h4 { margin: 1.4rem 0 .5rem; border-bottom: 1px solid var(--line); padding-bottom: .3rem; }
table.financeurs { width: 100%; border-collapse: collapse; font-size: .92rem; }
table.financeurs th, table.financeurs td { text-align: left; padding: .5rem; border-bottom: 1px solid var(--line); }
table.financeurs td.amount { text-align: right; font-variant-numeric: tabular-nums; }

.abond-list { list-style: none; padding: 0; }
.abond-list li { padding: .4rem 0; border-bottom: 1px solid var(--line); }
.yes { color: var(--green); font-weight: 600; }
.no { color: var(--muted); }

.footer { text-align: center; color: var(--muted); font-size: .8rem; padding: 1.5rem 1rem; }
.empty { text-align: center; color: var(--muted); padding: 2rem; }

@media (max-width: 600px) {
  .filters input, .filters button { flex: 1 1 100%; }
  .card .price { float: none; display: block; margin-top: .3rem; }
}
