/* =========================================================================
   Design system du back-office
   Chaleureux et professionnel : papier clair, vert profond, accents terre cuite.
   Aucun build nécessaire (fichier servi tel quel depuis /public).
   ========================================================================= */

:root {
    --bg: #f6f5f1;
    --surface: #ffffff;
    --surface-2: #faf9f6;
    --surface-3: #f1efe9;
    --border: #e6e2da;
    --border-strong: #d6d1c6;
    --ink: #1f1d1a;
    --ink-2: #57534c;
    --ink-3: #8b867c;

    --primary: #1f5f55;
    --primary-hover: #174a42;
    --primary-soft: #e5efec;
    --primary-ink: #ffffff;
    --accent: #c0663a;
    --accent-soft: #f8ebe3;

    --success: #2f7a4d;
    --success-soft: #e6f2ea;
    --warning: #a86a10;
    --warning-soft: #fbf1df;
    --danger: #b4402f;
    --danger-soft: #f9e8e5;

    --sidebar-bg: #fbfaf7;
    --ring: 0 0 0 3px rgba(31, 95, 85, .18);
    --shadow-sm: 0 1px 2px rgba(31, 29, 26, .05);
    --shadow: 0 1px 2px rgba(31, 29, 26, .04), 0 4px 16px rgba(31, 29, 26, .05);
    --shadow-lg: 0 12px 40px rgba(31, 29, 26, .14);

    --radius-sm: 8px;
    --radius: 12px;
    --radius-lg: 18px;

    --font: "Plus Jakarta Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
    --font-display: "Fraunces", Georgia, serif;
    --sidebar-w: 268px;

    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg: #121211;
        --surface: #1b1a18;
        --surface-2: #201f1c;
        --surface-3: #262522;
        --border: #2e2c28;
        --border-strong: #3b3934;
        --ink: #f1eee8;
        --ink-2: #bcb7ad;
        --ink-3: #888379;
        --primary: #5fb3a1;
        --primary-hover: #74c3b1;
        --primary-soft: #1d302c;
        --primary-ink: #0d1f1b;
        --accent: #e08a5c;
        --accent-soft: #33231b;
        --success: #6cc08d;
        --success-soft: #1a2b20;
        --warning: #e0a54a;
        --warning-soft: #30261a;
        --danger: #ec7f6d;
        --danger-soft: #331d19;
        --sidebar-bg: #161614;
        --ring: 0 0 0 3px rgba(95, 179, 161, .25);
        --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
        --shadow-lg: 0 12px 40px rgba(0, 0, 0, .5);
        color-scheme: dark;
    }
}
:root[data-theme="dark"] {
        --bg: #121211;
        --surface: #1b1a18;
        --surface-2: #201f1c;
        --surface-3: #262522;
        --border: #2e2c28;
        --border-strong: #3b3934;
        --ink: #f1eee8;
        --ink-2: #bcb7ad;
        --ink-3: #888379;
        --primary: #5fb3a1;
        --primary-hover: #74c3b1;
        --primary-soft: #1d302c;
        --primary-ink: #0d1f1b;
        --accent: #e08a5c;
        --accent-soft: #33231b;
        --success: #6cc08d;
        --success-soft: #1a2b20;
        --warning: #e0a54a;
        --warning-soft: #30261a;
        --danger: #ec7f6d;
        --danger-soft: #331d19;
        --sidebar-bg: #161614;
        --ring: 0 0 0 3px rgba(95, 179, 161, .25);
        --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
        --shadow-lg: 0 12px 40px rgba(0, 0, 0, .5);
        color-scheme: dark;
    }

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    font-family: var(--font);
    font-size: 14.5px;
    line-height: 1.55;
    color: var(--ink);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-hover); }
h1, h2, h3, h4 { margin: 0; line-height: 1.25; font-weight: 700; letter-spacing: -.01em; }
p { margin: 0; }
svg.icon { flex-shrink: 0; }
:focus-visible { outline: none; box-shadow: var(--ring); border-radius: 6px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--ink-2); }
.subtle { color: var(--ink-3); }
.small { font-size: 13px; }
.mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 12.5px; }
.nowrap { white-space: nowrap; }
.text-right { text-align: right; }

/* ---------- Layout ---------- */
.app { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); min-height: 100vh; }

.sidebar {
    position: sticky; top: 0; height: 100vh;
    display: flex; flex-direction: column;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--border);
    padding: 18px 14px;
    overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 18px; color: var(--ink); font-weight: 700; font-size: 16px; }
.brand:hover { color: var(--ink); }
.brand-mark {
    width: 32px; height: 32px; border-radius: 9px;
    display: grid; place-items: center;
    background: var(--primary); color: var(--primary-ink);
    font-family: var(--font-display); font-size: 18px; font-weight: 600;
}
.brand small { display: block; font-weight: 500; font-size: 11.5px; color: var(--ink-3); letter-spacing: .02em; }

.workspace {
    display: flex; align-items: center; gap: 10px;
    width: 100%; padding: 10px; margin-bottom: 18px;
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    box-shadow: var(--shadow-sm); color: var(--ink); text-align: left;
    font: inherit; cursor: pointer;
}
a.workspace:hover { border-color: var(--border-strong); color: var(--ink); }
.workspace-info { min-width: 0; flex: 1; }
.workspace-name { font-weight: 650; font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.workspace-role { font-size: 12px; color: var(--ink-3); }

.nav-group { margin-bottom: 16px; }
.nav-label { padding: 0 10px 6px; font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-3); }
.nav-link {
    display: flex; align-items: center; gap: 11px;
    padding: 8px 10px; margin-bottom: 2px; border-radius: 9px;
    color: var(--ink-2); font-weight: 550; font-size: 14px;
    transition: background .15s, color .15s;
}
.nav-link:hover { background: var(--surface-3); color: var(--ink); }
.nav-link.active { background: var(--primary-soft); color: var(--primary); }
.nav-link.active .icon { color: var(--primary); }
.nav-link .icon { color: var(--ink-3); }
.nav-link .count { margin-left: auto; font-size: 11.5px; color: var(--ink-3); font-weight: 600; }

.sidebar-foot { margin-top: auto; padding-top: 14px; border-top: 1px solid var(--border); }
.me { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 10px; color: var(--ink); }
.me:hover { background: var(--surface-3); color: var(--ink); }
.me-info { min-width: 0; flex: 1; }
.me-name { font-weight: 600; font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.me-mail { font-size: 12px; color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
    position: sticky; top: 0; z-index: 20;
    display: flex; align-items: center; gap: 12px;
    padding: 12px 32px;
    background: color-mix(in srgb, var(--bg) 85%, transparent);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid transparent;
}
.crumbs { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--ink-3); min-width: 0; }
.crumbs a { color: var(--ink-3); }
.crumbs a:hover { color: var(--ink); }
.crumbs .current { color: var(--ink-2); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.content { padding: 8px 32px 56px; max-width: 1240px; width: 100%; }
.topbar .menu-toggle { display: none; }
.scrim { display: none; }

/* ---------- Page header ---------- */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin: 12px 0 24px; }
.page-head h1 { font-size: 26px; }
.page-head .lead { margin-top: 6px; color: var(--ink-2); max-width: 640px; }
.page-head-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.back { display: inline-flex; align-items: center; gap: 6px; margin-bottom: 10px; font-size: 13px; color: var(--ink-3); font-weight: 550; }
.back:hover { color: var(--ink); }
.display { font-family: var(--font-display); font-weight: 500; letter-spacing: -.015em; }

/* ---------- Cards ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-sm); }
.card-pad { padding: 22px 24px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 18px 24px; border-bottom: 1px solid var(--border); }
.card-head h2, .card-head h3 { font-size: 15.5px; }
.card-head p { font-size: 13px; color: var(--ink-3); margin-top: 2px; }
.card-body { padding: 20px 24px; }
.card-foot { padding: 14px 24px; border-top: 1px solid var(--border); background: var(--surface-2); border-radius: 0 0 var(--radius-lg) var(--radius-lg); }
.stack { display: grid; gap: 20px; }
.stack > *, .grid > * { min-width: 0; } /* un texte non coupé ne doit jamais élargir la grille */
.grid { display: grid; gap: 20px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-main { grid-template-columns: minmax(0, 1.65fr) minmax(0, 1fr); align-items: start; }
.row { display: flex; align-items: center; gap: 10px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.wrap { flex-wrap: wrap; }

/* ---------- Hero / greeting ---------- */
.hero {
    position: relative; overflow: hidden;
    padding: 28px 30px; margin: 12px 0 24px;
    border-radius: var(--radius-lg);
    background:
        radial-gradient(1200px 300px at 100% 0%, color-mix(in srgb, var(--accent) 16%, transparent), transparent 60%),
        linear-gradient(135deg, var(--primary) 0%, color-mix(in srgb, var(--primary) 70%, #0b2a25) 100%);
    color: #fff;
}
.hero h1 { font-family: var(--font-display); font-weight: 500; font-size: 30px; letter-spacing: -.02em; }
.hero p { color: rgba(255, 255, 255, .82); margin-top: 6px; max-width: 620px; }
.hero .chips { margin-top: 16px; display: flex; flex-wrap: wrap; gap: 8px; }
.hero .chip { background: rgba(255, 255, 255, .14); color: #fff; border: 1px solid rgba(255, 255, 255, .18); }


/* ---------- Stats ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 14px; margin-bottom: 24px; }
.stat {
    display: flex; flex-direction: column; gap: 14px;
    padding: 18px; border-radius: var(--radius);
    background: var(--surface); border: 1px solid var(--border);
    color: var(--ink); transition: border-color .15s, transform .15s, box-shadow .15s;
}
a.stat:hover { color: var(--ink); border-color: var(--border-strong); box-shadow: var(--shadow); transform: translateY(-1px); }
.stat-top { display: flex; align-items: center; justify-content: space-between; }
.stat-label { font-size: 13px; color: var(--ink-2); font-weight: 550; }
.stat-value { font-size: 28px; font-weight: 700; letter-spacing: -.02em; line-height: 1; font-variant-numeric: tabular-nums; }
.stat-value small { font-size: 14px; font-weight: 600; color: var(--ink-3); margin-left: 4px; }
.stat-hint { font-size: 12px; color: var(--ink-3); }

.icon-tile { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; }

/* ---------- Tones (postes, stats, avatars) ---------- */
.tone-indigo { --t: #4f46b8; --t-soft: #ecebfa; }
.tone-teal { --t: #1f7a6d; --t-soft: #e3f1ee; }
.tone-amber { --t: #a7650c; --t-soft: #fbf0dc; }
.tone-rose { --t: #b23a5a; --t-soft: #f9e6ec; }
.tone-sky { --t: #22709e; --t-soft: #e3f0f8; }
.tone-violet { --t: #7a46b0; --t-soft: #f1e9f9; }
.tone-emerald { --t: #2a7a45; --t-soft: #e4f2e8; }
.tone-slate { --t: #55606e; --t-soft: #eceef1; }
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .tone-indigo { --t: #a5a0f0; --t-soft: #24223d; }
    :root:not([data-theme="light"]) .tone-teal { --t: #6fc7b8; --t-soft: #183029; }
    :root:not([data-theme="light"]) .tone-amber { --t: #e8b360; --t-soft: #33281a; }
    :root:not([data-theme="light"]) .tone-rose { --t: #ef8fa8; --t-soft: #3a1e27; }
    :root:not([data-theme="light"]) .tone-sky { --t: #7bbde3; --t-soft: #182b37; }
    :root:not([data-theme="light"]) .tone-violet { --t: #c49cef; --t-soft: #2c2139; }
    :root:not([data-theme="light"]) .tone-emerald { --t: #7fcf98; --t-soft: #1a2e20; }
    :root:not([data-theme="light"]) .tone-slate { --t: #aeb6c1; --t-soft: #262a30; }
}
:root[data-theme="dark"] .tone-indigo { --t: #a5a0f0; --t-soft: #24223d; }
:root[data-theme="dark"] .tone-teal { --t: #6fc7b8; --t-soft: #183029; }
:root[data-theme="dark"] .tone-amber { --t: #e8b360; --t-soft: #33281a; }
:root[data-theme="dark"] .tone-rose { --t: #ef8fa8; --t-soft: #3a1e27; }
:root[data-theme="dark"] .tone-sky { --t: #7bbde3; --t-soft: #182b37; }
:root[data-theme="dark"] .tone-violet { --t: #c49cef; --t-soft: #2c2139; }
:root[data-theme="dark"] .tone-emerald { --t: #7fcf98; --t-soft: #1a2e20; }
:root[data-theme="dark"] .tone-slate { --t: #aeb6c1; --t-soft: #262a30; }
.tinted { background: var(--t-soft); color: var(--t); }

/* ---------- Avatar ---------- */
.avatar {
    --size: 36px;
    width: var(--size); height: var(--size); flex-shrink: 0;
    display: inline-grid; place-items: center;
    border-radius: 50%;
    background: var(--t-soft); color: var(--t);
    font-weight: 700; font-size: calc(var(--size) * .38); letter-spacing: .02em;
}
.avatar.square { border-radius: 10px; }
.avatar-stack { display: flex; }
.avatar-stack .avatar { border: 2px solid var(--surface); margin-left: -8px; }
.avatar-stack .avatar:first-child { margin-left: 0; }
.person { display: flex; align-items: center; gap: 12px; min-width: 0; }
.person-name { font-weight: 600; color: var(--ink); }
.person-meta { font-size: 12.5px; color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- Badges & chips ---------- */
.badge {
    display: inline-flex; align-items: center; gap: 5px;
    padding: 3px 9px; border-radius: 999px;
    font-size: 12px; font-weight: 600; white-space: nowrap;
    background: var(--t-soft, var(--surface-3)); color: var(--t, var(--ink-2));
}
.badge .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-success { background: var(--success-soft); color: var(--success); }
.badge-warning { background: var(--warning-soft); color: var(--warning); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-neutral { background: var(--surface-3); color: var(--ink-2); }
.badge-primary { background: var(--primary-soft); color: var(--primary); }
.chip {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 4px 10px; border-radius: 999px;
    font-size: 12.5px; font-weight: 550;
    background: var(--surface-3); color: var(--ink-2); border: 1px solid var(--border);
}

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    height: 38px; padding: 0 16px;
    border-radius: 10px; border: 1px solid transparent;
    font: inherit; font-weight: 600; font-size: 14px; white-space: nowrap;
    cursor: pointer; transition: background .15s, border-color .15s, color .15s, box-shadow .15s;
}
.btn-primary { background: var(--primary); color: var(--primary-ink); box-shadow: 0 1px 0 rgba(255,255,255,.12) inset, var(--shadow-sm); }
.btn-primary:hover { background: var(--primary-hover); color: var(--primary-ink); }
.btn-secondary { background: var(--surface); color: var(--ink); border-color: var(--border-strong); box-shadow: var(--shadow-sm); }
.btn-secondary:hover { background: var(--surface-2); color: var(--ink); border-color: var(--ink-3); }
.btn-ghost { background: transparent; color: var(--ink-2); }
.btn-ghost:hover { background: var(--surface-3); color: var(--ink); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(.94); color: #fff; }
.btn-danger-ghost { background: transparent; color: var(--danger); }
.btn-danger-ghost:hover { background: var(--danger-soft); color: var(--danger); }
.btn-sm { height: 32px; padding: 0 12px; font-size: 13px; border-radius: 8px; }
.btn-icon { width: 34px; height: 34px; padding: 0; border-radius: 9px; }
.btn-block { width: 100%; }
.btn-lg { height: 46px; font-size: 15px; border-radius: 12px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.actions { display: inline-flex; align-items: center; gap: 4px; justify-content: flex-end; }
form.inline { display: inline; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th {
    padding: 11px 16px; text-align: left;
    font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em;
    color: var(--ink-3); background: var(--surface-2); border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
.table th:first-child { padding-left: 24px; }
.table th:last-child { padding-right: 24px; }
.table td { padding: 13px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table td:first-child { padding-left: 24px; }
.table td:last-child { padding-right: 24px; }
.table tbody tr { transition: background .12s; }
.table tbody tr:hover { background: var(--surface-2); }
.table tbody tr:last-child td { border-bottom: 0; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table-toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 14px 24px; border-bottom: 1px solid var(--border); }

/* ---------- Lists ---------- */
.list { list-style: none; margin: 0; padding: 0; }
.list-item { display: flex; align-items: center; gap: 12px; padding: 13px 24px; border-bottom: 1px solid var(--border); }
.list-item:last-child { border-bottom: 0; }
.list-item .grow { flex: 1; min-width: 0; }
.list-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-meta { font-size: 12.5px; color: var(--ink-3); }

/* ---------- Forms ---------- */
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px 20px; }
.form-grid .full { grid-column: 1 / -1; }
.field { display: grid; gap: 6px; }
.label { font-size: 13.5px; font-weight: 600; color: var(--ink); }
.label .optional { font-weight: 500; color: var(--ink-3); margin-left: 4px; }
.hint { font-size: 12.5px; color: var(--ink-3); }
.input, .select, .textarea {
    width: 100%; height: 42px; padding: 0 13px;
    font: inherit; font-size: 14.5px; color: var(--ink);
    background: var(--surface); border: 1px solid var(--border-strong); border-radius: 10px;
    transition: border-color .15s, box-shadow .15s;
}
.textarea { height: auto; min-height: 110px; padding: 11px 13px; resize: vertical; }
.select {
    appearance: none; padding-right: 38px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%238b867c' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat; background-position: right 12px center;
}
.input::placeholder, .textarea::placeholder { color: var(--ink-3); }
.input:hover, .select:hover, .textarea:hover { border-color: var(--ink-3); }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--primary); box-shadow: var(--ring); }
.is-invalid { border-color: var(--danger) !important; }
.error { font-size: 12.5px; color: var(--danger); font-weight: 550; }
.input-icon { position: relative; }
.input-icon .icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--ink-3); pointer-events: none; }
.input-icon .input { padding-left: 38px; }
.search { max-width: 320px; flex: 1; }
.search .input { height: 38px; }
.form-actions { display: flex; align-items: center; gap: 10px; justify-content: flex-end; flex-wrap: wrap; }

.check { display: flex; align-items: flex-start; gap: 10px; cursor: pointer; }
.check input { margin: 2px 0 0; width: 17px; height: 17px; accent-color: var(--primary); cursor: pointer; flex-shrink: 0; }
.check-title { font-weight: 600; font-size: 14px; }
.check-desc { font-size: 12.5px; color: var(--ink-3); }

.switch { position: relative; display: inline-flex; align-items: center; gap: 12px; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch .track { width: 38px; height: 22px; border-radius: 99px; background: var(--border-strong); position: relative; transition: background .15s; flex-shrink: 0; }
.switch .track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: var(--shadow-sm); transition: transform .15s; }
.switch input:checked + .track { background: var(--primary); }
.switch input:checked + .track::after { transform: translateX(16px); }
.switch input:focus-visible + .track { box-shadow: var(--ring); }

/* Color picker (postes) */
.swatches { display: flex; flex-wrap: wrap; gap: 8px; }
.swatch input { position: absolute; opacity: 0; }
.swatch span {
    display: block; width: 30px; height: 30px; border-radius: 50%;
    background: var(--t); cursor: pointer; border: 3px solid var(--surface);
    box-shadow: 0 0 0 1px var(--border-strong); transition: transform .12s;
}
.swatch input:checked + span { box-shadow: 0 0 0 2px var(--t); transform: scale(1.08); }
.swatch input:focus-visible + span { box-shadow: var(--ring); }

/* Privilege matrix */
.matrix { width: 100%; border-collapse: collapse; }
.matrix th, .matrix td { padding: 12px 14px; border-bottom: 1px solid var(--border); text-align: center; }
.matrix th:first-child, .matrix td:first-child { text-align: left; padding-left: 24px; }
.matrix thead th { font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-3); background: var(--surface-2); font-weight: 700; }
.matrix .group-row td { background: var(--surface-2); font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .07em; color: var(--ink-3); padding-top: 10px; padding-bottom: 10px; }
.matrix tbody tr:not(.group-row):hover { background: var(--surface-2); }
.matrix input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--primary); cursor: pointer; }
.matrix .na { color: var(--border-strong); }
.matrix .module-name { font-weight: 600; }
.matrix .row-toggle { font-size: 12px; font-weight: 600; color: var(--ink-3); background: none; border: 0; cursor: pointer; padding: 2px 6px; border-radius: 6px; font-family: inherit; }
.matrix .row-toggle:hover { background: var(--surface-3); color: var(--ink); }

/* ---------- Alerts / flash ---------- */
.alert { display: flex; gap: 12px; align-items: flex-start; padding: 13px 16px; border-radius: var(--radius); margin-bottom: 20px; font-size: 14px; border: 1px solid transparent; }
.alert .icon { margin-top: 1px; }
.alert-success { background: var(--success-soft); color: var(--success); border-color: color-mix(in srgb, var(--success) 18%, transparent); }
.alert-danger { background: var(--danger-soft); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 18%, transparent); }
.alert-info { background: var(--primary-soft); color: var(--primary); border-color: color-mix(in srgb, var(--primary) 18%, transparent); }
.alert-warning { background: var(--warning-soft); color: var(--warning); border-color: color-mix(in srgb, var(--warning) 20%, transparent); }
.alert ul { margin: 4px 0 0; padding-left: 18px; }
.alert-body { flex: 1; color: var(--ink); }
.alert-body strong { color: inherit; }
.alert-close { background: none; border: 0; color: inherit; opacity: .6; cursor: pointer; padding: 2px; }
.alert-close:hover { opacity: 1; }
.flash { animation: flash-in .35s ease-out; }
@keyframes flash-in { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }

.callout { display: flex; gap: 14px; padding: 16px 18px; border-radius: var(--radius); background: var(--surface-2); border: 1px dashed var(--border-strong); }
.callout .icon-tile { flex-shrink: 0; }
.callout h4 { font-size: 14px; margin-bottom: 2px; }
.callout p { font-size: 13px; color: var(--ink-2); }

/* ---------- Empty state ---------- */
.empty { text-align: center; padding: 48px 24px; }
.empty-illus { width: 56px; height: 56px; margin: 0 auto 16px; border-radius: 16px; display: grid; place-items: center; background: var(--primary-soft); color: var(--primary); }
.empty h3 { font-size: 16px; margin-bottom: 6px; }
.empty p { color: var(--ink-2); max-width: 400px; margin: 0 auto; font-size: 14px; }
.empty .btn { margin-top: 18px; }

/* ---------- Pagination ---------- */
.pagination { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 24px; border-top: 1px solid var(--border); font-size: 13px; color: var(--ink-3); flex-wrap: wrap; }
.pagination .pages { display: flex; gap: 4px; }
.pagination a, .pagination span.page { min-width: 32px; height: 32px; padding: 0 10px; display: inline-grid; place-items: center; border-radius: 8px; color: var(--ink-2); font-weight: 600; border: 1px solid var(--border); background: var(--surface); }
.pagination a:hover { border-color: var(--border-strong); color: var(--ink); }
.pagination .current { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.pagination .disabled { opacity: .45; }

/* ---------- Tabs / filters ---------- */
.tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.tab { padding: 6px 12px; border-radius: 8px; font-size: 13px; font-weight: 600; color: var(--ink-2); border: 1px solid transparent; }
.tab:hover { background: var(--surface-3); color: var(--ink); }
.tab.active { background: var(--surface); border-color: var(--border-strong); color: var(--ink); box-shadow: var(--shadow-sm); }
.tab .count { color: var(--ink-3); margin-left: 4px; font-weight: 500; }

/* ---------- Definition list ---------- */
.dl { display: grid; gap: 14px; }
.dl-row { display: flex; align-items: center; gap: 12px; font-size: 14px; }
.dl-row .icon { color: var(--ink-3); }
.dl-row .k { color: var(--ink-3); min-width: 110px; }

/* ---------- Postes cards ---------- */
.poste-card { display: flex; flex-direction: column; border-radius: var(--radius-lg); background: var(--surface); border: 1px solid var(--border); overflow: hidden; }
.poste-card-head { padding: 20px 22px 16px; display: flex; gap: 14px; align-items: flex-start; }
.poste-card-head h3 { font-size: 16px; }
.poste-card-body { padding: 0 22px 18px; flex: 1; }
.poste-card-foot { padding: 12px 22px; border-top: 1px solid var(--border); background: var(--surface-2); display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.meter { height: 6px; border-radius: 99px; background: var(--surface-3); overflow: hidden; margin: 10px 0 6px; }
.meter span { display: block; height: 100%; border-radius: inherit; background: var(--t, var(--primary)); }
.privs { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }

/* ---------- Espaces (choix d'entreprise) ---------- */
.espaces { display: grid; gap: 12px; }
.espace {
    display: flex; align-items: center; gap: 14px; width: 100%;
    padding: 16px 18px; border-radius: var(--radius);
    background: var(--surface); border: 1px solid var(--border);
    font: inherit; color: var(--ink); text-align: left; cursor: pointer;
    transition: border-color .15s, box-shadow .15s, transform .15s;
}
.espace:hover { border-color: var(--primary); box-shadow: var(--shadow); transform: translateY(-1px); }
.espace .grow { flex: 1; min-width: 0; }
.espace-name { font-weight: 650; font-size: 15px; }
.espace .icon.chev { color: var(--ink-3); }

/* ---------- Auth ---------- */
.auth { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.05fr); }
.auth-side {
    position: relative; overflow: hidden;
    padding: 48px; display: flex; flex-direction: column; justify-content: space-between;
    background:
        radial-gradient(900px 500px at 110% -10%, color-mix(in srgb, var(--accent) 30%, transparent), transparent 55%),
        radial-gradient(700px 500px at -20% 120%, rgba(255,255,255,.08), transparent 60%),
        linear-gradient(160deg, #1f5f55 0%, #123a34 100%);
    color: #fff;
}
.auth-side .brand { color: #fff; padding: 0; }
.auth-side .brand-mark { background: #fff; color: #1f5f55; }
.auth-side .brand small { color: rgba(255,255,255,.6); }
.auth-quote { max-width: 460px; }
.auth-quote h2 { font-family: var(--font-display); font-weight: 400; font-size: 36px; line-height: 1.15; letter-spacing: -.02em; }
.auth-quote p { margin-top: 16px; color: rgba(255,255,255,.75); font-size: 15px; }
.auth-points { display: grid; gap: 14px; margin-top: 32px; }
.auth-point { display: flex; gap: 12px; align-items: flex-start; color: rgba(255,255,255,.9); font-size: 14px; }
.auth-point .icon-tile { background: rgba(255,255,255,.12); color: #fff; width: 32px; height: 32px; }
.auth-point strong { display: block; color: #fff; }
.auth-foot { font-size: 12.5px; color: rgba(255,255,255,.55); }
.auth-main { display: grid; place-items: center; padding: 40px 24px; }
.auth-card { width: 100%; max-width: 420px; }
.auth-card h1 { font-family: var(--font-display); font-weight: 500; font-size: 30px; letter-spacing: -.02em; }
.auth-card .lead { color: var(--ink-2); margin: 8px 0 28px; }
.auth-card .stack { gap: 16px; }
.auth-alt { margin-top: 24px; text-align: center; color: var(--ink-2); font-size: 14px; }
.demo-box { margin-top: 28px; padding: 14px 16px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--border); font-size: 12.5px; color: var(--ink-2); }
.demo-box strong { color: var(--ink); }
.demo-box .mono { color: var(--ink); }
.demo-grid { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin-top: 8px; }

.centered { min-height: 100vh; display: grid; place-items: center; padding: 40px 16px; }
.centered-card { width: 100%; max-width: 540px; }

/* ---------- Divider / misc ---------- */
.divider { height: 1px; background: var(--border); margin: 20px 0; border: 0; }
.kbd { font-family: ui-monospace, monospace; font-size: 12px; padding: 2px 6px; border-radius: 6px; background: var(--surface-3); border: 1px solid var(--border); color: var(--ink-2); }
.section-title { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--ink-3); margin-bottom: 12px; }
.danger-zone { border-color: color-mix(in srgb, var(--danger) 30%, var(--border)); }
.danger-zone .card-head h3 { color: var(--danger); }
details.disclosure summary { cursor: pointer; list-style: none; }
details.disclosure summary::-webkit-details-marker { display: none; }

/* ---------- Parcours : Délégation → Client → Imprimante ---------- */
.trail { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin: 6px 0 18px; }
.trail-step {
    display: inline-flex; align-items: center; gap: 8px;
    padding: 6px 12px 6px 6px; border-radius: 999px;
    background: var(--surface); border: 1px solid var(--border);
    font-size: 13px; font-weight: 600; color: var(--ink-2); max-width: 100%;
}
a.trail-step:hover { border-color: var(--border-strong); color: var(--ink); }
.trail-step .num { width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; background: var(--surface-3); color: var(--ink-3); font-size: 11.5px; flex-shrink: 0; }
.trail-step.done .num { background: var(--primary-soft); color: var(--primary); }
.trail-step.current { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.trail-step.current .num { background: rgba(255,255,255,.2); color: var(--primary-ink); }
.trail-step.todo { color: var(--ink-3); border-style: dashed; background: transparent; }
.trail-step span.txt { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.trail .sep { color: var(--ink-3); }

.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; }
.tiles.wide { grid-template-columns: repeat(auto-fill, minmax(min(300px, 100%), 1fr)); }
.tile {
    display: flex; flex-direction: column; gap: 12px;
    padding: 18px; border-radius: var(--radius-lg);
    background: var(--surface); border: 1px solid var(--border); color: var(--ink);
    transition: border-color .15s, box-shadow .15s, transform .15s;
}
a.tile:hover { color: var(--ink); border-color: var(--primary); box-shadow: var(--shadow); transform: translateY(-2px); }
.tile-head { display: flex; align-items: center; gap: 12px; }
.tile-title { font-weight: 650; font-size: 15px; line-height: 1.3; }
.tile-sub { font-size: 12.5px; color: var(--ink-3); }
.tile-foot { display: flex; align-items: center; gap: 14px; margin-top: auto; padding-top: 12px; border-top: 1px solid var(--border); font-size: 12.5px; color: var(--ink-2); }
.tile-foot span { display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; }
.tile-foot .go { margin-left: auto; color: var(--primary); font-weight: 600; }
.tile.dashed { border-style: dashed; background: transparent; }

.metric-row { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0; }
.metric { padding: 16px 20px; border-right: 1px solid var(--border); }
.metric:last-child { border-right: 0; }
.metric-label { font-size: 12px; color: var(--ink-3); font-weight: 600; text-transform: uppercase; letter-spacing: .05em; }
.metric-value { font-size: 22px; font-weight: 700; letter-spacing: -.02em; margin-top: 4px; font-variant-numeric: tabular-nums; }
.metric-value small { font-size: 13px; color: var(--ink-3); font-weight: 600; margin-left: 3px; }

/* Frise de l'historique de maintenance */
.timeline { list-style: none; margin: 0; padding: 8px 24px 20px; }
.tl-item { position: relative; display: grid; grid-template-columns: 92px 28px minmax(0, 1fr); gap: 0 14px; padding-top: 14px; }
.tl-date { text-align: right; font-size: 12.5px; color: var(--ink-3); padding-top: 4px; line-height: 1.35; }
.tl-date strong { display: block; color: var(--ink); font-size: 13.5px; }
.tl-rail { position: relative; display: flex; justify-content: center; }
.tl-rail::before { content: ""; position: absolute; top: 0; bottom: -14px; width: 2px; background: var(--border); }
.tl-item:last-child .tl-rail::before { bottom: auto; height: 30px; }
.tl-dot { position: relative; z-index: 1; width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; background: var(--t-soft); color: var(--t); border: 3px solid var(--surface); }
.tl-body { padding: 2px 0 12px; border-bottom: 1px dashed var(--border); }
.tl-item:last-child .tl-body { border-bottom: 0; }
.tl-title { font-weight: 650; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.tl-meta { font-size: 12.5px; color: var(--ink-3); margin-top: 2px; }
.tl-desc { font-size: 13.5px; color: var(--ink-2); margin-top: 6px; white-space: pre-line; }
.tl-pieces { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }

.table tfoot td { padding: 13px 16px; background: var(--surface-2); border-top: 1px solid var(--border); font-weight: 700; }
.table tfoot td:first-child { padding-left: 24px; }
.table tfoot td:last-child { padding-right: 24px; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 28px 0 12px; flex-wrap: wrap; }
.section-head h2 { font-size: 18px; }
.section-head p { font-size: 13px; color: var(--ink-3); margin-top: 2px; }

/* ---------- Documents numérisés ---------- */
.doc-layout { display: grid; grid-template-columns: minmax(0, 0.95fr) minmax(0, 1.25fr); gap: 20px; align-items: start; }
.viewer { position: sticky; top: 72px; }
.viewer-frame { position: relative; overflow: auto; max-height: calc(100vh - 170px); border-radius: var(--radius); background: #2a2926; display: grid; place-items: center; }
.viewer-frame img { display: block; max-width: 100%; height: auto; cursor: zoom-in; transition: transform .2s; transform-origin: center; }
.viewer-frame.zoom img { max-width: none; width: 200%; cursor: zoom-out; }
.viewer-frame iframe { width: 100%; height: calc(100vh - 190px); border: 0; background: #fff; }
.viewer-bar { display: flex; align-items: center; gap: 8px; padding: 10px 14px; flex-wrap: wrap; }
.a-verifier { border-color: var(--warning) !important; background: color-mix(in srgb, var(--warning-soft) 70%, var(--surface)) !important; }
.erreur-champ { border-color: var(--danger) !important; background: color-mix(in srgb, var(--danger-soft) 60%, var(--surface)) !important; }
.lignes { width: 100%; border-collapse: collapse; }
.lignes th { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-3); text-align: left; padding: 0 6px 6px; font-weight: 700; white-space: nowrap; }
.lignes td { padding: 4px 3px; vertical-align: top; }
.lignes .input { height: 36px; padding: 0 9px; font-size: 13.5px; }
.lignes .num .input { text-align: right; }
.lignes .del { width: 36px; }
.alertes { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.alertes li { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border-radius: 10px; font-size: 13.5px; }
.alertes .erreur { background: var(--danger-soft); color: var(--danger); }
.alertes .attention { background: var(--warning-soft); color: var(--warning); }
.alertes .info { background: var(--primary-soft); color: var(--primary); }
.alertes li span.txt { color: var(--ink); }
.type-choices { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.type-choice input { position: absolute; opacity: 0; }
.type-choice .tile { cursor: pointer; align-items: center; text-align: center; padding: 22px 14px; }
.type-choice input:checked + .tile { border-color: var(--primary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 20%, transparent); }
.type-choice input:focus-visible + .tile { box-shadow: var(--ring); }
.dropzone { display: grid; place-items: center; gap: 10px; text-align: center; padding: 34px 20px; border: 2px dashed var(--border-strong); border-radius: var(--radius-lg); background: var(--surface-2); cursor: pointer; transition: border-color .15s, background .15s; }
.dropzone:hover, .dropzone.over { border-color: var(--primary); background: var(--primary-soft); }
.dropzone img { max-height: 260px; max-width: 100%; border-radius: 10px; box-shadow: var(--shadow); }
.thumb { width: 44px; height: 56px; border-radius: 8px; object-fit: cover; background: var(--surface-3); border: 1px solid var(--border); flex-shrink: 0; }
.spinner { width: 42px; height: 42px; border-radius: 50%; border: 4px solid var(--primary-soft); border-top-color: var(--primary); animation: tourne 0.9s linear infinite; margin: 0 auto 16px; }
@keyframes tourne { to { transform: rotate(360deg); } }
.trace { display: grid; gap: 10px; font-size: 13px; }
.trace div { display: flex; gap: 10px; align-items: center; color: var(--ink-2); }

/* ---------- Thème & carte ---------- */
[data-theme-icone][hidden] { display: none; }
.carte { height: 320px; border-radius: var(--radius); border: 1px solid var(--border); overflow: hidden; z-index: 0; }
.carte.petite { height: 220px; }
:root[data-theme="dark"] .carte .leaflet-tile-pane { filter: brightness(.7) invert(1) contrast(3) hue-rotate(200deg) saturate(.3) brightness(.7); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .carte .leaflet-tile-pane { filter: brightness(.7) invert(1) contrast(3) hue-rotate(200deg) saturate(.3) brightness(.7); } }

/* ---------- Responsive ---------- */
@media (max-width: 1080px) {
    .grid-main { grid-template-columns: minmax(0, 1fr); }
    .doc-layout { grid-template-columns: minmax(0, 1fr); }
    .viewer { position: static; }
    .viewer-frame { max-height: 60vh; }
    .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 960px) {
    .app { grid-template-columns: minmax(0, 1fr); }
    .sidebar {
        position: fixed; inset: 0 auto 0 0; z-index: 50; width: min(300px, 86vw);
        transform: translateX(-100%); transition: transform .22s ease;
        box-shadow: var(--shadow-lg);
    }
    #nav-toggle:checked ~ .app .sidebar { transform: none; }
    #nav-toggle:checked ~ .app .scrim { display: block; position: fixed; inset: 0; z-index: 40; background: rgba(0,0,0,.35); }
    .topbar .menu-toggle { display: inline-flex; }
    .topbar { padding: 10px 16px; border-bottom-color: var(--border); }
    .content { padding: 8px 16px 40px; }
    .auth { grid-template-columns: minmax(0, 1fr); }
    .auth-side { display: none; }
}

@media (max-width: 640px) {
    .grid-2, .grid-3, .form-grid { grid-template-columns: minmax(0, 1fr); }
    .page-head h1 { font-size: 22px; }
    .hero { padding: 22px 20px; }
    .hero h1 { font-size: 24px; }
    .card-head, .card-body, .card-foot { padding-left: 16px; padding-right: 16px; }
    .table th:first-child, .table td:first-child, .matrix th:first-child, .matrix td:first-child { padding-left: 16px; }
    .table th:last-child, .table td:last-child { padding-right: 16px; }
    .list-item { padding: 12px 16px; }
    .table-toolbar, .pagination { padding-left: 16px; padding-right: 16px; }
    .hide-sm { display: none !important; }
    .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .metric-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .type-choices { grid-template-columns: minmax(0, 1fr); }
    .type-choice .tile { flex-direction: row; text-align: left; padding: 14px; }
    .metric:nth-child(2) { border-right: 0; }
    .metric:nth-child(-n+2) { border-bottom: 1px solid var(--border); }
    .timeline { padding: 4px 16px 16px; }
    .tl-item { grid-template-columns: 28px minmax(0, 1fr); }
    .tl-date { grid-column: 2; grid-row: 1; text-align: left; padding: 0 0 4px; }
    .tl-date strong { display: inline; margin-right: 4px; }
    .tl-rail { grid-column: 1; grid-row: 1 / span 2; }
    .tl-body { grid-column: 2; }
    .trail-step span.txt { max-width: 140px; }
    .stat-value { font-size: 24px; }
    .form-actions { justify-content: stretch; }
    .form-actions .btn { flex: 1; }
}
