/* Thème de la plateforme (v1.6.1) — au-dessus de Pico.css : barre latérale, cartes, tableaux, pastilles,
   clair / sombre automatique. Aucune ressource externe. */

:root:not([data-theme=dark]), [data-theme=light] {
  --bg: #f4f6fb; --surface: #ffffff; --surface-2: #f8f9fc; --line: #e6e9f2; --text: #1d2433; --muted: #667085;
  --accent: #4f46e5; --accent-2: #4338ca; --accent-soft: #eef0ff; --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
  --ok: #16865a; --mid: #b26b00; --low: #d0342c; --action: #4f46e5;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme=light]) {
    --bg: #0d111a; --surface: #151b27; --surface-2: #1a2130; --line: #263045; --text: #e6e9f2; --muted: #98a2b8;
    --accent: #8b8cf7; --accent-2: #a5a6ff; --accent-soft: rgba(139, 140, 247, .14); --shadow: 0 1px 2px rgba(0, 0, 0, .4);
    --ok: #3fc98a; --mid: #f0b14a; --low: #ff7469; --action: #8b8cf7;
  }
}

/* sélecteur renforcé : Pico déclare ses couleurs sur :root:not([data-theme=dark]) (spécificité supérieure à :root) */
html:root:not([data-th-a]):not([data-th-b]) {
  --pico-font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --pico-font-size: 15px; --pico-line-height: 1.5; --pico-border-radius: .6rem;
  --pico-background-color: var(--bg); --pico-color: var(--text); --pico-muted-color: var(--muted);
  --pico-muted-border-color: var(--line); --pico-card-background-color: var(--surface);
  --pico-card-sectioning-background-color: var(--surface-2); --pico-card-box-shadow: var(--shadow);
  --pico-primary: var(--accent); --pico-primary-hover: var(--accent-2); --pico-primary-background: var(--accent);
  --pico-primary-hover-background: var(--accent-2); --pico-primary-border: var(--accent);
  --pico-primary-hover-border: var(--accent-2); --pico-primary-underline: color-mix(in srgb, var(--accent) 45%, transparent);
  --pico-primary-focus: color-mix(in srgb, var(--accent) 25%, transparent);
  --pico-form-element-background-color: var(--surface); --pico-form-element-border-color: var(--line);
  --pico-form-element-focus-color: var(--accent); --pico-spacing: 1rem; --pico-typography-spacing-vertical: .9rem;
  --pico-h1-color: var(--text); --pico-h2-color: var(--text); --pico-h3-color: var(--text); --pico-h4-color: var(--text);
  --side: 248px;
}
html { background: var(--bg); }
body { background: var(--bg); color: var(--text); -webkit-font-smoothing: antialiased; }
a { text-decoration: none; }
a:hover { text-decoration: underline; }

/* --- titres et textes -------------------------------------------------------------------------------------------- */
h1 { font-size: 1.65rem; letter-spacing: -.02em; margin-bottom: .4rem; }
h2 { font-size: 1.25rem; letter-spacing: -.01em; margin-top: 1.6rem; }
h3 { font-size: 1.05rem; }
h4 { font-size: .95rem; color: var(--muted); }
hgroup { margin-bottom: 1.2rem; }
hgroup > p, hgroup > :not(:first-child) { color: var(--muted); font-size: .95rem; }
.sub { color: var(--muted); font-size: .82rem; }

/* --- disposition : barre latérale -------------------------------------------------------------------------------- */
.nav-toggle { position: fixed; top: 0; left: 0; opacity: 0; pointer-events: none; margin: 0; }
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--side); z-index: 40; display: flex; flex-direction: column;
  background: var(--surface); border-right: 1px solid var(--line); padding: 1rem .75rem; overflow-y: auto;
}
.sidebar .brand, .topbar .brand { display: flex; align-items: center; gap: .55rem; font-weight: 700; color: var(--text);
  font-size: 1.05rem; letter-spacing: -.01em; padding: .25rem .5rem .9rem; }
.sidebar .brand .ico, .topbar .brand .ico { color: #fff; background: var(--accent); border-radius: .55rem; padding: 4px;
  width: 28px; height: 28px; }
.sidebar .brand:hover, .topbar .brand:hover { text-decoration: none; }
.sidebar nav { display: block; }
.sidebar nav ul { display: block; margin: 0 0 .6rem; padding: 0; }
.sidebar nav li { display: block; list-style: none; padding: 0; margin: 0; }
.nav-title { margin: .7rem .6rem .25rem; font-size: .68rem; font-weight: 700; letter-spacing: .08em;
  text-transform: uppercase; color: var(--muted); }
.sidebar nav a { display: flex; align-items: center; gap: .65rem; padding: .48rem .65rem; margin: 1px 0;
  border-radius: .55rem; color: var(--text); font-size: .92rem; font-weight: 500; line-height: 1.2; }
.sidebar nav a .ico { color: var(--muted); flex: none; }
.sidebar nav a:hover { background: var(--surface-2); text-decoration: none; }
.sidebar nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 650; text-decoration: none; }
.sidebar nav a.active .ico { color: var(--accent); }
.sidebar nav a .count, .top-count span { margin-left: auto; min-width: 1.4rem; padding: 0 .4rem; border-radius: 999px;
  background: var(--low); color: #fff; font-size: .72rem; font-weight: 700; text-align: center; line-height: 1.35rem; }
.sidebar-foot { margin-top: auto; padding: .8rem .5rem 0; border-top: 1px solid var(--line); display: grid; gap: .35rem; }
.sidebar-foot .who { font-size: .8rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-foot form { margin: 0; }
.sidebar-foot .logout { display: flex; align-items: center; gap: .5rem; width: 100%; padding: .45rem .6rem; margin: 0;
  background: transparent; border: 1px solid var(--line); color: var(--text); font-size: .88rem; font-weight: 500; }
.sidebar-foot .logout:hover { background: var(--surface-2); }
.sidebar-foot small { color: var(--muted); font-size: .72rem; }
.topbar { display: none; }
.nav-overlay { display: none !important; position: fixed; inset: 0; margin: 0; } /* hors du flux (marge des label Pico) */

body.app .shell { margin-left: var(--side); min-height: 100vh; }
body.app main.page { max-width: 1240px; padding: 1.6rem 2rem 3rem; margin: 0 auto; }
body.public main.page { max-width: 1100px; }

/* --- cartes ------------------------------------------------------------------------------------------------------- */
article { border: 1px solid var(--line); border-radius: .9rem; box-shadow: var(--shadow); padding: 1.15rem 1.3rem;
  margin-bottom: 1.1rem; background: var(--surface); }
article > h3:first-child, article > header:first-child { margin-top: 0; }
details summary { color: var(--text); }

/* --- tableaux ----------------------------------------------------------------------------------------------------- */
.tbl { background: var(--surface); border: 1px solid var(--line); border-radius: .8rem; box-shadow: var(--shadow);
  margin-bottom: 1.1rem; }
article .tbl { box-shadow: none; }
.tbl table { margin: 0; }
table { --pico-table-border-color: var(--line); }
th, td { border-bottom: 1px solid var(--line); background: transparent; }
thead th { font-size: .72rem; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--muted);
  background: var(--surface-2); }
.tbl thead th:first-child { border-top-left-radius: .8rem; }
.tbl thead th:last-child { border-top-right-radius: .8rem; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: color-mix(in srgb, var(--accent) 4%, transparent); }

/* --- boutons et champs -------------------------------------------------------------------------------------------- */
button, [role=button], input[type=submit] { border-radius: .6rem; font-weight: 600; font-size: .9rem;
  padding: .55rem 1rem; box-shadow: none; }
button.outline, [role=button].outline { background: var(--surface); }
button.secondary:not(.outline) { background: var(--text); border-color: var(--text); color: var(--surface); }
.inline button { padding: .3rem .75rem; font-size: .84rem; }
input:not([type=checkbox]):not([type=radio]), select, textarea { border-radius: .55rem; font-size: .92rem; }
label { font-size: .9rem; font-weight: 500; }

/* --- pastilles, alertes, indicateurs ------------------------------------------------------------------------------ */
.pill { border: 0; padding: .14rem .55rem; font-size: .74rem; font-weight: 650;
  background: color-mix(in srgb, currentColor 13%, transparent); }
.pill.muted { border: 1px dashed currentColor; background: transparent; }
.badge { background: var(--low); font-weight: 700; }
.flash { background: color-mix(in srgb, var(--ok) 9%, var(--surface)); border: 1px solid color-mix(in srgb, var(--ok) 30%, transparent);
  border-left: 4px solid var(--ok); border-radius: .7rem; color: var(--text); padding: .8rem 1rem; }
.flash.error, .flash .error, .error.flash { background: color-mix(in srgb, var(--low) 8%, var(--surface));
  border-color: color-mix(in srgb, var(--low) 30%, transparent); border-left-color: var(--low); color: var(--text); }
.kpis { gap: .9rem; }
.kpi { border: 1px solid var(--line); border-radius: .9rem; box-shadow: var(--shadow); padding: 1rem 1.1rem;
  background: var(--surface); position: relative; overflow: hidden; }
.kpi::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 4px; background: var(--accent); opacity: .85; }
.kpi b { font-size: 1.6rem; letter-spacing: -.02em; }
.kpi span { font-size: .82rem; }
.bar { background: var(--line); }
progress { accent-color: var(--accent); }
.rule { background: var(--surface); border-radius: .6rem; border: 1px solid var(--line); border-left-width: 4px; }
.gates i { height: .55rem; border-radius: 3px; }

/* --- pages publiques (connexion, double authentification) --------------------------------------------------------- */
body.public { background: radial-gradient(1200px 500px at 50% -10%, var(--accent-soft), transparent), var(--bg); }
body.public article { max-width: 420px; margin: 4rem auto; padding: 2rem; }

/* --- tablette et téléphone : tiroir + barre du haut + onglets ------------------------------------------------------ */
@media (max-width: 1023px) {
  body.app .shell { margin-left: 0; }
  body.app main.page { padding: 1rem 1rem 5.5rem; }
  .sidebar { transform: translateX(-100%); transition: transform .2s ease; box-shadow: none; }
  .nav-toggle:checked ~ .sidebar { transform: none; box-shadow: 0 10px 40px rgba(0, 0, 0, .25); }
  .nav-toggle:checked ~ .nav-overlay { display: block !important; z-index: 30; background: rgba(13, 17, 26, .45); }
  .topbar { display: flex; align-items: center; gap: .6rem; position: sticky; top: 0; z-index: 20; height: 56px;
    padding: 0 1rem; background: color-mix(in srgb, var(--surface) 88%, transparent); backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--line); }
  .topbar .brand { padding: 0; }
  .menu-btn { display: grid; place-items: center; width: 38px; height: 38px; margin: 0 0 0 -.4rem; border-radius: .6rem;
    color: var(--text); cursor: pointer; }
  .menu-btn:hover { background: var(--surface-2); }
  .top-count { margin-left: auto; display: flex; align-items: center; gap: .35rem; color: var(--text); }
  .top-count:hover { text-decoration: none; }
  h1 { font-size: 1.4rem; }
}
@media (max-width: 768px) {
  .tabbar { background: color-mix(in srgb, var(--surface) 94%, transparent); backdrop-filter: blur(8px);
    border-top: 1px solid var(--line); }
  .tabbar a { position: relative; gap: .15rem; font-size: .68rem; font-weight: 600; color: var(--muted); }
  .tabbar a[aria-current] { color: var(--accent); }
  .tabbar .dot { position: absolute; top: -2px; left: calc(50% + 6px); min-width: 1.05rem; padding: 0 .25rem;
    border-radius: 999px; background: var(--low); color: #fff; font-size: .62rem; line-height: 1.05rem; text-align: center; }
  article { padding: 1rem; border-radius: .8rem; }
  .tbl.cards { background: transparent; border: 0; box-shadow: none; }
  .tbl.cards tr { background: var(--surface); border: 1px solid var(--line); border-radius: .8rem; padding: .7rem .8rem;
    margin-bottom: .6rem; box-shadow: var(--shadow); }
  .tbl.cards tbody tr:hover td { background: transparent; }
  .tbl.cards td[data-label] { display: flex; justify-content: space-between; align-items: baseline; gap: .8rem;
    text-align: right; }
  .tbl.cards td[data-label]::before { content: attr(data-label); color: var(--muted); font-size: .78rem;
    font-weight: 600; text-align: left; flex: none; }
  .tbl.cards td[data-label]:first-child { display: block; text-align: left; }
  .tbl.cards td[data-label]:first-child::before { content: none; }
}

/* --- graphiques (v1.7) : palette validée (bleu / orange, clair et sombre), chrome discret ---------------------------- */
:root:not([data-theme=dark]), [data-theme=light] {
  --series-1: #2a78d6; --series-2: #eb6834; --viz-surface: #ffffff; --viz-grid: #ecedf2; --viz-base: #c9ccd6;
  --viz-axis: #8a8f9c; --viz-muted: #a4a9b6; --viz-accent: #2a78d6; --delta-good: #006300; --delta-bad: #c62f2f;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme=light]) {
    --series-1: #3987e5; --series-2: #d95926; --viz-surface: #151b27; --viz-grid: #222a3b; --viz-base: #3a4459;
    --viz-axis: #8f98ab; --viz-muted: #5d677c; --viz-accent: #3987e5; --delta-good: #2fbf6a; --delta-bad: #ff7469;
  }
}
.activite { margin-bottom: 2rem; }
.activite-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin: .2rem 0 .9rem; }
.activite-head h2 { margin: 0; }
.periodes { display: inline-flex; padding: 3px; gap: 2px; background: var(--surface-2); border: 1px solid var(--line); border-radius: .65rem; }
.periodes a { padding: .3rem .8rem; border-radius: .5rem; font-size: .85rem; font-weight: 600; color: var(--muted); }
.periodes a:hover { text-decoration: none; color: var(--text); }
.periodes a[aria-current] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(200px, 100%), 1fr)); gap: .9rem; margin-bottom: 1rem; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: .9rem; box-shadow: var(--shadow);
  padding: .9rem 1rem .7rem; display: flex; flex-direction: column; gap: .15rem; min-width: 0; }
.tile-label { font-size: .8rem; color: var(--muted); font-weight: 600; }
.tile-value { font-size: 1.7rem; font-weight: 650; letter-spacing: -.02em; line-height: 1.2; }
.delta { font-size: .8rem; font-weight: 650; }
.delta.bon { color: var(--delta-good); } .delta.mauvais { color: var(--delta-bad); } .delta.neutre { color: var(--muted); font-weight: 500; }
.tile .delta + .sub { font-size: .75rem; }
.spark { margin-top: .35rem; height: 34px; }
.viz-card { margin: 0 0 1rem; background: var(--surface); border: 1px solid var(--line); border-radius: .9rem;
  box-shadow: var(--shadow); padding: 1rem 1.1rem .6rem; min-width: 0; }
.viz-card figcaption { display: flex; flex-wrap: wrap; align-items: baseline; gap: .4rem 1rem; margin-bottom: .6rem; font-size: .95rem; }
.legend { display: inline-flex; gap: 1rem; font-size: .8rem; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: .35rem; }
.legend i { display: inline-block; width: 14px; height: 2px; border-radius: 1px; }
.chart { width: 100%; min-height: 40px; }
svg.viz { display: block; overflow: visible; font-family: inherit; }
svg.viz:focus { outline: 2px solid color-mix(in srgb, var(--accent) 40%, transparent); outline-offset: 4px; border-radius: 6px; }
.viz-grid { stroke: var(--viz-grid); stroke-width: 1; }
.viz-base { stroke: var(--viz-base); stroke-width: 1; }
.viz-cross { stroke: var(--viz-axis); stroke-width: 1; }
.viz-axis { fill: var(--viz-axis); font-size: 11px; font-variant-numeric: tabular-nums; }
.viz-label { fill: var(--text); font-size: 12.5px; }
.viz-value { fill: var(--muted); font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums; }
.viz-bar { cursor: default; outline: none; }
.viz-bar:hover path, .viz-bar:focus path { filter: brightness(1.12); }
.viz-bar:focus rect { fill: color-mix(in srgb, var(--accent) 8%, transparent); }
.viz-tip { position: absolute; z-index: 60; pointer-events: none; min-width: 150px; max-width: 280px; padding: .5rem .65rem;
  background: var(--surface); color: var(--text); border: 1px solid var(--line); border-radius: .6rem;
  box-shadow: 0 6px 24px rgba(16, 24, 40, .14); font-size: .8rem; }
.viz-tip-title { color: var(--muted); font-size: .75rem; margin-bottom: .25rem; }
.viz-tip-row { display: grid; grid-template-columns: 14px auto 1fr; align-items: center; gap: .45rem; }
.viz-tip-row i { width: 12px; height: 2px; border-radius: 1px; }
.viz-tip-row b { font-variant-numeric: tabular-nums; }
.viz-tip-row span { color: var(--muted); }
.table-view { margin-top: .4rem; }
.table-view summary { font-size: .8rem; color: var(--muted); }
.viz-empty { display: grid; gap: .25rem; padding: 1.4rem; text-align: center; background: var(--surface);
  border: 1px dashed var(--line); border-radius: .9rem; margin-bottom: 1rem; }
@media (max-width: 768px) {
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .6rem; }
  .tile { padding: .7rem .75rem .55rem; }
  .tile-value { font-size: 1.3rem; }
  .tile .delta + .sub { display: none; }
  .spark { height: 28px; }
  .viz-card { padding: .8rem .8rem .5rem; }
  .activite-head { align-items: flex-start; }
}
