:root {
    --background: #f7f7f5;
    --surface: #ffffff;
    --text: #1f2328;
    --muted: #656d76;
    --line: #d8dee4;
    --accent: #0b6bcb;
    --problem: #b42318;
    --problem-surface: #fdecea;
    --accent-surface: #e7f0fb;
    --green: #1a7f37;
    --green-surface: #e6f4ea;
    --violet: #6f42c1;
    --violet-surface: #f0eafa;
    --amber: #9a6700;
    /* Les bleus nuit du logo EoCraft : le bandeau garde ses couleurs dans les deux modes. */
    --brand: #16283f;
    --brand-deep: #1c2c3c;
    --brand-soft: #56637f;
    --on-brand: #ffffff;
    --on-brand-muted: #c3cad8;
}

@media (prefers-color-scheme: dark) {
    :root {
        --background: #15171a;
        --surface: #1e2125;
        --text: #e6e8eb;
        --muted: #9aa3ad;
        --line: #33383e;
        --accent: #5aa2f0;
        --problem: #ff8a80;
        --problem-surface: #3a1f1d;
        --accent-surface: #1b2c40;
        --green: #56d364;
        --green-surface: #1b3022;
        --violet: #c8a6ff;
        --violet-surface: #2c2440;
        --amber: #e3b341;
    }
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--background);
    color: var(--text);
    font: 16px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
}

.masthead {
    background: linear-gradient(135deg, var(--brand) 0%, var(--brand-deep) 60%, var(--brand-soft) 140%);
    color: var(--on-brand);
    box-shadow: 0 1px 4px rgb(0 0 0 / 0.25);
}

.masthead-inner {
    max-width: 860px;
    margin: 0 auto;
    padding: 14px 16px 0;
}

.brand {
    display: flex;
    align-items: center;
    gap: 14px;
    color: inherit;
    text-decoration: none;
}

.brand-logo {
    flex: none;
    display: grid;
    place-items: center;
    width: 52px;
    height: 52px;
    border-radius: 12px;
    background: #ffffff;
}

.brand-logo img { width: 36px; height: auto; display: block; }

.brand-text { display: flex; flex-direction: column; min-width: 0; }

.brand-name { font-size: 1.35rem; font-weight: 650; letter-spacing: 0.01em; line-height: 1.2; }

.brand-tagline { font-size: 0.875rem; color: var(--on-brand-muted); }

nav {
    display: flex;
    gap: 4px 20px;
    flex-wrap: wrap;
    margin-top: 12px;
}

nav a {
    color: var(--on-brand-muted);
    text-decoration: none;
    padding: 8px 0 10px;
    border-bottom: 3px solid transparent;
}

nav a:hover { color: var(--on-brand); }

nav a.active { color: var(--on-brand); font-weight: 600; border-bottom-color: var(--on-brand); }

/* La déconnexion, un formulaire (POST) habillé comme les liens du menu. */
nav .logout { display: contents; }

nav .logout button {
    color: var(--on-brand-muted);
    background: none;
    border: none;
    border-bottom: 3px solid transparent;
    border-radius: 0;
    padding: 8px 0 10px;
    font: inherit;
    cursor: pointer;
}

nav .logout button:hover { color: var(--on-brand); }

a { color: var(--accent); }

main { max-width: 860px; margin: 0 auto; padding: 16px; }

.box {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 16px;
    margin-bottom: 16px;
}

h1 { font-size: 1.1rem; margin: 0 0 4px; overflow-wrap: anywhere; }

.poll, .empty { color: var(--muted); margin: 0 0 12px; }

.problem {
    color: var(--problem);
    background: var(--problem-surface);
    border-radius: 6px;
    padding: 8px 12px;
    margin: 0 0 12px;
    overflow-wrap: anywhere;
}

.threads { list-style: none; margin: 0; padding: 0; }

.threads li {
    display: flex;
    flex-direction: column;
    padding: 10px 0;
    border-top: 1px solid var(--line);
}

.subject { font-weight: 500; overflow-wrap: anywhere; }

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

h2 { font-size: 1rem; margin: 0 0 12px; }

.list { list-style: none; padding: 4px 16px; }

.list li { display: flex; flex-direction: column; padding: 10px 0; border-top: 1px solid var(--line); }

.list li:first-child { border-top: none; }

.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }

.field > span { font-size: 0.875rem; color: var(--muted); }

input, textarea, select {
    font: inherit;
    color: var(--text);
    background: var(--background);
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 8px 10px;
    width: 100%;
}

input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.validation-message, .invalid + .validation-message { color: var(--problem); font-size: 0.875rem; }

input.invalid, textarea.invalid { border-color: var(--problem); }

button {
    font: inherit;
    color: #ffffff;
    background: var(--accent);
    border: none;
    border-radius: 6px;
    padding: 8px 16px;
    cursor: pointer;
}

.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }

.page-head h1 { margin: 0; }

.button {
    color: #ffffff;
    background: var(--accent);
    border-radius: 6px;
    padding: 8px 16px;
    text-decoration: none;
}

button.danger { background: var(--problem); }

.tag {
    font-size: 0.75rem;
    color: var(--problem);
    border: 1px solid var(--problem);
    border-radius: 999px;
    padding: 0 8px;
    margin-left: 8px;
    white-space: nowrap;
}

.field-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 0 12px; }

.check { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }

.check input { width: auto; }

.targets { list-style: none; margin: 0 0 12px; padding: 0; }

.targets li {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 8px 0;
    border-top: 1px solid var(--line);
}

.inline { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }

.inline select { width: auto; }

.sends { margin: 4px 0 0; padding-left: 18px; font-size: 0.875rem; }

.tag.neutral { color: var(--muted); border-color: var(--line); }

.summary { font-size: 0.875rem; }

.triage { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; }

.triage p { margin: 0; }

.triage .meta { flex-basis: 100%; }

.draft h2 { margin: 4px 0 8px; }

.draft-body { white-space: pre-wrap; margin: 0; }

button.secondary { color: var(--text); background: var(--background); border: 1px solid var(--line); }

.draft textarea { font-family: inherit; line-height: 1.5; }

.confirm {
    margin-top: 12px;
    padding: 12px;
    border: 2px solid var(--accent);
    border-radius: 6px;
}

.confirm p { margin: 0 0 8px; }

.message.sent { border-left: 3px solid var(--accent); }

.message .meta { margin: 0 0 6px; overflow-wrap: anywhere; }

.triage-line { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: 0 0 8px; }

.message-body { white-space: pre-wrap; overflow-wrap: anywhere; margin: 8px 0 0; line-height: 1.5; }

/* Les fils : la catégorie en couleur, l'état en pastille, d'abord. */
.labels { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-bottom: 2px; }

.labels .tag { margin-left: 0; }

.category, .state {
    font-size: 0.75rem;
    font-weight: 600;
    border-radius: 4px;
    padding: 1px 8px;
    white-space: nowrap;
    color: var(--cat-text, var(--text));
    background: var(--cat-surface, var(--background));
}

.cat-ContactReply { --cat-text: var(--green); --cat-surface: var(--green-surface); }
.cat-PressRequest { --cat-text: var(--accent); --cat-surface: var(--accent-surface); }
.cat-UserRequest { --cat-text: var(--violet); --cat-surface: var(--violet-surface); }
.cat-Solicitation, .cat-Notification, .cat-Other { --cat-text: var(--muted); --cat-surface: var(--background); }

.state { font-weight: 500; border: 1px solid var(--line); background: transparent; color: var(--muted); }
.state-ToReply, .state-ToTriage { color: var(--amber); border-color: var(--amber); }
.state-DraftInProgress { color: var(--accent); border-color: var(--accent); }

.filters { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px; }

.filters .field { flex: 1 1 180px; margin-bottom: 0; }
