/* ==========================================================================
   Habillage de l'application
   ========================================================================== */

:root {
  --brand: #b45309;
  --brand-dark: #92400e;
  --brand-soft: #fff4e5;
  --ink: #101828;
  --ink-soft: #475467;
  --ink-mute: #667085;
  --line: #e4e7ec;
  --bg: #f4f5f7;
  --card: #ffffff;
  --ok: #067647;
  --ok-soft: #ecfdf3;
  --warn: #b54708;
  --warn-soft: #fffaeb;
  --danger: #b42318;
  --danger-soft: #fef3f2;
  --radius: 18px;
  --radius-sm: 12px;
  --shadow: 0 4px 16px rgba(16, 24, 40, .06);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, .10);
  --tabbar-h: 64px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.55;
  -webkit-text-size-adjust: 100%;
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px));
}

img { max-width: 100%; display: block; }

a { color: var(--brand-dark); }

h1, h2, h3, h4 { line-height: 1.25; margin: 0 0 10px; }
h1 { font-size: 1.65rem; }
h2 { font-size: 1.28rem; }
h3 { font-size: 1.06rem; }
p { margin: 0 0 12px; }

.shell {
  width: 100%;
  max-width: 1120px;
  margin: 0 auto;
  padding: 0 16px;
}

.main { padding-top: 18px; padding-bottom: 28px; }

.muted { color: var(--ink-mute); }
.small { font-size: .84rem; }
.lead { color: var(--ink-soft); font-size: 1.02rem; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.mono { font-family: var(--mono); font-size: .92em; }

/* --------------------------------------------------------------- en-tete */

.topbar {
  position: sticky;
  top: 0;
  z-index: 60;
  background: rgba(255, 255, 255, .86);
  -webkit-backdrop-filter: saturate(160%) blur(16px);
  backdrop-filter: saturate(160%) blur(16px);
  border-bottom: 1px solid var(--line);
  padding-top: env(safe-area-inset-top, 0px);
}

.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 58px;
  padding-top: 6px;
  padding-bottom: 6px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--ink);
  min-width: 0;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  flex: 0 0 38px;
  border-radius: 12px;
  background: var(--brand);
  color: #fff;
}

.brand-text { display: flex; flex-direction: column; min-width: 0; overflow: hidden; }
.brand-text strong { font-size: .98rem; line-height: 1.2; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.brand-text small { color: var(--ink-mute); font-size: .74rem; line-height: 1.2; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.topbar-actions { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }

/* --------------------------------------------------------------- boutons */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 12px 18px;
  font-size: .95rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  text-decoration: none;
  transition: transform .12s ease, background .16s ease, border-color .16s ease, color .16s ease;
  background: var(--card);
  color: var(--ink);
}

.btn:active { transform: scale(.97); }

.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); }

.btn-outline { border-color: var(--line); background: var(--card); color: var(--ink); }
.btn-outline:hover { border-color: var(--brand); color: var(--brand-dark); }

.btn-ghost { background: transparent; color: var(--ink-soft); }
.btn-ghost:hover { background: rgba(16, 24, 40, .06); color: var(--ink); }

.btn-danger { background: var(--danger-soft); color: var(--danger); }
.btn-danger:hover { background: #fee4e2; }

.btn-sm { padding: 8px 12px; font-size: .86rem; border-radius: 10px; }
.btn-lg { padding: 16px 26px; font-size: 1.05rem; border-radius: 14px; }
.btn-block { width: 100%; }
.btn[disabled] { opacity: .55; pointer-events: none; }

/* ---------------------------------------------------------------- cartes */

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  margin-bottom: 16px;
}

.card-narrow { max-width: 520px; margin-left: auto; margin-right: auto; }

.card-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.section-head { margin: 26px 0 12px; }
.section-head h2 { margin-bottom: 4px; }
.section-head p { margin: 0; color: var(--ink-mute); font-size: .93rem; }

/* ------------------------------------------------------------------ hero */

.hero {
  position: relative;
  background: linear-gradient(140deg, #1f2937 0%, #0f172a 55%, #2b1a0d 100%);
  color: #fff;
  padding: 34px 0 30px;
}

.hero::after {
  content: "";
  position: absolute;
  inset: 0;
  background-image: url("https://images.unsplash.com/photo-1615751072497-5f5169febe17?w=1200");
  background-size: cover;
  background-position: center;
  opacity: .18;
  pointer-events: none;
}

.hero-inner { position: relative; z-index: 1; }
.hero h1 { font-size: 2rem; letter-spacing: -.5px; }
.hero .lead { color: rgba(255, 255, 255, .82); max-width: 620px; }
.hero-tag {
  display: inline-block;
  font-size: .76rem;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: #fbd38d;
  border: 1px solid rgba(251, 211, 141, .5);
  border-radius: 999px;
  padding: 4px 12px;
  margin-bottom: 14px;
}
.hero-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 18px; }
.hero-actions .btn-outline { background: rgba(255, 255, 255, .12); border-color: rgba(255, 255, 255, .35); color: #fff; }
.hero-actions .btn-outline:hover { background: rgba(255, 255, 255, .2); color: #fff; }

/* ------------------------------------------------------------- statistiques */

.stat-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  margin-top: 16px;
}

.stat {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
}

.stat-big { font-size: 1.7rem; font-weight: 700; line-height: 1.1; }
.stat small { color: var(--ink-mute); display: block; }

/* ------------------------------------------------------------- listes */

.grid-2, .grid-3, .grid-4, .grid-auto {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
}

.stack { display: grid; gap: 12px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: 999px;
  padding: 3px 10px;
  font-size: .78rem;
  font-weight: 600;
  background: #f2f4f7;
  color: var(--ink-soft);
}
.pill-ok { background: var(--ok-soft); color: var(--ok); }
.pill-warn { background: var(--warn-soft); color: var(--warn); }
.pill-danger { background: var(--danger-soft); color: var(--danger); }
.pill-brand { background: var(--brand-soft); color: var(--brand-dark); }

/* ------------------------------------------------------ carte imprimante */

.machine {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.machine-thumb { aspect-ratio: 16 / 10; width: 100%; object-fit: cover; background: #e9edf2; }
.machine-body { padding: 14px 16px 16px; display: flex; flex-direction: column; gap: 8px; flex: 1; }
.machine-body h3 { margin: 0; font-size: 1.02rem; }
.machine-specs { display: flex; flex-wrap: wrap; gap: 6px; font-size: .78rem; }
.machine-specs span { background: #f2f4f7; border-radius: 8px; padding: 3px 8px; color: var(--ink-soft); }

/* ------------------------------------------------------------- choix wizard */

.choice-grid { display: grid; grid-template-columns: 1fr; gap: 12px; }

.choice {
  display: block;
  position: relative;
  background: var(--card);
  border: 2px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  cursor: pointer;
  transition: transform .12s ease, border-color .16s ease, box-shadow .16s ease;
}

.choice:active { transform: scale(.98); }
.choice input { position: absolute; opacity: 0; pointer-events: none; }
.choice h3 { margin: 0 0 4px; font-size: 1rem; }
.choice p { margin: 0; color: var(--ink-mute); font-size: .88rem; }
.choice .choice-top { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.choice .choice-price { font-weight: 700; color: var(--brand-dark); font-size: .9rem; white-space: nowrap; }
.choice:has(input:checked) { border-color: var(--brand); box-shadow: 0 0 0 4px var(--brand-soft); }
.choice.is-selected { border-color: var(--brand); box-shadow: 0 0 0 4px var(--brand-soft); }
.choice-media { width: 100%; aspect-ratio: 16/9; object-fit: cover; border-radius: 12px; margin-bottom: 10px; background: #e9edf2; }
.choice-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }

.nozzle-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }

/* -------------------------------------------------------------- formulaires */

.form { display: grid; gap: 14px; }

.field { display: grid; gap: 6px; }
.field > span { font-size: .88rem; font-weight: 600; color: var(--ink-soft); }
.field .hint { font-size: .8rem; color: var(--ink-mute); font-weight: 400; }

input[type="text"], input[type="email"], input[type="password"], input[type="number"],
input[type="search"], select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 1rem;
  font-family: inherit;
  color: var(--ink);
  background: #fff;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-soft);
}

textarea { min-height: 110px; resize: vertical; }

.check {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: .92rem;
  color: var(--ink-soft);
}
.check input { width: 20px; height: 20px; margin-top: 2px; flex: 0 0 20px; accent-color: var(--brand); }

/* ---------------------------------------------------------------- alertes */

.alert {
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: .92rem;
  margin-bottom: 14px;
  border: 1px solid transparent;
}
.alert-error { background: var(--danger-soft); color: var(--danger); border-color: #fecdca; }
.alert-ok { background: var(--ok-soft); color: var(--ok); border-color: #abefc6; }
.alert-warn { background: var(--warn-soft); color: var(--warn); border-color: #fedf89; }
.alert-info { background: #eff8ff; color: #175cd3; border-color: #b2ddff; }

/* ------------------------------------------------------------- resultats */

.setgroup {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 14px;
  overflow: hidden;
}
.setgroup > summary,
.setgroup-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 14px 16px;
  cursor: pointer;
  font-weight: 700;
  list-style: none;
}
.setgroup > summary::-webkit-details-marker { display: none; }
.setgroup-head { cursor: default; }
.setgroup-intro { padding: 0 16px 8px; margin: 0; color: var(--ink-mute); font-size: .88rem; }
.setgroup-count { font-size: .78rem; color: var(--ink-mute); font-weight: 600; background: #f2f4f7; border-radius: 999px; padding: 2px 10px; }

.setrow {
  display: grid;
  grid-template-columns: 1fr;
  gap: 4px;
  padding: 12px 16px;
  border-top: 1px solid var(--line);
}
.setrow-name { font-size: .92rem; font-weight: 600; }
.setrow-name label { cursor: pointer; }
.setrow-key { font-family: var(--mono); font-size: .74rem; color: var(--ink-mute); word-break: break-all; }
.setrow-value {
  font-family: var(--mono);
  font-size: .98rem;
  font-weight: 700;
  color: var(--brand-dark);
  word-break: break-word;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.setrow-why { font-size: .84rem; color: var(--ink-mute); }

.setrow-input {
  width: 100%;
  max-width: 150px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
  font-family: var(--mono);
  font-size: .95rem;
  font-weight: 600;
  color: var(--brand-dark);
  background: #fff;
  text-align: right;
}
.setrow-input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.setrow-unit { font-size: .8rem; color: var(--ink-mute); font-weight: 600; }

.set-save {
  display: grid;
  gap: 10px;
  border-color: var(--brand);
  box-shadow: 0 6px 20px rgba(180, 83, 9, .12);
}
.set-save h3 { margin: 0; }
.set-save p { margin: 0; }

/* ---------------------------------------------------------------- wizard */

.steps { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.step {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: .8rem;
  color: var(--ink-mute);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 12px;
}
.step b { display: grid; place-items: center; width: 20px; height: 20px; border-radius: 999px; background: #f2f4f7; font-size: .72rem; }
.step.is-active { border-color: var(--brand); color: var(--brand-dark); font-weight: 700; }
.step.is-active b { background: var(--brand); color: #fff; }
.step.is-done b { background: var(--ok); color: #fff; }

.wizard-panel { display: block; }
.wizard-panel.is-hidden { display: none; }

.wizard-footer { display: flex; gap: 10px; justify-content: space-between; margin-top: 16px; flex-wrap: wrap; }
.wizard-footer .btn { flex: 1 1 auto; }

/* ----------------------------------------------------------------- barre bas */

.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 70;
  display: flex;
  align-items: stretch;
  justify-content: space-around;
  gap: 2px;
  min-height: var(--tabbar-h);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom, 0px));
  background: rgba(255, 255, 255, .82);
  -webkit-backdrop-filter: saturate(180%) blur(18px);
  backdrop-filter: saturate(180%) blur(18px);
  border-top: 1px solid rgba(16, 24, 40, .08);
}

.tab {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 6px 2px;
  border-radius: 14px;
  text-decoration: none;
  color: var(--ink-mute);
  font-size: .68rem;
  font-weight: 600;
  transition: transform .12s ease, background .16s ease, color .16s ease;
}

.tab:active { transform: scale(.94); }
.tab span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tab.is-active { color: var(--brand-dark); background: var(--brand-soft); }

/* ------------------------------------------------------------------ divers */

.recap-grid { display: grid; grid-template-columns: 1fr; gap: 12px; }
.recap-box { background: #fbfbfc; border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 14px; }
.recap-box strong { display: block; font-size: .82rem; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-mute); margin-bottom: 4px; }

.gauge { display: flex; gap: 4px; align-items: center; }
.gauge i { width: 16px; height: 8px; border-radius: 4px; background: #e4e7ec; display: block; }
.gauge i.on { background: var(--brand); }

.empty { text-align: center; padding: 34px 16px; color: var(--ink-mute); }

.trust { display: grid; grid-template-columns: 1fr; gap: 12px; }
.trust-item { display: flex; gap: 12px; align-items: flex-start; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.trust-ico { flex: 0 0 34px; width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; background: var(--brand-soft); color: var(--brand-dark); }

.help-list { display: grid; gap: 10px; }
details.help-item { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 12px 14px; }
details.help-item summary { cursor: pointer; font-weight: 600; }
details.help-item p { margin: 10px 0 0; color: var(--ink-soft); font-size: .93rem; }

/* ------------------------------------------------------------------ modal */

.modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(16, 24, 40, .5);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
}
.modal-box { background: #fff; border-radius: var(--radius); padding: 20px; max-width: 420px; width: 100%; box-shadow: var(--shadow-lg); max-height: 90vh; overflow: auto; }
.modal-actions { display: flex; gap: 10px; margin-top: 14px; }
.modal-actions .btn { flex: 1; }
.store-badges { display: flex; gap: 10px; margin-top: 14px; flex-wrap: wrap; }
.store-badge { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); border-radius: 10px; padding: 6px 10px; font-size: .8rem; color: var(--ink-soft); }

/* ------------------------------------------------------------------ splash */

#app-splash {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 99999;
  pointer-events: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: #0f172a;
  color: #fff;
  font-weight: 700;
  letter-spacing: .04em;
}
#app-splash.show { display: flex; animation: splashOut .4s ease 1.2s forwards; }
#app-splash img { border-radius: 22px; }
@keyframes splashOut { to { opacity: 0; visibility: hidden; } }

/* ------------------------------------------------------------------ pied */

.site-foot {
  border-top: 1px solid var(--line);
  background: #fff;
  padding: 22px 0 26px;
  margin-top: 26px;
}
.foot-links { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 10px; }
.foot-links a { font-size: .88rem; color: var(--ink-soft); text-decoration: none; }
.foot-links a:hover { color: var(--brand-dark); }

/* ------------------------------------------------------------------ tables */

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.data { width: 100%; border-collapse: collapse; font-size: .9rem; }
table.data th, table.data td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.data th { font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-mute); }
table.data tr:last-child td { border-bottom: none; }

/* ------------------------------------------------------------------ toast */

.toast {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px) + 14px);
  z-index: 300;
  background: #101828;
  color: #fff;
  border-radius: 999px;
  padding: 10px 18px;
  font-size: .9rem;
  box-shadow: var(--shadow-lg);
  max-width: calc(100% - 32px);
  text-align: center;
}

.spinner {
  width: 18px; height: 18px; border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, .45);
  border-top-color: #fff;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ================================================================== desktop */

@media (min-width: 640px) {
  .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-auto { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .choice-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .nozzle-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .setrow { grid-template-columns: 1.4fr .8fr; align-items: baseline; gap: 12px; }
  .setrow-why { grid-column: 1 / -1; }
  .recap-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (min-width: 900px) {
  .stat-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .grid-auto { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .choice-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .trust { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .tabbar { display: none; }
  body { padding-bottom: 0; }
  .hero h1 { font-size: 2.5rem; }
  .hero { padding: 52px 0 46px; }
  .grid-master { display: grid; grid-template-columns: 260px 1fr; gap: 18px; align-items: start; }
}
