/* =============================================================================
 * OuvrierPro — socle visuel (étape 44 quater)
 *
 * Feuille UNIQUE, servie par Caddy depuis public/. Aucune dépendance : ni CDN,
 * ni police distante, ni framework. Le sous-ensemble de règles ci-dessous est
 * ce qu'il faut pour habiller toutes les pages existantes — les gabarits ne
 * portent plus de <style> commun.
 *
 * Mobile-first : les règles de base valent pour un téléphone, la sidebar
 * n'apparaît qu'au-dessus de 60rem.
 * ========================================================================== */

/* ═══ JETONS ═══ */
:root {
    --blue-600: #1d4ed8;
    --blue-700: #1e40af;
    --blue-50: #eff6ff;

    --ink: #18181b;
    --ink-soft: #3f3f46;
    --muted: #71717a;
    --line: #e4e4e7;
    --line-strong: #d4d4d8;

    --bg: #f6f7f9;
    --surface: #ffffff;
    --sidebar: #ffffff;

    --ok: #047857;
    --ok-bg: #ecfdf5;
    --ok-line: #a7f3d0;
    --warn: #92400e;
    --warn-bg: #fffbeb;
    --warn-line: #fcd34d;
    --danger: #b91c1c;
    --danger-bg: #fef2f2;
    --danger-line: #fecaca;

    --radius: 10px;
    --radius-sm: 8px;
    --gap: 1rem;

    /* Ombres très légères : elles détachent la carte du fond, rien de plus. */
    --shadow: 0 1px 2px rgba(24, 24, 27, .05);
    --shadow-md: 0 2px 8px rgba(24, 24, 27, .07);

    --sidebar-w: 15.5rem;
}

* { box-sizing: border-box; }

/* `hidden` doit gagner contre un `display:` posé par une classe. Sans cette
   règle, un `display: inline-flex` rend visible un élément explicitement
   marqué caché — c'est ce qui ferait apparaître le bouton de dictée sur un
   navigateur incapable de dicter. */
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    font: 16px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    color: var(--ink);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
}

a { color: var(--blue-600); }

/* Un anneau de focus VISIBLE partout. Le retirer sur un SaaS utilisé au
   clavier revient à rendre la navigation invisible pour qui n'a pas de souris. */
:focus-visible {
    outline: 2px solid var(--blue-600);
    outline-offset: 2px;
    border-radius: 4px;
}

/* ═══ SQUELETTE ═══ */
.app { min-height: 100vh; }

/* Accès direct au contenu : premier élément focusable de la page. */
.skip-link {
    position: absolute;
    left: -9999px;
    top: 0;
    background: var(--blue-600);
    color: #fff;
    padding: .6rem 1rem;
    border-radius: 0 0 var(--radius-sm) 0;
    z-index: 60;
}
.skip-link:focus { left: 0; }

/* ═══ EN-TÊTE MOBILE ═══ */
.topbar {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: .6rem var(--gap);
    background: var(--surface);
    border-bottom: 1px solid var(--line);
    position: sticky;
    top: 0;
    z-index: 40;
}

.topbar .brand { margin-right: auto; }

.nav-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    min-height: 44px;
    padding: 0;
    background: var(--surface);
    color: var(--ink);
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-sm);
    cursor: pointer;
}
.nav-toggle:hover { background: var(--bg); }

/* ═══ MARQUE ═══ */
.brand {
    display: inline-flex;
    align-items: center;
    gap: .5rem;
    font-weight: 800;
    letter-spacing: .04em;
    font-size: .95rem;
    color: var(--ink);
    text-decoration: none;
}
.brand-mark {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 7px;
    background: var(--blue-600);
    color: #fff;
    font-size: .8rem;
    font-weight: 800;
    flex: 0 0 auto;
}

/* ═══ SIDEBAR ═══ */
.sidebar {
    display: none;
    flex-direction: column;
    background: var(--sidebar);
    border-right: 1px solid var(--line);
}
.sidebar.is-open { display: flex; }

.sidebar-head {
    padding: 1rem var(--gap) .5rem;
    display: none;
}

.nav { padding: .5rem .6rem; }
.nav + .nav { border-top: 1px solid var(--line); }

.nav-title {
    font-size: .7rem;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--muted);
    font-weight: 700;
    padding: .5rem .6rem .25rem;
    margin: 0;
}

.nav a {
    display: flex;
    align-items: center;
    gap: .65rem;
    padding: .6rem;
    min-height: 44px;
    border-radius: var(--radius-sm);
    color: var(--ink-soft);
    text-decoration: none;
    font-size: .93rem;
    font-weight: 500;
}
.nav a:hover { background: var(--bg); color: var(--ink); }

/* La page courante est signalée par la couleur ET par le fond : jamais par la
   couleur seule. */
.nav a[aria-current="page"] {
    background: var(--blue-50);
    color: var(--blue-700);
    font-weight: 600;
}

.nav a svg { flex: 0 0 auto; color: var(--muted); }
.nav a[aria-current="page"] svg { color: var(--blue-600); }

/* ═══ PIED DE SIDEBAR — IDENTITÉ ═══ */
.sidebar-foot {
    margin-top: auto;
    padding: .75rem;
    border-top: 1px solid var(--line);
}
.who { padding: .35rem .6rem .6rem; min-width: 0; }
.who-company {
    font-weight: 700;
    font-size: .88rem;
    color: var(--ink);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.who-user {
    font-size: .8rem;
    color: var(--muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.sidebar-foot form { margin: 0; }

/* ═══ CONTENU ═══ */
.content { min-width: 0; }

main {
    max-width: 62rem;
    margin: 0 auto;
    padding: var(--gap);
}
main.wide { max-width: 92rem; }

.page-head { margin-bottom: 1.1rem; }
h1 {
    font-size: 1.35rem;
    line-height: 1.3;
    margin: 0;
    letter-spacing: -.01em;
}
.page-sub {
    margin: .35rem 0 0;
    color: var(--muted);
    font-size: .95rem;
    max-width: 46rem;
}

h2 { font-size: 1.08rem; margin: 0 0 .5rem; }

/* ═══ CARTES ═══ */
.card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: var(--gap);
    margin-bottom: .85rem;
    box-shadow: var(--shadow);
}
.card h2 { font-size: 1.05rem; margin: 0 0 .25rem; }
.card p { margin: .15rem 0; color: var(--muted); font-size: .92rem; }
.card-lead { padding: 1.15rem; }

/* ═══ FORMULAIRES ═══ */
button, input, select, textarea {
    font: inherit;
    min-height: 44px;
    width: 100%;
    padding: .55rem .7rem;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--ink);
}
textarea { min-height: 7rem; resize: vertical; }

input:focus, select:focus, textarea:focus {
    border-color: var(--blue-600);
    outline: 2px solid var(--blue-600);
    outline-offset: 0;
}

input::placeholder, textarea::placeholder { color: #a1a1aa; }

label {
    display: block;
    margin-top: .85rem;
    margin-bottom: .3rem;
    font-weight: 600;
    font-size: .88rem;
    color: var(--ink-soft);
}

.help, small { color: var(--muted); font-weight: 400; font-size: .85rem; }
.help { display: block; margin-top: .35rem; }

fieldset {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    margin: var(--gap) 0;
    padding: 0 var(--gap) var(--gap);
    background: var(--surface);
}
legend { font-weight: 700; padding: 0 .4rem; font-size: .95rem; }

/* ═══ BOUTONS ═══ */
button {
    background: var(--blue-600);
    color: #fff;
    border: 1px solid var(--blue-600);
    font-weight: 600;
    cursor: pointer;
}
button:hover { background: var(--blue-700); border-color: var(--blue-700); }
button:disabled { opacity: .6; cursor: default; }

button.secondary {
    background: var(--surface);
    color: var(--ink);
    border: 1px solid var(--line-strong);
}
button.secondary:hover { background: var(--bg); }

button.danger { background: var(--danger); border-color: var(--danger); }
button.danger:hover { background: #991b1b; border-color: #991b1b; }

button.link {
    background: none;
    border: 0;
    color: var(--blue-600);
    width: auto;
    padding: .4rem 0;
    font-weight: 500;
    text-decoration: underline;
}

button.big { min-height: 52px; font-size: 1.02rem; }

.actions { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: var(--gap); }
.actions form { display: inline; margin: 0; }
/* Un <a> qui enveloppe un <button> ne doit pas étirer le bouton. */
.actions a { text-decoration: none; display: inline-block; }

/* ═══ BOUTON-LIEN (a stylé en bouton) ═══ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .5rem;
    min-height: 44px;
    padding: .55rem 1rem;
    border-radius: var(--radius-sm);
    background: var(--blue-600);
    border: 1px solid var(--blue-600);
    color: #fff;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    width: 100%;
}
.btn:hover { background: var(--blue-700); border-color: var(--blue-700); color: #fff; }
.btn-secondary {
    background: var(--surface);
    color: var(--ink);
    border-color: var(--line-strong);
}
.btn-secondary:hover { background: var(--bg); color: var(--ink); }
.btn-big { min-height: 52px; font-size: 1.02rem; }

/* ═══ BARRE D'OUTILS ═══ */
.toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: .5rem;
    align-items: center;
    margin-bottom: var(--gap);
}
.toolbar form { display: flex; gap: .5rem; flex: 1 1 14rem; margin: 0; }

/* ═══ BADGES ═══ */
.badge {
    display: inline-block;
    font-size: .74rem;
    font-weight: 600;
    padding: .18rem .55rem;
    border: 1px solid var(--line-strong);
    border-radius: 999px;
    color: var(--muted);
    background: var(--surface);
    white-space: nowrap;
}
.badge-review { background: var(--warn-bg); border-color: var(--warn-line); color: var(--warn); }
.badge-ok { background: var(--ok-bg); border-color: var(--ok-line); color: var(--ok); }
.badge-info { background: var(--blue-50); border-color: #bfdbfe; color: var(--blue-700); }

/* ═══ ALERTES ═══ */
.flash {
    padding: .8rem var(--gap);
    border-radius: var(--radius);
    margin-bottom: var(--gap);
    border: 1px solid var(--line);
    background: var(--surface);
    font-size: .93rem;
}
.flash-success { background: var(--ok-bg); border-color: var(--ok-line); color: #065f46; }
.flash-error { background: var(--danger-bg); border-color: var(--danger-line); color: #7f1d1d; }
.flash-warn { background: var(--warn-bg); border-color: var(--warn-line); color: var(--warn); }
.flash strong { display: block; margin-bottom: .15rem; }

ul.errors { color: var(--danger); padding-left: 1.1rem; margin: .3rem 0; }
.flash-warn ul.errors, .flash-warn li { color: var(--warn); }

.empty { color: var(--muted); font-style: italic; }

/* ═══ GRILLES ═══ */
.grid { display: grid; gap: .85rem; grid-template-columns: 1fr; }
.grid-2 { display: grid; gap: .85rem; grid-template-columns: 1fr; }

/* ═══ TUILES DE STATISTIQUE ═══ */
.stat {
    display: block;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: .9rem 1rem;
    text-decoration: none;
    color: var(--ink);
    box-shadow: var(--shadow);
}
.stat:hover { border-color: #c7d2fe; box-shadow: var(--shadow-md); }
.stat-flat:hover { border-color: var(--line); box-shadow: var(--shadow); }
.stat-label { font-size: .82rem; color: var(--muted); font-weight: 500; }
.stat-value {
    font-size: 1.75rem;
    font-weight: 700;
    line-height: 1.1;
    margin-top: .15rem;
    letter-spacing: -.02em;
}
.stat-value.accent { color: var(--blue-700); }

/* ═══ ACTIONS RAPIDES ═══ */
.quick {
    display: flex;
    align-items: center;
    gap: .7rem;
    padding: .75rem;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: var(--surface);
    text-decoration: none;
    color: var(--ink);
    font-weight: 500;
    font-size: .93rem;
    min-height: 44px;
}
.quick:hover { background: var(--blue-50); border-color: #bfdbfe; }
.quick svg { color: var(--blue-600); flex: 0 0 auto; }

/* ═══ TABLEAUX ═══ */
.table-wrap {
    overflow-x: auto;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}
table { border-collapse: collapse; width: 100%; min-width: 34rem; }
th, td {
    padding: .6rem .7rem;
    border-bottom: 1px solid var(--line);
    text-align: left;
    font-size: .93rem;
}
thead th {
    background: #fafafa;
    font-size: .74rem;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--muted);
    font-weight: 700;
}
tbody tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
tfoot th, tfoot td { font-weight: 700; border-top: 2px solid var(--line-strong); background: #fafafa; }
tfoot tr:last-child th, tfoot tr:last-child td { font-size: 1.02rem; }

/* ═══ LISTE DE QUESTIONS ═══ */
.question {
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    padding: .85rem var(--gap);
    margin-bottom: .6rem;
    background: var(--surface);
}
.question label { margin-top: 0; }

/* ═══ DICTÉE ═══ */

/* Le libellé du champ et le bouton de dictée partagent une ligne : « écrire ou
   dicter » doit se lire d'un coup d'œil, pas se chercher. */
.field-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .75rem;
    flex-wrap: wrap;
    margin-top: .85rem;
}
.field-head label { margin-top: 0; margin-bottom: 0; }

.dictate {
    display: inline-flex;
    align-items: center;
    gap: .45rem;
    width: auto;
    min-height: 40px;
    padding: .4rem .8rem;
    font-size: .88rem;
    background: var(--surface);
    color: var(--blue-700);
    border: 1px solid #bfdbfe;
    border-radius: 999px;
    font-weight: 600;
}
.dictate:hover { background: var(--blue-50); border-color: #93c5fd; }

/* En écoute : le bouton devient rouge et pulse. La couleur ne porte pas seule
   l'information — le libellé passe à « Arrêter la dictée ». */
.dictate.is-recording {
    background: var(--danger-bg);
    color: var(--danger);
    border-color: var(--danger-line);
}
.dictate.is-recording svg { animation: pulse 1.3s ease-in-out infinite; }

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: .35; }
}

.dictation-status {
    display: block;
    margin-top: .4rem;
    font-size: .85rem;
    color: var(--muted);
    min-height: 1.2em;
}

@media (prefers-reduced-motion: reduce) {
    .dictate.is-recording svg { animation: none; }
}

/* ═══ INDICATEUR DE TRAITEMENT ═══ */
.processing { display: flex; gap: .9rem; align-items: flex-start; }

.spinner {
    flex: 0 0 auto;
    width: 26px;
    height: 26px;
    margin-top: .15rem;
    border: 3px solid var(--line-strong);
    border-top-color: var(--blue-600);
    border-radius: 50%;
    animation: spin .9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Une barre de progression indéterminée, purement décorative. */
.progress {
    height: 4px;
    border-radius: 999px;
    background: var(--line);
    overflow: hidden;
    margin-top: .9rem;
}
.progress span {
    display: block;
    height: 100%;
    width: 35%;
    border-radius: 999px;
    background: var(--blue-600);
    animation: slide 1.6s ease-in-out infinite;
}
@keyframes slide {
    0% { margin-left: -35%; }
    100% { margin-left: 100%; }
}

/* Respecte le réglage système : aucune animation si l'utilisateur n'en veut pas. */
@media (prefers-reduced-motion: reduce) {
    .spinner, .progress span { animation: none; }
    .progress span { width: 100%; margin-left: 0; }
}

/* ═══ PAGE DE CONNEXION ═══ */
.auth {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 1fr;
    background: var(--bg);
}

.auth-aside { display: none; }

.auth-main {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem var(--gap);
}
.auth-box { width: 100%; max-width: 25rem; }
.auth-brand { margin-bottom: 1.5rem; }
.auth h1 { font-size: 1.5rem; }
.auth .page-sub { font-size: .96rem; }
.auth .card { padding: 1.25rem; box-shadow: var(--shadow-md); }
.auth .card label:first-of-type { margin-top: 0; }
/* Le bouton de connexion reste pleine largeur, y compris sur grand écran :
   c'est l'unique action de la page. */
.auth .actions { margin-top: 1.1rem; }
.auth .actions button { width: 100%; }
.auth-alt { margin-top: 1.1rem; text-align: center; font-size: .9rem; color: var(--muted); }

/* ═══ DESKTOP ═══ */
@media (min-width: 60rem) {
    .app {
        display: grid;
        grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
    }

    .topbar { display: none; }

    /* La sidebar est permanente : l'état « ouvert/fermé » ne concerne que le
       téléphone, et ne doit pas survivre ici. */
    .sidebar,
    .sidebar.is-open {
        display: flex;
        position: sticky;
        top: 0;
        height: 100vh;
        overflow-y: auto;
    }
    .sidebar-head { display: block; }

    main { padding: 1.75rem 2rem; }

    h1 { font-size: 1.6rem; }

    .actions button, .actions .btn, .toolbar button { width: auto; }

    .grid-2 { grid-template-columns: 1fr 1fr; }
    .grid-4 { grid-template-columns: repeat(4, 1fr); }
    .grid-3 { grid-template-columns: repeat(3, 1fr); }

    .auth { grid-template-columns: 1fr 1fr; }

    /* Panneau de gauche : un aplat sobre, aucun dégradé criard. */
    .auth-aside {
        display: flex;
        flex-direction: column;
        justify-content: center;
        padding: 3rem;
        background: var(--blue-700);
        color: #fff;
    }
    .auth-aside .brand, .auth-aside .brand-mark { color: #fff; }
    .auth-aside .brand-mark { background: rgba(255, 255, 255, .16); }
    .auth-aside h2 { font-size: 1.5rem; margin: 2rem 0 .75rem; line-height: 1.3; }
    .auth-aside p { color: #dbeafe; max-width: 26rem; margin: 0; }
    .auth-aside ul { margin: 1.5rem 0 0; padding: 0; list-style: none; color: #dbeafe; }
    .auth-aside li { display: flex; gap: .6rem; align-items: center; padding: .35rem 0; }
}

@media (min-width: 45rem) and (max-width: 59.99rem) {
    .grid-2, .grid-4, .grid-3 { grid-template-columns: 1fr 1fr; }
    .actions button, .actions .btn, .toolbar button { width: auto; }
}
