/* Thème : les couleurs viennent de js/theme.js (mêmes styles que l'app Android : clair / sombre / système + 8 palettes),
   qui pose ces variables sur <html> avant le premier affichage. Les valeurs ci-dessous (vert « forêt » clair) ne servent
   que de repli si le script ne s'exécute pas. */
:root {
    --primary: #2e6b41;
    --primary-contrast: #ffffff;
    --primary-soft: #b2f1be;
    --on-primary-soft: #00210e;
    --bg: #f6fbf3;
    --surface: #ffffff;
    --surface-high: #e3ece4;
    --text: #17211a;
    --muted: #4a5c4e;
    --track: #dfe8e0;
    --outline: #6e7f72;
    --border: #cbd8cd;
    --danger: #b3261e;
    --shadow: 0 1px 3px rgba(0, 0, 0, .12);
    --accent-1: #2f8f4d;
    --accent-2: #2d8f9a;
    --accent-3: #4fbf6d;
    --accent-gradient: linear-gradient(90deg, var(--accent-1), var(--accent-2), var(--accent-3));
    --accent-loop: linear-gradient(90deg, var(--accent-1), var(--accent-2), var(--accent-3), var(--accent-1));
    --rayon-1: #2f8f4d; --rayon-2: #2d8f9a; --rayon-3: #4fbf6d; --rayon-4: #6bb04f; --rayon-5: #3d9fb0; --rayon-6: #5bc07f;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    line-height: 1.4;
}

a { color: var(--primary); }
h1 { font-size: 1.6rem; margin: .2rem 0 .8rem; }
h2 { font-size: 1.2rem; margin: 0 0 .6rem; }
h3.section { font-size: .85rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 1.4rem 0 .4rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.center { text-align: center; }
.error { color: var(--danger); }
.grow { flex: 1; min-width: 0; }

/* ---- Écran de démarrage / connexion ---- */
.boot { display: grid; place-items: center; min-height: 60vh; color: var(--muted); }
.boot-logo { font-size: 3rem; width: 5rem; height: 5rem; border-radius: 50%; background: var(--primary); display: grid; place-items: center; margin: 0 auto .5rem; }
.login h1 { margin-top: 0; }

/* ---- Structure ---- */
.topbar { display: flex; align-items: center; gap: 1rem; padding: .5rem 1rem; background: var(--surface); position: sticky; top: 0; z-index: 5; }
/* Ruban de couleur qui défile doucement sous la barre du haut (dégradé du style choisi ; arc-en-ciel pour « Fierté »). */
.topbar::after { content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 4px; background: var(--accent-loop) 0 0 / 800px 100% repeat-x; animation: accent-shift 10s linear infinite; }
[data-palette="pride"] .topbar::after { animation-duration: 6s; }
@keyframes accent-shift { to { background-position-x: 800px; } }
.brand { font-weight: 700; text-decoration: none; color: var(--text); white-space: nowrap; }
.topbar nav { display: flex; align-items: center; gap: .25rem; margin-left: auto; }
.topbar nav a { padding: .45rem .7rem; border-radius: 999px; text-decoration: none; color: var(--text); position: relative; }
.topbar nav a.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.topbar .profile-link { padding: .15rem; }
.badge { display: inline-block; min-width: 1.25rem; padding: 0 .35rem; margin-left: .25rem; border-radius: 999px; background: #b3261e; color: #fff; font-size: .75rem; text-align: center; line-height: 1.25rem; }

.page { max-width: 760px; margin: 0 auto; padding: 1rem; }
.page.narrow { max-width: 420px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: .75rem; flex-wrap: wrap; margin-bottom: .5rem; }
.page-head h1 { margin-bottom: 0; }
.back { font-size: .9rem; text-decoration: none; }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; }

/* ---- Boutons et champs ---- */
.btn { border: 1px solid var(--border); background: var(--surface); color: var(--text); padding: .55rem 1rem; border-radius: 999px; font: inherit; cursor: pointer; text-decoration: none; display: inline-block; }
.btn:hover:not(:disabled) { border-color: var(--primary); }
.btn.primary { background: var(--primary); color: var(--primary-contrast); border-color: var(--primary); font-weight: 600; }
.btn.danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn.small { padding: .25rem .7rem; font-size: .85rem; }
.btn.wide { width: 100%; margin-top: .5rem; }
.btn:disabled { opacity: .5; cursor: default; }
.danger-text { color: var(--danger); }
.link, .linklike { background: none; border: 0; padding: 0; font: inherit; color: var(--primary); cursor: pointer; text-align: left; }
.linklike { color: inherit; }
.icon-btn { background: none; border: 0; color: var(--muted); font-size: 1.2rem; cursor: pointer; padding: .3rem .5rem; border-radius: 50%; }
.icon-btn:hover { background: var(--primary-soft); }

.field { display: block; margin: .6rem 0; }
.field > span { display: block; font-size: .85rem; color: var(--muted); margin-bottom: .2rem; }
input, textarea, select { width: 100%; font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: .55rem .7rem; }
input:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; }
input[type=checkbox] { width: 1.2rem; height: 1.2rem; accent-color: var(--primary); flex: none; }
.add-row { display: flex; gap: .5rem; margin: .5rem 0 1rem; }
.add-row .qty { width: 8rem; flex: none; }

/* ---- Cartes et rangées ---- */
.cards, .rows { list-style: none; margin: 0; padding: 0; }
.cards { display: grid; gap: .75rem; }
.card { display: flex; align-items: center; gap: .75rem; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: .75rem .5rem .75rem 1.3rem; box-shadow: var(--shadow); position: relative; overflow: visible;
    animation: card-in .42s ease-out both; animation-delay: calc(var(--i, 0) * 70ms); }
/* La transform de card-in fait de .card un contexte d'empilement isolé (même une fois l'animation
   finie) : sans ça, le menu (z-index plus bas dans le document que les cartes suivantes) se ferait
   couper par la carte suivante dès qu'il dépasse l'espace entre deux cartes. */
.card.menu-open { z-index: 5; }
/* Bande de couleur à gauche + pastille d'émoji : couleur et émoji stables pour une liste donnée (comme dans l'app). */
.card::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 6px; background: var(--card-color, var(--primary)); border-radius: 16px 0 0 16px; }
.card-emoji { width: 48px; height: 48px; border-radius: 50%; display: grid; place-items: center; font-size: 1.5rem; flex: none; background: color-mix(in srgb, var(--card-color, var(--primary)) 22%, transparent); }
.card-main { flex: 1; display: grid; gap: .15rem; text-decoration: none; color: inherit; min-width: 0; }
/* Invitation directe à une liste, en attente d'accepter/refuser. */
.invite-banner { background: var(--primary-soft); color: var(--on-primary-soft); border-radius: 16px; padding: .9rem 1rem; display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.invite-banner .actions { display: flex; gap: .4rem; flex: none; }
@keyframes card-in { from { opacity: 0; transform: translateY(48px); } to { opacity: 1; transform: none; } }
/* Barre de progression : dégradé du style, remplissage qui rebondit un peu. */
.progress { display: block; height: 6px; background: var(--track); border-radius: 999px; overflow: hidden; margin-top: .3rem; }
.progress > span { display: block; height: 100%; background: var(--accent-gradient); border-radius: 999px; transition: width .7s cubic-bezier(.34, 1.3, .64, 1); }
.progress.big { height: 10px; margin-top: .4rem; }
.progress-head { padding: .4rem 0 .6rem; }
.progress-line { display: flex; align-items: center; gap: .5rem; }
.progress-line strong { flex: 1; font-size: .95rem; }
.progress-line .pct { color: var(--primary); font-weight: 600; font-size: .9rem; }
.rayon-head { display: flex; align-items: center; gap: .6rem; margin: 1.1rem 0 .2rem; }
.rayon-emoji { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; font-size: 1rem; background: color-mix(in srgb, var(--rc, var(--outline)) 22%, transparent); flex: none; }
.rayon-head h3 { flex: 1; margin: 0; font-size: .95rem; font-weight: 600; }
.rayon-count { font-size: .8rem; padding: .05rem .6rem; border-radius: 999px; background: color-mix(in srgb, var(--rc, var(--outline)) 28%, transparent); }
.row { display: flex; align-items: center; gap: .7rem; padding: .55rem .25rem; border-bottom: 1px solid var(--border); }
.row.clickable { cursor: pointer; }
.row.clickable:hover { background: var(--primary-soft); }
.row.item { border-left: 4px solid var(--accent, transparent); padding-left: .5rem; transition: opacity .25s; }
.row.item.done { opacity: .55; }
.row.item input[type=checkbox]:checked { animation: check-pop .4s cubic-bezier(.34, 1.56, .64, 1); }
@keyframes check-pop { from { transform: scale(.55); } to { transform: scale(1); } }
.row.done .item-name { text-decoration: line-through; color: var(--muted); }
.row .note { display: block; }
.price { color: var(--muted); font-variant-numeric: tabular-nums; }
.total { text-align: right; margin-top: 1rem; }
.thumb { width: 44px; height: 44px; border-radius: 10px; object-fit: cover; flex: none; }

.menu-wrap { position: relative; }
.menu { position: absolute; right: 0; top: 100%; z-index: 4; min-width: 12rem; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: 0 6px 18px rgba(0, 0, 0, .18); padding: .3rem; display: grid; }
.menu button { background: none; border: 0; text-align: left; padding: .55rem .7rem; font: inherit; color: inherit; border-radius: 8px; cursor: pointer; }
.menu button:hover { background: var(--primary-soft); }

.avatar { display: inline-grid; place-items: center; width: 2.2rem; height: 2.2rem; border-radius: 50%; background: var(--primary-soft); color: var(--primary); font-weight: 700; flex: none; }
.avatar-lg { width: 5rem; height: 5rem; font-size: 2rem; }
.avatar-img { width: 5rem; height: 5rem; border-radius: 50%; object-fit: cover; }
.nick { font-size: 1.05rem; }
.empty { text-align: center; padding: 2.5rem 1rem; color: var(--muted); }
.empty-emoji { font-size: 4.5rem; display: inline-block; animation: bob 1.6s ease-in-out infinite alternate; }
@keyframes bob { from { transform: translateY(-10px) rotate(-6deg); } to { transform: translateY(10px) rotate(6deg); } }

/* ---- Dialogues et messages ---- */
.overlay { position: fixed; inset: 0; background: rgba(0, 0, 0, .45); display: grid; place-items: center; z-index: 20; padding: 1rem; }
.dialog { background: var(--surface); border-radius: 18px; padding: 1.25rem; width: min(100%, 26rem); max-height: 90vh; overflow: auto; }
.dialog-actions { display: flex; justify-content: flex-end; gap: .5rem; margin-top: 1rem; }
.share-code { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 2.2rem; letter-spacing: .15em; text-align: center; margin: .5rem 0; }
.toasts { position: fixed; bottom: 1rem; left: 50%; transform: translateX(-50%); display: grid; gap: .5rem; z-index: 30; width: min(92vw, 28rem); }
.toast { background: var(--text); color: var(--bg); padding: .7rem 1rem; border-radius: 12px; box-shadow: 0 4px 14px rgba(0, 0, 0, .3); cursor: pointer; }
.toast-error { background: var(--danger); color: #fff; }

/* ---- Cadeaux ---- */
.gift-card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: .85rem 1rem; margin-bottom: .75rem; box-shadow: var(--shadow); }
.gift-top { display: flex; gap: .8rem; align-items: flex-start; }
.gift-photo { width: 64px; height: 64px; border-radius: 12px; object-fit: cover; background: var(--primary-soft); display: grid; place-items: center; font-size: 1.6rem; flex: none; }
.gift-links { margin: .35rem 0 0 0; padding: 0; list-style: none; font-size: .9rem; }
.gift-links a { word-break: break-all; }
.reservation { margin-top: .5rem; font-size: .9rem; }
.gift-actions { display: flex; gap: .5rem; flex-wrap: wrap; margin-top: .6rem; }

/* ---- Messagerie ---- */
.chat { display: flex; flex-direction: column; height: calc(100vh - 8.5rem); min-height: 20rem; }
.thread { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: .35rem; padding: .5rem 0; }
.bubble { max-width: 78%; padding: .5rem .8rem; border-radius: 16px; background: var(--surface); border: 1px solid var(--border); align-self: flex-start; overflow-wrap: anywhere; }
.bubble .body { white-space: pre-wrap; }
.bubble.mine { align-self: flex-end; background: var(--primary-soft); border-color: transparent; }
.bubble time { display: flex; align-items: center; gap: .3rem; font-size: .7rem; color: var(--muted); margin-top: .15rem; }
.bubble.deleted { background: transparent; border-style: dashed; }
.bubble .clickable { cursor: pointer; }
.bubble-actions { display: flex; gap: .1rem; margin-top: .1rem; }
.bubble-actions .icon-btn { font-size: .8rem; padding: .1rem .3rem; }
.edit-form { display: flex; gap: .4rem; align-items: center; }
.composer { display: flex; gap: .5rem; align-items: flex-end; padding-top: .5rem; }
.composer textarea { resize: none; }

/* ---- Profil ---- */
.picker { display: flex; flex-wrap: wrap; gap: .5rem; }
.font-chip { border: 2px solid var(--border); background: var(--surface); color: var(--text); border-radius: 12px; padding: .4rem .8rem; cursor: pointer; font-size: 1.05rem; }
.font-chip.selected { border-color: var(--primary); }
.color-dot { width: 2.2rem; height: 2.2rem; border-radius: 50%; border: 3px solid transparent; cursor: pointer; }
.color-dot.selected { border-color: var(--text); }

#blazor-error-ui { background: #fff3cd; color: #333; bottom: 0; box-shadow: 0 -1px 2px rgba(0, 0, 0, .2); display: none; left: 0; padding: .6rem 1.25rem; position: fixed; width: 100%; z-index: 1000; }
#blazor-error-ui .dismiss { cursor: pointer; position: absolute; right: .75rem; top: .5rem; }

@media (max-width: 520px) {
    .brand span { display: none; }
    .topbar { padding: .4rem .5rem; gap: .25rem; }
    .topbar nav a { padding: .4rem .5rem; }
    .add-row { flex-wrap: wrap; }
    .add-row .qty { width: 100%; }
}

.block { display: block; }
.file-input { display: none; }
label.btn { cursor: pointer; }

.narrow-chat { max-width: 640px; }
.friend-link { text-decoration: none; color: inherit; border-bottom: 0; padding: 0; }
.strong { font-weight: 700; color: var(--text); }
.profile-photo { display: flex; align-items: center; gap: 1rem; margin: .5rem 0 1rem; }
.preview { font-size: 1.6rem; margin: .8rem 0; }
.handle-row { display: flex; align-items: center; gap: .8rem; margin: .2rem 0; }
.handle { font-size: 1.3rem; overflow-wrap: anywhere; }

.site-footer { text-align: center; color: var(--muted); font-size: .8rem; padding: 1.5rem 1rem 2rem; }

/* ---- Réglages : thème et style de couleur ---- */
.segmented { display: inline-flex; border: 1px solid var(--border); border-radius: 999px; overflow: hidden; background: var(--surface); }
.segmented button { border: 0; background: none; color: var(--text); font: inherit; padding: .5rem 1.1rem; cursor: pointer; }
.segmented button + button { border-left: 1px solid var(--border); }
.segmented button.selected { background: var(--primary-soft); color: var(--on-primary-soft); font-weight: 600; }
.swatches { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: .4rem; margin: .4rem 0 1rem; }
.swatch { display: grid; justify-items: center; gap: .4rem; background: none; border: 0; color: var(--text); font: inherit; font-size: .8rem; cursor: pointer; padding: .4rem .2rem; border-radius: 14px; transition: transform .3s cubic-bezier(.34, 1.56, .64, 1); }
.swatch:hover { background: var(--surface-high); }
.swatch.selected { transform: scale(1.1); }
.swatch-dot { width: 56px; height: 56px; border-radius: 50%; border: 1px solid var(--border); display: grid; place-items: center; color: #fff; font-size: 1.4rem; font-weight: 700; }
.swatch.selected .swatch-dot { border: 3px solid var(--text); }

@media (prefers-reduced-motion: reduce) {
    .topbar::after, .empty-emoji, .card, .row.item input[type=checkbox]:checked { animation: none; }
    .progress > span, .swatch { transition: none; }
}

/* ---- Administration (/admin) ---- */
.page.admin { max-width: 900px; }
.page.admin.wide { max-width: 1200px; }
.admin-tabs { display: flex; gap: .25rem; flex-wrap: wrap; margin: .25rem 0 1rem; border-bottom: 1px solid var(--border); }
.admin-tabs a { padding: .5rem .9rem; text-decoration: none; color: var(--text); border-bottom: 3px solid transparent; margin-bottom: -1px; }
.admin-tabs a.active { border-bottom-color: var(--primary); color: var(--primary); font-weight: 600; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .75rem; margin: .5rem 0; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: .8rem 1rem; box-shadow: var(--shadow); }
.stat strong { display: block; font-size: 1.6rem; }
.stat span { color: var(--muted); font-size: .85rem; }
.stat.warn-card { border-color: var(--danger); }
.warn { color: var(--danger); }
.tag { display: inline-block; font-size: .7rem; padding: 0 .5rem; border-radius: 999px; background: var(--primary-soft); color: var(--on-primary-soft); vertical-align: middle; }
.mono, code { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .85rem; }
.secret { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 1.6rem; letter-spacing: .06em; text-align: center; background: var(--surface-high); border-radius: 12px; padding: .8rem; user-select: all; overflow-wrap: anywhere; }
.admin-user { align-items: flex-start; flex-wrap: wrap; }
.admin-user .actions { justify-content: flex-end; }
.table-picker { margin-bottom: .75rem; }
.table-scroll { overflow-x: auto; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); }
table.grid { border-collapse: collapse; width: 100%; font-size: .85rem; }
table.grid th, table.grid td { padding: .4rem .6rem; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; max-width: 22rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
table.grid th { background: var(--surface-high); position: sticky; top: 0; }
table.grid th .kind { display: block; font-weight: 400; font-size: .7rem; color: var(--muted); }
table.grid td.null { color: var(--muted); font-style: italic; }
table.grid td.protected { color: var(--muted); }
.nowrap { white-space: nowrap; }
.pager { display: flex; align-items: center; justify-content: space-between; gap: .5rem; margin: .75rem 0; }
.chart-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: .75rem; }
.chart { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: .7rem .9rem; box-shadow: var(--shadow); }
.chart-head { display: flex; justify-content: space-between; align-items: baseline; gap: .5rem; }
.chart svg { display: block; width: 100%; height: 72px; margin: .4rem 0 .2rem; }
.chart .bar { fill: var(--primary); }
.chart .bar.zero { fill: var(--track); }
.chart-axis { display: flex; justify-content: space-between; }
.bar-row { gap: .8rem; }
.bar-label { flex: 0 0 min(20rem, 42%); }
.bar-value { flex: 0 0 auto; color: var(--muted); font-size: .85rem; font-variant-numeric: tabular-nums; }
.rank-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 1rem; }
.rank-list { list-style: none; margin: 0; padding: 0; display: grid; gap: .35rem; }
.rank-list li { display: flex; align-items: center; gap: .6rem; }
.rank-label { flex: 0 0 8.5rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .9rem; }
.rank-list .progress { margin: 0; }

/* Très petits écrans : le lien « Admin » s'ajoute à la barre du haut, on resserre pour ne pas déborder. */
@media (max-width: 420px) {
    .topbar { padding: .4rem .35rem; }
    .topbar nav { gap: 0; }
    .topbar nav a { padding: .4rem .32rem; font-size: .92rem; }
}

/* Administration : sur petit écran, les boutons passent sous le texte au lieu de l'écraser. */
.admin .add-row input.grow { flex: 1 1 12rem; min-width: 10rem; }
.admin-user > .grow { flex: 1 1 16rem; min-width: 13rem; }
.admin-user .actions { flex: 0 1 auto; }
a.font-chip { text-decoration: none; display: inline-block; }
