/*
 * Charte Champ Libre (vert sapin #1D4145, Montserrat) sur une base sobre façon iOS.
 * Thème clair et sombre suivis automatiquement ; tailles en rem pour respecter
 * la taille de texte choisie sur l'appareil.
 */

@font-face {
    font-family: 'Montserrat';
    src: url("../fonts/montserrat-regular-CQBBhOQ.woff2") format('woff2');
    font-weight: 400;
    font-display: swap;
}

@font-face {
    font-family: 'Montserrat';
    src: url("../fonts/montserrat-medium--JXSJN8.woff2") format('woff2');
    font-weight: 500;
    font-display: swap;
}

@font-face {
    font-family: 'Montserrat';
    src: url("../fonts/montserrat-semibold-gsz9ESR.woff2") format('woff2');
    font-weight: 600;
    font-display: swap;
}

:root {
    color-scheme: light dark;

    --brand: #1d4145;
    --background: #f6f4ef;
    --surface: #ffffff;
    --text: #1c1c1e;
    --text-secondary: #5f6466;
    --separator: rgb(60 60 67 / 0.18);
    --danger: #c0392b;
    --danger-surface: #fbeceb;
    --on-brand: #ffffff;
    --logo-filter: none;

    /* Zone tactile minimale (Apple : 44 pt). */
    --touch-target: 2.75rem;
    --radius: 0.875rem;
}

@media (prefers-color-scheme: dark) {
    :root {
        /* Le vert sapin sur fond sombre manque de contraste : version éclaircie. */
        --brand: #8fc1bc;
        --background: #0e1a1b;
        --surface: #172628;
        --text: #f2f2f0;
        --text-secondary: #a3acad;
        --separator: rgb(235 235 245 / 0.16);
        --danger: #ff8a7a;
        --danger-surface: #3a1f1c;
        --on-brand: #0e1a1b;
        /* Logo au trait noir sur fond transparent : inversé en blanc. */
        --logo-filter: invert(1);
    }
}

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

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

body {
    margin: 0;
    min-height: 100dvh;
    background: var(--background);
    color: var(--text);
    font: 400 1rem/1.5 'Montserrat', system-ui, -apple-system, sans-serif;
    -webkit-font-smoothing: antialiased;
}

/* --- Accueil ------------------------------------------------------------ */

.welcome {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    min-height: 100dvh;
    padding: max(2rem, env(safe-area-inset-top)) 1.5rem max(2rem, env(safe-area-inset-bottom));
    text-align: center;
}

.welcome__logo {
    width: min(14rem, 60vw);
    height: auto;
    filter: var(--logo-filter);
}

.welcome__title {
    margin: 0.5rem 0 0;
    color: var(--brand);
    font-size: clamp(2.5rem, 6vw, 3.5rem);
    font-weight: 600;
    line-height: 1.05;
    /* Grand titre : interlettrage resserré. */
    letter-spacing: -0.02em;
}

.welcome__lead {
    max-width: 28rem;
    margin: 0;
    font-size: 1.125rem;
    line-height: 1.45;
}

.welcome__status {
    margin: 1rem 0 0;
    color: var(--text-secondary);
    font-size: 0.875rem;
    /* Petit texte : interlettrage légèrement ouvert pour la lisibilité. */
    letter-spacing: 0.01em;
}

/* --- Connexion ---------------------------------------------------------- */

.login {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    min-height: 100dvh;
    padding: max(2.5rem, env(safe-area-inset-top)) 1.25rem max(2rem, env(safe-area-inset-bottom));
    text-align: center;
}

.login__logo {
    width: min(9rem, 40vw);
    height: auto;
    filter: var(--logo-filter);
}

.login__title {
    margin: 0.25rem 0 0;
    color: var(--brand);
    font-size: 2.25rem;
    font-weight: 600;
    line-height: 1.1;
    letter-spacing: -0.02em;
}

.login__lead {
    margin: 0 0 1rem;
    color: var(--text-secondary);
}

.login__form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    width: min(100%, 24rem);
    text-align: start;
}

/* --- Écrans ------------------------------------------------------------- */

.screen {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    width: min(100%, 40rem);
    min-height: 100dvh;
    margin: 0 auto;
    padding: max(1.5rem, env(safe-area-inset-top)) 1.25rem max(2rem, env(safe-area-inset-bottom));
}

.screen--centered {
    align-items: center;
    text-align: center;
}

.screen__title {
    margin: 0;
    color: var(--brand);
    font-size: 2rem;
    font-weight: 600;
    line-height: 1.1;
    letter-spacing: -0.02em;
}

.screen__lead {
    margin: -0.5rem 0 0;
    color: var(--text-secondary);
}

.back-link {
    display: inline-flex;
    align-items: center;
    align-self: flex-start;
    min-height: var(--touch-target);
    color: var(--brand);
    font-weight: 500;
    text-decoration: none;
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
}

.welcome__action {
    width: auto;
    margin-top: 1.5rem;
    text-decoration: none;
}

/* --- Bandeau du vendeur ------------------------------------------------- */

.seller-banner {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: max(0.25rem, env(safe-area-inset-top)) 1.25rem 0.25rem;
    /* Matériau translucide : le contenu défile dessous. */
    background: color-mix(in srgb, var(--background) 80%, transparent);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    backdrop-filter: blur(20px) saturate(180%);
    border-bottom: 1px solid var(--separator);
}

.seller-banner p {
    margin: 0;
}

.seller-banner__who {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex: 1;
    min-width: 0;
}

.seller-banner__name {
    overflow: hidden;
    font-size: 1.125rem;
    font-weight: 600;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.seller-banner__change {
    display: inline-flex;
    align-items: center;
    min-height: var(--touch-target);
    color: var(--brand);
    font-weight: 500;
    text-decoration: none;
}

.seller-banner__countdown {
    color: var(--text-secondary);
    font-size: 0.875rem;
    font-variant-numeric: tabular-nums;
}

.seller-banner__end {
    margin: 0;
}

@media (prefers-reduced-transparency: reduce) {
    .seller-banner {
        background: var(--background);
        -webkit-backdrop-filter: none;
        backdrop-filter: none;
    }
}

.notice--flash {
    width: min(calc(100% - 2.5rem), 40rem);
    margin: 1rem auto 0;
}

/* --- Formulaire de déclaration ----------------------------------------- */

.report-form {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.report-form__section {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    min-width: 0;
    margin: 0;
    padding: 0;
    border: 0;
}

.report-form__row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr));
    gap: 1.25rem;
}

.report-form__label {
    padding: 0;
    color: var(--text-secondary);
    font-size: 0.8125rem;
    font-weight: 500;
    letter-spacing: 0.01em;
}

.report-form__input {
    width: 100%;
    min-height: var(--touch-target);
    padding: 0.625rem 0.875rem;
    border: 1px solid transparent;
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    font: inherit;
    /* 1 rem au moins : en dessous, Safari iOS zoome au focus. */
    font-size: max(1rem, 17px);
}

.report-form__input:focus-visible {
    border-color: var(--brand);
    outline: none;
}

textarea.report-form__input {
    resize: vertical;
}

.money {
    position: relative;
}

.money .report-form__input {
    padding-right: 2.25rem;
}

.money__currency {
    position: absolute;
    top: 50%;
    right: 0.875rem;
    color: var(--text-secondary);
    transform: translateY(-50%);
    pointer-events: none;
}

.report-form__total {
    margin: 0;
    color: var(--text-secondary);
}

.report-form__total strong {
    color: var(--text);
    font-size: 1.125rem;
    font-variant-numeric: tabular-nums;
}

.form-error {
    margin: 0;
    color: var(--danger);
    font-size: 0.875rem;
}

/* Tuiles des familles : de grosses cibles, choisies d'un coup d'œil. */
.family-tiles {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(9.5rem, 1fr));
    gap: 0.625rem;
}

.family-tiles__input,
.segmented__input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.family-tiles__tile {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 4rem;
    padding: 0.5rem 0.75rem;
    border: 2px solid transparent;
    border-radius: var(--radius);
    background: var(--surface);
    font-weight: 500;
    line-height: 1.25;
    text-align: center;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    transition: transform 100ms ease-out, background-color 100ms ease-out, border-color 100ms ease-out;
}

.family-tiles__tile:active {
    transform: scale(0.97);
}

.family-tiles__input:checked + .family-tiles__tile {
    border-color: var(--brand);
    background: color-mix(in srgb, var(--brand) 12%, var(--surface));
    color: var(--brand);
}

.family-tiles__input:focus-visible + .family-tiles__tile,
.segmented__input:focus-visible + .segmented__option {
    outline: 3px solid var(--brand);
    outline-offset: 2px;
}

/* Quantité : − / + de part et d'autre du champ. */
.stepper {
    display: grid;
    grid-template-columns: var(--touch-target) 1fr var(--touch-target);
    overflow: hidden;
    border-radius: var(--radius);
    background: var(--surface);
}

.stepper__button {
    min-height: var(--touch-target);
    border: 0;
    background: transparent;
    color: var(--brand);
    font: inherit;
    font-size: 1.5rem;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.stepper__button:active {
    background: var(--separator);
}

.stepper__input {
    width: 100%;
    min-width: 0;
    border: 0;
    background: transparent;
    color: var(--text);
    font: inherit;
    font-size: 1.25rem;
    font-variant-numeric: tabular-nums;
    text-align: center;
    -moz-appearance: textfield;
    appearance: textfield;
}

.stepper__input::-webkit-inner-spin-button,
.stepper__input::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

/* Unité : contrôle segmenté façon iOS. */
.segmented {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.25rem;
    padding: 0.25rem;
    border-radius: var(--radius);
    background: var(--separator);
}

.segmented__option {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: calc(var(--touch-target) - 0.5rem);
    border-radius: calc(var(--radius) - 0.25rem);
    font-weight: 500;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    transition: background-color 150ms ease-out;
}

.segmented__input:checked + .segmented__option {
    background: var(--surface);
    box-shadow: 0 1px 3px rgb(0 0 0 / 0.12);
}

/* --- Choix du prénom ----------------------------------------------------- */

.seller-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(9rem, 1fr));
    gap: 0.75rem;
}

.seller-grid__item {
    display: flex;
    align-items: center;
    justify-content: center;
    /* Grandes cibles : on choisit debout, souvent d'une main. */
    min-height: 4.5rem;
    padding: 0.75rem;
    background: var(--surface);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 1.125rem;
    font-weight: 500;
    text-align: center;
    text-decoration: none;
    -webkit-tap-highlight-color: transparent;
    transition: transform 100ms ease-out, background-color 100ms ease-out;
}

.seller-grid__item:active {
    transform: scale(0.97);
    background: var(--separator);
}

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

/* --- PIN ----------------------------------------------------------------- */

.pin {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.25rem;
    width: min(100%, 20rem);
}

.pin__field {
    width: 100%;
}

.pin__input {
    width: 100%;
    min-height: var(--touch-target);
    border: 0;
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    font: inherit;
    font-size: 1.5rem;
    letter-spacing: 0.5em;
    text-align: center;
}

/* Avec le pavé, les points remplacent le champ. */
.pin:has(.pin__pad:not([hidden])) .pin__field {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.pin__dots {
    display: flex;
    gap: 1.25rem;
}

.pin:not(:has(.pin__pad:not([hidden]))) .pin__dots {
    display: none;
}

.pin__dot {
    width: 0.875rem;
    height: 0.875rem;
    border: 2px solid var(--brand);
    border-radius: 50%;
    transition: background-color 100ms ease-out;
}

.pin__dot--filled {
    background: var(--brand);
}

.pin__pad {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.875rem 1.25rem;
}

.pin__pad[hidden] {
    display: none;
}

.pin__key {
    width: 4.75rem;
    height: 4.75rem;
    border: 0;
    border-radius: 50%;
    background: var(--surface);
    color: var(--text);
    font: inherit;
    font-size: 1.75rem;
    font-weight: 500;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    transition: transform 100ms ease-out, background-color 100ms ease-out;
}

/* Retour à l'appui, comme le pavé de l'iPhone. */
.pin__key:active {
    transform: scale(0.94);
    background: var(--separator);
}

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

.pin__key--erase {
    background: transparent;
    font-size: 1.5rem;
}

/* --- Champs groupés (liste groupée iOS) ---------------------------------- */

.field-group {
    overflow: hidden;
    background: var(--surface);
    border-radius: var(--radius);
}

.field {
    display: flex;
    flex-direction: column;
    padding: 0.5rem 1rem;
}

.field + .field {
    /* Séparateur en retrait à gauche, comme les listes iOS. */
    margin-left: 1rem;
    padding-left: 0;
    border-top: 1px solid var(--separator);
}

.field__label {
    color: var(--text-secondary);
    font-size: 0.8125rem;
    letter-spacing: 0.01em;
}

.field__input {
    min-height: var(--touch-target);
    padding: 0;
    border: 0;
    background: transparent;
    color: var(--text);
    /* 1 rem au moins : en dessous, Safari iOS zoome au focus. */
    font: inherit;
    font-size: max(1rem, 17px);
    outline: none;
}

.field:focus-within .field__label {
    color: var(--brand);
}

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

.button {
    min-height: var(--touch-target);
    padding: 0.75rem 1.25rem;
    border: 0;
    border-radius: var(--radius);
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    transition: transform 100ms ease-out, opacity 100ms ease-out;
}

/* Retour immédiat à l'appui, pas au relâchement. */
.button:active {
    transform: scale(0.97);
    opacity: 0.85;
}

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

.button--primary {
    width: 100%;
    background: var(--brand);
    color: var(--on-brand);
}

.button--plain {
    margin-top: 0.5rem;
    background: transparent;
    color: var(--brand);
}

/* --- Messages ------------------------------------------------------------ */

.notice {
    margin: 0;
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    font-size: 0.9375rem;
    line-height: 1.4;
}

.notice:not(.notice--error) {
    background: var(--surface);
    color: var(--text);
}

.notice--error {
    background: var(--danger-surface);
    color: var(--danger);
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}
