/* =====================================================================
   AYUF Facturation — interface
   Palette : encre (navigation), papier (fond), vert encaissement (action)
   ===================================================================== */
:root {
  --ink: #182433;
  --ink-2: #22324a;
  --ink-text: #c9d3df;
  --paper: #f3f5f7;
  --surface: #ffffff;
  --line: #dce1e7;
  --line-strong: #c3cbd5;
  --text: #1c2530;
  --muted: #5b6775;
  --accent: #0d6b57;
  --accent-hover: #0a5646;
  --accent-soft: #e3f1ed;
  --amber: #9a5f07;
  --amber-soft: #fbf0dc;
  --red: #b42318;
  --red-soft: #fce8e6;
  --blue: #1f5fa8;
  --blue-soft: #e5eef9;
  --radius: 6px;
  --radius-lg: 10px;
  --font: "Source Sans 3", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --sidebar: 248px;
}

*, *::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(--paper);
}
a { color: var(--accent); }
a:hover { color: var(--accent-hover); }
img { max-width: 100%; height: auto; }
:focus-visible { outline: 3px solid #6aa9ff; outline-offset: 2px; }
.num, td.num, .amount { font-variant-numeric: tabular-nums; white-space: nowrap; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------- Structure ---------- */
.app { display: grid; grid-template-columns: var(--sidebar) 1fr; min-height: 100vh; }
.sidebar {
  background: var(--ink); color: var(--ink-text); position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 12px; padding: 22px 20px 18px; color: #fff; text-decoration: none; }
.brand-mark {
  width: 38px; height: 38px; border-radius: 8px; background: #fff; color: var(--ink);
  display: grid; place-items: center; font-weight: 800; letter-spacing: -.5px; font-size: 15px; overflow: hidden;
}
.brand-mark img { width: 100%; height: 100%; object-fit: contain; }
.brand-name { font-weight: 700; font-size: 16px; line-height: 1.15; }
.brand-name small { display: block; font-weight: 400; color: var(--ink-text); font-size: 12.5px; }
.nav { padding: 6px 10px 16px; flex: 1; }
.nav-group { margin-top: 18px; padding: 0 12px 6px; font-size: 12.5px; color: #8797ab; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: var(--radius);
  color: var(--ink-text); text-decoration: none; font-size: 14.5px;
}
.nav a svg { width: 18px; height: 18px; flex: none; opacity: .85; }
.nav a:hover { background: var(--ink-2); color: #fff; }
.nav a[aria-current="page"] { background: #fff; color: var(--ink); font-weight: 600; }
.nav a[aria-current="page"] svg { opacity: 1; }
.sidebar-foot { padding: 14px 20px 20px; border-top: 1px solid #2b3b52; font-size: 13px; }
.sidebar-foot .who { color: #fff; font-weight: 600; }
.sidebar-foot a, .sidebar-foot button { color: var(--ink-text); }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 16px; padding: 14px 32px; background: var(--surface);
  border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5;
}
.topbar h1 { font-size: 20px; margin: 0; font-weight: 700; flex: 1; min-width: 0; }
.btn.menu-btn { display: none; padding: 6px 8px; }
.menu-btn svg { width: 20px; height: 20px; }
.content { padding: 28px 32px 48px; max-width: 1280px; width: 100%; }

/* ---------- Composants ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 40px;
  padding: 8px 16px; border-radius: var(--radius); border: 1px solid var(--line-strong);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 600; font-size: 14.5px;
  text-decoration: none; cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: var(--muted); color: var(--text); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: #fff; }
.btn-danger { color: var(--red); border-color: #e9b4ae; }
.btn-danger:hover { background: var(--red-soft); border-color: var(--red); color: var(--red); }
.btn-small { min-height: 32px; padding: 4px 10px; font-size: 13.5px; }
.btn-link { border: 0; background: none; padding: 0; min-height: 0; color: var(--accent); font-weight: 600; cursor: pointer; font: inherit; }
.btn[disabled], .btn.is-busy { opacity: .6; cursor: progress; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); }
.panel + .panel, .panel + .grid, .grid + .panel { margin-top: 20px; }
.panel-head { display: flex; align-items: center; gap: 12px; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.panel-head h2 { font-size: 16px; margin: 0; }
.panel-body { padding: 20px; }
.panel-body > :first-child { margin-top: 0; }
.panel-body > :last-child { margin-bottom: 0; }
.grid { display: grid; gap: 20px; }
.grid > .panel, .grid > div > .panel:first-child { margin-top: 0; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.muted { color: var(--muted); }
.small { font-size: 13.5px; }
.lead { font-size: 16.5px; color: var(--muted); margin: 0 0 20px; max-width: 70ch; }

/* ---------- Alertes ---------- */
.flash { padding: 12px 16px; border-radius: var(--radius); margin-bottom: 18px; border: 1px solid; }
.flash-success { background: var(--accent-soft); border-color: #b5d9cf; color: #0a4d3f; }
.flash-error { background: var(--red-soft); border-color: #f1b8b1; color: #8c1c13; }
.flash-info { background: var(--blue-soft); border-color: #bcd2ee; color: #17477e; }

/* ---------- Formulaires ---------- */
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px 20px; }
.form-grid .full { grid-column: 1 / -1; }
.field label { display: block; font-weight: 600; font-size: 14px; margin-bottom: 5px; }
.field .hint { font-size: 13px; color: var(--muted); margin: 4px 0 0; }
input[type=text], input[type=email], input[type=password], input[type=tel], input[type=url], input[type=number],
input[type=date], input[type=search], select, textarea {
  width: 100%; min-height: 42px; padding: 8px 12px; font: inherit; color: var(--text);
  background: #fff; border: 1px solid var(--line-strong); border-radius: var(--radius);
}
textarea { min-height: 96px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(13,107,87,.15); }
.has-error input, .has-error select, .has-error textarea { border-color: var(--red); }
.field-error { color: var(--red); font-size: 13.5px; margin: 4px 0 0; }
.form-foot { display: flex; gap: 10px; justify-content: flex-end; padding-top: 20px; margin-top: 20px; border-top: 1px solid var(--line); }
.checkbox { display: flex; gap: 8px; align-items: flex-start; font-weight: 400; }
.checkbox input { margin-top: 3px; width: 17px; height: 17px; accent-color: var(--accent); }
.pwd-wrap { position: relative; }
.pwd-wrap input { padding-right: 88px; }
.pwd-toggle { position: absolute; right: 8px; top: 50%; transform: translateY(-50%); font-size: 13px; }

/* ---------- Filtres ---------- */
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 16px; }
.filters .field { min-width: 160px; }
.filters .grow { flex: 1; min-width: 220px; }

/* ---------- Tableaux ---------- */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 14.5px; }
table.data th { text-align: left; font-weight: 600; color: var(--muted); font-size: 13px; padding: 10px 14px; border-bottom: 1px solid var(--line); background: #fafbfc; white-space: nowrap; }
table.data td { padding: 12px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.data tr:last-child td { border-bottom: 0; }
table.data tbody tr:hover { background: #fafbfc; }
table.data .num { text-align: right; }
.row-link { color: var(--text); font-weight: 600; text-decoration: none; }
.row-link:hover { color: var(--accent); text-decoration: underline; }
.empty { padding: 40px 20px; text-align: center; color: var(--muted); }
.empty strong { display: block; color: var(--text); font-size: 16px; margin-bottom: 4px; }

/* ---------- Badges ---------- */
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12.5px; font-weight: 600; background: #eef1f4; color: var(--muted); white-space: nowrap; }
.badge-ok { background: var(--accent-soft); color: var(--accent); }
.badge-warn { background: var(--amber-soft); color: var(--amber); }
.badge-danger { background: var(--red-soft); color: var(--red); }
.badge-info { background: var(--blue-soft); color: var(--blue); }

.avatar { width: 32px; height: 32px; border-radius: 50%; background: #e7ecf1; color: var(--ink); display: inline-grid; place-items: center; font-size: 12.5px; font-weight: 700; flex: none; }
.person { display: flex; align-items: center; gap: 10px; }

/* ---------- Tableau de bord ---------- */
.checklist { list-style: none; margin: 0; padding: 0; }
.checklist li { display: flex; gap: 10px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); }
.checklist li:last-child { border-bottom: 0; }
.tick { width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; flex: none; font-size: 13px; font-weight: 700; }
.tick-ok { background: var(--accent); color: #fff; }
.tick-todo { border: 2px solid var(--line-strong); }
.progress { height: 8px; background: #e7ecf1; border-radius: 999px; overflow: hidden; margin: 6px 0 16px; }
.progress span { display: block; height: 100%; background: var(--accent); }
.big-figure { font-size: 34px; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; letter-spacing: -.5px; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { padding: 10px 0; border-bottom: 1px solid var(--line); }
.timeline li:last-child { border-bottom: 0; }
.timeline time { display: block; color: var(--muted); font-size: 13px; }

/* ---------- Onglets ---------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 20px; overflow-x: auto; }
.tabs a { padding: 10px 16px; text-decoration: none; color: var(--muted); font-weight: 600; border-bottom: 3px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs a[aria-current="page"] { color: var(--text); border-bottom-color: var(--accent); }

/* ---------- Matrice des permissions ---------- */
.matrix th, .matrix td { text-align: center; }
.matrix th:first-child, .matrix td:first-child { text-align: left; }
.matrix .module td { background: #f6f8fa; font-weight: 700; text-align: left; color: var(--ink); }
.matrix input { width: 18px; height: 18px; accent-color: var(--accent); }

.copy-box { display: flex; gap: 8px; }
.copy-box input { font-family: ui-monospace, Consolas, monospace; font-size: 13px; }
.logo-preview { width: 180px; height: 90px; border: 1px dashed var(--line-strong); border-radius: var(--radius); display: grid; place-items: center; background: #fafbfc; }
.logo-preview img { max-height: 80px; max-width: 170px; }
.pagination { display: flex; gap: 6px; justify-content: center; padding: 16px; }

/* ---------- Pages publiques ---------- */
.guest { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr); }
.guest-side { background: var(--ink); color: #fff; padding: 48px; display: flex; flex-direction: column; justify-content: space-between; }
.guest-side .brand { padding: 0; }
.guest-side h2 { font-size: 32px; line-height: 1.2; margin: 0 0 12px; max-width: 16ch; font-weight: 700; }
.guest-side p { color: var(--ink-text); max-width: 42ch; margin: 0; }
.guest-figure { font-variant-numeric: tabular-nums; border-top: 1px solid #2b3b52; padding-top: 18px; color: var(--ink-text); font-size: 14px; }
.guest-figure strong { display: block; color: #fff; font-size: 26px; font-weight: 600; }
.guest-main { display: grid; place-items: center; padding: 40px 24px; }
.guest-card { width: 100%; max-width: 420px; }
.guest-card h1 { font-size: 26px; margin: 0 0 6px; }
.guest-card .field { margin-bottom: 16px; }
.guest-card .btn-primary { width: 100%; min-height: 46px; }

/* ---------- Responsive ---------- */
@media (max-width: 1080px) {
  .grid-3 { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: min(290px, 85vw); z-index: 20; transform: translateX(-100%); transition: transform .2s ease; }
  .sidebar.is-open { transform: none; box-shadow: 0 0 0 100vmax rgba(10,18,28,.45); }
  .btn.menu-btn { display: inline-flex; }
  .topbar { padding: 12px 16px; }
  .content { padding: 20px 16px 40px; }
  .grid-2, .grid-3, .form-grid { grid-template-columns: 1fr; }
  .guest { grid-template-columns: 1fr; }
  .guest-side { padding: 28px 24px; gap: 20px; }
  .guest-side h2 { font-size: 24px; }
  .guest-figure { display: none; }
  /* Tableaux en fiches sur mobile */
  table.data.stack thead { display: none; }
  table.data.stack tr { display: block; border-bottom: 1px solid var(--line); padding: 8px 0; }
  table.data.stack td { display: flex; justify-content: space-between; gap: 16px; border: 0; padding: 5px 14px; text-align: right; }
  table.data.stack td::before { content: attr(data-label); color: var(--muted); font-size: 13px; text-align: left; }
  table.data.stack td.num { text-align: right; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
@media print { .sidebar, .topbar, .no-print { display: none !important; } .app { display: block; } body { background: #fff; } }

/* ---------- Phase 2 : listes, fiches, catalogue ---------- */
.sort-link { color: inherit; text-decoration: none; }
.sort-link:hover, .sort-link[aria-sort] { color: var(--text); text-decoration: underline; }
.count-line { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 20px; border-bottom: 1px solid var(--line); color: var(--muted); font-size: 14px; }
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0; border: 1px solid var(--line); border-radius: var(--radius-lg); background: var(--surface); margin-bottom: 20px; }
.stat { padding: 16px 20px; border-left: 1px solid var(--line); }
.stat:first-child { border-left: 0; }
.stat .label { color: var(--muted); font-size: 13.5px; }
.stat .value { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; margin-top: 2px; }
.stat .value.is-due { color: var(--amber); }
.stat .value.is-late { color: var(--red); }
.facts { display: grid; grid-template-columns: 150px 1fr; gap: 8px 16px; margin: 0; }
.facts dt { color: var(--muted); font-size: 14px; }
.facts dd { margin: 0; overflow-wrap: anywhere; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head .code { color: var(--muted); font-variant-numeric: tabular-nums; }
.page-head h2 { margin: 2px 0 6px; font-size: 24px; }
.components td { vertical-align: top; padding: 8px 10px; }
.components input, .components select { min-height: 38px; }
.components .col-qty { width: 110px; }
.components .col-unit { width: 130px; }
.components .col-del { width: 48px; text-align: center; }
.price-preview { background: #f6f8fa; border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 16px; font-variant-numeric: tabular-nums; }
.price-preview strong { font-size: 20px; display: block; }
.inline-form { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.inline-form .field { flex: 1; min-width: 180px; }
.tag { display: inline-block; font-size: 12.5px; padding: 1px 8px; border: 1px solid var(--line-strong); border-radius: 4px; color: var(--muted); }
@media (max-width: 900px) {
  .stats { grid-template-columns: 1fr 1fr; }
  .stat:nth-child(3) { border-left: 0; }
  .stat:nth-child(n+3) { border-top: 1px solid var(--line); }
  .facts { grid-template-columns: 1fr; gap: 2px; }
  .facts dd { margin-bottom: 10px; }
  table.data.components thead { display: none; }
  table.data.components tr { display: grid; grid-template-columns: 1fr 1fr auto; gap: 6px; padding: 10px 0; border-bottom: 1px solid var(--line); }
  table.data.components td { padding: 0; border: 0; width: auto; }
  table.data.components td.col-label, table.data.components td.col-notes { grid-column: 1 / -1; }
  table.data.components td.col-label { order: 1; } table.data.components td.col-qty { order: 2; }
  table.data.components td.col-unit { order: 3; } table.data.components td.col-del { order: 4; }
  table.data.components td.col-notes { order: 5; }
}

/* ---------- Phase 3 : documents commerciaux ---------- */
.catalog-search { position: relative; max-width: 560px; margin-bottom: 16px; }
.catalog-search label { display: block; font-weight: 600; font-size: 14px; margin-bottom: 5px; }
.catalog-results { position: absolute; z-index: 10; left: 0; right: 0; top: 100%; margin: 4px 0 0; padding: 4px; list-style: none; background: #fff; border: 1px solid var(--line-strong); border-radius: var(--radius); box-shadow: 0 8px 24px rgba(24,36,51,.14); max-height: 320px; overflow-y: auto; }
.catalog-results li { padding: 8px 10px; border-radius: 4px; cursor: pointer; }
.catalog-results li strong { display: block; font-weight: 600; }
.catalog-results li span { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.catalog-results li:hover, .catalog-results li[aria-selected="true"] { background: var(--accent-soft); }
.catalog-results li.empty-result { color: var(--muted); cursor: default; }
table.doc-lines td { vertical-align: top; padding: 8px 6px; }
table.doc-lines th { padding: 8px 6px; }
table.doc-lines input, table.doc-lines select, table.doc-lines textarea { min-height: 36px; padding: 6px 8px; font-size: 14px; }
table.doc-lines textarea { min-height: 36px; margin-top: 4px; resize: vertical; }
.doc-lines .c-des { min-width: 240px; }
.doc-lines .c-qty { width: 80px; } .doc-lines .c-unit { width: 110px; } .doc-lines .c-price { width: 130px; }
.doc-lines .c-disc { width: 170px; } .doc-lines .c-vat { width: 72px; } .doc-lines .c-total { width: 130px; padding-top: 16px !important; font-weight: 600; }
.doc-lines .c-act { width: 118px; }
.line-ref { display: block; font-size: 12.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.line-ref:empty { display: none; }
.disc { display: flex; gap: 4px; }
.disc select { width: 72px; flex: none; }
.line-actions { display: flex; gap: 4px; }
.line-actions .btn-small { min-height: 34px; padding: 4px 9px; }
.totals { display: grid; grid-template-columns: 1fr auto; gap: 8px 16px; margin: 0; font-variant-numeric: tabular-nums; }
.totals + .totals { margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--line); }
.totals dt { color: var(--muted); }
.totals dd { margin: 0; text-align: right; white-space: nowrap; }
.totals .strong { color: var(--text); font-weight: 700; }
.totals .grand { font-size: 20px; font-weight: 800; color: var(--text); }
.gdisc-label label { display: block; margin-bottom: 4px; }
.gdisc-label .disc { max-width: 240px; }
.sticky-foot { position: sticky; bottom: 0; background: var(--paper); padding: 14px 0; margin-top: 8px; z-index: 4; }
.quick-dialog { border: 0; border-radius: var(--radius-lg); padding: 24px; width: min(640px, 94vw); box-shadow: 0 20px 60px rgba(10,18,28,.35); }
.quick-dialog::backdrop { background: rgba(10,18,28,.45); }
.quick-dialog h2 { margin: 0 0 4px; font-size: 19px; }

/* Document (aperçu écran, base du futur PDF) */
.doc-paper { background: #fff; border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 36px 40px; }
.doc-top { display: flex; justify-content: space-between; gap: 24px; flex-wrap: wrap; }
.doc-company { max-width: 46ch; font-size: 14px; color: var(--muted); }
.doc-company strong { color: var(--text); font-size: 17px; display: block; }
.doc-company img { max-height: 70px; max-width: 200px; display: block; margin-bottom: 10px; }
.doc-title { text-align: right; }
.doc-title h2 { margin: 0; font-size: 26px; letter-spacing: -.3px; }
.doc-title .no { font-variant-numeric: tabular-nums; font-size: 17px; font-weight: 600; }
.doc-meta { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 24px; margin: 28px 0; }
.doc-box { border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; font-size: 14.5px; }
.doc-box h3 { margin: 0 0 6px; font-size: 13px; color: var(--muted); font-weight: 600; }
.doc-items td, .doc-items th { padding: 10px 10px; }
.doc-items .desc { color: var(--muted); font-size: 13.5px; white-space: pre-line; }
.doc-foot { display: grid; grid-template-columns: minmax(0, 1fr) minmax(280px, 380px); gap: 32px; margin-top: 24px; }
.doc-foot .terms { font-size: 14px; }
.doc-foot .terms h3 { font-size: 13px; color: var(--muted); margin: 14px 0 4px; }
.doc-foot .terms h3:first-child { margin-top: 0; }
.doc-foot .terms p { margin: 0; white-space: pre-line; }
.status-actions { display: flex; gap: 8px; flex-wrap: wrap; }
@media (max-width: 900px) {
  table.data.doc-lines thead { display: none; }
  table.data.doc-lines tr { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 6px; padding: 12px 0; border-bottom: 1px solid var(--line); }
  table.data.doc-lines td { width: auto !important; padding: 0 !important; border: 0; }
  table.data.doc-lines td.c-des { grid-column: 1 / -1; min-width: 0; }
  table.data.doc-lines td.c-disc { grid-column: span 2; }
  table.data.doc-lines td.c-total { grid-column: 1 / 3; align-self: center; }
  table.data.doc-lines td.c-act { justify-self: end; }
  table.data.doc-lines td.c-total::before { content: 'Total HT : '; color: var(--muted); font-weight: 400; }
  table.data.doc-lines td[data-label]::before { content: attr(data-label); display: block; font-size: 12px; color: var(--muted); margin-bottom: 2px; }
  .doc-paper { padding: 20px 16px; }
  .doc-meta, .doc-foot { grid-template-columns: 1fr; }
  .doc-title { text-align: left; }
}
@media print {
  .doc-paper { border: 0; padding: 0; }
  .content > p, .status-actions, .page-head .actions, .panel.no-print { display: none !important; }
}
.panel + .doc-paper, .doc-paper + .panel { margin-top: 20px; }
.disc select { width: 84px; }
@media (max-width: 900px) {
  table.data.stack.doc-items td[data-label="Désignation"] { display: block; text-align: left; padding-top: 10px; }
  table.data.stack.doc-items td[data-label="Désignation"]::before { display: block; margin-bottom: 2px; }
  table.data.stack.doc-items tr { padding: 4px 0 10px; }
}

/* ---------- Phase 5 : paiements, reçus, impayés ---------- */
.stats.aging { grid-template-columns: repeat(6, minmax(0, 1fr)); }
.stat-link { text-decoration: none; color: inherit; }
.stat-link:hover, .stat-link.is-current { background: #f6f8fa; }
.stat-link.is-current { box-shadow: inset 0 -3px 0 var(--accent); }
tr.row-late td { background: #fff8f7; }
tr.row-late-strong td { background: var(--red-soft); }
.receipt-line { margin: 28px 0 4px; font-size: 16px; }
.receipt-amount { font-size: 34px; font-weight: 800; margin: 0; font-variant-numeric: tabular-nums; letter-spacing: -.5px; }
.signature { display: flex; justify-content: flex-end; margin-top: 36px; }
.signature span { border-top: 1px solid var(--line-strong); padding-top: 6px; min-width: 220px; text-align: center; color: var(--muted); font-size: 13px; }
@media (max-width: 1080px) { .stats.aging { grid-template-columns: repeat(3, minmax(0, 1fr)); } .stats.aging .stat:nth-child(4) { border-left: 0; } .stats.aging .stat:nth-child(n+4) { border-top: 1px solid var(--line); } }
@media (max-width: 900px) { .stats.aging { grid-template-columns: 1fr 1fr; } .stats.aging .stat { border-left: 1px solid var(--line); border-top: 1px solid var(--line); } .stats.aging .stat:nth-child(odd) { border-left: 0; } .stats.aging .stat:nth-child(-n+2) { border-top: 0; } }
.stats.aging .value { font-size: 18px; }
.stats.aging .stat { padding: 14px 16px; min-width: 0; }
table.data.unpaid th, table.data.unpaid td { padding: 10px 9px; }
table.data.unpaid td:first-child { min-width: 170px; }
@media (min-width: 901px) { table.data.unpaid { font-size: 14px; } }

/* ---------- Phase 7 : tableau de bord, rapports, recherche ---------- */
.dash-head { display: flex; justify-content: space-between; align-items: center; gap: 16px; flex-wrap: wrap; margin-bottom: 16px; }
.period-bar { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.segmented { display: inline-flex; background: #e7ecf1; border-radius: 8px; padding: 3px; flex-wrap: wrap; }
.segmented a { padding: 6px 12px; border-radius: 6px; text-decoration: none; color: var(--muted); font-weight: 600; font-size: 14px; }
.segmented a[aria-current="page"] { background: #fff; color: var(--text); box-shadow: 0 1px 2px rgba(24,36,51,.12); }
.period-custom { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.period-custom input, .period-custom select { min-height: 34px; padding: 4px 8px; font-size: 14px; width: auto; }
.period-label { margin: 10px 0 16px; }
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 20px; }
.kpi { display: flex; flex-direction: column; gap: 3px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 16px 18px; color: var(--text); text-decoration: none; min-width: 0; }
a.kpi:hover { border-color: var(--accent); color: var(--text); }
.kpi-main { grid-column: span 2; background: var(--ink); color: #fff; border-color: var(--ink); }
a.kpi-main:hover { color: #fff; border-color: var(--ink-2); }
.kpi-main .k-label, .kpi-main .k-sub, .kpi-main .muted { color: var(--ink-text); }
.kpi-main .k-value { font-size: 32px; }
.kpi-alert { border-color: #f1b8b1; }
.k-label { font-size: 13.5px; color: var(--muted); font-weight: 600; }
.k-value { font-size: 24px; font-weight: 800; letter-spacing: -.4px; font-variant-numeric: tabular-nums; line-height: 1.15; overflow-wrap: anywhere; }
.k-sub { font-size: 13px; font-variant-numeric: tabular-nums; }
.k-sub.late { color: var(--red); font-weight: 600; }
.var { font-weight: 700; }
.var.up { color: #1f9d63; } .kpi-main .var.up { color: #7fe0b4; }
.var.down { color: var(--red); } .kpi-main .var.down { color: #ffb4ab; }
svg.chart { width: 100%; height: auto; display: block; font-family: var(--font); }
svg.chart .grid { stroke: #e3e7ec; stroke-width: 1; }
svg.chart .grid.zero { stroke: #9aa5b1; }
svg.chart .axis { font-size: 11px; fill: #5b6775; }
svg.chart .legend { font-size: 12px; fill: #1c2530; }
svg.chart .bar-label { font-size: 13px; fill: #1c2530; }
svg.chart .bar-value { font-size: 12.5px; fill: #5b6775; font-variant-numeric: tabular-nums; }
.chart-data { margin-top: 10px; font-size: 14px; }
.chart-data summary, .definitions summary { cursor: pointer; color: var(--accent); font-weight: 600; }
.definitions { margin: 4px 0 20px; font-size: 14px; }
.definitions ul { margin: 8px 0 0; padding-left: 20px; color: var(--muted); }
tr.total-row td { background: #f6f8fa; }
.global-search { position: relative; width: min(340px, 36vw); }
.global-search input { min-height: 36px; padding: 6px 12px; font-size: 14px; background: #f6f8fa; }
.gs-results { position: absolute; right: 0; top: calc(100% + 6px); width: min(520px, 92vw); max-height: 70vh; overflow-y: auto; background: #fff; border: 1px solid var(--line-strong); border-radius: var(--radius-lg); box-shadow: 0 12px 32px rgba(24,36,51,.18); z-index: 30; padding: 6px; }
.gs-results h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); margin: 8px 10px 4px; }
.gs-results a, .search-results a { display: block; padding: 7px 10px; border-radius: 6px; text-decoration: none; color: var(--text); }
.gs-results a span, .search-results a span { display: block; color: var(--muted); font-size: 13px; }
.gs-results a:hover, .gs-results a[aria-selected="true"], .search-results a:hover { background: var(--accent-soft); }
.gs-results .gs-all { font-weight: 600; color: var(--accent); border-top: 1px solid var(--line); margin-top: 4px; }
.search-results { list-style: none; margin: 0; padding: 6px; }
kbd { border: 1px solid var(--line-strong); border-bottom-width: 2px; border-radius: 4px; padding: 0 5px; font-size: 12px; }
@media (max-width: 1080px) { .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 900px) {
  .global-search { width: 100%; order: 3; }
  .topbar { flex-wrap: wrap; }
  .kpis { grid-template-columns: 1fr 1fr; gap: 10px; }
  .kpi { padding: 12px 14px; }
  .k-value { font-size: 19px; }
  .kpi-main .k-value { font-size: 24px; }
}
@media (max-width: 480px) { .kpis { grid-template-columns: 1fr; } .kpi-main { grid-column: auto; } }
@media print { .kpi-main { background: #fff; color: #000; } }
.hbars { list-style: none; margin: 0; padding: 0; }
.hbars li { display: grid; grid-template-columns: minmax(90px, 32%) 1fr auto; gap: 10px; align-items: center; padding: 6px 0; font-size: 14px; }
.hb-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hb-track { background: #eef1f4; border-radius: 4px; height: 14px; overflow: hidden; }
.hb-bar { display: block; height: 100%; border-radius: 4px; }
.hb-value { font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; text-align: right; }
.hb-value small { display: block; font-weight: 400; color: var(--muted); font-size: 12px; }
@media print { .hb-bar { -webkit-print-color-adjust: exact; print-color-adjust: exact; } }
.chart-scroll { overflow-x: auto; }
.chart-scroll svg.chart { min-width: 560px; }

/* ---------- Phase 9 : corrections responsive issues du test automatisé ---------- */
.grid-wide-left { grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr); }
.count-line { flex-wrap: wrap; }
.count-line .num { white-space: normal; text-align: right; }
.stat { min-width: 0; }
.stat .value { overflow-wrap: anywhere; }
@media (max-width: 900px) {
  .grid-wide-left { grid-template-columns: 1fr; }
  .count-line { flex-direction: column; align-items: flex-start; gap: 4px; }
  .count-line .num { text-align: left; }
  .stat { padding: 12px 14px; }
  .stat .value { font-size: 17px; }
  .totals dd { white-space: normal; }
}
.tick-warn { background: var(--amber); color: #fff; }
.tick-err { background: var(--red); color: #fff; }
