:root {
    --bg: #0f172a;
    --surface: #1e293b;
    --surface-2: #334155;
    --line: #334155;
    --text: #e2e8f0;
    --muted: #94a3b8;
    --accent: #38bdf8;
    --accent-ink: #082f49;
    --ok: #34d399;
    --warn: #fbbf24;
    --err: #f87171;
    --radius: 14px;
    --nav-h: 62px;
}

* { 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;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }

.boot {
    position: fixed; inset: 0;
    display: flex; flex-direction: column; gap: .75rem;
    align-items: center; justify-content: center;
    color: var(--muted);
}
.boot-logo { font-size: 3rem; }

/* ---------- layout ---------- */
.app-shell {
    min-height: 100dvh;
    padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom));
    max-width: 640px;
    margin: 0 auto;
}

.topbar {
    position: sticky; top: 0; z-index: 20;
    display: flex; align-items: center; gap: .5rem;
    padding: .6rem .9rem;
    padding-top: calc(.6rem + env(safe-area-inset-top));
    background: rgba(15, 23, 42, .92);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--line);
}
.topbar .brand { font-weight: 700; margin-right: auto; letter-spacing: .2px; }
.topbar select {
    background: var(--surface); color: var(--text);
    border: 1px solid var(--line); border-radius: 10px;
    padding: .4rem .5rem; font-size: .9rem; max-width: 45vw;
}
.topbar .conn {
    font-size: 1.05rem; padding: .2rem .3rem; border-radius: 8px; opacity: .75;
}
.topbar .conn.active { opacity: 1; background: var(--surface-2); }
.topbar .who {
    font-size: .75rem; color: var(--muted);
    background: none; border: none; padding: .2rem .3rem;
}

/* L'app affiche ses propres erreurs (State.Error, messages de page) —
   on masque le bandeau générique de Blazor. */
#blazor-error-ui { display: none !important; }

.pad { padding: 1rem .9rem 2rem; }
h1 { font-size: 1.3rem; margin: .2rem 0 1rem; }
h2 { font-size: 1.05rem; margin: 1.4rem 0 .6rem; color: var(--muted); font-weight: 600; }

/* ---------- cards ---------- */
.card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: .85rem .9rem;
    margin-bottom: .7rem;
}
/* helpers de mise en page — utilisables partout, pas seulement dans .card */
.row { display: flex; gap: .6rem; align-items: flex-start; }
.grow { flex: 1; min-width: 0; }
.muted { color: var(--muted); font-size: .82rem; }
.title { font-weight: 600; margin-bottom: .15rem; }
.card p { margin: .3rem 0 0; font-size: .9rem; white-space: pre-wrap; word-break: break-word; }
a.card { display: block; color: inherit; }
.thumb { width: 64px; height: 64px; border-radius: 10px; object-fit: cover; background: var(--surface-2); flex: none; cursor: pointer; }
.thumb-video { display: flex; align-items: center; justify-content: center; font-size: 1.6rem; }

.lightbox {
    position: fixed; inset: 0; z-index: 1000; padding: 1.2rem;
    background: rgba(0, 0, 0, .85);
    display: flex; align-items: center; justify-content: center;
    cursor: zoom-out;
}
.lightbox img, .lightbox video {
    max-width: 100%; max-height: 100%; border-radius: 10px; cursor: default;
}
.lightbox-close {
    position: absolute; top: 1rem; right: 1rem;
    width: 2.2rem; height: 2.2rem; border-radius: 50%; border: none;
    background: rgba(255, 255, 255, .15); color: #fff; font-size: 1.1rem;
    cursor: pointer;
}

/* carte cliquable + chevron */
.tappable { cursor: pointer; -webkit-tap-highlight-color: transparent; }
.tappable:active { background: var(--surface-2); }
.chev { align-self: center; color: var(--muted); font-size: 1.4rem; flex: none; }

/* feuille de détail (overlay plein écran) */
.overlay {
    position: fixed; inset: 0; z-index: 40;
    background: rgba(2, 6, 23, .72);
    display: flex; align-items: flex-end; justify-content: center;
}
.sheet {
    width: 100%; max-width: 640px;
    max-height: 92dvh; overflow-y: auto;
    background: var(--bg);
    border: 1px solid var(--line);
    border-radius: 18px 18px 0 0;
    padding: 1rem .9rem calc(1.2rem + env(safe-area-inset-bottom));
}
.sheet-head { display: flex; align-items: flex-start; gap: .5rem; margin-bottom: .6rem; }
.sheet-head .muted { flex: 1; }
.iconbtn {
    background: var(--surface-2); border: 1px solid var(--line);
    border-radius: 999px; width: 32px; height: 32px; padding: 0;
    font-size: .9rem; flex: none;
}
/* média en grand (fiche détail ET cartes de plan) */
.media {
    display: block; width: 100%; margin: .8rem 0;
    border-radius: 12px; background: #000;
    max-height: 55dvh; object-fit: contain;
}
video.media { aspect-ratio: 9 / 16; }
.sheet .caption {
    white-space: pre-wrap; word-break: break-word;
    font-size: .95rem; line-height: 1.45; margin: .6rem 0 0;
}

.pill {
    display: inline-block; font-size: .72rem; padding: .12rem .5rem;
    border-radius: 999px; background: var(--surface-2); color: var(--text);
    margin-right: .35rem;
}

/* ---------- controls ---------- */
button, .btn {
    font: inherit; cursor: pointer;
    border: 1px solid var(--line); border-radius: 10px;
    background: var(--surface-2); color: var(--text);
    padding: .55rem .9rem;
}
.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; font-weight: 600; }
.btn-danger { background: transparent; color: var(--err); border-color: var(--err); }
.btn-sm { padding: .35rem .6rem; font-size: .82rem; }
button:disabled { opacity: .5; cursor: default; }

label { display: block; font-size: .82rem; color: var(--muted); margin: .8rem 0 .25rem; }
input, select, textarea {
    width: 100%; font: inherit;
    background: var(--surface); color: var(--text);
    border: 1px solid var(--line); border-radius: 10px; padding: .6rem;
}
textarea { min-height: 90px; resize: vertical; }

/* sélecteur de mode */
.seg { display: flex; gap: .35rem; background: var(--surface); border: 1px solid var(--line);
    border-radius: 12px; padding: .25rem; margin-top: .3rem; }
.seg-btn { flex: 1; border: none; background: none; color: var(--muted); padding: .5rem .4rem;
    border-radius: 9px; font-size: .88rem; }
.seg-btn.active { background: var(--surface-2); color: var(--text); font-weight: 600; }
a.seg-btn, span.seg-btn { display: block; text-decoration: none; }
a.seg-btn { color: var(--muted); }

/* idées de thème */
.ideas { display: flex; flex-direction: column; gap: .4rem; margin-top: .5rem; }
.idea { text-align: left; background: var(--surface); border: 1px solid var(--line);
    border-radius: 10px; padding: .6rem .7rem; display: flex; flex-direction: column; gap: .15rem; }
.idea-t { font-weight: 600; }
.idea-r { color: var(--muted); font-size: .8rem; }

/* composition (steppers) */
.comp { display: flex; flex-direction: column; gap: .5rem; margin-top: .3rem; }
.stepper { display: flex; align-items: center; justify-content: space-between; gap: .6rem;
    background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: .5rem .7rem; }
.stepper-label { font-size: .88rem; }
.stepper-ctl { display: flex; align-items: center; gap: .1rem; flex: none; }
.stepper-ctl button { width: 34px; height: 34px; padding: 0; font-size: 1.1rem; border-radius: 8px; }
.stepper-val { min-width: 2ch; text-align: center; font-weight: 600; }

.err { color: var(--err); font-size: .85rem; margin-top: .5rem; }
.ok { color: var(--ok); }
.warn { color: var(--warn); }
.center { text-align: center; }
.spinner {
    width: 26px; height: 26px; border-radius: 50%;
    border: 3px solid var(--surface-2); border-top-color: var(--accent);
    animation: spin 1s linear infinite; margin: 1.5rem auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- bottom nav ---------- */
.bottomnav {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
    display: flex; justify-content: space-around;
    background: rgba(15, 23, 42, .96);
    backdrop-filter: blur(8px);
    border-top: 1px solid var(--line);
    padding-bottom: env(safe-area-inset-bottom);
    max-width: 640px; margin: 0 auto;
}
.bottomnav a {
    flex: 1; text-align: center; color: var(--muted);
    padding: .5rem 0; font-size: .68rem; line-height: 1.4;
}
.bottomnav a .ico { display: block; font-size: 1.25rem; }
.bottomnav a.active { color: var(--accent); }

/* ---------- login ---------- */
.login {
    min-height: 100dvh; display: flex; flex-direction: column;
    align-items: center; justify-content: center; gap: 1rem; padding: 2rem;
    text-align: center;
}
.login .logo { font-size: 3.5rem; }
.login .legal { max-width: 28rem; line-height: 1.6; }
.login .legal a { color: var(--accent); }

/* ---------- alertes (échecs de publication / jetons) ---------- */
.alert-banner {
    background: rgba(248, 113, 113, .12);
    border: 1px solid var(--err);
    border-radius: var(--radius);
    padding: .75rem .85rem; margin-bottom: .8rem;
}
.alert-banner .alert-head { color: var(--err); font-weight: 700; margin-bottom: .3rem; }
.alert-line { display: flex; gap: .5rem; align-items: center; font-size: .85rem; padding: .3rem 0; border-top: 1px solid rgba(248, 113, 113, .25); }
.alert-line:first-of-type { border-top: none; }
.alert-line .grow { word-break: break-word; }
.card.failed { border-color: var(--err); box-shadow: inset 3px 0 0 var(--err); }
.card.failed .err-inline { color: var(--err); font-size: .8rem; margin-top: .25rem; }

/* ---------- collisions de programmation (même plateforme, même moment) ---------- */
.collision-warn {
    background: rgba(251, 191, 36, .1);
    border: 1px solid var(--warn);
    border-radius: var(--radius);
    padding: .65rem .8rem; margin-top: .6rem; font-size: .85rem;
}
.collision-head { color: var(--warn); font-weight: 700; margin-bottom: .25rem; }
.collision-line { padding: .2rem 0; word-break: break-word; }
.collision-line .muted { display: block; font-size: .8rem; }
.card.collision { border-color: var(--warn); box-shadow: inset 3px 0 0 var(--warn); }
.pill.pill-warn { background: #422006; color: var(--warn); }
.alert-line .warn-text { color: var(--warn); }

/* ---------- base de connaissances ---------- */
.topbar .kb {
    font-size: 1.05rem; padding: .2rem .3rem; border-radius: 8px; opacity: .75;
}
.topbar .kb.active { opacity: 1; background: var(--surface-2); }
.dirty-bar {
    position: sticky; top: calc(3.2rem + env(safe-area-inset-top)); z-index: 15;
    display: flex; align-items: center; gap: .5rem; flex-wrap: wrap;
    background: #422006; border: 1px solid var(--warn); color: var(--warn);
    border-radius: var(--radius); padding: .6rem .8rem; margin-bottom: .7rem; font-size: .88rem;
}
.dirty-bar span { flex: 1; min-width: 12rem; }
.fact { display: flex; gap: .5rem; align-items: flex-start; }
.fact textarea { min-height: 64px; font-size: .9rem; }
.fact-actions { display: flex; flex-direction: column; gap: .3rem; flex: none; }
.fact-actions button { width: 34px; height: 30px; padding: 0; font-size: .85rem; }
.fact-meta { display: flex; justify-content: space-between; align-items: center; margin-top: .25rem; }
.proposal { display: flex; gap: .5rem; align-items: flex-start; padding: .45rem 0; border-top: 1px solid var(--line); }
.proposal input[type=checkbox] { width: auto; margin-top: .7rem; flex: none; }
.proposal.present { opacity: .55; }
.kb-warn { color: var(--warn); font-size: .85rem; }
dl.brand { margin: 0; }
dl.brand dt { font-size: .78rem; color: var(--muted); margin-top: .6rem; }
dl.brand dd { margin: .15rem 0 0; font-size: .9rem; white-space: pre-wrap; word-break: break-word; }

/* ---------- boîte de réception (agent de messagerie) ---------- */
.topbar .inbox {
    position: relative;
    font-size: 1.05rem; padding: .2rem .3rem; border-radius: 8px; opacity: .75;
}
.topbar .inbox.active { opacity: 1; background: var(--surface-2); }
.topbar .inbox .badge {
    position: absolute; top: -.35rem; right: -.45rem;
    min-width: 1.1rem; padding: 0 .25rem; border-radius: 999px;
    background: var(--err); color: #fff; font-size: .65rem; font-weight: 700;
    line-height: 1.1rem; text-align: center;
}
.msg-head { display: flex; justify-content: space-between; gap: .5rem; align-items: baseline; }
.msg-head .muted { font-size: .78rem; flex: none; }
.msg-text { white-space: pre-wrap; word-break: break-word; margin: .35rem 0; }
.msg-preview { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thread { border-left: 3px solid var(--line); padding-left: .6rem; margin: .5rem 0; font-size: .85rem; }
.thread .them, .thread .us { margin: .25rem 0; white-space: pre-wrap; word-break: break-word; }
.thread .us { color: var(--accent); }
.msg-actions { display: flex; gap: .4rem; flex-wrap: wrap; margin-top: .5rem; }
.msg-actions .btn-primary { margin-left: auto; }
.faq-item { display: flex; flex-direction: column; gap: .35rem; }
.check { display: flex; align-items: center; gap: .45rem; color: var(--text); font-size: .9rem; }
.check input { width: auto; }

/* ---------- Reels : choix de l'image source, coût ---------- */
.pick-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: .4rem; margin-top: .6rem; }
.pick { position: relative; padding: 0; border: 2px solid transparent; border-radius: 12px;
    background: var(--surface-2); overflow: hidden; cursor: pointer; }
.pick img { display: block; width: 100%; aspect-ratio: 1; object-fit: cover; }
.pick.sel { border-color: var(--accent); }
.pick-label { position: absolute; left: 0; right: 0; bottom: 0; padding: .1rem .3rem;
    font-size: .62rem; color: #fff; background: rgba(0, 0, 0, .6);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cost-box { margin-top: .6rem; padding: .6rem .7rem; border: 1px solid var(--warn); border-radius: 12px; }

/* ---------- Statistiques : indicateurs ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(92px, 1fr)); gap: .4rem; margin-top: .5rem; }
.kpi { background: var(--surface-2); border-radius: 10px; padding: .45rem .55rem; }
.kpi .v { font-size: 1.05rem; font-weight: 700; }
.kpi .l { font-size: .7rem; color: var(--muted); }
.stat-post { display: flex; gap: .6rem; margin-top: .6rem; padding-top: .6rem; border-top: 1px solid var(--line); }
.stat-metrics { font-size: .78rem; color: var(--muted); margin-top: .2rem; }

/* ---------- jauges de quota (formule du mois) ---------- */
.quota-line { margin-top: .6rem; font-size: .88rem; }
.quota .bar {
    height: 8px; border-radius: 999px; background: var(--surface-2);
    overflow: hidden; margin-top: .3rem;
}
.quota .fill { height: 100%; background: var(--accent); border-radius: 999px; }
.quota .fill.high { background: var(--warn); }
.quota .fill.full { background: var(--err); }
.err-ink { color: var(--err); font-weight: 600; }
.quota-block { color: var(--warn); font-size: .82rem; margin-top: .35rem; }
