:root {
  --brand: #0f5c8c;
  --brand-dark: #0a4468;
  --brand-soft: #e8f1f7;
  --ink: #1b2430;
  --muted: #5f6b7a;
  --line: #dde3ea;
  --bg: #f4f6f9;
  --card: #ffffff;
  --green: #1d7a46; --green-soft: #e3f4ea;
  --orange: #b25e00; --orange-soft: #fdf0e0;
  --red: #b3261e; --red-soft: #fbe7e6;
  --blue: #1f5fa8; --blue-soft: #e5eefa;
  --grey-soft: #eceff3;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif; color: var(--ink); background: var(--bg); }
a { color: var(--brand); }
h1 { font-size: 1.55rem; margin: 0 0 .25rem; letter-spacing: -.01em; }
h2 { font-size: 1.12rem; margin: 0 0 .75rem; }
h3 { font-size: 1rem; margin: 1rem 0 .5rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .8rem; word-break: break-all; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }

/* ---------- barre du haut ---------- */
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 1rem; padding: 0 1rem; height: 56px; background: var(--brand); color: #fff; box-shadow: 0 2px 6px rgba(0,0,0,.12); }
.brand { display: flex; align-items: center; gap: .5rem; color: #fff; text-decoration: none; font-weight: 700; white-space: nowrap; }
.brand-mark { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 8px; background: #fff; color: var(--brand); font-weight: 800; }
.mainnav { display: flex; gap: .15rem; overflow-x: auto; scrollbar-width: none; flex: 1; }
.mainnav::-webkit-scrollbar { display: none; }
.mainnav a { color: rgba(255,255,255,.85); text-decoration: none; padding: .45rem .75rem; border-radius: 7px; white-space: nowrap; font-weight: 500; }
.mainnav a:hover { background: rgba(255,255,255,.12); color: #fff; }
.mainnav a.active { background: #fff; color: var(--brand); }
.usermenu { display: flex; align-items: center; gap: .6rem; white-space: nowrap; }
.usermenu a { color: #fff; text-decoration: none; font-size: .9rem; max-width: 160px; overflow: hidden; text-overflow: ellipsis; }
.usermenu form { margin: 0; }
.linkbtn { background: none; border: 1px solid rgba(255,255,255,.5); color: #fff; border-radius: 6px; padding: .25rem .6rem; cursor: pointer; font: inherit; font-size: .85rem; }
@media (max-width: 760px) {
  .topbar { flex-wrap: wrap; height: auto; padding: .5rem .75rem 0; gap: .4rem .75rem; }
  .mainnav { order: 3; flex-basis: 100%; padding-bottom: .4rem; }
  .usermenu { margin-left: auto; }
  .usermenu a { display: none; }
}

/* ---------- mise en page ---------- */
.container { max-width: 1180px; margin: 0 auto; padding: 1.25rem 1rem 3rem; }
.narrow { max-width: 760px; margin: 0 auto; padding: 1.25rem 1rem 3rem; }
.pagehead { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: .75rem; margin-bottom: 1.25rem; }
.pagehead .actions { display: flex; flex-wrap: wrap; gap: .5rem; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.1rem 1.2rem; margin-bottom: 1rem; }
.card > h2:first-child { margin-top: 0; }
.grid { display: grid; gap: 1rem; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.stack > * + * { margin-top: .75rem; }
.row { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }

/* ---------- tuiles ---------- */
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.1rem; box-shadow: var(--shadow); text-decoration: none; color: inherit; display: block; }
.stat .label { color: var(--muted); font-size: .85rem; }
.stat .value { font-size: 1.6rem; font-weight: 700; margin-top: .15rem; font-variant-numeric: tabular-nums; }
.stat .sub { font-size: .85rem; color: var(--muted); }
.meter { height: 10px; border-radius: 99px; background: var(--grey-soft); overflow: hidden; margin: .5rem 0 .25rem; }
.meter > span { display: block; height: 100%; background: var(--brand); }
.meter.warn > span { background: var(--orange); }
.meter.danger > span { background: var(--red); }

/* ---------- tableaux ---------- */
.tablewrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.list { width: 100%; border-collapse: collapse; }
table.list th { text-align: left; font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; padding: .55rem .6rem; border-bottom: 2px solid var(--line); white-space: nowrap; }
table.list td { padding: .6rem; border-bottom: 1px solid var(--line); vertical-align: top; }
table.list tr.clickable { cursor: pointer; }
table.list tr.clickable:hover td { background: var(--brand-soft); }
table.list td.num, table.list th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.empty { text-align: center; padding: 2rem 1rem; color: var(--muted); }

/* ---------- badges ---------- */
.badge { display: inline-block; padding: .12rem .55rem; border-radius: 99px; font-size: .78rem; font-weight: 600; white-space: nowrap; }
.badge-grey { background: var(--grey-soft); color: var(--muted); }
.badge-blue { background: var(--blue-soft); color: var(--blue); }
.badge-green { background: var(--green-soft); color: var(--green); }
.badge-orange { background: var(--orange-soft); color: var(--orange); }
.badge-red { background: var(--red-soft); color: var(--red); }

/* ---------- boutons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; padding: .55rem 1rem; border-radius: 8px; border: 1px solid var(--line); background: #fff; color: var(--ink); font: inherit; font-weight: 600; text-decoration: none; cursor: pointer; min-height: 40px; }
.btn:hover { border-color: #b9c3cf; background: #f9fafb; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); border-color: var(--brand-dark); }
.btn-success { background: var(--green); border-color: var(--green); color: #fff; }
.btn-success:hover { filter: brightness(.95); background: var(--green); }
.btn-danger { color: var(--red); border-color: #f0c4c1; }
.btn-danger:hover { background: var(--red-soft); }
.btn-sm { padding: .3rem .65rem; min-height: 32px; font-size: .85rem; }
.btn-lg { padding: .8rem 1.4rem; font-size: 1.05rem; min-height: 50px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
form.inline { display: inline; margin: 0; }

/* ---------- formulaires ---------- */
label { display: block; font-weight: 600; font-size: .88rem; margin-bottom: .25rem; }
.field { margin-bottom: .9rem; }
.hint { font-size: .8rem; color: var(--muted); margin-top: .2rem; font-weight: 400; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=tel], input[type=search], input[type=url], select, textarea {
  width: 100%; padding: .55rem .7rem; border: 1px solid #c9d1db; border-radius: 8px; font: inherit; background: #fff; color: var(--ink); min-height: 42px;
}
textarea { min-height: 90px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(15,92,140,.25); border-color: var(--brand); }
.checkline { display: flex; align-items: center; gap: .55rem; font-weight: 500; cursor: pointer; }
.checkline input { width: 20px; height: 20px; accent-color: var(--brand); }
.formgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 0 1rem; }
.formactions { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: 1rem; }
.searchbar { display: flex; gap: .5rem; margin-bottom: 1rem; }
.searchbar input { flex: 1; }
.filters { display: flex; flex-wrap: wrap; gap: .35rem; margin-bottom: 1rem; }
.filters a { padding: .3rem .75rem; border-radius: 99px; background: #fff; border: 1px solid var(--line); text-decoration: none; color: var(--muted); font-size: .88rem; }
.filters a.active { background: var(--brand); border-color: var(--brand); color: #fff; }

/* ---------- messages ---------- */
.flash { padding: .75rem 1rem; border-radius: 8px; margin-bottom: 1rem; border: 1px solid; }
.flash-success { background: var(--green-soft); border-color: #b9e0c8; color: #14532d; }
.flash-error { background: var(--red-soft); border-color: #f2c2be; color: #7f1d1d; }
.notice { padding: .8rem 1rem; border-radius: 8px; background: var(--brand-soft); border: 1px solid #c8dceb; margin-bottom: 1rem; }
.notice.warn { background: var(--orange-soft); border-color: #f2d3ad; }
.notice.ok { background: var(--green-soft); border-color: #b9e0c8; }
.notice.bad { background: var(--red-soft); border-color: #f2c2be; }

/* ---------- éditeur de lignes ---------- */
.lines-table { width: 100%; border-collapse: collapse; }
.lines-table th { text-align: left; font-size: .78rem; color: var(--muted); padding: .35rem; text-transform: uppercase; }
.lines-table td { padding: .3rem; vertical-align: top; }
.lines-table td input, .lines-table td textarea { min-height: 38px; padding: .4rem .5rem; }
.lines-table td textarea { min-height: 38px; height: 38px; font-size: .88rem; }
.lines-table .c-qty { width: 80px; } .lines-table .c-unit { width: 110px; } .lines-table .c-price { width: 120px; } .lines-table .c-total { width: 120px; text-align: right; padding-top: .7rem; font-variant-numeric: tabular-nums; white-space: nowrap; } .lines-table .c-act { width: 44px; }
.iconbtn { width: 36px; height: 36px; border-radius: 8px; border: 1px solid var(--line); background: #fff; cursor: pointer; font-size: 1.1rem; color: var(--muted); }
.iconbtn:hover { color: var(--red); border-color: #f0c4c1; }
.totals-box { margin-left: auto; max-width: 340px; margin-top: 1rem; }
.totals-box div { display: flex; justify-content: space-between; padding: .25rem 0; font-variant-numeric: tabular-nums; }
.totals-box .grand { border-top: 2px solid var(--brand); margin-top: .3rem; padding-top: .45rem; font-weight: 700; font-size: 1.1rem; }
.catalog-picker { display: flex; gap: .5rem; flex-wrap: wrap; margin: .75rem 0; }
.catalog-picker select { flex: 1; min-width: 220px; }
@media (max-width: 760px) {
  .lines-table thead { display: none; }
  .lines-table, .lines-table tbody, .lines-table tr, .lines-table td { display: block; width: 100% !important; }
  .lines-table tr { border: 1px solid var(--line); border-radius: 8px; padding: .5rem; margin-bottom: .6rem; display: grid; grid-template-columns: 1fr 1fr; gap: .25rem; }
  .lines-table td.c-label { grid-column: 1 / -1; }
  .lines-table td.c-total { text-align: left; }
  .lines-table td::before { content: attr(data-label); display: block; font-size: .72rem; color: var(--muted); text-transform: uppercase; }
}

/* ---------- PV ---------- */
.pv-section { margin-bottom: 1.25rem; }
.pv-section h3 { margin: 0 0 .5rem; color: var(--brand); display: flex; justify-content: space-between; align-items: baseline; gap: .5rem; }
.pv-item { display: grid; grid-template-columns: 34px 1fr; gap: .1rem .5rem; align-items: start; padding: .55rem .2rem; border-bottom: 1px solid var(--line); }
.pv-item input[type=checkbox] { width: 26px; height: 26px; margin: 0; accent-color: var(--green); }
.pv-item .lbl { font-weight: 500; padding-top: .15rem; cursor: pointer; }
.pv-item .extra { grid-column: 2; display: flex; gap: .5rem; align-items: center; }
.pv-item .extra input[type=text] { min-height: 34px; padding: .3rem .5rem; font-size: .88rem; }
.pv-item .extra .del { white-space: nowrap; font-size: .8rem; color: var(--muted); display: flex; gap: .25rem; align-items: center; font-weight: 400; margin: 0; }
.pv-item.readonly { grid-template-columns: 30px 1fr; }
.mark { font-size: 1.25rem; line-height: 1; }
.mark.yes { color: var(--green); } .mark.no { color: #a0a9b4; }
.progress-txt { font-size: .85rem; color: var(--muted); font-weight: 400; }
.add-item input { min-height: 36px; }

/* ---------- signature ---------- */
.sigpad-wrap { border: 2px dashed #b9c3cf; border-radius: 10px; background: #fff; position: relative; touch-action: none; }
.sigpad-wrap canvas { display: block; width: 100%; height: 220px; border-radius: 10px; cursor: crosshair; }
.sigpad-wrap .placeholder { position: absolute; inset: 0; display: grid; place-items: center; color: #a0a9b4; pointer-events: none; font-size: 1.05rem; }
.sigpad-wrap.signed .placeholder { display: none; }
.sigpad-wrap.signed { border-style: solid; border-color: var(--brand); }
.sig-img { max-width: 260px; max-height: 110px; border: 1px solid var(--line); border-radius: 6px; background: #fff; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { padding: .5rem 0 .5rem 1.1rem; border-left: 2px solid var(--line); position: relative; font-size: .9rem; }
.timeline li::before { content: ""; position: absolute; left: -6px; top: .85rem; width: 10px; height: 10px; border-radius: 50%; background: var(--brand); }
.timeline .when { color: var(--muted); font-size: .8rem; }

/* ---------- pages publiques ---------- */
.public-head { background: var(--brand); color: #fff; padding: 1rem; text-align: center; }
.public-head img { max-height: 48px; background: #fff; border-radius: 6px; padding: 4px 8px; }
.public-head .name { font-weight: 700; font-size: 1.15rem; }
.doc-paper { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 1.2rem; box-shadow: var(--shadow); }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: .25rem 1rem; font-size: .92rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 500; }
.login-box { max-width: 380px; margin: 8vh auto 0; }
.login-box .brand-mark { width: 52px; height: 52px; font-size: 1.6rem; margin: 0 auto .75rem; background: var(--brand); color: #fff; border-radius: 14px; }
pre.template-help { background: var(--grey-soft); padding: .75rem; border-radius: 8px; font-size: .85rem; white-space: pre-wrap; }
details summary { cursor: pointer; font-weight: 600; }
.tabs { display: flex; gap: .25rem; border-bottom: 2px solid var(--line); margin-bottom: 1rem; overflow-x: auto; }
.tabs a { padding: .55rem .9rem; text-decoration: none; color: var(--muted); font-weight: 600; border-bottom: 3px solid transparent; margin-bottom: -2px; white-space: nowrap; }
.tabs a.active { color: var(--brand); border-color: var(--brand); }

/* 1.1.3 – CGV */
.terms h1 { font-size: 1.25rem; }
.terms h2 { font-size: 1rem; margin: 1.1rem 0 .35rem; }
.terms p { margin: 0 0 .5rem; line-height: 1.5; }
.terms .terms-li { margin: 0 0 .25rem .8rem; }
textarea.terms-editor { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .85rem; line-height: 1.45; min-height: 60vh; }
.checkline input { flex: none; }

/* 1.1.4 – Site web */
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 900px) { .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.stat .up { color: #15803d; font-weight: 600; } .stat .down { color: #b91c1c; font-weight: 600; }
.barchart { display: flex; align-items: flex-end; gap: 2px; height: 170px; border-bottom: 1px solid var(--line); padding-top: .5rem; }
.barchart .bar { position: relative; flex: 1; height: 100%; min-width: 2px; }
.barchart .bar span { position: absolute; bottom: 0; left: 0; right: 0; border-radius: 3px 3px 0 0; }
.barchart .views { background: #c7dbe9; }
.barchart .visitors { background: var(--brand); left: 18% !important; right: 18% !important; }
.legend { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin: 0 .25rem 0 .7rem; vertical-align: -1px; }
.legend.views { background: #c7dbe9; } .legend.visitors { background: var(--brand); }
.hbar { display: grid; grid-template-columns: 9rem 1fr 3rem; align-items: center; gap: .6rem; padding: .3rem 0; font-size: .9rem; }
.hbar .lbl { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hbar .track { height: 10px; background: #eef2f6; border-radius: 99px; overflow: hidden; }
.hbar .track span { display: block; height: 100%; background: var(--brand); border-radius: 99px; }
.hbar .num { text-align: right; font-variant-numeric: tabular-nums; }
.grid-2x { grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (max-width: 760px) { .grid-2x { grid-template-columns: 1fr; } }
