/* ============================================================
   /facture-libre/ — Reçus & factures sans compte
   Le blanc domine ; --c1 et --c2 sont choisies par le visiteur.
   ============================================================ */

:root {
    --c1: #0f766e;
    --c2: #f59e0b;
    --c1-soft: rgba(15, 118, 110, .08);
    --c2-soft: rgba(245, 158, 11, .12);

    --ink: #14181d;
    --ink-soft: #626d78;
    --line: #e7ebef;
    --bg: #f7f9fb;
    --white: #ffffff;
    --danger: #d92b45;

    --r: 16px;
    --r-sm: 11px;
    --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 8px 24px rgba(16, 24, 40, .06);
    --header-h: 58px;
    --steps-h: 56px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
    background: var(--bg);
    color: var(--ink);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    line-height: 1.5;
}

img, svg { max-width: 100%; }
button, input, select, textarea { font-family: inherit; }

/* ---------------- HEADER ---------------- */
.app-header {
    position: fixed;
    inset: 0 0 auto 0;
    height: var(--header-h);
    background: var(--white);
    border-bottom: 1px solid var(--line);
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 14px;
    z-index: 60;
}
.hd-back {
    width: 34px; height: 34px;
    display: flex; align-items: center; justify-content: center;
    border-radius: 10px;
    color: var(--ink);
    background: var(--bg);
    text-decoration: none;
    flex-shrink: 0;
}
.hd-title { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.2; }
.hd-title strong { font-size: 15px; font-weight: 700; }
.hd-title span { font-size: 11px; color: var(--ink-soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hd-book {
    display: inline-flex; align-items: center; gap: 6px;
    background: var(--c1); color: #fff;
    border: none; border-radius: 999px;
    padding: 8px 13px; font-size: 12px; font-weight: 700;
    cursor: pointer; flex-shrink: 0;
}

/* ---------------- STEPS ---------------- */
.steps-bar {
    position: fixed;
    top: var(--header-h); left: 0; right: 0;
    background: var(--white);
    border-bottom: 1px solid var(--line);
    z-index: 55;
}
.steps-inner {
    display: flex; gap: 6px;
    padding: 11px 14px 9px;
    overflow-x: auto;
    scrollbar-width: none;
}
.steps-inner::-webkit-scrollbar { display: none; }
.step-dot {
    font-size: 11.5px; font-weight: 600;
    color: var(--ink-soft);
    background: var(--bg);
    border-radius: 999px;
    padding: 5px 11px;
    white-space: nowrap;
}
.step-dot.is-active { color: #fff; background: var(--c1); }
.step-dot.is-done { color: var(--c1); background: var(--c1-soft); }
.steps-track { height: 3px; background: var(--line); }
.steps-fill { height: 100%; width: 33.33%; background: var(--c2); transition: width .35s ease; }

/* ---------------- LAYOUT ---------------- */
.main {
    max-width: 640px;
    margin: 0 auto;
    padding: calc(var(--header-h) + var(--steps-h) + 16px) 14px 72px;
}
.step { display: none; }
.step.is-active { display: block; animation: rise .28s ease; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.card {
    background: var(--white);
    border: 1px solid var(--line);
    border-radius: var(--r);
    padding: 18px 16px;
    margin-bottom: 14px;
    box-shadow: var(--shadow);
}
.card h2 {
    font-size: 16px; font-weight: 700;
    display: flex; align-items: center; gap: 8px;
    margin-bottom: 4px;
}
.card h2 i { color: var(--c1); font-size: 15px; }
.subtitle { font-size: 12.5px; color: var(--ink-soft); margin-bottom: 14px; }

.hero-card { border: none; background: linear-gradient(180deg, var(--c1-soft), var(--white)); }
.hero-card h1 { font-size: 24px; font-weight: 800; letter-spacing: -.4px; margin-bottom: 6px; }
.hero-card .lead { font-size: 13.5px; color: var(--ink-soft); }

/* ---------------- COULEURS ---------------- */
.swatches {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(46px, 1fr));
    gap: 9px;
    margin-bottom: 14px;
}
.swatch {
    position: relative;
    aspect-ratio: 1;
    border-radius: 12px;
    border: 2px solid transparent;
    cursor: pointer;
    outline: none;
    box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .06);
}
.swatch.is-on { border-color: var(--ink); }
.swatch.is-on::after {
    content: '\f00c';
    font-family: 'Font Awesome 6 Free'; font-weight: 900;
    position: absolute; inset: 0;
    display: flex; align-items: center; justify-content: center;
    color: #fff; font-size: 13px;
    text-shadow: 0 1px 3px rgba(0, 0, 0, .45);
}
.swatch .sw-rank {
    position: absolute; top: -6px; right: -6px;
    width: 18px; height: 18px; border-radius: 50%;
    background: var(--ink); color: #fff;
    font-size: 10px; font-weight: 700;
    display: none; align-items: center; justify-content: center;
}
.swatch.is-on .sw-rank { display: flex; }

.color-summary { display: flex; flex-wrap: wrap; gap: 14px; font-size: 12px; color: var(--ink-soft); }
.color-summary b { color: var(--ink); }
#csDot1 { color: var(--c1); }
#csDot2 { color: var(--c2); }

/* ---------------- FORMULAIRES ---------------- */
.fg { margin-bottom: 13px; }
.fg label { display: block; font-size: 12px; font-weight: 600; color: var(--ink-soft); margin-bottom: 5px; }
.fg label .hint { font-weight: 400; }
.fg label .opt { font-weight: 400; font-size: 11px; color: #98a2ac; }
.fg label .req { color: var(--danger); }
.fg input, .fg select, .fg textarea {
    width: 100%;
    padding: 12px 13px;
    border: 1.5px solid var(--line);
    border-radius: var(--r-sm);
    background: var(--white);
    font-size: 15px;
    color: var(--ink);
    outline: none;
    transition: border-color .18s, box-shadow .18s;
}
.fg textarea { resize: vertical; }
.fg input:focus, .fg select:focus, .fg textarea:focus {
    border-color: var(--c1);
    box-shadow: 0 0 0 3px var(--c1-soft);
}
.fg-row { display: flex; gap: 10px; }
.fg-row .fg { flex: 1; min-width: 0; }

.remember { display: flex; align-items: center; gap: 9px; font-size: 12.5px; color: var(--ink-soft); margin: 4px 0 14px; cursor: pointer; }
.remember input { width: 17px; height: 17px; accent-color: var(--c1); }

/* ---------------- TILES ---------------- */
.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.tiles-3 { grid-template-columns: repeat(3, 1fr); }
.tile {
    background: var(--white);
    border: 1.5px solid var(--line);
    border-radius: var(--r-sm);
    padding: 13px 10px;
    text-align: center;
    cursor: pointer;
    transition: border-color .18s, background .18s, transform .12s;
    display: flex; flex-direction: column; align-items: center; gap: 3px;
}
.tile:active { transform: scale(.98); }
.tile i { font-size: 19px; color: var(--ink-soft); margin-bottom: 2px; }
.tile b { font-size: 13px; }
.tile span { font-size: 10.5px; color: var(--ink-soft); line-height: 1.3; }
.tile.is-selected { border-color: var(--c1); background: var(--c1-soft); }
.tile.is-selected i { color: var(--c1); }

/* ---------------- ITEMS ---------------- */
.item {
    background: var(--bg);
    border: 1px solid var(--line);
    border-radius: var(--r-sm);
    padding: 13px;
    margin-bottom: 10px;
}
.item-top { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.item-num { font-size: 11px; font-weight: 700; color: var(--c1); text-transform: uppercase; letter-spacing: .4px; }
.item-tag { font-size: 10px; font-weight: 700; padding: 2px 8px; border-radius: 999px; }
.item-tag.product { background: var(--c1-soft); color: var(--c1); }
.item-tag.service { background: var(--c2-soft); color: #8a5a00; }
.item-del {
    margin-left: auto;
    width: 27px; height: 27px; border-radius: 50%;
    border: none; background: rgba(217, 43, 69, .1); color: var(--danger);
    cursor: pointer; font-size: 11px;
}
.item-sum { text-align: right; font-size: 13px; font-weight: 700; color: var(--c1); }

.add-row { display: flex; gap: 9px; }
.btn-add {
    flex: 1;
    padding: 12px;
    border: 1.5px dashed var(--c1);
    background: transparent;
    color: var(--c1);
    border-radius: var(--r-sm);
    font-size: 13px; font-weight: 700;
    cursor: pointer;
}
.btn-add-alt { border-color: var(--c2); color: #8a5a00; }

/* ---------------- BOUTONS ---------------- */
.btn {
    display: flex; align-items: center; justify-content: center; gap: 8px;
    width: 100%;
    padding: 14px;
    border: none;
    border-radius: var(--r-sm);
    font-size: 14.5px; font-weight: 700;
    cursor: pointer;
    text-decoration: none;
    margin-bottom: 10px;
    transition: filter .18s, background .18s;
}
.btn:active { filter: brightness(.95); }
.btn-primary { background: var(--c1); color: #fff; }
.btn-secondary { background: var(--c2); color: #1d1400; }
.btn-outline { background: var(--white); color: var(--c1); border: 1.5px solid var(--c1); }
.btn-ghost { background: var(--bg); color: var(--ink); }
.btn:disabled { opacity: .55; cursor: not-allowed; }

.dl-actions { display: flex; gap: 10px; margin-top: 16px; }
.dl-actions .btn { margin-bottom: 10px; }
.after-actions { display: flex; gap: 10px; }

/* ---------------- MESSAGES ---------------- */
.msg { display: none; font-size: 12.5px; padding: 10px 12px; border-radius: 10px; margin-bottom: 10px; }
.msg.is-on { display: block; }
.msg-error { background: #fdecef; color: var(--danger); }

.toast {
    position: fixed;
    left: 50%; bottom: 22px;
    transform: translate(-50%, 130%);
    background: var(--ink); color: #fff;
    font-size: 13px; font-weight: 600;
    padding: 11px 18px; border-radius: 999px;
    z-index: 200;
    transition: transform .3s ease;
    max-width: calc(100% - 32px);
    text-align: center;
}
.toast.is-on { transform: translate(-50%, 0); }

/* ---------------- PROMO ---------------- */
.promo-card { display: flex; gap: 13px; align-items: flex-start; border-color: var(--c2); background: linear-gradient(180deg, var(--c2-soft), var(--white)); }
.promo-ico {
    width: 40px; height: 40px; flex-shrink: 0;
    border-radius: 12px;
    background: var(--c2); color: #1d1400;
    display: flex; align-items: center; justify-content: center;
    font-size: 17px;
}
.promo-txt h3 { font-size: 14.5px; font-weight: 700; margin-bottom: 4px; }
.promo-txt p { font-size: 12.5px; color: var(--ink-soft); margin-bottom: 10px; }
.promo-txt .btn { margin-bottom: 0; }
.promo-slim { margin-top: 18px; }

/* ---------------- PAGE BADGE ---------------- */
.page-card { padding: 14px 16px; }
.page-badge { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.pb-label { font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: var(--ink-soft); font-weight: 700; }
.pb-num {
    font-size: 19px; font-weight: 800; color: var(--c1);
    background: var(--c1-soft);
    padding: 4px 12px; border-radius: 10px;
}
.pb-book { font-size: 11.5px; color: var(--ink-soft); }

/* ============================================================
   DOCUMENT — style cahier / carnet à souches
   ============================================================ */
.doc-scroll { overflow-x: auto; padding-bottom: 4px; }

.sheet {
    position: relative;
    background: var(--white);
    border: 1px solid var(--line);
    border-radius: 6px;
    box-shadow: 0 10px 30px rgba(16, 24, 40, .1);
    min-width: 320px;
    overflow: hidden;
}
.sheet-holes {
    position: absolute;
    top: 0; bottom: 0; left: 0;
    width: 22px;
    background: repeating-linear-gradient(
        to bottom,
        transparent 0 14px,
        rgba(20, 24, 29, .1) 14px 15px,
        transparent 15px 34px
    );
    border-right: 1px dashed var(--line);
}
.sheet-body { padding-left: 22px; }

.doc-head { display: flex; align-items: center; gap: 12px; padding: 16px 16px 12px; border-bottom: 3px solid var(--c1); }
.doc-logo {
    width: 46px; height: 46px; flex-shrink: 0;
    border-radius: 12px;
    background: var(--c1); color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-size: 16px; font-weight: 800; letter-spacing: .5px;
}
.doc-biz { min-width: 0; }
.doc-biz h2 { font-size: 16px; font-weight: 800; line-height: 1.25; }
.doc-biz p { font-size: 11px; color: var(--ink-soft); }

.doc-band { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 9px 16px; background: var(--c1); color: #fff; }
.doc-band .db-type { font-size: 12.5px; font-weight: 800; letter-spacing: 1.2px; text-transform: uppercase; }
.doc-band .db-num { font-size: 13px; font-weight: 800; background: rgba(255, 255, 255, .2); padding: 2px 10px; border-radius: 8px; }

.doc-flags { display: flex; flex-wrap: wrap; gap: 6px; padding: 10px 16px 0; }
.flag { font-size: 9.5px; font-weight: 800; text-transform: uppercase; letter-spacing: .3px; padding: 3px 9px; border-radius: 999px; }
.flag.warn { background: var(--c2-soft); color: #8a5a00; }
.flag.bad { background: #fdecef; color: var(--danger); }
.flag.ok { background: var(--c1-soft); color: var(--c1); }

.doc-meta { display: flex; flex-wrap: wrap; gap: 4px 16px; padding: 10px 16px 2px; font-size: 11.5px; color: var(--ink-soft); }
.doc-client { padding: 6px 16px 10px; font-size: 13px; }
.doc-client strong { font-weight: 700; }
.doc-client .dc-sub { font-size: 11px; color: var(--ink-soft); }
.doc-rule { border-top: 1.5px dashed var(--line); margin: 2px 16px; }

.doc-table { width: calc(100% - 32px); margin: 10px 16px; border-collapse: collapse; font-size: 12.5px; }
.doc-table th {
    text-align: left; font-size: 9.5px; text-transform: uppercase; letter-spacing: .4px;
    color: var(--ink-soft); font-weight: 800;
    padding-bottom: 6px; border-bottom: 1.5px solid var(--line);
}
.doc-table th.n, .doc-table td.n { text-align: right; }
.doc-table td { padding: 7px 0; border-bottom: 1px solid #f3f5f7; vertical-align: top; }
.doc-table .it-name { font-weight: 600; }
.doc-table .it-ref { font-size: 10px; color: var(--ink-soft); }
.doc-table .it-kind { font-size: 9px; background: var(--bg); color: var(--ink-soft); padding: 1px 6px; border-radius: 5px; display: inline-block; margin-top: 2px; }

.doc-totals { margin: 10px 16px 4px; }
.doc-totals .row { display: flex; justify-content: space-between; gap: 12px; font-size: 12.5px; padding: 3px 0; color: var(--ink-soft); }
.doc-totals .row.grand { font-size: 16.5px; font-weight: 800; color: var(--c1); border-top: 2px solid var(--line); margin-top: 5px; padding-top: 8px; }
.doc-totals .row.rest { font-size: 13px; font-weight: 800; color: var(--danger); }

.doc-note { margin: 10px 16px; font-size: 11.5px; background: var(--c1-soft); color: var(--ink); padding: 9px 11px; border-radius: 9px; }
.doc-due { margin: 4px 16px; font-size: 11px; color: var(--ink-soft); }

.doc-sign { display: flex; align-items: flex-end; justify-content: space-between; gap: 14px; padding: 14px 16px 6px; }
.doc-stamp svg { transform: rotate(-7deg); }
.sign-line { flex: 1; text-align: center; }
.sign-line .sl-bar { border-top: 1px solid var(--ink-soft); margin-bottom: 4px; }
.sign-line span { font-size: 10px; color: var(--ink-soft); }

.doc-footer { text-align: center; padding: 12px 16px 14px; }
.doc-footer .df-thanks { font-size: 12px; font-weight: 700; color: var(--c1); }
.doc-footer .df-contact { font-size: 10.5px; color: var(--ink-soft); margin-top: 2px; }

/* SOUCHE (talon conservé) */
.stub-cut { position: relative; margin: 6px 0 0; border-top: 2px dashed #cfd6dd; }
.stub-cut::before {
    content: '\2702';
    position: absolute; top: -10px; left: 12px;
    background: var(--white); padding: 0 5px;
    font-size: 12px; color: #b7c0c9;
}
.stub { background: var(--bg); padding: 12px 16px 16px; }
.stub-title { font-size: 10px; font-weight: 800; letter-spacing: 1px; text-transform: uppercase; color: var(--ink-soft); margin-bottom: 8px; }
.stub-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px 12px; font-size: 11.5px; }
.stub-grid div span { color: var(--ink-soft); display: block; font-size: 9.5px; text-transform: uppercase; letter-spacing: .3px; }
.stub-grid div b { font-weight: 700; }

/* ---------------- CARNET / SOUCHES ---------------- */
.book-head { display: flex; align-items: flex-start; gap: 12px; justify-content: space-between; margin-bottom: 12px; }
.book-select { border: 1.5px solid var(--line); border-radius: 10px; padding: 8px 10px; font-size: 12.5px; background: var(--white); color: var(--ink); }

.book-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(38px, 1fr)); gap: 6px; }
.bg-cell {
    aspect-ratio: 1;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--white);
    color: #b7c0c9;
    font-size: 10.5px; font-weight: 700;
    display: flex; align-items: center; justify-content: center;
    cursor: default;
}
.bg-cell.is-used { background: var(--c1-soft); border-color: var(--c1); color: var(--c1); cursor: pointer; }

.souches-list { display: flex; flex-direction: column; gap: 9px; }
.souche {
    display: flex; align-items: center; gap: 11px;
    border: 1px solid var(--line);
    border-radius: var(--r-sm);
    padding: 11px 12px;
    background: var(--white);
}
.souche-num {
    width: 44px; flex-shrink: 0;
    text-align: center;
    font-size: 12px; font-weight: 800;
    color: var(--c1); background: var(--c1-soft);
    border-radius: 8px; padding: 6px 0;
}
.souche-mid { flex: 1; min-width: 0; }
.souche-mid b { font-size: 13.5px; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.souche-mid span { font-size: 11px; color: var(--ink-soft); }
.souche-total { font-size: 13px; font-weight: 800; white-space: nowrap; }
.souche-open { border: none; background: var(--bg); color: var(--ink); border-radius: 9px; padding: 8px 10px; cursor: pointer; font-size: 12px; }
.empty-note { font-size: 12.5px; color: var(--ink-soft); text-align: center; padding: 18px 4px; }

/* ---------------- RESPONSIVE ---------------- */
@media (min-width: 700px) {
    .hero-card h1 { font-size: 28px; }
    .tiles { grid-template-columns: repeat(4, 1fr); }
    .tiles-2 { grid-template-columns: repeat(2, 1fr); }
    .tiles-3 { grid-template-columns: repeat(3, 1fr); }
    .sheet { max-width: 620px; margin: 0 auto; }
}

@media (max-width: 400px) {
    .tiles { grid-template-columns: repeat(2, 1fr); }
    .dl-actions, .after-actions { flex-direction: column; gap: 0; }
}

@media print {
    .app-header, .steps-bar, .dl-actions, .after-actions, .promo-card, .btn, .toast { display: none !important; }
    .main { padding: 0; }
    .sheet { box-shadow: none; border: none; }
}