/* =====================================================================
   SuiviPro : feuille de style unique (mobile d'abord, sans dépendance)
   ===================================================================== */

:root {
  --primary: #0F766E;
  --primary-dark: #115E59;
  --primary-soft: #E6F4F2;
  --accent: #F59E0B;
  --accent-soft: #FEF3C7;
  --danger: #DC2626;
  --danger-soft: #FEE2E2;
  --success: #16A34A;
  --success-soft: #DCFCE7;
  --info: #2563EB;
  --info-soft: #DBEAFE;
  --bg: #F6F7F9;
  --card: #FFFFFF;
  --text: #1F2937;
  --muted: #6B7280;
  --border: #E5E7EB;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --bottom-nav-h: 64px;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5rem; }
h2 { font-size: 1.1rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 .75rem; }
small, .muted { color: var(--muted); }
.icon { width: 20px; height: 20px; flex: none; }
.skip-link { position: absolute; left: -9999px; }
.skip-link:focus { left: 1rem; top: 1rem; z-index: 100; background: #fff; padding: .5rem 1rem; border-radius: 8px; }
:focus-visible { outline: 3px solid rgba(15, 118, 110, .45); outline-offset: 2px; }

/* --- Structure --------------------------------------------------------- */
.app { min-height: 100vh; }
.sidebar { display: none; }
.main { min-width: 0; overflow-x: hidden; padding-bottom: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom) + 16px); }
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: .75rem;
  padding: .6rem 1rem;
  background: var(--primary); color: #fff;
}
.page-title { font-size: 1.05rem; margin: 0; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.content { padding: 1rem; max-width: 1200px; margin: 0 auto; }
.footer { text-align: center; font-size: .8rem; padding: 1rem; }

.brand { display: flex; align-items: center; gap: .6rem; color: inherit; text-decoration: none !important; }
.brand-logo {
  width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center;
  background: var(--accent); color: #fff; font-weight: 800; font-size: 1.1rem;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text small { color: inherit; opacity: .75; font-size: .75rem; }
.brand-mobile .brand-logo { width: 30px; height: 30px; }
.brand-mobile .brand-text { display: none; }

/* --- Navigation basse (mobile) ---------------------------------------- */
.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(5, 1fr); align-items: end;
  height: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--card); border-top: 1px solid var(--border);
  box-shadow: 0 -2px 8px rgba(0, 0, 0, .05);
}
.tab {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  height: var(--bottom-nav-h); color: var(--muted); font-size: .72rem; text-decoration: none !important;
}
.tab .icon { width: 22px; height: 22px; }
.tab.active { color: var(--primary); font-weight: 600; }
.tab-add { position: relative; }
.add-circle {
  width: 56px; height: 56px; border-radius: 50%; display: grid; place-items: center;
  background: var(--accent); color: #fff; margin-top: -26px;
  box-shadow: 0 4px 12px rgba(245, 158, 11, .45); border: 4px solid var(--bg);
}
.add-circle .icon { width: 26px; height: 26px; stroke-width: 2.4; }

/* --- Feuilles (menus du bas) ------------------------------------------- */
.sheet { display: none; position: fixed; inset: 0; z-index: 50; }
.sheet:target, .sheet.open { display: block; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(17, 24, 39, .45); }
.sheet-panel {
  position: absolute; left: 0; right: 0; bottom: 0;
  background: var(--card); border-radius: 16px 16px 0 0;
  padding: 1rem 1rem calc(1rem + env(safe-area-inset-bottom));
  max-height: 85vh; overflow-y: auto;
  animation: monte .18s ease-out;
}
@keyframes monte { from { transform: translateY(30px); } to { transform: none; } }
.sheet-title { font-weight: 700; margin-bottom: .5rem; }
.sheet-link {
  display: flex; align-items: center; gap: .9rem; width: 100%;
  padding: .8rem .5rem; border: 0; border-bottom: 1px solid var(--border);
  background: none; color: var(--text); font: inherit; text-align: left; cursor: pointer;
  text-decoration: none !important;
}
.sheet-link .icon { color: var(--primary); width: 24px; height: 24px; }
.sheet-link span { display: flex; flex-direction: column; }
.sheet-link small { font-size: .8rem; }
.sheet-logout .icon { color: var(--danger); }
.sheet .btn-block { margin-top: .75rem; }

/* --- Barre latérale (desktop ≥ 900px) ----------------------------------- */
@media (min-width: 900px) {
  .app { display: grid; grid-template-columns: 250px 1fr; }
  .sidebar {
    display: flex; flex-direction: column;
    position: sticky; top: 0; height: 100vh; overflow-y: auto;
    background: var(--primary-dark); color: #fff; padding: 1rem .75rem;
  }
  .sidebar .brand { padding: .25rem .5rem 1rem; }
  .side-nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
  .side-nav a {
    display: flex; align-items: center; gap: .7rem;
    padding: .55rem .75rem; border-radius: 8px; color: rgba(255, 255, 255, .85);
    text-decoration: none;
  }
  .side-nav a:hover { background: rgba(255, 255, 255, .08); }
  .side-nav a.active { background: var(--primary); color: #fff; font-weight: 600; box-shadow: inset 3px 0 0 var(--accent); }
  .nav-section { margin: .9rem .75rem .25rem; font-size: .7rem; text-transform: uppercase; letter-spacing: .06em; color: rgba(255, 255, 255, .5); }
  .side-user {
    display: flex; align-items: center; justify-content: space-between; gap: .5rem;
    border-top: 1px solid rgba(255, 255, 255, .15); padding: .75rem .5rem 0; margin-top: 1rem;
  }
  .side-user div { display: flex; flex-direction: column; line-height: 1.2; }
  .side-user small { color: rgba(255, 255, 255, .65); }
  .side-user .btn-icon { color: #fff; }
  .bottom-nav, .brand-mobile { display: none; }
  .main { padding-bottom: 0; }
  .topbar { background: transparent; color: var(--text); padding: 1.25rem 1.5rem 0; position: static; }
  .page-title { font-size: 1.4rem; }
  .content { padding: 1rem 1.5rem 2rem; }
  .sheet-panel { left: 50%; right: auto; width: 420px; transform: translateX(-50%); bottom: 2rem; border-radius: 16px; animation: none; }
}

/* --- Cartes ---------------------------------------------------------- */
.card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 1rem; margin-bottom: 1rem;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: .5rem; margin-bottom: .75rem; flex-wrap: wrap; }
.card-head h2 { margin: 0; }
.card-flush { padding: 0; overflow: hidden; }
.card-flush .card-head { padding: 1rem 1rem 0; }
.card-accent { border-left: 4px solid var(--accent); }
.card-danger { border-left: 4px solid var(--danger); }

.grid { display: grid; gap: 1rem; }
.grid-2, .grid-3, .grid-4 { display: grid; gap: .75rem; grid-template-columns: 1fr 1fr; }
.grid-3 { grid-template-columns: 1fr; }
@media (min-width: 600px) { .grid-3 { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 900px) {
  .grid-4 { grid-template-columns: repeat(4, 1fr); }
  .grid-main { grid-template-columns: 3fr 2fr; }
  .grid-half { grid-template-columns: 1fr 1fr; }
}

/* --- KPI -------------------------------------------------------------- */
.kpi { padding: .9rem; margin: 0; display: flex; flex-direction: column; gap: .2rem; color: var(--text); text-decoration: none !important; }
.kpi-label { font-size: .78rem; color: var(--muted); display: flex; align-items: center; gap: .35rem; }
.kpi-value { font-size: 1.15rem; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi-sub { font-size: .75rem; color: var(--muted); }
.kpi-danger .kpi-value { color: var(--danger); }
.kpi-primary .kpi-value { color: var(--primary); }
.kpi-success .kpi-value { color: var(--success); }
@media (min-width: 900px) { .kpi-value { font-size: 1.35rem; } }

/* Trois chiffres en tête de fiche crédit */
.trio { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .4rem; text-align: center; }
.trio div { background: var(--bg); border-radius: 10px; padding: .6rem .2rem; min-width: 0; }
.trio span { display: block; font-size: .75rem; color: var(--muted); }
.trio strong { display: block; font-variant-numeric: tabular-nums; font-size: clamp(.74rem, 3.4vw, 1rem); white-space: nowrap; }
.trio .reste strong { color: var(--danger); font-size: clamp(.78rem, 3.6vw, 1.1rem); }
.trio .reste.ok strong { color: var(--success); }
@media (min-width: 600px) { .trio strong { font-size: 1.25rem; } .trio .reste strong { font-size: 1.35rem; } }

/* Barre de progression */
.progress { height: 10px; background: var(--border); border-radius: 99px; overflow: hidden; margin: .75rem 0 .25rem; }
.progress > span { display: block; height: 100%; background: var(--primary); border-radius: 99px; }
.progress.done > span { background: var(--success); }
.progress-sm { height: 6px; margin: .35rem 0 0; }

/* --- Boutons ---------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  min-height: 42px; padding: .5rem 1rem; border-radius: 10px; border: 1px solid transparent;
  font: inherit; font-weight: 600; cursor: pointer; text-decoration: none !important;
  background: var(--primary); color: #fff; white-space: nowrap;
}
.btn:hover { background: var(--primary-dark); }
.btn .icon { width: 18px; height: 18px; }
.btn-accent { background: var(--accent); color: #1F2937; }
.btn-accent:hover { background: #D97706; color: #fff; }
.btn-danger { background: var(--danger); }
.btn-danger:hover { background: #B91C1C; }
.btn-light { background: var(--card); color: var(--text); border-color: var(--border); }
.btn-light:hover { background: var(--bg); }
.btn-outline { background: transparent; color: var(--primary); border-color: var(--primary); }
.btn-outline:hover { background: var(--primary-soft); }
.btn-wa { background: #fff; color: #128C7E; border-color: #25D366; }
.btn-wa:hover { background: #E7F8EE; }
.btn-sm { min-height: 34px; padding: .3rem .7rem; font-size: .85rem; }
.btn-block { width: 100%; }
.btn-icon { background: none; border: 0; padding: .35rem; cursor: pointer; color: var(--muted); border-radius: 8px; display: inline-grid; place-items: center; }
.btn-icon:hover { background: rgba(0, 0, 0, .06); }
.actions { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.actions-end { justify-content: flex-end; }
form.inline { display: inline; }

/* --- Formulaires ------------------------------------------------------ */
.form-grid { display: grid; gap: .9rem; }
@media (min-width: 700px) { .form-grid.cols-2 { grid-template-columns: 1fr 1fr; } .span-2 { grid-column: span 2; } }
label { display: block; font-weight: 600; font-size: .88rem; margin-bottom: .3rem; }
.field small { display: block; font-weight: 400; margin-top: .25rem; }
input[type=text], input[type=email], input[type=password], input[type=date], input[type=tel],
input[type=number], input[type=search], select, textarea {
  width: 100%; min-height: 44px; padding: .55rem .75rem;
  border: 1px solid var(--border); border-radius: 10px; background: #fff;
  font: inherit; font-size: 16px; color: var(--text);
}
textarea { min-height: 90px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--primary); outline: none; box-shadow: 0 0 0 3px rgba(15, 118, 110, .15); }
input.montant { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
input[type=file] { font-size: .9rem; max-width: 100%; }
.check { display: flex; align-items: center; gap: .5rem; font-weight: 500; }
.check input { width: 20px; height: 20px; }
.radio-cards { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; }
.radio-cards label {
  display: flex; flex-direction: column; gap: .1rem; cursor: pointer;
  border: 2px solid var(--border); border-radius: 10px; padding: .6rem .75rem; margin: 0;
}
.radio-cards input { position: absolute; opacity: 0; pointer-events: none; }
.radio-cards label:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); }
.radio-cards small { font-weight: 400; }
.errors { margin: 0; padding-left: 1.2rem; }
.hidden { display: none !important; }

/* Filtres repliables */
.filters { margin-bottom: 1rem; }
.filters summary { cursor: pointer; font-weight: 600; padding: .25rem 0; }
.filters .form-grid { margin-top: .75rem; grid-template-columns: 1fr 1fr; }
.filters .full { grid-column: 1 / -1; }
@media (min-width: 900px) { .filters .form-grid { grid-template-columns: repeat(5, 1fr) auto; align-items: end; } .filters .full { grid-column: auto; } }

/* Onglets */
.tabs { display: flex; gap: .25rem; background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: .25rem; margin-bottom: 1rem; overflow-x: auto; }
.tabs a { flex: 1; text-align: center; padding: .55rem .75rem; border-radius: 9px; color: var(--muted); font-weight: 600; white-space: nowrap; text-decoration: none !important; }
.tabs a.active { background: var(--primary); color: #fff; }
.chips { display: flex; gap: .4rem; flex-wrap: wrap; margin-bottom: .75rem; }
.chip { padding: .3rem .75rem; border-radius: 99px; border: 1px solid var(--border); background: var(--card); color: var(--text); font-size: .85rem; text-decoration: none !important; }
.chip.active { background: var(--primary-soft); border-color: var(--primary); color: var(--primary-dark); font-weight: 600; }

/* --- Alertes et badges --------------------------------------------------- */
.alert { padding: .75rem 1rem; border-radius: 10px; margin-bottom: 1rem; border: 1px solid; }
.alert-success { background: var(--success-soft); border-color: #86EFAC; color: #14532D; }
.alert-danger { background: var(--danger-soft); border-color: #FCA5A5; color: #7F1D1D; }
.alert-warning { background: var(--accent-soft); border-color: #FCD34D; color: #78350F; }
.alert-info { background: var(--info-soft); border-color: #93C5FD; color: #1E3A8A; }
.badge { display: inline-block; padding: .12rem .55rem; border-radius: 99px; font-size: .75rem; font-weight: 700; white-space: nowrap; }
.badge-info { background: var(--info-soft); color: #1D4ED8; }
.badge-warning { background: var(--accent-soft); color: #B45309; }
.badge-success { background: var(--success-soft); color: #15803D; }
.badge-danger { background: var(--danger-soft); color: #B91C1C; }
.badge-muted { background: var(--bg); color: var(--muted); border: 1px solid var(--border); }

/* --- Montants : alignés à droite, chiffres tabulaires -------------------- */
.num, .amount { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.amount { font-weight: 700; }
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }
.text-primary { color: var(--primary); }
.text-right { text-align: right; }

/* --- Tableaux (desktop) / listes en cartes (mobile) ---------------------- */
.table-wrap { overflow-x: auto; }
table.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: .65rem .75rem; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
.table th { font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); background: #FAFAFB; }
.table th.num, .table td.num { text-align: right; }
.table tbody tr:hover { background: #FAFBFC; }
.table tfoot td { font-weight: 700; background: #FAFAFB; }

@media (max-width: 699px) {
  table.table-cards thead { display: none; }
  table.table-cards, .table-cards tbody, .table-cards tr, .table-cards td { display: block; width: 100%; }
  .table-cards tr { padding: .75rem 1rem; border-bottom: 1px solid var(--border); position: relative; }
  .table-cards td { border: 0; padding: .1rem 0; text-align: left; }
  .table-cards td.num { text-align: left; }
  .table-cards td[data-label]::before { content: attr(data-label) " : "; color: var(--muted); font-size: .8rem; }
  .table-cards td.cell-main { font-weight: 600; padding-right: 8.5rem; }
  .table-cards td.cell-amount { position: absolute; top: .75rem; right: 1rem; width: auto; text-align: right; font-size: 1rem; }
  .table-cards td.cell-amount::before { content: none; }
  .table-cards td.cell-actions { padding-top: .4rem; }
  .table-cards tfoot tr { display: flex; justify-content: space-between; }
}

/* Liste simple (dashboard) */
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; align-items: center; justify-content: space-between; gap: .75rem; padding: .65rem 0; border-bottom: 1px solid var(--border); }
.list li:last-child { border-bottom: 0; }
.list .meta { display: flex; flex-direction: column; min-width: 0; }
.list .meta strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list .meta small { font-size: .8rem; }
.list .right { display: flex; flex-direction: column; align-items: flex-end; gap: .2rem; }
.empty { text-align: center; color: var(--muted); padding: 1.5rem .5rem; }

/* --- Graphiques SVG ----------------------------------------------------- */
.chart { width: 100%; height: auto; display: block; }
.chart text { font-family: var(--font); font-size: 15px; fill: var(--muted); }
.chart .bar { fill: var(--primary); }
.chart .bar-current { fill: var(--accent); }
.chart .value { fill: var(--text); font-weight: 600; font-size: 14px; }
.chart .grid-line { stroke: var(--border); stroke-width: 1; }
.hbars { list-style: none; padding: 0; margin: 0; }
.hbars li { margin-bottom: .65rem; }
.hbars .hb-head { display: flex; justify-content: space-between; gap: .5rem; font-size: .88rem; }
.hbars .hb-track { height: 8px; background: var(--bg); border-radius: 99px; overflow: hidden; margin-top: .2rem; }
.hbars .hb-fill { height: 100%; background: var(--primary); border-radius: 99px; }

/* Tranches d'ancienneté */
.aging { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .4rem; }
.aging div { border-radius: 10px; padding: .6rem .2rem; text-align: center; min-width: 0; }
.aging span { display: block; font-size: .75rem; }
.aging strong { display: block; font-variant-numeric: tabular-nums; font-size: clamp(.72rem, 3.3vw, .95rem); white-space: nowrap; }
.aging .a1 { background: var(--success-soft); color: #14532D; }
.aging .a2 { background: var(--accent-soft); color: #78350F; }
.aging .a3 { background: var(--danger-soft); color: #7F1D1D; }

/* Historique (timeline) */
.timeline { list-style: none; margin: 0; padding: 0 0 0 1rem; border-left: 2px solid var(--border); }
.timeline li { position: relative; padding: 0 0 .9rem .75rem; }
.timeline li::before { content: ""; position: absolute; left: -1.43rem; top: .35rem; width: 10px; height: 10px; border-radius: 50%; background: var(--primary); border: 2px solid #fff; }
.timeline .t-row { display: flex; justify-content: space-between; gap: .5rem; }

/* Personne (synthèse) */
.person { margin-bottom: 1rem; }
.person summary { list-style: none; cursor: pointer; }
.person summary::-webkit-details-marker { display: none; }
.person-head { display: flex; justify-content: space-between; gap: .75rem; align-items: flex-start; }
.person-head .meta { min-width: 0; }
.person-body { border-top: 1px solid var(--border); margin-top: .75rem; padding-top: .75rem; }
.mini-stats { display: flex; flex-wrap: wrap; gap: .25rem 1rem; font-size: .85rem; margin-top: .4rem; }
.mini-stats b { font-variant-numeric: tabular-nums; }

/* Page de connexion */
.auth-page { min-height: 100vh; display: grid; place-items: center; padding: 1rem; background: linear-gradient(160deg, var(--primary-dark), var(--primary)); }
.auth-card { width: 100%; max-width: 400px; }
.auth-card .brand { justify-content: center; margin-bottom: 1rem; color: var(--text); }

/* Pagination */
.pagination { display: flex; align-items: center; justify-content: center; gap: .75rem; padding: 1rem; }

/* Définitions (fiche) */
.dl { display: grid; grid-template-columns: auto 1fr; gap: .35rem 1rem; margin: 0; }
.dl dt { color: var(--muted); font-size: .88rem; }
.dl dd { margin: 0; }

@media print {
  .sidebar, .bottom-nav, .sheet, .actions, .filters, .topbar .brand { display: none !important; }
  .main { padding: 0; }
  .card { box-shadow: none; }
}

/* Petits écrans : la frise reste lisible et les références longues se coupent */
.timeline small { overflow-wrap: anywhere; }

/* --- PWA ------------------------------------------------------------- */
.sheet-link[hidden] { display: none !important; }
button.sheet-link { width: 100%; background: none; border: 0; font: inherit; text-align: left; cursor: pointer; }
.pwa-steps { margin: 0 0 .5rem; padding-left: 1.25rem; line-height: 1.7; }
.net-banner {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom) + 10px);
  z-index: 60; max-width: calc(100% - 24px);
  background: #1F2937; color: #fff; font-size: .85rem; padding: .55rem .9rem;
  border-radius: 999px; box-shadow: 0 4px 14px rgba(0,0,0,.2);
}
.net-banner[hidden] { display: none; }
@media (min-width: 900px) { .net-banner { bottom: 16px; } }
/* Application installée : marge pour l'encoche en haut (iPhone) */
.pwa-standalone .topbar { padding-top: max(.75rem, env(safe-area-inset-top)); }
.pwa-standalone .auth-page { padding-top: env(safe-area-inset-top); }
