:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --ink: #1c2434;
  --muted: #5b6474;
  --faint: #8a93a3;
  --line: #e3e6ec;
  --accent: #ea580c;
  --accent-dark: #c2410c;
  --accent-soft: #fff1e6;
  --side: #1c2434;
  --side-ink: #c9cfdb;
  --green: #15803d; --green-soft: #e8f6ec;
  --red: #b91c1c; --red-soft: #fdecec;
  --amber: #a16207; --amber-soft: #fdf5dc;
  --blue: #1d4ed8; --blue-soft: #e8eefd;
  --gray-soft: #eef0f3;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(28, 36, 52, .06), 0 2px 8px rgba(28, 36, 52, .04);
  color-scheme: light;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
a { color: var(--accent-dark); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .6em; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.1rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 .8em; }
small, .muted { color: var(--muted); }
.faint { color: var(--faint); }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; text-align: right; }
.nowrap { white-space: nowrap; }
.pre { white-space: pre-line; }
hr { border: 0; border-top: 1px solid var(--line); margin: 1.2rem 0; }

/* ---------- Structure ---------- */
.shell { display: flex; min-height: 100vh; }
.side {
  width: 236px; flex: none; background: var(--side); color: var(--side-ink);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: .6rem; padding: 1.1rem 1.2rem; color: #fff; font-weight: 800; font-size: 1.15rem; letter-spacing: .02em; }
.brand:hover { text-decoration: none; }
.brand .mark { width: 32px; height: 32px; border-radius: 9px; background: var(--accent); display: grid; place-items: center; }
.brand .mark svg { width: 20px; height: 20px; stroke: #fff; fill: none; stroke-width: 2.2; }
.side nav { padding: .3rem .6rem; display: flex; flex-direction: column; gap: 2px; }
.side nav a {
  display: flex; align-items: center; gap: .7rem; padding: .55rem .7rem; border-radius: 8px;
  color: var(--side-ink); font-weight: 500;
}
.side nav a:hover { background: rgba(255, 255, 255, .06); color: #fff; text-decoration: none; }
.side nav a.on { background: rgba(234, 88, 12, .18); color: #fff; }
.side nav a.on svg { stroke: #fb923c; }
.side nav svg { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.side .sep { font-size: .7rem; text-transform: uppercase; letter-spacing: .12em; color: #7d8698; padding: 1rem .7rem .3rem; }
.side-foot { margin-top: auto; padding: 1rem 1.2rem; border-top: 1px solid rgba(255, 255, 255, .08); font-size: .85rem; }
.side-foot strong { color: #fff; display: block; }
.side-foot a, .side-foot button { color: var(--side-ink); }
.side-foot .links { display: flex; gap: .8rem; margin-top: .4rem; align-items: center; }
.linklike { background: none; border: 0; padding: 0; font: inherit; cursor: pointer; text-decoration: none; }
.linklike:hover { text-decoration: underline; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.top {
  display: flex; align-items: center; gap: .8rem; padding: .7rem 1.6rem; background: var(--card);
  border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20;
}
.top-title { font-weight: 700; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.burger { display: none; background: none; border: 0; padding: .3rem; cursor: pointer; color: var(--ink); }
.burger svg, .bell svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }
.bell { position: relative; color: var(--ink); display: grid; place-items: center; padding: .3rem; }
.bell .dot {
  position: absolute; top: -2px; right: -4px; min-width: 18px; height: 18px; border-radius: 9px; padding: 0 5px;
  background: var(--accent); color: #fff; font-size: .7rem; font-weight: 700; display: grid; place-items: center;
}
.content { padding: 1.6rem; max-width: 1240px; width: 100%; }
.overlay { display: none; }

/* ---------- Éléments ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.2rem 1.3rem; margin-bottom: 1.2rem; min-width: 0; }
.card > h2:first-child, .card > h3:first-child { margin-top: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: .8rem; flex-wrap: wrap; margin-bottom: .8rem; }
.card-head h2 { margin: 0; }
.grid { display: grid; gap: 1.2rem; }
.grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid > .card { margin-bottom: 0; }
.stack > * + * { margin-top: 1.2rem; }

.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.2rem; }
.page-head h1 { margin: 0; }
.page-head .sub { color: var(--muted); margin-top: .2rem; }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.actions form { margin: 0; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem; padding: .55rem 1rem;
  border-radius: 9px; border: 1px solid var(--line); background: var(--card); color: var(--ink);
  font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; line-height: 1.2; min-height: 40px;
}
.btn:hover { text-decoration: none; border-color: #c9ced8; background: #fafbfc; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-dark); border-color: var(--accent-dark); }
.btn.danger { color: var(--red); }
.btn.danger:hover { background: var(--red-soft); border-color: #f3c4c4; }
.btn.sm { padding: .35rem .7rem; min-height: 32px; font-size: .88rem; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn[disabled] { opacity: .5; pointer-events: none; }

.badge { display: inline-block; padding: .15rem .55rem; border-radius: 999px; font-size: .78rem; font-weight: 600; white-space: nowrap; background: var(--gray-soft); color: var(--muted); }
.badge.green { background: var(--green-soft); color: var(--green); }
.badge.red { background: var(--red-soft); color: var(--red); }
.badge.amber { background: var(--amber-soft); color: var(--amber); }
.badge.blue { background: var(--blue-soft); color: var(--blue); }
.badge.orange { background: var(--accent-soft); color: var(--accent-dark); }

.flash { padding: .8rem 1rem; border-radius: 10px; margin-bottom: 1.2rem; border: 1px solid; }
.flash.ok { background: var(--green-soft); border-color: #bfe3c9; color: #14532d; }
.flash.info { background: var(--blue-soft); border-color: #c8d5fa; color: #1e3a8a; }
.flash.error { background: var(--red-soft); border-color: #f3c4c4; color: #7f1d1d; }
.notice { background: var(--accent-soft); border: 1px solid #fed7aa; border-radius: 10px; padding: .8rem 1rem; margin-bottom: 1.2rem; }

/* ---------- Tableaux ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -1.3rem; padding: 0 1.3rem; }
table.table { width: 100%; border-collapse: collapse; font-size: .93rem; }
.table th { text-align: left; font-size: .75rem; text-transform: uppercase; letter-spacing: .06em; color: var(--faint); font-weight: 700; padding: .5rem .6rem; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table td { padding: .65rem .6rem; border-bottom: 1px solid var(--line); vertical-align: top; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: #fafbfc; }
.table th.num, .table td.num { text-align: right; }
.table .main-col { font-weight: 600; }
.table a.row-link { color: var(--ink); font-weight: 600; }
.table tfoot td { font-weight: 700; border-top: 2px solid var(--line); }
.empty { text-align: center; color: var(--muted); padding: 2rem 1rem; }
.empty .btn { margin-top: .8rem; }

/* ---------- Formulaires ---------- */
form { margin: 0; }
.field { display: flex; flex-direction: column; gap: .3rem; margin-bottom: .9rem; min-width: 0; }
.field label, .label { font-weight: 600; font-size: .88rem; }
.field .hint { font-size: .82rem; color: var(--muted); }
input:not([type]), input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=tel], input[type=search], select, textarea {
  width: 100%; padding: .55rem .7rem; border: 1px solid #cfd4dd; border-radius: 9px; background: #fff;
  font: inherit; color: var(--ink); min-height: 40px;
}
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(234, 88, 12, .35); outline-offset: 0; border-color: var(--accent); }
input[type=checkbox], input[type=radio] { width: 18px; height: 18px; accent-color: var(--accent); margin: 0; flex: none; }
.check { display: flex; gap: .55rem; align-items: flex-start; margin-bottom: .6rem; cursor: pointer; font-weight: 500; }
.check input { margin-top: 2px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 1rem; }
.form-grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.form-grid .full { grid-column: 1 / -1; }
.form-foot { display: flex; gap: .6rem; flex-wrap: wrap; justify-content: flex-end; padding-top: .4rem; }
.filters { display: flex; gap: .6rem; flex-wrap: wrap; align-items: flex-end; margin-bottom: 1rem; }
.filters .field { margin: 0; }
.filters input[type=search] { min-width: 220px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; background: #fff; flex-wrap: wrap; }
.seg a { padding: .45rem .8rem; color: var(--muted); font-weight: 600; font-size: .88rem; border-right: 1px solid var(--line); }
.seg a:last-child { border-right: 0; }
.seg a.on { background: var(--ink); color: #fff; }
.seg a:hover { text-decoration: none; }
fieldset { border: 1px solid var(--line); border-radius: 10px; padding: .8rem 1rem .3rem; margin: 0 0 1rem; }
legend { font-weight: 700; padding: 0 .4rem; }
.radio-cards { display: grid; gap: .6rem; }
.radio-card { display: flex; gap: .7rem; padding: .8rem 1rem; border: 1px solid var(--line); border-radius: 10px; cursor: pointer; align-items: flex-start; }
.radio-card:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.radio-card input { margin-top: 3px; }

/* ---------- Tableau de bord ---------- */
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1rem; margin-bottom: 1.2rem; }
.kpis.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.1rem; box-shadow: var(--shadow); min-width: 0; }
.kpi .k { font-size: .8rem; color: var(--muted); font-weight: 600; }
.kpi .v { font-size: 1.45rem; font-weight: 800; margin-top: .2rem; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi .d { font-size: .8rem; color: var(--faint); margin-top: .1rem; }
.kpi.accent { border-color: #fed7aa; background: linear-gradient(180deg, #fff, var(--accent-soft)); }
.kpi.alert .v { color: var(--red); }
.kpi.good .v { color: var(--green); }
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; justify-content: space-between; gap: .8rem; padding: .55rem 0; border-bottom: 1px solid var(--line); align-items: baseline; }
.list li:last-child { border-bottom: 0; }
.list .grow { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.alert-item { display: flex; gap: .6rem; align-items: baseline; padding: .45rem 0; }
.alert-item .badge { flex: none; }
.bar { height: 8px; background: var(--gray-soft); border-radius: 4px; overflow: hidden; margin-top: .5rem; }
.bar span { display: block; height: 100%; background: var(--accent); }

/* ---------- Détail document ---------- */
.dl { display: grid; grid-template-columns: max-content 1fr; gap: .35rem 1rem; margin: 0; }
.dl dt { color: var(--muted); font-size: .88rem; }
.dl dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.totals { margin-left: auto; max-width: 340px; width: 100%; }
.totals .row { display: flex; justify-content: space-between; gap: 1rem; padding: .3rem 0; font-variant-numeric: tabular-nums; }
.totals .row.big { font-size: 1.1rem; font-weight: 800; border-top: 2px solid var(--ink); margin-top: .3rem; padding-top: .5rem; }
.totals .row.due { color: var(--accent-dark); font-weight: 700; }
.doc-lines td .desc { color: var(--muted); font-size: .86rem; white-space: pre-line; }
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { padding: .4rem 0 .4rem 1.1rem; border-left: 2px solid var(--line); position: relative; font-size: .9rem; }
.timeline li::before { content: ""; position: absolute; left: -6px; top: .75rem; width: 10px; height: 10px; border-radius: 50%; background: var(--accent); }
.copy-box { display: flex; gap: .5rem; }
.copy-box input { font-family: ui-monospace, Consolas, monospace; font-size: .85rem; }
.tabs { display: flex; gap: .3rem; border-bottom: 1px solid var(--line); margin-bottom: 1rem; overflow-x: auto; }
.tabs a { padding: .55rem .9rem; color: var(--muted); font-weight: 600; border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs a.on { color: var(--ink); border-color: var(--accent); }
.tabs a:hover { text-decoration: none; color: var(--ink); }
.tab-panel { display: none; }
.tab-panel.on { display: block; }

/* ---------- Éditeur de lignes ---------- */
.editor-tools { display: flex; gap: .6rem; flex-wrap: wrap; margin: .8rem 0; align-items: center; }
.editor-tools select { width: auto; max-width: 100%; flex: 1 1 260px; }
.lines-table { width: 100%; border-collapse: collapse; table-layout: fixed; }
.lines-table input, .lines-table select { min-width: 0; }
.lines-table th { font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--faint); text-align: left; padding: .4rem .3rem; border-bottom: 1px solid var(--line); }
.lines-table td { padding: .5rem .3rem; border-bottom: 1px solid var(--line); vertical-align: top; }
.lines-table input, .lines-table select, .lines-table textarea { min-height: 36px; padding: .4rem .5rem; font-size: .92rem; }
.lines-table textarea { min-height: 36px; height: 36px; margin-top: .35rem; font-size: .86rem; }
.lines-table .c-qty { width: 80px; } .lines-table .c-unit { width: 86px; } .lines-table .c-pu { width: 110px; }
.lines-table .c-disc { width: 72px; } .lines-table .c-vat { width: 86px; } .lines-table .c-tot { width: 110px; text-align: right; }
.lines-table .c-act { width: 96px; }
.line-total { font-weight: 700; padding-top: .5rem; font-variant-numeric: tabular-nums; white-space: nowrap; text-align: right; }
.line-actions { display: flex; gap: 2px; justify-content: flex-end; }
.icon-btn { width: 30px; height: 30px; border: 1px solid var(--line); background: #fff; border-radius: 7px; cursor: pointer; color: var(--muted); font-size: 14px; line-height: 1; }
.icon-btn:hover { color: var(--ink); border-color: #c9ced8; }
.icon-btn.del:hover { color: var(--red); border-color: #f3c4c4; }
.m-label { display: none; }
.cost-row { font-size: .8rem; color: var(--faint); margin-top: .3rem; }
.editor-totals { display: flex; justify-content: space-between; gap: 1.2rem; flex-wrap: wrap; margin-top: 1rem; align-items: flex-start; }

/* ---------- Pages publiques ---------- */
.auth { max-width: 440px; margin: 0 auto; padding: 3rem 1rem; }
.auth .brand { color: var(--ink); justify-content: center; font-size: 1.4rem; padding: 0 0 1.4rem; }
.public { max-width: 900px; margin: 0 auto; padding: 1.5rem 1rem 3rem; }
.public-head { display: flex; justify-content: space-between; gap: 1rem; align-items: center; flex-wrap: wrap; margin-bottom: 1.2rem; }
.public-head img { max-height: 56px; max-width: 180px; }
.sig-pad { border: 2px dashed #cfd4dd; border-radius: 10px; background: #fff; touch-action: none; width: 100%; height: 180px; display: block; cursor: crosshair; }
.sig-pad.signed { border-style: solid; border-color: var(--accent); }
details summary { cursor: pointer; font-weight: 600; }
.logo-prev { max-height: 70px; max-width: 220px; border: 1px solid var(--line); border-radius: 8px; padding: 6px; background: #fff; }
.perm-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 1rem; }

/* ---------- Écrans moyens ---------- */
@media (max-width: 1100px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid.three { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* ---------- Téléphone et tablette ---------- */
@media (max-width: 860px) {
  .side { position: fixed; left: 0; top: 0; bottom: 0; z-index: 50; transform: translateX(-100%); transition: transform .2s ease; }
  body.nav-open .side { transform: none; }
  body.nav-open .overlay { display: block; position: fixed; inset: 0; background: rgba(15, 20, 30, .45); z-index: 40; }
  .burger { display: block; }
  .top { padding: .6rem 1rem; }
  .content { padding: 1rem; }
  .grid.two, .grid.three { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  body { font-size: 15px; }
  h1 { font-size: 1.3rem; }
  .card { padding: 1rem; border-radius: 10px; }
  .table-wrap { margin: 0 -1rem; padding: 0 1rem; }
  .kpi .v { font-size: 1.2rem; }
  .kpis.three { grid-template-columns: 1fr; gap: .6rem; }
  .form-grid, .form-grid.three, .perm-grid { grid-template-columns: 1fr; }
  .page-head .actions { width: 100%; }
  .filters input[type=search] { min-width: 0; }
  .filters > * { flex: 1 1 100%; }
  .table .hide-sm { display: none; }
  .dl { grid-template-columns: 1fr; gap: .1rem; }
  .dl dd { margin-bottom: .5rem; }
  /* Lignes de devis : une carte par ligne */
  .lines-table thead { display: none; }
  .lines-table, .lines-table tbody, .lines-table tr, .lines-table td { display: block; width: 100%; }
  .lines-table tr { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .4rem .5rem; border: 1px solid var(--line); border-radius: 10px; padding: .7rem; margin-bottom: .7rem; background: #fcfcfd; }
  .lines-table td { padding: 0; border: 0; width: auto !important; }
  .lines-table td.c-label { grid-column: 1 / -1; }
  .lines-table td.c-tot { grid-column: 1 / 3; text-align: left; }
  .lines-table td.c-act { grid-column: 3; }
  .m-label { display: block; font-size: .72rem; color: var(--faint); font-weight: 700; text-transform: uppercase; letter-spacing: .05em; margin-bottom: 2px; }
  .line-total { text-align: left; padding-top: 0; }
  .totals { max-width: none; }
}
@media print {
  .side, .top, .actions, .btn { display: none !important; }
  .content { padding: 0; }
}
