/* ChildVitalStats — thème
   Un code couleur unique par indicateur, partout (chiffres, graphiques, carte) :
   naissances = bleu, décès = prune, vaccinations = vert. */
:root {
  --ink: #16324f;
  --ink-2: #24486d;
  --paper: #f4f7f9;
  --line: #dde4ea;
  --muted: #5d6b78;
  --birth: #2563a8;
  --death: #7a2e4a;
  --vacc: #1f8a62;
  --warn: #b7741a;
  --late: #b4372f;
  --radius: 5px;

  --bs-body-font-family: "Public Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --bs-body-bg: var(--paper);
  --bs-body-color: #1d2a36;
  --bs-primary: var(--ink);
  --bs-primary-rgb: 22, 50, 79;
  --bs-link-color: var(--birth);
  --bs-link-color-rgb: 37, 99, 168;
  --bs-border-color: var(--line);
}

body { font-feature-settings: "tnum" 1; }
h1, h2, h3, h4, h5 { color: var(--ink); font-weight: 700; letter-spacing: -0.01em; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.15rem; }
.req { color: var(--late); }

.btn-primary { --bs-btn-bg: var(--ink); --bs-btn-border-color: var(--ink); --bs-btn-hover-bg: var(--ink-2); --bs-btn-hover-border-color: var(--ink-2); --bs-btn-active-bg: var(--ink-2); }
.btn-outline-primary { --bs-btn-color: var(--ink); --bs-btn-border-color: var(--ink); --bs-btn-hover-bg: var(--ink); --bs-btn-hover-border-color: var(--ink); }
.btn-vacc { --bs-btn-color: #fff; --bs-btn-bg: var(--vacc); --bs-btn-border-color: var(--vacc); --bs-btn-hover-color: #fff; --bs-btn-hover-bg: #187251; --bs-btn-hover-border-color: #187251; }
:focus-visible { outline: 3px solid #f2b84b; outline-offset: 2px; }

/* --- Mise en page --- */
.app { display: flex; min-height: 100vh; min-height: 100dvh; }
.sidebar {
  width: 252px; flex-shrink: 0; background: var(--ink); color: #c9d6e2;
  position: sticky; top: 0; height: 100vh; height: 100dvh;
  display: flex; flex-direction: column; padding: 1.1rem .75rem .75rem;
}
.sidebar-top { display: flex; align-items: center; justify-content: space-between; padding-bottom: .5rem; }
/* Zone défilante du menu : barre fine, discrète, assortie au fond */
.sidebar-scroll {
  flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain;
  margin-right: -.4rem; padding-right: .4rem;
  scrollbar-width: thin; scrollbar-color: transparent transparent;
  mask-image: linear-gradient(to bottom, transparent 0, #000 12px, #000 calc(100% - 18px), transparent 100%);
  padding-top: 10%;
  padding-bottom: 10%;
}
.sidebar-scroll:hover, .sidebar-scroll:focus-within { scrollbar-color: rgba(255,255,255,.28) transparent; }
.sidebar-scroll::-webkit-scrollbar { width: 6px; }
.sidebar-scroll::-webkit-scrollbar-track { background: transparent; }
.sidebar-scroll::-webkit-scrollbar-thumb { background: transparent; border-radius: 6px; }
.sidebar-scroll:hover::-webkit-scrollbar-thumb { background: rgba(255,255,255,.22); }
.sidebar-scroll::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,.4); }
.sidebar-close { background: transparent; border: 0; color: #d6e1eb; font-size: 1.2rem; width: 40px; height: 40px; border-radius: 8px; }
.sidebar-close:hover { background: rgba(255,255,255,.08); }
.sidebar-user { display: flex; align-items: center; gap: .6rem; border-top: 1px solid rgba(255,255,255,.12); padding-top: .75rem; margin-top: .5rem; }
.sidebar-user .who-m { color: #fff; text-decoration: none; font-weight: 600; font-size: .9rem; line-height: 1.2; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.sidebar-user .who-m small { display: block; color: #8ea4b9; font-weight: 400; }

.brand { display: flex; align-items: center; gap: .6rem; color: #fff; text-decoration: none; padding: 0 .5rem; }
.brand-mark { display: inline-grid; grid-template-columns: repeat(3, 6px); gap: 3px; }
.brand-mark i { display: block; width: 6px; height: 22px; border-radius: 3px; }
.brand-mark i:nth-child(1) { background: #6ea6e6; }
.brand-mark i:nth-child(2) { background: #c97b9a; height: 16px; align-self: end; }
.brand-mark i:nth-child(3) { background: #5ccf9d; height: 28px; align-self: end; }
.brand strong { font-size: 1.05rem; letter-spacing: -0.01em; }
.brand-compact { color: var(--ink); padding: 0; }
.brand-compact .brand-mark i { height: 16px; }
.brand-compact .brand-mark i:nth-child(2) { height: 11px; }
.brand-compact .brand-mark i:nth-child(3) { height: 20px; }

.nav-group { font-size: .78rem; color: #8ea4b9; margin: 1.1rem .6rem .35rem; }
.sidebar .nav-link { color: #d6e1eb; border-radius: 8px; padding: .5rem .6rem; display: flex; gap: .6rem; align-items: center; font-size: .94rem; }
.sidebar .nav-link:hover { background: rgba(255,255,255,.07); color: #fff; }
.sidebar .nav-link.active { background: #fff; color: var(--ink); font-weight: 600; }

.avatar { width: 36px; height: 36px; flex-shrink: 0; border-radius: 50%; display: inline-grid; place-items: center;
          background: #2f6fb3; color: #fff; font-weight: 700; font-size: .85rem; text-decoration: none; }
.avatar-top { margin-left: auto; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 1rem; padding: .75rem 1.5rem; background: #fff; border-bottom: 1px solid var(--line);
          position: sticky; top: 0; z-index: 1020; }
.topbar .who { margin-left: auto; text-align: right; line-height: 1.2; font-size: .9rem; }
.topbar .who small { color: var(--muted); }
.content { padding: 1.5rem; max-width: 1400px; width: 100%; }
.page-head { display: flex; flex-wrap: wrap; align-items: end; gap: .75rem 1rem; margin-bottom: 1.25rem; }
.page-head h1 { margin: 0; }
.page-head .sub { color: var(--muted); margin: .2rem 0 0; }
.page-head .actions { margin-left: auto; display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }

.sidebar-backdrop { position: fixed; inset: 0; background: rgba(10, 25, 40, .45); z-index: 1039; }
.bottom-nav { display: none; }

/* --- Surfaces --- */
.panel { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); }
.panel-head { display: flex; align-items: center; gap: .75rem; padding: .85rem 1.1rem; border-bottom: 1px solid var(--line); }
.panel-head h2 { margin: 0; font-size: 1rem; }
.panel-body { padding: 1.1rem; }
.filters { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: .85rem 1rem; margin-bottom: 1rem; }
.filters .form-label { font-size: .8rem; color: var(--muted); margin-bottom: .2rem; }

.table { --bs-table-bg: transparent; margin: 0; }
.table thead th { font-size: .8rem; color: var(--muted); font-weight: 600; background: #f8fafb; border-bottom-width: 1px; white-space: nowrap; }
.table td { vertical-align: middle; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table-wrap { overflow-x: auto; }
.empty { padding: 2.5rem 1rem; text-align: center; color: var(--muted); }

/* --- DataTables (intégration au thème) --- */
.panel > .dt-container, .panel > form > .dt-container, .table-wrap > .dt-container { padding: .85rem 1rem .6rem; }
.panel .panel-head + .dt-container { padding-top: .75rem; }
.dt-container .dt-layout-row { margin: .35rem 0; }
.dt-container .dt-layout-table { margin: .5rem -1rem; }
.dt-container .dt-search input { min-width: 240px; margin-left: 0; }
.dt-container .dt-length select { margin-right: .35rem; }
.dt-container .dt-info { color: var(--muted); font-size: .85rem; }
.dt-container .dt-buttons { gap: .35rem; display: inline-flex; flex-wrap: wrap; margin-left: .5rem; }
.dt-container .dt-buttons .btn { border-radius: 6px !important; }
.dt-container .pagination { margin: 0; }
.dt-container .page-link { color: var(--ink); }
.dt-container .active > .page-link { background: var(--ink); border-color: var(--ink); color: #fff; }
table.dataTable { margin: 0 !important; }
/* Taille de texte des tableaux : plus compacte que le corps de page */
.panel table.table, table.dataTable { font-size: .8125rem; line-height: 1.35; }
table.dataTable > tbody > tr > td, .panel table.table > tbody > tr > td { padding: .45rem .6rem; }
table.dataTable > thead > tr > th, .panel table.table > thead > tr > th { padding: .5rem .6rem; font-size: .75rem; }
table.dataTable td small, .panel table.table td small { font-size: .72rem; }
table.dataTable .pill, .panel table.table .pill { font-size: .7rem; padding: .1rem .45rem; }
table.dataTable .btn-sm, .panel table.table .btn-sm { --bs-btn-padding-y: .15rem; --bs-btn-padding-x: .4rem; --bs-btn-font-size: .75rem; }
table.dataTable > tbody > tr.child ul.dtr-details > li { font-size: .8125rem; padding: .35rem 0; }
.dt-container .dt-info, .dt-container .dt-length, .dt-container .dt-search input, .dt-container .dt-length select { font-size: .8125rem; }
.dt-container .pagination { --bs-pagination-font-size: .8125rem; --bs-pagination-padding-x: .6rem; --bs-pagination-padding-y: .25rem; }
.dt-container .dt-buttons .btn { font-size: .75rem; padding: .2rem .55rem; }
table.dataTable > thead > tr > th { font-size: .8rem; color: var(--muted); font-weight: 600; background: #f8fafb; }
table.dataTable > tbody > tr > td:first-child, table.dataTable > thead > tr > th:first-child { padding-left: 1rem; }
table.dataTable > tbody > tr > td:last-child, table.dataTable > thead > tr > th:last-child { padding-right: 1rem; }
div.dt-processing { background: #fff; border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 6px 20px rgba(22, 50, 79, .1); color: var(--ink); }
div.dt-processing > div:last-child > div { background: var(--vacc); }
table.dataTable.dtr-inline.collapsed > tbody > tr > td.dtr-control::before { border-left-color: var(--ink); }
table.dataTable > tbody > tr.child ul.dtr-details { width: 100%; }
table.dataTable > tbody > tr.child ul.dtr-details > li { display: flex; justify-content: space-between; gap: 1rem; }
table.dataTable > tbody > tr.child span.dtr-title { color: var(--muted); font-weight: 600; min-width: auto; }
table.dataTable td.dt-empty { color: var(--muted); padding: 2rem 1rem; }

/* --- Indicateurs --- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 1rem; margin-bottom: 1.25rem; }
.kpi { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.1rem; border-top: 4px solid var(--c, var(--ink)); }
.kpi .v { font-size: 2rem; font-weight: 700; color: var(--c, var(--ink)); line-height: 1.1; }
.kpi .l { font-weight: 600; color: var(--ink); }
.kpi .s { color: var(--muted); font-size: .85rem; margin-top: .25rem; }
.c-birth { --c: var(--birth); }
.c-death { --c: var(--death); }
.c-vacc { --c: var(--vacc); }
.c-warn { --c: var(--warn); }
.c-late { --c: var(--late); }

.pill { display: inline-flex; align-items: center; gap: .3rem; font-size: .78rem; font-weight: 600; padding: .15rem .55rem; border-radius: 999px; background: #eef2f5; color: var(--ink); white-space: nowrap; }
.pill.done, .pill.ok, .pill.alive, .pill.sent { background: #e2f3ea; color: #146446; }
.pill.late, .pill.expired, .pill.failed, .pill.deceased { background: #f8e3e1; color: #8e2a23; }
.pill.due, .pill.expiring, .pill.low, .pill.pending { background: #fbefd9; color: #7e4f0c; }
.pill.upcoming, .pill.transferred { background: #e3edf8; color: #1f4f86; }
.pill.na, .pill.cancelled, .pill.empty { background: #eceff2; color: #5d6b78; }

/* --- Carnet de vaccination --- */
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: .6rem; }
.dose { border: 1px solid var(--line); border-radius: 8px; padding: .6rem .7rem; background: #fff; border-left: 4px solid #c3ccd5; }
.dose.done { border-left-color: var(--vacc); }
.dose.late { border-left-color: var(--late); background: #fffafa; }
.dose.due { border-left-color: var(--warn); }
.dose .t { font-weight: 700; color: var(--ink); }
.dose .d { font-size: .82rem; color: var(--muted); }

dl.facts { display: grid; grid-template-columns: max-content 1fr; gap: .35rem 1rem; margin: 0; }
dl.facts dt { color: var(--muted); font-weight: 500; }
dl.facts dd { margin: 0; }

/* --- Carte --- */
.map-shell { display: grid; grid-template-columns: 1fr 340px; gap: 1rem; }
@media (max-width: 1199.98px) { .map-shell { grid-template-columns: 1fr; } }
#map, .mini-map { height: calc(100vh - 290px); min-height: 460px; border-radius: var(--radius); border: 1px solid var(--line); }
.mini-map { height: 420px; min-height: 0; }
.indicator-switch { display: flex; flex-wrap: wrap; gap: .4rem; }
.indicator-switch input { position: absolute; opacity: 0; pointer-events: none; }
.indicator-switch label { cursor: pointer; border: 1px solid var(--line); border-radius: 999px; padding: .35rem .8rem; font-weight: 600; font-size: .88rem; background: #fff; color: var(--ink); display: inline-flex; gap: .4rem; align-items: center; }
.indicator-switch label::before { content: ""; width: 10px; height: 10px; border-radius: 50%; background: var(--c); }
.indicator-switch input:checked + label { background: var(--c); border-color: var(--c); color: #fff; }
.indicator-switch input:checked + label::before { background: #fff; }
.indicator-switch input:focus-visible + label { outline: 3px solid #f2b84b; outline-offset: 2px; }
.legend { background: #fff; padding: .6rem .75rem; border-radius: 8px; border: 1px solid var(--line); font-size: .8rem; line-height: 1.5; min-width: 150px; }
.legend i { display: inline-block; width: 16px; height: 12px; margin-right: 6px; vertical-align: -1px; border-radius: 2px; }
.rank { max-height: calc(100vh - 260px); overflow-y: auto; }
.rank-row { display: grid; grid-template-columns: 1fr auto; gap: .2rem .75rem; padding: .6rem 1rem; border-bottom: 1px solid var(--line); cursor: pointer; }
.rank-row:hover, .rank-row:focus { background: #f6f9fb; outline: none; }
.rank-row .bar { grid-column: 1 / -1; height: 5px; background: #edf1f4; border-radius: 3px; overflow: hidden; }
.rank-row .bar span { display: block; height: 100%; background: var(--c); }
.rank-row .val { font-weight: 700; color: var(--c); }
.leaflet-popup-content { font-family: var(--bs-body-font-family); font-size: .88rem; }
.leaflet-popup-content table td { padding: 1px 8px 1px 0; }

/* --- Autocomplétion --- */
.ac { position: relative; }
.ac-list { position: absolute; z-index: 1050; left: 0; right: 0; top: 100%; background: #fff; border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 8px 24px rgba(22, 50, 79, .12); max-height: 320px; overflow-y: auto; }
.ac-item { padding: .5rem .75rem; cursor: pointer; border-bottom: 1px solid #f0f3f5; }
.ac-item:hover, .ac-item.active { background: #eef4fa; }
.ac-item small { display: block; color: var(--muted); }
.child-chip { display: flex; gap: .75rem; align-items: center; padding: .6rem .8rem; border: 1px solid var(--line); border-radius: 8px; background: #f8fafb; }

/* --- Authentification --- */
.auth-wrap { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1fr) minmax(360px, 480px); }
.auth-side { background: var(--ink); color: #d6e1eb; padding: 3rem; display: flex; flex-direction: column; justify-content: space-between; }
.auth-side h1 { color: #fff; font-size: 2.2rem; max-width: 16ch; line-height: 1.15; }
.auth-side p { max-width: 46ch; }
.auth-bars { display: flex; align-items: end; gap: 10px; height: 120px; }
.auth-bars span { width: 26px; border-radius: 6px; }
.auth-form { background: #fff; padding: 3rem 2.5rem; display: flex; flex-direction: column; justify-content: center; }
@media (max-width: 767.98px) { .auth-wrap { grid-template-columns: 1fr; } .auth-side { display: none; } }

pre.json { background: #f8fafb; border: 1px solid var(--line); border-radius: 8px; padding: .75rem; font-size: .82rem; max-height: 420px; overflow: auto; }

@media print {
  .sidebar, .topbar, .actions, .no-print, .filters { display: none !important; }
  .content { padding: 0; }
  .panel { border: 0; }
}

/* --- Page publique de vérification --- */
.verify-page { background: var(--paper); }
.verify { max-width: 520px; margin: 0 auto; padding: 1.5rem 1rem 3rem; }
.verify .brand { color: var(--ink); padding: 0; }
.verify-status h1 { font-size: 1.4rem; margin-bottom: .4rem; }
.verify-status.ok { border-top: 5px solid var(--vacc); }
.verify-status.ok h1 { color: var(--vacc); }
.verify-status.invalid { border-top: 5px solid var(--late); }
.verify-status.invalid h1 { color: var(--late); }

/* =====================================================================
   Mobile et tablette
   ===================================================================== */
@media (max-width: 991.98px) {
  .sidebar { position: fixed; z-index: 1045; left: 0; transform: translateX(-105%); transition: transform .22s ease;
             width: min(300px, 86vw); padding-bottom: calc(.75rem + env(safe-area-inset-bottom)); }
  .sidebar.open { transform: none; box-shadow: 8px 0 30px rgba(0,0,0,.25); }
  body.menu-open { overflow: hidden; }

  .topbar { padding: .6rem 1rem; padding-top: calc(.6rem + env(safe-area-inset-top)); }
  .content { padding: 1rem 1rem calc(84px + env(safe-area-inset-bottom)); }

  .bottom-nav { display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 1030;
                background: #fff; border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
                box-shadow: 0 -4px 16px rgba(22, 50, 79, .06); }
  .bottom-nav a, .bottom-nav button { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
                min-height: 58px; color: var(--muted); text-decoration: none; font-size: .7rem; font-weight: 600; background: none; border: 0; }
  .bottom-nav i { font-size: 1.25rem; line-height: 1; }
  .bottom-nav a.active { color: var(--ink); }
  .bottom-nav a.primary i { background: var(--vacc); color: #fff; width: 44px; height: 30px; border-radius: 15px; display: grid; place-items: center; }
}

@media (max-width: 767.98px) {
  h1 { font-size: 1.35rem; }
  .topbar .who { display: none; }
  .page-head { align-items: stretch; flex-direction: column; }
  .page-head .actions { margin-left: 0; }
  .page-head .actions > .btn, .page-head .actions > a.btn { flex: 1 1 auto; }
  .page-head .actions > form { flex: 1 1 auto; }
  .page-head .actions > form .btn { width: 100%; }

  /* Pas de zoom automatique iOS sur les champs, cibles tactiles confortables */
  .form-control, .form-select { font-size: 16px; }
  .btn { min-height: 40px; }
  .btn-sm { min-height: 36px; min-width: 36px; }
  table.dataTable .btn-sm, .panel table.table .btn-sm { min-height: 32px; min-width: 32px; }
  .form-check-input { width: 1.25em; height: 1.25em; }

  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .6rem; }
  .kpi { padding: .75rem .8rem; }
  .kpi .v { font-size: 1.5rem; }
  .kpi .s { font-size: .78rem; }

  /* Filtres repliables */
  .filters-toggle { display: flex; width: 100%; justify-content: space-between; align-items: center; margin-bottom: .75rem; }
  .filters.collapsible:not(.open) { display: none !important; }

  /* Tableaux empilés en fiches : chaque ligne devient une carte */
  table.stack thead { display: none; }
  table.stack, table.stack tbody, table.stack tfoot, table.stack tr, table.stack td { display: block; width: 100%; }
  table.stack tr { padding: .6rem .9rem; border-bottom: 1px solid var(--line); }
  table.stack td { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; border: 0; padding: .2rem 0; text-align: right; }
  table.stack td::before { content: attr(data-label); color: var(--muted); font-size: .8rem; font-weight: 600; text-align: left; flex-shrink: 0; max-width: 45%; }
  table.stack td[data-label=""]::before, table.stack td:not([data-label])::before { display: none; }
  table.stack td[data-label=""] { justify-content: flex-end; padding-top: .45rem; }
  table.stack td.num { text-align: right; }
  table.stack td > br { display: none; }
  table.stack td small { margin-left: .35rem; }
  table.stack .text-nowrap { white-space: normal !important; }

  /* Carte */
  .map-shell { gap: .75rem; }
  #map { height: 62vh; min-height: 340px; }
  .mini-map { height: 320px !important; }
  .rank { max-height: none; }
  .indicator-switch { flex-wrap: nowrap; overflow-x: auto; padding-bottom: .25rem; scrollbar-width: none; }
  .indicator-switch::-webkit-scrollbar { display: none; }
  .indicator-switch label { white-space: nowrap; }
  .leaflet-control-layers-expanded { padding: 4px 6px; font-size: .78rem; }

  .card-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }

  /* DataTables sur téléphone : barre d'outils empilée, recherche pleine largeur */
  .dt-container .dt-layout-row:not(.dt-layout-table) { flex-direction: column; align-items: stretch; gap: .5rem; }
  .dt-container .dt-layout-cell { justify-content: space-between !important; text-align: left !important; }
  .dt-container .dt-search, .dt-container .dt-search input { width: 100%; min-width: 0; }
  .dt-container .dt-buttons { margin-left: 0; }
  .dt-container .dt-paging { display: flex; justify-content: center; width: 100%; }
  dl.facts { grid-template-columns: 1fr; gap: 0; }
  dl.facts dd { margin-bottom: .5rem; }
  .panel-head { flex-wrap: wrap; }
  .pagination { flex-wrap: wrap; }
}
