/* Facturation CMA — interface et documents A4 */
:root {
  --ink: #181716;        /* noir chaud CMA */
  --teal: #0082A4;       /* bleu pétrole CMA */
  --teal-d: #00627C;
  --teal-l: #E2F1F6;
  --steel: #5E6A71;
  --line: #D6DCDF;
  --bg: #EDF0F1;
  --paper: #FFFFFF;
  --ok: #2E7A53;
  --warn: #9A620C;
  --bad: #B42318;
  --f: 'Barlow', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --fc: 'Barlow Semi Condensed', 'Barlow', system-ui, sans-serif;
}
* { box-sizing: border-box; }
html { font-size: 15px; }
body { margin: 0; font-family: var(--f); color: var(--ink); background: var(--bg); line-height: 1.45; font-variant-numeric: tabular-nums; }
a { color: var(--teal-d); }
a:hover { color: var(--ink); }
h1, h2, h3 { font-family: var(--fc); font-weight: 600; margin: 0; line-height: 1.2; }
h2 { font-size: 1.2rem; margin-bottom: .8rem; }
h3 { font-size: 1.02rem; margin: 1.2rem 0 .6rem; color: var(--steel); }
small, .small { font-size: .82rem; color: var(--steel); }
.muted, tr.muted td { color: var(--steel); }
:focus-visible { outline: 2px solid var(--teal); outline-offset: 2px; }

/* ------------------------------------------------ Structure */
.shell { display: grid; grid-template-columns: 224px 1fr; min-height: 100vh; }
.side { background: var(--ink); color: #C9CED0; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 10px; padding: 22px 20px 20px; color: #fff; text-decoration: none; font-family: var(--fc); font-size: 1.5rem; font-weight: 700; letter-spacing: .02em; }
.brand .beam { color: var(--teal); flex: none; }
.brand small { display: block; font-family: var(--f); font-weight: 500; font-size: .8rem; letter-spacing: 0; color: #9AA3A7; margin-top: 1px; }
.brand span { line-height: 1; }
.side nav { display: flex; flex-direction: column; padding: 6px 0; flex: 1; }
.side nav a { color: #C9CED0; text-decoration: none; padding: 9px 20px 9px 17px; border-left: 3px solid transparent; font-weight: 500; }
.side nav a:hover { color: #fff; background: #242220; }
.side nav a.on { color: #fff; border-left-color: var(--teal); background: #22201F; }
.me { padding: 16px 20px 20px; border-top: 1px solid #2E2C2A; font-size: .85rem; }
.me span { display: block; color: #fff; font-weight: 600; }
.me small { display: block; color: #8D969A; margin-bottom: 6px; }
.me a { color: #C9CED0; }
.navtoggle { display: none; }
.main { padding: 26px 32px 60px; min-width: 0; max-width: 1480px; }

.ph { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.ph h1 { font-size: 1.95rem; }
.ph h1 .sub { display: block; font-family: var(--f); font-size: 1rem; font-weight: 500; color: var(--steel); margin-top: 4px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
form.inline { display: inline-flex; gap: 8px; align-items: center; margin: 0; }

/* ------------------------------------------------ Boutons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; font: 600 .93rem var(--f); padding: 7px 14px; border: 1px solid #B9C1C5; background: var(--paper); color: var(--ink); border-radius: 3px; cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { border-color: var(--ink); color: var(--ink); }
.btn.primary { background: var(--teal); border-color: var(--teal); color: #fff; }
.btn.primary:hover { background: var(--teal-d); border-color: var(--teal-d); color: #fff; }
.btn.danger { color: var(--bad); border-color: #E3B7B2; }
.btn.danger:hover { background: var(--bad); color: #fff; border-color: var(--bad); }
.btn.small { padding: 4px 10px; font-size: .85rem; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.tbl form.inline select { min-width: 130px; }
.btn.wide { width: 100%; }
.link { background: none; border: 0; padding: 0; font: inherit; color: var(--teal-d); text-decoration: underline; cursor: pointer; }
.link.danger { color: var(--bad); font-size: .8rem; }

/* ------------------------------------------------ Messages */
.flash { padding: 10px 14px; border-radius: 3px; margin: 0 0 14px; border-left: 4px solid; background: var(--paper); }
.flash.ok { border-color: var(--ok); color: #1F5A3C; background: #EAF5EF; }
.flash.err { border-color: var(--bad); color: #8A1B12; background: #FCEDEB; }
.flash.warn { border-color: #D39B2A; color: #6E4608; background: #FDF5E4; }
.hint { color: var(--steel); font-size: .9rem; margin: .2rem 0 .8rem; max-width: 80ch; }
.empty { color: var(--steel); margin: .4rem 0; }

/* ------------------------------------------------ Poutre d'indicateurs */
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); background: var(--paper); border-top: 5px solid var(--ink); border-bottom: 5px solid var(--ink); margin-bottom: 20px; }
.kpis > div { padding: 14px 18px 12px; border-left: 1px solid var(--line); }
.kpis > div:first-child { border-left: 0; }
.kpis span { display: block; color: var(--steel); font-size: .88rem; font-weight: 500; }
.kpis strong { display: block; font-family: var(--fc); font-size: 1.75rem; font-weight: 600; line-height: 1.15; margin-top: 2px; }
.kpis em { font-style: normal; font-size: .82rem; color: var(--steel); }
.kpis .alert strong { color: var(--bad); }

/* ------------------------------------------------ Panneaux */
.panel { background: var(--paper); border: 1px solid var(--line); border-radius: 3px; padding: 18px 20px; margin-bottom: 18px; }
.panel-h { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.panel-h h2 { margin: 0; }
.panel-h .total { color: var(--steel); }
.panel-h .total strong { color: var(--ink); font-family: var(--fc); font-size: 1.2rem; }
details.panel > summary { cursor: pointer; list-style: none; }
details.panel > summary::-webkit-details-marker { display: none; }
details.panel > summary h2 { display: inline; margin: 0; }
details.panel > summary::before { content: '+'; display: inline-block; width: 1.2em; font-weight: 700; color: var(--teal); }
details.panel[open] > summary::before { content: '–'; }
details.panel[open] > summary { margin-bottom: 14px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; align-items: start; }
.grid2 > .panel { margin-bottom: 0; }
.grid2 + * { margin-top: 18px; }
.narrow { max-width: 520px; }
.panel.todo { border-left: 4px solid var(--teal); }
.panel.todo ul { margin: 0; padding-left: 20px; }
.panel.todo li { padding: 3px 0; font-weight: 500; }
pre.code { background: #F3F5F6; border: 1px solid var(--line); border-radius: 3px; padding: 10px 12px; overflow-x: auto; font-size: .85rem; margin: 4px 0 12px; }
.chk.inline { display: inline-flex; padding: 0; font-size: .85rem; gap: 4px; }
.tbl form.inline select, .tbl form.inline .btn { margin-right: 2px; }
.tag { display: inline-block; font-size: .72rem; font-weight: 600; padding: 1px 6px; border-radius: 2px; background: var(--teal-l); color: var(--teal-d); vertical-align: 1px; }

/* ------------------------------------------------ Histogramme */
.bars { display: grid; grid-template-columns: repeat(12, 1fr); gap: 6px; height: 190px; align-items: end; }
.bar { position: relative; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; height: 100%; }
.bar i { display: block; width: 70%; background: var(--teal); min-height: 1px; }
.bar i.bad { background: var(--bad); }
.bars.prev { grid-template-columns: repeat(5, 1fr); height: 150px; }
.bar span { font-size: .78rem; color: var(--steel); margin-top: 4px; height: 16px; }
.bar b { order: -1; margin-bottom: 2px; font-size: .72rem; font-weight: 600; color: var(--steel); }

/* ------------------------------------------------ Tableaux */
.tblwrap { overflow-x: auto; }
.tbl { width: 100%; border-collapse: collapse; }
.tbl th { text-align: left; font-weight: 600; font-size: .85rem; color: var(--steel); padding: 7px 8px; border-bottom: 2px solid var(--ink); white-space: nowrap; }
.tbl td { padding: 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.tbl tbody tr:hover td { background: #F7F9F9; }
.tbl tfoot td { font-weight: 600; border-top: 2px solid var(--ink); border-bottom: 0; }
.tbl .r, .r { text-align: right; }
.nw { white-space: nowrap; }
.tbl tr.late td:first-child { box-shadow: inset 3px 0 0 var(--bad); }
.prog { min-width: 170px; }
.meter { height: 7px; background: #E3E7E9; margin: 6px 0 3px; }
.meter i { display: block; height: 100%; background: var(--teal); }

.badge { display: inline-block; font-size: .8rem; font-weight: 600; padding: 2px 8px; border-radius: 10px; white-space: nowrap; }
.b-brouillon { background: #ECEEEF; color: var(--steel); }
.b-attente { background: var(--teal-l); color: var(--teal-d); }
.b-partielle { background: #FDF1D8; color: var(--warn); }
.b-retard { background: #FCE4E1; color: var(--bad); }
.b-payee { background: #E3F2E9; color: var(--ok); }

/* ------------------------------------------------ Formulaires */
fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
.form h2 { margin-top: .2rem; }
.form fieldset h2 { margin-top: 1.4rem; }
.form fieldset h2:first-child { margin-top: 0; }
.cols h3.sep { grid-column: 1 / -1; margin: 10px 0 0; padding-top: 8px; border-top: 1px solid var(--line); font-size: .95rem; color: var(--teal-d); }
.cols h3.sep:first-child { border-top: 0; padding-top: 0; margin-top: 0; }
.cols { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 12px 16px; margin-bottom: 8px; }
.fld { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.fld.wide, .chk.wide { grid-column: span 2; }
.fld > span { font-size: .85rem; font-weight: 500; color: var(--steel); }
.fld > em { font-style: normal; font-size: .8rem; color: var(--steel); }
input, select, textarea { font: inherit; color: var(--ink); background: #fff; border: 1px solid #C3CACE; border-radius: 3px; padding: 7px 9px; min-width: 0; width: 100%; }
input:focus, select:focus, textarea:focus { border-color: var(--teal); outline: 2px solid var(--teal-l); }
input[type=checkbox] { width: auto; accent-color: var(--teal); }
input[type=file] { padding: 5px; }
textarea { resize: vertical; }
.chk { display: flex; align-items: center; gap: 8px; font-weight: 500; padding-top: 22px; }
.cols > .chk { white-space: nowrap; }
.pjbox .chk, .form.compact .chk, .chk.inline { padding-top: 0; white-space: normal; }
.formbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-top: 14px; }
.formbar select { width: auto; }
.formbar.sticky { position: sticky; bottom: 0; background: rgba(237, 240, 241, .95); padding: 12px 0; margin-top: 0; border-top: 1px solid var(--line); z-index: 5; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.filters select, .filters input { width: auto; }
.filters input[type=search] { min-width: 240px; }
.form.compact .fld { margin-bottom: 8px; }
.exports { display: flex; gap: 10px; flex-wrap: wrap; margin: 6px 0 12px; }
.checks { list-style: none; padding: 0; margin: 0 0 16px; }
.checks li { padding: 3px 0; }
.checks .ok { color: var(--ok); } .checks .ko { color: var(--bad); font-weight: 600; }
.logoprev { max-height: 48px; max-width: 200px; margin-top: 6px; background: #fff; }

/* ------------------------------------------------ Éditeurs de lignes */
.lines td { padding: 4px 5px; vertical-align: middle; }
.lines input, .lines select, .lines textarea { padding: 5px 7px; }
.lines textarea { min-height: 32px; line-height: 1.35; }
.lines .n { text-align: right; width: 108px; }
.lines .u { width: 58px; }
.lines .code { width: 78px; }
.lines select { width: auto; }
.lines td.q { width: 1%; white-space: nowrap; }
.dpgf td:nth-child(5), .fact td:nth-child(3) { min-width: 260px; }
.sit td:nth-child(2) { width: 30%; min-width: 180px; }
.lines .mvc { white-space: nowrap; width: 1%; }
.mv, .del { border: 0; background: none; cursor: pointer; color: #9AA3A7; font-size: .75rem; padding: 4px 3px; }
.del { font-size: 1.25rem; line-height: 1; }
.mv:hover { color: var(--ink); } .del:hover { color: var(--bad); }
.lines tr.t-titre td, .lines tr.t-texte td { background: #F3F5F6; }
.lines tr.t-titre textarea { font-weight: 600; }
.lines tr.t-texte textarea { font-style: italic; }
.lines tr.t-titre .q > *, .lines tr.t-texte .q > *, .lines tr.t-titre td.q, .lines tr.t-texte td.q { visibility: hidden; }
.dpgf tr.o-ts td:first-child { box-shadow: inset 3px 0 0 var(--teal); }
.sit tr.t-titre td { font-weight: 600; background: #F3F5F6; }
.sit tr.sep td { background: var(--teal-l); color: var(--teal-d); font-weight: 600; }
.sit .n { width: 82px; }
.sit input.over { color: var(--bad); border-color: var(--bad); }
.sit td[data-out] { white-space: nowrap; }
.paste { margin-top: 18px; border-top: 1px solid var(--line); padding-top: 12px; }
.paste summary { cursor: pointer; font-weight: 600; color: var(--teal-d); }
.paste textarea { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .85rem; }

.calc { display: grid; grid-template-columns: 1fr auto; gap: 6px 18px; margin: 0; }
.calc dt { color: var(--steel); }
.calc dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
.calc .strong { color: var(--ink); font-weight: 600; }
.calc .net { color: var(--ink); font-weight: 700; font-family: var(--fc); font-size: 1.3rem; border-top: 2px solid var(--ink); padding-top: 6px; }
.calc.right { max-width: 360px; margin: 16px 0 0 auto; }
output.ro { display: block; padding: 7px 9px; border: 1px solid var(--line); border-radius: 3px; background: #F3F5F6; font-weight: 600; }

/* ------------------------------------------------ Fiche document */
.docview { display: grid; grid-template-columns: minmax(0, 1fr) 330px; gap: 18px; align-items: start; }
.paper { background: #C9D0D4; padding: 22px; overflow: auto; border-radius: 3px; }
.paper .sheet { box-shadow: 0 1px 3px rgba(24, 23, 22, .25); zoom: .8; }
@media (min-width: 1700px) { .paper .sheet { zoom: 1; } }
.links h2 { color: var(--ink); }
.links p { margin: 0 0 6px; font-size: .9rem; }
.docside .panel { margin-bottom: 14px; }
.docside .state { margin-bottom: 10px; }
.pjbox { border: 1px solid var(--line); border-radius: 3px; padding: 10px 14px; margin: 4px 0 14px; }
.pjbox legend { font-size: .85rem; font-weight: 600; color: var(--steel); padding: 0 6px; }
.pjbox .chk { padding: 3px 0; }
.pays { list-style: none; padding: 0; margin: 0 0 12px; }
.pays li { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 4px 10px; padding: 7px 0; border-bottom: 1px solid var(--line); font-size: .9rem; }
.pays li span { color: var(--steel); }
.pays li form { width: 100%; text-align: right; }

/* ------------------------------------------------ Connexion / installation */
body.login { display: grid; place-items: center; min-height: 100vh; padding: 20px; background: var(--ink); }
.loginbox { width: 100%; max-width: 380px; background: var(--paper); padding: 30px; border-top: 6px solid var(--teal); display: flex; flex-direction: column; gap: 14px; }
.loginbox.wide { max-width: 760px; }
.loginbox .brand { color: var(--ink); padding: 0 0 8px; }
.loginbox .brand small { color: var(--steel); }
.loginbox h1 { font-size: 1.8rem; }
.loginbox h2 { margin-top: 1rem; }

/* ------------------------------------------------ Document A4 */
.sheet { width: 210mm; min-height: 297mm; margin: 0 auto; background: #fff; color: #181716; padding: 16mm 10mm 12mm 18mm; font: 9.5pt/1.35 Arial, Helvetica, sans-serif; display: flex; flex-direction: column; position: relative; font-variant-numeric: tabular-nums; }
.sheet.draft::before { content: 'BROUILLON'; position: absolute; top: 40%; left: 0; right: 0; text-align: center; font: 700 88pt Arial, sans-serif; color: rgba(180, 35, 24, .08); transform: rotate(-28deg); pointer-events: none; }
.s-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10mm; margin-bottom: 8mm; }
.s-logo img { max-height: 22mm; max-width: 80mm; display: block; }
.s-logo strong { font-size: 15pt; color: #0082A4; }
.s-slogan { text-align: right; color: #0082A4; font-size: 9pt; font-weight: 700; }
.s-top { display: grid; grid-template-columns: 1fr 82mm; gap: 8mm; margin-bottom: 6mm; }
.s-title h1 { font: 700 16pt Arial, sans-serif; color: #0082A4; margin: 0 0 1mm; }
.s-num { font-weight: 700; font-size: 11pt; margin: 0 0 3mm; }
.s-meta { border-collapse: collapse; }
.s-meta th { text-align: left; font-weight: 400; color: #5E6A71; padding: 0 5mm 0.6mm 0; }
.s-meta td { padding: 0 0 0.6mm; font-weight: 700; }
.s-client { border: 0.3mm solid #181716; padding: 4mm 5mm; font-size: 10pt; line-height: 1.4; align-self: start; }
.s-client small { display: block; margin-top: 2mm; font-size: 8pt; color: #5E6A71; }
.s-ref { border-left: 1mm solid #0082A4; padding: 1.5mm 4mm; margin-bottom: 5mm; background: #F1F7F9; }
.s-ref b { display: inline-block; min-width: 30mm; font-weight: 400; color: #5E6A71; }
.s-lines { width: 100%; border-collapse: collapse; margin-bottom: 5mm; font-size: 8.8pt; }
.s-lines th { background: #181716; color: #fff; font-weight: 700; padding: 1.6mm 2mm; text-align: left; }
.s-lines td { padding: 1.3mm 2mm; border-bottom: 0.2mm solid #D6DCDF; vertical-align: top; }
.s-lines .r { text-align: right; white-space: nowrap; }
.s-lines .c { text-align: center; }
.s-lines tr.t td { font-weight: 700; background: #E6EEF1; }
.s-lines tr.t2 td { font-weight: 700; }
.s-lines tr.x td { font-style: italic; color: #3C4449; }
.s-lines tr.z td { color: #98A1A6; }
.s-lines tfoot td { font-weight: 700; border-top: 0.4mm solid #181716; border-bottom: 0; }
.s-lines thead { display: table-header-group; }
.s-lines tr { page-break-inside: avoid; }
.s-h3 { font: 700 10pt Arial, sans-serif; color: #0082A4; margin: 2mm 0 2mm; }
.s-totals { width: 95mm; margin: 0 0 5mm auto; border-collapse: collapse; font-size: 9.5pt; page-break-inside: avoid; }
.s-totals th { text-align: left; font-weight: 400; padding: 1.1mm 2mm; }
.s-totals td { text-align: right; padding: 1.1mm 2mm; white-space: nowrap; }
.s-totals tr.sub th, .s-totals tr.sub td { font-weight: 700; border-top: 0.2mm solid #181716; }
.s-totals tr.grand th, .s-totals tr.grand td { background: #0082A4; color: #fff; font-weight: 700; font-size: 11pt; padding: 2mm; }
.s-accord { margin: 5mm 0 0 auto; width: 85mm; }
.s-accord small { display: block; color: #5E6A71; font-size: 7pt; margin: 0.5mm 0 1mm; }
.s-cadre { border: 0.3mm solid #181716; height: 26mm; }
.s-mentions { font-size: 8.5pt; page-break-inside: avoid; }
.s-mentions p { margin: 0 0 1.8mm; }
.s-mentions .small { font-size: 7.5pt; color: #5E6A71; }
.s-foot { margin-top: auto; padding-top: 5mm; font-size: 7.5pt; text-align: center; color: #181716; }
.s-foot .band { background: #0082A4; color: #fff; padding: 1.2mm 3mm; margin-top: 1.5mm; }

body.print { background: #C9D0D4; padding: 70px 0 30px; }
.printbar { position: fixed; top: 0; left: 0; right: 0; background: var(--ink); color: #C9CED0; padding: 12px 20px; display: flex; gap: 16px; align-items: center; font-size: .88rem; z-index: 10; }

@page { size: A4; margin: 12mm 10mm 12mm 18mm; }
@media print {
  body, body.print { background: #fff; padding: 0; }
  .printbar, .side, .ph, .docside { display: none !important; }
  .sheet { box-shadow: none; margin: 0; width: auto; min-height: 270mm; padding: 0; zoom: 1 !important; }
  .sheet.draft::before { position: fixed; }
  .s-foot { break-inside: avoid; page-break-inside: avoid; }
}

/* ------------------------------------------------ Responsive */
@media (max-width: 1100px) {
  .docview { grid-template-columns: 1fr; }
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .kpis > div:nth-child(3) { border-left: 0; }
  .kpis > div:nth-child(n+3) { border-top: 1px solid var(--line); }
}
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: static; height: auto; }
  .side nav, .me { display: none; }
  body.navopen .side nav, body.navopen .me { display: flex; }
  body.navopen .me { display: block; }
  .brand { padding: 14px 16px; }
  .navtoggle { display: block; position: absolute; top: 14px; right: 16px; background: none; color: #fff; border: 1px solid #55504C; border-radius: 3px; padding: 6px 12px; font: 600 .9rem var(--f); }
  .side { position: relative; }
  .main { padding: 18px 14px 50px; }
  .grid2 { grid-template-columns: 1fr; }
  .fld.wide, .chk.wide { grid-column: auto; }
  .ph h1 { font-size: 1.6rem; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
