/* ============================================================
   ANT — Thème global
   Tout passe par les variables. Jamais de hex dans les pages.
   --primary est surchargée par la couleur de la commune (inline
   sur <html> via layout.php).
   ============================================================ */

:root {
    /* Thème CLAIR par défaut. Confort d'abord : fond adouci plutôt que blanc
       pur, texte ardoise plutôt que noir, et des gris secondaires remontés
       bien au-dessus du minimum (voir les mesures dans le CHANGELOG). */
    --bg:           #eef2f7;
    --surface:      #ffffff;
    --surface-2:    #f7f9fc;
    --border:       rgba(15,23,42,.14);
    --text:         #16202e;
    --text-muted:   #4b5768;
    --primary:      #1d4ed8;
    --primary-soft: rgba(29,78,216,.10);
    --accent:       #b45309;
    --success:      #065f46;
    --warning:      #92400e;
    --danger:       #991b1b;
    /* Encre des liens : la couleur de la commune telle quelle en thème clair,
       éclaircie en thème sombre, sinon un bleu de commune sur fond sombre
       tombe sous 3 pour 1. */
    --primary-ink:  var(--primary);
    /* Fond des boutons rouges : blanc dessus, dans les deux thèmes. */
    --danger-solid: #991b1b;
    --attention:    #f59e0b;
    --attention-ink:#a8520a;
    --radius:       12px;
    --shadow:       0 4px 24px rgba(15,23,42,.08);
}

html[data-theme="dark"] {
    --bg:           #0f172a;
    --surface:      rgba(255,255,255,.06);
    --surface-2:    rgba(255,255,255,.10);
    --border:       rgba(255,255,255,.16);
    --text:         #f1f5f9;
    --text-muted:   #a7b4c6;
    --primary-soft: rgba(29,78,216,.18);
    --accent:       #f59e0b;
    --success:      #10b981;
    --warning:      #f59e0b;
    --danger:       #f87171;
    --primary-ink:  #93b4ff;
    --primary-ink:  color-mix(in srgb, var(--primary) 40%, #ffffff);
    --danger-solid: #b91c1c;
    --attention-ink:#fbbf24;
    --shadow:       0 4px 24px rgba(0,0,0,.25);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 15px;
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--primary-ink); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3 { line-height: 1.25; margin: 0 0 .6em; }
h1 { font-size: 1.5rem; font-weight: 800; }
h2 { font-size: 1.15rem; font-weight: 700; }

/* ── Layout app ── */
.app { display: flex; min-height: 100vh; }

.sidebar {
    width: 240px;
    flex-shrink: 0;
    background: var(--surface);
    border-right: 1px solid var(--border);
    padding: 20px 14px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.sidebar .brand {
    display: flex; align-items: center; gap: 10px;
    font-weight: 800; font-size: 1.05rem;
    padding: 6px 10px 18px;
}
.sidebar .brand img { width: 34px; height: 34px; border-radius: 8px; object-fit: cover; }
.sidebar .nav-item {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 12px;
    border-radius: 10px;
    color: var(--text-muted);
    font-weight: 600;
    font-size: .92rem;
}
.sidebar .nav-item:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
/* Page courante : le libellé et l'icône prennent --text. --primary est la
   couleur de la commune, inconnue à l'écriture, et sur --primary-soft elle
   tombait à 2,03 pour 1 en thème sombre. La commune reste dite par le filet. */
.sidebar .nav-item.active {
    background: var(--primary-soft);
    color: var(--text);
    font-weight: 700;
    box-shadow: inset 3px 0 0 var(--primary);
}
.sidebar .nav-item svg { width: 18px; height: 18px; flex-shrink: 0; }
/* Bascule de thème : en haut à droite de chaque page */
.topbar { display: flex; justify-content: flex-end; margin: -10px 0 8px; }
.theme-toggle { display: inline-flex; align-items: center; gap: 8px; background: var(--surface, transparent); color: var(--text-muted); border: 1px solid var(--border); border-radius: 999px; padding: 6px 14px; font: inherit; font-size: .85rem; font-weight: 600; cursor: pointer; }
.theme-toggle:hover { color: var(--text); border-color: var(--primary); }
.theme-toggle svg { width: 16px; height: 16px; flex-shrink: 0; }
/* Déconnexion : bouton d'un formulaire POST, habillé comme un lien du menu */
.sidebar button.nav-item { background: none; border: 0; width: 100%; text-align: left; cursor: pointer; font-family: inherit; }
.sidebar .nav-group {
    font-size: .67rem; font-weight: 700; letter-spacing: .07em;
    text-transform: uppercase; color: var(--text-muted); opacity: .55;
    padding: 6px 12px 4px; margin-top: 12px;
}
.sidebar .nav-group:first-of-type { margin-top: 2px; }
.sidebar .spacer { flex: 1; }

.main { flex: 1; padding: 28px 32px; max-width: 1200px; }

/* ── Bandeau impersonation ── */
.impersonation-banner {
    background: var(--warning);
    color: #1a1a1a;
    padding: 8px 16px;
    text-align: center;
    font-weight: 700;
    font-size: .88rem;
}
.impersonation-banner a { color: #1a1a1a; text-decoration: underline; }

/* ── Composants ── */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 16px;
}

.btn {
    display: inline-flex; align-items: center; gap: 8px;
    background: var(--primary);
    color: #fff;
    border: none;
    padding: 10px 18px;
    border-radius: 10px;
    font-weight: 700;
    font-size: .92rem;
    cursor: pointer;
    text-decoration: none;
}
.btn:hover { opacity: .9; text-decoration: none; }
.btn.btn-ghost { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
.btn.btn-danger { background: var(--danger-solid); }
.btn.btn-sm { padding: 6px 12px; font-size: .84rem; }

/* ── Barres de progression (remplissage animé, pur CSS) ── */
.pbar { height: 9px; border-radius: 99px; background: var(--surface-2); overflow: hidden; margin: 4px 0; }
.pbar > span {
    display: block; height: 100%; border-radius: 99px;
    background: var(--primary); transform-origin: left;
    animation: pbar-grow .7s cubic-bezier(.4, 0, .2, 1);
}
.pbar.warn > span    { background: var(--warning); }
.pbar.success > span { background: var(--success); }
.pbar.danger > span  { background: var(--danger); }
.pbar-label { display: flex; justify-content: space-between; align-items: baseline;
    font-size: .8rem; color: var(--text-muted); margin-bottom: 3px; font-weight: 600; }
.pbar-label b { color: var(--text); font-size: .9rem; }
@keyframes pbar-grow { from { transform: scaleX(0); } }
@media (prefers-reduced-motion: reduce) { .pbar > span { animation: none; } }

.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 99px;
    font-size: .76rem;
    font-weight: 700;
}
.badge-success { background: rgba(16,185,129,.15); color: var(--success); }
.badge-warning { background: rgba(245,158,11,.15);  color: var(--warning); }
.badge-danger  { background: rgba(239,68,68,.15);   color: var(--danger); }
.badge-muted   { background: var(--surface-2);      color: var(--text-muted); }

/* ── Formulaires ── */
label { display: block; font-weight: 600; font-size: .86rem; margin-bottom: 6px; color: var(--text-muted); }
input[type=text], input[type=email], input[type=password], input[type=tel],
input[type=number], input[type=date], input[type=color], select, textarea {
    width: 100%;
    padding: 10px 12px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text);
    font-size: .94rem;
    font-family: inherit;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: 1px; }
.form-row { margin-bottom: 16px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

/* ── Tables ── */
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: .78rem; text-transform: uppercase; letter-spacing: .04em;
     color: var(--text-muted); padding: 10px 12px; border-bottom: 1px solid var(--border); }
td { padding: 12px; border-bottom: 1px solid var(--border); font-size: .92rem; }
tr:last-child td { border-bottom: none; }

/* ── Flash messages ── */
.flash { padding: 12px 16px; border-radius: 10px; margin-bottom: 18px; font-weight: 600; font-size: .9rem; }
.flash-success { background: rgba(16,185,129,.12); color: var(--success); border: 1px solid rgba(16,185,129,.3); }
.flash-error   { background: rgba(239,68,68,.12);  color: var(--danger);  border: 1px solid rgba(239,68,68,.3); }

/* ── Dashboard boîte à faire ── */
.todo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
.todo-tile {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px;
    display: flex; flex-direction: column; gap: 8px;
}
.todo-tile .count { font-size: 2rem; font-weight: 800; color: var(--primary); line-height: 1; }
.todo-tile .label { font-weight: 700; }
.todo-tile .hint  { font-size: .84rem; color: var(--text-muted); }

/* ── Tableau de bord ──
   En-tête, « À traiter » (compteurs), puis une section de tuiles par
   famille du menu. Deux colonnes dès le téléphone, davantage ensuite. */
.dash-head {
    display: flex; flex-wrap: wrap; align-items: flex-start;
    justify-content: space-between; gap: 12px; margin-bottom: 26px;
}
.dash-head h1 { margin: 0 0 4px; }
.dash-head p  { margin: 0; color: var(--text-muted); font-size: .92rem; }
.dash-visit {
    display: inline-flex; align-items: center; gap: 8px;
    padding: 9px 16px; border-radius: 999px;
    border: 1px solid var(--border); background: var(--surface);
    color: var(--text-muted); font-size: .85rem; font-weight: 600;
}
.dash-visit:hover { color: var(--primary); border-color: var(--primary); text-decoration: none; }
.dash-visit svg { width: 16px; height: 16px; flex-shrink: 0; }

.dash-sec { margin-bottom: 28px; }
.dash-sec h2 {
    font-size: .76rem; font-weight: 800; text-transform: uppercase;
    letter-spacing: .08em; color: var(--text-muted); margin: 0 0 12px;
}
.dash-empty { text-align: center; padding: 40px; color: var(--text-muted); }

/* À traiter */
.dash-todos { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; }
.dash-todo {
    position: relative; overflow: hidden;
    display: flex; flex-direction: column; gap: 6px;
    padding: 18px 18px 18px 22px;
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); color: var(--text);
    transition: border-color .12s, transform .12s;
}
.dash-todo::before {
    content: ''; position: absolute; left: 0; top: 0; bottom: 0;
    width: 4px; background: var(--attention);
}
.dash-todo:hover { border-color: var(--primary); transform: translateY(-1px); text-decoration: none; }
.dash-todo .n { font-size: 2rem; font-weight: 800; color: var(--attention-ink); line-height: 1; }
.dash-todo .t { font-weight: 700; font-size: .95rem; }
.dash-todo .h { font-size: .82rem; color: var(--text-muted); }

/* Téléphone : « À traiter » en lignes compactes, le chiffre à gauche,
   sinon sept tuiles pleine largeur repoussent les sections hors de l'écran. */
@media (max-width: 639px) {
    .dash-todos { gap: 10px; }
    .dash-todo {
        display: grid; grid-template-columns: auto 1fr;
        column-gap: 14px; row-gap: 2px; align-items: center;
        padding: 14px 14px 14px 18px;
    }
    .dash-todo .n { font-size: 1.6rem; grid-row: 1 / span 2; }
    .dash-todo .t { font-size: .9rem; }
    .dash-todo .h { font-size: .78rem; }
}

/* Tuiles des familles */
.dash-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
@media (min-width: 640px) {
    .dash-grid { grid-template-columns: repeat(auto-fill, minmax(158px, 1fr)); }
}
.dash-tile {
    position: relative; min-height: 108px;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 10px; padding: 18px 10px; text-align: center;
    background: var(--surface); border: 1px solid var(--border);
    border-radius: 14px; color: var(--text);
    transition: border-color .12s, transform .12s;
}
.dash-tile:hover { border-color: var(--primary); transform: translateY(-1px); text-decoration: none; }
.dash-tile .ic {
    width: 40px; height: 40px; border-radius: 12px;
    display: flex; align-items: center; justify-content: center;
    background: var(--primary-soft); color: var(--primary); flex-shrink: 0;
}
.dash-tile .ic svg { width: 20px; height: 20px; }
.dash-tile .l { font-size: .82rem; font-weight: 700; line-height: 1.3; }
.dash-tile .b {
    position: absolute; top: 8px; right: 8px;
    min-width: 22px; height: 22px; padding: 0 6px; border-radius: 11px;
    background: var(--attention); color: #3a2206;
    font-size: .72rem; font-weight: 800;
    display: flex; align-items: center; justify-content: center;
}
.dash-todo:focus-visible, .dash-tile:focus-visible, .dash-visit:focus-visible {
    outline: 2px solid var(--primary); outline-offset: 2px;
}

/* ── Mobile ── */
@media (max-width: 860px) {
    .app { flex-direction: column; }
    .sidebar {
        width: 100%; flex-direction: row; align-items: center;
        overflow-x: auto; padding: 10px 12px; gap: 6px;
        border-right: none; border-bottom: 1px solid var(--border);
    }
    .sidebar .brand { padding: 0 8px 0 0; }
    .sidebar .nav-item { white-space: nowrap; padding: 8px 12px; }
    .sidebar .spacer { display: none; }
    .main { padding: 18px 16px; }
    .form-grid { grid-template-columns: 1fr; }
}

/* Sélecteur de dates par calendrier (assets/date-range.js) */
.dr-cal { max-width: 420px; }
.dr-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.dr-caption { text-transform: capitalize; }
.dr-nav { width: 40px; height: 40px; border: 1px solid var(--border); background: var(--surface, transparent); color: var(--primary); border-radius: 10px; font-size: 1.4rem; line-height: 1; cursor: pointer; }
.dr-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.dr-dow { text-align: center; font-size: .72rem; color: var(--text-muted); font-weight: 600; padding: 4px 0; }
.dr-day { position: relative; min-height: 40px; border: 1px solid var(--border); background: var(--surface-2, transparent); color: var(--text); border-radius: 8px; font: inherit; font-size: .92rem; cursor: pointer; }
.dr-day:hover { border-color: var(--primary); }
.dr-day:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; }
.dr-day.is-today { font-weight: 800; border-color: var(--primary); }
.dr-day.is-sel { background: var(--primary-soft); border-color: var(--primary); color: var(--primary); font-weight: 700; }
.dr-day.is-start, .dr-day.is-end { background: var(--primary); color: #fff; }
.dr-dot { display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: var(--primary); }
.dr-day .dr-dot { position: absolute; left: 50%; bottom: 4px; margin-left: -3px; background: #e0902b; }
.dr-day.is-start .dr-dot, .dr-day.is-end .dr-dot { background: #fff; }
.dr-legend { display: flex; gap: 14px; margin-top: 8px; font-size: .8rem; color: var(--text-muted); }
.dr-legend .dr-dot { background: #e0902b; margin-right: 6px; vertical-align: 1px; }
.dr-summary { margin: 12px 0 0; padding: 10px 12px; border-radius: 8px; background: var(--surface-2, transparent); font-size: .92rem; }
.dr-summary.is-ok { border-left: 4px solid var(--primary); }
.dr-summary.is-warn { background: #fdf0e3; color: #5c4300; }
.dr-times { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 12px; max-width: 420px; }
@media (max-width: 480px) { .dr-times { grid-template-columns: 1fr; } }
