/* ===== Thèmes ===== */
/* ===== Thèmes (noir profond, gris neutres, accents blancs) ===== */
:root {
  color-scheme: dark;
  --bg: #070707; --bg2: #0b0b0b; --card: #0e0e0f; --card2: #141415; --text: #f2f2f3; --muted: #8c8c92;
  --line: #222224; --input: #0a0a0b; --input-line: #2a2a2d;
  --primary: #f2f2f3; --primary-d: #ffffff; --primary-soft: rgba(255, 255, 255, .07); --on-primary: #0a0a0a;
  --danger: #f87171; --ok: #34d399; --warn: #fbbf24; --blue: #3b82f6;
  --shadow: 0 8px 28px rgba(0, 0, 0, .5);
  --radius: 12px; --rb: 9px; --fs: 15px;
  --accent: var(--text); --on-accent: var(--on-primary);
}
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f5f5f6; --bg2: #ededee; --card: #ffffff; --card2: #f6f6f7; --text: #0f0f10; --muted: #6d6d73;
  --line: #e4e4e7; --input: #ffffff; --input-line: #d4d4d8;
  --primary: #0f0f10; --primary-d: #000; --primary-soft: rgba(0, 0, 0, .06); --on-primary: #ffffff;
  --danger: #dc2626; --ok: #059669; --warn: #d97706;
  --shadow: 0 8px 28px rgba(0, 0, 0, .07);
}

* { box-sizing: border-box; }
html { scrollbar-color: var(--line) transparent; }
body { margin: 0; font: var(--fs) / 1.5 Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: radial-gradient(900px 400px at 85% -10%, rgba(255,255,255,.045), transparent 60%), var(--bg); color: var(--text); min-height: 100vh; }
h1, h2, h3 { margin: 0 0 .6em; letter-spacing: -.01em; }
h1 { font-size: 1.6rem; font-weight: 700; }
h2 { font-size: 1.05rem; font-weight: 650; }
a { color: var(--text); text-decoration-color: var(--muted); text-underline-offset: 3px; }
code { background: var(--card2); padding: 1px 6px; border-radius: 6px; }
details summary { cursor: pointer; color: var(--text); font-weight: 500; }

/* ===== Barre du haut ===== */
.topbar { display: flex; align-items: center; gap: 24px; padding: 0 28px; height: 60px; position: sticky; top: 0; z-index: 10;
  background: color-mix(in srgb, var(--bg) 78%, transparent); backdrop-filter: blur(14px); border-bottom: 1px solid var(--line); }
.brand { font-weight: 500; font-size: 1.1rem; display: flex; align-items: center; gap: 10px; }
.brand .logo-mark { width: 30px; height: 30px; flex: none; display: block; }
.brand .nm b { font-weight: 600; color: var(--accent, currentColor); }
:root[data-theme="light"] .brand .nm b, :root[data-theme="light"] .brand .nm .dot { color: color-mix(in srgb, var(--accent, #000) 62%, #000); }
.brand .nm { letter-spacing: -.02em; }
.brand .nm .dot { font-style: normal; color: var(--accent, currentColor); }
#nav { display: flex; gap: 4px; }
#nav button { background: none; border: 0; color: var(--muted); padding: 8px 14px; border-radius: 10px; cursor: pointer; font: inherit; font-weight: 500; transition: .15s; }
#nav button:hover { color: var(--text); background: var(--card); }
#nav button.active { background: var(--card); color: var(--text); box-shadow: inset 0 0 0 1px var(--accent); }
.saved { margin-left: auto; font-size: .8rem; color: var(--muted); }
.theme-btn { background: var(--card); border: 1px solid var(--line); color: var(--text); width: 38px; height: 38px; border-radius: 10px; cursor: pointer; font-size: 1rem; }
.theme-btn:hover { border-color: var(--accent); }

main { max-width: 1500px; margin: 0 auto; padding: 28px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; margin-bottom: 20px; box-shadow: var(--shadow); }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.grow { flex: 1; }
.muted { color: var(--muted); }
.right { text-align: right; }

/* ===== Boutons / champs ===== */
button.btn, a.btn, label.btn { display: inline-flex; align-items: center; gap: 6px; padding: 9px 16px; border-radius: var(--rb); border: 1px solid var(--line); background: var(--card2); color: var(--text); font: inherit; font-size: .8rem; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; cursor: pointer; text-decoration: none; transition: .15s; }
.btn:hover { border-color: var(--accent); }
.btn:disabled { opacity: .35; cursor: default; transform: none; border-color: var(--line); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.primary:hover { filter: brightness(.88); }
.btn.danger { color: var(--danger); }
.btn.small { padding: 4px 10px; font-size: .72rem; border-radius: 8px; }
.btn.icon { padding: 4px 8px; }

label { display: block; font-size: .75rem; font-weight: 600; color: var(--muted); margin-bottom: 5px; letter-spacing: .02em; }
input, select, textarea { width: 100%; padding: 9px 12px; border: 1px solid var(--input-line); border-radius: var(--rb); font: inherit; background: var(--input); color: var(--text); transition: .15s; }
input::placeholder, textarea::placeholder { color: var(--muted); opacity: .6; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--primary-soft); }
input[type=checkbox] { accent-color: var(--accent); }
textarea { resize: vertical; min-height: 44px; }
.field { margin-bottom: 14px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }

/* ===== Stats ===== */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 20px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); position: relative; overflow: hidden; }
.stat::after { content: ""; position: absolute; inset: 0 0 auto 0; height: 3px; background: var(--line); }
.stat .n { font-size: 1.6rem; font-weight: 700; letter-spacing: -.02em; }
.stat .l { color: var(--muted); font-size: .85rem; }

/* ===== Tableaux ===== */
table.list { width: 100%; border-collapse: collapse; }
table.list th { text-align: left; font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--line); }
table.list td { padding: 12px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.list tr:last-child td { border-bottom: 0; }
table.list tr:hover td { background: var(--card2); }
.empty { text-align: center; padding: 44px; color: var(--muted); }

.badge { display: inline-block; padding: 3px 11px; border-radius: 999px; font-size: .75rem; font-weight: 600; }
.badge.brouillon { background: rgba(148, 163, 184, .18); color: var(--muted); }
.badge.envoye { background: rgba(59, 130, 246, .16); color: var(--blue); }
.badge.accepte { background: rgba(52, 211, 153, .14); color: var(--ok); }
.badge.refuse { background: rgba(248, 113, 113, .16); color: var(--danger); }

/* ===== Éditeur ===== */
.editor { display: grid; grid-template-columns: minmax(440px, 560px) 1fr; gap: 24px; align-items: start; }
.editor.wide { grid-template-columns: 1fr; }
.editor.wide .form { display: none; }
.editor.wide .preview-wrap { max-width: 900px; margin: 0 auto; width: 100%; }
.editor .form { min-width: 0; }
.editor .preview-wrap { position: sticky; top: 80px; max-height: calc(100vh - 100px); overflow: auto; border-radius: var(--radius); padding: 18px; background: var(--bg2); border: 1px solid var(--line); }

.line { border: 1px solid var(--line); border-radius: 12px; padding: 10px; margin-bottom: 10px; background: var(--card2); }
.line .r1 { display: grid; grid-template-columns: 92px 1fr; gap: 8px; margin-bottom: 8px; }
.line .r2 { display: grid; grid-template-columns: .8fr 1fr 1fr 1.15fr 1.1fr auto; gap: 8px; align-items: end; }
.line .tot { text-align: right; padding-bottom: 8px; white-space: nowrap; }
.line .tot label { text-align: right; }
.line .acts { display: flex; gap: 4px; padding-bottom: 2px; }
.line.kind { display: flex; align-items: center; gap: 10px; padding: 8px 10px; }
.line.kind input { flex: 1; }
.line .tag { font-size: .7rem; text-transform: uppercase; letter-spacing: .06em; color: var(--text); background: var(--primary-soft); padding: 3px 8px; border-radius: 6px; white-space: nowrap; font-weight: 600; }
.pay { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.pay input[data-p=label] { flex: 1; }
.pay b { white-space: nowrap; min-width: 90px; text-align: right; }

/* ===== Document (papier, toujours clair) ===== */

.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; background: var(--input); border: 1px solid var(--line); border-radius: 12px; padding: 4px; }
.seg label { margin: 0; cursor: pointer; }
.seg input { position: absolute; opacity: 0; pointer-events: none; width: 0; }
.seg span { display: block; text-align: center; padding: 9px; border-radius: 9px; color: var(--muted); font-size: .85rem; font-weight: 600; transition: .15s; }
.seg input:checked + span { background: var(--accent); color: var(--on-accent); }
[hidden] { display: none !important; }
.sugg { position: absolute; left: 0; right: 0; top: 100%; margin-top: 4px; z-index: 5; background: var(--card2); border: 1px solid var(--input-line); border-radius: 10px; overflow: hidden; box-shadow: var(--shadow); }
.sugg .sg { display: flex; flex-direction: column; align-items: flex-start; width: 100%; padding: 9px 12px; background: none; border: 0; border-bottom: 1px solid var(--line); color: var(--text); font: inherit; text-align: left; cursor: pointer; }
.sugg .sg:last-child { border-bottom: 0; }
.sugg .sg:hover { background: var(--primary-soft); }
.sugg .sg span { font-size: .78rem; }

/* ===== Boîtes de dialogue / toast ===== */
dialog { border: 1px solid var(--line); border-radius: 18px; padding: 26px; width: min(540px, 94vw); background: var(--card); color: var(--text); box-shadow: 0 30px 80px rgba(0, 0, 0, .5); }
dialog::backdrop { background: rgba(5, 8, 20, .6); backdrop-filter: blur(3px); }
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(20px); background: var(--accent); color: var(--on-accent); padding: 10px 18px; border-radius: 10px; opacity: 0; transition: .25s; pointer-events: none; z-index: 50; }
.toast.show { opacity: 1; transform: translateX(-50%); }
.logo-prev { max-height: 90px; max-width: 240px; display: block; margin-bottom: 10px; background: #fff; border-radius: 8px; padding: 6px; }

@media (max-width: 1150px) {
  .editor { grid-template-columns: 1fr; }
  .editor .preview-wrap { position: static; max-height: none; }
  .stats { grid-template-columns: repeat(2, 1fr); }
}

/* ===== Impression ===== */
@media print {
  :root, :root[data-theme] { color-scheme: light; }
  body { background: #fff !important; min-height: 0; }
  .no-print, .topbar, .toast { display: none !important; }
  main { padding: 0; max-width: none; }
  .editor { display: block; }
  .editor .form { display: none; }
  .editor .preview-wrap { position: static; max-height: none; overflow: visible; padding: 0; border: 0; background: none; max-width: none; }
}

/* ===== Comptes, abonnement, administration ===== */
body.auth-mode { background: var(--bg); }
.auth { display: grid; grid-template-columns: 1.1fr 1fr; min-height: 100vh; }
.auth-hero { padding: 64px 56px; display: flex; flex-direction: column; justify-content: center; gap: 22px; border-right: 1px solid var(--line);
  background: radial-gradient(700px 400px at 20% 10%, rgba(255,255,255,.06), transparent 60%), var(--bg2); }
.auth-hero h1 { font-size: 2.3rem; line-height: 1.15; margin: 0; }
.auth-hero ul { list-style: none; padding: 0; margin: 0; display: grid; gap: 10px; color: var(--muted); }
.brand.big { font-size: 1.3rem; }
.hero-card { max-width: 340px; background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 16px 18px; box-shadow: var(--shadow); }
.hc-row { display: flex; justify-content: space-between; padding: 6px 0; color: var(--muted); border-bottom: 1px solid var(--line); }
.hc-row b { color: var(--text); } .hc-row.tot { border: 0; padding-top: 10px; } .hc-row.tot span, .hc-row.tot b { color: var(--text); font-weight: 800; }
.auth-card { display: flex; flex-direction: column; justify-content: center; padding: 48px 8vw; position: relative; max-width: 560px; width: 100%; margin: 0 auto; }
.auth-theme { position: absolute; top: 20px; right: 20px; }
.auth-card h2 { font-size: 1.6rem; margin-bottom: 4px; }
.auth-alt { text-align: center; margin-top: 18px; color: var(--muted); }
.big-ico { font-size: 3rem; margin-bottom: 8px; }
a.fr { float: right; font-weight: 400; font-size: .78rem; }
.btn.block { width: 100%; justify-content: center; padding: 12px; margin-top: 6px; }
label.check { display: flex; gap: 8px; align-items: flex-start; font-size: .85rem; font-weight: 400; color: var(--text); margin-bottom: 12px; }
label.check input { width: auto; margin-top: 3px; }
.form-err { color: var(--danger); font-size: .88rem; margin: 6px 0 10px; }
.form-err.good { color: var(--ok); }
.notice { padding: 10px 14px; border-radius: 10px; margin: 12px 0; font-size: .9rem; border: 1px solid var(--line); }
.notice.ok { background: rgba(52,211,153,.1); color: var(--ok); border-color: rgba(52,211,153,.3); }
.notice.bad { background: rgba(248,113,113,.1); color: var(--danger); border-color: rgba(248,113,113,.3); }
.devbox { background: rgba(251,191,36,.08); border: 1px dashed rgba(251,191,36,.5); color: var(--text); padding: 10px 14px; border-radius: 10px; margin: 14px 0; font-size: .85rem; word-break: break-all; }

#accessPill { margin-left: 4px; }
.pill { display: inline-block; padding: 5px 12px; border-radius: 999px; font-size: .75rem; font-weight: 600; border: 1px solid var(--line); background: none; color: var(--text); font-family: inherit; }
.pill.ok { color: var(--ok); border-color: rgba(52,211,153,.35); background: rgba(52,211,153,.08); }
.pill.bad { color: var(--danger); border-color: rgba(248,113,113,.4); background: rgba(248,113,113,.08); cursor: pointer; }
#userbox { position: relative; }
.avatar { width: 38px; height: 38px; border-radius: 50%; border: 1px solid var(--line); background: var(--accent); color: var(--on-accent); font-weight: 700; cursor: pointer; font-family: inherit; }
.pop { display: none; position: absolute; right: 0; top: 48px; width: 250px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); padding: 6px; z-index: 30; }
#userbox.open .pop { display: block; }
.pop-head { display: flex; flex-direction: column; padding: 10px 12px; border-bottom: 1px solid var(--line); margin-bottom: 4px; font-size: .88rem; word-break: break-all; }
.pop button { display: block; width: 100%; text-align: left; padding: 9px 12px; background: none; border: 0; color: var(--text); border-radius: 8px; cursor: pointer; font: inherit; }
.pop button:hover { background: var(--primary-soft); } .pop button.danger { color: var(--danger); }

.card.status { display: flex; align-items: center; gap: 16px; }
.card.status.ok { border-color: rgba(52,211,153,.35); } .card.status.bad { border-color: rgba(248,113,113,.4); }
.card.status h2 { margin-bottom: 4px; }
.plans { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 18px; margin-bottom: 20px; }
.plan { position: relative; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 24px; box-shadow: var(--shadow); }
.plan.hot { border-color: var(--accent); } .plan.off { opacity: .55; }
.plan .ribbon { position: absolute; top: -11px; right: 18px; background: var(--accent); color: var(--on-accent); font-size: .7rem; font-weight: 700; padding: 3px 10px; border-radius: 999px; }
.plan h3 { margin: 0 0 6px; } .price { font-size: 2.1rem; font-weight: 800; letter-spacing: -.02em; } .price small { font-size: .9rem; font-weight: 500; color: var(--muted); }
.plan ul { list-style: none; padding: 0; margin: 14px 0 18px; display: grid; gap: 7px; } .plan li::before { content: "✓ "; color: var(--ok); font-weight: 700; }

.tabs { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 20px; border-bottom: 1px solid var(--line); }
.tabs button { background: none; border: 0; border-bottom: 2px solid transparent; color: var(--muted); padding: 10px 14px; cursor: pointer; font: inherit; font-weight: 500; margin-bottom: -1px; }
.tabs button:hover { color: var(--text); } .tabs button.on { color: var(--text); border-color: var(--accent); }
.bars { display: flex; align-items: flex-end; gap: 12px; height: 170px; padding-top: 22px; }
.bar { flex: 1; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 4px; position: relative; }
.bar i { display: block; width: 100%; max-width: 46px; background: linear-gradient(var(--accent), color-mix(in srgb, var(--accent) 35%, transparent)); border-radius: 6px 6px 2px 2px; }
.bar .v { font-size: .7rem; color: var(--muted); white-space: nowrap; } .bar .l { font-size: .72rem; color: var(--muted); }
.env { display: flex; flex-direction: column; gap: 2px; padding: 10px 0; border-bottom: 1px solid var(--line); font-size: .9rem; }
.env.on b { color: var(--ok); } .env.off b { color: var(--warn); }
details.mail { border-bottom: 1px solid var(--line); padding: 10px 0; } details.mail summary { cursor: pointer; }
details.mail pre { white-space: pre-wrap; background: var(--input); border: 1px solid var(--line); padding: 12px; border-radius: 10px; font: inherit; font-size: .85rem; word-break: break-word; }
dialog:has(.modal-wide) { width: min(760px, 95vw); max-height: 92vh; }
.modal-wide h3 { font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-bottom: 8px; }
@media (max-width: 900px) { .auth { grid-template-columns: 1fr; } .auth-hero { display: none; } }
body.auth-mode main { max-width: none; padding: 0; }

/* ===== Factures ===== */
.badge.payee { background: rgba(52,211,153,.14); color: var(--ok); }
.badge.annulee { background: rgba(148,163,184,.18); color: var(--muted); text-decoration: line-through; }
.badge.retard { background: rgba(248,113,113,.16); color: var(--danger); }
.badge.info2 { background: rgba(59,130,246,.16); color: #60a5fa; font-size: .7rem; }
/* ===== Sélecteur de catalogue ===== */
.cp-row { display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; margin-bottom: 10px; background: var(--card2); }
.cp-info { display: flex; flex-direction: column; min-width: 0; }
.cp-info .tag { font-size: .68rem; text-transform: uppercase; background: var(--primary-soft); padding: 2px 7px; border-radius: 6px; }
.cp-calc { display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.cp-qty { width: 90px !important; }
.cp-tot { min-width: 100px; text-align: right; }
/* ===== Catalogue complet ===== */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.cchip { background: var(--card2); border: 1px solid var(--line); color: var(--text); padding: 6px 14px; border-radius: 999px; cursor: pointer; font: inherit; font-size: .85rem; font-weight: 500; }
.cchip i { font-style: normal; color: var(--muted); margin-left: 4px; }
.cchip:hover { border-color: var(--accent); } .cchip.on { background: var(--accent); color: var(--on-accent); border-color: var(--accent); } .cchip.on i { color: inherit; opacity: .6; }
.star { background: none; border: 0; font-size: 1.2rem; cursor: pointer; color: var(--muted); } .star.on { color: #fbbf24; }
.part { display: grid; grid-template-columns: 1fr 90px 50px 100px auto; gap: 8px; align-items: center; margin-bottom: 8px; }
.part .p-tot { text-align: right; }
.cp-sum { margin-top: 12px; padding: 12px 14px; border-radius: 10px; background: var(--card2); border: 1px solid var(--line); }
#catTable td, #catTable th { white-space: nowrap; } #catTable td:nth-child(3) { white-space: normal; min-width: 280px; }
/* ===== Fournisseurs ===== */
.sup-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 16px; }
.sup { display: flex; flex-direction: column; gap: 10px; margin: 0; }
.sup-info { font-size: .88rem; line-height: 1.7; }

/* ===== Assistant de prix ===== */
.finder { margin: 6px 0 4px; padding: 10px 14px; border: 1px dashed var(--input-line); border-radius: 12px; }
.pf-calc { display: grid; grid-template-columns: 1fr 1fr 1.3fr; gap: 12px; margin-top: 12px; }
.offer { display: flex; justify-content: space-between; gap: 14px; align-items: center; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; margin-bottom: 8px; background: var(--card2); }

/* ===== Icônes ===== */
.ic { width: 1.1em; height: 1.1em; vertical-align: -.2em; flex: none; margin-right: .4em; }
.ic:only-child, .btn.icon .ic, .star .ic, .theme-btn .ic, .avatar .ic { margin-right: 0; }
.star .ic { width: 1.2em; height: 1.2em; }
.big-ico .ic { width: 1em; height: 1em; margin: 0; stroke-width: 1.5; }
.theme-btn .ic { width: 1.1em; height: 1.1em; }
.btn .ic { opacity: .9; }
.card:has(> table.list) { overflow-x: auto; }

/* ===== Boîte à outils ===== */
.tool-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(460px, 1fr)); gap: 20px; align-items: start; }
.tool-grid .card { margin: 0; }
.grid4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.dropzone { border: 2px dashed var(--input-line); border-radius: 14px; padding: 26px; text-align: center; color: var(--muted); transition: .15s; }
.dropzone.over { border-color: var(--accent); background: var(--primary-soft); color: var(--text); }
.frow { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; margin-top: 8px; background: var(--card2); }
.fthumb { width: 48px; height: 48px; object-fit: cover; border-radius: 8px; background: #fff; }
.cp-sum b { white-space: nowrap; }
.tips { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 16px; }
.tip { margin: 0; }
input[type=range] { padding: 0; accent-color: var(--accent); }
@media (max-width: 900px) { .grid4 { grid-template-columns: 1fr 1fr; } .tool-grid { grid-template-columns: 1fr; } }

/* ===== Guide du devis ===== */
.steps { display: grid; gap: 14px; }
.step { display: flex; gap: 16px; align-items: flex-start; }
.sn { flex: none; width: 34px; height: 34px; border-radius: 50%; background: var(--accent); color: var(--on-accent); display: flex; align-items: center; justify-content: center; font-weight: 800; }
.ex { padding: 16px 18px; border-radius: 12px; border: 1px solid var(--line); background: var(--card2); }
.ex.bad { border-color: rgba(248,113,113,.4); } .ex.good { border-color: rgba(52,211,153,.4); }
.score { margin-bottom: 14px; } .sbar { height: 8px; border-radius: 99px; background: var(--card2); border: 1px solid var(--line); overflow: hidden; margin-bottom: 8px; } .sbar i { display: block; height: 100%; }
.chk { display: flex; gap: 12px; padding: 10px 12px; border-radius: 10px; margin-bottom: 6px; border: 1px solid var(--line); background: var(--card2); }
.chk .mk { flex: none; width: 24px; height: 24px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: .8rem; }
.chk.ok .mk { background: rgba(52,211,153,.16); color: var(--ok); } .chk.bad .mk { background: rgba(248,113,113,.16); color: var(--danger); } .chk.warn .mk { background: rgba(251,191,36,.16); color: var(--warn); }

/* ===== Relecture IA ===== */
.ai-card { border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; margin-bottom: 10px; background: var(--card2); }
.ai-card.applied { border-color: rgba(52,211,153,.4); } .ai-card.ignored { opacity: .55; } .ai-card.stale { border-color: rgba(251,191,36,.5); }
.ai-diff { display: grid; gap: 8px; }
.ai-txt { white-space: pre-wrap; padding: 8px 10px; border-radius: 8px; background: var(--input); border: 1px solid var(--line); font-size: .92rem; }
.ai-txt del { background: rgba(248,113,113,.22); color: inherit; text-decoration: line-through; border-radius: 3px; }
.ai-txt ins { background: rgba(52,211,153,.25); color: inherit; text-decoration: none; border-radius: 3px; }
.spin { display: inline-block; width: 34px; height: 34px; border-radius: 50%; border: 4px solid var(--line); border-top-color: var(--accent); animation: sp 0.8s linear infinite; }
@keyframes sp { to { transform: rotate(360deg); } }

/* =====================================================================
   RESPONSIVE : ordinateur (> 1150 px), tablette (641–1150 px), téléphone (≤ 640 px)
   ===================================================================== */
html { -webkit-text-size-adjust: 100%; }
body { overflow-x: hidden; }
img, svg, video { max-width: 100%; }
.bottomnav, .more-sheet, .pane-switch { display: none; }

/* ----- Tablette et en dessous ----- */
@media (max-width: 1150px) {
  .pane-switch { display: flex; gap: 6px; margin-bottom: 14px; background: var(--input); border: 1px solid var(--line); border-radius: 12px; padding: 4px; }
  .pane-switch button { flex: 1; padding: 10px; border: 0; border-radius: 9px; background: none; color: var(--muted); font: inherit; font-weight: 600; cursor: pointer; }
  .pane-switch button.on { background: var(--accent); color: var(--on-accent); }
  .editor[data-pane="form"] .preview-wrap { display: none; }
  .editor[data-pane="doc"] .form { display: none; }
  .hide-sm { display: none !important; }
  .editor .preview-wrap { padding: 10px; }
  .tool-grid { grid-template-columns: 1fr; }
}
@media (max-width: 1024px) {
  .topbar { gap: 14px; padding: 0 16px; }
  #nav { flex: 1 1 auto; min-width: 0; overflow-x: auto; scrollbar-width: none; }
  #nav::-webkit-scrollbar { display: none; }
  #nav button { white-space: nowrap; padding: 8px 11px; }
  .saved { display: none; }
  main { padding: 20px 16px; }
  .grid4 { grid-template-columns: 1fr 1fr; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .tabs { overflow-x: auto; flex-wrap: nowrap; scrollbar-width: none; }
  .tabs button { white-space: nowrap; }
  .auth-card { padding: 40px 6vw; }
}

/* ----- Téléphone ----- */
@media (max-width: 640px) {
  body { font-size: 15px; }
  h1 { font-size: 1.3rem; }
  .topbar { height: 54px; padding: 0 14px; gap: 10px; padding-top: env(safe-area-inset-top); }
  #nav { display: none; }
  .brand { font-size: 1rem; }
  #accessPill { margin-left: auto; max-width: 150px; }
  .pill { font-size: .68rem; padding: 4px 9px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; max-width: 150px; }
  .pop { right: -6px; width: min(260px, 90vw); }
  main { padding: 16px 14px calc(88px + env(safe-area-inset-bottom)); }
  .card { padding: 16px; border-radius: 12px; }
  .row.between { gap: 10px; }
  .row.between > .row { width: 100%; }
  .row.between > .row .btn { flex: 1 1 auto; justify-content: center; }
  input, select, textarea { font-size: 16px; }

  /* barre de navigation du bas */
  .bottomnav { display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(14px); border-top: 1px solid var(--line); padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); }
  .bottomnav button { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px; background: none; border: 0; color: var(--muted); font: inherit; font-size: .68rem; font-weight: 600; padding: 6px 2px; border-radius: 10px; cursor: pointer; }
  .bottomnav button .ic { width: 22px; height: 22px; margin: 0; }
  .bottomnav button.active { color: var(--text); }
  .bottomnav button.active .ic { stroke-width: 2.4; }
  body.auth-mode .bottomnav, body.auth-mode .more-sheet { display: none !important; }
  .more-sheet:not([hidden]) { display: block; position: fixed; inset: 0; z-index: 45; }
  .sheet-bg { position: absolute; inset: 0; background: rgba(0, 0, 0, .55); }
  .sheet { position: absolute; left: 0; right: 0; bottom: 0; background: var(--card); border-top: 1px solid var(--line); border-radius: 18px 18px 0 0; padding: 10px 12px calc(14px + env(safe-area-inset-bottom)); }
  .sheet .pop-head { padding: 10px 12px; }
  .sheet button { display: block; width: 100%; text-align: left; padding: 14px 12px; background: none; border: 0; border-bottom: 1px solid var(--line); color: var(--text); font: inherit; font-size: 1rem; cursor: pointer; }
  .sheet button.danger { color: var(--danger); border-bottom: 0; }

  /* grilles */
  .grid2, .grid3, .grid4, .pf-calc { grid-template-columns: 1fr; }
  .stats { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stat { padding: 12px; } .stat .n { font-size: 1.2rem; }
  .plans, .tips, .sup-grid { grid-template-columns: 1fr; }
  .editor[style] { grid-template-columns: 1fr !important; }

  /* lignes du devis */
  .line .r1 { grid-template-columns: 76px 1fr; }
  .line .r2 { grid-template-columns: repeat(3, 1fr); }
  .line .tot { text-align: left; } .line .tot label { text-align: left; }
  .line .acts { grid-column: 1 / -1; justify-content: flex-end; }
  .pay { flex-wrap: wrap; } .pay input[data-p=label] { flex: 1 1 100%; order: 3; } .pay b { margin-left: auto; }
  .part { grid-template-columns: 1fr auto; } .part .p-sel { grid-column: 1 / -1; }
  .cp-row { flex-direction: column; align-items: stretch; }
  .cp-calc { flex-wrap: wrap; justify-content: space-between; }
  .offer { flex-direction: column; align-items: stretch; }
  .frow { flex-wrap: wrap; }
  .card.status { flex-direction: column; align-items: flex-start; }
  .tool-grid { grid-template-columns: 1fr; }
  .score .sbar { margin-bottom: 6px; }
  .step { gap: 12px; }
  .dropzone { padding: 18px 10px; }

  /* fenêtres */
  dialog { width: 100vw; max-width: 100vw; margin: auto 0 0 0; border-radius: 18px 18px 0 0; max-height: 92vh; overflow-y: auto; padding: 18px 16px calc(18px + env(safe-area-inset-bottom)); }
  dialog:has(.modal-wide) { width: 100vw; }

  /* tableaux : une carte par ligne */
  table.list, table.list tbody, table.list tr, table.list td { display: block; width: 100%; }
  table.list thead { display: none; }
  table.list tr { border: 1px solid var(--line); border-radius: 12px; padding: 8px 12px; margin-bottom: 10px; background: var(--card2); }
  table.list tr:hover td { background: none; }
  table.list td { display: flex; justify-content: space-between; align-items: center; gap: 12px; border: 0; padding: 6px 0; text-align: right; }
  table.list td::before { content: attr(data-label); color: var(--muted); font-size: .7rem; text-transform: uppercase; letter-spacing: .05em; text-align: left; flex: none; }
  table.list td[data-label=""]::before { display: none; }
  table.list td[data-label=""] { justify-content: flex-end; flex-wrap: wrap; }
  .card:has(> table.list) { overflow: visible; }
  #catTable td:nth-child(3) { min-width: 0; }
  #catTable td, #catTable th { white-space: normal; }

  /* connexion */
  .auth-card { padding: 28px 18px; max-width: none; }
  .auth-theme { top: 12px; right: 12px; }
  .plan { padding: 18px; }
  .price { font-size: 1.7rem; }
  .toast { bottom: calc(80px + env(safe-area-inset-bottom)); max-width: 92vw; text-align: center; }
}

/* ----- Écrans tactiles : cibles plus grandes ----- */
@media (pointer: coarse) {
  .btn { min-height: 40px; }
  .btn.small { min-height: 36px; }
  .btn.icon { min-width: 36px; }
  input:not([type=checkbox]):not([type=radio]):not([type=range]), select { min-height: 44px; }
  .star { min-width: 36px; min-height: 36px; }
}

/* ----- Impression : toujours le document complet ----- */
@media print {
  .editor[data-pane] .preview-wrap { display: block !important; }
  .bottomnav, .more-sheet, .pane-switch { display: none !important; }
}

/* ----- Navigation : libellés courts selon la largeur, barre du bas jusqu'à 900 px ----- */
.brand { white-space: nowrap; }
.pill { white-space: nowrap; }
#nav .sh, #accessPill .sh { display: none; }
@media (max-width: 1280px) { #nav .lg { display: none; } #nav .sh { display: inline; } }
@media (max-width: 760px) { #accessPill .lg { display: none; } #accessPill .sh { display: inline; } }
@media (max-width: 900px) {
  #nav { display: none; }
  .topbar { height: 54px; padding: 0 14px; gap: 10px; padding-top: env(safe-area-inset-top); }
  #accessPill { margin-left: auto; }
  main { padding-bottom: calc(88px + env(safe-area-inset-bottom)); }
  .bottomnav { display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(14px); border-top: 1px solid var(--line); padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); }
  .bottomnav button { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px; background: none; border: 0; color: var(--muted); font: inherit; font-size: .72rem; font-weight: 600; padding: 6px 2px; border-radius: 10px; cursor: pointer; }
  .bottomnav button .ic { width: 22px; height: 22px; margin: 0; }
  .bottomnav button.active { color: var(--text); }
  .bottomnav button.active .ic { stroke-width: 2.4; }
  body.auth-mode .bottomnav, body.auth-mode .more-sheet { display: none !important; }
  .more-sheet:not([hidden]) { display: block; position: fixed; inset: 0; z-index: 45; }
  .sheet-bg { position: absolute; inset: 0; background: rgba(0, 0, 0, .55); }
  .sheet { position: absolute; left: 0; right: 0; bottom: 0; max-width: 560px; margin: 0 auto; background: var(--card); border: 1px solid var(--line); border-bottom: 0; border-radius: 18px 18px 0 0; padding: 10px 12px calc(14px + env(safe-area-inset-bottom)); }
  .sheet .pop-head { padding: 10px 12px; }
  .sheet button { display: block; width: 100%; text-align: left; padding: 14px 12px; background: none; border: 0; border-bottom: 1px solid var(--line); color: var(--text); font: inherit; font-size: 1rem; cursor: pointer; }
  .sheet button.danger { color: var(--danger); border-bottom: 0; }
  .toast { bottom: calc(80px + env(safe-area-inset-bottom)); }
}

/* ----- Ajustements tablette / zones étroites ----- */
.theme-btn, .avatar, #userbox, #accessPill { flex: none; }
#nav { flex: 1 1 auto; min-width: 0; overflow-x: auto; scrollbar-width: none; }
#nav::-webkit-scrollbar { display: none; }
.editor .form { container-type: inline-size; container-name: form; }
@container form (max-width: 640px) {
  .line .r1 { grid-template-columns: 76px 1fr; }
  .line .r2 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .line .tot { text-align: left; } .line .tot label { text-align: left; }
  .line .acts { grid-column: 1 / -1; justify-content: flex-end; }
  .grid3 { grid-template-columns: 1fr 1fr; }
}
@container form (max-width: 460px) { .grid2, .grid3 { grid-template-columns: 1fr; } }
@media (max-width: 900px) {
  /* tableaux : une carte par ligne (2 colonnes sur tablette, 1 sur téléphone) */
  table.list, table.list tbody, table.list tr, table.list td { display: block; width: 100%; }
  table.list thead { display: none; }
  table.list tbody { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
  table.list tr { border: 1px solid var(--line); border-radius: 12px; padding: 8px 12px; background: var(--card2); margin: 0; }
  table.list tr:hover td { background: none; }
  table.list td { display: flex; justify-content: space-between; align-items: center; gap: 12px; border: 0; padding: 6px 0; text-align: right; }
  table.list td::before { content: attr(data-label); color: var(--muted); font-size: .7rem; text-transform: uppercase; letter-spacing: .05em; text-align: left; flex: none; }
  table.list td[data-label=""]::before { display: none; }
  table.list td[data-label=""] { justify-content: flex-end; flex-wrap: wrap; }
  .card:has(> table.list) { overflow: visible; }
  #catTable td, #catTable th { white-space: normal; }
  #catTable td:nth-child(3) { min-width: 0; }
  table.list td:first-child .star { margin-left: -8px; }
}
@media (max-width: 640px) { table.list tbody { grid-template-columns: 1fr; } }
@media (max-width: 1280px) and (min-width: 901px) { #nav button { padding: 8px 8px; } .topbar { gap: 10px; } }
html { overflow-x: hidden; }
@media (max-width: 640px) {
  .tabs { overflow: visible; flex-wrap: wrap; gap: 0; }
  .tabs button { padding: 10px 10px; }
  #cpSearch { min-width: 180px; }
}
@media (max-width: 900px) { table.list tbody { grid-template-columns: repeat(2, minmax(0, 1fr)); } table.list td { min-width: 0; overflow-wrap: anywhere; } }
@media (max-width: 640px) { table.list tbody { grid-template-columns: minmax(0, 1fr); } }

/* ===== Personnalisation (couleur, fond, formes, texte, densité) ===== */
html[data-radius="sharp"] { --radius: 4px; --rb: 3px; }
html[data-radius="round"] { --radius: 22px; --rb: 16px; }
html[data-size="large"] { --fs: 17px; }
html[data-size="xl"] { --fs: 19px; }
html[data-density="compact"] .card { padding: 14px; margin-bottom: 14px; }
html[data-density="compact"] main { padding-top: 18px; }
html[data-density="compact"] .field { margin-bottom: 9px; }
html[data-density="compact"] table.list td { padding: 7px 10px; }
html[data-density="compact"] .btn { padding: 6px 12px; }
:root[data-bg="graphite"]:not([data-theme="light"]) { --bg: #131417; --bg2: #17181c; --card: #1b1c21; --card2: #212227; --line: #2b2d33; --input: #15161a; --input-line: #34363d; }
:root[data-bg="navy"]:not([data-theme="light"]) { --bg: #0a1020; --bg2: #0d1428; --card: #111a30; --card2: #16213b; --line: #223153; --input: #0c1426; --input-line: #2c3d63; }
:root[data-bg="bronze"]:not([data-theme="light"]) { --bg: #0d0a07; --bg2: #120e0a; --card: #17120d; --card2: #1e1812; --line: #33281c; --input: #110d09; --input-line: #403222; }
:root[data-bg="forest"]:not([data-theme="light"]) { --bg: #0a120e; --bg2: #0d1712; --card: #101b15; --card2: #15231b; --line: #223a2c; --input: #0c1510; --input-line: #2c4a39; }
.optrow { display: flex; gap: 8px; flex-wrap: wrap; }
.opt { padding: 10px 16px; border-radius: var(--rb); border: 1px solid var(--line); background: var(--card2); color: var(--text); font: inherit; font-size: .9rem; font-weight: 500; cursor: pointer; }
.opt:hover { border-color: var(--accent); }
.opt.on { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); font-weight: 700; }
.swatches { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.sw { width: 40px; height: 40px; border-radius: 50%; border: 2px solid var(--line); cursor: pointer; display: inline-flex; align-items: center; justify-content: center; padding: 0; color: #fff; }
.sw.on { outline: 3px solid var(--text); outline-offset: 2px; }
.sw .ic { margin: 0; width: 18px; height: 18px; }
.sw.neutral { background: linear-gradient(135deg, #f2f2f3 50%, #0a0a0a 50%); }
.bgsw { width: 76px; height: 52px; border-radius: 10px; border: 2px solid var(--line); cursor: pointer; padding: 0; }
.bgsw.on { outline: 3px solid var(--accent); outline-offset: 2px; }
.preview-box { padding: 18px; border: 1px dashed var(--input-line); border-radius: var(--radius); }
.pref-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; align-items: start; }
.pref-grid .card { margin: 0; }
@media (max-width: 900px) { .pref-grid { grid-template-columns: 1fr; } .pref-grid .card[style] { grid-column: auto !important; } }
.sw:not(.on) { color: transparent; } .sw.neutral.on { color: #0a0a0a; }
#nav button { white-space: nowrap; }

/* ===== Chantiers ===== */
.bar { height: 8px; border-radius: 999px; background: var(--line); overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--accent); border-radius: 999px; }
.bar.over i { background: var(--danger); }
.kv { display: grid; grid-template-columns: 90px 1fr; gap: 8px 14px; margin: 0; }
.kv dt { color: var(--muted); font-size: .85rem; } .kv dd { margin: 0; overflow-wrap: anywhere; }

/* ===== Palette or et blanc : textes chauds, titres couleur principale ===== */
:root[data-bg="bronze"]:not([data-theme="light"]) { --text: #f7ead4; --muted: #ad9672; --primary: #f7ead4; --primary-soft: rgba(227, 160, 75, .12); }
:root[data-theme="light"] { --text: #1d150b; --muted: #7b6a54; --line: #e8e2d8; --input-line: #d9d0c2; --bg: #f7f5f1; --bg2: #efebe4; --card2: #f8f6f2; }
#app h1:not(.doc *), #app h2:not(.doc *), #app .stat .n:not(.doc *) { color: var(--accent); }
:root[data-theme="light"] #app h1:not(.doc *), :root[data-theme="light"] #app h2:not(.doc *), :root[data-theme="light"] #app .stat .n:not(.doc *) { color: color-mix(in srgb, var(--accent) 60%, #000); }
#app a:not(.doc *):not(.btn) { text-decoration-color: color-mix(in srgb, var(--accent) 60%, transparent); }


/* ===== Éditeur (ordinateur) : le formulaire de gauche défile seul, avec sa barre de défilement, comme l'aperçu ===== */
@media (min-width: 1151px) {
  .editor .form { position: sticky; top: 80px; max-height: calc(100vh - 100px); overflow-y: auto; overflow-x: hidden; padding: 0 8px 24px 0; overscroll-behavior: contain; }
  .editor .form, .editor .preview-wrap { scrollbar-width: thin; scrollbar-color: color-mix(in srgb, var(--accent) 55%, var(--line)) transparent; }
  .editor .form::-webkit-scrollbar, .editor .preview-wrap::-webkit-scrollbar { width: 10px; }
  .editor .form::-webkit-scrollbar-track, .editor .preview-wrap::-webkit-scrollbar-track { background: transparent; }
  .editor .form::-webkit-scrollbar-thumb, .editor .preview-wrap::-webkit-scrollbar-thumb { background: color-mix(in srgb, var(--accent) 55%, var(--line)); border-radius: 8px; border: 2px solid transparent; background-clip: padding-box; }
  .editor .form::-webkit-scrollbar-thumb:hover, .editor .preview-wrap::-webkit-scrollbar-thumb:hover { background: var(--accent); background-clip: padding-box; border: 2px solid transparent; }
}
@media print { .editor .form { display: none !important; } }
