:root {
  --bg: #f6f6f4;
  --surface: #ffffff;
  --surface-2: #f1f1ee;
  --line: #deded9;
  --fg: #1d1d1b;
  --muted: #6b6b66;
  --accent: #2b59c3;
  --accent-fg: #ffffff;
  --ok: #2f7d32;
  --warn: #9a6400;
  --bad: #b3261e;
  --info: #2b59c3;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161616;
    --surface: #1e1e1e;
    --surface-2: #262626;
    --line: #353535;
    --fg: #e8e8e6;
    --muted: #9b9b96;
    --accent: #7ea2f0;
    --accent-fg: #0f1a33;
    --ok: #7bc47f;
    --warn: #e0b453;
    --bad: #f08a80;
    --info: #7ea2f0;
    color-scheme: dark;
  }
}

* { box-sizing: border-box }
[hidden] { display: none !important }
html, body { margin: 0 }
body { background: var(--bg); color: var(--fg); font: 14px/1.5 var(--font) }
h1, h2, h3 { margin: 0; font-weight: 600; line-height: 1.25 }
h1 { font-size: 17px }
h2 { font-size: 15px }
h3 { font-size: 13px; color: var(--muted); font-weight: 500 }
button, input, select, textarea { font: inherit; color: inherit }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px }
.num, .inp input:not(.txt), table.bd td:last-child, table.list .r { font-variant-numeric: tabular-nums }

/* En-tête */
.top { position: sticky; top: 0; z-index: 5; background: var(--surface); border-bottom: 1px solid var(--line) }
.top-in { max-width: 1200px; margin: 0 auto; display: flex; align-items: center; gap: 28px; flex-wrap: wrap;
  padding: 0 max(16px, env(safe-area-inset-left, 0px)) }
.brand h1 { padding: 14px 0 }
nav.tabs { display: flex; gap: 22px; margin-right: auto }
nav.tabs a { padding: 14px 0 12px; text-decoration: none; color: var(--muted); border-bottom: 2px solid transparent }
nav.tabs a:hover { color: var(--fg) }
nav.tabs a[aria-current="page"] { color: var(--fg); border-bottom-color: var(--fg) }
.who { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 13px }

main { max-width: 1200px; margin: 0 auto; padding: 20px max(16px, env(safe-area-inset-right, 0px)) 48px max(16px, env(safe-area-inset-left, 0px)) }
.banner { border: 1px solid var(--line); background: var(--surface); padding: 10px 14px; margin-bottom: 16px }

/* Blocs */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 4px; padding: 16px; display: flex; flex-direction: column; gap: 12px; min-width: 0 }
.panel-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap }
.hint { color: var(--muted); font-size: 12.5px }
.grid { display: grid; gap: 10px 12px }
.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)) }
@media (max-width: 640px) { .g3, .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)) } }

label.f { display: flex; flex-direction: column; gap: 3px; min-width: 0 }
label.f > span { font-size: 12.5px; color: var(--muted) }
.inp { display: flex; align-items: stretch; border: 1px solid var(--line); border-radius: 3px; background: var(--surface); min-width: 0 }
.inp:focus-within { border-color: var(--accent) }
.inp input, .inp select, .inp textarea { border: 0; background: transparent; padding: 6px 8px; width: 100%; min-width: 0; outline: none }
.inp em { font-style: normal; color: var(--muted); font-size: 12.5px; padding: 0 8px; display: flex; align-items: center; white-space: nowrap }
textarea { resize: vertical }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line); background: var(--surface); border-radius: 3px; padding: 6px 12px; cursor: pointer; white-space: nowrap; text-decoration: none }
.btn:hover { background: var(--surface-2) }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg) }
.btn.primary:hover { filter: brightness(1.08) }
.btn.ghost { border-color: transparent; background: transparent; color: var(--muted) }
.btn.ghost:hover { color: var(--fg) }
.btn.danger { color: var(--bad) }
.btn.small { padding: 3px 8px; font-size: 13px }
.btn:disabled { opacity: .5; cursor: not-allowed }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center }

/* Chiffrage */
.layout { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 16px; align-items: start }
@media (max-width: 960px) { .layout { grid-template-columns: minmax(0, 1fr) } }
.col { display: flex; flex-direction: column; gap: 16px; min-width: 0 }
.summary { position: sticky; top: 64px }
@media (max-width: 960px) { .summary { position: static } }

.drop { border: 1px dashed var(--line); border-radius: 3px; padding: 14px; display: flex; gap: 12px; align-items: center; flex-wrap: wrap; cursor: pointer }
.drop:hover, .drop.over { border-color: var(--accent) }
.drop svg { display: none }
.drop-txt { flex: 1; min-width: 200px }
.drop-txt b { display: block; font-weight: 600 }
.import-res { font-size: 13px; padding: 8px 10px; border-left: 3px solid var(--line); background: var(--surface-2) }
.import-res.ok { border-left-color: var(--ok) }
.import-res.err { border-left-color: var(--bad) }
details.paste summary { cursor: pointer; color: var(--muted); font-size: 13px }
details.paste textarea { width: 100%; margin-top: 8px; border: 1px solid var(--line); border-radius: 3px; background: var(--surface); padding: 8px; font: 12px/1.5 var(--mono); min-height: 90px }

.lines { display: flex; flex-direction: column; gap: 8px }
.line { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr) minmax(0, 1fr) auto; gap: 8px; align-items: end }
@media (max-width: 560px) { .line { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto } .line .l-mat { grid-column: 1 / -1 } }
.swatch { width: 10px; height: 10px; border-radius: 2px; border: 1px solid var(--line); flex: none; align-self: center; margin-left: 8px }
.extra { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr) auto; gap: 8px; align-items: end }
details.adv summary { cursor: pointer; color: var(--muted); font-size: 13px }
details.adv[open] summary { margin-bottom: 10px }

.price .big { font-size: 28px; font-weight: 600; font-variant-numeric: tabular-nums; line-height: 1.2; margin-top: 2px }
.price .sub { color: var(--muted); font-size: 13px }
.kpis { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); padding: 8px 0 }
.kpi span { display: block; font-size: 12px; color: var(--muted) }
.kpi b { font-weight: 500; font-variant-numeric: tabular-nums }
table.bd { width: 100%; border-collapse: collapse; font-size: 13px }
table.bd td { padding: 4px 0 }
table.bd td:last-child { text-align: right; white-space: nowrap }
table.bd tr.tot td { font-weight: 600; border-top: 1px solid var(--line); padding-top: 6px }
table.bd .detail { color: var(--muted); font-size: 12px; margin-left: 6px }
.state { font-size: 12.5px; color: var(--muted) }
.state.dirty { color: var(--warn) }
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(20px + env(safe-area-inset-bottom, 0px)); background: var(--fg); color: var(--bg); padding: 8px 14px; border-radius: 3px; z-index: 20; max-width: calc(100% - 32px) }

/* Historique */
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center }
.toolbar .inp { flex: 1; min-width: 180px }
.seg { display: flex; border: 1px solid var(--line); border-radius: 3px; overflow: hidden }
.seg button { border: 0; background: var(--surface); padding: 5px 12px; cursor: pointer; color: var(--muted) }
.seg button + button { border-left: 1px solid var(--line) }
.seg button[aria-pressed="true"] { background: var(--surface-2); color: var(--fg); font-weight: 500 }
.tbl-wrap { overflow-x: auto }
table.list { width: 100%; border-collapse: collapse; min-width: 720px }
table.list th { text-align: left; font-size: 12.5px; color: var(--muted); font-weight: 500; padding: 6px 10px; border-bottom: 1px solid var(--line) }
table.list td { padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: middle }
table.list tbody tr { cursor: pointer }
table.list tbody tr:hover { background: var(--surface-2) }
table.list td.r, table.list th.r { text-align: right }
.t-title { font-weight: 500 }
.t-sub { color: var(--muted); font-size: 12.5px }
.author { white-space: nowrap }
.pill { font-size: 12.5px; white-space: nowrap }
.pill.brouillon { color: var(--muted) }
.pill.envoye { color: var(--info) }
.pill.accepte { color: var(--ok) }
.pill.refuse { color: var(--bad) }
.empty { padding: 28px 16px; text-align: center; color: var(--muted); display: flex; flex-direction: column; gap: 8px; align-items: center }
.empty b { color: var(--fg); font-weight: 500 }

/* Atelier */
.atelier { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; align-items: start }
@media (max-width: 860px) { .atelier { grid-template-columns: minmax(0, 1fr) } }
.items { display: flex; flex-direction: column }
.item { display: flex; gap: 10px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line) }
.item:last-child { border-bottom: 0 }
.item .grow { flex: 1; min-width: 0 }
.item .meta { color: var(--muted); font-size: 12.5px; font-variant-numeric: tabular-nums }
.item .tag { color: var(--muted); font-size: 12px; margin-left: 6px }
.editor { border: 1px solid var(--line); border-radius: 3px; padding: 12px; display: flex; flex-direction: column; gap: 10px }
.formula { font: 12px/1.7 var(--mono); color: var(--muted); overflow-x: auto; white-space: nowrap }

/* Connexion */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px }
.auth-card { width: 100%; max-width: 320px; display: flex; flex-direction: column; gap: 12px }
.auth-card h1 { font-size: 20px; margin-bottom: 4px }
.auth-card p { margin: 0; color: var(--muted); font-size: 13px }
.auth-err { color: var(--bad); font-size: 13px }

/* Écrans simplifiés */
.narrow { max-width: 720px; margin: 0 auto; display: flex; flex-direction: column; gap: 16px }
.opts { display: flex; flex-direction: column; gap: 12px }
.banner a { color: var(--accent) }
.summary .big { font-size: 32px; font-weight: 600; font-variant-numeric: tabular-nums; line-height: 1.15 }
.summary .sub { color: var(--muted); font-size: 13px }
.drop { padding: 22px; background: var(--surface) }
.drop-txt b { font-size: 15px }
.search input { padding: 9px 10px }
#devis-list { display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: 4px; background: var(--surface) }
#devis-list .empty { border: 0 }
.qrow { display: flex; align-items: center; gap: 14px; width: 100%; text-align: left; border: 0; border-bottom: 1px solid var(--line); background: transparent; padding: 12px 14px; cursor: pointer }
.qrow:last-child { border-bottom: 0 }
.qrow:hover { background: var(--surface-2) }
.qrow .grow { flex: 1; min-width: 0; display: flex; flex-direction: column }
.qrow .t-title, .qrow .t-sub { overflow: hidden; text-overflow: ellipsis; white-space: nowrap }
.qprice { font-weight: 600; font-variant-numeric: tabular-nums; min-width: 80px; text-align: right }
.how { padding: 0 2px }

/* Listes déroulantes lisibles en thème sombre (Windows dessine les options sur fond blanc sinon) */
.inp select { background: var(--surface) }
select option { background: var(--surface); color: var(--fg) }

.st { font-weight: 500 }
.st-sent { color: var(--info) }
.st-ok { color: var(--ok) }
.st-expired { color: var(--warn) }
