/* ===================================================================
   Liste de courses familiale — feuille de style mobile-first
   =================================================================== */

:root {
    --accent: #16A34A;
    --accent-dark: #15803D;
    --danger: #DC2626;
    --bg: #F3F4F6;
    --surface: #FFFFFF;
    --text: #111827;
    --text-muted: #6B7280;
    --border: #E5E7EB;
    --radius: 14px;
    --topbar-h: 56px;
    --tap: 48px; /* cible tactile minimale */
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
}

body {
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    -webkit-tap-highlight-color: transparent;
    overscroll-behavior-y: contain;
}

h1, h2, p { margin: 0; }
button { font-family: inherit; cursor: pointer; }
ul { list-style: none; margin: 0; padding: 0; }

h1:focus { outline: none; }

/* ---------- Avatar ---------- */
.avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    color: #fff;
    font-weight: 700;
    font-size: 0.85rem;
    flex: 0 0 auto;
    user-select: none;
}

.avatar--lg {
    width: 84px;
    height: 84px;
    font-size: 1.9rem;
}

/* ---------- Barre supérieure ---------- */
.topbar {
    position: sticky;
    top: 0;
    z-index: 30;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: calc(var(--topbar-h) + var(--safe-top));
    padding: var(--safe-top) 14px 0;
    background: var(--accent);
    color: #fff;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
}

.topbar__brand {
    font-weight: 700;
    font-size: 1.15rem;
}

.topbar__profile {
    border: 2px solid rgba(255, 255, 255, 0.7);
    border-radius: 50%;
    padding: 0;
    background: none;
    line-height: 0;
}

/* ---------- Menu (profil + actions) ---------- */
.menu-backdrop {
    position: fixed;
    inset: 0;
    z-index: 35;
}

.menu {
    position: absolute;
    z-index: 40;
    background: var(--surface);
    border-radius: 12px;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.18);
    overflow: hidden;
    min-width: 220px;
}

.topbar .menu {
    top: calc(var(--topbar-h) + var(--safe-top) - 4px);
    right: 12px;
}

.menu__header {
    padding: 12px 16px;
    font-weight: 700;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
}

.menu__form { margin: 0; }

.menu__item {
    display: flex;
    align-items: center;
    width: 100%;
    min-height: var(--tap);        /* cible tactile (≥ 48px) */
    text-align: left;
    border: none;
    background: none;
    padding: 12px 16px;
    font-size: 1rem;
    color: var(--text);
}

.menu__item:active { background: var(--bg); }
.menu__item:disabled { color: #C2C7CF; }
.menu__item--danger { color: var(--danger); }

/* ---------- Contenu ---------- */
.content {
    max-width: 640px;
    margin: 0 auto;
    padding: 12px 12px calc(96px + var(--safe-bottom));
}

/* ---------- En-tête de liste : onglets + actions ---------- */
.list-header {
    position: relative;
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
}

/* Barre de tri (GH#10) : sous l'en-tête, au-dessus de la liste. */
.sortbar {
    margin-bottom: 12px;
}

.segmented {
    flex: 1;
    display: flex;
    background: #E5E7EB;
    border-radius: 12px;
    padding: 4px;
    gap: 4px;
}

.segmented__btn {
    flex: 1;
    border: none;
    background: none;
    border-radius: 9px;
    padding: 0 8px;
    height: 40px;
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-muted);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.segmented__btn.is-active {
    background: var(--surface);
    color: var(--text);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
}

.pill {
    background: var(--accent);
    color: #fff;
    border-radius: 999px;
    font-size: 0.72rem;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.segmented__btn:not(.is-active) .pill { background: #9CA3AF; }

/* ---------- Boutons icônes ---------- */
.iconbtn {
    width: var(--tap);
    height: var(--tap);
    border: none;
    background: none;
    border-radius: 10px;
    font-size: 1.2rem;
    color: var(--text-muted);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
}

.iconbtn:active { background: var(--bg); }
.iconbtn--actions { background: #E5E7EB; color: var(--text); font-size: 1.5rem; }

.list-header .menu--actions {
    top: calc(100% + 6px);
    right: 0;
}

/* ---------- Articles ---------- */
.items { display: flex; flex-direction: column; gap: 8px; }

.item {
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--surface);
    border-radius: var(--radius);
    padding: 8px 8px 8px 12px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
    min-height: 60px;
    /* Swipe pour déplacer : pan-y laisse le scroll vertical natif au navigateur et ne
       livre que le geste horizontal au JS. La transition anime le retour / la sortie ;
       .item--swiping la coupe pour suivre le doigt 1:1. */
    touch-action: pan-y;
    transition: transform .18s ease;
}

.item--checked { background: #ECFDF3; }

.item__name {
    flex: 1;
    font-size: 1.05rem;
    word-break: break-word;
    /* « juste coché », jamais barré : on ne met PAS de line-through */
}

/* Checkbox tactile personnalisée */
.check {
    position: relative;
    width: var(--tap);
    height: var(--tap);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
}

.check input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; }

.check__box {
    width: 28px;
    height: 28px;
    border: 2px solid #CBD5E1;
    border-radius: 8px;
    background: #fff;
    transition: background-color .12s, border-color .12s;
}

.check input:checked + .check__box {
    background: var(--accent);
    border-color: var(--accent);
}

.check input:checked + .check__box::after {
    content: "";
    position: absolute;
    left: 50%;
    top: 47%;
    width: 7px;
    height: 13px;
    border: solid #fff;
    border-width: 0 3px 3px 0;
    transform: translate(-50%, -55%) rotate(45deg);
}

/* Bouton +1 « ça m'intéresse aussi » */
.plusone {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    border: 1.5px solid var(--border);
    background: #fff;
    color: var(--text-muted);
    border-radius: 999px;
    height: 38px;
    padding: 0 10px;
    font-weight: 700;
    font-size: 0.85rem;
    flex: 0 0 auto;
    white-space: nowrap;
}

.plusone__count {
    background: var(--accent);
    color: #fff;
    border-radius: 999px;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    font-size: 0.72rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.plusone.is-mine { background: var(--accent); border-color: var(--accent); color: #fff; }
.plusone.is-mine .plusone__count { background: #fff; color: var(--accent); }
.plusone:active { transform: scale(0.94); }

/* Une seule cible secondaire sur la ligne (« ⋯ ») : on garde la cible tactile pleine
   (var(--tap) = 48px) et l'espacement aéré de base — plus besoin de compacter. */
.item .avatar { width: 28px; height: 28px; font-size: 0.72rem; }
.item__name { min-width: 0; }

/* Menu d'actions par article (réutilise .menu / .menu__item), ancré sous le « ⋯ ». */
.itemmenu { position: relative; flex: 0 0 auto; }
.menu--item-actions { top: calc(100% + 4px); right: 0; }

/* Champ d'édition inline du libellé (remplace .item__name pendant l'édition). */
.item__edit {
    flex: 1;
    min-width: 0;
    height: 40px;
    border: 1.5px solid var(--accent);
    border-radius: 10px;
    padding: 0 12px;
    font-size: 1.05rem;
    font-family: inherit;
    background: #fff;
    color: var(--text);
}

.item__edit:focus { outline: none; }

/* Pendant le geste : la ligne suit le doigt sans transition. À la sortie : on l'estompe
   et on coupe les interactions le temps de l'animation avant que .NET ne retire la ligne. */
.item--swiping { transition: none; will-change: transform; }
.item--leaving { opacity: .5; pointer-events: none; }

/* Regroupement nom + badge rayon dans la colonne centrale de l'article. */
.item__body {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

/* Badge de rayon discret — visible quel que soit le tri actif. */
.category-badge {
    display: inline-block;
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--accent-dark);
    background: #DCFCE7;
    border-radius: 999px;
    padding: 1px 8px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
    align-self: flex-start;
}

/* Zone d'édition inline du rayon (remplace .item__name + badge pendant l'édition). */
.item__category-edit {
    flex: 1;
    min-width: 0;
    position: relative;
}

.item__edit--category {
    width: 100%;
}

/* Liste de suggestions d'autocomplétion (Blazor pur, zéro JS). */
.autocomplete {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    z-index: 45;
    background: var(--surface);
    border-radius: 12px;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.18);
    overflow: hidden;
    max-height: 200px;
    overflow-y: auto;
    padding: 4px 0;
}

.autocomplete__item {
    padding: 10px 16px;
    font-size: 0.95rem;
    cursor: pointer;
    color: var(--text);
    min-height: var(--tap);
    display: flex;
    align-items: center;
}

.autocomplete__item:active,
.autocomplete__item.is-selected {
    background: var(--bg);
}

/* En-tête de section pour le tri « Rayon » (Home.razor). */
.section-header {
    font-size: 0.8rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    padding: 16px 4px 6px;
}

.section-header--uncategorized {
    color: #9CA3AF;
}

/* ---------- Page Rayons (/rayons) ---------- */
.categories-page { }

.categories-page__title {
    font-size: 1.2rem;
    font-weight: 700;
    margin-bottom: 16px;
    color: var(--text);
}

.category-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.category-item {
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--surface);
    border-radius: var(--radius);
    padding: 8px 8px 8px 12px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
    min-height: 56px;
}

.category-item__name {
    flex: 1;
    font-size: 1rem;
    word-break: break-word;
}

.category-item__edit {
    flex: 1;
    min-width: 0;
    height: 40px;
    border: 1.5px solid var(--accent);
    border-radius: 10px;
    padding: 0 12px;
    font-size: 1rem;
    font-family: inherit;
    background: #fff;
    color: var(--text);
}

.category-item__edit:focus { outline: none; }

.category-item__actions {
    display: flex;
    align-items: center;
    gap: 4px;
    flex: 0 0 auto;
}

.category-item__order {
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex: 0 0 auto;
}

.iconbtn--sm {
    width: 36px;
    height: 36px;
    font-size: 1rem;
}

/* ---------- Barre d'ajout collante ---------- */
.addbar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 25;
    display: flex;
    gap: 8px;
    padding: 10px 12px calc(10px + var(--safe-bottom));
    background: var(--surface);
    border-top: 1px solid var(--border);
    max-width: 640px;
    margin: 0 auto;
}

.addbar__input {
    flex: 1;
    height: var(--tap);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 0 14px;
    font-size: 1rem;
    background: var(--bg);
}

.addbar__input:focus {
    outline: none;
    border-color: var(--accent);
    background: #fff;
}

.addbar__btn {
    width: var(--tap);
    height: var(--tap);
    border: none;
    border-radius: 12px;
    background: var(--accent);
    color: #fff;
    font-size: 1.8rem;
    line-height: 1;
    flex: 0 0 auto;
}

.addbar__btn:disabled { background: #9CA3AF; }
.addbar__btn:active:not(:disabled) { background: var(--accent-dark); }

/* ---------- États vides / chargement ---------- */
.state {
    text-align: center;
    color: var(--text-muted);
    padding: 48px 16px;
}

.state__icon { font-size: 3rem; }
.state__hint { font-size: 0.9rem; margin-top: 4px; }

/* ---------- Boutons génériques ---------- */
.btn {
    border: none;
    border-radius: 12px;
    height: var(--tap);
    padding: 0 20px;
    font-size: 1rem;
    font-weight: 600;
}

.btn--primary { background: var(--accent); color: #fff; }
.btn--primary:active { background: var(--accent-dark); }
.btn--danger { background: var(--danger); color: #fff; }
.btn--ghost { background: var(--bg); color: var(--text); }

/* ---------- Porte d'entrée (login) ---------- */
.gate {
    min-height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: linear-gradient(160deg, var(--accent), var(--accent-dark));
}

.gate__card {
    background: var(--surface);
    border-radius: 20px;
    padding: 32px 24px;
    width: 100%;
    max-width: 360px;
    text-align: center;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.25);
}

.gate__logo { font-size: 3rem; }
.gate__title { font-size: 1.4rem; margin-top: 8px; }
.gate__sub { color: var(--text-muted); margin: 6px 0 20px; }
.gate__form { display: flex; flex-direction: column; gap: 12px; }

.gate__input {
    height: 52px;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 0 16px;
    font-size: 1.3rem;
    text-align: center;
    letter-spacing: 0.3em;
}

.gate__input:focus { outline: none; border-color: var(--accent); }
.gate__btn { width: 100%; }
.gate__error { color: var(--danger); margin-top: 14px; font-weight: 600; }

/* Bouton « Installer l'app » (PWA) — n'apparaît que si le navigateur le propose */
.install-btn {
    width: 100%;
    margin-top: 18px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.install-btn:active { background: var(--border); }
.install-btn__icon { font-size: 1.2rem; line-height: 1; }

.install-hint {
    margin-top: 18px;
    font-size: 0.9rem;
    color: var(--text-muted);
    line-height: 1.45;
}

/* ---------- Sélection de profil (Netflix) ---------- */
.profiles {
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 32px 16px calc(32px + var(--safe-bottom));
    background: #111827;
    color: #fff;
}

.profiles__title { font-size: 1.6rem; margin-bottom: 32px; text-align: center; }

.profiles__grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
    gap: 20px;
    width: 100%;
    max-width: 480px;
}

.profile {
    background: none;
    border: none;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    color: #fff;
    padding: 8px;
    border-radius: 14px;
}

.profile:active { background: rgba(255, 255, 255, 0.08); }
.profile .avatar--lg { transition: transform .12s; }
.profile:active .avatar--lg { transform: scale(0.94); }
.profile__name { font-size: 1rem; font-weight: 600; }

/* ---------- Modale de confirmation ---------- */
.modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 50;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.modal {
    background: var(--surface);
    border-radius: 16px;
    padding: 24px;
    width: 100%;
    max-width: 360px;
}

.modal__title { font-size: 1.2rem; }
.modal__msg { color: var(--text-muted); margin: 12px 0 24px; }
.modal__actions { display: flex; gap: 10px; }
.modal__actions .btn { flex: 1; }

/* ---------- UI d'erreur Blazor (vit dans App.razor) ---------- */
#blazor-error-ui {
    color-scheme: light only;
    background: lightyellow;
    bottom: 0;
    box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
    box-sizing: border-box;
    display: none;
    left: 0;
    padding: 0.6rem 1.25rem 0.7rem 1.25rem;
    position: fixed;
    width: 100%;
    z-index: 1000;
}

#blazor-error-ui .dismiss {
    cursor: pointer;
    position: absolute;
    right: 0.75rem;
    top: 0.5rem;
}

.blazor-error-boundary {
    background: #b32121;
    padding: 1rem;
    color: white;
}

.blazor-error-boundary::after { content: "Une erreur est survenue."; }
