:root {
    --ink: #0f172a;
    --ink-soft: #1e293b;
    --navy: #0b1c2c;
    --navy-mid: #12263a;
    --accent: #0e7490;
    --accent-deep: #0b5f75;
    --accent-soft: #e0f2f7;
    --bg: #f3f5f8;
    --paper: #ffffff;
    --line: #e2e8f0;
    --line-strong: #cbd5e1;
    --muted: #64748b;
    --blush: #b42318;
    --ok: #067647;
    --warn: #b54708;
    --shadow: 0 1px 2px rgba(15, 23, 42, .05), 0 10px 24px rgba(15, 23, 42, .04);
    --radius: 10px;
    --radius-sm: 6px;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
    font-family: "IBM Plex Sans", "Segoe UI", sans-serif;
    color: var(--ink);
    background: var(--bg);
    line-height: 1.5;
    font-size: 15px;
}

h1, h2, h3, .serif {
    font-family: "IBM Plex Sans", "Segoe UI", sans-serif;
    font-weight: 650;
    letter-spacing: -.02em;
    color: var(--ink);
}
h1, h1.serif { font-size: 1.5rem; line-height: 1.25; }
h2 { font-size: 1.05rem; margin: 0 0 12px; }
.topbar h1, .topbar h1.serif { font-size: 1.5rem !important; margin: 4px 0 0 !important; }
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; }
img { max-width: 100%; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.app { display: grid; grid-template-columns: 248px 1fr; min-height: 100vh; }
.sidebar {
    background: var(--navy);
    color: #e8eef4;
    padding: 22px 16px;
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
}
.brand { display: block; margin-bottom: 18px; padding: 0 4px; }
.brand-logo { display: block; width: 100%; max-width: 196px; height: auto; }
.mark {
    width: 36px; height: 36px; border-radius: 8px;
    background: var(--accent);
    display: grid; place-items: center; color: #fff;
    font-weight: 700; font-size: 16px; letter-spacing: -.03em;
}
.brand strong { display: block; font-size: 14px; }
.brand small { display: block; color: #94a3b8; font-size: 11px; margin-top: 8px; padding-left: 2px; }
.hero .brand-logo { max-width: 280px; }
.nav { display: grid; gap: 2px; }
.nav-group { margin-bottom: 14px; }
.nav-label {
    display: block; padding: 8px 12px 6px;
    color: #7c8fa3; font-size: 10px; letter-spacing: .12em;
    text-transform: uppercase; font-weight: 700;
}
.nav a {
    display: flex; align-items: center; gap: 10px;
    padding: 8px 12px; border-radius: 8px; color: #c5d0db;
    border-left: 2px solid transparent;
}
.nav a:hover { background: rgba(255,255,255,.05); color: #fff; }
.nav a.active {
    background: rgba(14, 116, 144, .22);
    color: #fff;
    border-left-color: var(--accent);
}
.nav svg { width: 16px; height: 16px; opacity: .8; flex-shrink: 0; }
.sidebar-foot { margin-top: auto; padding-top: 16px; border-top: 1px solid rgba(255,255,255,.08); }
.user-chip { display: flex; align-items: center; gap: 10px; }
.avatar, .dot {
    width: 34px; height: 34px; border-radius: 8px;
    display: grid; place-items: center; font-weight: 650; font-size: 12px;
    background: var(--accent); color: #fff;
}
.avatar { background: #1e3a4c; }
.sidebar-foot .btn-ghost {
    width: 100%; margin-top: 12px; color: #c5d0db;
    background: transparent; border-color: rgba(255,255,255,.16);
}
.sidebar-foot .btn-ghost:hover {
    background: rgba(255,255,255,.07); color: #fff; border-color: rgba(255,255,255,.28);
}
.main { padding: 28px 32px 48px; max-width: 1280px; }
.topbar { display: flex; justify-content: space-between; align-items: flex-start; gap: 20px; margin-bottom: 22px; }
.kicker {
    color: var(--accent); font-size: 11px; letter-spacing: .12em;
    text-transform: uppercase; font-weight: 700; margin: 0;
}
.lede { color: var(--muted); max-width: 62ch; margin: 6px 0 0; font-size: 14px; }

.grid { display: grid; gap: 16px; }
.cols-2 { grid-template-columns: 1.2fr .8fr; }
.cols-3 { grid-template-columns: repeat(3, 1fr); }
.cols-4 { grid-template-columns: repeat(4, 1fr); }
.card {
    background: var(--paper);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
}
.stat { position: relative; overflow: hidden; }
.stat b {
    display: block; font-size: 26px; margin-top: 8px;
    font-variant-numeric: tabular-nums; letter-spacing: -.03em;
}
.stat span { color: var(--muted); font-size: 13px; font-weight: 600; }
.stat small { display: block; margin-top: 6px; color: var(--muted); font-size: 12px; font-weight: 600; }
.stat i { position: absolute; right: 16px; top: 16px; font-style: normal; font-size: 22px; opacity: .35; }

.btn, .btn-ghost, .btn-gold, .btn-danger {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    border: 0; border-radius: var(--radius-sm); padding: 9px 14px; cursor: pointer; font-weight: 600;
    font-size: 14px; line-height: 1.2;
}
.btn, .btn-gold { background: var(--accent); color: #fff; }
.btn:hover, .btn-gold:hover { background: var(--accent-deep); }
.btn-ghost { background: #fff; border: 1px solid var(--line-strong); color: var(--ink-soft); }
.btn-ghost:hover { background: #f8fafc; border-color: #94a3b8; }
.btn-danger { background: var(--blush); color: #fff; }

.field { display: grid; gap: 6px; }
.field span, label.field span { font-size: 12px; color: var(--muted); font-weight: 650; }
input, select, textarea {
    width: 100%; border: 1px solid var(--line-strong); background: #fff;
    border-radius: var(--radius-sm); padding: 9px 11px; color: var(--ink);
}
input:focus, select:focus, textarea:focus {
    border-color: var(--accent); box-shadow: 0 0 0 3px rgba(14, 116, 144, .12);
    outline: none;
}
textarea { min-height: 96px; resize: vertical; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-inset, .form-panel {
    margin-bottom: 20px; padding: 16px;
    background: #f8fafc; border: 1px solid var(--line); border-radius: var(--radius);
}
.full { grid-column: 1 / -1; }

.table { width: 100%; border-collapse: collapse; }
.table th {
    text-align: left; font-size: 11px; letter-spacing: .08em; text-transform: uppercase;
    color: var(--muted); padding: 10px 12px; border-bottom: 1px solid var(--line);
    background: #f8fafc; font-weight: 700;
}
.table td { padding: 12px; border-top: 1px solid var(--line); vertical-align: middle; }
.table td:last-child, .table th:last-child { text-align: right; }
.table tbody tr:first-child td { border-top: 0; }
.table tr:hover td { background: #f8fafc; }

.badge {
    display: inline-flex; align-items: center; padding: 3px 8px; border-radius: 4px;
    font-size: 11px; font-weight: 700; letter-spacing: .02em;
}
.badge-brouillon { background: #f1f5f9; color: #475569; }
.badge-emise { background: #e0f2f7; color: #0b5f75; }
.badge-partielle { background: #fef3c7; color: #92400e; }
.badge-payee { background: #dcfce7; color: #166534; }
.badge-en_retard, .badge-refusee { background: #fee4e2; color: #b42318; }
.badge-annulee { background: #f1f5f9; color: #64748b; }
.badge-soumise, .badge-approuvee { background: #e0f2f7; color: #0b5f75; }
.badge-actif { background: #dcfce7; color: #166534; }
.badge-inactif { background: #f1f5f9; color: #475569; }
.badge-en_attente { background: #f1f5f9; color: #475569; }

.flash {
    background: #ecfdf3; color: #067647; padding: 11px 14px;
    border-radius: var(--radius-sm); margin-bottom: 16px; border: 1px solid #abefc6;
}
.errors { color: var(--blush); font-size: 13px; }

.searchbar { display: flex; gap: 10px; align-items: center; }
.toolbar { display: flex; justify-content: space-between; gap: 12px; align-items: center; margin-bottom: 16px; flex-wrap: wrap; }

.bars { display: flex; align-items: flex-end; gap: 10px; height: 150px; }
.bar { flex: 1; display: grid; align-items: end; }
.bar span {
    display: block; background: var(--accent); border-radius: 4px 4px 0 0; min-height: 8px;
}
.bar small { display: block; text-align: center; color: var(--muted); margin-top: 4px; font-size: 12px; }
.bar b { display: block; text-align: center; font-size: 10px; color: var(--muted); font-weight: 650; margin-top: 4px; }

.aging { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.aging div { background: #f8fafc; border: 1px solid var(--line); border-radius: 8px; padding: 12px; }
.aging b { display: block; font-size: 20px; font-variant-numeric: tabular-nums; }

.paper {
    background: #fff; border-radius: var(--radius); padding: 28px;
    box-shadow: var(--shadow);
    border: 1px solid var(--line);
}
.paper h2 { margin: 0 0 4px; }
.line-row { display: grid; grid-template-columns: 90px 1fr 70px 100px 28px; gap: 8px; align-items: center; margin-bottom: 8px; }
.lookup { position: relative; }
.lookup-list {
    position: absolute; left: 0; right: 0; top: calc(100% + 6px); z-index: 8;
    background: #fff; border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); overflow: hidden;
}
.lookup-list button { width: 100%; text-align: left; background: #fff; border: 0; padding: 10px 12px; cursor: pointer; }
.lookup-list button:hover { background: #f8fafc; }
.lookup-list button span { display: block; color: var(--muted); font-size: 13px; }
.cim-code { font-family: "IBM Plex Mono", ui-monospace, monospace; font-variant-numeric: tabular-nums; letter-spacing: .02em; }
.cim-chosen { color: var(--accent); font-size: 12px; font-weight: 600; }

.guest {
    min-height: 100vh; display: grid; grid-template-columns: 1.05fr .95fr;
    background: var(--bg);
}
.hero {
    background: linear-gradient(165deg, #0b1c2c 0%, #123047 58%, #0e4a5c 100%);
    color: #eef4f8; padding: 56px;
    display: flex; flex-direction: column; justify-content: space-between;
}
.hero .brand small { color: #9fb0c0; }
.hero blockquote {
    font-size: 32px; line-height: 1.25; margin: 36px 0 0; max-width: 16ch;
    font-weight: 650; letter-spacing: -.03em;
}
.hero-points { margin: 28px 0 0; padding: 0; list-style: none; display: grid; gap: 12px; color: #c5d4df; font-size: 14px; }
.hero-points li { display: flex; gap: 10px; align-items: flex-start; }
.hero-points i {
    width: 8px; height: 8px; border-radius: 50%; background: var(--accent);
    margin-top: 7px; flex-shrink: 0; display: block;
}
.hero p { color: #9fb0c0; margin: 0; max-width: 42ch; }
.panel { display: grid; place-items: center; padding: 40px; }
.login-card { width: min(400px, 100%); }
.login-card h1 { font-size: 1.65rem !important; margin: 6px 0 0; }
.login-card .btn { width: 100%; padding: 11px 14px; }
.check { display: flex; align-items: center; gap: 8px; color: var(--muted); }
.check input { width: auto; }

.empty { text-align: center; padding: 40px 20px; color: var(--muted); }
.person { display: flex; align-items: center; gap: 12px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

.pagination { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }
.pagination a, .pagination span {
    padding: 7px 11px; border-radius: 6px; border: 1px solid var(--line);
    background: #fff; font-size: 13px; font-weight: 600;
}
.pagination a:hover { border-color: var(--accent); color: var(--accent); }

.profile-pills { display: flex; flex-wrap: wrap; gap: 8px; }
.pill {
    display: inline-flex; align-items: center; padding: 5px 10px; border-radius: 4px;
    background: #f1f5f9; color: var(--ink-soft); font-size: 12px; font-weight: 650;
    border: 1px solid var(--line);
}
.pill-gold { background: #fff7ed; color: #9a3412; border-color: #fed7aa; }
.ramq-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.ramq-tile {
    display: flex; flex-direction: column; width: 100%; font: inherit; text-align: left;
    background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius);
    padding: 16px; box-shadow: var(--shadow); cursor: pointer; color: inherit;
}
.ramq-tile:hover { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(14, 116, 144, .1); }
.ramq-tile small { color: var(--accent); font-size: 11px; letter-spacing: .1em; text-transform: uppercase; font-weight: 700; }
.ramq-tile strong {
    display: block; font-family: "IBM Plex Mono", ui-monospace, monospace;
    font-size: 22px; margin: 6px 0 4px; color: var(--accent-deep);
}
.ramq-tile p { margin: 0 0 12px; color: var(--ink); min-height: 2.6em; }
.ramq-tile b {
    margin-top: auto; padding-top: 10px; border-top: 1px solid var(--line);
    color: var(--ink); font-size: 1.05rem; font-variant-numeric: tabular-nums;
}
.ramq-tile em { display: block; margin-top: 6px; font-style: normal; color: var(--muted); font-size: 12px; }
.ramq-profile { margin-bottom: 18px; }
.ramq-profile h2 { margin: 6px 0 12px; }
.grid-picker { margin-bottom: 18px; }
.grid-matches { position: relative; margin-top: 8px; }
.grid-selected {
    display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
    margin-top: 16px; padding: 12px 14px;
    background: #f0f9fb; border: 1px solid #c5e4ec; border-radius: var(--radius);
}
.grid-selected strong { display: block; }
.grid-selected small { display: block; color: var(--muted); font-size: 13px; margin-top: 2px; }
.grid-selected .btn-ghost { margin-left: auto; }
.grid-switch {
    display: inline-flex; align-items: center; gap: 8px; cursor: pointer;
    padding: 6px 10px; border-radius: var(--radius-sm);
    border: 1px solid var(--line); background: #fff; font-size: 13px; font-weight: 650;
}
.grid-switch input { width: auto; margin: 0; }
.grid-switch.is-on { background: #fff7ed; border-color: #fed7aa; color: #9a3412; }
.grid-section { margin-bottom: 22px; }
.grid-section-head {
    display: flex; justify-content: space-between; align-items: baseline; gap: 12px;
    margin-bottom: 10px;
}
.grid-section-head h2 { margin: 0; }
.grid-section-head span { color: var(--muted); font-size: 13px; font-weight: 650; }
.grid-empty { padding: 48px 24px; }
.grid-empty strong { display: block; color: var(--ink); font-size: 1.05rem; margin-bottom: 6px; }
.grid-empty p { margin: 0 0 16px; }
.grid-empty ol {
    margin: 0 auto; padding: 0; max-width: 36ch; list-style: none; counter-reset: step;
    display: grid; gap: 8px; text-align: left; color: var(--ink-soft); font-size: 14px;
}
.grid-empty li {
    padding: 8px 12px; background: #f8fafc; border: 1px solid var(--line); border-radius: 6px;
    counter-increment: step;
}
.grid-empty li::before {
    content: counter(step); display: inline-flex; align-items: center; justify-content: center;
    width: 20px; height: 20px; margin-right: 8px; border-radius: 50%;
    background: var(--accent); color: #fff; font-size: 11px; font-weight: 700;
}

.mode-tabs { display: flex; gap: 8px; flex-wrap: wrap; margin: -8px 0 18px; }
.mode-tabs button {
    border: 1px solid var(--line-strong); background: #fff; border-radius: var(--radius-sm);
    padding: 8px 14px; cursor: pointer; font-weight: 650; color: var(--ink); font-size: 13px;
}
.mode-tabs button.active, .btn-ghost.is-on {
    background: var(--accent); color: #fff; border-color: var(--accent);
}
.pos-desk { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-bottom: 18px; }
.pos-band {
    margin: -8px 0 14px; padding: 6px 10px; border-radius: 4px;
    background: #f1f5f9; color: var(--accent); font-size: 11px; letter-spacing: .1em;
    text-transform: uppercase; font-weight: 700;
}
.pos-nam { background: linear-gradient(180deg, #f0f9fb, var(--paper) 42%); }
.patient-meta { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 12px 0; }
.patient-meta span { display: block; color: var(--muted); font-size: 12px; font-weight: 600; }
.patient-meta b { display: block; margin-top: 2px; }
.flag-list { display: grid; gap: 8px; margin-top: 12px; }
.act-entry { margin-bottom: 18px; }
.act-entry-row { display: flex; gap: 10px; align-items: flex-end; }
.pos-table input { padding: 8px 10px; border-radius: 6px; }
.act-context { margin-top: 8px; }
.act-context input { background: #f8fafc; }
.act-context .cim-chosen { display: flex; align-items: center; margin-top: 6px; }
.btn-ghost.is-on:hover { color: #fff; }
.total { font-size: 1.5rem; font-variant-numeric: tabular-nums; letter-spacing: -.03em; }
.place-stats { display: flex; gap: 10px; }
.place-stat {
    min-width: 104px; padding: 10px 14px;
    background: var(--paper); border: 1px solid var(--line);
    border-radius: var(--radius); box-shadow: var(--shadow);
}
.place-stat span { display: block; color: var(--muted); font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
.place-stat b { display: block; margin-top: 4px; font-size: 22px; font-variant-numeric: tabular-nums; letter-spacing: -.03em; }
.mode-tabs button em {
    margin-left: 8px; font-style: normal; font-size: 11px; font-weight: 700;
    padding: 1px 6px; border-radius: 999px; background: #f1f5f9; color: var(--muted);
}
.mode-tabs button.active em { background: rgba(255,255,255,.2); color: #fff; }
.place-context {
    display: flex; justify-content: space-between; align-items: center; gap: 16px;
    margin: -6px 0 16px; padding: 14px 18px; border-radius: var(--radius);
    background: linear-gradient(135deg, #0e7490 0%, #0b4f63 100%); color: #fff;
}
.place-context span { display: block; margin-top: 2px; font-size: 13px; opacity: .86; }
.place-context b { font-size: 1.4rem; font-variant-numeric: tabular-nums; letter-spacing: -.03em; }
.place-card-shell { padding: 22px; }
.place-filters {
    display: grid; grid-template-columns: minmax(240px, 1.6fr) 1fr 1fr;
    gap: 14px; margin-bottom: 16px; padding: 16px;
    background: #f8fafc; border: 1px solid var(--line); border-radius: var(--radius);
}
.place-chips { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: -4px 0 16px; }
.place-chips .btn-ghost { padding: 5px 10px; font-size: 12px; }
.place-dir-head {
    display: flex; justify-content: space-between; gap: 12px;
    margin-bottom: 12px; color: var(--muted); font-size: 13px; font-weight: 650;
}
.place-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.place-card {
    display: flex; flex-direction: column; gap: 8px;
    padding: 16px; border: 1px solid var(--line); border-radius: var(--radius);
    background: #fff; min-height: 100%;
}
.place-card.is-legal { border-left: 3px solid var(--accent); }
.place-card.is-ramq { border-left: 3px solid #b54708; }
.place-card:hover { border-color: #b6d4de; box-shadow: 0 0 0 3px rgba(14, 116, 144, .08); }
.place-card-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.place-code-label { display: block; font-size: 10px; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); font-weight: 700; }
.place-code { display: block; margin-top: 2px; font-size: 15px; color: var(--accent); }
.place-name { margin: 0; font-size: 1.02rem; line-height: 1.3; }
.place-aka { margin: 0; color: var(--muted); font-size: 13px; }
.place-where { color: var(--ink-soft); font-size: 13px; }
.place-where p { margin: 0 0 2px; }
.place-where .cim-code { color: var(--muted); margin-left: 6px; font-size: 12px; }
.place-parent { color: var(--muted); }
.place-card-foot {
    display: flex; justify-content: space-between; align-items: flex-end; gap: 10px;
    margin-top: auto; padding-top: 10px; border-top: 1px solid var(--line);
}
.place-missions { display: flex; flex-wrap: wrap; gap: 6px; }
.place-missions .pill { padding: 3px 8px; font-size: 11px; }
.place-region { color: var(--muted); font-size: 12px; font-weight: 700; white-space: nowrap; }
.place-empty { padding: 48px 20px; }
.place-empty strong { display: block; color: var(--ink); margin-bottom: 6px; }
.place-empty p { margin: 0 0 14px; }
.place-source { margin: 18px 0 0; color: var(--muted); font-size: 12px; }
.catalog-card { padding: 22px; }
.catalog-filters-1 { grid-template-columns: 1fr; }
.catalog-filters-2 { grid-template-columns: minmax(240px, 1.6fr) 1fr; }
.catalog-filters-3 { grid-template-columns: 1.4fr 1fr 1fr; }
.dash-alert {
    display: flex; justify-content: space-between; align-items: center; gap: 12px;
    margin-bottom: 16px; padding: 12px 16px;
    background: #fff7ed; border: 1px solid #fed7aa; border-radius: var(--radius);
    color: #9a3412; font-weight: 650;
}
.dash-alert span { font-size: 13px; }
.statement-net {
    display: flex; justify-content: flex-end; align-items: baseline; gap: 12px;
    margin: 16px 0 0;
}
.cim-list { display: grid; gap: 8px; }
.cim-row {
    display: grid; grid-template-columns: 92px minmax(0, 1fr) minmax(140px, .7fr) auto;
    align-items: center; gap: 14px; padding: 12px 14px;
    border: 1px solid var(--line); border-radius: var(--radius); background: #fff;
}
.cim-row:hover { border-color: #b6d4de; box-shadow: 0 0 0 3px rgba(14, 116, 144, .08); }
.cim-row-code { font-size: 16px; color: var(--accent); }
.cim-row-body h3 { margin: 0; font-size: 15px; font-weight: 650; line-height: 1.35; }
.cim-row-body p { margin: 3px 0 0; color: var(--muted); font-size: 13px; }
.cim-row-chapter { color: var(--muted); font-size: 12px; font-weight: 650; line-height: 1.35; }

.statement-head { display: flex; justify-content: space-between; gap: 24px; flex-wrap: wrap; }
.statement-meta { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 18px; min-width: 280px; }
.statement-meta span { display: block; color: var(--muted); font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
.statement-meta b { display: block; margin-top: 2px; font-variant-numeric: tabular-nums; }

@media (max-width: 1100px) {
    .pos-desk { grid-template-columns: 1fr; }
}

@media (max-width: 980px) {
    .app, .guest { grid-template-columns: 1fr; }
    .sidebar { height: auto; position: relative; }
    .cols-2, .cols-3, .cols-4, .form-grid, .aging, .pos-desk, .patient-meta, .place-filters, .place-grid, .catalog-filters-2, .catalog-filters-3, .cim-row { grid-template-columns: 1fr; }
    .main { padding: 20px; }
    .line-row { grid-template-columns: 1fr 1fr; }
}
