:root {
    --primary: #0075c9;
    --primary-dark: #005a9e;
    --primary-light: #e0f2fe;
    --text-dark: #1e293b;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    --bg: #f8fafc;
    --border: #e2e8f0;
    --success: #10b981;
    --warning: #f59e0b;
    --error: #ef4444;
    --purple: #8b5cf6;
    --orange: #f59e0b;
    --sidebar-w: 260px;
    --l1: #0075c9;
    --l2: #f59e0b;
    --l3: #8b5cf6;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: 'Outfit', sans-serif;
    background: var(--bg);
    color: var(--text-dark);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

.app { display: flex; min-height: 100vh; }

.sidebar {
    width: var(--sidebar-w);
    background: linear-gradient(180deg, var(--primary) 0%, var(--primary-dark) 100%);
    padding: 0 20px 24px;
    display: flex;
    flex-direction: column;
    position: fixed;
    height: 100vh;
    left: 0;
    top: 0;
    z-index: 40;
}
.logo {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 70px;
    min-height: 70px;
    margin: 0 -20px 20px;
    border-bottom: 1px solid rgba(255,255,255,0.2);
}
.logo img { max-width: 180px; height: auto; filter: brightness(0) invert(1); opacity: 0.95; }
.nav-section { flex: 1; display: flex; flex-direction: column; gap: 6px; }
.nav-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 11px 12px;
    border-radius: 10px;
    color: rgba(255,255,255,0.86);
    text-decoration: none;
    font-size: 13.5px;
    font-weight: 500;
    transition: background 0.15s ease;
}
.nav-link svg { width: 18px; height: 18px; flex-shrink: 0; opacity: 0.85; }
.nav-link:hover, .nav-link.active { background: rgba(255,255,255,0.16); color: #fff; }
.user-section { border-top: 1px solid rgba(255,255,255,0.1); padding-top: 18px; margin-top: auto; }
.user-info { display: flex; align-items: center; gap: 12px; padding: 10px 8px 14px; }
.user-avatar {
    width: 36px; height: 36px;
    background: rgba(255,255,255,0.2);
    border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    font-size: 14px; font-weight: 600; color: #fff;
}
.user-name { font-size: 13px; font-weight: 600; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.btn-back-memento {
    width: 100%;
    display: flex; align-items: center; justify-content: center; gap: 8px;
    padding: 11px 14px;
    background: rgba(255,255,255,0.08);
    color: rgba(255,255,255,0.9);
    border: 1px solid rgba(255,255,255,0.16);
    border-radius: 10px;
    font-size: 13px; font-weight: 500; font-family: inherit;
    text-decoration: none; cursor: pointer;
}
.btn-back-memento:hover { background: rgba(255,255,255,0.14); }

.main { flex: 1; margin-left: var(--sidebar-w); padding: 32px 40px 64px; min-width: 0; }
body.sans-sidebar .main { margin-left: 0; }

.header { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 28px; flex-wrap: wrap; }
.header h1 { font-size: 28px; font-weight: 700; }
.header p { font-size: 14px; color: var(--text-muted); margin-top: 4px; }
.header-actions { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    border: none; border-radius: 10px;
    padding: 11px 18px;
    font-size: 14px; font-weight: 600; font-family: inherit;
    cursor: pointer; text-decoration: none;
    transition: transform 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
}
.btn:hover { transform: translateY(-1px); }
/* `display: inline-flex` l'emporte sur la règle d'agent utilisateur : sans ceci,
   poser l'attribut hidden sur un bouton ne le retirerait pas de la barre. */
.btn[hidden] { display: none; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: #fff; color: var(--text-secondary); border: 1px solid var(--border); }
.btn svg { width: 16px; height: 16px; flex-shrink: 0; }
.btn-outline { background: #fff; color: var(--primary); border: 1px solid #bfdbfe; }
.btn-outline:hover { background: #f0f9ff; }
.btn-ghost { background: #f1f5f9; color: var(--text-secondary); }
.btn-home {
    background: #f6f8fb; color: #475569; border: 1px solid #eef2f7;
}
.btn-home:hover { background: #eaf3fc; border-color: #cfe3f6; color: #0075c9; }
.btn-danger { background: var(--error); color: #fff; }
.btn-sm { padding: 7px 12px; font-size: 12.5px; border-radius: 8px; }

.pill {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    background: #f1f5f9; color: var(--text-secondary);
    border-radius: 999px; padding: 4px 10px;
    font-size: 12px; font-weight: 600; line-height: 1.2;
}

/* Dans la barre, les actions reprennent les boutons contour des autres modules. */
.sticky-bar .btn,
.sticky-bar .btn-sm {
    padding: 10px 16px;
    font-size: 13px;
    border-radius: 10px;
    font-weight: 600;
}
.sticky-bar .btn:hover { transform: none; }
.sticky-bar .view-tabs {
    padding: 2px; gap: 2px; border-radius: 999px;
}
.sticky-bar .view-tab {
    padding: 4px 10px; font-size: 12px; border-radius: 999px;
}

.projects-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 20px; }
.project-card {
    background: #fff; border: 1px solid var(--border); border-radius: 16px;
    padding: 22px; display: flex; flex-direction: column;
    transition: box-shadow 0.2s ease, transform 0.2s ease;
}
.project-card:hover { box-shadow: 0 8px 24px rgba(15,23,42,0.08); transform: translateY(-2px); }
.project-card h3 { font-size: 17px; font-weight: 600; margin-bottom: 6px; }
.project-card .desc { font-size: 14px; color: var(--text-muted); margin-bottom: 16px; flex: 1; }
.project-meta { font-size: 12px; color: var(--text-muted); display: flex; flex-direction: column; gap: 4px; padding-bottom: 14px; border-bottom: 1px solid var(--border); margin-bottom: 14px; }
.project-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.project-actions .btn-primary { grid-column: 1 / -1; }

.empty-state, .loading { text-align: center; padding: 60px 32px; background: #fff; border: 1px solid var(--border); border-radius: 16px; }
.empty-state h3 { font-size: 18px; margin-bottom: 8px; }
.empty-state p { color: var(--text-muted); font-size: 14px; margin-bottom: 20px; }
.spinner { width: 40px; height: 40px; border: 3px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin 0.8s linear infinite; margin: 0 auto 16px; }
@keyframes spin { to { transform: rotate(360deg); } }

.modal-overlay {
    position: fixed; inset: 0; background: rgba(15,23,42,0.45);
    display: none; align-items: center; justify-content: center;
    z-index: 80; padding: 20px;
}
.modal-overlay.show { display: flex; }
.modal {
    background: #fff; border-radius: 20px; padding: 28px;
    width: 100%; max-width: 520px; max-height: 90vh; overflow: auto;
    box-shadow: 0 20px 60px rgba(0,0,0,0.2);
}
.modal h3 { font-size: 20px; font-weight: 700; margin-bottom: 20px; }
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 13px; font-weight: 600; color: var(--text-secondary); margin-bottom: 6px; }
.form-group input, .form-group textarea, .form-group select {
    width: 100%; padding: 12px 14px; background: #f8fafc;
    border: 2px solid var(--border); border-radius: 10px;
    font-size: 14px; font-family: inherit; color: var(--text-dark);
}
.form-group input:focus, .form-group textarea:focus, .form-group select:focus {
    outline: none; border-color: var(--primary); background: #fff;
}
.form-group small, .hint { display: block; font-size: 12px; color: var(--text-muted); margin-top: 6px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 22px; }

.toast-wrap { position: fixed; top: 18px; right: 18px; z-index: 120; display: flex; flex-direction: column; gap: 8px; }
.toast {
    background: #0f172a; color: #fff; padding: 12px 16px; border-radius: 10px;
    font-size: 13px; font-weight: 500; box-shadow: 0 8px 24px rgba(0,0,0,0.18);
    min-width: 220px;
}
.toast.ok { background: #065f46; }
.toast.err { background: #991b1b; }

/* ===== Modèle ===== */
.view-tabs {
    display: inline-flex; background: #fff; border: 1px solid var(--border);
    border-radius: 12px; padding: 4px; gap: 4px;
}
.view-tab {
    border: none; background: transparent; font-family: inherit;
    font-size: 13.5px; font-weight: 600; color: var(--text-secondary);
    padding: 8px 16px; border-radius: 8px; cursor: pointer;
}
.view-tab.active { background: var(--primary); color: #fff; }
.view-panel { display: none; }
.view-panel.active { display: block; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }

.card {
    background: #fff; border: 1px solid var(--border); border-radius: 16px; padding: 20px 22px;
}
.card h2 { font-size: 16px; font-weight: 700; margin-bottom: 4px; }
.card .card-sub { font-size: 13px; color: var(--text-muted); margin-bottom: 16px; }

.kpi { background: #fff; border: 1px solid var(--border); border-radius: 14px; padding: 16px 18px; }
.kpi .lbl { font-size: 12px; color: var(--text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em; }
.kpi .val { font-size: 26px; font-weight: 700; margin-top: 4px; letter-spacing: -0.03em; }
.kpi .sub { font-size: 12px; color: var(--text-secondary); margin-top: 4px; }
.kpi.l1 .val { color: var(--l1); }
.kpi.l2 .val { color: #d97706; }
.kpi.l3 .val { color: var(--l3); }
.kpi.ok .val { color: #059669; }

.field-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
.field-row .form-group, .field-pair .form-group { margin-bottom: 0; }
/* Deux champs seuls dans une field-row s'étireraient sur toute la largeur. */
.field-pair { display: grid; grid-template-columns: minmax(180px, 320px) minmax(140px, 200px); gap: 12px; }

/* Phases du protocole : une ligne de champs par phase, comme le parcours. */
.proto-empty {
    margin: 12px 0 0;
    padding: 12px 14px;
    border: 1px dashed #c4b5fd;
    border-radius: 10px;
    background: #f5f3ff;
    color: #5b21b6;
    font-size: 13px;
    line-height: 1.4;
}
.proto-line {
    margin-top: 10px;
    padding: 8px 10px 10px;
    border: 1px solid var(--border);
    border-left: 3px solid #8b5cf6;
    border-radius: 10px;
    background: #faf9ff;
}
.proto-line-head {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 6px;
}
.proto-line-head h3 {
    margin: 0;
    flex: 1;
    min-width: 0;
    font-size: 14px;
    font-weight: 700;
    color: var(--text-dark);
    line-height: 1.3;
}
.proto-line-kicker {
    display: inline;
    font-size: 11px;
    font-weight: 650;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    color: #7c3aed;
    margin-right: 8px;
}
.proto-line-n {
    margin: 0;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    white-space: nowrap;
}
.proto-line-head [data-add-phase] {
    flex: none;
    padding: 4px 8px;
    font-size: 12px;
}
.proto-uptake {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    margin: 0 0 8px;
    padding: 6px 8px;
    background: #fff;
    border: 1px solid #ddd6fe;
    border-radius: 8px;
}
.proto-uptake label {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin: 0;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    white-space: nowrap;
}
.proto-uptake input[type="month"],
.proto-uptake input[type="number"] {
    width: auto;
    min-width: 0;
    padding: 4px 8px;
    border: 1px solid var(--border);
    border-radius: 7px;
    font-family: inherit;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-dark);
    background: #fff;
}
.proto-uptake input[type="month"] { width: 148px; }
.proto-uptake input[type="number"] { width: 56px; }
.proto-uptake input:focus { outline: none; border-color: var(--primary); }
.proto-uptake-hint {
    margin: 0;
    font-size: 12px;
    font-weight: 500;
    color: #7c3aed;
}
.proto-legend, .proto-phase {
    display: grid;
    grid-template-columns: minmax(110px, 1.2fr) 118px 58px 58px 52px 70px 58px 28px 32px;
    gap: 6px;
    align-items: center;
}
.proto-legend {
    padding: 0 6px 4px;
    font-size: 10.5px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    border-bottom: 1px solid var(--border);
    margin-bottom: 4px;
}
.proto-phase {
    margin-top: 4px;
    padding: 4px 6px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #fff;
}
.proto-phase.is-off { opacity: 0.5; }
.proto-phase.is-once .proto-repeat input {
    visibility: hidden;
    pointer-events: none;
}
.proto-phase input:not([type="checkbox"]), .proto-phase select {
    width: 100%;
    padding: 5px 7px;
    border: 1px solid var(--border);
    border-radius: 7px;
    font-family: inherit;
    font-size: 13px;
    background: #fff;
    color: var(--text-dark);
}
.proto-phase input[data-ph="label"] {
    font-weight: 650;
    border-color: transparent;
    background: transparent;
    padding-left: 2px;
}
.proto-phase input[data-ph="label"]:focus {
    border-color: var(--primary);
    background: #fff;
}
.proto-phase input:focus, .proto-phase select:focus { outline: none; border-color: var(--primary); }
.pp-on { display: flex; justify-content: center; }
.pp-on input { width: 15px; height: 15px; accent-color: var(--primary); cursor: pointer; }
.pp-act { display: flex; justify-content: flex-end; }
.proto-phase .icon-btn { width: 26px; height: 26px; }
.proto-toolbar { display: none; }
#sumProto { margin: 8px 0 0; font-size: 12px; }

.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; }

/* Volets de réglages secondaires. Le résumé donne leur valeur sans les ouvrir : ce qui
   est replié doit rester connu, sinon on ne fait que cacher. */
.adv { margin-top: 16px; border-top: 1px solid var(--border); padding-top: 12px; }
.adv > summary {
    cursor: pointer; list-style: none; display: flex; align-items: baseline;
    gap: 8px; flex-wrap: wrap;
    font-size: 13px; font-weight: 600; color: var(--text-secondary);
}
.adv > summary::-webkit-details-marker { display: none; }
.adv > summary::before {
    content: ""; width: 0; height: 0; flex: none;
    border-left: 5px solid currentColor; border-top: 4px solid transparent; border-bottom: 4px solid transparent;
    transform: translateY(1px); transition: transform 0.2s ease;
}
.adv[open] > summary::before { transform: rotate(90deg) translateX(1px); }
.adv > summary:hover { color: var(--primary); }
.adv-sum { font-size: 12px; font-weight: 500; color: var(--text-muted); }
.adv > .field-row { margin-top: 14px; }

/* Parcours de soins : une ligne par branche, à plat. Les intitulés vivent dans la
   légende, écrits une seule fois, et la profondeur se lit au décalage du nom. */
.node-tree { display: flex; flex-direction: column; gap: 6px; }
.node-legend, .node-row {
    display: grid;
    grid-template-columns: minmax(170px, 1fr) 92px 68px minmax(130px, 180px) 62px 78px 74px 64px;
    gap: 8px; align-items: start;
}
.node-legend {
    padding: 0 8px 6px;
    font-size: 11px; font-weight: 600; color: var(--text-muted);
    text-transform: uppercase; letter-spacing: 0.03em;
    border-bottom: 1px solid var(--border); margin-bottom: 4px;
}
.node-row {
    position: relative;
    background: #f8fafc; border: 1px solid var(--border); border-left-width: 3px;
    border-radius: 10px; padding: 6px 8px;
    margin-left: calc(var(--depth, 0) * 1.75rem);
    width: calc(100% - var(--depth, 0) * 1.75rem);
    box-sizing: border-box;
}
.node-row:hover { background: #f1f5f9; }
.node-row[data-line="1"] { border-left-color: var(--l1); }
.node-row[data-line="2"] { border-left-color: var(--l2); }
.node-row[data-line="3"] { border-left-color: var(--l3); }
.node-row[data-line="4"] { border-left-color: #0ea5e9; }
.node-row:not(.is-root)::before {
    content: "";
    position: absolute;
    left: -1.1rem;
    top: 50%;
    width: 0.85rem;
    height: 2px;
    background: #94a3b8;
    border-radius: 1px;
}

.node-row input:not([type="checkbox"]), .node-row select {
    width: 100%; padding: 7px 9px; border: 1px solid var(--border); border-radius: 8px;
    font-family: inherit; font-size: 13px; background: #fff; color: var(--text-dark);
}
.node-row input:focus, .node-row select:focus { outline: none; border-color: var(--primary); }
.node-row input:disabled { background: #f1f5f9; color: var(--text-muted); }

.nr-name { display: block; }

.nr-num { position: relative; display: block; }
.nr-num input { padding-right: 22px !important; }
.nr-num i { position: absolute; right: 8px; top: 50%; transform: translateY(-50%); font-style: normal; font-size: 11px; color: var(--text-muted); }
.nr-inconnu {
    display: block;
    padding: 7px 4px;
    border: 1px dashed var(--border);
    border-radius: 8px;
    font-size: 11px;
    font-weight: 650;
    color: var(--text-muted);
    background: #f8fafc;
    text-align: center;
    white-space: nowrap;
}
.nr-pres { display: flex; justify-content: center; }
.nr-pres input { width: 16px; height: 16px; accent-color: var(--primary); cursor: pointer; }
.nr-count { text-align: right; white-space: nowrap; }
.node-row .nr-count { font-size: 13px; font-weight: 650; color: var(--primary); }
.nr-act { display: flex; gap: 4px; justify-content: flex-end; }
.nr-dcis, .flow-dcis {
    display: flex; flex-direction: column; align-items: flex-start; gap: 4px;
}
.nr-dcis {
    grid-column: 1 / -1;
    padding: 4px 0 0;
}
.nr-dcis input { width: 100%; }
.nr-dcis-chips, .flow-dcis-chips {
    display: flex; flex-wrap: wrap; gap: 4px; align-items: center;
}
.nr-dcis-lbl, .flow-dcis-lbl {
    font-size: 10px; font-weight: 700; letter-spacing: 0.04em;
    text-transform: uppercase; color: var(--text-muted);
}
.dci-chip {
    font-size: 11px; font-weight: 650; line-height: 1.25;
    padding: 3px 8px; border-radius: 999px;
    background: #e0f2fe; color: #0369a1; border: 1px solid #bae6fd;
    max-width: 100%;
}

.icon-btn {
    display: inline-flex; align-items: center; justify-content: center;
    width: 28px; height: 28px; flex: none; padding: 0;
    background: #fff; border: 1px solid var(--border); border-radius: 8px;
    color: var(--text-secondary); cursor: pointer;
}
.icon-btn svg { width: 14px; height: 14px; }
.icon-btn:hover { border-color: var(--primary); color: var(--primary); }
.icon-btn.danger:hover { border-color: #ef4444; color: #ef4444; }

/* Flow render — schéma en arbre (bulles + liaisons) */
.flow-board {
    overflow: auto;
    padding: 4px 0 8px;
}
.flow-canvas {
    position: relative;
    margin: 0 auto;
}
.flow-headers {
    position: absolute;
    left: 0; top: 0;
    right: 0;
    height: 28px;
    z-index: 1;
    pointer-events: none;
}
.flow-col-title {
    position: absolute;
    top: 0;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    text-align: center;
    white-space: nowrap;
}
.flow-svg {
    position: absolute;
    left: 0; top: 0;
    overflow: visible;
    pointer-events: none;
    z-index: 1;
}
.flow-link {
    fill: none;
    stroke: #94a3b8;
    stroke-width: 2;
    stroke-linecap: round;
}
.flow-link.is-presence { stroke: #8b5cf6; }
.flow-link-label rect {
    fill: #fff;
    stroke: #e2e8f0;
    stroke-width: 1;
}
.flow-link-label.is-presence rect { stroke: #ddd6fe; }
.flow-link-label text {
    fill: #475569;
    font-size: 11px;
    font-weight: 700;
    font-family: Outfit, sans-serif;
    text-anchor: middle;
}
.flow-link-label.is-presence text { fill: #6d28d9; }
.flow-bubble {
    position: absolute;
    width: 216px;
    transform: translate(-50%, 0);
    text-align: center;
    z-index: 2;
    pointer-events: none;
}
.flow-circle {
    width: 86px;
    height: 86px;
    margin: 0 auto 8px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-weight: 700;
    font-size: 15px;
    box-shadow: 0 8px 18px rgba(15,23,42,0.12), inset 0 -4px 10px rgba(0,0,0,0.12);
    border: 3px solid #fff;
}
.flow-bubble.l0 .flow-circle { background: #334155; }
.flow-bubble.l1 .flow-circle { background: var(--l1); }
.flow-bubble.l2 .flow-circle { background: #d97706; }
.flow-bubble.l3 .flow-circle { background: var(--l3); }
.flow-bubble.l4 .flow-circle { background: #0ea5e9; }
.flow-bubble.attrition .flow-circle { background: #94a3b8; }
.flow-bubble.presence .flow-circle {
    box-shadow: 0 0 0 3px rgba(139,92,246,0.28), 0 8px 18px rgba(139,92,246,0.16);
}
.flow-bubble.is-inconnu .flow-circle {
    font-size: 22px;
    font-weight: 600;
    letter-spacing: 0;
}
.flow-label {
    font-size: 13px; font-weight: 700; line-height: 1.3; color: var(--text-dark);
    display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2;
    overflow: hidden;
}
.flow-strat {
    margin-top: 3px;
    font-size: 11px; font-weight: 500; line-height: 1.35; color: var(--text-secondary);
    display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2;
    overflow: hidden;
}
.flow-meta { font-size: 11px; color: var(--text-muted); margin-top: 5px; }
.flow-dcis {
    align-items: stretch;
    width: 100%;
    margin-top: 8px;
    padding: 6px 6px 5px;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    box-sizing: border-box;
}
.flow-dcis-chips { justify-content: center; }
.flow-dcis .dci-chip {
    font-size: 10px;
    padding: 2px 7px;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.flow-pdm {
    margin: 8px auto 0;
    width: 100%;
    background: #f5f3ff;
    border: 1px solid #ddd6fe;
    border-radius: 10px;
    padding: 7px 8px;
    font-size: 11.5px;
    text-align: left;
    line-height: 1.35;
}
.flow-pdm strong { color: #6d28d9; }

.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th {
    text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em;
    color: var(--text-muted); padding: 8px 10px; border-bottom: 1px solid var(--border);
}
.data-table td { padding: 9px 10px; border-bottom: 1px solid #f1f5f9; }
.data-table tr:last-child td { border-bottom: none; }
.data-table .num { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.data-table tfoot td { font-weight: 700; background: #f8fafc; }

#tablePatients th,
#tablePatients td,
#tablePatients .num,
#tableVolumes th,
#tableVolumes td,
#tableVolumes .num {
    text-align: center;
    vertical-align: middle;
}
#tablePatients th.branche,
#tablePatients td.branche,
#tablePatients tfoot td.branche { text-align: left; }
#tablePatients .arbre-nom {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding-left: calc(var(--depth, 0) * 1.35rem);
    font-weight: 650;
}
#tablePatients tr.is-fille .arbre-nom::before {
    content: "";
    width: 0.7rem;
    height: 0;
    border-top: 2px solid #94a3b8;
    flex: none;
    margin-left: -0.85rem;
}
#tablePatients tr.is-present td.branche { color: #5b21b6; }

#tableVolumes col.sep { width: 10px; }
#tableVolumes th.sep,
#tableVolumes td.sep {
    width: 10px;
    min-width: 10px;
    max-width: 10px;
    padding: 0;
    background: #cbd5e1;
    border-bottom: none;
}
#tableVolumes thead th.grp-mois,
#tableVolumes thead th.grp-cumul {
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-size: 10px;
    color: #64748b;
}
#tableVolumes thead th.grp-mois { background: #f8fafc; }
#tableVolumes thead th.grp-cumul,
#tableVolumes td.is-cumul,
#tableVolumes tfoot td.is-cumul {
    background: #f1f5f9;
}

.chart-pair { align-items: stretch; }
.chart-card {
    display: flex;
    flex-direction: column;
    min-height: 0;
}
.chart-card h2 { flex: none; margin-bottom: 12px; }
.chart-card .card-sub { display: none; }
.chart-wrap {
    position: relative;
    flex: 1 1 auto;
    height: 280px;
    min-height: 280px;
}

.sticky-bar {
    position: sticky; top: 0; z-index: 20;
    background: rgba(248,250,252,0.92); backdrop-filter: blur(10px);
    margin: -32px -40px 22px; padding: 16px 40px 12px;
    border-bottom: 1px solid var(--border);
    display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap;
}


/* --------------------------------------------- scénarios de démonstration */

/* Le bandeau dit d'où viennent les chiffres. Il tient sur une ligne au-dessus
   des indicateurs, en ambre : c'est un avertissement, pas une erreur. */
.demo-bandeau {
    display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
    margin-bottom: 16px; padding: 11px 16px;
    background: #fffbeb; border: 1px solid #fde68a; border-radius: 12px;
    font-size: 13px; line-height: 1.45; color: #78350f;
}
.demo-bandeau[hidden] { display: none; }
.demo-bandeau-corps { flex: 1 1 320px; min-width: 0; }
.demo-bandeau-corps strong { font-weight: 700; }
.demo-bandeau-corps span { color: #92400e; }
.demo-bandeau-lien {
    flex: none; font-weight: 650; color: #b45309; text-decoration: underline;
    text-underline-offset: 2px; white-space: nowrap;
}
.demo-bandeau-lien:hover { color: #78350f; }
.demo-bandeau-lien[hidden] { display: none; }

/* Sur une démonstration, ajouter ou retirer une branche n'a pas de sens : les
   champs sont désarmés par le script, les boutons disparaissent ici. La colonne
   qui les portait est retirée du gabarit, sans quoi elle laisserait un blanc de
   soixante-quatre pixels au bout de chaque ligne. */
body.est-demo .nr-act { display: none; }
body.est-demo .node-legend > span:last-child { display: none; }
/* Une démonstration montre un parcours observé, pas un protocole produit :
   dose, rythme et volumes n'ont rien à y faire. L'export CSV est celui des
   boîtes : il disparaît avec eux. */
body.est-demo #cardProtocole,
body.est-demo #cardVolumes,
body.est-demo #cardPatients,
body.est-demo #cardVolumesTable,
body.est-demo #csvBtn,
body.est-demo #dupUserBtn { display: none; }
body.est-demo #view-rendu .grid-2 { grid-template-columns: 1fr; }
body.est-parcours-clinique #view-rendu .grid-2,
body.est-parcours-clinique #cardPatientsTable,
body.est-parcours-clinique #cardVolumesTable { display: none; }
body.est-parcours-clinique #flowBoard { overflow: visible; padding: 0; }
/* Sous 1100 px la ligne se replie sur deux colonnes : ce gabarit-ci ne vaut que
   pour la disposition large, sinon sa spécificité l'emporterait sur le repli. */
@media (min-width: 1101px) {
    body.est-demo .node-legend,
    body.est-demo .node-row {
        grid-template-columns: minmax(170px, 1fr) 82px 68px minmax(130px, 180px) 62px 78px 74px;
    }
}

@media (max-width: 1100px) {
    .grid-4 { grid-template-columns: 1fr 1fr; }
    .grid-3, .grid-2 { grid-template-columns: 1fr; }

    /* Huit colonnes ne tiennent plus : la légende laisse la place aux intitulés
       portés par chaque cellule, et la ligne se replie sur deux colonnes. */
    .node-legend { display: none; }
    .node-row {
        grid-template-columns: 1fr 1fr; row-gap: 10px; padding: 10px;
        margin-left: calc(var(--depth, 0) * 1.15rem);
        width: calc(100% - var(--depth, 0) * 1.15rem);
    }
    .node-row .nr-name, .node-row .nr-act, .node-row .nr-dcis { grid-column: 1 / -1; }
    .node-row > span[data-lbl]::after {
        content: attr(data-lbl);
        display: block; order: -1;
        font-size: 10.5px; font-weight: 600; color: var(--text-muted); margin-bottom: 3px;
    }
    .node-row > span[data-lbl] { display: flex; flex-direction: column; }
    .nr-pres { align-items: flex-start; }
    .nr-count { text-align: left; }
    .field-pair { grid-template-columns: 1fr; }
    .proto-legend { display: none; }
    .proto-phase {
        grid-template-columns: 1fr 1fr;
        row-gap: 8px;
        padding: 8px;
    }
    .proto-phase .pp-name, .proto-phase .pp-act { grid-column: 1 / -1; }
    .proto-phase.is-once .proto-repeat { display: none; }
    .proto-phase.is-once .proto-repeat input { visibility: visible; }
    .proto-phase > span[data-lbl]::before {
        content: attr(data-lbl);
        display: block;
        font-size: 10.5px; font-weight: 600; color: var(--text-muted); margin-bottom: 2px;
        text-transform: none; letter-spacing: 0;
    }
    .proto-line-head { flex-wrap: wrap; }
    .proto-uptake { padding: 8px; }
    .proto-uptake input[type="month"] { width: 100%; max-width: 168px; }
}
@media (max-width: 768px) {
    .sidebar { display: none; }
    .main { margin-left: 0; padding: 20px 16px 48px; }
    .sticky-bar { margin: -20px -16px 16px; padding: 12px 16px; }
    .grid-4 { grid-template-columns: 1fr; }
}
