/* Magic - simulateur de pigments cuir (AWS44) - v1.0.0
   Interface volontairement NEUTRE (gris sans dominante) : un fond coloré fausserait la lecture des teintes. */
:root {
  --bg: #ececec;
  --card: #ffffff;
  --ink: #1f1f1f;
  --muted: #6b6b6b;
  --line: #d6d6d6;
  --accent: #2b2b2b;
  --accent-ink: #ffffff;
  --focus: #4d4d4d;
  --danger: #a12a1f;
  --ok: #2c6e3f;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,.08);
  color-scheme: light;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}
h1, h2 { margin: 0; line-height: 1.2; }
h2 { font-size: 1.05rem; margin-bottom: .4rem; }
p { margin: .4rem 0; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.center { text-align: center; }
.mono, .code { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* En-tête et onglets */
.top { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: .8rem 1rem; background: var(--accent); color: var(--accent-ink); }
.top__brand { display: flex; align-items: center; gap: .7rem; }
.top h1 { font-size: 1.3rem; letter-spacing: .02em; }
.top__sub { margin: 0; font-size: .82rem; opacity: .8; }
.top__logo { width: 34px; height: 34px; border-radius: 50%; background: conic-gradient(#c68b2c 0 25%, #6e2b1e 0 50%, #3b2214 0 75%, #f7f6f0 0); box-shadow: 0 0 0 2px rgba(255,255,255,.35); flex: none; }
.badge { font-size: .75rem; padding: .2rem .55rem; border-radius: 99px; }
.badge--off { background: #5a5a5a; color: #fff; }
.tabs { position: sticky; top: 0; z-index: 20; display: flex; gap: .25rem; overflow-x: auto; padding: .4rem .6rem; background: #f7f7f7; border-bottom: 1px solid var(--line); scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab { flex: none; border: 0; background: transparent; padding: .55rem .85rem; border-radius: 99px; font: inherit; font-size: .95rem; color: var(--ink); cursor: pointer; }
.tab:hover { background: #e4e4e4; }
.tab.is-active { background: var(--accent); color: var(--accent-ink); }

main { max-width: 1180px; margin: 0 auto; padding: 1rem; }
.panel[hidden] { display: none; }
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1rem; margin-bottom: 1rem; }
.card--danger { border: 1px solid #e7c4c0; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(290px, 1fr)); gap: 0 1rem; }
.row { display: flex; flex-wrap: wrap; align-items: flex-end; gap: .6rem; margin: .5rem 0; }
.row--between { justify-content: space-between; align-items: flex-start; }
.row--end { justify-content: flex-end; }

/* Champs */
.field { display: flex; flex-direction: column; gap: .25rem; min-width: 0; font-size: .85rem; color: var(--muted); }
.field > span:first-child { font-weight: 500; }
.field--grow { flex: 1 1 260px; }
.field--small { width: 7.5rem; }
.field--inline { margin: 0; }
input[type=text], input[type=search], input[type=number], select, textarea {
  font: inherit; font-size: 1rem; color: var(--ink); background: #fff; border: 1px solid #bdbdbd; border-radius: 8px; padding: .5rem .6rem; min-height: 2.6rem; width: 100%;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }
input.is-bad { border-color: var(--danger); background: #fff6f5; }
input[type=range] { width: 100%; accent-color: var(--accent); min-height: 2rem; }
input[type=color] { width: 3rem; height: 2.6rem; padding: 2px; border: 1px solid #bdbdbd; border-radius: 8px; background: #fff; flex: none; }
.colorpair { display: flex; gap: .4rem; align-items: center; }
.colorpair input[type=text] { width: 7.5rem; }

/* Boutons */
.btn { font: inherit; font-size: .95rem; border: 1px solid #b5b5b5; background: #f4f4f4; color: var(--ink); border-radius: 8px; padding: .55rem .9rem; min-height: 2.6rem; cursor: pointer; }
.btn:hover { background: #e9e9e9; }
.btn--primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn--primary:hover { background: #444; }
.btn--ghost { background: transparent; }
.btn--danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn--small { font-size: .82rem; padding: .3rem .6rem; min-height: 2rem; }
.btn--big { font-size: 1.05rem; padding: .7rem 1.2rem; }
.btn--icon { min-width: 2.6rem; padding: .3rem; }
.chips { display: flex; flex-wrap: wrap; gap: .4rem; }
.chip { font: inherit; font-size: .85rem; border: 1px solid #c5c5c5; background: #fff; border-radius: 99px; padding: .3rem .75rem; cursor: pointer; }
.chip:hover { background: #f0f0f0; }

/* Mélange : aperçu à droite (ordinateur), en haut et collant (téléphone) */
.mix { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 1rem; align-items: start; }
.mix__preview { grid-column: 2; grid-row: 1; position: sticky; top: 3.6rem; }
.mix__form { grid-column: 1; grid-row: 1; min-width: 0; }
.swatches { display: grid; grid-template-columns: 1fr 1fr; gap: .8rem; }
.swatch { margin: 0; }
.swatch__chip { height: 150px; border-radius: 10px; border: 1px solid rgba(0,0,0,.12); background: #fff; transition: background-color .15s; }
.swatch__chip--mid { height: 110px; }
.swatch figcaption { margin-top: .4rem; font-size: .88rem; display: flex; flex-direction: column; gap: .05rem; }
.code { font-size: .85rem; }
.tone { margin: .7rem 0 .2rem; font-weight: 500; }
.before { display: flex; align-items: center; gap: .5rem; font-size: .85rem; margin-top: .5rem; padding-top: .5rem; border-top: 1px dashed var(--line); }
.before[hidden] { display: none; }
.before__chip { width: 34px; height: 34px; border-radius: 6px; border: 1px solid rgba(0,0,0,.12); flex: none; }
.preview__actions { margin-top: .5rem; }

.table-wrap { overflow-x: auto; margin: .3rem 0; }
.ing { width: 100%; border-collapse: collapse; }
.ing th, .ing td { padding: .35rem .3rem; border-bottom: 1px solid #ececec; text-align: left; vertical-align: middle; }
.ing thead th { font-size: .78rem; color: var(--muted); font-weight: 600; }
.ing tfoot th { border-bottom: 0; font-size: .95rem; }
.ing .num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.ing td.num { font-size: .9rem; }
.ing input[type=text] { text-align: right; width: 6.5rem; }
.pig { display: flex; align-items: center; gap: .45rem; min-width: 10rem; }
.pig__dot { width: 22px; height: 22px; border-radius: 50%; border: 1px solid rgba(0,0,0,.18); flex: none; }
.ing .del { border: 0; background: transparent; font-size: 1.1rem; color: var(--muted); cursor: pointer; min-width: 2.4rem; min-height: 2.4rem; border-radius: 8px; }
.ing .del:hover { background: #f3e3e1; color: var(--danger); }
.bar { height: 4px; background: #ececec; border-radius: 2px; margin-top: 3px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: #9a9a9a; }

/* Recettes */
.recipes { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: .8rem; margin-top: .6rem; }
.rcp { border: 1px solid var(--line); border-radius: 10px; padding: .8rem; display: flex; flex-direction: column; gap: .4rem; }
.rcp__head { display: flex; gap: .7rem; align-items: center; }
.rcp__chip { width: 54px; height: 54px; border-radius: 8px; border: 1px solid rgba(0,0,0,.12); flex: none; }
.rcp__title { font-weight: 600; word-break: break-word; }
.rcp__ing { font-size: .85rem; color: var(--muted); }
.rcp__notes { font-size: .85rem; white-space: pre-wrap; word-break: break-word; background: #f6f6f6; border-radius: 6px; padding: .4rem .5rem; }
.rcp__warn { font-size: .8rem; color: #8a5a00; }
.rcp .row { margin: .2rem 0 0; }
.empty { color: var(--muted); padding: 1rem 0; }

/* Nuancier */
.pigments { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: .8rem; margin-top: .6rem; }
.pgm { border: 1px solid var(--line); border-radius: 10px; padding: .8rem; display: flex; flex-direction: column; gap: .5rem; }
.pgm__head { display: flex; gap: .6rem; align-items: center; }
.pgm__chip { width: 46px; height: 46px; border-radius: 50%; border: 1px solid rgba(0,0,0,.15); flex: none; }
.pgm__used { font-size: .78rem; }
.slider { display: grid; grid-template-columns: 1fr 5rem; gap: .5rem; align-items: center; }
.slider input[type=text] { text-align: right; }

.calib { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 1rem; }
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; }
.pair figure { margin: 0; font-size: .85rem; }
.pair figcaption { margin-top: .3rem; }
.delta { font-weight: 600; margin-top: .6rem; }
.delta--ok { color: var(--ok); }
.delta--mid { color: #8a5a00; }
.delta--bad { color: var(--danger); }

/* Fenêtre */
.dlg { border: 0; border-radius: var(--radius); padding: 1.1rem; width: min(560px, calc(100vw - 2rem)); box-shadow: 0 10px 40px rgba(0,0,0,.25); }
.dlg::backdrop { background: rgba(0,0,0,.35); }
.dlg .field { margin-bottom: .6rem; }

.toast { position: fixed; left: 50%; bottom: 1.2rem; transform: translateX(-50%); background: #222; color: #fff; padding: .6rem 1rem; border-radius: 8px; z-index: 50; max-width: calc(100vw - 2rem); box-shadow: 0 4px 14px rgba(0,0,0,.25); font-size: .95rem; }
.toast--err { background: var(--danger); }
.toast[hidden], .banner[hidden] { display: none; }
.banner { background: #fff4d6; border-bottom: 1px solid #ecd9a4; padding: .5rem 1rem; text-align: center; font-size: .9rem; }

.prose li { margin: .3rem 0; }
.foot { text-align: center; padding: 1rem 1rem 1.5rem; }

@media (max-width: 860px) {
  main { padding: .6rem; }
  .mix { grid-template-columns: 1fr; }
  .mix__preview { grid-column: 1; grid-row: 1; top: 3.1rem; z-index: 10; padding: .6rem; }
  .mix__form { grid-row: 2; }
  .swatch__chip { height: 74px; }
  .swatch figcaption { font-size: .8rem; }
  .swatch figcaption .code.muted { display: none; }
  .tone { font-size: .88rem; margin-top: .4rem; }
  .preview__actions { display: none; }
  .calib { grid-template-columns: 1fr; }
  .ing input[type=text] { width: 5.2rem; }
  .pig { min-width: 8.5rem; }
  .ing th:nth-child(4), .ing td:nth-child(4) { display: none; }
}
@media (max-width: 420px) {
  .top__sub { display: none; }
  .field--small { width: 6rem; }
}
@media print {
  .tabs, .top, .foot, .row, .chips, .before, .preview__actions, #toast, #update, .card:not(#preview) .muted.small { display: none !important; }
  body { background: #fff; }
  .card { box-shadow: none; border: 1px solid #ccc; break-inside: avoid; }
  .mix { grid-template-columns: 1fr; }
  .mix__preview { position: static; }
}
