:root {
  --brand: #0F4C5C;
  --brand-600: #0d4250;
  --brand-50: #e8f2f3;
  --brand-100: #cfe5e7;
  --accent: #2a9d8f;
  --ink: #1d2430;
  --ink-2: #3b4452;
  --muted: #6b7380;
  --line: #e3e7ec;
  --bg: #f5f7f9;
  --card: #ffffff;
  --danger: #c0392b;
  --danger-50: #fdecea;
  --warn: #b7791f;
  --warn-50: #fff7e6;
  --ok: #1e8e5a;
  --ok-50: #e7f6ee;
  --info-50: #eef4fb;
  --info: #2b6cb0;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .08);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, .14);
  --sidebar: 248px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
  font-size: 15px;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0 0 .5rem; letter-spacing: -.01em; }
h1 { font-size: 1.55rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1.02rem; }
p { margin: 0 0 .75rem; line-height: 1.5; }
small, .muted { color: var(--muted); }
.boot { display: grid; place-items: center; height: 100vh; color: var(--muted); }
code { background: #f0f2f5; padding: 1px 5px; border-radius: 4px; font-size: .88em; }

/* ---------- layout ---------- */
.shell { display: grid; grid-template-columns: var(--sidebar) 1fr; min-height: 100vh; }
.sidebar { background: var(--brand); color: #fff; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 10px; padding: 20px 20px 16px; font-weight: 700; font-size: 1.05rem; letter-spacing: .02em; }
.brand img { max-height: 34px; max-width: 120px; background: #fff; border-radius: 6px; padding: 3px; }
.brand .logo-mark { width: 34px; height: 34px; border-radius: 9px; background: rgba(255,255,255,.14); display: grid; place-items: center; font-size: .8rem; }
.brand small { display: block; color: rgba(255,255,255,.65); font-weight: 500; font-size: .72rem; letter-spacing: .06em; text-transform: uppercase; }
.nav { padding: 8px 10px; display: flex; flex-direction: column; gap: 2px; flex: 1; overflow-y: auto; }
.nav a { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 9px; color: rgba(255,255,255,.82); font-weight: 500; font-size: .94rem; }
.nav a:hover { background: rgba(255,255,255,.08); color: #fff; text-decoration: none; }
.nav a.active { background: rgba(255,255,255,.16); color: #fff; }
.nav a.cta { background: #fff; color: var(--brand); margin: 6px 0 10px; justify-content: center; font-weight: 700; }
.nav a.cta:hover { background: var(--brand-50); }
.nav svg { width: 18px; height: 18px; flex-shrink: 0; }
.side-foot { padding: 14px 18px; border-top: 1px solid rgba(255,255,255,.12); font-size: .85rem; }
.side-foot .who { font-weight: 600; }
.side-foot .role { color: rgba(255,255,255,.65); font-size: .78rem; }
.side-foot button { margin-top: 8px; background: transparent; border: 1px solid rgba(255,255,255,.3); color: #fff; border-radius: 8px; padding: 5px 10px; cursor: pointer; font-size: .8rem; }
.main { min-width: 0; }
.topbar { display: none; }
.content { padding: 28px 32px 60px; max-width: 1240px; margin: 0 auto; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head p { margin: 2px 0 0; color: var(--muted); }

/* ---------- cards / grid ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; }
.card + .card { margin-top: 16px; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 12px; }
.card-head h2, .card-head h3 { margin: 0; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.span2 { grid-column: span 2; }
.span-all { grid-column: 1 / -1; }
.stat { padding: 16px 18px; }
.stat .v { font-size: 1.6rem; font-weight: 700; margin-top: 4px; }
.stat .l { color: var(--muted); font-size: .82rem; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.between { justify-content: space-between; }
.stack > * + * { margin-top: 12px; }
.hr { height: 1px; background: var(--line); margin: 16px 0; }

/* ---------- buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid var(--line); background: #fff; color: var(--ink); border-radius: 9px; padding: 9px 14px; font: inherit; font-weight: 600; font-size: .9rem; cursor: pointer; white-space: nowrap; transition: background .12s, border-color .12s, box-shadow .12s; }
.btn:hover { background: #f6f8fa; text-decoration: none; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-600); }
.btn.accent { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { color: var(--danger); border-color: #f1c4bf; }
.btn.danger:hover { background: var(--danger-50); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: #eef1f4; }
.btn.sm { padding: 6px 10px; font-size: .82rem; border-radius: 8px; }
.btn.lg { padding: 12px 20px; font-size: 1rem; }
.btn svg { width: 16px; height: 16px; }
.btn-group { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- forms ---------- */
label.f { display: flex; flex-direction: column; gap: 6px; font-size: .84rem; font-weight: 600; color: var(--ink-2); }
label.f .hint { font-weight: 400; color: var(--muted); font-size: .78rem; }
input, select, textarea { font: inherit; font-size: .93rem; color: var(--ink); background: #fff; border: 1px solid #cfd6de; border-radius: 9px; padding: 9px 11px; width: 100%; transition: border-color .12s, box-shadow .12s; }
textarea { min-height: 84px; resize: vertical; line-height: 1.45; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(15, 76, 92, .14); }
input.invalid, select.invalid, textarea.invalid { border-color: var(--danger); background: #fffafa; }
input[type=checkbox], input[type=radio] { width: auto; accent-color: var(--brand); }
.check { display: flex; gap: 10px; align-items: flex-start; font-size: .9rem; line-height: 1.4; cursor: pointer; }
.check input { margin-top: 3px; }
.check small { display: block; }
.star { color: var(--danger); margin-left: 2px; }
.field-ok { color: var(--ok); font-size: .78rem; font-weight: 600; }
.field-ko { color: var(--danger); font-size: .78rem; font-weight: 600; }
.search { position: relative; }
.search input { padding-left: 36px; }
.search svg { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); width: 17px; color: var(--muted); }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; }
table.t { width: 100%; border-collapse: collapse; font-size: .9rem; }
table.t th { text-align: left; font-size: .74rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 700; padding: 11px 14px; background: #fafbfc; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.t td { padding: 12px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.t tr:last-child td { border-bottom: 0; }
table.t tr.click { cursor: pointer; }
table.t tr.click:hover td { background: #f8fafb; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.empty { text-align: center; color: var(--muted); padding: 40px 16px; }

/* ---------- badges / alerts ---------- */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; border-radius: 999px; font-size: .75rem; font-weight: 700; white-space: nowrap; background: #eef1f4; color: var(--ink-2); }
.badge.B2B { background: #e8eefc; color: #2c4fa3; }
.badge.B2C { background: #f3e9fb; color: #7a3fa8; }
.s-BROUILLON { background: #eef1f4; color: #4a5361; }
.s-EN_VALIDATION { background: var(--warn-50); color: var(--warn); }
.s-ENVOYE { background: var(--info-50); color: var(--info); }
.s-EN_SIGNATURE { background: #fff1e0; color: #c05621; }
.s-SIGNE { background: var(--ok-50); color: var(--ok); }
.s-ACTIF { background: #d9f2e6; color: #13734a; }
.s-ECHU { background: #f1f1f1; color: #6b6b6b; }
.s-RESILIE { background: var(--danger-50); color: var(--danger); }
.s-ARCHIVE { background: #ececec; color: #777; }
.alert { border-radius: 10px; padding: 12px 14px; font-size: .9rem; display: flex; gap: 10px; align-items: flex-start; line-height: 1.45; border: 1px solid transparent; }
.alert + .alert { margin-top: 8px; }
.alert svg { width: 18px; height: 18px; flex-shrink: 0; margin-top: 1px; }
.alert.bloquant, .alert.danger { background: var(--danger-50); color: #8f2a1f; border-color: #f6cdc8; }
.alert.avertissement, .alert.warning, .alert.warn { background: var(--warn-50); color: #7a4f12; border-color: #f7e1b5; }
.alert.info { background: var(--info-50); color: #1f4f82; border-color: #d3e3f5; }
.alert.ok { background: var(--ok-50); color: #156342; border-color: #c4e9d6; }
.alert.urgent { background: var(--danger-50); color: #8f2a1f; border-color: #f6cdc8; }
.config-banner { background: linear-gradient(90deg, #fff7e6, #fffaf0); border: 1px dashed #e8c37a; color: #6b4a10; border-radius: 10px; padding: 10px 14px; font-size: .88rem; display: flex; gap: 10px; align-items: center; }
.config-banner svg { width: 18px; flex-shrink: 0; }

/* ---------- wizard ---------- */
.steps { display: flex; align-items: center; gap: 0; margin: 4px 0 22px; overflow-x: auto; padding-bottom: 4px; }
.step { display: flex; align-items: center; gap: 9px; color: var(--muted); font-weight: 600; font-size: .9rem; white-space: nowrap; }
.step .dot { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; background: #fff; border: 2px solid var(--line); font-size: .85rem; }
.step.done .dot { background: var(--brand); border-color: var(--brand); color: #fff; }
.step.current { color: var(--ink); }
.step.current .dot { border-color: var(--brand); color: var(--brand); box-shadow: 0 0 0 4px rgba(15,76,92,.12); }
.step-bar { flex: 1; min-width: 26px; height: 2px; background: var(--line); margin: 0 10px; }
.step-bar.done { background: var(--brand); }
.choice-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.choice { border: 2px solid var(--line); border-radius: 16px; padding: 24px; background: #fff; cursor: pointer; text-align: left; font: inherit; color: inherit; transition: border-color .15s, box-shadow .15s, transform .15s; display: flex; flex-direction: column; gap: 8px; }
.choice:hover { border-color: var(--brand-100); box-shadow: var(--shadow-lg); transform: translateY(-1px); }
.choice.sel { border-color: var(--brand); box-shadow: 0 0 0 4px rgba(15,76,92,.1); }
.choice .ic { width: 46px; height: 46px; border-radius: 12px; display: grid; place-items: center; background: var(--brand-50); color: var(--brand); }
.choice .ic svg { width: 24px; height: 24px; }
.choice h3 { font-size: 1.15rem; margin: 6px 0 0; }
.choice p { color: var(--muted); margin: 0; font-size: .9rem; }
.wizard-foot { position: sticky; bottom: 0; background: rgba(245,247,249,.92); backdrop-filter: blur(6px); padding: 14px 0; margin-top: 18px; display: flex; justify-content: space-between; gap: 10px; border-top: 1px solid var(--line); z-index: 5; }
.svc-cat { margin-bottom: 14px; }
.svc-cat h4 { font-size: .78rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0 0 8px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { border: 1px solid #cfd6de; background: #fff; border-radius: 999px; padding: 7px 13px; font: inherit; font-size: .86rem; cursor: pointer; color: var(--ink-2); }
.chip:hover { border-color: var(--brand); color: var(--brand); }
.chip.on { background: var(--brand); border-color: var(--brand); color: #fff; }
.line-card { border: 1px solid var(--line); border-radius: 12px; background: #fff; padding: 16px; position: relative; }
.line-card + .line-card { margin-top: 12px; }
.line-card .lc-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 12px; }
.line-card .lc-total { font-weight: 700; font-variant-numeric: tabular-nums; }
.totals-bar { display: flex; justify-content: flex-end; gap: 22px; padding: 14px 16px; background: var(--brand-50); border-radius: 10px; margin-top: 12px; font-variant-numeric: tabular-nums; flex-wrap: wrap; }
.totals-bar b { font-size: 1.05rem; }
.company-card { border: 1px solid var(--brand-100); background: linear-gradient(180deg, #f6fbfb, #fff); border-radius: 12px; padding: 16px; }
.kv { display: grid; grid-template-columns: 170px 1fr; gap: 6px 14px; font-size: .9rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 500; }
.section-title { font-size: .76rem; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); font-weight: 700; margin: 18px 0 10px; }

/* ---------- document preview ---------- */
.paper { background: #fff; max-width: 860px; margin: 0 auto; padding: 48px 56px; border-radius: 6px; box-shadow: var(--shadow-lg); font-family: Georgia, "Times New Roman", serif; color: #222; font-size: 14.5px; line-height: 1.58; }
.paper .ph { display: flex; justify-content: space-between; gap: 20px; align-items: flex-start; margin-bottom: 26px; }
.paper .ph img { max-height: 60px; max-width: 170px; }
.paper .ph .co { text-align: right; font-family: -apple-system, Segoe UI, sans-serif; font-size: 11.5px; color: #666; line-height: 1.5; }
.paper .ph .co-name { font: 700 20px -apple-system, Segoe UI, sans-serif; color: var(--brand); }
.paper .ptitle { background: var(--brand); color: #fff; text-align: center; padding: 16px; border-radius: 4px; font-family: -apple-system, Segoe UI, sans-serif; }
.paper .ptitle h2 { color: #fff; margin: 0; font-size: 18px; text-transform: uppercase; letter-spacing: .02em; }
.paper .ptitle div { font-size: 12px; opacity: .85; margin-top: 4px; }
.paper h3.sec { font-family: -apple-system, Segoe UI, sans-serif; color: var(--brand); border-bottom: 1.5px solid var(--brand); padding-bottom: 4px; margin: 28px 0 14px; font-size: 15px; }
.paper h4 { font-family: -apple-system, Segoe UI, sans-serif; color: var(--brand); font-size: 14px; margin: 20px 0 6px; }
.paper p { white-space: pre-line; margin: 0 0 9px; text-align: justify; }
.paper ul { margin: 0 0 10px; padding-left: 22px; }
.paper .kt { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; font-family: -apple-system, Segoe UI, sans-serif; }
.paper .kt div { background: #f3f5f7; padding: 8px 12px; border-radius: 4px; font-size: 13px; }
.paper .kt span { display: block; font-size: 10px; text-transform: uppercase; color: #777; font-weight: 700; letter-spacing: .04em; }
.paper table { width: 100%; border-collapse: collapse; margin-top: 14px; font-family: -apple-system, Segoe UI, sans-serif; font-size: 12.5px; }
.paper th { background: var(--brand); color: #fff; padding: 7px 8px; text-align: left; font-size: 11.5px; }
.paper td { padding: 8px; border-bottom: 1px solid #e3e3e3; vertical-align: top; }
.paper td .d { color: #777; font-size: 11.5px; margin-top: 3px; line-height: 1.4; }
.paper .tot { margin-left: auto; width: 270px; margin-top: 10px; font-family: -apple-system, Segoe UI, sans-serif; font-size: 13px; }
.paper .tot div { display: flex; justify-content: space-between; padding: 4px 10px; }
.paper .tot .g { background: var(--brand); color: #fff; font-weight: 700; border-radius: 3px; }
.paper .sigs { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: 18px; font-family: -apple-system, Segoe UI, sans-serif; font-size: 13px; }
.paper .sigs > div { border: 1px solid #ccc; padding: 12px; min-height: 140px; border-radius: 4px; }
.paper .sigs b { color: var(--brand); }
.paper .annex { border-top: 2px dashed #ddd; margin-top: 30px; padding-top: 8px; }
.doc-layout { display: grid; grid-template-columns: minmax(0, 1fr) 330px; gap: 20px; align-items: start; }
.doc-side { position: sticky; top: 16px; }
.doc-side .card { padding: 16px; }
.actions-list { display: flex; flex-direction: column; gap: 8px; }
.actions-list .btn { justify-content: flex-start; }
.timeline { list-style: none; padding: 0; margin: 0; font-size: .85rem; }
.timeline li { padding: 8px 0 8px 18px; border-left: 2px solid var(--line); position: relative; }
.timeline li::before { content: ""; position: absolute; left: -6px; top: 13px; width: 10px; height: 10px; border-radius: 50%; background: var(--brand-100); border: 2px solid #fff; }
.timeline .when { color: var(--muted); font-size: .76rem; }
.issues-box { max-height: 340px; overflow-y: auto; }

/* ---------- tabs ---------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 18px; overflow-x: auto; }
.tabs button { background: none; border: 0; padding: 10px 14px; font: inherit; font-weight: 600; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs button.on { color: var(--brand); border-bottom-color: var(--brand); }

/* ---------- modal / toast ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(16, 24, 40, .45); display: grid; place-items: center; z-index: 50; padding: 16px; animation: fade .15s; }
.modal { background: #fff; border-radius: 14px; box-shadow: var(--shadow-lg); width: min(640px, 100%); max-height: 90vh; overflow-y: auto; padding: 22px; }
.modal.wide { width: min(980px, 100%); }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
#toasts { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 60; }
.toast { background: var(--ink); color: #fff; padding: 11px 16px; border-radius: 10px; box-shadow: var(--shadow-lg); font-size: .9rem; max-width: 420px; animation: slide .2s; }
.toast.err { background: var(--danger); }
.toast.ok { background: var(--ok); }
@keyframes fade { from { opacity: 0; } }
@keyframes slide { from { transform: translateY(10px); opacity: 0; } }

/* ---------- auth ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; background: linear-gradient(135deg, var(--brand) 0%, #146a7a 55%, var(--accent) 100%); padding: 16px; }
.auth .card { width: min(420px, 100%); padding: 32px; box-shadow: var(--shadow-lg); }
.auth h1 { color: var(--brand); }

.spinner { width: 16px; height: 16px; border: 2px solid rgba(255,255,255,.4); border-top-color: #fff; border-radius: 50%; animation: spin .7s linear infinite; }
.btn:not(.primary):not(.accent) .spinner { border-color: rgba(0,0,0,.15); border-top-color: var(--brand); }
@keyframes spin { to { transform: rotate(360deg); } }
.tpl-body { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .84rem; min-height: 320px; }
.pill-cond { font-family: ui-monospace, Menlo, monospace; font-size: .74rem; background: #f1f3f5; border-radius: 5px; padding: 1px 6px; margin-right: 4px; }

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
  .doc-layout { grid-template-columns: minmax(0, 1fr); }
  .doc-side { position: static; }
  .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 860px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: 272px; transform: translateX(-100%); transition: transform .2s; z-index: 40; }
  .shell.nav-open .sidebar { transform: none; box-shadow: var(--shadow-lg); }
  .shell.nav-open::after { content: ""; position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 30; }
  .topbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 14px; background: var(--brand); color: #fff; position: sticky; top: 0; z-index: 20; }
  .topbar button { background: transparent; border: 0; color: #fff; padding: 6px; cursor: pointer; }
  .topbar svg { width: 24px; height: 24px; }
  .topbar a.btn { background: #fff; color: var(--brand); border: 0; }
  .content { padding: 18px 14px 80px; }
  .g2, .g3, .g4, .choice-grid { grid-template-columns: minmax(0, 1fr); }
  .paper table { display: block; overflow-x: auto; }
  .page-head h1 { font-size: 1.3rem; }
  .span2 { grid-column: auto; }
  .paper { padding: 24px 18px; font-size: 13.5px; }
  .paper .kt, .paper .sigs { grid-template-columns: 1fr; }
  .kv { grid-template-columns: 1fr; }
  .kv dt { margin-top: 6px; }
  table.t.responsive thead { display: none; }
  table.t.responsive tr { display: block; border-bottom: 1px solid var(--line); padding: 8px 4px; }
  table.t.responsive td { display: flex; justify-content: space-between; gap: 10px; border: 0; padding: 4px 10px; text-align: right; }
  table.t.responsive td::before { content: attr(data-l); color: var(--muted); font-size: .78rem; font-weight: 600; text-align: left; }
}
@media print {
  .sidebar, .topbar, .page-head, .doc-side, .wizard-foot { display: none !important; }
  .shell { display: block; }
  .content { padding: 0; }
  .paper { box-shadow: none; }
}
