/*
 * home-ui.css - Le style de l'app maison
 * =======================================
 * Chargé par home_page_start() avant home-anim.css (qui ne fait que bouger les
 * choses). Tableau de bord sombre, pensé pour le téléphone d'abord.
 *
 * Briques à utiliser dans les pages (voir aussi les aides PHP de _bootstrap.php) :
 *   .page-head            titre de page + sous-titre (.sub) + boutons (.actions)
 *   .alert .ok|.err       message de retour d'un formulaire (home_alerts())
 *   .tiles > .tile        chiffres clés : .tile-label, .tile-value, .tile-hint
 *   .grid                 colonnes qui se remplissent seules (.grid-2, .grid-3 pour forcer)
 *   .card                 bloc ; .card-head (titre + badges), .card-actions (boutons en bas)
 *   .row-list > .row      liste dense : .row-main (.row-title, .row-meta) + .row-side
 *   .badge .ok|.warn|.err|.mut   pastille d'état
 *   details.add           formulaire d'ajout replié (« + Ajouter … »)
 *   .field                libellé + champ + aide (.hint) ; .form-grid pour mettre des champs côte à côte
 *   .form-actions         boutons d'un formulaire
 *   .empty                état vide (titre, texte, bouton)
 *   .progress             barre de progression ; .ring pour un cercle
 *   .pager                semaine / mois précédent, courant, suivant
 *   .btn-sm .btn-danger .btn-quiet .btn-link   variantes de bouton (.btn-quiet : action destructive discrète)
 *   .req .sr-only .amt    étoile de champ obligatoire, texte réservé aux lecteurs d'écran, montant qui ne se coupe pas
 *   .tile.good|ok|warn|err   tuile « tout va bien », « à surveiller », « en retard »
 */
:root {
    --bg: #0f1115; --card: #181b22; --card2: #1e222b; --line: #2a2f3a; --line2: #363c49;
    --txt: #e8eaee; --mut: #9aa1ad; --acc: #7cc4a4; --acc-d: #3f7a62; --acc-soft: #7cc4a41a;
    --warn: #e3b66b; --warn-soft: #e3b66b1f; --err: #e07a7a; --err-soft: #e07a7a1f;
    --radius: 12px; --radius-s: 8px;
    color-scheme: dark;
}
*, *::before, *::after { box-sizing: border-box; }
html { background: var(--bg); -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--txt); font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
main { max-width: 1040px; margin: 0 auto; padding: 20px 16px 72px; display: grid; gap: 16px; align-content: start; }
main > * { margin: 0; min-width: 0; }
a { color: var(--acc); text-underline-offset: 3px; }
h1 { font-size: 1.6rem; line-height: 1.2; margin: 0; text-wrap: balance; }
h2 { font-size: 1.05rem; margin: 0; }
h3 { font-size: .95rem; margin: 0; }
p { margin: 0; }
.mut { color: var(--mut); }
.ok { color: var(--acc); }
.err { color: var(--err); }
.warn { color: var(--warn); }
.num { font-variant-numeric: tabular-nums; }

/* ── Titre de page ──────────────────────────────────────────────────────── */
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 10px 16px; }
.page-head > div:first-child { flex: 1 1 320px; min-width: 0; display: grid; gap: 4px; }
.page-head .sub { color: var(--mut); font-size: .95rem; }
.page-head .actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
/* Boutons d'en-tête : même taille sur toutes les pages, sur toute la largeur sur téléphone. */
.page-head .actions > .btn { min-height: 42px; padding: 8px 16px; font-size: .92rem; }

/* ── Messages de retour ─────────────────────────────────────────────────── */
.alert { padding: 10px 14px; border-radius: var(--radius-s); border: 1px solid var(--line); background: var(--card); }
.alert.ok { color: var(--txt); border-color: var(--acc-d); background: var(--acc-soft); }
.alert.err { color: var(--txt); border-color: #8a4a4a; background: var(--err-soft); }
.alert.ok::before { content: "✓ "; color: var(--acc); font-weight: 700; }
.alert.err::before { content: "! "; color: var(--err); font-weight: 700; }

/* ── Blocs ──────────────────────────────────────────────────────────────── */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin: 0; display: grid; gap: 10px; align-content: start; min-width: 0; }
.card-head { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; min-width: 0; }
.card-head > strong, .card-head > h2, .card-head > h3 { margin-right: auto; min-width: 0; overflow-wrap: anywhere; }
.card-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.card form { margin: 0; }
.section-title { font-size: .75rem; letter-spacing: .08em; text-transform: uppercase; color: var(--mut); margin: 8px 0 -4px; }
/* Titre de section d'une page (h2) : même taille que les autres titres de section ; le petit libellé en capitales reste pour les sous-parties d'une carte. */
h2.section-title { font-size: 1.15rem; letter-spacing: 0; text-transform: none; color: var(--txt); margin: 8px 0 0; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr)); gap: 12px; align-items: start; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 280px), 1fr)); }
.stack { display: grid; gap: 12px; }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 150px), 1fr)); gap: 10px; }
.tile { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; display: grid; gap: 2px; text-decoration: none; color: var(--txt); min-width: 0; }
a.tile:hover { border-color: var(--acc-d); }
.tile-label { color: var(--mut); font-size: .82rem; }
.tile-value { font-size: 1.7rem; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.2; }
.tile-hint { color: var(--mut); font-size: .8rem; }
.tile.warn { border-color: #8a6e3a; background: var(--warn-soft); }
.tile.err { border-color: #8a4a4a; background: var(--err-soft); }
.tile.good, .tile.ok { border-color: var(--acc-d); background: var(--acc-soft); }
.tile.good .tile-value, .tile.ok .tile-value { color: var(--acc); }

.badge { display: inline-flex; align-items: center; gap: 4px; font-size: .75rem; font-weight: 600; padding: 2px 9px; border-radius: 99px; border: 1px solid var(--line2); color: var(--mut); background: var(--card2); white-space: nowrap; }
.badge.ok { color: var(--acc); border-color: var(--acc-d); background: var(--acc-soft); }
.badge.warn { color: var(--warn); border-color: #8a6e3a; background: var(--warn-soft); }
.badge.err { color: var(--err); border-color: #8a4a4a; background: var(--err-soft); }

.row-list { display: grid; gap: 0; }
.row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px; padding: 10px 0; border-top: 1px solid var(--line); min-width: 0; }
.row:first-child { border-top: 0; }
.row-main { flex: 1 1 200px; min-width: 0; display: grid; gap: 1px; }
.row-title { font-weight: 600; overflow-wrap: anywhere; }
.row-meta { color: var(--mut); font-size: .88rem; overflow-wrap: anywhere; }
.row-side { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-left: auto; }

.empty { border: 1px dashed var(--line2); border-radius: var(--radius); padding: 28px 16px; text-align: center; display: grid; gap: 6px; justify-items: center; color: var(--mut); }
.empty strong { color: var(--txt); font-size: 1.02rem; }
.empty p { max-width: 46ch; }

.pager { display: inline-flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 4px; max-width: 100%; background: var(--card); border: 1px solid var(--line); border-radius: 99px; padding: 3px; }
.pager a { display: inline-flex; align-items: center; justify-content: center; min-height: 42px; min-width: 42px; color: var(--mut); text-decoration: none; padding: 0 14px; border-radius: 99px; font-size: .9rem; white-space: nowrap; transition: background .2s, color .2s; }
.pager a:hover { background: var(--card2); color: var(--txt); }
.pager strong { min-width: 0; padding: 0 8px; font-size: .92rem; line-height: 1.2; text-align: center; }
@media (max-width: 420px) { .pager a { padding: 0 10px; } .pager strong { padding: 0 4px; } }
@media (max-width: 359px) { .pager { border-radius: 22px; } }

/* ── Formulaires ────────────────────────────────────────────────────────── */
label { display: block; margin: 0 0 4px; color: var(--mut); font-size: .88rem; }
input, select, textarea, button { font: inherit; color: var(--txt); }
input, select, textarea { width: 100%; background: var(--bg); border: 1px solid var(--line2); border-radius: var(--radius-s); padding: 9px 11px; min-height: 42px; }
input[type=checkbox], input[type=radio] { width: auto; min-height: 0; accent-color: var(--acc); }
input::placeholder, textarea::placeholder { color: #6b7280; }
select { appearance: none; -webkit-appearance: none; padding-right: 34px; cursor: pointer;
    background: var(--bg) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%239aa1ad' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") no-repeat right 12px center; }
textarea { min-height: 96px; resize: vertical; }
input[type=date] { color-scheme: dark; }
.field { display: grid; gap: 0; min-width: 0; }
.field .hint, .hint { color: var(--mut); font-size: .82rem; margin-top: 4px; }
.form { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 170px), 1fr)); gap: 12px; align-items: start; }
.req { color: var(--warn); font-weight: 700; }
.form-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.inline-form { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 0; }
.inline-form input, .inline-form select { width: auto; flex: 1 1 140px; }

button { cursor: pointer; background: var(--acc); color: #0f1115; border: 0; border-radius: var(--radius-s); padding: 9px 16px; min-height: 42px; font-weight: 600; }
button.ghost { background: transparent; color: var(--mut); border: 1px solid var(--line2); font-weight: 500; }
button.ghost:hover { color: var(--txt); }
button:disabled { opacity: .5; cursor: not-allowed; }
.btn-sm { min-height: 42px; padding: 5px 12px; font-size: .88rem; }
.btn-danger { background: transparent; color: var(--err); border: 1px solid #8a4a4a; font-weight: 500; }
.btn-danger:hover { background: var(--err-soft); color: var(--err); }
/* Action destructive d'une ligne : discrète tant qu'on ne la survole pas (toujours confirmée par data-confirm). */
.btn-quiet { background: transparent; color: var(--mut); border: 0; font-weight: 500; font-size: .88rem; padding: 6px 12px; }
.btn-quiet:hover, .btn-quiet:focus-visible { background: var(--err-soft); color: var(--err); }
.btn-link { background: none; border: 0; color: var(--acc); padding: 0; min-height: 0; font-weight: 500; text-decoration: underline; text-underline-offset: 3px; }
a.btn { display: inline-flex; align-items: center; justify-content: center; background: var(--acc); color: #0f1115; text-decoration: none; border-radius: var(--radius-s); padding: 9px 16px; min-height: 42px; font-weight: 600; }
a.btn.ghost { background: transparent; color: var(--mut); border: 1px solid var(--line2); font-weight: 500; }

/* Formulaire d'ajout replié : la liste d'abord, l'ajout à un clic. */
details.add { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
details.add > summary { list-style: none; cursor: pointer; padding: 12px 16px; font-weight: 600; color: var(--acc); display: flex; align-items: center; gap: 8px; border-radius: var(--radius); }
details.add > summary::-webkit-details-marker { display: none; }
details.add > summary::before { content: "+"; display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; background: var(--acc-soft); font-size: 1.1rem; line-height: 1; transition: transform .3s; }
details.add[open] > summary::before { transform: rotate(45deg); }
details.add > .form, details.add > form { padding: 0 16px 16px; }

/* ── Progression ────────────────────────────────────────────────────────── */
.progress { height: 8px; background: var(--card2); border-radius: 99px; overflow: hidden; }
.progress > i { display: block; height: 100%; background: linear-gradient(90deg, var(--acc-d), var(--acc)); border-radius: 99px; }
.progress.warn > i { background: var(--warn); }
.progress.err > i { background: var(--err); }
.ring { position: relative; width: 120px; height: 120px; flex: none; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: 10; }
.ring .bg { stroke: var(--card2); }
.ring .fg { stroke: var(--acc); stroke-linecap: round; }
.ring .num { position: absolute; inset: 0; display: grid; place-items: center; font-weight: 700; font-size: 1.2rem; }

/* ── Semaine : sept jours sur PC, une pile sur mobile ───────────────────── */
.week { display: grid; grid-template-columns: 1fr; gap: 10px; }
@media (min-width: 640px) { .week { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
@media (min-width: 1000px) { .week { grid-template-columns: repeat(7, minmax(0, 1fr)); } }
.week-day { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; display: grid; gap: 8px; align-content: start; min-width: 0; }
.week-day.is-today { border-color: var(--acc); }
.week-day h3 { font-size: .75rem; letter-spacing: .06em; text-transform: uppercase; color: var(--mut); display: flex; justify-content: space-between; gap: 6px; }
.week-day.is-today h3 { color: var(--acc); }

/* ── Dialogue de confirmation ───────────────────────────────────────────── */
dialog.confirm { background: var(--card); color: var(--txt); border: 1px solid var(--line2); border-radius: var(--radius); padding: 18px; max-width: min(92vw, 380px); box-shadow: 0 30px 60px -20px #000; }
dialog.confirm::backdrop { background: #000a; }
dialog.confirm p { margin-bottom: 14px; }
dialog.confirm .form-actions { justify-content: flex-end; }

@media (max-width: 520px) {
    h1 { font-size: 1.4rem; }
    .row-side { margin-left: 0; width: 100%; }
    .card { padding: 12px; }
    .tile-value { font-size: 1.45rem; }
    .page-head .actions { width: 100%; }
    .page-head .actions > .btn { flex: 1 1 150px; }
}

/* ── Utilitaires ────────────────────────────────────────────────────────── */
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.amt { font-variant-numeric: tabular-nums; white-space: nowrap; }
.tile-value { overflow-wrap: anywhere; }
