/* ECBF Comptabilité — feuille de style unique, thèmes clair et sombre. */

:root {
    --bg: #f2f4f1;
    --surface: #ffffff;
    --surface-2: #f7f9f6;
    --ink: #16201c;
    --muted: #5b6862;
    --line: #dce2dd;
    --line-strong: #c3ccc6;
    --accent: #1d6b57;
    --accent-hover: #175746;
    --accent-ink: #ffffff;
    --accent-soft: #e2efe9;
    --success: #1e7a45;
    --success-soft: #e1f2e7;
    --warning: #8f5b00;
    --warning-soft: #fbf0d9;
    --danger: #b3261e;
    --danger-soft: #fbe8e6;
    --info: #245b8f;
    --info-soft: #e5edf6;
    --chart-products: #1d6b57;
    --chart-charges: #c98a2b;
    --shadow: 0 1px 2px rgb(22 32 28 / 6%), 0 8px 24px rgb(22 32 28 / 8%);
    --radius: 6px;
    --font-sans: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    --font-mono: "IBM Plex Mono", ui-monospace, "Cascadia Mono", Consolas, monospace;
    --sidebar: 15.5rem;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg: #0e1412;
        --surface: #151d1a;
        --surface-2: #1a2420;
        --ink: #e5ebe7;
        --muted: #99a79f;
        --line: #29342f;
        --line-strong: #3a4741;
        --accent: #5cb99a;
        --accent-hover: #74c9ac;
        --accent-ink: #0b1411;
        --accent-soft: #1c322a;
        --success: #6bca8e;
        --success-soft: #16301f;
        --warning: #e3ad45;
        --warning-soft: #33280f;
        --danger: #f08a80;
        --danger-soft: #3a1f1c;
        --info: #88b7e8;
        --info-soft: #172838;
        --chart-products: #5cb99a;
        --chart-charges: #e0a54a;
        --shadow: 0 1px 2px rgb(0 0 0 / 40%), 0 8px 24px rgb(0 0 0 / 35%);
    }
}

:root[data-theme="dark"] {
    --bg: #0e1412;
    --surface: #151d1a;
    --surface-2: #1a2420;
    --ink: #e5ebe7;
    --muted: #99a79f;
    --line: #29342f;
    --line-strong: #3a4741;
    --accent: #5cb99a;
    --accent-hover: #74c9ac;
    --accent-ink: #0b1411;
    --accent-soft: #1c322a;
    --success: #6bca8e;
    --success-soft: #16301f;
    --warning: #e3ad45;
    --warning-soft: #33280f;
    --danger: #f08a80;
    --danger-soft: #3a1f1c;
    --info: #88b7e8;
    --info-soft: #172838;
    --chart-products: #5cb99a;
    --chart-charges: #e0a54a;
    --shadow: 0 1px 2px rgb(0 0 0 / 40%), 0 8px 24px rgb(0 0 0 / 35%);
}

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

/* L'attribut hidden l'emporte toujours sur les display des composants (flex, grid…). */
[hidden] { display: none !important; }

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

body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font: 400 0.9375rem/1.5 var(--font-sans);
}

h1, h2, h3 { margin: 0; line-height: 1.25; text-wrap: balance; }
h1 { font-size: 1.6rem; font-weight: 600; letter-spacing: -0.01em; }
h2 { font-size: 1.05rem; font-weight: 600; }
h3 { font-size: 0.95rem; font-weight: 600; margin-block: 1rem 0.5rem; }
p { margin: 0; }
a { color: var(--accent); }
a:hover { color: var(--accent-hover); }
code, .mono, .code { font-family: var(--font-mono); font-size: 0.88em; }
abbr { text-decoration: none; }

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

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

.muted { color: var(--muted); }
.small { font-size: 0.82rem; }
.nowrap { white-space: nowrap; }
.negative, .overdue { color: var(--danger); }
.amount { font-family: var(--font-mono); font-variant-numeric: tabular-nums; white-space: nowrap; }
.clamp { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.noscript { padding: 2rem; }

/* ------------------------------------------------------------------ */
/* Structure                                                           */
/* ------------------------------------------------------------------ */

.skip-link {
    position: absolute; left: 1rem; top: -3rem; z-index: 100;
    background: var(--accent); color: var(--accent-ink); padding: 0.5rem 0.75rem; border-radius: var(--radius);
}
.skip-link:focus { top: 1rem; }

.layout { display: grid; grid-template-columns: var(--sidebar) minmax(0, 1fr); min-height: 100vh; }

.sidebar {
    position: sticky; top: 0; height: 100vh; overflow-y: auto;
    display: flex; flex-direction: column; gap: 1.25rem;
    padding: 1.25rem 0.75rem; background: var(--surface); border-right: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 0.6rem; padding-inline: 0.5rem; color: var(--ink); text-decoration: none; font-weight: 600; }
.brand-mark {
    display: inline-grid; place-items: center; width: 2rem; height: 2rem; border-radius: var(--radius);
    background: var(--accent); color: var(--accent-ink); font: 600 0.8rem var(--font-mono); letter-spacing: 0.02em;
}

.nav-group { display: flex; flex-direction: column; gap: 0.1rem; }
.nav-group-title {
    padding: 0 0.6rem 0.3rem; color: var(--muted);
    font-size: 0.7rem; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase;
}
.nav-link { display: block; padding: 0.42rem 0.6rem; border-radius: var(--radius); color: var(--ink); text-decoration: none; }
.nav-link:hover { background: var(--surface-2); color: var(--ink); }
.nav-link.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav-footer { margin-top: auto; padding-inline: 0.6rem; color: var(--muted); font-size: 0.75rem; }

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

.topbar {
    position: sticky; top: 0; z-index: 20;
    display: flex; align-items: center; gap: 1rem; min-height: 3.5rem; padding-inline: 1.5rem;
    background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(6px);
    border-bottom: 1px solid var(--line);
}
.topbar-org { flex: 1; min-width: 0; font-weight: 600; }
.org-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: block; }
.org-select { max-width: 22rem; }
.topbar-user { display: flex; align-items: center; gap: 0.75rem; }
.user-name { color: var(--muted); font-size: 0.875rem; }
.nav-toggle { display: none; }
.nav-backdrop { display: none; }

.main { padding: 1.5rem 1.5rem 3rem; outline: none; max-width: 90rem; width: 100%; }
.view { display: flex; flex-direction: column; gap: 1.25rem; }
.boot { min-height: 100vh; display: grid; place-items: center; }

.page-header { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 1rem; }
.page-header > div:first-child { min-width: 0; max-width: 62ch; }
.eyebrow { color: var(--muted); font-size: 0.75rem; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; margin-bottom: 0.25rem; }
.page-subtitle { color: var(--muted); margin-top: 0.35rem; }
.page-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.1rem 1.25rem; display: flex; flex-direction: column; gap: 0.75rem; }
.section-title { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; flex-wrap: wrap; }
.section-heading { margin-block: 0.5rem; }

/* ------------------------------------------------------------------ */
/* Contrôles                                                           */
/* ------------------------------------------------------------------ */

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
    min-height: 2.25rem; padding: 0.4rem 0.9rem; border-radius: var(--radius);
    border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink);
    font: 500 0.875rem/1.2 var(--font-sans); text-decoration: none; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); color: var(--ink); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: var(--accent-ink); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger); color: #fff; filter: brightness(0.92); }
.btn-ghost { border-color: transparent; background: transparent; color: var(--accent); }
.btn-ghost:hover { background: var(--accent-soft); color: var(--accent); }
.btn-icon { font-weight: 600; }

.icon-button {
    display: inline-grid; place-items: center; width: 2rem; height: 2rem; border-radius: var(--radius);
    border: 1px solid transparent; background: transparent; color: var(--muted); font-size: 1.25rem; cursor: pointer;
}
.icon-button:hover { background: var(--surface-2); color: var(--ink); }
.icon-button:disabled { visibility: hidden; }
.link-button { border: 0; background: none; color: var(--accent); cursor: pointer; font: inherit; font-size: 0.8rem; padding: 0; text-decoration: underline; }
.text-link { font-size: 0.875rem; font-weight: 500; }

.input {
    width: 100%; min-height: 2.25rem; padding: 0.4rem 0.6rem;
    border: 1px solid var(--line-strong); border-radius: var(--radius);
    background: var(--surface); color: var(--ink); font: inherit;
}
.input:focus { outline: 2px solid color-mix(in srgb, var(--accent) 40%, transparent); border-color: var(--accent); }
.input:disabled { background: var(--surface-2); color: var(--muted); }
.input.num { text-align: right; font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.input.invalid, .has-error .input { border-color: var(--danger); }
textarea.input { resize: vertical; }

.field { display: flex; flex-direction: column; gap: 0.3rem; min-width: 0; }
.field > label, .setting-row > label { font-size: 0.8rem; font-weight: 600; color: var(--muted); }
.required { color: var(--danger); }
.field-hint { font-size: 0.78rem; color: var(--muted); }
.field-error { font-size: 0.8rem; color: var(--danger); }
.field-error:empty { display: none; }

.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr)); gap: 0.9rem; }
.form-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; align-items: center; gap: 0.6rem; }
.form-messages:empty { display: none; }
.check-field { display: flex; align-items: flex-start; gap: 0.5rem; }
.check-field input { margin-top: 0.3rem; }
.checks { border: 1px solid var(--line); border-radius: var(--radius); padding: 0.75rem 1rem; display: grid; gap: 0.5rem; margin: 0; }
.checks legend { font-size: 0.8rem; font-weight: 600; color: var(--muted); padding-inline: 0.25rem; }
.inline-field { display: inline-flex; flex-direction: column; vertical-align: middle; max-width: 8rem; }

.filter-bar { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 0.75rem; padding: 0.9rem 1rem; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.filter { display: flex; flex-direction: column; gap: 0.25rem; min-width: 8.5rem; flex: 0 1 auto; }
.filter label { font-size: 0.75rem; font-weight: 600; color: var(--muted); }
.filter.checkbox { flex-direction: row; align-items: center; min-height: 2.25rem; min-width: 0; }
.filter.checkbox label { font-size: 0.85rem; font-weight: 400; color: var(--ink); }

/* Suggestions */
.ac { position: relative; min-width: 0; }
.ac-list {
    position: absolute; z-index: 30; left: 0; right: 0; top: calc(100% + 2px); min-width: 16rem;
    margin: 0; padding: 0.25rem; list-style: none; max-height: 18rem; overflow-y: auto;
    background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--radius); box-shadow: var(--shadow);
}
.ac-list li { display: flex; gap: 0.6rem; padding: 0.4rem 0.5rem; border-radius: 4px; cursor: pointer; }
.ac-list li.active, .ac-list li:hover { background: var(--accent-soft); }
.ac-code { font-family: var(--font-mono); font-size: 0.85rem; color: var(--accent); white-space: nowrap; }
.ac-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ac-list li.ac-empty { color: var(--muted); cursor: default; }

/* ------------------------------------------------------------------ */
/* États et messages                                                   */
/* ------------------------------------------------------------------ */

.pill {
    display: inline-flex; align-items: center; padding: 0.1rem 0.5rem; border-radius: 999px;
    font-size: 0.75rem; font-weight: 600; line-height: 1.5; white-space: nowrap;
    background: var(--surface-2); color: var(--muted); border: 1px solid var(--line);
}
.pill-success { background: var(--success-soft); color: var(--success); border-color: transparent; }
.pill-warning { background: var(--warning-soft); color: var(--warning); border-color: transparent; }
.pill-danger { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.pill-neutral { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.pill-muted { background: transparent; color: var(--muted); }
.pill-row { display: inline-flex; flex-wrap: wrap; gap: 0.3rem; align-items: center; }

.alert { padding: 0.7rem 0.9rem; border-radius: var(--radius); border-left: 3px solid; font-size: 0.9rem; }
.alert ul { margin: 0.4rem 0 0; padding-left: 1.1rem; }
.alert-danger { background: var(--danger-soft); border-color: var(--danger); }
.alert-warning { background: var(--warning-soft); border-color: var(--warning); }
.alert-info { background: var(--info-soft); border-color: var(--info); }

.loading { display: flex; align-items: center; gap: 0.6rem; padding: 2rem 0; color: var(--muted); }
.spinner { width: 1rem; height: 1rem; border: 2px solid var(--line-strong); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.empty-state { padding: 2.5rem 1.5rem; text-align: center; background: var(--surface); border: 1px dashed var(--line-strong); border-radius: var(--radius); display: grid; gap: 0.5rem; justify-items: center; }
.empty-state p { max-width: 55ch; color: var(--muted); }
.empty-state .empty-title { color: var(--ink); font-weight: 600; font-size: 1.05rem; }

.toasts { position: fixed; right: 1rem; bottom: 1rem; z-index: 200; display: flex; flex-direction: column; gap: 0.5rem; max-width: min(26rem, calc(100vw - 2rem)); }
.toast { padding: 0.7rem 0.9rem; border-radius: var(--radius); background: var(--ink); color: var(--bg); box-shadow: var(--shadow); transition: opacity 0.3s, transform 0.3s; }
.toast-danger { background: var(--danger); color: #fff; }
.toast-warning { background: var(--warning); color: #fff; }
.toast.leaving { opacity: 0; transform: translateY(0.5rem); }

.modal { width: min(36rem, calc(100vw - 2rem)); max-height: calc(100vh - 2rem); padding: 0; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.modal-wide { width: min(56rem, calc(100vw - 2rem)); }
.modal::backdrop { background: rgb(10 16 14 / 45%); }
.modal-header { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 1rem 1.25rem; border-bottom: 1px solid var(--line); }
.modal-body { padding: 1rem 1.25rem; display: flex; flex-direction: column; gap: 0.9rem; }
.modal-footer { display: flex; justify-content: flex-end; gap: 0.5rem; padding: 0.9rem 1.25rem; border-top: 1px solid var(--line); background: var(--surface-2); }

/* ------------------------------------------------------------------ */
/* Tableaux                                                            */
/* ------------------------------------------------------------------ */

.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.data-table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
.data-table th, .data-table td { padding: 0.5rem 0.7rem; text-align: left; vertical-align: top; border-bottom: 1px solid var(--line); }
.data-table thead th { position: sticky; top: 0; background: var(--surface-2); color: var(--muted); font-size: 0.72rem; font-weight: 600; letter-spacing: 0.05em; text-transform: uppercase; white-space: nowrap; }
.data-table .num { text-align: right; }
.data-table tbody tr:last-child td { border-bottom: 0; }
.data-table tfoot th, .data-table tfoot td { background: var(--surface-2); border-top: 2px solid var(--line-strong); border-bottom: 0; font-weight: 600; }
.data-table tr.clickable { cursor: pointer; }
.data-table tr.clickable:hover td, .data-table tr.selected td { background: var(--accent-soft); }
.data-table .empty-row td { padding: 2rem; text-align: center; color: var(--muted); }
.row-draft td:first-child { box-shadow: inset 3px 0 0 var(--warning); }
.row-warning td { background: color-mix(in srgb, var(--warning-soft) 60%, transparent); }
.row-lettered td { color: var(--muted); }
.row-special td { background: var(--surface-2); }
.subtotal-row td { background: var(--surface-2); border-bottom: 2px solid var(--line-strong); }
.group-row td { background: var(--surface-2); }
.entry-head-row td { background: var(--surface-2); border-top: 2px solid var(--line-strong); }
.entry-line-row td:first-child { padding-left: 1.5rem; }
.credit { color: var(--info); }

.account-link { display: inline-flex; gap: 0.4rem; text-decoration: none; }
.account-link .code { color: var(--accent); }
.account-link .account-name { color: var(--ink); }
.account-link:hover .account-name { text-decoration: underline; }
.entry-link { font-family: var(--font-mono); font-size: 0.85rem; }
.sub-accounts { display: flex; gap: 0.5rem; font-size: 0.8rem; }

.result-count, .report-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 0.6rem 1rem; color: var(--muted); font-size: 0.85rem; }
.pager { display: flex; justify-content: center; align-items: center; gap: 1rem; padding-top: 0.5rem; color: var(--muted); }

.tabs { display: flex; gap: 0.25rem; border-bottom: 1px solid var(--line); overflow-x: auto; }
.tab { padding: 0.55rem 0.9rem; color: var(--muted); text-decoration: none; border-bottom: 2px solid transparent; white-space: nowrap; font-weight: 500; }
.tab:hover { color: var(--ink); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab-badge { margin-left: 0.4rem; font-size: 0.7rem; color: var(--muted); }

/* ------------------------------------------------------------------ */
/* Connexion                                                           */
/* ------------------------------------------------------------------ */

/* Fond volontairement sombre dans les deux thèmes (titre et pied de page en blanc) ;
   la carte suit les jetons du thème. */
.login-screen {
    min-height: 100vh;
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2rem;
    padding: 2.5rem 16px 1.5rem;
    color: #ffffff;
    background-color: #0c1a16;
    background-image:
        linear-gradient(rgb(8 18 15 / 72%), rgb(8 18 15 / 86%)),
        linear-gradient(rgb(255 255 255 / 5%) 1px, transparent 1px),
        linear-gradient(90deg, rgb(255 255 255 / 5%) 1px, transparent 1px),
        radial-gradient(circle at 20% 15%, #1d6b57 0, transparent 45%),
        radial-gradient(circle at 85% 90%, #7a5a12 0, transparent 40%),
        linear-gradient(135deg, #123c31, #0c1a16 60%);
    background-size: auto, 32px 32px, 32px 32px, auto, auto, auto;
}

.login-header { text-align: center; display: grid; gap: 0.5rem; justify-items: center; }
.login-kicker { display: inline-flex; align-items: center; gap: 0.5rem; font-size: 0.78rem; font-weight: 600; letter-spacing: 0.12em; text-transform: uppercase; color: rgb(255 255 255 / 75%); }
.login-kicker .brand-mark { width: 1.6rem; height: 1.6rem; font-size: 0.65rem; background: #ffffff; color: #1d6b57; }
.login-header h1 { font-size: clamp(1.6rem, 4vw, 2.4rem); font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; color: #ffffff; text-shadow: 0 2px 12px rgb(0 0 0 / 35%); }

.login-card {
    width: min(58rem, 100%);
    display: grid;
    grid-template-columns: minmax(0, 13rem) minmax(0, 12rem) minmax(0, 1fr);
    background: var(--surface);
    color: var(--ink);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: 0 24px 60px rgb(0 0 0 / 45%);
}

.login-art { position: relative; min-height: 22rem; background: #0f3d31; }
.login-art svg { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

.login-tabs { display: grid; grid-auto-rows: 1fr; border-right: 1px solid var(--line); }
.login-tab {
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0.45rem;
    padding: 1rem 0.75rem; border: 0; border-bottom: 1px solid var(--line);
    background: var(--surface); color: var(--ink);
    font: 500 0.9rem/1.3 var(--font-sans); text-align: center; cursor: pointer;
    transition: background-color 0.15s ease, color 0.15s ease;
}
.login-tab:last-child { border-bottom: 0; }
.login-tab:hover { background: var(--surface-2); }
.login-tab.active { background: var(--accent); color: var(--accent-ink); }
.login-tab:focus-visible { outline-offset: -4px; }

.login-content { display: flex; flex-direction: column; gap: 1.1rem; padding: 2rem clamp(1.25rem, 3vw, 2.25rem); }
.login-title { font-size: 1.3rem; font-weight: 500; text-align: center; }
.login-body { display: flex; flex-direction: column; gap: 0.9rem; }

.login-form { display: flex; flex-direction: column; gap: 0.85rem; }
.login-input {
    display: flex; align-items: center; gap: 0.6rem;
    padding-inline: 0.8rem; border-radius: var(--radius);
    background: var(--surface-2); border: 1px solid var(--line); color: var(--muted);
}
.login-input:focus-within { border-color: var(--accent); outline: 2px solid color-mix(in srgb, var(--accent) 35%, transparent); }
.login-input .input { flex: 1 1 auto; min-width: 0; border: 0; background: transparent; min-height: 2.75rem; padding-inline: 0; outline: none; }
.login-input svg { flex: 0 0 auto; }
.login-tab span { overflow-wrap: anywhere; }
.login-input .input:focus { outline: none; }
.login-form .btn-primary, .login-info .btn-primary { width: 100%; min-height: 2.75rem; font-weight: 600; letter-spacing: 0.04em; }
.login-link { align-self: center; border: 0; background: none; color: var(--muted); font: inherit; font-size: 0.85rem; cursor: pointer; padding: 0.25rem; }
.login-link:hover { color: var(--accent); text-decoration: underline; }

.login-info { display: flex; flex-direction: column; gap: 0.85rem; font-size: 0.92rem; }
.login-info ol { margin: 0; padding-left: 1.2rem; display: grid; gap: 0.35rem; }
.login-note { font-size: 0.82rem; color: var(--muted); }

.login-footer { font-size: 0.8rem; color: rgb(255 255 255 / 70%); text-align: center; text-wrap: balance; }

@media (max-width: 900px) {
    .login-card { grid-template-columns: minmax(0, 11rem) minmax(0, 1fr); }
    .login-art { display: none; }
}

@media (max-width: 600px) {
    .login-screen { justify-content: flex-start; gap: 1.25rem; padding-top: 1.75rem; }
    .login-card { grid-template-columns: minmax(0, 1fr); }
    .login-tabs { grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); grid-auto-rows: auto; border-right: 0; border-bottom: 1px solid var(--line); }
    .login-tab { border-bottom: 0; border-right: 1px solid var(--line); padding: 0.75rem 0.4rem; font-size: 0.78rem; }
    .login-tab:last-child { border-right: 0; }
    .login-content { padding: 1.5rem 1.1rem; }
}

@media (prefers-reduced-motion: reduce) {
    .login-tab { transition: none; }
}

/* ------------------------------------------------------------------ */
/* Tableau de bord                                                     */
/* ------------------------------------------------------------------ */

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(11.5rem, 1fr)); gap: 0.75rem; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 0.9rem 1rem; display: grid; gap: 0.2rem; }
.kpi-label { font-size: 0.75rem; font-weight: 600; color: var(--muted); letter-spacing: 0.04em; text-transform: uppercase; }
.kpi-value { font-size: 1.35rem; font-weight: 600; }
.kpi-value .currency { font-size: 0.75rem; color: var(--muted); font-weight: 500; }
.kpi-note { font-size: 0.8rem; color: var(--muted); }
.kpi-positive .kpi-value { color: var(--success); }
.kpi-negative .kpi-value { color: var(--danger); }
.kpi-attention { border-top: 3px solid var(--warning); }

.dashboard-grid { display: grid; grid-template-columns: minmax(0, 2fr) minmax(16rem, 1fr); gap: 1rem; align-items: start; }
.side-stack { display: grid; gap: 1rem; }
.legend { display: flex; gap: 1rem; font-size: 0.8rem; color: var(--muted); }
.legend-item::before { content: ""; display: inline-block; width: 0.7rem; height: 0.7rem; border-radius: 2px; margin-right: 0.35rem; vertical-align: -1px; }
.legend-item.products::before { background: var(--chart-products); }
.legend-item.charges::before { background: var(--chart-charges); }
.chart-wrap { width: 100%; overflow-x: auto; }
.chart { width: 100%; min-width: 30rem; height: auto; display: block; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .tick { fill: var(--muted); font: 11px var(--font-mono); }
.chart .bar-products { fill: var(--chart-products); }
.chart .bar-charges { fill: var(--chart-charges); }

.progress { height: 0.5rem; background: var(--surface-2); border: 1px solid var(--line); border-radius: 999px; overflow: hidden; }
.progress-bar { display: block; height: 100%; background: var(--accent); }
.stat-list { margin: 0; display: grid; gap: 0.35rem; }
.stat { display: flex; justify-content: space-between; gap: 1rem; padding-block: 0.25rem; border-bottom: 1px solid var(--line); }
.stat:last-child { border-bottom: 0; }
.stat dt { color: var(--muted); }
.stat dd { margin: 0; font-family: var(--font-mono); font-weight: 600; }
.stat.highlight dd a { color: var(--warning); }
.plain-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.4rem; }
.split { display: flex; justify-content: space-between; gap: 1rem; }

/* ------------------------------------------------------------------ */
/* Saisie d'écriture                                                   */
/* ------------------------------------------------------------------ */

.entry-form { display: flex; flex-direction: column; gap: 1rem; }
.lines-head, .line-main { display: grid; grid-template-columns: 1.75rem minmax(12rem, 1.3fr) minmax(10rem, 1.5fr) minmax(15rem, 1fr) 2rem; gap: 0.5rem; align-items: start; }
.lines-head { padding-inline: 0.5rem; font-size: 0.72rem; font-weight: 600; letter-spacing: 0.05em; text-transform: uppercase; color: var(--muted); }
.lines-head .num:nth-child(4) { text-align: right; }
.lines-head span:nth-child(5) { display: none; }
.amount-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem; }
.entry-lines { display: flex; flex-direction: column; gap: 0.5rem; }
.entry-line { padding: 0.6rem 0.5rem; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface-2); display: grid; gap: 0.5rem; }
.line-number { padding-top: 0.5rem; font-family: var(--font-mono); color: var(--muted); font-size: 0.85rem; }
.line-details { display: grid; grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr)); gap: 0.5rem; padding-left: 2.25rem; }
.line-details label { font-size: 0.72rem; font-weight: 600; color: var(--muted); }
.requires-analytics .line-project label { color: var(--warning); }
.lines-actions { display: flex; justify-content: flex-start; }
.entry-totals { display: flex; flex-wrap: wrap; justify-content: flex-end; align-items: center; gap: 0.75rem 1.5rem; padding-top: 0.75rem; border-top: 2px solid var(--line-strong); }
.total { display: flex; align-items: baseline; gap: 0.5rem; }
.total > span:first-child { font-size: 0.8rem; color: var(--muted); }
.total .amount { font-size: 1.05rem; }
.difference { color: var(--danger); }

.facts { margin: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(13rem, 1fr)); gap: 0.75rem 1.25rem; }
.fact dt { font-size: 0.72rem; font-weight: 600; color: var(--muted); letter-spacing: 0.04em; text-transform: uppercase; }
.fact dd { margin: 0.15rem 0 0; }
.back-link { font-size: 0.875rem; }

/* ------------------------------------------------------------------ */
/* États, lettrage, clôture, paramétrage                                */
/* ------------------------------------------------------------------ */

.ledger-account { display: flex; flex-direction: column; gap: 0.5rem; }
.ledger-account + .ledger-account { margin-top: 1rem; }
.ledger-account-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: 0.5rem; }
.ledger-account-head .code { color: var(--accent); }

.aged-details { display: grid; gap: 0.5rem; }
.aged-detail { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 0.6rem 0.9rem; }
.aged-detail summary { cursor: pointer; font-weight: 500; }
.aged-detail[open] summary { margin-bottom: 0.6rem; }

.lettering-summary {
    position: sticky; bottom: 0; z-index: 10;
    display: flex; flex-wrap: wrap; justify-content: flex-end; align-items: center; gap: 0.75rem 1.5rem;
    padding: 0.75rem 1rem; background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--radius); box-shadow: var(--shadow);
}
.lettering-summary:empty { display: none; }
.lettering-code { display: inline-flex; align-items: center; gap: 0.4rem; }

.statements-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(22rem, 1fr)); gap: 1rem; align-items: start; }
.statement-table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
.statement-table th, .statement-table td { padding: 0.4rem 0; border-bottom: 1px solid var(--line); text-align: left; font-weight: 400; }
.statement-table td { text-align: right; }
.statement-table tr.subtotal th, .statement-table tr.subtotal td { font-weight: 600; background: var(--surface-2); }
.statement-table tr.result th, .statement-table tr.result td { font-weight: 600; border-bottom: 2px solid var(--line-strong); }
.statement-table tr.total th, .statement-table tr.total td { font-weight: 700; border-top: 2px solid var(--ink); border-bottom: 0; padding-top: 0.6rem; }

.checklist { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.4rem; }
.checklist li { display: flex; flex-wrap: wrap; align-items: center; gap: 0.6rem; }
.check-mark { display: inline-grid; place-items: center; width: 1.3rem; height: 1.3rem; border-radius: 50%; font-size: 0.75rem; font-weight: 700; }
.checklist .ok .check-mark { background: var(--success-soft); color: var(--success); }
.checklist .ko .check-mark { background: var(--warning-soft); color: var(--warning); }

.export-grid, .posting-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(20rem, 1fr)); gap: 1rem; align-items: start; }
.batch-report { display: grid; gap: 0.5rem; }

.settings-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(24rem, 1fr)); gap: 1rem; align-items: start; }
.setting-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr); gap: 0.75rem; align-items: center; padding-block: 0.35rem; border-bottom: 1px solid var(--line); }
.setting-row:last-child { border-bottom: 0; }
.setting-row > label { font-size: 0.875rem; font-weight: 500; color: var(--ink); display: grid; }
.setting-key { font: 0.7rem var(--font-mono); color: var(--muted); }

/* ------------------------------------------------------------------ */
/* Écrans étroits                                                      */
/* ------------------------------------------------------------------ */

@media (max-width: 1100px) {
    .dashboard-grid { grid-template-columns: 1fr; }
}

@media (max-width: 960px) {
    .layout { grid-template-columns: 1fr; }
    .sidebar {
        position: fixed; inset: 0 auto 0 0; z-index: 60; width: min(var(--sidebar), 85vw);
        transform: translateX(-100%); transition: transform 0.2s ease; box-shadow: var(--shadow);
    }
    body.nav-open .sidebar { transform: none; }
    body.nav-open .nav-backdrop { display: block; position: fixed; inset: 0; z-index: 50; background: rgb(10 16 14 / 40%); }
    .nav-toggle { display: inline-grid; }
    .topbar { padding-inline: 1rem; }
    .main { padding: 1rem 1rem 2.5rem; }
}

@media (max-width: 760px) {
    .lines-head { display: none; }
    .line-main { grid-template-columns: 1.5rem minmax(0, 1fr) 2rem; }
    .line-main .line-account { grid-column: 2; }
    .line-main .line-label, .line-main .line-amounts { grid-column: 2 / 3; }
    .line-main .line-remove { grid-column: 3; grid-row: 1; }
    .line-details { padding-left: 0; }
    .user-name { display: none; }
    .setting-row { grid-template-columns: 1fr; }
    .settings-grid, .statements-grid, .export-grid, .posting-grid { grid-template-columns: 1fr; }
    .filter { flex: 1 1 10rem; }
    .entry-totals { justify-content: flex-start; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
