/* ============================================================
   Plateforme Digitalsante — Design system back-office
   ============================================================ */
:root {
    /* Charte Seven Assurances : bleu indigo #3E4095 + rouge #EE3137 */
    --bg: #f6f7fb;
    --surface: #ffffff;
    --sidebar: #23244f;
    --sidebar-hover: #2f3168;
    --sidebar-active: #ee3137;
    --sidebar-text: #a7aad0;
    --sidebar-title: #6f72a6;

    --primary: #3e4095;
    --primary-dark: #313270;
    --primary-soft: #ecedf8;

    --accent: #ee3137;
    --accent-dark: #d52026;
    --accent-soft: #fdeaeb;

    --text: #1f2440;
    --text-muted: #6b7089;
    --border: #e7e8f1;
    --border-champ: #c3c7de;
    --border-tableau: #d3d6e6;

    --success: #16a34a;
    --success-soft: #e7f6ec;
    --warning: #d97706;
    --warning-soft: #fdf3e2;
    --danger: #ee3137;
    --danger-soft: #fdeaeb;
    --neutral-soft: #eef0f6;

    --radius: 14px;
    --radius-sm: 9px;
    --shadow-sm: 0 1px 2px rgba(16,25,53,.05);
    --shadow: 0 4px 20px rgba(16,25,53,.07);
    --shadow-lg: 0 12px 40px rgba(16,25,53,.14);
    --sidebar-w: 256px;
}

* { box-sizing: border-box; }

html, body {
    height: 100%;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    margin: 0;
    font-size: 14.5px;
    -webkit-font-smoothing: antialiased;
}

a { text-decoration: none; }

/* ---------- Layout shell ---------- */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
    width: var(--sidebar-w);
    flex-shrink: 0;
    background: var(--sidebar);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
}

.sidebar .brand {
    display: block;
    padding: 18px 18px 14px;
}
.sidebar .brand .logo-chip {
    background: #fff;
    border-radius: 12px;
    padding: 10px 14px;
    display: block;
    box-shadow: 0 4px 14px rgba(0,0,0,.18);
}
.sidebar .brand .logo-chip img { width: 100%; height: auto; display: block; }
.sidebar .brand .tag {
    display: block;
    color: var(--sidebar-text);
    font-size: .72rem;
    letter-spacing: .16em;
    text-transform: uppercase;
    text-align: center;
    margin-top: 9px;
    font-weight: 600;
}

.sidebar-nav { padding: 4px 12px 24px; }

.nav-section {
    font-size: .68rem;
    text-transform: uppercase;
    letter-spacing: .09em;
    color: var(--sidebar-title);
    font-weight: 600;
    padding: 18px 12px 8px;
}

/* ---- Groupes déroulants ---- */
.nav-group { margin-top: 6px; }
.nav-group-header {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 10px 12px 8px;
    font-size: .68rem;
    text-transform: uppercase;
    letter-spacing: .09em;
    color: var(--sidebar-title);
    font-weight: 700;
    transition: color .13s;
}
.nav-group-header:hover { color: #c7cbe8; }
.nav-group-header .chev {
    width: 14px; height: 14px;
    transition: transform .2s ease;
    flex-shrink: 0;
}
.nav-group-items {
    overflow: hidden;
    max-height: 0;
    transition: max-height .25s ease;
}
.nav-group.open > .nav-group-items { max-height: 600px; }
.nav-group.open > .nav-group-header .chev { transform: rotate(180deg); }

.nav-link-item {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 9px 12px;
    color: var(--sidebar-text);
    border-radius: var(--radius-sm);
    font-weight: 500;
    margin-bottom: 2px;
    transition: background .13s, color .13s;
}
.nav-link-item:hover { background: var(--sidebar-hover); color: #fff; }
.nav-link-item.active {
    background: var(--sidebar-active);
    color: #fff;
    box-shadow: 0 6px 16px rgba(37,99,235,.4);
}
.nav-link-item svg { width: 18px; height: 18px; flex-shrink: 0; opacity: .9; }

/* ---- Ce qui attend une décision ---- */
.pastille-alerte {
    margin-left: auto; min-width: 21px; height: 21px; padding: 0 6px;
    display: inline-grid; place-items: center;
    background: var(--accent); color: #fff;
    border-radius: 11px; font-size: .72rem; font-weight: 700;
    box-shadow: 0 0 0 3px rgba(238,49,55,.22);
}
.alerte-attente {
    display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
    background: var(--accent-soft); border: 1.5px solid var(--accent);
    border-radius: var(--radius); padding: 12px 16px; margin-bottom: 12px;
}
.alerte-attente-pastille {
    width: 34px; height: 34px; flex: 0 0 34px;
    display: grid; place-items: center;
    background: var(--accent); color: #fff;
    border-radius: 50%; font-weight: 750;
}
.alerte-attente-texte { flex: 1; min-width: 240px; display: flex; flex-direction: column; gap: 2px; font-size: .88rem; }
.alerte-attente-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---- Fiche d'une demande de prise en charge ---- */
.fiche-demande {
    display: grid; gap: 16px 26px; align-items: start;
    grid-template-columns: 128px repeat(3, minmax(210px, 1fr));
}
.fiche-demande-photo { text-align: center; }
/* Colonnes étroites : le libellé se serre pour laisser la valeur tenir sur une ligne. */
.fiche-demande .detail-list .row-item { grid-template-columns: minmax(80px, 112px) 1fr; gap: 3px 10px; }
.fiche-demande .detail-list dt { font-size: .8rem; }
.fiche-demande-photo img {
    width: 124px; height: 150px; object-fit: cover;
    border-radius: var(--radius); border: 1.5px solid var(--border-champ);
}
.fiche-demande-initiales {
    width: 124px; height: 150px; display: flex; align-items: center; justify-content: center;
    border: 1.5px dashed var(--border-champ); border-radius: var(--radius);
    background: #f1f2f6; font-size: 32px; font-weight: 650; color: var(--text-muted);
}
@media (max-width: 1200px) { .fiche-demande { grid-template-columns: 128px repeat(2, minmax(200px, 1fr)); } }
@media (max-width: 820px) { .fiche-demande { grid-template-columns: 1fr; } .fiche-demande-photo { text-align: left; } }

/* ---- Deux colonnes : le patient à gauche, le travail à droite ----
   Même disposition que le portail prestataire : la fiche du patient reste sous les yeux
   pendant qu'on instruit la demande ou qu'on lit la prestation. */
.dossier-layout {
    display: grid; grid-template-columns: 296px minmax(0, 1fr);
    gap: 12px; align-items: start;
}
.dossier-aside { position: sticky; top: 76px; }
.dossier-corps { min-width: 0; }
.dossier-aside .fiche-photo { display: flex; justify-content: center; margin-bottom: 12px; }
/* Dans une colonne étroite, la valeur passe sous son libellé. */
.dossier-aside .detail-list .row-item { grid-template-columns: 1fr; gap: 1px; }
.dossier-aside .detail-list dt { font-size: .78rem; }
@media (max-width: 1100px) {
    .dossier-layout { grid-template-columns: 1fr; }
    .dossier-aside { position: static; }
}

/* ---------- Main content ---------- */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
    height: 64px;
    background: rgba(255,255,255,.85);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 28px;
    position: sticky;
    top: 0;
    z-index: 20;
}
.topbar .page-title { font-size: 1.15rem; font-weight: 650; letter-spacing: -.01em; }

.user-chip {
    display: flex; align-items: center; gap: 10px;
}
.user-chip .avatar {
    width: 34px; height: 34px; border-radius: 50%;
    background: var(--primary-soft); color: var(--primary);
    display: grid; place-items: center; font-weight: 700; font-size: .85rem;
}
.user-chip .name { font-weight: 600; font-size: .9rem; }
.user-chip .role { font-size: .72rem; color: var(--text-muted); }

.content { padding: 20px; flex: 1; }

/* ---------- Cards ---------- */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}
.card-pad { padding: 14px 16px; }
/* Deux panneaux ne se touchent jamais, que la marge vienne de l'utilitaire .mb-3
   ou de cette règle : les marges verticales adjacentes fusionnent, jamais ne s'ajoutent. */
.card + .card { margin-top: 12px; }

.card-title-row {
    display: flex; align-items: center; justify-content: space-between;
    padding: 11px 16px; border-bottom: 1px solid var(--border);
    font-weight: 650;
}

/* ---------- Stat cards ---------- */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
    gap: 12px;
}
.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px 22px;
    box-shadow: var(--shadow-sm);
    transition: transform .15s, box-shadow .15s;
}
.stat-card:hover { transform: translateY(-3px); box-shadow: var(--shadow); }
.stat-card .stat-icon {
    width: 44px; height: 44px; border-radius: 12px;
    display: grid; place-items: center; margin-bottom: 14px;
}
.stat-card .stat-icon svg { width: 22px; height: 22px; }
.stat-card .stat-value { font-size: 1.9rem; font-weight: 750; letter-spacing: -.02em; line-height: 1; }
.stat-card .stat-label { color: var(--text-muted); font-size: .85rem; margin-top: 6px; font-weight: 500; }

.ic-blue   { background: var(--primary-soft); color: var(--primary); }
.ic-green  { background: #e7f6ec; color: #16a34a; }
.ic-purple { background: #f0ebfe; color: #7c3aed; }
.ic-amber  { background: #fdf3e2; color: #d97706; }
.ic-teal   { background: #e2f7f5; color: #0d9488; }
.ic-rose   { background: var(--accent-soft); color: var(--accent); }

/* ---------- Search bar ---------- */
.toolbar {
    display: flex; align-items: center; justify-content: space-between;
    gap: 16px; margin-bottom: 12px; flex-wrap: wrap;
}
.search-box { position: relative; flex: 1; max-width: 420px; }
.search-box svg {
    position: absolute; left: 13px; top: 50%; transform: translateY(-50%);
    width: 17px; height: 17px; color: var(--text-muted);
}
.search-box input {
    width: 100%;
    padding: 8px 14px 8px 40px;
    border: 1.5px solid var(--border-champ);
    border-radius: 9px;
    background: var(--surface);
    font-size: .9rem;
    transition: border .15s, box-shadow .15s;
}
.search-box input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-soft);
}
.result-count { color: var(--text-muted); font-size: .85rem; font-weight: 500; white-space: nowrap; }

/* ============================================================
   Système de boutons unifié
   Base .btn (géométrie) + variantes de couleur + tailles
   ============================================================ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 18px;
    font-family: inherit;
    font-size: .9rem;
    font-weight: 600;
    line-height: 1.1;
    border-radius: 10px;
    border: 1px solid transparent;
    cursor: pointer;
    text-decoration: none;
    white-space: nowrap;
    transition: background .13s, border .13s, color .13s, box-shadow .13s, transform .05s;
}
.btn:active { transform: translateY(1px); }
.btn:disabled, .btn.disabled { opacity: .55; pointer-events: none; }
.btn svg { width: 18px; height: 18px; flex-shrink: 0; }

/* Variantes de couleur */
.btn-primary {
    background: var(--primary); border-color: var(--primary); color: #fff;
    box-shadow: 0 6px 16px rgba(62,64,149,.30);
}
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); color: #fff; box-shadow: 0 8px 22px rgba(62,64,149,.40); }

.btn-accent {
    background: var(--accent); border-color: var(--accent); color: #fff;
    box-shadow: 0 6px 16px rgba(238,49,55,.30);
}
.btn-accent:hover { background: var(--accent-dark); border-color: var(--accent-dark); color: #fff; box-shadow: 0 8px 22px rgba(238,49,55,.40); }

.btn-ghost {
    background: var(--surface); border-color: var(--border); color: var(--text);
}
.btn-ghost:hover { background: var(--neutral-soft); color: var(--text); border-color: var(--border); }

/* Tailles */
.btn-sm { padding: 6px 12px; font-size: .82rem; border-radius: 8px; }
.btn-sm svg { width: 15px; height: 15px; }
.btn-lg { padding: 13px 22px; font-size: 1rem; border-radius: 11px; }
.btn-block { width: 100%; }

.page-head {
    display: flex; align-items: center; justify-content: space-between;
    gap: 16px; margin-bottom: 12px;
}
.page-head h2 { margin: 0; font-size: 1.15rem; font-weight: 650; }

/* ---------- Tables ---------- */
.data-table { width: 100%; border-collapse: collapse; }
.data-table thead th {
    text-align: left;
    font-size: .74rem;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--text-muted);
    font-weight: 600;
    padding: 7px 12px;
    /* Filets de tableau plus soutenus que ceux des panneaux : les lignes se comptent. */
    border-bottom: 1.5px solid var(--border-tableau);
    background: #f6f7fb;
    white-space: nowrap;
}
.data-table tbody td {
    padding: 8px 12px;
    border-bottom: 1px solid var(--border-tableau);
    vertical-align: middle;
}
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tfoot td { border-top: 1.5px solid var(--border-tableau); padding: 8px 12px; }
.data-table tbody tr { transition: background .1s; }
.data-table tbody tr:hover { background: #f8faff; }
.data-table .num { text-align: right; font-variant-numeric: tabular-nums; }
/* Un montant ne se coupe jamais en deux lignes : il reste d'un bloc, cale a droite. */
.data-table th.num, .data-table td.num { white-space: nowrap; }
.data-table .strong { font-weight: 600; }
/* « strong » n'existait que dans les tableaux : une valeur mise en avant ailleurs — le cumul
   d'un dossier, un montant de fiche — ne changeait pas d'épaisseur. */
.strong { font-weight: 650; }
.detail-list dd.strong { font-weight: 700; }
.table-wrap { overflow-x: auto; }

/* ---------- Badges ---------- */
.badge-pill {
    display: inline-flex; align-items: center; gap: 5px;
    padding: 4px 10px; border-radius: 100px;
    font-size: .74rem; font-weight: 600; line-height: 1;
}
.badge-pill::before { content: ''; 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(--neutral-soft); color: var(--text-muted); }

/* ---------- Definition lists (details) ---------- */
.detail-list { display: grid; grid-template-columns: 1fr; gap: 0; }
/* La valeur se lit juste apres son libelle : rejetee au bord oppose, l'oeil doit
   traverser toute la fiche pour rapprocher les deux. Les montants des tableaux,
   eux, restent alignes a droite : c'est la colonne qui se lit, pas la ligne. */
.detail-list .row-item {
    display: grid; grid-template-columns: minmax(100px, 190px) 1fr; gap: 4px 14px;
    align-items: baseline;
    padding: 6px 0; border-bottom: 1px dashed var(--border);
}
.detail-list .row-item:last-child { border-bottom: none; }
.detail-list dt { color: var(--text-muted); font-weight: 500; }
.detail-list dd { margin: 0; font-weight: 550; text-align: left; }

/* ---------- Pagination ---------- */
.pager { display: flex; gap: 6px; margin-top: 20px; flex-wrap: wrap; }
.pager a {
    min-width: 36px; height: 36px; padding: 0 10px;
    display: grid; place-items: center;
    border: 1px solid var(--border); border-radius: 9px;
    color: var(--text); font-weight: 550; font-size: .85rem;
    transition: background .12s, border .12s;
}
.pager a:hover { background: var(--neutral-soft); }
.pager a.active { background: var(--primary); border-color: var(--primary); color: #fff; }

/* ---------- Login ---------- */
.login-wrap {
    min-height: 100vh;
    display: grid; place-items: center;
    background: radial-gradient(1100px 600px at 15% -10%, #3e4095 0%, transparent 55%),
                radial-gradient(900px 520px at 110% 115%, #ee3137 0%, transparent 48%),
                #1a1b3d;
    padding: 20px;
}
.login-card {
    width: 100%; max-width: 580px;
    background: var(--surface);
    border-radius: 22px;
    box-shadow: var(--shadow-lg);
    padding: 60px 64px 64px;
}
.login-card .login-logo { display: block; width: 300px; max-width: 80%; margin: 4px auto 28px; }
.login-card h1 { font-size: 1.4rem; text-align: center; margin: 0 0 32px; font-weight: 700; }
.login-card .subtitle { text-align: center; color: var(--text-muted); margin-bottom: 26px; font-size: .9rem; }
.form-field { margin-bottom: 18px; }
.form-field label { display: block; font-weight: 550; font-size: .82rem; margin-bottom: 7px; }
.form-field input {
    width: 100%; padding: 11px 14px;
    border: 1px solid var(--border); border-radius: 10px; font-size: .95rem;
    transition: border .15s, box-shadow .15s;
}
.form-field input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.alert-error {
    background: var(--danger-soft); color: var(--danger);
    padding: 10px 14px; border-radius: 10px; font-size: .85rem; margin-bottom: 18px; font-weight: 500;
}

/* ---------- Forms (content area) ---------- */
.form-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px 16px;
}
@media (min-width: 1100px) { .form-grid { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 700px) { .form-grid { grid-template-columns: 1fr; } }
.form-grid .full { grid-column: 1 / -1; }
.field label {
    display: block; font-weight: 650; font-size: .82rem; margin-bottom: 4px; color: var(--text);
}
.field label .req { color: var(--accent); margin-left: 2px; }
.field input, .field select, .field textarea {
    width: 100%;
    padding: 8px 12px;
    /* Champs franchement dessinés : le filet des panneaux est trop léger pour une saisie. */
    border: 1.5px solid var(--border-champ);
    border-radius: 9px;
    background: var(--surface);
    font-size: .9rem;
    font-family: inherit;
    color: var(--text);
    transition: border .15s, box-shadow .15s;
}
.field input:focus, .field select:focus, .field textarea:focus {
    outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft);
}
.field .field-error { color: var(--accent); font-size: .78rem; margin-top: 5px; }

/* ---- Select2 aligné sur la charte ---- */
.select2-container .select2-selection--single {
    height: 38px;
    border: 1.5px solid var(--border-champ);
    border-radius: 9px;
    display: flex;
    align-items: center;
    background: var(--surface);
}
.select2-container--default .select2-selection--single .select2-selection__rendered {
    line-height: normal;
    padding-left: 13px;
    color: var(--text);
    font-size: .9rem;
}
.select2-container--default .select2-selection--single .select2-selection__arrow {
    height: 36px;
}
.select2-container--default .select2-selection--single .select2-selection__placeholder {
    color: var(--text-muted);
}
.select2-container--default.select2-container--focus .select2-selection--single,
.select2-container--default.select2-container--open .select2-selection--single {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-soft);
}
.select2-dropdown {
    border-color: var(--border);
    border-radius: 10px;
    box-shadow: var(--shadow);
    overflow: hidden;
}
.select2-container--default .select2-search--dropdown .select2-search__field {
    border: 1.5px solid var(--border-champ);
    border-radius: 8px;
    padding: 8px 10px;
    font-size: .88rem;
}
.select2-container--default .select2-search--dropdown .select2-search__field:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-soft);
}
.select2-container--default .select2-results__option {
    font-size: .88rem;
    padding: 8px 12px;
}
.select2-container--default .select2-results__option--highlighted[aria-selected] {
    background: var(--primary);
}
.select2-container--default .select2-results__option[aria-selected=true] {
    background: var(--primary-soft);
    color: var(--primary);
}
.field input.input-invalid, .field select.input-invalid { border-color: var(--accent); }
.form-section-title {
    font-weight: 650; font-size: .95rem; margin: 6px 0 2px;
    grid-column: 1 / -1; color: var(--text);
}
.form-actions {
    display: flex; gap: 12px; margin-top: 24px; padding-top: 20px; border-top: 1px solid var(--border);
}

/* ---------- Flash message ---------- */
.flash {
    display: flex; align-items: center; gap: 10px;
    padding: 12px 16px; border-radius: 10px; margin-bottom: 18px; font-weight: 550; font-size: .9rem;
}
.flash-success { background: var(--success-soft); color: var(--success); }
.flash-error { background: var(--danger-soft); color: var(--danger); }

/* ---------- Detail grid ---------- */
.detail-grid { display: grid; grid-template-columns: 5fr 7fr; gap: 22px; align-items: start; }
.detail-grid.even { grid-template-columns: 1fr 1fr; }
@media (max-width: 900px) { .detail-grid, .detail-grid.even { grid-template-columns: 1fr; } }

/* ---------- Minimal utilities ---------- */
.d-flex { display: flex; }
.align-items-center { align-items: center; }
.gap-2 { gap: 10px; }
.ms-2 { margin-left: 10px; }
.mt-3 { margin-top: 12px; }
.mb-3 { margin-bottom: 12px; }
.mb-0 { margin-bottom: 0; }
.d-inline-block { display: inline-block; }
.text-muted { color: var(--text-muted); }
@media (min-width: 640px) { .d-sm-block { display: block !important; } }
@media (max-width: 639px) { .d-sm-block { display: none; } }
@media (max-width: 860px) { .d-md-none { display: inline-flex; } }
@media (min-width: 861px) { .d-md-none { display: none; } }

/* ---------- Responsive ---------- */
@media (max-width: 860px) {
    .sidebar { position: fixed; left: -100%; z-index: 100; transition: left .2s; box-shadow: var(--shadow-lg); }
    .sidebar.open { left: 0; }
    .content { padding: 18px; }
}

/* Jauge horizontale (répartitions du module DJOLY) */
.jauge { height: 7px; border-radius: 4px; background: var(--neutral-soft); overflow: hidden; }
.jauge > span { display: block; height: 100%; background: var(--primary); border-radius: 4px; }
@media (max-width: 820px) { .grid-2 { grid-template-columns: 1fr !important; } }
