:root {
  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface-2: #eef1f7;
  --text: #1d2433;
  --muted: #5b6475;
  --border: #d9dee8;
  --primary: #1b3a6b;
  --primary-2: #2a5298;
  --on-primary: #ffffff;
  --accent: #f28c28;
  --accent-dark: #d8741a;
  --ok: #1f8a4c;
  --ok-bg: #e5f5ec;
  --warn: #9a5b00;
  --warn-bg: #fff3dc;
  --danger: #c62828;
  --danger-bg: #fdecec;
  --info-bg: #e8effb;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(20, 30, 50, .06), 0 4px 16px rgba(20, 30, 50, .06);
  --nav-h: 68px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #10141c;
    --surface: #181e29;
    --surface-2: #212938;
    --text: #e7ebf3;
    --muted: #9aa4b8;
    --border: #2e374a;
    --primary: #5b8def;
    --primary-2: #7aa3f5;
    --on-primary: #0c1322;
    --ok: #4cc27f;
    --ok-bg: #16301f;
    --warn: #f2b35a;
    --warn-bg: #33270f;
    --danger: #f06b6b;
    --danger-bg: #3a1a1a;
    --info-bg: #1b2740;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--primary); }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5rem; }
h1 { font-size: 1.45rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 .75rem; }
.muted { color: var(--muted); }
.small { font-size: .86rem; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.hidden { display: none !important; }

/* ---------- mise en page ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: .5rem;
  padding: calc(env(safe-area-inset-top) + .6rem) 1rem .6rem;
  background: var(--primary); color: var(--on-primary);
}
.topbar h1 { font-size: 1.1rem; margin: 0; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar .icon-btn { color: var(--on-primary); }
main.page {
  max-width: 860px; margin: 0 auto;
  padding: 1rem 1rem calc(var(--nav-h) + env(safe-area-inset-bottom) + 1.5rem);
}
.bottomnav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(5, 1fr); align-items: end;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface); border-top: 1px solid var(--border);
}
.bottomnav a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  height: var(--nav-h); color: var(--muted); text-decoration: none; font-size: .72rem; font-weight: 600;
}
.bottomnav a.active { color: var(--primary); }
.bottomnav a svg { width: 24px; height: 24px; }
.bottomnav .mic-tab { position: relative; }
.bottomnav .mic-tab span.fab {
  width: 60px; height: 60px; margin-top: -26px; border-radius: 50%;
  display: grid; place-items: center; background: var(--accent); color: #fff;
  box-shadow: 0 6px 18px rgba(242, 140, 40, .45);
}
.bottomnav .mic-tab span.fab svg { width: 28px; height: 28px; }

@media (min-width: 900px) {
  main.page { padding-bottom: 3rem; }
  .bottomnav { position: sticky; top: 0; height: auto; grid-template-columns: repeat(5, auto); justify-content: center; gap: 1.5rem; padding: 0; border: 0; border-bottom: 1px solid var(--border); }
  .bottomnav a { flex-direction: row; height: 52px; font-size: .9rem; gap: .4rem; }
  .bottomnav .mic-tab span.fab { width: 36px; height: 36px; margin: 0; box-shadow: none; }
  .bottomnav .mic-tab span.fab svg { width: 20px; height: 20px; }
}

/* ---------- composants ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1rem; margin-bottom: 1rem; box-shadow: var(--shadow);
}
.card > h2:first-child, .card > h3:first-child { margin-top: 0; }
.row { display: flex; gap: .75rem; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: .75rem; }
@media (max-width: 520px) { .grid2.stack-sm { grid-template-columns: 1fr; } }
.stack > * + * { margin-top: .75rem; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  min-height: 48px; padding: .7rem 1.1rem; border-radius: 12px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 650; text-decoration: none; cursor: pointer;
  transition: transform .06s ease, background .15s ease;
}
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn svg { width: 20px; height: 20px; flex: none; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.btn.accent { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.block { width: 100%; }
.btn.big { min-height: 64px; font-size: 1.1rem; border-radius: 16px; }
.btn.sm { min-height: 38px; padding: .4rem .75rem; font-size: .9rem; }
.icon-btn {
  display: inline-grid; place-items: center; width: 44px; height: 44px; border-radius: 12px;
  border: 0; background: transparent; color: var(--text); cursor: pointer;
}
.icon-btn svg { width: 22px; height: 22px; }
.icon-btn:hover { background: rgba(127, 127, 127, .12); }

label.field { display: block; }
label.field > span { display: block; font-size: .85rem; font-weight: 650; color: var(--muted); margin-bottom: .25rem; }
input, select, textarea {
  width: 100%; min-height: 48px; padding: .65rem .8rem;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface); color: var(--text); font: inherit; font-size: 16px;
}
textarea { min-height: 90px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary-2); outline-offset: 0; border-color: transparent; }
input[type=checkbox] { width: auto; min-height: 0; }
.input-suffix { position: relative; }
.input-suffix input { padding-right: 2.2rem; }
.input-suffix em { position: absolute; right: .75rem; top: 50%; transform: translateY(-50%); font-style: normal; color: var(--muted); pointer-events: none; }

.segmented { display: flex; background: var(--surface-2); border-radius: 12px; padding: 4px; gap: 4px; }
.segmented button { flex: 1; min-height: 40px; border: 0; border-radius: 9px; background: transparent; color: var(--muted); font: inherit; font-weight: 650; cursor: pointer; }
.segmented button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

.badge { display: inline-block; padding: .15rem .55rem; border-radius: 999px; font-size: .75rem; font-weight: 700; white-space: nowrap; }
.badge.brouillon { background: var(--surface-2); color: var(--muted); }
.badge.a_verifier { background: var(--warn-bg); color: var(--warn); }
.badge.valide { background: var(--ok-bg); color: var(--ok); }
.badge.envoye { background: var(--info-bg); color: var(--primary); }

.alert { border-radius: 12px; padding: .8rem 1rem; margin-bottom: 1rem; }
.alert.warn { background: var(--warn-bg); color: var(--warn); }
.alert.danger { background: var(--danger-bg); color: var(--danger); }
.alert.info { background: var(--info-bg); color: var(--text); }
.alert.ok { background: var(--ok-bg); color: var(--ok); }
.alert ul { margin: .35rem 0 0; padding-left: 1.2rem; }
.alert h3 { color: inherit; }

.list { list-style: none; margin: 0; padding: 0; }
.list li + li { border-top: 1px solid var(--border); }
.list a.item, .list .item {
  display: flex; align-items: center; gap: .75rem; padding: .85rem .25rem; color: var(--text); text-decoration: none;
}
.list .item .title { font-weight: 650; }
.list .item .sub { color: var(--muted); font-size: .86rem; }
.empty { text-align: center; color: var(--muted); padding: 2rem 1rem; }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: .6rem; margin-bottom: 1rem; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .8rem; text-align: center; text-decoration: none; color: var(--text); }
.stat b { display: block; font-size: 1.6rem; line-height: 1.1; }
.stat span { font-size: .78rem; color: var(--muted); font-weight: 600; }

.search { position: relative; margin-bottom: .75rem; }
.search input { padding-left: 2.5rem; }
.search svg { position: absolute; left: .8rem; top: 50%; transform: translateY(-50%); width: 18px; height: 18px; color: var(--muted); }
.chips { display: flex; gap: .4rem; overflow-x: auto; padding-bottom: .5rem; margin-bottom: .5rem; }
.chip { flex: none; padding: .45rem .85rem; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit; font-size: .88rem; font-weight: 600; cursor: pointer; }
.chip.on { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }

/* ---------- auth ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 1.5rem 1rem; }
.auth .card { width: 100%; max-width: 420px; }
.auth .brand { text-align: center; margin-bottom: 1.25rem; }
.auth .brand img { width: 72px; height: 72px; }
.auth .brand p { color: var(--muted); }

/* ---------- dictée ---------- */
.recorder { text-align: center; padding: 1.5rem 1rem; }
.mic-big {
  width: 132px; height: 132px; border-radius: 50%; border: 0; cursor: pointer;
  display: inline-grid; place-items: center; background: var(--accent); color: #fff;
  box-shadow: 0 10px 30px rgba(242, 140, 40, .45); transition: transform .1s ease;
}
.mic-big svg { width: 56px; height: 56px; }
.mic-big:active { transform: scale(.96); }
.mic-big.rec { background: var(--danger); animation: pulse 1.4s infinite; box-shadow: 0 0 0 0 rgba(198, 40, 40, .5); }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(198, 40, 40, .45); } 70% { box-shadow: 0 0 0 26px rgba(198, 40, 40, 0); } 100% { box-shadow: 0 0 0 0 rgba(198, 40, 40, 0); } }
.timer { font-variant-numeric: tabular-nums; font-size: 1.4rem; font-weight: 700; margin-top: 1rem; }
.example { background: var(--surface-2); border-radius: 12px; padding: .8rem 1rem; font-style: italic; color: var(--muted); text-align: left; }

/* ---------- éditeur de devis ---------- */
.line {
  border: 1px solid var(--border); border-radius: 12px; padding: .75rem; margin-bottom: .75rem; background: var(--surface);
}
.line.review { border-color: var(--warn); background: var(--warn-bg); }
.line .review-msg { display: flex; gap: .5rem; align-items: flex-start; color: var(--warn); font-size: .88rem; font-weight: 600; margin-bottom: .6rem; }
.line textarea { min-height: 52px; }
.line .line-grid { display: grid; grid-template-columns: 1fr 1.1fr 1.3fr 1fr; gap: .5rem; margin-top: .5rem; }
@media (max-width: 520px) { .line .line-grid { grid-template-columns: 1fr 1fr; } }
.line .line-grid label.field > span { font-size: .75rem; }
.line .line-foot { display: flex; align-items: center; justify-content: space-between; margin-top: .5rem; }
.line .src { font-size: .75rem; color: var(--muted); }
.line .total { font-weight: 750; }
.totals-bar {
  position: sticky; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom)); z-index: 10;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: .75rem 1rem; box-shadow: 0 -4px 20px rgba(20, 30, 50, .08); margin-bottom: 1rem;
}
@media (min-width: 900px) { .totals-bar { bottom: 1rem; } }
.totals-bar .ttc { font-size: 1.3rem; font-weight: 800; }
.totals-table { width: 100%; border-collapse: collapse; }
.totals-table td { padding: .3rem 0; }
.totals-table tr.grand td { font-weight: 800; font-size: 1.1rem; border-top: 1px solid var(--border); padding-top: .5rem; }
.save-state { font-size: .78rem; color: var(--muted); }
details.transcript summary { cursor: pointer; font-weight: 650; }
details.transcript p { white-space: pre-wrap; margin-top: .5rem; }

.client-pick { display: flex; gap: .5rem; align-items: center; }
.client-card { background: var(--surface-2); border-radius: 12px; padding: .75rem; }

/* ---------- modales et toast ---------- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 100; background: rgba(10, 15, 25, .55);
  display: flex; align-items: flex-end; justify-content: center;
}
@media (min-width: 640px) { .modal-backdrop { align-items: center; } }
.modal {
  width: 100%; max-width: 560px; max-height: 92vh; overflow: auto;
  background: var(--surface); border-radius: 18px 18px 0 0; padding: 1rem 1rem calc(1rem + env(safe-area-inset-bottom));
}
@media (min-width: 640px) { .modal { border-radius: 18px; } }
.modal header { display: flex; align-items: center; justify-content: space-between; margin-bottom: .75rem; }
.modal header h2 { margin: 0; }
#toast {
  position: fixed; left: 50%; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 16px); z-index: 200;
  transform: translateX(-50%) translateY(20px); opacity: 0; pointer-events: none;
  background: #1d2433; color: #fff; padding: .7rem 1.1rem; border-radius: 12px; font-weight: 600;
  transition: all .2s ease; max-width: calc(100% - 32px);
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.error { background: var(--danger); }

.boot { min-height: 100vh; display: grid; place-items: center; }
.spinner { width: 36px; height: 36px; border-radius: 50%; border: 4px solid var(--border); border-top-color: var(--primary); animation: spin .8s linear infinite; }
.spinner.sm { width: 18px; height: 18px; border-width: 3px; }
@keyframes spin { to { transform: rotate(360deg); } }
.processing { text-align: center; padding: 2.5rem 1rem; }
.processing .spinner { margin: 0 auto 1rem; }

.logo-preview { max-height: 80px; max-width: 220px; background: #fff; border-radius: 8px; padding: 6px; border: 1px solid var(--border); }

/* ---------- correctifs petits écrans ---------- */
.grid2 > *, .grid3 > * { min-width: 0; }
.quick .btn { flex-direction: column; gap: .2rem; padding: .6rem .3rem; font-size: .85rem; }
.discount-grid { grid-template-columns: 1.5fr 1fr; }
