/* GR Factures — vert profond, crème, papier. */
:root {
  --bg: #f4f2ea; --paper: #fffdf8; --ink: #1d2823; --muted: #6a736d; --faint: #9aa29c;
  --line: #e4e0d3; --line-strong: #d3cebd;
  --accent: #24493a; --accent-hover: #1b3a2e; --accent-ink: #fbfaf5; --accent-soft: #e5ede6;
  --gold: #b48a4f;
  --good: #23704a; --good-bg: #e3f1e8; --bad: #a8321f; --bad-bg: #fbe9e4;
  --warn: #8a5a0b; --warn-bg: #fbf0d9;
  --field: #fbf9f2;
  --shadow: 0 1px 2px rgba(29, 40, 35, .04), 0 8px 24px -12px rgba(29, 40, 35, .12);
  --radius: 16px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111714; --paper: #18201c; --ink: #e9ede8; --muted: #a2aba5; --faint: #77817b;
    --line: #2a332e; --line-strong: #39443e;
    --accent: #7dbb9a; --accent-hover: #93c9ac; --accent-ink: #0f1512; --accent-soft: #1f2d26;
    --gold: #cfa86e;
    --good: #79c79a; --good-bg: #18301f; --bad: #f09a87; --bad-bg: #3a1c16;
    --warn: #e2b75f; --warn-bg: #33280f;
    --field: #141b17;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  -webkit-font-smoothing: antialiased; }
a { color: var(--accent); }
h1, h2, h3 { letter-spacing: -.015em; }
h2 { font-size: 1.08rem; margin: 0 0 1rem; display: flex; align-items: center; gap: .55rem; }
h2 .step { display: inline-grid; place-items: center; width: 1.6rem; height: 1.6rem; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent); font-size: .8rem; font-weight: 700; }
h3 { font-size: .95rem; margin: 1.4rem 0 .6rem; }
.muted { color: var(--muted); } .small { font-size: .86rem; }
.mono { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: .8rem; word-break: break-all; }
.bad-text { color: var(--bad); }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8;
  stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }

/* --- Charpente : menu latéral (ordinateur) / barre d'onglets (téléphone) --- */
.shell { min-height: 100vh; }
.side { position: sticky; top: 0; z-index: 20; background: var(--bg);
  border-bottom: 1px solid var(--line); padding: 10px 16px 0; }
.brand { display: flex; align-items: center; gap: .7rem; color: var(--ink); text-decoration: none; }
.mark { position: relative; display: grid; place-items: center; width: 38px; height: 38px; border-radius: 11px;
  background: var(--accent); color: var(--accent-ink); font-weight: 800; font-size: .95rem; letter-spacing: -.02em; }
.mark i { position: absolute; right: -3px; bottom: -3px; width: 11px; height: 11px; border-radius: 50%;
  background: var(--gold); border: 2px solid var(--bg); }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text b { font-size: .98rem; letter-spacing: .01em; }
.brand-text small { color: var(--muted); font-size: .76rem; }
.side-label, .side-foot { display: none; }
.nav { display: flex; gap: 2px; margin: 8px -16px 0; padding: 0 12px; overflow-x: auto; scrollbar-width: none; }
.nav::-webkit-scrollbar { display: none; }
.nav a { display: flex; align-items: center; gap: .4rem; padding: .6rem .7rem .7rem; color: var(--muted);
  text-decoration: none; font-weight: 600; font-size: .92rem; white-space: nowrap; border-bottom: 2.5px solid transparent; }
.nav a svg { width: 18px; height: 18px; }
.nav a em { font-style: normal; display: none; }
.nav a.on { color: var(--accent); border-bottom-color: var(--accent); }

.main { padding: 20px 16px 120px; max-width: 1240px; }
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 20px; }
.eyebrow { margin: 0 0 .35rem; font-size: .72rem; font-weight: 700; letter-spacing: .16em; text-transform: uppercase; color: var(--muted); }
.page-head h1 { margin: 0; font-size: 1.85rem; line-height: 1.1; font-weight: 800; letter-spacing: -.025em; overflow-wrap: anywhere; }
.page-head .sub { margin: .45rem 0 0; color: var(--muted); }
.date-pill { display: none; padding: .45rem .9rem; border: 1px solid var(--line); border-radius: 999px;
  background: var(--paper); font-size: .85rem; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }

@media (min-width: 980px) {
  .shell { display: grid; grid-template-columns: 268px 1fr; }
  .side { height: 100vh; display: flex; flex-direction: column; padding: 28px 22px 22px;
    border-bottom: 0; border-right: 1px solid var(--line); }
  .mark { width: 44px; height: 44px; font-size: 1.05rem; border-radius: 13px; }
  .brand-text b { font-size: 1.02rem; letter-spacing: .12em; text-transform: uppercase; }
  .side-label { display: block; margin: 40px 10px 10px; font-size: .7rem; font-weight: 700;
    letter-spacing: .16em; text-transform: uppercase; color: var(--muted); }
  .nav { flex-direction: column; gap: 4px; margin: 0; padding: 0; overflow: visible; }
  .nav a { gap: .8rem; padding: .8rem .9rem; border-radius: 12px; border: 0; font-size: 1rem; color: var(--ink); }
  .nav a em { display: inline; }
  .nav a svg { width: 20px; height: 20px; color: var(--muted); }
  .nav a:hover { background: var(--paper); }
  .nav a.on { background: var(--accent-soft); color: var(--accent); }
  .nav a.on svg { color: var(--accent); }
  .side-foot { display: flex; flex-direction: column; gap: 14px; margin-top: auto; }
  .side-quote { display: flex; flex-direction: column; gap: .3rem; padding: 0 10px; font-size: .86rem; }
  .side-quote svg { width: 44px; height: 44px; padding: 11px; border-radius: 13px; background: var(--accent-soft);
    color: var(--accent); margin-bottom: .5rem; }
  .side-quote span { color: var(--muted); line-height: 1.45; }
  .quit { background: none; border: 0; padding: .5rem 10px; color: var(--muted); font: inherit; font-size: .88rem;
    cursor: pointer; text-align: left; }
  .quit:hover { color: var(--ink); }
  .main { padding: 44px 48px 64px; }
  .page-head { margin-bottom: 32px; }
  .page-head h1 { font-size: 2.6rem; }
  .date-pill { display: inline-block; }
}

/* --- Cartes, champs ------------------------------------------------------- */
.stack > * + * { margin-top: 16px; }
.card { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px;
  box-shadow: var(--shadow); }
.card + .card, .alert + .card, .card + .alert { margin-top: 16px; }
@media (min-width: 980px) { .card { padding: 26px 28px; } }

.field { display: block; margin-bottom: .95rem; }
.field > span { display: block; font-size: .86rem; font-weight: 600; margin-bottom: .35rem; }
.field > span .opt { font-weight: 400; color: var(--faint); }
.field.small { margin: .9rem 0 0; }
input, select, textarea { width: 100%; font: inherit; font-size: 16px; color: var(--ink); background: var(--field);
  border: 1px solid var(--line); border-radius: 12px; padding: .78rem .9rem; transition: border-color .15s, box-shadow .15s; }
input::placeholder, textarea::placeholder { color: var(--faint); }
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent); background: var(--paper); }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
@media (max-width: 460px) { .row { grid-template-columns: 1fr; } }

.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 8px; margin-bottom: 1rem; }
.seg label { position: relative; }
.seg input { position: absolute; opacity: 0; inset: 0; pointer-events: none; }
.seg span { display: flex; align-items: center; justify-content: center; text-align: center; min-height: 48px; height: 100%;
  padding: .55rem .6rem; border: 1px solid var(--line); border-radius: 12px; background: var(--field);
  font-size: .92rem; font-weight: 600; line-height: 1.2; cursor: pointer; transition: all .15s; }
.seg span:hover { border-color: var(--line-strong); }
.seg input:checked + span { border-color: var(--accent); background: var(--accent); color: var(--accent-ink); }
.seg input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.seg.three span { font-size: .86rem; }
.seg.stores span { min-height: 58px; }

form[data-kind="part"] .pro-only, form[data-kind="pro"] .part-only { display: none; }

/* --- Boutons, messages ---------------------------------------------------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .5rem; min-height: 50px;
  padding: .6rem 1.3rem; border-radius: 12px; border: 1px solid var(--line-strong); background: var(--paper);
  color: var(--ink); font: inherit; font-weight: 700; text-decoration: none; cursor: pointer; transition: all .15s; }
.btn:hover { border-color: var(--ink); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.wide { width: 100%; }
.btn:disabled { opacity: .55; cursor: progress; }
.btn svg { width: 18px; height: 18px; }
.link { background: none; border: 0; color: var(--accent); font: inherit; font-size: .9rem; font-weight: 600; padding: .3rem 0; cursor: pointer; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 16px; }
.actions .btn { flex: 1 1 150px; }

.alert { border-radius: 12px; padding: .8rem 1rem; margin: 1rem 0; }
.alert.bad { background: var(--bad-bg); color: var(--bad); }
.alert.good { background: var(--good-bg); color: var(--good); }
.alert.warn { background: var(--warn-bg); color: var(--warn); }
.badge { display: inline-block; font-size: .76rem; font-weight: 700; padding: .22rem .6rem; border-radius: 999px;
  background: var(--accent-soft); color: var(--muted); white-space: nowrap; }
.s-envoye { background: var(--good-bg); color: var(--good); }
.s-echec { background: var(--bad-bg); color: var(--bad); }
.s-incertain, .s-en_cours { background: var(--warn-bg); color: var(--warn); }
.banner { display: flex; gap: .8rem; align-items: flex-start; padding: 1rem 1.2rem; border-radius: var(--radius);
  background: var(--accent-soft); border: 1px solid color-mix(in srgb, var(--accent) 20%, transparent); }
.banner svg { color: var(--accent); margin-top: 2px; }
.banner b { display: block; }
.banner span { color: var(--muted); font-size: .9rem; }

/* --- Nouvelle facture : formulaire + aperçu en direct ----------------------- */
.compose { display: grid; gap: 16px; }
@media (min-width: 1180px) {
  .compose { grid-template-columns: minmax(0, 1fr) 430px; gap: 28px; align-items: start; }
  .preview-col { position: sticky; top: 28px; }
}
.preview-col .eyebrow { margin: 4px 0 10px 4px; }
.sheet { background: #fffefb; color: #1d1d1f; border-radius: 6px; padding: 26px 24px 22px; font-size: 10.5px; line-height: 1.45;
  box-shadow: 0 1px 2px rgba(0,0,0,.06), 0 18px 40px -18px rgba(29, 40, 35, .35); border: 1px solid #ece8dc;
  aspect-ratio: 1 / 1.3; display: flex; flex-direction: column; }
.sheet-top { display: flex; justify-content: space-between; gap: 12px; }
.sheet-seller div:first-child { font-weight: 800; font-size: 11.5px; margin-bottom: 2px; }
.sheet-seller div { white-space: pre-line; }
.sheet-title { text-align: right; }
.sheet-title b { display: block; font-size: 19px; letter-spacing: .02em; margin-bottom: 4px; }
.sheet-title span { display: block; color: #6e6e73; }
.sheet-client { margin: 18px 0 0 50%; min-height: 64px; }
.sheet-client small { display: block; color: #6e6e73; font-size: 8.5px; letter-spacing: .08em; margin-bottom: 2px; }
.sheet-client .ph, .sheet .ph { color: #b9b6ac; }
.sheet table { width: 100%; border-collapse: collapse; margin-top: 18px; font-variant-numeric: tabular-nums; }
.sheet th { background: #f2f1ec; font-weight: 700; text-align: right; padding: 6px 4px; white-space: nowrap; }
.sheet th:first-child, .sheet td:first-child { text-align: left; }
.sheet td { padding: 7px 4px; text-align: right; white-space: nowrap; border-bottom: 1px solid #e6e3da; vertical-align: top; }
.sheet td:first-child { white-space: normal; }
.sheet td small { display: block; color: #8a877e; }
.sheet-totals { margin: 12px 0 0 auto; width: 58%; font-variant-numeric: tabular-nums; }
.sheet-totals div { display: flex; justify-content: space-between; padding: 2px 6px; }
.sheet-totals .ttc { font-weight: 800; font-size: 12px; border-top: 1px solid #1d1d1f; margin-top: 4px; padding-top: 6px; }
.sheet-foot { margin-top: auto; padding-top: 14px; color: #6e6e73; }
.sheet-msg { margin-top: 10px; color: var(--bad); font-size: .85rem; min-height: 1.2em; }
.preview-actions { display: grid; grid-template-columns: 1fr 1.4fr; gap: 10px; margin-top: 16px; }
.mobile-bar { display: none; }
@media (max-width: 1179px) {
  .preview-col { order: 2; }
  .preview-actions { display: none; }
  .mobile-bar { display: flex; align-items: center; gap: 12px; position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
    padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); background: color-mix(in srgb, var(--paper) 94%, transparent);
    backdrop-filter: blur(10px); border-top: 1px solid var(--line); }
  .mobile-bar .total { flex: 1; min-width: 0; line-height: 1.2; }
  .mobile-bar .total small { display: block; color: var(--muted); font-size: .75rem; }
  .mobile-bar .total b { font-size: 1.15rem; font-variant-numeric: tabular-nums; }
  .mobile-bar .btn { min-height: 48px; padding: .5rem 1rem; }
}
@media (max-width: 420px) { .sheet { padding: 18px 14px; font-size: 9.5px; aspect-ratio: auto; min-height: 420px; } }

/* --- Facture, historique, clients ---------------------------------------- */
.head-row { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: .55rem 1.4rem; margin: 0; }
.kv dt { color: var(--muted); font-size: .88rem; } .kv dd { margin: 0; overflow-wrap: anywhere; }
.amount-big { font-size: 2rem; font-weight: 800; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.two { display: grid; gap: 16px; }
@media (min-width: 980px) { .two { grid-template-columns: 1.2fr 1fr; align-items: start; } .two .card + .card { margin-top: 0; } }
.log { list-style: none; padding: 0; margin: 0; }
.log li { padding: .8rem 0; border-top: 1px solid var(--line); font-size: .9rem; }

.search { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.search input { flex: 2 1 240px; } .search select { flex: 1 1 180px; width: auto; }
.search .btn { flex: 0 0 auto; }
.list { padding: 6px 20px; }
@media (min-width: 980px) { .list { padding: 6px 28px; } }
.item { display: flex; justify-content: space-between; align-items: center; gap: 14px; padding: 1rem 0;
  border-top: 1px solid var(--line); color: inherit; text-decoration: none; }
.item:first-child { border-top: 0; }
a.item:hover strong:first-child { color: var(--accent); }
.item > div:first-child { min-width: 0; overflow-wrap: anywhere; }
.avatar { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 50%; flex-shrink: 0;
  background: var(--accent-soft); color: var(--accent); font-weight: 800; font-size: .9rem; }
.who { display: flex; gap: 12px; align-items: center; min-width: 0; }
.right { text-align: right; flex-shrink: 0; }
.right strong { font-variant-numeric: tabular-nums; }
.empty { text-align: center; padding: 2.5rem 1rem; color: var(--muted); }

.suggest { border: 1px solid var(--line); border-radius: 12px; margin: -.5rem 0 1rem; overflow: hidden; background: var(--paper); box-shadow: var(--shadow); }
.suggest button { display: block; width: 100%; text-align: left; background: none; color: var(--ink); border: 0;
  border-top: 1px solid var(--line); padding: .7rem .9rem; font: inherit; font-size: .92rem; cursor: pointer; }
.suggest button:first-child { border-top: 0; }
.suggest button:hover { background: var(--accent-soft); }
.profiles { margin: -.4rem 0 1rem; padding: .8rem .9rem; border-radius: 12px; background: var(--accent-soft); }
.profiles p { margin: 0 0 .55rem; color: var(--accent); font-weight: 600; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font: inherit; font-size: .88rem; font-weight: 600; padding: .45rem .85rem; border-radius: 999px; cursor: pointer;
  border: 1px solid var(--line-strong); background: var(--paper); color: var(--ink); max-width: 100%;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.presets { margin-bottom: .55rem; }
.pay-row { display: grid; grid-template-columns: minmax(0, 1fr) 128px 40px; gap: 8px; align-items: center; margin-bottom: 8px; }
.pay-row.single { grid-template-columns: minmax(0, 1fr); }
.pay-row .check { grid-column: 1 / -1; margin-top: -2px; }
.pay-row .x { width: 40px; height: 46px; border: 1px solid var(--line); border-radius: 12px; background: var(--field);
  color: var(--muted); font-size: 1.2rem; cursor: pointer; }
.pay-row .x:hover { color: var(--bad); border-color: var(--bad); }
.pay-summary { margin: .5rem 0 0; padding: .6rem .8rem; border-radius: 10px; background: var(--accent-soft);
  color: var(--accent); font-size: .88rem; font-weight: 600; }
.pay-summary.warn { background: var(--warn-bg); color: var(--warn); }
.chip.add { border-style: dashed; color: var(--accent); background: transparent; }

/* --- Connexion ------------------------------------------------------------ */
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px;
  background: radial-gradient(1200px 600px at 50% -10%, color-mix(in srgb, var(--accent) 12%, transparent), transparent 70%), var(--bg); }
.login-wrap { width: 100%; max-width: 400px; }
.login-brand { display: flex; flex-direction: column; align-items: center; gap: .6rem; margin-bottom: 22px; }
.login-brand .mark { width: 52px; height: 52px; font-size: 1.15rem; border-radius: 15px; }
.login-brand b { letter-spacing: .2em; text-transform: uppercase; font-size: .95rem; }
.login-brand small { color: var(--muted); font-size: .72rem; letter-spacing: .3em; text-transform: uppercase; margin-top: -.4rem; }
.login-card h1 { font-size: 1.5rem; margin: .2rem 0 .3rem; letter-spacing: -.02em; }
.login-card .lock { width: 44px; height: 44px; padding: 11px; border-radius: 13px; background: var(--accent-soft); color: var(--accent); }
.login-foot { margin-top: 14px; color: var(--faint); font-size: .8rem; text-align: center; }

/* Finitions téléphone */
@media (max-width: 1179px) { .mobile-bar .total b { white-space: nowrap; font-size: 1.05rem; } }
@media (max-width: 520px) {
  .nav { justify-content: space-between; }
  .nav a { padding: .6rem .45rem .7rem; font-size: .9rem; }
  .nav a svg { display: none; }
}
.search > * { min-width: 0; }
@media (max-width: 520px) {
  .search input, .search select { flex: 1 1 100%; width: 100%; }
  .search .btn { flex: 1 1 auto; }
  .avatar { display: none; }
  .item { align-items: flex-start; }
}
.check { display: inline-flex; align-items: center; gap: .5rem; font-size: .88rem; font-weight: 600; cursor: pointer;
  padding: .35rem .2rem; color: var(--muted); }
.check input { width: 20px; height: 20px; margin: 0; padding: 0; accent-color: var(--accent); cursor: pointer; }
.check input:checked + span { color: var(--bad); }
.chip.add.on { background: var(--accent); border-style: solid; color: var(--accent-ink); }

/* Paramètres : ajout d'un magasin */
.add-store { margin-top: 16px; padding: 0; }
.add-store > summary { list-style: none; cursor: pointer; display: flex; align-items: center; gap: .7rem;
  padding: 18px 20px; font-weight: 700; color: var(--accent); }
.add-store > summary::-webkit-details-marker { display: none; }
.add-store .plus { display: inline-grid; place-items: center; width: 1.8rem; height: 1.8rem; border-radius: 50%;
  background: var(--accent-soft); font-size: 1.1rem; }
.add-store[open] > summary { border-bottom: 1px solid var(--line); }
.add-form { padding: 20px; }
@media (min-width: 980px) { .add-store > summary { padding: 22px 28px; } .add-form { padding: 26px 28px; } }
.company-choice { grid-auto-flow: row; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.company-choice span { flex-direction: column; gap: .15rem; }
.company-choice small { font-weight: 500; font-size: .76rem; opacity: .8; }
.add-form:has(input[value="__new__"]:not(:checked)) .new-company { display: none; }
/* Plus de deux magasins : les boutons passent à la ligne */
.seg.stores { grid-auto-flow: row; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.mentions { border: 0; padding: 16px 0 4px; margin: 4px 0 12px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); min-width: 0; }
.mentions legend { padding: 0 .5rem 0 0; font-weight: 700; font-size: .95rem; }
.printed { margin: -4px 0 14px; font-size: .86rem; color: var(--muted); }
.printed summary { cursor: pointer; }
.printed pre { margin: .5rem 0 0; padding: .8rem 1rem; background: var(--field); border: 1px solid var(--line); border-radius: 10px;
  font: inherit; font-size: .86rem; white-space: pre-wrap; color: var(--ink); }
