:root {
  --bg: #f4f3ef;
  --surface: #fcfcfb;
  --surface-2: #ecebe5;
  --border: #dcdad2;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #7a7973;
  --brand: #17613f;          /* vert institutionnel */
  --brand-ink: #ffffff;
  --brand-soft: #e2efe7;
  --accent: #d9661f;         /* orange */
  --chart: #2a78d6;          /* série unique des graphiques */
  --warn-bg: #fff3d6;
  --warn-ink: #7a4b00;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 2px 8px rgba(0,0,0,.04);
  --font: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121211; --surface: #1a1a19; --surface-2: #242422; --border: #34332f;
    --text: #ffffff; --text-2: #c3c2b7; --muted: #8f8e86;
    --brand: #3fa877; --brand-ink: #08130d; --brand-soft: #1d3328;
    --accent: #ef8a4a; --chart: #3987e5; --warn-bg: #3a2c0b; --warn-ink: #f5cf7a;
    --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #121211; --surface: #1a1a19; --surface-2: #242422; --border: #34332f;
  --text: #ffffff; --text-2: #c3c2b7; --muted: #8f8e86;
  --brand: #3fa877; --brand-ink: #08130d; --brand-soft: #1d3328;
  --accent: #ef8a4a; --chart: #3987e5; --warn-bg: #3a2c0b; --warn-ink: #f5cf7a;
  --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 15px/1.45 var(--font); -webkit-tap-highlight-color: transparent; }
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; cursor: pointer; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
.muted { color: var(--muted); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------- En-tête ---------- */
.topbar { position: sticky; top: 0; z-index: 20; background: var(--brand); color: var(--brand-ink);
  display: flex; align-items: center; gap: 12px; padding: 10px 16px; }
.topbar .logo { display: flex; align-items: center; gap: 10px; font-weight: 700; white-space: nowrap; }
.topbar .logo svg { width: 28px; height: 28px; }
.topbar .logo small { display: block; font-weight: 400; opacity: .8; font-size: 11px; }
.search { flex: 1; max-width: 520px; margin-left: auto; position: relative; }
.search input { width: 100%; border: 0; border-radius: 999px; padding: 9px 14px 9px 36px; font: inherit;
  background: rgba(255,255,255,.95); color: #111; }
.search svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); width: 16px; color: #666; }
.topnav { display: flex; gap: 4px; }
.topnav a { padding: 7px 12px; border-radius: 999px; opacity: .85; white-space: nowrap; }
.topnav a.on, .topnav a:hover { background: rgba(255,255,255,.18); opacity: 1; }
.icon-btn { background: transparent; border: 0; padding: 6px; border-radius: 8px; display: grid; place-items: center; }
.icon-btn:hover { background: rgba(255,255,255,.15); }
.icon-btn svg { width: 20px; height: 20px; }

/* Barre du bas (mobile) */
.bottomnav { display: none; }
@media (max-width: 760px) {
  .topnav, .topbar .logo small { display: none; }
  .topbar { padding: 8px 12px; gap: 8px; }
  .topbar .logo span { display: none; }
  .bottomnav { display: grid; grid-template-columns: repeat(4, 1fr); position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
    background: var(--surface); border-top: 1px solid var(--border); padding-bottom: env(safe-area-inset-bottom); }
  .bottomnav a { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 0 7px; font-size: 11px; color: var(--muted); }
  .bottomnav a.on { color: var(--brand); font-weight: 600; }
  .bottomnav svg { width: 22px; height: 22px; }
  main { padding-bottom: 84px !important; }
}

main { max-width: 1200px; margin: 0 auto; padding: 20px 16px 40px; }
.crumbs { font-size: 13px; color: var(--muted); margin-bottom: 8px; display: flex; flex-wrap: wrap; gap: 6px; }
.crumbs a:hover { color: var(--brand); text-decoration: underline; }
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 8px 16px; margin-bottom: 16px; }
.page-head h1 { font-size: 24px; }
.page-head .sub { color: var(--text-2); }
section { margin-top: 26px; }
section > h2 { font-size: 17px; margin-bottom: 10px; display: flex; align-items: baseline; gap: 8px; }
section > h2 .muted { font-size: 13px; font-weight: 400; }

/* ---------- Tuiles ---------- */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.tile .v { font-size: 28px; font-weight: 700; font-variant-numeric: tabular-nums; }
.tile .l { color: var(--text-2); font-size: 13px; }
.alert { display: flex; gap: 10px; align-items: center; background: var(--warn-bg); color: var(--warn-ink);
  border-radius: var(--radius); padding: 10px 14px; margin-top: 14px; font-size: 14px; }
.alert a { text-decoration: underline; font-weight: 600; }

/* ---------- Cartes de catégories / unités ---------- */
.cats { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.cat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px;
  box-shadow: var(--shadow); display: flex; gap: 12px; align-items: center; transition: border-color .15s; }
.cat:hover { border-color: var(--brand); }
.cat .ic { width: 40px; height: 40px; border-radius: 10px; background: var(--brand-soft); color: var(--brand);
  display: grid; place-items: center; flex: none; }
.cat .ic svg { width: 22px; height: 22px; }
.cat b { display: block; font-size: 14px; }
.cat .muted { font-size: 12.5px; }
.cat.empty { opacity: .55; }

/* ---------- Grille d'événements ---------- */
.events { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; }
.ev { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden;
  box-shadow: var(--shadow); display: flex; flex-direction: column; transition: transform .15s, border-color .15s; }
.ev:hover { transform: translateY(-2px); border-color: var(--brand); }
.ev .cover { aspect-ratio: 16/10; background: var(--surface-2); display: grid; place-items: center; color: var(--muted); overflow: hidden; }
.ev .cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.ev .cover svg { width: 36px; height: 36px; opacity: .6; }
.ev .body { padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 4px; flex: 1; }
.ev .date { font-size: 12.5px; color: var(--accent); font-weight: 600; }
.ev .t { font-weight: 600; font-size: 14px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.ev .meta { font-size: 12.5px; color: var(--muted); margin-top: auto; display: flex; gap: 10px; flex-wrap: wrap; }
.ev .meta span { display: inline-flex; align-items: center; gap: 3px; }
.ev .meta svg { width: 13px; height: 13px; }
.badge { display: inline-block; font-size: 11.5px; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--text-2); }
.badge.warn { background: var(--warn-bg); color: var(--warn-ink); }

/* Liste compacte (accueil, chronologie) */
.list { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.row { display: flex; align-items: center; gap: 12px; padding: 10px 14px; border-top: 1px solid var(--border); }
.row:first-child { border-top: 0; }
.row:hover { background: var(--surface-2); }
.row .thumb { width: 52px; height: 52px; border-radius: 8px; overflow: hidden; background: var(--surface-2); flex: none; display: grid; place-items: center; color: var(--muted); }
.row .thumb img { width: 100%; height: 100%; object-fit: cover; }
.row .thumb svg { width: 22px; height: 22px; }
.row .main { min-width: 0; flex: 1; }
.row .main b { display: block; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .main .muted { font-size: 12.5px; }
.row .d { font-size: 12.5px; color: var(--text-2); white-space: nowrap; text-align: right; }

/* ---------- Filtres ---------- */
.filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; align-items: center; }
.chip { border: 1px solid var(--border); background: var(--surface); border-radius: 999px; padding: 5px 12px; font-size: 13px; }
.chip.on { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
select.chip { padding-right: 8px; }

/* ---------- Page événement ---------- */
.ev-head { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); }
.ev-head h1 { font-size: 22px; margin: 4px 0 8px; }
.ev-head .facts { display: flex; flex-wrap: wrap; gap: 6px 18px; color: var(--text-2); font-size: 14px; }
.ev-head .facts b { color: var(--text); font-weight: 600; }
.ev-nav { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border); background: var(--surface); border-radius: 8px; padding: 6px 12px; font-size: 13.5px; }
.btn:hover { border-color: var(--brand); color: var(--brand); }
.btn[aria-disabled="true"] { opacity: .4; pointer-events: none; }
.btn svg { width: 15px; height: 15px; }
.docs { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 10px; }
.doc { display: flex; gap: 10px; align-items: center; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; }
.doc:hover { border-color: var(--brand); }
.doc .ext { width: 40px; height: 40px; border-radius: 8px; display: grid; place-items: center; font-size: 11px; font-weight: 700; flex: none; color: #fff; background: #7a7973; }
.doc .ext.pdf { background: #c62828; } .doc .ext.docx, .doc .ext.doc { background: #1e5bb8; } .doc .ext.pptx, .doc .ext.ppt { background: #c2541b; } .doc .ext.mp4 { background: #4a3aa7; }
.doc .n { font-size: 13.5px; font-weight: 600; word-break: break-word; }
.doc .muted { font-size: 12px; }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 6px; }
@media (max-width: 500px) { .gallery { grid-template-columns: repeat(3, 1fr); gap: 3px; } }
.gallery button { border: 0; padding: 0; aspect-ratio: 1; background: var(--surface-2); border-radius: 6px; overflow: hidden; }
.gallery img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform .2s; }
.gallery button:hover img { transform: scale(1.04); }
video { width: 100%; max-height: 70vh; background: #000; border-radius: var(--radius); }

/* Visionneuse */
.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.94); z-index: 50; display: flex; flex-direction: column; color: #fff; }
.lightbox .bar { display: flex; align-items: center; gap: 10px; padding: 10px 14px; font-size: 13px; }
.lightbox .bar .n { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; opacity: .85; }
.lightbox .stage { flex: 1; display: grid; place-items: center; min-height: 0; position: relative; touch-action: pan-y; }
.lightbox .stage img { max-width: 100%; max-height: 100%; object-fit: contain; user-select: none; }
.lightbox .nav { position: absolute; top: 50%; transform: translateY(-50%); background: rgba(255,255,255,.12); border: 0; color: #fff;
  width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; }
.lightbox .nav:hover { background: rgba(255,255,255,.25); }
.lightbox .prev { left: 12px; } .lightbox .next { right: 12px; }
.lightbox .icon-btn { color: #fff; }
@media (max-width: 760px) { .lightbox .nav { display: none; } }

/* ---------- Graphiques (une série = une teinte, pas de légende) ---------- */
.charts { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 14px; }
@media (max-width: 420px) { .charts { grid-template-columns: 1fr; } }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); min-width: 0; }
.card h3 { font-size: 14.5px; margin-bottom: 12px; }
.card h3 .muted { font-weight: 400; font-size: 12.5px; }
.hbars { display: grid; grid-template-columns: minmax(90px, max-content) 1fr auto; gap: 7px 10px; align-items: center; font-size: 13px; }
.hbars .lab { color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 190px; }
.hbars .lab a:hover { color: var(--brand); text-decoration: underline; }
.hbars .track { height: 14px; position: relative; }
.hbars .bar { height: 100%; background: var(--chart); border-radius: 0 4px 4px 0; min-width: 2px; }
.hbars .val { font-variant-numeric: tabular-nums; color: var(--text); font-weight: 600; text-align: right; }
.hbars .hit { display: contents; cursor: pointer; }
.hbars .hit:hover .bar { filter: brightness(1.12); }
.cols { display: flex; align-items: flex-end; gap: 6px; height: 170px; border-bottom: 1px solid var(--border); padding-top: 18px; }
.cols .c { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; position: relative; cursor: pointer; }
.cols .c .bar { width: 100%; max-width: 38px; background: var(--chart); border-radius: 4px 4px 0 0; min-height: 2px; }
.cols .c .v { font-size: 12px; font-weight: 600; margin-bottom: 3px; font-variant-numeric: tabular-nums; }
.cols .c:hover .bar { filter: brightness(1.12); }
.cols-x { display: flex; gap: 6px; margin-top: 5px; }
.cols-x span { flex: 1; text-align: center; font-size: 11.5px; color: var(--muted); }
.heat { width: 100%; border-collapse: separate; border-spacing: 2px; font-size: 12px; }
.heat th { font-weight: 500; color: var(--muted); text-align: center; padding: 2px; }
.heat th.u { text-align: left; color: var(--text-2); white-space: nowrap; max-width: 180px; overflow: hidden; text-overflow: ellipsis; }
.heat td { text-align: center; height: 28px; min-width: 28px; border-radius: 4px; font-variant-numeric: tabular-nums; cursor: default; }
.heat td.z { background: var(--surface-2); color: transparent; }
.scroll-x { overflow-x: auto; }
.tip { position: fixed; z-index: 60; pointer-events: none; background: var(--text); color: var(--surface); padding: 6px 9px; border-radius: 6px; font-size: 12.5px; max-width: 260px; box-shadow: 0 4px 14px rgba(0,0,0,.2); }
.tablev { width: 100%; border-collapse: collapse; font-size: 13px; }
.tablev th, .tablev td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--border); }
.tablev td.n { text-align: right; font-variant-numeric: tabular-nums; }
details.tbl summary { cursor: pointer; color: var(--text-2); font-size: 13px; margin-top: 10px; }

.empty-state { text-align: center; padding: 50px 16px; color: var(--muted); }
.empty-state svg { width: 44px; height: 44px; opacity: .5; }
.loading { padding: 40px; text-align: center; color: var(--muted); }
.foot { margin-top: 36px; font-size: 12px; color: var(--muted); display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.foot button { background: none; border: 1px solid var(--border); border-radius: 6px; padding: 3px 8px; font-size: 12px; color: var(--text-2); }

/* Connexion */
body.login { display: grid; place-items: center; min-height: 100vh; background: var(--brand); padding: 16px; }
.login-card { background: var(--surface); padding: 28px; border-radius: 16px; width: 100%; max-width: 340px; display: grid; gap: 12px; text-align: center; }
.login-card input { font: inherit; font-size: 22px; letter-spacing: 6px; text-align: center; padding: 10px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); color: var(--text); }
.login-card button { background: var(--brand); color: var(--brand-ink); border: 0; padding: 11px; border-radius: 10px; font-weight: 600; }
.login-card .err { color: #c62828; margin: 0; }
