/* =====================================================================
 *  GESTICOUR : feuille de style (thèmes clair et sombre)
 *  Le thème est porté par l'attribut <html data-theme="light|dark">
 * ===================================================================== */

:root {
    --bg: #f3f5fa;
    --surface: #ffffff;
    --surface-2: #f8fafc;
    --surface-3: #eef2f7;
    --border: #e3e8f0;
    --border-strong: #cdd5e1;
    --text: #0f172a;
    --text-2: #475569;
    --text-3: #8a96a8;
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --primary-soft: #eef2ff;
    --primary-text: #ffffff;
    --success: #059669;
    --success-soft: #e7f8f1;
    --warning: #b45309;
    --warning-soft: #fdf3e1;
    --danger: #dc2626;
    --danger-soft: #fdecec;
    --info: #0369a1;
    --info-soft: #e6f4fb;
    --side: #0f172a;
    --side-text: #cbd5e1;
    --side-muted: #64748b;
    --side-active: rgba(99, 102, 241, 0.18);
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
    --shadow: 0 1px 2px rgba(15, 23, 42, 0.04), 0 10px 30px -12px rgba(15, 23, 42, 0.12);
    --radius: 14px;
    --radius-sm: 9px;
    --focus: 0 0 0 3px rgba(79, 70, 229, 0.25);
    color-scheme: light;
}

[data-theme="dark"] {
    --bg: #0a0f1c;
    --surface: #111a2c;
    --surface-2: #0e1628;
    --surface-3: #18233a;
    --border: #1f2c45;
    --border-strong: #2b3b5a;
    --text: #e6ebf5;
    --text-2: #a4b0c6;
    --text-3: #6f7d96;
    --primary: #818cf8;
    --primary-hover: #a5b4fc;
    --primary-soft: rgba(129, 140, 248, 0.14);
    --primary-text: #0b1020;
    --success: #34d399;
    --success-soft: rgba(52, 211, 153, 0.12);
    --warning: #fbbf24;
    --warning-soft: rgba(251, 191, 36, 0.12);
    --danger: #f87171;
    --danger-soft: rgba(248, 113, 113, 0.12);
    --info: #38bdf8;
    --info-soft: rgba(56, 189, 248, 0.12);
    --side: #070b15;
    --side-text: #b8c3d9;
    --side-muted: #56647e;
    --side-active: rgba(129, 140, 248, 0.16);
    --shadow-sm: none;
    --shadow: 0 1px 0 rgba(255, 255, 255, 0.03) inset, 0 16px 40px -18px rgba(0, 0, 0, 0.6);
    --focus: 0 0 0 3px rgba(129, 140, 248, 0.3);
    color-scheme: dark;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
    margin: 0;
    font-family: "Inter", "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
    transition: background-color .25s ease, color .25s ease;
}

h1, h2, h3, h4 { margin: 0; letter-spacing: -0.01em; }
p { margin: 0; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
svg.i { width: 18px; height: 18px; flex-shrink: 0; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.muted { color: var(--text-3); }
.small { font-size: 12.5px; }
.mono { font-family: ui-monospace, "SFMono-Regular", Consolas, monospace; font-size: 12.5px; }
.nowrap { white-space: nowrap; }
.hidden { display: none !important; }
.grow { flex: 1; min-width: 0; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack { display: flex; flex-direction: column; gap: 14px; }

/* ---------- Layout ---------- */
.app { display: grid; grid-template-columns: 264px 1fr; min-height: 100vh; }

.sidebar {
    position: sticky; top: 0; height: 100vh; overflow-y: auto;
    background: var(--side); color: var(--side-text);
    display: flex; flex-direction: column; padding: 18px 14px;
    border-right: 1px solid rgba(255, 255, 255, 0.04);
}
.brand { display: flex; align-items: center; gap: 12px; padding: 6px 10px 20px; }
.brand-mark {
    width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center;
    background: linear-gradient(135deg, #6366f1, #a855f7 60%, #ec4899);
    color: #fff; font-weight: 800; font-size: 18px; box-shadow: 0 8px 20px -6px rgba(99, 102, 241, 0.6);
}
.brand-name { font-weight: 800; color: #fff; letter-spacing: 0.02em; font-size: 15px; }
.brand-sub { font-size: 11.5px; color: var(--side-muted); }
.brand-block { flex-direction: column; align-items: flex-start; gap: 7px; }
.brand-logo { display: block; height: 36px; width: auto; max-width: 175px; object-fit: contain; }
.hero-logo { height: 48px; max-width: 250px; margin-bottom: 26px; }
.auth-logo { margin-bottom: 18px; }
.auth-logo img { height: 34px; width: auto; max-width: 190px; object-fit: contain; }
.only-dark { display: none; }
[data-theme="dark"] .only-dark { display: block; }
[data-theme="dark"] .only-light { display: none; }
.logo-duo { display: inline-flex; flex-shrink: 0; }
.logo-duo img { height: 34px; width: auto; max-width: 175px; object-fit: contain; }

.nav-title {
    font-size: 10.5px; font-weight: 700; letter-spacing: 0.12em; text-transform: uppercase;
    color: var(--side-muted); padding: 16px 12px 6px;
}
.nav a {
    display: flex; align-items: center; gap: 11px; padding: 8px 12px; margin: 2px 0;
    border-radius: 10px; color: var(--side-text); font-weight: 500; position: relative;
}
.nav a:hover { background: rgba(255, 255, 255, 0.05); color: #fff; text-decoration: none; }
.nav a.active { background: var(--side-active); color: #fff; }
.nav a.active::before {
    content: ""; position: absolute; left: -14px; top: 8px; bottom: 8px; width: 3px;
    border-radius: 0 3px 3px 0; background: var(--primary);
}
.nav .count {
    margin-left: auto; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px;
    background: var(--danger); color: #fff; font-size: 11px; font-weight: 700; display: grid; place-items: center;
}
.sidebar-foot { margin-top: auto; padding: 14px 10px 0; border-top: 1px solid rgba(255, 255, 255, 0.06); }
.sidebar-user { display: flex; align-items: center; gap: 10px; }
.avatar {
    width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; flex-shrink: 0;
    background: linear-gradient(135deg, #4f46e5, #7c3aed); color: #fff; font-weight: 700; font-size: 13px;
}
.sidebar-user .name { color: #fff; font-weight: 600; font-size: 13.5px; }
.sidebar-user .role { font-size: 11.5px; color: var(--side-muted); }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
    position: sticky; top: 0; z-index: 20; height: 64px; padding: 0 28px;
    display: flex; align-items: center; gap: 14px;
    background: color-mix(in srgb, var(--bg) 82%, transparent);
    backdrop-filter: saturate(160%) blur(12px); -webkit-backdrop-filter: saturate(160%) blur(12px);
    border-bottom: 1px solid var(--border);
}
.topbar .search { position: relative; max-width: 420px; width: 100%; }
.topbar .search svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--text-3); }
.topbar .search input { padding-left: 38px; background: var(--surface); }
.icon-btn {
    width: 40px; height: 40px; border-radius: 11px; display: inline-grid; place-items: center;
    border: 1px solid var(--border); background: var(--surface); color: var(--text-2); cursor: pointer;
    position: relative; transition: all .15s ease;
}
.icon-btn:hover { color: var(--primary); border-color: var(--border-strong); text-decoration: none; }
.icon-btn .dot {
    position: absolute; top: -4px; right: -4px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 999px;
    background: var(--danger); color: #fff; font-size: 10.5px; font-weight: 700; display: grid; place-items: center;
    border: 2px solid var(--bg);
}
.menu-toggle { display: none; }
.content { padding: 28px; max-width: 1400px; width: 100%; margin: 0 auto; }

/* ---------- Page header ---------- */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 22px; }
.page-head h1 { font-size: 24px; font-weight: 750; }
.page-head p { color: var(--text-2); margin-top: 4px; }
.page-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.crumb { font-size: 12.5px; color: var(--text-3); margin-bottom: 6px; display: flex; gap: 6px; align-items: center; }

/* ---------- Cards ---------- */
.card {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    box-shadow: var(--shadow); padding: 20px; min-width: 0;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.card-head h3 { font-size: 15px; font-weight: 650; display: flex; align-items: center; gap: 8px; }
.card-head h3 svg { color: var(--primary); }
.card.flush { padding: 0; overflow: hidden; }
.card.flush > .card-head { padding: 18px 20px 0; margin-bottom: 12px; }
.grid { display: grid; gap: 18px; }
.grid.kpis { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.grid.two { grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); }
.grid.two-eq { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.side { grid-template-columns: minmax(0, 1fr) 340px; }

.kpi { display: flex; gap: 14px; align-items: center; }
.kpi-icon { width: 46px; height: 46px; border-radius: 13px; display: grid; place-items: center; flex-shrink: 0; }
.kpi-icon svg { width: 22px; height: 22px; }
.kpi .value { font-size: 26px; font-weight: 750; line-height: 1.1; letter-spacing: -0.02em; }
.kpi .label { color: var(--text-2); font-size: 12.5px; margin-top: 2px; }
.tone-primary.kpi-icon { background: var(--primary-soft); color: var(--primary); }
.tone-success.kpi-icon { background: var(--success-soft); color: var(--success); }
.tone-warning.kpi-icon { background: var(--warning-soft); color: var(--warning); }
.tone-danger.kpi-icon { background: var(--danger-soft); color: var(--danger); }
.tone-info.kpi-icon { background: var(--info-soft); color: var(--info); }
.tone-neutral.kpi-icon { background: var(--surface-3); color: var(--text-2); }

/* ---------- Badges ---------- */
.badge {
    display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px;
    font-size: 12px; font-weight: 600; white-space: nowrap;
    background: var(--tone-bg, var(--surface-3)); color: var(--tone-fg, var(--text-2));
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .85; }
.badge.plain::before { display: none; }
.tone-neutral-b { --tone-bg: var(--surface-3); --tone-fg: var(--text-2); }
.tone-info-b { --tone-bg: var(--info-soft); --tone-fg: var(--info); }
.tone-primary-b { --tone-bg: var(--primary-soft); --tone-fg: var(--primary); }
.tone-success-b { --tone-bg: var(--success-soft); --tone-fg: var(--success); }
.tone-warning-b { --tone-bg: var(--warning-soft); --tone-fg: var(--warning); }
.tone-danger-b { --tone-bg: var(--danger-soft); --tone-fg: var(--danger); }
.tone-muted-b { --tone-bg: transparent; --tone-fg: var(--text-3); box-shadow: inset 0 0 0 1px var(--border-strong); }
.dir-in { --tone-bg: var(--info-soft); --tone-fg: var(--info); }
.dir-out { --tone-bg: var(--success-soft); --tone-fg: var(--success); }
.dir-internal { --tone-bg: var(--primary-soft); --tone-fg: var(--primary); }
.conf-public { --tone-bg: var(--surface-3); --tone-fg: var(--text-2); }
.conf-interne { --tone-bg: var(--surface-3); --tone-fg: var(--text-2); }
.conf-confidentiel { --tone-bg: var(--warning-soft); --tone-fg: var(--warning); }
.conf-secret { --tone-bg: var(--danger-soft); --tone-fg: var(--danger); }
.prio-urgente { --tone-bg: var(--danger-soft); --tone-fg: var(--danger); }
.prio-haute { --tone-bg: var(--warning-soft); --tone-fg: var(--warning); }
.prio-normale { --tone-bg: var(--info-soft); --tone-fg: var(--info); }
.prio-basse { --tone-bg: var(--surface-3); --tone-fg: var(--text-3); }

/* ---------- 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: 13.5px; cursor: pointer; white-space: nowrap;
    transition: background .15s ease, border-color .15s ease, color .15s ease, box-shadow .15s ease, transform .05s;
    background: var(--surface); color: var(--text); border-color: var(--border-strong);
}
.btn:hover { text-decoration: none; border-color: var(--text-3); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: none; box-shadow: var(--focus); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn svg.i { width: 16px; height: 16px; }
.btn-primary { background: linear-gradient(180deg, var(--primary), var(--primary-hover)); color: var(--primary-text); border-color: transparent; box-shadow: 0 6px 16px -8px var(--primary); }
.btn-primary:hover { border-color: transparent; filter: brightness(1.05); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-3); color: var(--text); border-color: transparent; }
.btn-danger { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.btn-danger:hover { background: var(--danger); color: #fff; }
.btn-success { background: var(--success); color: #fff; border-color: transparent; }
.btn-success:hover { filter: brightness(1.06); }
.btn-warning { background: var(--warning-soft); color: var(--warning); border-color: transparent; }
.btn-warning:hover { background: var(--warning); color: #fff; }
.btn-sm { height: 32px; padding: 0 11px; font-size: 12.5px; border-radius: 8px; }
.btn-icon { width: 34px; padding: 0; }
.btn-block { width: 100%; }

/* ---------- Forms ---------- */
label.lbl { display: block; font-size: 12.5px; font-weight: 600; color: var(--text-2); margin-bottom: 6px; }
label.lbl .req { color: var(--danger); margin-left: 2px; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date],
input[type=datetime-local], input[type=search], input[type=tel], select, textarea {
    width: 100%; height: 40px; padding: 0 12px; font: inherit; color: var(--text);
    background: var(--surface-2); border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
    transition: border-color .15s ease, box-shadow .15s ease, background .15s ease;
}
textarea { height: auto; min-height: 90px; padding: 10px 12px; resize: vertical; }
select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--text-3) 50%), linear-gradient(135deg, var(--text-3) 50%, transparent 50%);
    background-position: calc(100% - 18px) 55%, calc(100% - 13px) 55%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 32px; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: var(--focus); background: var(--surface); }
input[type=checkbox], input[type=radio] { accent-color: var(--primary); width: 16px; height: 16px; margin: 0; }
input[type=file] { font: inherit; color: var(--text-2); }
.field { margin-bottom: 0; min-width: 0; }
.field.full { grid-column: 1 / -1; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px 18px; }
.form-grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.form-section { grid-column: 1 / -1; font-size: 12px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--primary); padding-top: 10px; border-top: 1px solid var(--border); margin-top: 4px; }
.form-section:first-child { border-top: 0; padding-top: 0; margin-top: 0; }
.check { display: inline-flex; align-items: center; gap: 9px; font-weight: 500; color: var(--text); cursor: pointer; }
.hint { font-size: 12px; color: var(--text-3); margin-top: 5px; }
.search-line { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.search-line .field { flex: 1 1 200px; }
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.toolbar .fi { min-width: 150px; flex: 0 1 170px; }
.toolbar .fi.wide { flex: 1 1 260px; }
.toolbar .fi > label { display: block; font-size: 11.5px; font-weight: 600; color: var(--text-3); margin-bottom: 4px; text-transform: uppercase; letter-spacing: .04em; }
.toolbar label.check { display: inline-flex; font-size: 13px; font-weight: 500; color: var(--text-2); text-transform: none; letter-spacing: 0; margin: 0; white-space: nowrap; }
.toolbar select, .toolbar input { height: 36px; font-size: 13px; }
.adv { display: none; width: 100%; }
.adv.open { display: flex; }

/* ---------- Tables ---------- */
.table-wrap { overflow: auto; }
table.table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13.5px; }
.table th {
    text-align: left; font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em;
    color: var(--text-3); padding: 11px 14px; background: var(--surface-2); border-bottom: 1px solid var(--border);
    position: sticky; top: 0; white-space: nowrap;
}
.table td { padding: 12px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tbody tr { transition: background .12s ease; }
.table tbody tr:hover { background: var(--primary-soft); }
.table tbody tr:last-child td { border-bottom: 0; }
.table tr.clickable { cursor: pointer; }
.table tr.overdue td:first-child { box-shadow: inset 3px 0 0 var(--danger); }
.table tr.unread td { font-weight: 600; }
.table .title { font-weight: 600; color: var(--text); }
.table .sub { font-size: 12px; color: var(--text-3); margin-top: 2px; }
.table .actions { display: flex; gap: 6px; justify-content: flex-end; }
.pager { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 20px; border-top: 1px solid var(--border); color: var(--text-2); font-size: 13px; }
.empty { text-align: center; padding: 42px 20px; color: var(--text-3); }
.empty svg { width: 40px; height: 40px; opacity: .5; margin-bottom: 8px; }
.empty strong { display: block; color: var(--text-2); font-size: 14px; margin-bottom: 4px; }

/* ---------- Progress & bars ---------- */
.progress { height: 7px; border-radius: 999px; background: var(--surface-3); overflow: hidden; min-width: 80px; }
.progress > span { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--primary), #a855f7); }
.hbars { display: grid; gap: 12px; }
.hbar .top { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 5px; color: var(--text-2); }
.hbar .top b { color: var(--text); }
.hbar .track { height: 8px; border-radius: 999px; background: var(--surface-3); overflow: hidden; }
.hbar .fill { height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--primary), #a855f7); }
.columns { display: flex; align-items: flex-end; gap: 10px; height: 220px; padding-top: 8px; }
.col { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 6px; height: 100%; min-width: 0; }
.col .stack-bar { width: 100%; max-width: 34px; display: flex; flex-direction: column-reverse; border-radius: 8px 8px 4px 4px; overflow: hidden; background: var(--surface-3); }
.col .stack-bar span { display: block; width: 100%; }
.col .lab { font-size: 11px; color: var(--text-3); white-space: nowrap; }
.col .tot { font-size: 11px; font-weight: 700; color: var(--text-2); }
.legend { display: flex; gap: 14px; font-size: 12.5px; color: var(--text-2); flex-wrap: wrap; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.seg-in { background: var(--info); }
.seg-out { background: var(--success); }
.seg-internal { background: var(--primary); }

/* ---------- Lists ---------- */
.list { display: flex; flex-direction: column; }
.list-item { display: flex; gap: 12px; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--border); }
.list-item:last-child { border-bottom: 0; padding-bottom: 0; }
.list-item:first-child { padding-top: 0; }
.list-item .main { flex: 1; min-width: 0; }
.list-item .t { font-weight: 600; font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-item .s { font-size: 12px; color: var(--text-3); }
.list-item.unread .t::after { content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--primary); margin-left: 8px; vertical-align: 2px; }
.dot-ico { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; flex-shrink: 0; background: var(--surface-3); color: var(--text-2); }
.dot-ico.tone-warning { background: var(--warning-soft); color: var(--warning); }
.dot-ico.tone-danger { background: var(--danger-soft); color: var(--danger); }
.dot-ico.tone-primary { background: var(--primary-soft); color: var(--primary); }
.dot-ico.tone-success { background: var(--success-soft); color: var(--success); }

/* ---------- Detail ---------- */
.detail-head { display: flex; gap: 18px; justify-content: space-between; align-items: flex-start; flex-wrap: wrap; }
.detail-head h1 { font-size: 22px; font-weight: 750; margin: 8px 0 10px; line-height: 1.3; }
.ref { font-family: ui-monospace, "SFMono-Regular", Consolas, monospace; font-weight: 700; font-size: 13px; color: var(--primary); background: var(--primary-soft); padding: 4px 10px; border-radius: 8px; display: inline-block; }
.badges { display: flex; gap: 6px; flex-wrap: wrap; }
.actionbar { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.kv { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 22px; }
.kv > div { min-width: 0; }
.kv .k { font-size: 11.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--text-3); margin-bottom: 3px; }
.kv .v { font-size: 14px; color: var(--text); word-break: break-word; }
.kv .v.empty-v { color: var(--text-3); }
.kv .full { grid-column: 1 / -1; }
.prose { white-space: pre-wrap; color: var(--text-2); line-height: 1.7; }
.docs .doc { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.docs .doc:last-child { border-bottom: 0; }
.docs .doc .ext { width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center; font-size: 10.5px; font-weight: 800; letter-spacing: .04em; background: var(--primary-soft); color: var(--primary); flex-shrink: 0; text-transform: uppercase; }
.timeline { position: relative; padding-left: 22px; }
.timeline::before { content: ""; position: absolute; left: 6px; top: 6px; bottom: 6px; width: 2px; background: var(--border); border-radius: 2px; }
.tl-item { position: relative; padding: 0 0 18px; }
.tl-item:last-child { padding-bottom: 0; }
.tl-item::before { content: ""; position: absolute; left: -22px; top: 5px; width: 14px; height: 14px; border-radius: 50%; background: var(--surface); border: 3px solid var(--primary); box-sizing: border-box; }
.tl-item.done::before { border-color: var(--success); }
.tl-item.warn::before { border-color: var(--warning); }
.tl-item.bad::before { border-color: var(--danger); }
.tl-item .tt { font-weight: 600; font-size: 13.5px; }
.tl-item .tm { font-size: 12px; color: var(--text-3); }
.tl-item .cm { margin-top: 6px; padding: 8px 10px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 9px; color: var(--text-2); font-size: 13px; white-space: pre-wrap; }
.kvrow { display: flex; justify-content: space-between; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--border); font-size: 13.5px; }
.kvrow:last-child { border-bottom: 0; }
.kvrow span:first-child { color: var(--text-3); }
.kvrow span:last-child { text-align: right; font-weight: 500; min-width: 0; word-break: break-word; }

/* ---------- Modal & toast ---------- */
.modal-backdrop {
    position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 24px;
    background: rgba(2, 6, 23, 0.55); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
    animation: fade .15s ease;
}
.modal {
    width: min(680px, 100%); max-height: calc(100vh - 48px); display: flex; flex-direction: column;
    background: var(--surface); border: 1px solid var(--border); border-radius: 18px; box-shadow: 0 30px 80px -20px rgba(0, 0, 0, .5);
    animation: pop .18s ease;
}
.modal.wide { width: min(880px, 100%); }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 18px 22px; border-bottom: 1px solid var(--border); }
.modal-head h2 { font-size: 16px; font-weight: 700; }
.modal-body { padding: 20px 22px; overflow-y: auto; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 22px; border-top: 1px solid var(--border); background: var(--surface-2); border-radius: 0 0 18px 18px; }
.toasts { position: fixed; right: 20px; bottom: 20px; z-index: 200; display: flex; flex-direction: column; gap: 10px; }
.toast {
    min-width: 260px; max-width: 420px; padding: 13px 16px; border-radius: 12px; background: var(--surface);
    border: 1px solid var(--border); box-shadow: var(--shadow); font-weight: 500; display: flex; gap: 10px; align-items: center;
    animation: pop .2s ease;
}
.toast svg { flex-shrink: 0; }
.toast.ok svg { color: var(--success); }
.toast.err { border-color: color-mix(in srgb, var(--danger) 40%, var(--border)); }
.toast.err svg { color: var(--danger); }
.alert { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: 10px; font-size: 13.5px; background: var(--danger-soft); color: var(--danger); }
.alert.info { background: var(--info-soft); color: var(--info); }
.alert.warn { background: var(--warning-soft); color: var(--warning); }

/* ---------- Login ---------- */
.auth {
    min-height: 100vh; display: grid; place-items: center; padding: 24px; position: relative; overflow: hidden;
    background:
        radial-gradient(900px 500px at 10% -10%, rgba(99, 102, 241, .25), transparent 60%),
        radial-gradient(800px 500px at 110% 110%, rgba(236, 72, 153, .18), transparent 60%),
        var(--bg);
}
.auth-card { width: min(980px, 100%); display: grid; grid-template-columns: 1.05fr 1fr; background: var(--surface); border: 1px solid var(--border); border-radius: 22px; overflow: hidden; box-shadow: var(--shadow); }
.auth-hero { padding: 44px; color: #e2e8f0; background: linear-gradient(160deg, #1e1b4b 0%, #312e81 45%, #581c87 100%); position: relative; display: flex; flex-direction: column; justify-content: space-between; }
.auth-hero::after { content: ""; position: absolute; width: 360px; height: 360px; border-radius: 50%; right: -140px; bottom: -140px; background: radial-gradient(circle, rgba(236, 72, 153, .45), transparent 65%); }
.auth-hero h2 { font-size: 28px; font-weight: 800; color: #fff; line-height: 1.2; position: relative; z-index: 1; }
.auth-hero p { color: #c7d2fe; margin-top: 12px; position: relative; z-index: 1; max-width: 380px; }
.auth-hero ul { list-style: none; padding: 0; margin: 24px 0 0; display: grid; gap: 10px; position: relative; z-index: 1; color: #e0e7ff; font-size: 13.5px; }
.auth-hero li { display: flex; gap: 10px; align-items: center; }
.auth-hero li svg { color: #a5b4fc; }
.auth-form { padding: 44px; display: flex; flex-direction: column; justify-content: center; }
.auth-form h1 { font-size: 24px; font-weight: 750; }
.auth-form > p { color: var(--text-2); margin: 6px 0 24px; }
.auth-form .theme-corner { position: absolute; top: 18px; right: 18px; }
.auth-wrap { position: relative; width: 100%; display: grid; place-items: center; }

/* ---------- Divers ---------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 18px; overflow-x: auto; }
.tabs button { background: none; border: 0; padding: 10px 14px; font: inherit; font-weight: 600; color: var(--text-3); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs button.active { color: var(--primary); border-bottom-color: var(--primary); }
.tabs button:hover { color: var(--text); }
.perm-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 10px; }
.perm { display: flex; gap: 10px; align-items: flex-start; padding: 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2); cursor: pointer; }
.perm:hover { border-color: var(--border-strong); }
.perm b { display: block; font-size: 13px; }
.perm small { color: var(--text-3); font-size: 11.5px; }
.perm.changed { border-color: var(--primary); box-shadow: inset 0 0 0 1px var(--primary); }
.module-title { font-size: 11.5px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--text-3); margin: 18px 0 8px; }
.role-list { display: flex; flex-direction: column; gap: 4px; }
.role-list button { display: flex; justify-content: space-between; align-items: center; gap: 8px; text-align: left; padding: 10px 12px; border-radius: 10px; border: 1px solid transparent; background: none; font: inherit; color: var(--text-2); cursor: pointer; }
.role-list button:hover { background: var(--surface-3); color: var(--text); }
.role-list button.active { background: var(--primary-soft); color: var(--primary); border-color: color-mix(in srgb, var(--primary) 30%, transparent); font-weight: 650; }
.role-list .n { font-size: 12px; color: var(--text-3); }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 3px; }
.print-only { display: none; }

.circuit-steps { list-style: none; margin: 0; padding: 0; position: relative; display: grid; gap: 12px; }
.circuit-steps li { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 11px; background: var(--surface-2); }
.circuit-steps .step-n, .step-row .step-n { width: 28px; height: 28px; border-radius: 50%; display: inline-grid; place-items: center; flex-shrink: 0; background: var(--primary-soft); color: var(--primary); font-weight: 700; font-size: 12.5px; }
.step-row { display: grid; grid-template-columns: 28px minmax(0, 1.4fr) minmax(0, 1fr) minmax(0, 1fr) 92px 34px; gap: 8px; align-items: center; margin-bottom: 8px; }
.step-row input, .step-row select { height: 36px; font-size: 13px; }
.steps-head { display: grid; grid-template-columns: 28px minmax(0, 1.4fr) minmax(0, 1fr) minmax(0, 1fr) 92px 34px; gap: 8px; margin-bottom: 4px; }
.tpl-preview { margin: 0; white-space: pre-wrap; font: 12.5px/1.6 ui-monospace, "SFMono-Regular", Consolas, monospace; color: var(--text-2); background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 12px; max-height: 180px; overflow: hidden; }
@media (max-width: 640px) { .step-row, .steps-head { grid-template-columns: 1fr; } .steps-head { display: none; } }
.ocr-box { grid-column: 1 / -1; display: grid; gap: 10px; padding: 14px; border: 1px dashed var(--border-strong); border-radius: 12px; background: var(--surface-2); }
.ocr-box textarea { min-height: 96px; font-size: 12.5px; }
.qr-box svg { width: 100%; height: auto; display: block; border-radius: 10px; background: #fff; padding: 6px; box-sizing: border-box; }

@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop { from { opacity: 0; transform: translateY(6px) scale(.985); } to { opacity: 1; transform: none; } }

/* ---------- Responsive ---------- */
@media (max-width: 1180px) {
    .grid.two, .grid.side { grid-template-columns: 1fr; }
    .form-grid.three { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 960px) {
    .app { grid-template-columns: 1fr; }
    .sidebar {
        position: fixed; left: 0; top: 0; bottom: 0; width: 272px; z-index: 60; height: 100vh;
        transform: translateX(-100%); transition: transform .25s ease; box-shadow: 0 0 40px rgba(0, 0, 0, .4);
    }
    .sidebar.open { transform: none; }
    .menu-toggle { display: inline-grid; }
    .scrim { position: fixed; inset: 0; background: rgba(2, 6, 23, .5); z-index: 55; }
    .topbar { padding: 0 16px; }
    .content { padding: 18px; }
    .auth-card { grid-template-columns: 1fr; }
    .auth-hero { display: none; }
}
@media (max-width: 640px) {
    .form-grid, .form-grid.three, .kv { grid-template-columns: 1fr; }
    .topbar .search { display: none; }
    .page-head h1 { font-size: 20px; }
    .auth-form { padding: 28px; }
    .modal-body { padding: 16px; }
    .table th, .table td { padding: 10px; }
}

@media print {
    .sidebar, .topbar, .no-print, .toasts { display: none !important; }
    .app { display: block; }
    .content { padding: 0; }
    body { background: #fff; color: #000; }
    .card { box-shadow: none; border-color: #bbb; }
}
