/* ============================================================
   BC Facturation Web — charte Building Conception
   bleu marine #244565 / gris #626366 — mobile first
   ============================================================ */
:root {
  --navy: #244565;
  --navy-dark: #1a3249;
  --grey: #626366;
  --bg: #f2f4f7;
  --card: #ffffff;
  --line: #dfe3e8;
  --danger: #b3382c;
  --ok: #2e7d4f;
}
* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { font-size: 16px; }
body {
  font-family: -apple-system, "Helvetica Neue", Helvetica, Arial, sans-serif;
  background: var(--bg); color: #2b2f33;
  min-height: 100vh;
}
.hidden { display: none !important; }
.flex { flex: 1; }

/* ---------- boutons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  border: 1px solid var(--line); background: #fff; color: var(--navy);
  border-radius: .55rem; padding: .55rem .9rem;
  font-size: .95rem; font-weight: 600; cursor: pointer; text-decoration: none;
}
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--navy); border-color: var(--navy); color: #fff; }
.btn.primary.dark { background: var(--navy-dark); border-color: var(--navy-dark); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--navy); }
.btn.danger { background: #fff; border-color: var(--danger); color: var(--danger); }
.btn.big { width: 100%; padding: .8rem; font-size: 1.05rem; }
.btn.block { width: 100%; margin-top: .6rem; }
.btn.small { padding: .3rem .55rem; font-size: .85rem; }
.btn.chip { border-radius: 2rem; font-size: .8rem; padding: .3rem .7rem; }

/* ---------- login ---------- */
#view-login { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--navy); padding: 1rem; }
.login-box { background: var(--card); border-radius: 1rem; padding: 2rem 1.5rem; width: 100%; max-width: 22rem; text-align: center; box-shadow: 0 10px 40px rgba(0,0,0,.3); }
.login-box img { max-height: 3.2rem; max-width: 70%; margin-bottom: .8rem; }
.login-box h1 { font-size: 1.25rem; color: var(--navy); margin-bottom: 1.2rem; }
.login-box .input { width: 100%; margin-bottom: 1rem; }
.err-msg { color: var(--danger); font-size: .85rem; margin-top: .6rem; min-height: 1.2em; }

/* ---------- structure ---------- */
#app { max-width: 60rem; margin: 0 auto; min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: .6rem;
  background: var(--navy); color: #fff; padding: .6rem .9rem;
  position: sticky; top: 0; z-index: 10;
}
.topbar img { height: 1.9rem; background: #fff; border-radius: .25rem; padding: .15rem .35rem; }
.topbar-title { font-weight: 700; font-size: 1.02rem; flex: 1; }
.topbar .btn.ghost { color: #fff; }
.topbar-num { font-size: .8rem; opacity: .8; }
.tabs { display: flex; background: #fff; border-bottom: 1px solid var(--line); position: sticky; top: 3.1rem; z-index: 9; }
.tab { flex: 1; padding: .75rem .3rem; background: none; border: none; font-size: .95rem; font-weight: 600; color: var(--grey); border-bottom: 3px solid transparent; cursor: pointer; }
.tab.active { color: var(--navy); border-bottom-color: var(--navy); }
main { flex: 1; padding: .9rem; }

/* ---------- inputs ---------- */
.input, input.input, select.input {
  width: 100%; padding: .6rem .7rem; font-size: 1rem;
  border: 1px solid var(--line); border-radius: .55rem; background: #fff;
  font-family: inherit;
}
.input.slim { width: auto; min-width: 7rem; padding: .45rem .6rem; font-size: .95rem; }
label { display: block; font-size: .85rem; font-weight: 600; color: var(--grey); margin: .55rem 0 .15rem; }
label .input { margin-top: .2rem; font-weight: 400; color: #2b2f33; }

/* ---------- listes ---------- */
.row-actions { display: flex; align-items: center; gap: .5rem; margin-bottom: .8rem; flex-wrap: wrap; }
.summary-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(8.5rem, 1fr)); gap: .5rem; margin-bottom: .9rem; }
.sum-card { background: #fff; border: 1px solid var(--line); border-top: 3px solid var(--navy); border-radius: .55rem; padding: .55rem .7rem; }
.sum-card .v { font-weight: 800; color: var(--navy); font-size: 1.05rem; }
.sum-card .l { font-size: .72rem; color: var(--grey); text-transform: uppercase; letter-spacing: .03em; }
.cards { display: flex; flex-direction: column; gap: .55rem; }
.doc-card { background: #fff; border: 1px solid var(--line); border-radius: .6rem; padding: .7rem .8rem; cursor: pointer; }
.doc-card:active { background: #f6f8fa; }
.doc-head { display: flex; align-items: baseline; gap: .5rem; }
.doc-num { font-weight: 800; color: var(--navy); }
.doc-kind { font-size: .72rem; font-weight: 700; text-transform: uppercase; padding: .12rem .45rem; border-radius: 1rem; }
.doc-kind.devis { background: #e8eef5; color: var(--navy); }
.doc-kind.facture { background: #e5f0e9; color: var(--ok); }
.doc-client { font-size: .92rem; color: #444; margin-top: .15rem; }
.doc-foot { display: flex; align-items: center; gap: .5rem; margin-top: .4rem; font-size: .85rem; }
.doc-ttc { font-weight: 700; }
.doc-status { font-size: .75rem; padding: .1rem .5rem; border-radius: 1rem; background: #eef1f4; color: var(--grey); }
.doc-status.payee, .doc-status.accepte { background: #e5f0e9; color: var(--ok); }
.doc-status.aencaisser, .doc-status.attente { background: #fdf3e3; color: #92600a; }

/* ---------- éditeur ---------- */
#editor, #client-editor { position: fixed; inset: 0; background: var(--bg); z-index: 20; overflow-y: auto; max-width: 60rem; margin: 0 auto; }
.editor-body { padding: .9rem; padding-bottom: 3rem; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; }
.lines-title, .ded-title { font-weight: 700; color: var(--navy); margin: .9rem 0 .3rem; font-size: .95rem; }
.line-row { display: grid; grid-template-columns: 1fr 4.4rem 4.6rem 5.6rem 2rem; gap: .35rem; margin-bottom: .4rem; align-items: center; }
.line-row .input { padding: .5rem .45rem; font-size: .92rem; }
.line-row .del { background: none; border: none; color: var(--danger); font-size: 1.2rem; cursor: pointer; }
.totals { background: #fff; border: 1px solid var(--line); border-radius: .6rem; padding: .7rem .9rem; margin-top: .9rem; }
.tot-row { display: flex; justify-content: space-between; padding: .18rem 0; font-size: .95rem; }
.tot-row.grand { font-weight: 800; color: var(--navy); font-size: 1.08rem; border-top: 1px solid var(--line); margin-top: .35rem; padding-top: .45rem; }
.editor-actions { display: flex; align-items: center; gap: .4rem; margin-top: 1.1rem; flex-wrap: wrap; }
.ded-item { display: flex; align-items: center; gap: .5rem; background: #fff; border: 1px solid var(--line); border-radius: .5rem; padding: .5rem .6rem; margin-bottom: .35rem; font-size: .9rem; }
.ded-item input[type=checkbox] { width: 1.1rem; height: 1.1rem; }
.ded-item .amt { margin-left: auto; font-weight: 600; color: var(--navy); }

/* ---------- toast ---------- */
#toast { position: fixed; left: 50%; bottom: 1.4rem; transform: translateX(-50%) translateY(200%); background: #2b2f33; color: #fff; padding: .65rem 1.1rem; border-radius: .6rem; font-size: .92rem; transition: transform .25s; z-index: 99; max-width: 90vw; text-align: center; }
#toast.show { transform: translateX(-50%) translateY(0); }
#toast.err { background: var(--danger); }

/* ============================================================
   DOCUMENT IMPRIMÉ (devis/facture officiels — charte BC)
   ============================================================ */
#print-area { display: none; }
@media print {
  body > *:not(#print-area) { display: none !important; }
  #print-area { display: block !important; }
  body { background: #fff; }
}
#print-area .doc-devis, #print-area .doc-facture {
  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; color: #1c1e20;
  font-size: 10.5pt; line-height: 1.35; padding: 2mm 1mm; max-width: 190mm; margin: 0 auto;
}
#print-area .logo { height: 14mm; }
#print-area .addr { text-align: right; font-size: 8.5pt; color: #444; margin-top: 1mm; }
#print-area .bar { border-bottom: 2.5px solid #244565; margin: 3mm 0; }
#print-area .cols { display: flex; justify-content: space-between; gap: 8mm; }
#print-area .cols3 { display: flex; justify-content: space-between; }
#print-area .date { font-weight: 700; }
#print-area .client { font-size: 10pt; }
#print-area .attn { margin: 3mm 0; font-size: 9.5pt; color: #333; }
#print-area .attn .who { font-weight: 700; }
#print-area .mail { color: #244565; }
#print-area .num-banner { background: #244565; color: #fff; font-weight: 800; letter-spacing: .06em; text-align: center; padding: 2mm; margin: 4mm 0; font-size: 12pt; }
#print-area .num-plain { font-weight: 800; letter-spacing: .05em; font-size: 13pt; margin: 2mm 0; text-align: center; }
#print-area .concern-box { display: flex; border: 1px solid #999; margin: 3mm 0; }
#print-area .concern-box .c1 { background: #e8e8e8; padding: 2mm 3mm; font-weight: 700; border-right: 1px solid #999; }
#print-area .concern-box .c2 { padding: 2mm 3mm; flex: 1; }
#print-area .concern-plain { margin: 2mm 0; font-weight: 600; }
#print-area .concern-plain .c2 { font-weight: 400; color: #444; }
#print-area table.dt { width: 100%; border-collapse: collapse; margin: 2mm 0; }
#print-area table.dt th { background: #244565; color: #fff; padding: 1.8mm 2mm; font-size: 9pt; text-align: left; }
#print-area table.dt th.ctr, #print-area table.dt td.ctr { text-align: center; }
#print-area table.dt th.num, #print-area table.dt td.num { text-align: right; }
#print-area table.dt td { border: 1px solid #bbb; padding: 1.6mm 2mm; vertical-align: top; }
#print-area table.dt tr.ded td { color: #555; font-style: italic; }
#print-area table.dt tfoot td { border: none; }
#print-area .tot-row { display: flex; justify-content: space-between; padding: .6mm 0; }
#print-area .tot-row.sep { border-top: 1px solid #999; }
#print-area .tot-row.grand { font-weight: 800; font-size: 11.5pt; border-top: 2px solid #244565; border-bottom: 2px solid #244565; margin: 1mm 0; padding: 1.2mm 0; }
#print-area .politesse { font-size: 9pt; margin: 5mm 0; font-style: italic; color: #333; }
#print-area .sign { margin-top: 6mm; font-size: 9.5pt; }
#print-area .sign .co { font-weight: 800; color: #244565; }
#print-area .payable { font-weight: 700; margin: 3mm 0; }
#print-area .bank { font-size: 9pt; border-top: 1px solid #999; padding-top: 2mm; margin-top: 4mm; }
#print-area .bank .b1 { font-weight: 700; margin: 1mm 0; }
#print-area .bank-table { width: 100%; border-collapse: collapse; }
#print-area .bank-table td { border: 1px solid #999; padding: 1.6mm 2mm; }
#print-area .bank-table .tva { text-align: right; }
#print-area .sheet-facture { border: 1.5px solid #244565; padding: 6mm 7mm; }

@media (min-width: 700px) {
  .editor-body, main { padding: 1.2rem; }
}
