/* App de révision — CSS mobile-first, thème sombre par défaut.
   Design volontairement minimal : lisibilité + gros boutons + zéro friction. */

:root {
    --fond: #1a1a1a;
    --fond-carte: #262626;
    --fond-carte-hover: #303030;
    --texte: #f5f5f5;
    --texte-doux: #a0a0a0;
    --accent: #4ade80;         /* vert doux, action principale */
    --accent-fonce: #22c55e;
    --danger: #ef4444;
    --alerte: #fbbf24;
    --bordure: #3a3a3a;
    --radius: 8px;
    --espace: 12px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--fond);
    color: var(--texte);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    font-size: 16px;
    line-height: 1.5;
}

body {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ---------- Header / nav ---------- */

header {
    background: var(--fond-carte);
    padding: var(--espace);
    border-bottom: 1px solid var(--bordure);
    position: sticky;
    top: 0;
    z-index: 10;
}

header h1 {
    margin: 0 0 8px 0;
    font-size: 1.1rem;
    color: var(--texte-doux);
    font-weight: 500;
}

/* Petit badge discret qui affiche le modèle LLM actif à côté du titre.
   Sert à savoir d'un coup d'œil quel provider tourne (gemini vs anthropic)
   quand on switch via LLM_PROVIDER en env var. Vide tant que /modele-actif
   n'a pas répondu ; se remplit sans provoquer de layout shift visible. */
.modele-badge {
    font-size: 0.65rem;
    font-weight: 400;
    color: var(--texte-doux);
    background: var(--fond);
    border: 1px solid var(--bordure);
    padding: 2px 6px;
    border-radius: 4px;
    margin-left: 8px;
    vertical-align: middle;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.modele-badge:empty { display: none; }

nav {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

nav a {
    padding: 6px 12px;
    background: var(--fond);
    color: var(--texte-doux);
    border: 1px solid var(--bordure);
    border-radius: var(--radius);
    text-decoration: none;
    font-size: 0.9rem;
    transition: all 0.15s;
}

nav a.actif {
    background: var(--accent);
    color: var(--fond);
    border-color: var(--accent);
}

nav a:hover:not(.actif) {
    background: var(--fond-carte-hover);
    color: var(--texte);
}

/* ---------- Contenu principal ---------- */

main {
    flex: 1;
    padding: var(--espace);
    max-width: 900px;
    width: 100%;
    margin: 0 auto;
}

section {
    margin-bottom: calc(var(--espace) * 2);
}

section h2 {
    font-size: 1rem;
    color: var(--texte-doux);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin: 0 0 10px 0;
    font-weight: 600;
}

/* ---------- Champs ---------- */

textarea, input[type="text"], input[type="number"], select {
    width: 100%;
    padding: 10px;
    background: var(--fond-carte);
    color: var(--texte);
    border: 1px solid var(--bordure);
    border-radius: var(--radius);
    font-size: 1rem;
    font-family: inherit;
}

textarea {
    min-height: 140px;
    resize: vertical;
}

textarea:focus, input:focus, select:focus {
    outline: none;
    border-color: var(--accent);
}

/* ---------- Boutons ---------- */

button, .bouton {
    padding: 10px 18px;
    border: 0;
    border-radius: var(--radius);
    background: var(--accent);
    color: var(--fond);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s;
    font-family: inherit;
}

button:hover, .bouton:hover { background: var(--accent-fonce); }
button:disabled { opacity: 0.5; cursor: not-allowed; }

button.secondaire {
    background: var(--fond-carte);
    color: var(--texte);
    border: 1px solid var(--bordure);
}
button.secondaire:hover { background: var(--fond-carte-hover); }

button.danger {
    background: var(--danger);
    color: white;
}
button.danger:hover { background: #dc2626; }

.bouton-plein {
    width: 100%;
    padding: 14px;
    font-size: 1.05rem;
    margin-top: 10px;
}

/* ---------- Cartes de séance / item ---------- */

.carte {
    background: var(--fond-carte);
    border: 1px solid var(--bordure);
    border-radius: var(--radius);
    padding: var(--espace);
    margin-bottom: 8px;
}

.carte .titre {
    font-weight: 600;
    color: var(--texte);
    margin-bottom: 4px;
}

.carte .meta {
    font-size: 0.85rem;
    color: var(--texte-doux);
    margin-bottom: 8px;
}

.carte .actions {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin-top: 8px;
}

.carte .actions button {
    padding: 6px 12px;
    font-size: 0.85rem;
}

/* Badges */
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}
.badge-principal { background: var(--accent); color: var(--fond); }
.badge-croise { background: var(--fond); color: var(--texte-doux); border: 1px solid var(--bordure); }
.badge-nouveau { background: var(--alerte); color: var(--fond); }
.badge-confiance-basse { background: var(--alerte); color: var(--fond); }
.badge-retard { background: var(--danger); color: white; }

/* Ligne de séance dans le popup de validation */

.seance-edit {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
    padding: 12px;
    background: var(--fond-carte);
    border: 1px solid var(--bordure);
    border-radius: var(--radius);
    margin-bottom: 10px;
}

.seance-edit .ligne { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.seance-edit label {
    font-size: 0.8rem;
    color: var(--texte-doux);
    min-width: 80px;
}
.seance-edit select, .seance-edit input {
    flex: 1;
    min-width: 100px;
    padding: 6px 8px;
    font-size: 0.9rem;
}

/* ---------- Modal ---------- */

.modal-fond {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    display: none;
    align-items: flex-start;
    justify-content: center;
    padding: 20px;
    z-index: 100;
    overflow-y: auto;
}
.modal-fond.ouvert { display: flex; }

.modal {
    background: var(--fond);
    border: 1px solid var(--bordure);
    border-radius: var(--radius);
    max-width: 700px;
    width: 100%;
    padding: var(--espace);
}

.modal h2 { margin-top: 0; }

/* ---------- Divers ---------- */

.vide {
    color: var(--texte-doux);
    font-style: italic;
    padding: 10px;
    text-align: center;
}

.chargement {
    color: var(--texte-doux);
    text-align: center;
    padding: 20px;
}

.erreur {
    color: var(--danger);
    padding: 10px;
    background: rgba(239, 68, 68, 0.1);
    border-radius: var(--radius);
    margin: 10px 0;
}

/* ---------- Progression barres ---------- */

.progres-ligne {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 6px;
}
.progres-ligne .label {
    flex: 1;
    font-size: 0.9rem;
}
.progres-barre {
    width: 120px;
    height: 8px;
    background: var(--fond-carte);
    border-radius: 4px;
    overflow: hidden;
}
.progres-fill {
    height: 100%;
    background: var(--accent);
}

@media (min-width: 700px) {
    .seance-edit { grid-template-columns: 1fr 1fr; }
}

/* ---------- Indicateur d'état du brouillon ---------- */

.etat-brouillon {
    font-size: 0.8rem;
    color: var(--texte-doux);
    margin: 4px 2px 0;
    min-height: 1.2em;
    text-align: right;
    font-style: italic;
}
.etat-brouillon.enregistrement { color: var(--alerte); }
.etat-brouillon.enregistre     { color: var(--accent); }

/* ---------- Toasts (notifications discrètes) ---------- */

#toast-bac {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 1000;
    pointer-events: none;
}
.toast {
    background: var(--fond-carte);
    color: var(--texte);
    padding: 12px 20px;
    border-radius: var(--radius);
    border-left: 3px solid var(--accent);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
    font-size: 0.95rem;
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.25s ease, transform 0.25s ease;
    max-width: 90vw;
}
.toast.visible {
    opacity: 1;
    transform: translateY(0);
}
.toast-erreur {
    border-left-color: var(--danger);
}

/* ---------- Historique / révisions faites ---------- */

.carte-saisie {
    background: var(--fond-carte);
    border-radius: var(--radius);
    padding: 14px 16px;
    margin-bottom: 16px;
}
.entete-saisie {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 12px;
    margin-bottom: 8px;
    flex-wrap: wrap;
}
.date-saisie {
    font-weight: 600;
    color: var(--texte);
    font-size: 0.95rem;
}
.prompt-saisie {
    background: var(--fond);
    border-left: 3px solid var(--accent);
    padding: 8px 12px;
    border-radius: 4px;
    font-style: italic;
    color: var(--texte-doux);
    margin-bottom: 12px;
    white-space: pre-wrap;
    word-break: break-word;
}
.groupe-chapitre {
    border-top: 1px solid var(--bordure);
    padding-top: 8px;
    margin-top: 8px;
}
.groupe-chapitre:first-child {
    border-top: none;
    padding-top: 0;
    margin-top: 0;
}
.groupe-chapitre-titre {
    font-weight: 600;
    color: var(--accent);
    margin-bottom: 6px;
    font-size: 0.95rem;
}
.ligne-seance {
    padding: 4px 0 4px 8px;
    border-left: 2px solid var(--bordure);
    margin-left: 4px;
    margin-bottom: 4px;
}
.actions-seance {
    display: flex;
    gap: 6px;
    margin-top: 4px;
}
.actions-seance button {
    font-size: 0.8rem;
    padding: 3px 10px;
}
.commentaire-seance {
    color: var(--texte-doux);
    font-size: 0.85rem;
    margin-top: 2px;
    font-style: italic;
}
.meta-doux { color: var(--texte-doux); }

/* ---------- En-tête de groupe par date ---------- */

.groupe-date {
    color: var(--texte-doux);
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin: 16px 0 6px;
    padding-bottom: 4px;
    border-bottom: 1px solid var(--bordure);
}

/* ---------- Formulaire d'ajout manuel (aujourdhui.html) ---------- */

.ajout-manuel {
    background: var(--fond-carte);
    border: 1px solid var(--bordure);
    border-radius: var(--radius);
    padding: 10px 12px;
    margin-bottom: 8px;
}
.ajout-manuel > summary {
    cursor: pointer;
    color: var(--texte-doux);
    font-size: 0.95rem;
    padding: 4px 0;
    user-select: none;
}
.ajout-manuel[open] > summary {
    color: var(--texte);
    margin-bottom: 8px;
    border-bottom: 1px solid var(--bordure);
    padding-bottom: 6px;
}
.form-manuel {
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.form-manuel .ligne-form {
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.form-manuel .ligne-form label {
    color: var(--texte-doux);
    font-size: 0.85rem;
}
.form-manuel input,
.form-manuel select {
    background: var(--fond);
    color: var(--texte);
    border: 1px solid var(--bordure);
    border-radius: var(--radius);
    padding: 8px 10px;
    font-size: 1rem;
    width: 100%;
}
.form-manuel button[type="submit"] {
    margin-top: 4px;
}

/* ---------- Composant recherche_cible (autocomplete) ---------- */

.recherche-conteneur {
    position: relative;
    width: 100%;
}
.recherche-panneau {
    display: none;
    position: absolute;
    top: calc(100% + 2px);
    left: 0;
    right: 0;
    background: var(--fond-carte);
    border: 1px solid var(--bordure);
    border-radius: var(--radius);
    max-height: 280px;
    overflow-y: auto;
    z-index: 20;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
}
.recherche-item {
    padding: 8px 10px;
    display: flex;
    gap: 8px;
    align-items: center;
    cursor: pointer;
    border-bottom: 1px solid var(--bordure);
    font-size: 0.9rem;
}
.recherche-item:last-child { border-bottom: none; }
.recherche-item:hover,
.recherche-item.focus {
    background: var(--fond-carte-hover);
}
.recherche-tag {
    font-size: 0.7rem;
    padding: 1px 6px;
    border-radius: 4px;
    background: var(--bordure);
    color: var(--texte-doux);
    flex-shrink: 0;
}
.recherche-tag-chap {
    background: var(--accent-fonce);
    color: var(--fond);
}
.recherche-lib {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.recherche-vide {
    padding: 10px;
    color: var(--texte-doux);
    font-style: italic;
    font-size: 0.9rem;
}

/* ---------- Ajout inline dans la popup validation ---------- */

.ajout-inline {
    margin: 12px 0 4px;
    padding-top: 12px;
    border-top: 1px dashed var(--bordure);
}
.ajout-inline #btn-ligne-manuelle {
    font-size: 0.85rem;
    padding: 6px 12px;
}
.ajout-inline #zone-manuelle {
    margin-top: 8px;
}
.ajout-inline input[type="text"] {
    background: var(--fond);
    color: var(--texte);
    border: 1px solid var(--bordure);
    border-radius: var(--radius);
    padding: 8px 10px;
    font-size: 1rem;
    width: 100%;
}
