/* PWA notifications : charte Prefabloc (tokens + composants repris de FNC) */
/*
 * FNC · v2 mobile first
 * Couleurs Prefabloc : rouge brique #C43B1E, aubergine #321A29, ocre #DD9933.
 */

:root {
    color-scheme: light;

    --bg: #f5f5f5;
    --surface: #ffffff;
    --surface-2: #f1eef0;
    --line: #e2dde0;
    --line-strong: #cbc3c8;
    --ink: #321a29;
    --text: #3a3a3a;
    --muted: #6e676b;

    --brand: #c43b1e;
    --brand-hover: #a93219;
    --brand-soft: #f9e7e2;
    --on-brand: #ffffff;
    --ochre: #dd9933;
    --ochre-soft: #fbf0dd;
    --ochre-ink: #85560f;
    --ok: #2f7d4f;
    --ok-soft: #e3f1e8;
    --low: #56657a;
    --low-soft: #e8edf2;

    --bar-bg: #321a29;
    --bar-text: #ffffff;

    --radius-s: 8px;
    --radius-m: 14px;
    --radius-l: 22px;

    --appbar-h: 56px;
    --tabbar-h: 64px;
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);

    --font: "Mulish", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;

    --hazard: repeating-linear-gradient(-45deg, #c43b1e 0 8px, #321a29 8px 16px);
}

@media (prefers-color-scheme: dark) {
    :root {
        color-scheme: dark;

        --bg: #1b1117;
        --surface: #26171f;
        --surface-2: #311f2a;
        --line: #43303b;
        --line-strong: #5a4450;
        --ink: #f6eef2;
        --text: #e4dade;
        --muted: #b0a2aa;

        --brand: #e0583a;
        --brand-hover: #ec6c4f;
        --brand-soft: #4a221c;
        --ochre-soft: #43321a;
        --ochre-ink: #f0c070;
        --ok: #6cc592;
        --ok-soft: #1f3a2a;
        --low: #a9b8ca;
        --low-soft: #2a313b;

        --bar-bg: #26171f;
    }
}

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

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

body {
    margin: 0;
    min-height: 100dvh;
    background: var(--bg);
    color: var(--text);
    font: 16px/1.5 var(--font);
    -webkit-tap-highlight-color: transparent;
}

a { color: var(--brand); }
h1, h2, h3 { color: var(--ink); line-height: 1.2; margin: 0; }
p { margin: 0; }

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

.muted { color: var(--muted); font-size: 0.9rem; }

.visually-hidden {
    position: absolute !important;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}

.icon { flex-shrink: 0; }

/* ---------- Coque : barre du haut ---------- */

.appbar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    gap: 12px;
    height: calc(var(--appbar-h) + var(--safe-top));
    padding: var(--safe-top) 12px 0;
    background: var(--bar-bg);
    color: var(--bar-text);
}

.appbar__title {
    flex: 1;
    min-width: 0;
    color: inherit;
    font-size: 1.15rem;
    font-weight: 800;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.appbar__icon {
    display: grid;
    place-items: center;
    width: 44px;
    height: 44px;
    margin-left: -6px;
    border-radius: 50%;
    color: inherit;
}

/* Rappel du cadre à traits interrompus du logo Prefabloc */
.appbar__mark {
    width: 26px;
    height: 20px;
    margin: 0 4px;
    border: 2.5px solid var(--brand);
    clip-path: polygon(0 0, 40% 0, 40% 30%, 100% 30%, 100% 100%, 65% 100%, 65% 70%, 0 70%);
}

.avatar {
    display: grid;
    place-items: center;
    width: 38px;
    height: 38px;
    border: 0;
    border-radius: 50%;
    background: var(--brand);
    color: var(--on-brand);
    font: 800 0.85rem var(--font);
    cursor: pointer;
}
/* ---------- Contenu ---------- */

.page {
    width: 100%;
    max-width: 760px;
    margin: 0 auto;
    padding: 16px 16px calc(var(--tabbar-h) + var(--safe-bottom) + 32px);
}

.page--wide { max-width: 1280px; }

.page-intro { margin-bottom: 20px; }
.page-intro h2 { font-size: 1.5rem; font-weight: 800; margin-bottom: 4px; }

.panel {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-m);
    padding: 16px;
}

.panel + .panel { margin-top: 12px; }

.panel__title { font-size: 1.05rem; font-weight: 800; margin-bottom: 14px; }

/* ---------- Formulaires ---------- */

.form-section { margin: 0 0 12px; }

.field { border: 0; margin: 0 0 16px; padding: 0; min-width: 0; }
.field:last-child { margin-bottom: 0; }

.label { display: block; margin-bottom: 6px; padding: 0; color: var(--ink); font-weight: 700; font-size: 0.95rem; }
.label .req { color: var(--brand); }

.input {
    width: 100%;
    min-height: 48px;
    padding: 11px 14px;
    border: 1.5px solid var(--line-strong);
    border-radius: var(--radius-s);
    background: var(--surface);
    color: var(--text);
    font: inherit;
}

.input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.input[readonly] { background: var(--surface-2); border-color: var(--line); }
textarea.input { min-height: 96px; resize: vertical; }
select.input { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 20px) 50%, calc(100% - 14px) 50%; background-size: 6px 6px; background-repeat: no-repeat; padding-right: 40px; }

.grid-2 { display: grid; gap: 0 12px; }

@media (min-width: 560px) {
    .grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

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

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 48px;
    padding: 10px 20px;
    border: 1.5px solid transparent;
    border-radius: var(--radius-s);
    font: 800 0.95rem var(--font);
    text-decoration: none;
    cursor: pointer;
}

.button:disabled { opacity: 0.6; cursor: progress; }
.button--block { width: 100%; }
.button--small { min-height: 38px; padding: 6px 14px; font-size: 0.85rem; }

.button--primary { background: var(--brand); color: var(--on-brand); }
.button--primary:hover { background: var(--brand-hover); }

.button--ghost { background: var(--surface); border-color: var(--line-strong); color: var(--ink); }
.button--ghost:hover { border-color: var(--ink); }

.button--danger { background: var(--ink); color: var(--surface); }
.button--danger-ghost { background: var(--surface); border-color: var(--brand); color: var(--brand); }

/* ---------- Badges, messages, toasts ---------- */

.badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 10px;
    border-radius: 999px;
    background: var(--surface-2);
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 800;
    white-space: nowrap;
}

.badge--low { background: var(--low-soft); color: var(--low); }
.badge--medium { background: var(--ochre-soft); color: var(--ochre-ink); }
.badge--high { background: var(--brand-soft); color: var(--brand); }
.badge--critical { background: var(--hazard); color: #fff; text-shadow: 0 1px 2px rgb(0 0 0 / 60%); }
.badge--en_attente { background: var(--ochre-soft); color: var(--ochre-ink); }
.badge--validee, .badge--ouverte { background: var(--ok-soft); color: var(--ok); }
.badge--refusee { background: var(--brand-soft); color: var(--brand); }
.badge--cloturee { background: var(--surface-2); color: var(--muted); }

.notice { padding: 12px 14px; border-radius: var(--radius-s); font-size: 0.95rem; }
.notice ul { margin: 0; padding-left: 18px; }
.notice + * { margin-top: 12px; }
* + .notice { margin-top: 12px; }
.notice--info { background: var(--low-soft); color: var(--low); }
.notice--success { background: var(--ok-soft); color: var(--ok); }
.notice--error { background: var(--brand-soft); color: var(--brand); }
.notice--warning { background: var(--ochre-soft); color: var(--ochre-ink); }

.toasts {
    position: fixed;
    left: 16px;
    right: 16px;
    bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 16px);
    z-index: 50;
    display: grid;
    gap: 8px;
    justify-items: center;
    pointer-events: none;
}

.toast {
    display: flex;
    align-items: center;
    gap: 10px;
    max-width: 480px;
    padding: 12px 16px;
    border-radius: var(--radius-m);
    background: var(--ink);
    color: var(--surface);
    font-weight: 700;
    box-shadow: 0 10px 30px rgb(50 26 41 / 30%);
    animation: toast-in 0.2s ease-out;
}

.toast--success .icon { color: #7fd6a2; }
.toast--error .icon { color: var(--ochre); }

@keyframes toast-in {
    from { transform: translateY(12px); opacity: 0; }
}
/* ---------- Cartes FNC / demandes ---------- */

.cards { display: grid; gap: 10px; margin-top: 12px; }

.card {
    position: relative;
    display: grid;
    gap: 6px;
    padding: 14px 16px 14px 22px;
    border: 1px solid var(--line);
    border-radius: var(--radius-m);
    background: var(--surface);
    color: var(--text);
    text-decoration: none;
    text-align: left;
    font: inherit;
    width: 100%;
    overflow: hidden;
    cursor: pointer;
}

/* Bande d'urgence sur le bord gauche */
.card::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 6px; background: var(--line-strong); }
.card--low::before { background: var(--low); }
.card--medium::before { background: var(--ochre); }
.card--high::before { background: var(--brand); }
.card--critical::before { width: 8px; background: var(--hazard); }

.card:hover { border-color: var(--line-strong); }
.card.is-active { border-color: var(--brand); box-shadow: 0 0 0 1px var(--brand); }

.card__top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.card__ref { font-weight: 800; color: var(--muted); font-size: 0.85rem; font-variant-numeric: tabular-nums; }
.card__title { color: var(--ink); font-size: 1.05rem; font-weight: 800; overflow-wrap: anywhere; }
.card__meta { color: var(--muted); font-size: 0.88rem; }
.card__foot { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 4px; }

@media (min-width: 900px) {
    .cards--grid { grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }
}

.empty { padding: 40px 16px; text-align: center; display: grid; gap: 8px; justify-items: center; }
.empty h3 { font-size: 1.1rem; }
/* ---------- FNC : en-tête ---------- */

.hero { position: relative; margin-bottom: 12px; padding: 18px 16px 16px; border-radius: var(--radius-l); background: var(--surface); border: 1px solid var(--line); overflow: hidden; }
.hero::before { content: ""; position: absolute; inset: 0 0 auto; height: 6px; background: var(--line-strong); }
.hero--low::before { background: var(--low); }
.hero--medium::before { background: var(--ochre); }
.hero--high::before { background: var(--brand); }
.hero--critical::before { height: 12px; background: var(--hazard); }

.hero__badges { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.hero__title { font-size: 1.6rem; font-weight: 800; overflow-wrap: anywhere; }
.hero__sub { margin-top: 4px; color: var(--muted); }
.hero__actions { margin-top: 14px; }
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---------- PWA notifications ---------- */

[hidden] { display: none !important; }

/* Pas de barre d'onglets : marge basse réduite */
.page { padding-bottom: calc(32px + var(--safe-bottom)); }
.toasts { bottom: calc(24px + var(--safe-bottom)); }

.stack > * + * { margin-top: 12px; }

.key-input {
    font: 800 1.5rem/1.2 ui-monospace, "SFMono-Regular", Consolas, monospace;
    letter-spacing: 0.14em;
    text-align: center;
    text-transform: uppercase;
}
.key-input::placeholder { color: var(--line-strong); }

.panel .button--block + .notice { margin-top: 12px; }
.panel p.muted { margin-bottom: 14px; }

.badge--active { background: var(--ok-soft); color: var(--ok); }
.badge--group { background: var(--ochre-soft); color: var(--ochre-ink); }
.hero--active::before { background: var(--ok); }

.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.actions > * { flex: 1 1 140px; }

.list-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin: 24px 0 0; }
.list-head h2 { font-size: 1.15rem; font-weight: 800; }

.card { cursor: default; }
.card::before { background: var(--brand); }
.card.is-old::before { background: var(--line-strong); }
.card__body { color: var(--text); white-space: pre-wrap; overflow-wrap: anywhere; }

.steps { margin: 8px 0 0; padding-left: 20px; }
.steps li + li { margin-top: 4px; }

.appbar__reload { margin: 0 -6px 0 0; padding: 0; border: 0; background: none; cursor: pointer; }
.appbar__reload:active { background: rgb(255 255 255 / 12%); }
