/* Offres Borgeat — interface
   Mise en page : barre latérale de navigation + espace de travail ; l'éditeur d'offre a un panneau de totaux collant à droite. */
:root {
  --ink: #1b2033;
  --muted: #5d6480;
  --faint: #8a90a8;
  --bg: #f4f5f9;
  --surface: #ffffff;
  --sunk: #eef0f6;
  --line: #dde1ec;
  --line-strong: #c4cadb;
  --brand: #2b3f8f;          /* bleu de l'en-tête Borgeat */
  --brand-ink: #1e2d6b;
  --brand-soft: #e7ebf8;
  --ok: #1f7a4d;   --ok-soft: #e3f3ea;
  --warn: #9a5b00; --warn-soft: #fbf0dc;
  --bad: #b3261e;  --bad-soft: #fbe6e4;
  --neutral-soft: #eceef4;
  --radius: 6px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; font: 14px/1.45 var(--font); color: var(--ink); background: var(--bg); }
button, input, select, textarea { font: inherit; color: inherit; }
.boot { padding: 40px; color: var(--muted); }
[hidden] { display: none !important; }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }

/* ---------- Coquille ---------- */
.shell { display: grid; grid-template-columns: 210px 1fr; min-height: 100vh; }
.side { background: var(--brand-ink); color: #dfe4f7; display: flex; flex-direction: column; padding: 18px 12px; gap: 4px; position: sticky; top: 0; height: 100vh; }
.side .brand { font-weight: 700; letter-spacing: .06em; font-size: 15px; color: #fff; padding: 4px 10px 18px; }
.side .brand span { display: block; font-weight: 400; letter-spacing: 0; font-size: 12px; color: #aab4dd; }
.side a { color: inherit; text-decoration: none; padding: 8px 10px; border-radius: var(--radius); display: flex; justify-content: space-between; }
.side a:hover { background: rgba(255,255,255,.08); }
.side a.on { background: rgba(255,255,255,.16); color: #fff; font-weight: 600; }
.side .grow { flex: 1; }
.side .who { font-size: 12.5px; color: #aab4dd; padding: 8px 10px; border-top: 1px solid rgba(255,255,255,.12); }
.side .who button { background: none; border: 0; color: #fff; padding: 0; cursor: pointer; text-decoration: underline; }
main { min-width: 0; padding: 22px 28px 60px; }
.page-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head h1 { font-size: 20px; margin: 0; letter-spacing: -.01em; text-wrap: balance; }
.page-head .sp { flex: 1; }

/* ---------- Contrôles ---------- */
.btn { text-decoration: none; display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line-strong); background: var(--surface); padding: 6px 12px; border-radius: var(--radius); cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: var(--brand); color: var(--brand); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-ink); color: #fff; }
.btn.danger:hover { border-color: var(--bad); color: var(--bad); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--sunk); }
.btn.sm { padding: 3px 8px; font-size: 12.5px; }
.btn:disabled { opacity: .5; cursor: default; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=search], select, textarea {
  border: 1px solid var(--line-strong); background: var(--surface); border-radius: 4px; padding: 6px 8px; min-width: 0; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
textarea { resize: vertical; }
label.f { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; color: var(--muted); }
label.f > span { font-weight: 600; letter-spacing: .02em; }
label.chk { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 12px; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 12px; }
.grid4 { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 12px; }
.span2 { grid-column: span 2; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; }
.card-pad { padding: 16px; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.toolbar input[type=search] { max-width: 320px; }
.toolbar select { width: auto; }

/* ---------- Tableaux de listes ---------- */
.tbl-wrap { overflow-x: auto; }
table.list { width: 100%; border-collapse: collapse; }
table.list th { text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; padding: 10px 12px; border-bottom: 1px solid var(--line); background: var(--sunk); }
table.list td { padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.list tr:last-child td { border-bottom: 0; }
table.list tr.click { cursor: pointer; }
table.list tr.click:hover td { background: #f8f9fd; }
table.list .code { font-family: var(--mono); font-size: 12.5px; color: var(--muted); white-space: nowrap; }
.empty { padding: 40px 20px; text-align: center; color: var(--muted); }
.empty strong { display: block; color: var(--ink); font-size: 15px; margin-bottom: 4px; }

/* ---------- Statuts ---------- */
.pill { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: 12px; font-weight: 600; white-space: nowrap; border: 0; }
.st-brouillon { background: var(--neutral-soft); color: var(--muted); }
.st-envoyee { background: var(--warn-soft); color: var(--warn); }
.st-acceptee { background: var(--ok-soft); color: var(--ok); }
.st-refusee { background: var(--bad-soft); color: var(--bad); }
select.pill { width: auto; cursor: pointer; padding-right: 22px; appearance: auto; }
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; cursor: pointer; text-align: left; }
.stat.on { border-color: var(--brand); box-shadow: 0 0 0 2px var(--brand-soft); }
.stat .lbl { display: flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--muted); }
.stat .dot { width: 8px; height: 8px; border-radius: 50%; }
.stat .val { font-size: 20px; font-weight: 650; font-variant-numeric: tabular-nums; margin-top: 2px; }
.stat .sub { font-size: 12.5px; color: var(--muted); font-variant-numeric: tabular-nums; }

/* ---------- Éditeur d'offre ---------- */
.ed { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 18px; align-items: start; }
.ed-head { display: grid; grid-template-columns: 1.4fr 1fr; gap: 16px; }
.client-box { border: 1px dashed var(--line-strong); border-radius: 6px; padding: 10px 12px; font-size: 13.5px; min-height: 74px; position: relative; }
.client-box .addr { white-space: pre-line; padding-right: 150px; }
.cb-acts { position: absolute; top: 8px; right: 8px; display: flex; gap: 4px; }
.pick { position: relative; }
.pick .menu { position: absolute; left: 0; right: 0; top: calc(100% + 2px); background: var(--surface); border: 1px solid var(--line-strong); border-radius: 6px; box-shadow: 0 8px 24px rgba(20,30,70,.14); z-index: 30; max-height: 340px; overflow: auto; }
.pick .menu button { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 8px 12px; cursor: pointer; border-bottom: 1px solid var(--line); }
.pick .menu button:last-child { border-bottom: 0; }
.pick .menu button:hover, .pick .menu button.hl { background: var(--brand-soft); }
.pick .menu .m-row { display: flex; gap: 10px; align-items: baseline; }
.pick .menu .m-des { flex: 1; min-width: 0; }
.pick .menu .m-code { font-family: var(--mono); font-size: 12px; color: var(--muted); }

.items { margin-top: 16px; }
.items-head, .it { display: grid; grid-template-columns: 22px minmax(0, 1fr) 92px 58px 60px 84px 88px 76px; gap: 6px; align-items: start; }
.items-head { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--line); background: var(--sunk); border-radius: 8px 8px 0 0; }
.items-head .r { text-align: right; }
.it { padding: 6px 10px; border-bottom: 1px solid var(--line); background: var(--surface); }
.it:focus-within { background: #fafbff; }
.it.cur { box-shadow: inset 3px 0 0 var(--brand); }
.it input, .it select, .it textarea { padding: 4px 6px; font-size: 13.5px; }
.it textarea { min-height: 30px; height: 30px; overflow: hidden; resize: none; line-height: 1.35; }
.it .h { color: var(--faint); font-size: 12px; padding-top: 6px; cursor: grab; user-select: none; text-align: center; }
.it .mt { padding-top: 5px; font-weight: 600; }
.it .acts { display: flex; gap: 2px; justify-content: flex-end; padding-top: 2px; }
.it .acts button { border: 0; background: none; width: 20px; height: 24px; border-radius: 4px; cursor: pointer; color: var(--faint); padding: 0; font-size: 13px; }
.it .acts button:hover { background: var(--sunk); color: var(--ink); }
.it .acts button.del:hover { color: var(--bad); }
.it .flags { grid-column: 2 / span 5; display: flex; gap: 14px; flex-wrap: wrap; font-size: 12.5px; color: var(--muted); align-items: center; }
.it .flags input { width: 96px; }
.it .flags label { white-space: nowrap; }
.it .flags .marg { font-variant-numeric: tabular-nums; }
.it.var { background: repeating-linear-gradient(-45deg, #fff, #fff 8px, #f7f8fb 8px, #f7f8fb 16px); }
.it.var .mt { color: var(--muted); font-weight: 400; }
.it.mo .h::after { content: "h"; }

.it.sec { background: var(--brand-soft); grid-template-columns: 22px 70px 110px minmax(0,1fr) 40px 76px; border-bottom-color: #cfd6ef; }
.it.sec.n1 input.ti { font-weight: 700; font-size: 15px; }
.it.sec.n2 { background: #eef1fa; }
.it.sec.n2 input.ti { font-weight: 650; }
.it.sec.n3 { background: #f5f7fc; }
.it.sec input.ti { background: transparent; border-color: transparent; }
.it.sec input.ti:hover { border-color: var(--line-strong); }
.it.sec input.ti:focus { background: var(--surface); }
.it.tot { grid-template-columns: 22px minmax(0,1fr) 120px 76px; background: var(--surface); color: var(--muted); font-size: 12.5px; padding-top: 4px; padding-bottom: 8px; }
.it.tot .num { color: var(--ink); font-weight: 650; border-top: 1px solid var(--ink); padding-top: 2px; }
.it.tot.n1 { font-size: 13.5px; }
.ind-2 { padding-left: 18px !important; }
.ind-3 { padding-left: 34px !important; }

.addbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; padding: 12px 10px; background: var(--surface); border-radius: 0 0 8px 8px; }
.addbar .pick { flex: 1; min-width: 240px; }
.items-empty { padding: 26px 16px; color: var(--muted); background: var(--surface); text-align: center; border-bottom: 1px solid var(--line); }

.aside { position: sticky; top: 16px; display: flex; flex-direction: column; gap: 12px; }
.sum dl { margin: 0; display: grid; grid-template-columns: 1fr auto; gap: 6px 10px; }
.sum dt { color: var(--muted); }
.sum dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
.sum .ttc dt, .sum .ttc dd { font-weight: 700; font-size: 17px; color: var(--ink); padding-top: 8px; border-top: 1px solid var(--line); }
.sum h3, .recap h3 { font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0 0 10px; }
.recap ul { list-style: none; margin: 0; padding: 0; font-size: 12.5px; }
.recap li { display: flex; justify-content: space-between; gap: 8px; padding: 3px 0; border-bottom: 1px dotted var(--line); }
.recap li span:first-child { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.recap li.n1 { font-weight: 650; }
.recap li.n3 { padding-left: 10px; color: var(--muted); }
.meter { height: 6px; background: var(--sunk); border-radius: 3px; overflow: hidden; margin-top: 6px; }
.meter i { display: block; height: 100%; background: var(--ok); }
.dirty { font-size: 12.5px; color: var(--warn); }
.saved { font-size: 12.5px; color: var(--ok); }

/* ---------- Dialogues ---------- */
dialog { border: 0; border-radius: 10px; padding: 0; width: min(640px, calc(100vw - 32px)); box-shadow: 0 20px 60px rgba(15,25,60,.3); color: var(--ink); }
dialog.wide { width: min(980px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(20,28,60,.42); }
dialog .dh { padding: 16px 20px; border-bottom: 1px solid var(--line); font-weight: 650; font-size: 16px; display: flex; justify-content: space-between; align-items: center; }
dialog .db { padding: 18px 20px; display: flex; flex-direction: column; gap: 12px; max-height: 70vh; overflow: auto; }
dialog .df { padding: 12px 20px; border-top: 1px solid var(--line); display: flex; gap: 8px; justify-content: flex-end; background: var(--sunk); border-radius: 0 0 10px 10px; flex-wrap: wrap; }
dialog .df .sp { flex: 1; }
.preview-tbl { overflow: auto; max-height: 260px; border: 1px solid var(--line); border-radius: 6px; }
.preview-tbl table { border-collapse: collapse; font-size: 12px; }
.preview-tbl td, .preview-tbl th { padding: 4px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; max-width: 260px; overflow: hidden; text-overflow: ellipsis; }
.preview-tbl th { background: var(--sunk); position: sticky; top: 0; }
.note { background: var(--brand-soft); border-radius: 6px; padding: 10px 12px; font-size: 13px; color: var(--brand-ink); }
.err { background: var(--bad-soft); color: var(--bad); border-radius: 6px; padding: 8px 12px; font-size: 13px; }

/* ---------- Connexion ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login .card { width: min(380px, 100%); padding: 28px; display: flex; flex-direction: column; gap: 14px; }
.login img { width: 230px; max-width: 100%; margin: 0 auto 6px; display: block; }
.login h1 { font-size: 18px; margin: 0; text-align: center; }

#toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 8px; z-index: 100; box-shadow: 0 8px 30px rgba(0,0,0,.25); max-width: calc(100vw - 32px); }
#toast.bad { background: var(--bad); }

/* ---------- Écrans étroits ---------- */
@media (max-width: 1180px) {
  .ed { grid-template-columns: minmax(0, 1fr); }
  .aside { position: static; display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
}
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: sticky; z-index: 40; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 8px 12px; }
  .side .brand { padding: 4px 10px 4px 0; }
  .side .brand span, .side .grow { display: none; }
  .side .who { border: 0; margin-left: auto; padding: 4px; }
  main { padding: 16px; }
  .stats { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .grid3, .grid4 { grid-template-columns: 1fr 1fr; }
  .ed-head { grid-template-columns: 1fr; }
  .client-box .addr { padding-right: 0; }
  .cb-acts { position: static; margin-top: 8px; }
  .items-head { display: none; }
  .it { grid-template-columns: 22px repeat(4, minmax(0,1fr)); }
  .it > .des { grid-column: 2 / -1; }
  .it .acts { grid-column: 2 / -1; justify-content: flex-start; }
  .it .flags { grid-column: 2 / -1; }
  .it.sec { grid-template-columns: 22px 64px 1fr; }
  .it.sec .ti { grid-column: 2 / -1; }
  .it.sec .num, .it.sec .acts { grid-column: 2 / -1; text-align: left; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
.it:not(.cur):not(:focus-within) .flags { display: none; }
