:root {
  --navy: #12305a;
  --navy-2: #0c2242;
  --gold: #a87b26;
  --bg: #f3f5f9;
  --bs-primary: #12305a;
  --bs-primary-rgb: 18, 48, 90;
  --bs-link-color: #1d4f91;
  --bs-link-color-rgb: 29, 79, 145;
  --bs-body-font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  /* Graphiques : couleur de série validée (bande de luminosité, chroma, contraste ≥ 3:1 sur blanc) */
  --series-1: #1d4f91;
  --viz-grid: #e9ecf1;
  --viz-axis: #c3c9d4;
  --ink-muted: #6b7280;
}
body { background: var(--bg); font-size: .925rem; }

.btn-primary { --bs-btn-bg: var(--navy); --bs-btn-border-color: var(--navy); --bs-btn-hover-bg: var(--navy-2); --bs-btn-hover-border-color: var(--navy-2); --bs-btn-active-bg: var(--navy-2); --bs-btn-disabled-bg: var(--navy); }
.btn-outline-primary { --bs-btn-color: var(--navy); --bs-btn-border-color: var(--navy); --bs-btn-hover-bg: var(--navy); --bs-btn-hover-border-color: var(--navy); --bs-btn-active-bg: var(--navy); --bs-btn-active-border-color: var(--navy); }
.progress-bar { background: var(--series-1); }
.page-link { color: var(--navy); }
.active > .page-link { background: var(--navy); border-color: var(--navy); }
.form-check-input:checked { background-color: var(--navy); border-color: var(--navy); }

/* Layout */
.app { display: flex; min-height: 100vh; }
.sidebar { width: 250px; flex-shrink: 0; background: linear-gradient(180deg, var(--navy) 0%, var(--navy-2) 100%); color: #fff;
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow-y: auto; z-index: 1040; }
.brand { display: flex; align-items: center; gap: .7rem; padding: 1.2rem 1.1rem; color: #fff; text-decoration: none; border-bottom: 1px solid rgba(255,255,255,.08); }
.brand small { display: block; font-size: .72rem; opacity: .7; }
.brand-mark { display: inline-grid; place-items: center; width: 38px; height: 38px; border-radius: 10px; background: var(--gold); color: #fff; font-weight: 800; font-size: 1.15rem; font-family: Georgia, serif; }
.brand-mark.lg { width: 56px; height: 56px; font-size: 1.6rem; border-radius: 14px; }
.sidebar .nav { padding: .8rem .6rem; gap: 2px; flex: 1; }
.sidebar .nav-link { color: rgba(255,255,255,.78); border-radius: 8px; padding: .5rem .75rem; display: flex; gap: .65rem; align-items: center; font-size: .9rem; }
.sidebar .nav-link:hover { background: rgba(255,255,255,.07); color: #fff; }
.sidebar .nav-link.active { background: rgba(255,255,255,.13); color: #fff; box-shadow: inset 3px 0 0 var(--gold); }
.nav-section { text-transform: uppercase; font-size: .68rem; letter-spacing: .08em; opacity: .5; padding: 1rem .75rem .3rem; }
.sidebar-user { padding: 1rem; border-top: 1px solid rgba(255,255,255,.08); }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: rgba(255,255,255,.15); display: inline-grid; place-items: center; font-weight: 700; }
.main { flex: 1; min-width: 0; }
.content { padding: 1.75rem; max-width: 1500px; }
.topbar { display: flex; gap: .75rem; align-items: center; padding: .6rem 1rem; background: #fff; border-bottom: 1px solid #e3e7ee; position: sticky; top: 0; z-index: 1030; }

@media (max-width: 991.98px) {
  .sidebar { position: fixed; left: 0; transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.3); }
  .content { padding: 1rem; }
}

.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.5rem; }
.page-head h1 { font-size: 1.45rem; font-weight: 700; color: var(--navy); margin-bottom: .2rem; }

.card { border: 1px solid #e3e7ee; border-radius: 12px; box-shadow: 0 1px 2px rgba(16,24,40,.04); }
.card-header { background: #fff; font-weight: 600; color: var(--navy); border-bottom: 1px solid #edf0f5; padding: .8rem 1.1rem; border-radius: 12px 12px 0 0 !important; }
.table > :not(caption) > * > * { padding: .6rem .9rem; }
.table thead th { font-size: .74rem; text-transform: uppercase; letter-spacing: .04em; color: #6b7280; font-weight: 600; background: #f8f9fb; }
.row-link { cursor: pointer; }

/* Stats */
.stat { display: flex; flex-direction: column; background: #fff; border: 1px solid #e3e7ee; border-radius: 12px; padding: 1rem 1.1rem; text-decoration: none; color: inherit; height: 100%; transition: border-color .15s, transform .15s; }
.stat:hover { border-color: var(--navy); transform: translateY(-1px); }
.stat i { color: var(--gold); font-size: 1.2rem; }
.stat-n { font-size: 1.8rem; font-weight: 700; color: var(--navy); line-height: 1.2; margin-top: .3rem; font-variant-numeric: tabular-nums; }
.stat-l { font-size: .8rem; color: #6b7280; }

/* Formulaire attestation */
.step { display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; background: var(--navy); color: #fff; font-size: .78rem; margin-right: .4rem; }
.form-label { font-weight: 500; margin-bottom: .3rem; }
.form-label.req::after { content: " *"; color: #c0392b; }
.opt { font-weight: 400; color: #8a94a6; font-size: .8em; }
.type-switch { display: flex; gap: .5rem; flex-wrap: wrap; }
.type-switch .btn { padding: .55rem 1.1rem; }
.services-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: .5rem; }
.service-item { border: 1px solid #e3e7ee; border-radius: 8px; padding: .5rem .7rem; transition: background .15s, border-color .15s; }
.service-item.checked { background: #eef3fa; border-color: #b5c6de; }
.service-item .form-check { margin: 0; }
.innovation-box { background: #fbf7ee; border: 1px solid #ead9b5; border-radius: 8px; padding: .8rem 1rem; }
.number-display { font-size: 1.5rem; font-weight: 700; color: var(--navy); text-align: center; background: #f4f7fb; border: 1px dashed #b5c6de; border-radius: 8px; padding: .5rem; font-variant-numeric: tabular-nums; }
.actions-card { border-color: #c9d3e3; }
.preview-frame { width: 100%; height: 80vh; min-height: 600px; border: 0; display: block; background: #e9edf3; border-radius: 0 0 12px 12px; }
.modal .preview-frame { border-radius: 0; }
.info-list dt { font-weight: 500; color: #6b7280; }
.info-list dd { margin-bottom: .4rem; }
.sticky-save { position: sticky; bottom: 0; background: linear-gradient(transparent, var(--bg) 30%); padding: 1rem 0; }

.stamp-option { border: 1px solid #e3e7ee; border-radius: 8px; padding: .7rem 1rem; }
#id_doc_number::placeholder { text-transform: none; }
.settings-thumb { max-height: 56px; max-width: 160px; object-fit: contain; background: #f4f7fb; border-radius: 6px; padding: 4px; }

/* Reprise d'un bénéficiaire existant */
.reuse-box { background: #f4f7fb; border: 1px dashed #b5c6de; border-radius: 8px; padding: .6rem .8rem; }
.reuse-results { position: absolute; top: calc(100% + 4px); left: 0; right: 0; z-index: 20; max-height: 320px; overflow-y: auto; }

/* Recherche rapide (barre latérale) */
.sidebar-search { position: relative; margin: .8rem .9rem 0; }
.sidebar-search i { position: absolute; left: .7rem; top: 50%; transform: translateY(-50%); color: rgba(255,255,255,.55); font-size: .85rem; }
.sidebar-search input { width: 100%; border: 1px solid rgba(255,255,255,.14); background: rgba(255,255,255,.08); color: #fff; border-radius: 8px; padding: .4rem .6rem .4rem 2rem; font-size: .85rem; }
.sidebar-search input::placeholder { color: rgba(255,255,255,.5); }
.sidebar-search input:focus { outline: 2px solid var(--gold); outline-offset: 1px; background: rgba(255,255,255,.14); }

/* Vérification */
.verify-code-badge { font-family: var(--bs-font-monospace); font-weight: 700; letter-spacing: .06em; color: var(--navy); background: #f4f7fb; border: 1px solid #c9d3e3; border-radius: 6px; padding: .2rem .5rem; }

/* Graphique mensuel (tableau de bord) */
.viz { margin: 0; }
.viz-sub { font-weight: 400; font-size: .8rem; color: var(--ink-muted); }
.viz-plot { position: relative; height: 200px; margin-left: 2rem; margin-top: 1.2rem; }
.viz-grid { position: absolute; inset: 0; pointer-events: none; }
.viz-gridline { position: absolute; left: 0; right: 0; border-top: 1px solid var(--viz-grid); }
.viz-gridline.base { border-top-color: var(--viz-axis); }
.viz-gridline span { position: absolute; right: calc(100% + .5rem); top: -.55rem; font-size: .72rem; color: var(--ink-muted); font-variant-numeric: tabular-nums; }
.viz-cols { position: absolute; inset: 0; display: flex; }
.viz-col { flex: 1; position: relative; display: flex; justify-content: center; align-items: flex-end; cursor: default; border-radius: 6px; outline: none; }
.viz-col:hover, .viz-col.active { background: rgba(29, 79, 145, .05); }
.viz-col:focus-visible { box-shadow: inset 0 0 0 2px var(--series-1); }
.viz-bar { display: block; width: min(24px, 60%); background: var(--series-1); border-radius: 4px 4px 0 0; transition: opacity .15s; }
.viz-col:hover .viz-bar, .viz-col.active .viz-bar { opacity: .82; }
.viz-cap { position: absolute; left: 0; right: 0; text-align: center; margin-bottom: 3px; font-size: .75rem; font-weight: 600; color: #1d2433; }
.viz-x { display: flex; margin-left: 2rem; margin-top: .4rem; }
.viz-x span { flex: 1; text-align: center; font-size: .72rem; color: var(--ink-muted); line-height: 1.15; }
.viz-x small { font-size: .68rem; }
.viz-table summary { color: var(--bs-link-color); cursor: pointer; width: max-content; }
.viz-tooltip { position: fixed; z-index: 1080; pointer-events: none; background: #fff; border: 1px solid #dfe3ea; border-radius: 8px; box-shadow: 0 6px 20px rgba(16,24,40,.12); padding: .45rem .7rem; display: grid; grid-template-columns: auto 1fr; column-gap: .45rem; align-items: center; }
.viz-tooltip[hidden] { display: none; }
.viz-tip-key { width: 12px; height: 2px; background: var(--series-1); grid-row: span 2; }
.viz-tip-value { font-size: .9rem; color: #1d2433; }
.viz-tip-label { font-size: .75rem; color: var(--ink-muted); grid-column: 2; }
@media (min-width: 1200px) {
  .viz-plot { height: 280px; }
}
@media (max-width: 575.98px) {
  .viz-x span { font-size: .62rem; }
  .viz-x small { font-size: .58rem; }
}

/* Connexion et pages publiques */
body.guest { min-height: 100vh; display: grid; place-items: center; background: radial-gradient(circle at 20% 10%, #1d4f91 0%, var(--navy) 45%, var(--navy-2) 100%); padding: 1rem; }
.guest-card { background: #fff; border-radius: 16px; padding: 2rem; width: 100%; max-width: 420px; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.guest-card.wide { max-width: 560px; }
.guest-logo { max-height: 64px; max-width: 200px; object-fit: contain; }
.captcha-row { display: flex; align-items: center; gap: .5rem; }
.captcha-img { border: 1px solid #dfe3ea; border-radius: 8px; max-width: calc(100% - 3rem); height: auto; background: #f6f8fc; }
.captcha-refresh { height: 44px; width: 44px; display: grid; place-items: center; }
.captcha-input { text-transform: uppercase; letter-spacing: .2em; font-family: var(--bs-font-monospace); }
.captcha-input::placeholder { text-transform: none; letter-spacing: normal; font-family: var(--bs-body-font-family); }
.verify-result { display: flex; gap: .9rem; align-items: center; border-radius: 12px; padding: 1rem 1.1rem; margin-bottom: 1rem; }
.verify-result.valid { background: #ecf7ef; border: 1px solid #b7dfc2; color: #11532a; }
.verify-result.archived { background: #f1f4f8; border: 1px solid #cfd8e3; color: #2b3a4f; }
.verify-icon { font-size: 2rem; line-height: 1; }
.verify-title { font-weight: 700; font-size: 1.05rem; }
.verify-details { display: grid; grid-template-columns: max-content 1fr; gap: .35rem 1rem; font-size: .9rem; margin-bottom: 1rem; }
.verify-details dt { color: var(--ink-muted); font-weight: 500; }
.verify-details dd { margin: 0; }
.verify-input { letter-spacing: .15em; text-transform: uppercase; }
.verify-input::placeholder { letter-spacing: .1em; }
