/*
 * Kunto — feuille de style unique (TRD § 8.1), reprise du prototype A0
 * (docs/maquettes/kunto-prototype-a0.html) et des jetons du design brief.
 *
 * Règles de qualité (TRD § 8.4) : cibles tactiles d’au moins 44 px, focus
 * visible, aucune largeur fixe (grilles en minmax(0, 1fr)), aucun
 * débordement horizontal à 360 px, état jamais signalé par la seule couleur.
 *
 * Cadre : barre basse et bouton « Capturer » sur téléphone ; colonne
 * latérale à partir de 960 px (D14, D56).
 */

:root {
    --accent: #157b7d;
    --accent-strong: #0f6466;
    --soft: #e8f4f1;
    --text: #243b3b;
    --text-secondary: #617574;
    --background: #f5f8f6;
    --surface: #ffffff;
    --line: #e3ebe6;
    --field: #b7ceca;
    --late: #b65340;
    --late-soft: #f8ebe7;
    --waiting: #8a6512;
    --waiting-soft: #f6efdc;
    --tabs: #e9efeb;
    --focus: #d59b75;
    --radius: 19px;
    --target: 44px;
    --nav-height: 4.25rem;
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

[hidden] {
    display: none !important;
}

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

body {
    margin: 0;
    background: var(--background);
    color: var(--text);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    font-size: 1rem;
    line-height: 1.5;
    overflow-wrap: anywhere;
    -webkit-font-smoothing: antialiased;
}

h1 {
    margin: 0.125rem 0;
    font-size: 1.75rem;
    font-weight: 600;
    letter-spacing: -0.03em;
    line-height: 1.2;
}

h2 {
    margin: 0;
    font-size: 1.125rem;
    font-weight: 600;
    line-height: 1.3;
}

p {
    margin: 0.75rem 0;
}

code {
    word-break: break-all;
}

ol,
ul {
    padding-left: 1.5rem;
}

/* ---------- Icônes ---------- */

.sprite {
    position: absolute;
    width: 0;
    height: 0;
    overflow: hidden;
}

.icon {
    flex-shrink: 0;
    width: 1.375rem;
    height: 1.375rem;
}

.icon.accent {
    color: var(--accent);
}

.icon.chev {
    color: var(--text-secondary);
    width: 1.125rem;
    height: 1.125rem;
}

/* ---------- Champs, boutons et liens ---------- */

label {
    display: block;
    margin-bottom: 0.25rem;
    font-weight: 600;
}

textarea,
input:not([type="hidden"]),
button {
    font: inherit;
    min-height: var(--target);
}

textarea,
input:not([type="hidden"]) {
    display: block;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    padding: 0.625rem 0.75rem;
    border: 1px solid var(--field);
    border-radius: 12px;
    background: var(--surface);
    color: var(--text);
    font-size: 1rem;
}

textarea {
    min-height: 7.5rem;
    resize: vertical;
    line-height: 1.5;
}

input[aria-invalid="true"],
textarea[aria-invalid="true"] {
    border-color: var(--late);
    border-width: 2px;
}

.field-error {
    margin: 0.25rem 0 0;
    color: var(--late);
    font-size: 0.875rem;
    font-weight: 600;
}

/* Repère visuel, en plus du texte et de la bordure ; texte de remplacement vide pour les lecteurs d’écran. */
.field-error::before {
    content: "⚠ " / "";
}

button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    min-width: var(--target);
    padding: 0.625rem 1.25rem;
    border: 0;
    border-radius: 999px;
    background: var(--accent);
    color: var(--surface);
    font-weight: 600;
    cursor: pointer;
}

button:hover {
    background: var(--accent-strong);
}

button.secondary {
    background: var(--soft);
    color: var(--accent);
}

button.plain {
    background: transparent;
    color: var(--accent);
    padding-left: 0.5rem;
    padding-right: 0.5rem;
}

button:disabled {
    cursor: progress;
    opacity: 0.7;
}

/* Liens dans le contenu : une cible de 44 px de haut au moins. */
main a {
    display: inline-flex;
    align-items: center;
    min-height: var(--target);
    padding: 0.25rem 0;
    color: var(--accent);
    text-decoration: underline;
}

:focus-visible {
    outline: 3px solid var(--focus);
    outline-offset: 2px;
}

/* La cible de « Aller au contenu » reçoit le focus sans contour permanent. */
main:focus {
    outline: none;
}

/* Les messages d’erreur portent aussi un texte et une bordure, pas seulement une couleur. */
[role="alert"] {
    padding: 0.75rem 1rem;
    border-left: 4px solid var(--late);
    border-radius: 0 12px 12px 0;
    background: var(--surface);
    color: var(--late);
    font-weight: 600;
}

/* ---------- Pages sans navigation : connexion, installation, erreurs ---------- */

.bare main {
    width: 100%;
    max-width: 32rem;
    margin: 0 auto;
    padding: 1.5rem 1rem 6rem;
}

figure {
    margin: 1rem 0;
}

figure svg {
    display: block;
    width: 100%;
    max-width: 16rem;
    height: auto;
    background: var(--surface);
}

/* Passage de la passkey au mot de passe sur la page de connexion. */
.separator {
    margin-top: 1.5rem;
    color: var(--text-secondary);
}

/* ---------- Cadre de l’utilisateur connecté ---------- */

.skip-link {
    position: absolute;
    top: 0.5rem;
    left: 0.5rem;
    z-index: 50;
    display: inline-flex;
    align-items: center;
    min-height: var(--target);
    padding: 0.5rem 1rem;
    border-radius: 999px;
    background: var(--accent);
    color: var(--surface);
    font-weight: 600;
    transform: translateY(-200%);
}

.skip-link:focus {
    transform: none;
}

.app {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    min-height: 100vh;
}

.main {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    align-content: start;
    gap: 1.125rem;
    width: 100%;
    max-width: 44rem;
    margin: 0 auto;
    padding: 1.25rem 1.375rem calc(var(--nav-height) + var(--safe-bottom) + 1.5rem);
}

.with-capture .main {
    padding-bottom: calc(var(--nav-height) + var(--safe-bottom) + 6rem);
}

.main > * {
    min-width: 0;
    margin: 0;
}

.intro {
    display: grid;
    gap: 0.25rem;
}

.eyebrow {
    margin: 0;
    color: var(--text-secondary);
    font-size: 0.75rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.back {
    justify-self: start;
    gap: 0.5rem;
    text-decoration: none;
}

.stack {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 0.75rem;
}

.center {
    display: flex;
    justify-content: center;
}

/* Boîtes et lignes */
.box {
    margin: 0;
    padding: 0;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    list-style: none;
    overflow: hidden;
}

.rows > li + li {
    border-top: 1px solid var(--line);
}

.main a.row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    width: 100%;
    min-height: 3.25rem;
    padding: 0.75rem 0.875rem;
    color: var(--text);
    text-decoration: none;
}

.main a.row:hover {
    background: #fafcfb;
}

.main a.row:focus-visible {
    outline-offset: -3px;
}

.grow {
    flex: 1;
    min-width: 0;
}

.title {
    display: block;
    font-weight: 550;
}

.meta {
    display: block;
    color: var(--text-secondary);
    font-size: 0.8125rem;
}

.empty {
    padding: 1.5rem 1rem;
    border: 1px dashed var(--field);
    border-radius: var(--radius);
    color: var(--text-secondary);
    text-align: center;
}

.empty p {
    margin: 0;
}

/* Barre basse (téléphone) */
.nav {
    position: fixed;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 10;
    padding: 0.375rem 0.5rem calc(0.375rem + var(--safe-bottom));
    border-top: 1px solid var(--line);
    background: var(--surface);
}

.nav ul {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0.125rem;
    margin: 0;
    padding: 0;
    list-style: none;
}

/*
 * Deux boîtes par onglet (issue #14) : le lien, sans arrondi, porte le
 * trait de l’onglet courant ; .nav-item porte les coins arrondis et le fond.
 * Le trait ne suit donc jamais la courbe des coins.
 */
.nav li a {
    position: relative;
    display: flex;
    min-height: 3.25rem;
    color: var(--text-secondary);
    font-size: 0.75rem;
    line-height: 1.2;
    text-align: center;
    text-decoration: none;
}

.nav-item {
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.1875rem;
    min-width: 0;
    padding: 0.375rem 0.125rem;
    border-radius: 12px;
}

/* Le contour de focus suit l’arrondi de la boîte intérieure. */
.nav li a:focus-visible {
    border-radius: 12px;
}

/* L’onglet courant : couleur, graisse et trait, pas seulement la couleur. */
.nav a[aria-current="page"] {
    color: var(--accent);
    font-weight: 650;
}

/*
 * Le trait : un segment droit, hors flux (aucun décalage au changement
 * d’onglet), posé sur la partie droite du bord, entre les deux arrondis.
 * Une bordure plutôt qu’un fond, pour rester visible en couleurs forcées.
 */
.nav a[aria-current="page"]::before {
    position: absolute;
    top: 0;
    right: 12px;
    left: 12px;
    border-top: 0.1875rem solid var(--accent);
    border-radius: 0;
    content: "";
    pointer-events: none;
}

.brand {
    display: none;
}

/* Bouton « Capturer » */
.fab {
    position: fixed;
    right: 1.125rem;
    bottom: calc(var(--nav-height) + var(--safe-bottom) + 1rem);
    z-index: 11;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    min-height: 3.25rem;
    padding: 0 1.25rem 0 1rem;
    border-radius: 999px;
    background: var(--accent);
    color: var(--surface);
    font-weight: 600;
    text-decoration: none;
    box-shadow: 0 8px 22px #157b7d45;
}

.fab:hover {
    background: var(--accent-strong);
}

/* Messages (toasts) : au-dessus du bouton « Capturer », jamais par-dessus la barre. */
.toasts {
    position: fixed;
    right: 1rem;
    bottom: calc(1rem + var(--safe-bottom));
    left: 1rem;
    z-index: 30;
    display: grid;
    gap: 0.5rem;
    max-width: 28rem;
    margin: 0 auto;
    pointer-events: none;
}

.with-shell .toasts {
    bottom: calc(var(--nav-height) + var(--safe-bottom) + 1rem);
}

.with-capture .toasts {
    bottom: calc(var(--nav-height) + var(--safe-bottom) + 5.25rem);
}

.toast {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.25rem 0.75rem;
    margin: 0;
    padding: 0.5rem 0.5rem 0.5rem 1rem;
    border-radius: 14px;
    background: #20393a;
    color: var(--surface);
    font-size: 0.9375rem;
    pointer-events: auto;
}

p.toast {
    min-height: var(--target);
    padding-right: 1rem;
}

.toast span {
    flex: 1 1 10rem;
    min-width: 0;
}

.toast button {
    min-height: var(--target);
    padding: 0.5rem 0.75rem;
    background: transparent;
    color: #9fe0d6;
    text-decoration: underline;
}

.toast button:hover {
    background: #ffffff1a;
}

.toast button.close {
    text-decoration: none;
}

/* ---------- Capture et Boîte de réception (B07) ---------- */

.lead {
    margin: 0.25rem 0 0;
    color: var(--text-secondary);
}

.capture-form > p {
    margin: 0;
}

.capture-form .center {
    text-align: center;
}

/* En-tête d’une liste : décompte et ordre. */
.heading {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 0.25rem 1rem;
    color: var(--text-secondary);
    font-size: 0.8125rem;
}

.capture-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem 0.75rem;
    padding: 0.75rem 0.875rem;
}

.capture-row p {
    margin: 0;
}

/* Le texte saisi s’affiche en entier, retours à la ligne compris. */
.capture-text {
    white-space: pre-line;
}

.capture-row form {
    margin-left: auto;
}

/* Surimpression de capture : une feuille en bas de l’écran sur téléphone, centrée sur ordinateur. */
dialog.sheet {
    width: 100%;
    max-width: 40rem;
    max-height: 88vh;
    margin: auto auto 0;
    padding: 0.75rem 1.375rem calc(1.5rem + var(--safe-bottom));
    border: 0;
    border-radius: 24px 24px 0 0;
    background: var(--background);
    color: var(--text);
    overflow-y: auto;
}

dialog.sheet[open] {
    display: grid;
    gap: 0.75rem;
}

dialog.sheet::backdrop {
    background: #18302c55;
}

.sheet-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
}

.sheet-head h2 {
    margin: 0;
}

/* Liste des passkeys (B05) : une carte par passkey, bouton de révocation dessous. */
.passkeys {
    padding: 0;
    list-style: none;
}

.passkeys li {
    margin-bottom: 0.75rem;
    padding: 0.75rem 1rem;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
}

.passkeys form {
    margin-top: 0.5rem;
}

/* ---------- Ordinateur : colonne latérale (D14) ---------- */

@media (min-width: 960px) {
    .app {
        grid-template-columns: 15rem minmax(0, 1fr);
    }

    .nav {
        position: sticky;
        top: 0;
        bottom: auto;
        display: flex;
        flex-direction: column;
        gap: 1.25rem;
        height: 100vh;
        padding: 1.5rem 1rem;
        border-top: 0;
        border-right: 1px solid var(--line);
    }

    .brand {
        display: inline-flex;
        align-items: center;
        gap: 0.5rem;
        min-height: var(--target);
        padding: 0 0.75rem;
        color: var(--text);
        font-size: 1.3rem;
        font-weight: 650;
        letter-spacing: -0.03em;
        text-decoration: none;
    }

    .brand .icon {
        color: var(--accent);
    }

    .nav ul {
        grid-template-columns: minmax(0, 1fr);
        gap: 0.25rem;
    }

    .nav li a {
        min-height: var(--target);
        font-size: 0.9375rem;
        text-align: left;
    }

    .nav-item {
        flex-direction: row;
        justify-content: flex-start;
        gap: 0.75rem;
        padding: 0.5rem 0.75rem;
    }

    .nav a[aria-current="page"] .nav-item {
        background: var(--soft);
    }

    .nav a[aria-current="page"]::before {
        top: 12px;
        right: auto;
        bottom: 12px;
        left: 0;
        border-top: 0;
        border-left: 0.1875rem solid var(--accent);
    }

    .main,
    .with-capture .main {
        padding: 2rem 2rem 7rem;
    }

    .fab {
        bottom: 1.5rem;
        right: 2rem;
    }

    dialog.sheet {
        margin: auto;
        border-radius: var(--radius);
    }

    .with-shell .toasts,
    .with-capture .toasts {
        bottom: 6rem;
        left: 16rem;
    }
}

@media (max-width: 380px) {
    .main {
        padding-left: 1rem;
        padding-right: 1rem;
    }
}
