:root {
  --bg: #f6f4ef;
  --paper: #fffdf9;
  --ink: #141414;
  --muted: #77726a;
  --line: #e2ddd3;
  --soft: #eeebe4;
  --accent: #8a6a3e;
  --danger: #a3332b;
  --serif: "Didot", "Bodoni 72", "Bodoni MT", "Playfair Display", "Libre Bodoni", Georgia, serif;
  --sans: "Helvetica Neue", Helvetica, "Inter", system-ui, -apple-system, "Segoe UI", Arial, sans-serif;
  --radius: 4px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.5 var(--sans); min-height: 100vh; }
img { max-width: 100%; }
a { color: inherit; }
h1, h2, h3 { margin: 0; font-weight: 400; }
h1 { font-family: var(--serif); font-size: clamp(34px, 5vw, 52px); line-height: 1.05; letter-spacing: -.01em; }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .14em; font-weight: 600; margin-bottom: 14px; }
input, select, textarea, button { font: inherit; color: inherit; }
[hidden] { display: none !important; }

.eyebrow { margin: 0 0 6px; font-size: 11px; letter-spacing: .2em; text-transform: uppercase; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.loading, .error { padding: 60px 24px; text-align: center; color: var(--muted); }
.error { color: var(--danger); }

/* --- Barre du haut --- */
.topbar {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 28px;
  padding: 0 clamp(16px, 4vw, 48px); height: 64px; background: rgba(246, 244, 239, .92);
  backdrop-filter: blur(8px); border-bottom: 1px solid var(--line);
}
.logo { font-family: var(--serif); font-size: 26px; text-decoration: none; letter-spacing: .02em; display: flex; align-items: baseline; gap: 8px; }
.logo span { font-family: var(--sans); font-size: 10px; letter-spacing: .3em; text-transform: uppercase; color: var(--muted); }
.nav { display: flex; gap: 4px; flex: 1; }
.nav a { text-decoration: none; padding: 8px 12px; font-size: 13px; letter-spacing: .08em; text-transform: uppercase; border-bottom: 1px solid transparent; }
.nav a:hover { border-color: var(--line); }
.nav a.active { border-color: var(--ink); }
.nav .nav-add { margin-left: auto; }
.user { display: flex; align-items: center; gap: 10px; font-size: 13px; }
.avatar { width: 30px; height: 30px; border-radius: 50%; object-fit: cover; background: var(--soft); display: grid; place-items: center; }

/* --- Boutons et champs --- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 11px 20px; border: 1px solid var(--ink);
  background: var(--ink); color: var(--paper); border-radius: var(--radius); cursor: pointer; text-decoration: none;
  font-size: 12px; letter-spacing: .12em; text-transform: uppercase; font-weight: 600; white-space: nowrap;
}
.btn:hover { background: #333; }
.btn.ghost { background: transparent; color: var(--ink); }
.btn.ghost:hover { background: var(--soft); }
.btn.small { padding: 8px 12px; font-size: 11px; }
.btn.danger { border-color: var(--danger); color: var(--danger); }
.btn:disabled { opacity: .4; cursor: default; }
.link { background: none; border: 0; padding: 0; text-decoration: underline; cursor: pointer; color: inherit; }
.icon { background: none; border: 0; width: 32px; height: 32px; font-size: 18px; cursor: pointer; color: var(--muted); border-radius: 50%; }
.icon:hover { background: var(--soft); color: var(--ink); }

input:not([type=checkbox]):not([type=range]), select, textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--paper);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--ink); outline-offset: -1px; }
input[type=range] { width: 100%; accent-color: var(--ink); }
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; cursor: pointer; }
.check input { accent-color: var(--ink); width: 16px; height: 16px; }
.range { display: grid; gap: 4px; font-size: 12px; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); }
.row { display: flex; gap: 8px; }

/* --- Pages --- */
.page { padding: 36px clamp(16px, 4vw, 48px) 80px; max-width: 1440px; margin: 0 auto; }
.page.narrow { max-width: 980px; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 20px; flex-wrap: wrap; margin-bottom: 26px; }
.tools { display: flex; gap: 8px; flex-wrap: wrap; }
.tools input { width: 220px; }
.tools select { width: auto; }

.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 26px; }
.chip {
  border: 1px solid var(--line); background: transparent; padding: 7px 14px; border-radius: 999px; cursor: pointer;
  font-size: 13px; display: inline-flex; gap: 8px; align-items: center;
}
.chip span { font-size: 11px; color: var(--muted); }
.chip:hover { border-color: var(--ink); }
.chip.on { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.chip.on span { color: #bbb; }

/* --- Catalogue --- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 28px 20px; }
.card { display: flex; flex-direction: column; }
.card-img { display: block; aspect-ratio: 3 / 4; background: var(--soft); overflow: hidden; }
.card-img img { width: 100%; height: 100%; object-fit: cover; transition: transform .4s ease; }
.card-img.cut { background: linear-gradient(180deg, #f1eee8, #e8e4dc); }
.card-img.cut img { object-fit: contain; padding: 10%; }
.card:hover .card-img img { transform: scale(1.03); }
.card-body { padding: 12px 0 8px; flex: 1; }
.brand { margin: 0 0 3px; font-size: 11px; letter-spacing: .18em; text-transform: uppercase; font-weight: 600; }
.card h3 { font-size: 14px; line-height: 1.35; margin-bottom: 6px; }
.meta { margin: 0; display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); }
.meta strong { color: var(--ink); font-weight: 600; }
.card-actions { display: flex; gap: 6px; flex-wrap: wrap; }

.empty { grid-column: 1 / -1; text-align: center; padding: 70px 20px; border: 1px dashed var(--line); }
.empty h2 { font-family: var(--serif); font-size: 28px; text-transform: none; letter-spacing: 0; font-weight: 400; }
.empty p { color: var(--muted); max-width: 440px; margin: 0 auto 20px; }

/* --- Éditeur --- */
.panel { background: var(--paper); border: 1px solid var(--line); padding: clamp(18px, 3vw, 30px); margin-bottom: 20px; }
.panel h2:not(:first-child) { margin-top: 30px; }
.tip { display: flex; gap: 24px; align-items: center; justify-content: space-between; background: #fbf8f1; border-color: #e5d9c3; }
.tip p { margin: 0; color: var(--muted); font-size: 14px; max-width: 560px; }
.bookmarklet {
  flex-shrink: 0; padding: 12px 18px; border: 1px dashed var(--accent); color: var(--accent); text-decoration: none;
  border-radius: 999px; font-weight: 600; font-size: 14px; cursor: grab; background: #fff;
}
.status { min-height: 1.5em; margin: 10px 0 0; font-size: 14px; color: var(--muted); }
.status.ok { color: #3c6b3f; }
.status.warn { color: var(--danger); }
.candidates { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; margin-top: 14px; max-height: 360px; overflow: auto; }
.cand { padding: 0; border: 2px solid transparent; background: var(--soft); aspect-ratio: 3 / 4; cursor: pointer; overflow: hidden; }
.cand img { width: 100%; height: 100%; object-fit: cover; }
.cand:hover { border-color: var(--line); }
.cand.on { border-color: var(--ink); }
.drop { border: 1px dashed #cfc8bb; padding: 22px; text-align: center; background: var(--bg); }
.drop.over { border-color: var(--ink); background: var(--soft); }
.drop p { margin: 0 0 12px; color: var(--muted); font-size: 14px; }
.drop .row { max-width: 520px; margin: 0 auto; }
.cut-panel { display: grid; grid-template-columns: 260px 1fr; gap: 24px; margin-top: 20px; align-items: start; }
.cut-controls { display: grid; gap: 16px; }
.preview { aspect-ratio: 3 / 4; display: grid; place-items: center; padding: 12px; border: 1px solid var(--line); }
.preview canvas, .preview img { max-width: 100%; max-height: 100%; object-fit: contain; }
.checker { background: #fff repeating-conic-gradient(#ece9e3 0% 25%, #fff 0% 50%) 0 0 / 18px 18px; }
.fields { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; }
.field { display: grid; gap: 6px; }
.field > span { font-size: 11px; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); }
.field.wide { grid-column: 1 / -1; }
.form-actions { display: flex; justify-content: space-between; align-items: center; margin-top: 24px; gap: 10px; }
.form-actions div { display: flex; gap: 8px; }

/* --- Modèle --- */
.model-grid { display: grid; grid-template-columns: 300px minmax(320px, 1fr) 300px; gap: 28px; align-items: start; }
.slots { display: grid; gap: 8px; }
.slot { display: flex; align-items: center; background: var(--paper); border: 1px solid var(--line); padding-right: 4px; }
.slot.on { border-color: var(--ink); }
.slot-main { flex: 1; display: flex; gap: 12px; align-items: center; padding: 8px; background: none; border: 0; text-align: left; cursor: pointer; min-width: 0; }
.slot-thumb { width: 48px; height: 58px; flex-shrink: 0; display: grid; place-items: center; background: var(--soft); color: var(--muted); font-size: 22px; }
.slot-thumb img { width: 100%; height: 100%; object-fit: contain; padding: 4px; }
.slot-text { display: grid; min-width: 0; }
.slot-text small { font-size: 10px; letter-spacing: .16em; text-transform: uppercase; color: var(--muted); }
.slot-text span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 14px; }
.slot:not(.filled) .slot-text span { color: var(--muted); }

.stage-col { position: sticky; top: 84px; }
.stage {
  background: radial-gradient(ellipse at 50% 35%, #fbfaf7 0%, #efece5 60%, #e6e1d8 100%);
  border: 1px solid var(--line); display: flex; justify-content: center; padding: 16px 0;
}
.stage-svg { display: block; width: 100%; max-width: 380px; height: auto; max-height: calc(100vh - 230px); touch-action: none; user-select: none; }
.stage-svg image { cursor: grab; filter: drop-shadow(0 2px 3px rgba(0, 0, 0, .18)); }
.sel-box { fill: none; stroke: var(--accent); stroke-width: 1.5; stroke-dasharray: 5 4; pointer-events: none; }
.adjust { display: flex; gap: 12px; align-items: center; padding: 12px 0; min-height: 56px; flex-wrap: wrap; }
.adjust .range { flex: 1; min-width: 140px; }

.summary { background: var(--paper); border: 1px solid var(--line); padding: 20px; display: grid; gap: 14px; }
.summary h2 { margin: 0; }
.pieces { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.pieces li { display: flex; justify-content: space-between; gap: 10px; font-size: 14px; border-bottom: 1px solid var(--soft); padding-bottom: 8px; }
.pieces small { display: block; font-size: 10px; letter-spacing: .16em; text-transform: uppercase; color: var(--muted); }
.pieces a { white-space: nowrap; font-weight: 600; text-decoration: none; border-bottom: 1px solid var(--line); align-self: flex-start; }
.total { display: flex; justify-content: space-between; align-items: baseline; margin: 0; }
.total span { font-size: 11px; letter-spacing: .16em; text-transform: uppercase; color: var(--muted); }
.total strong { font-family: var(--serif); font-size: 26px; font-weight: 400; }
.stack { display: grid; gap: 8px; }

.picker { width: min(920px, 94vw); max-height: 86vh; border: 0; padding: 0; background: var(--bg); }
.picker::backdrop { background: rgba(20, 20, 20, .45); }
.picker-head { display: flex; justify-content: space-between; align-items: center; padding: 18px 22px; position: sticky; top: 0; background: var(--bg); border-bottom: 1px solid var(--line); z-index: 1; }
.picker-head h2 { margin: 0; }
.picker .chips { padding: 16px 22px 0; margin: 0; }
.picker-grid { padding: 18px 22px 24px; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 16px; }
.pick { display: grid; gap: 3px; text-align: left; background: none; border: 0; padding: 0; cursor: pointer; font-size: 13px; }
.pick small { font-size: 10px; letter-spacing: .16em; text-transform: uppercase; font-weight: 600; margin-top: 6px; }
.pick:hover .card-img { outline: 1px solid var(--ink); }

/* --- Tenues --- */
.outfits { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 24px; }
.outfit { background: var(--paper); border: 1px solid var(--line); display: flex; flex-direction: column; }
.outfit-img { background: radial-gradient(ellipse at 50% 35%, #fbfaf7 0%, #ebe7df 100%); border: 0; padding: 14px; cursor: pointer; }
.outfit-img svg { width: 100%; height: 340px; }
.outfit-body { padding: 16px; display: grid; gap: 8px; }
.outfit-body h3 { font-family: var(--serif); font-size: 22px; }
.outfit-body p { margin: 0; }
.outfit .total strong { font-size: 20px; }

/* --- Connexion --- */
.login { min-height: 100vh; display: grid; grid-template-columns: 1fr 1fr; }
.login-art { background: radial-gradient(ellipse at 50% 40%, #fbfaf7 0%, #e9e4da 100%); display: grid; place-items: center; padding: 40px; }
.login-art svg { height: min(80vh, 760px); width: auto; }
.login-card { display: flex; flex-direction: column; justify-content: center; padding: clamp(28px, 7vw, 100px); max-width: 620px; }
.login-card h1 { font-size: clamp(56px, 8vw, 104px); display: flex; flex-direction: column; margin-bottom: 22px; }
.login-card h1 em { font-size: .32em; font-style: normal; font-family: var(--sans); letter-spacing: .5em; text-transform: uppercase; color: var(--muted); margin-top: 12px; }
.lead { font-size: 18px; color: #4a463f; margin: 0 0 34px; max-width: 440px; }
.gbtn { min-height: 44px; }
.login-error { color: var(--danger); min-height: 1.4em; font-size: 14px; }

.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translate(-50%, 20px); background: var(--ink); color: var(--paper);
  padding: 12px 20px; font-size: 14px; opacity: 0; pointer-events: none; transition: .25s; z-index: 100; border-radius: var(--radius);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* --- IA --- */
.mode-bar { display: flex; gap: 6px; margin-bottom: 10px; }
.stage { position: relative; }
.photo-stage { position: relative; width: 100%; display: flex; justify-content: center; }
.photo-stage img { display: block; width: 100%; max-width: 560px; max-height: calc(100vh - 250px); object-fit: contain; }
.photo-stage img.stale { opacity: .45; }
.photo-note { position: absolute; left: 50%; bottom: 10px; transform: translateX(-50%); margin: 0; background: rgba(255, 253, 249, .92); padding: 6px 12px; font-size: 13px; white-space: nowrap; }
.photo-empty { text-align: center; padding: 80px 30px; max-width: 420px; margin: 0 auto; }
.photo-empty h2 { font-family: var(--serif); font-size: 28px; text-transform: none; letter-spacing: 0; font-weight: 400; }
.photo-empty p { color: var(--muted); margin: 0 0 20px; }
.busy { position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; gap: 14px; background: rgba(246, 244, 239, .78); text-align: center; padding: 20px; z-index: 2; }
.busy p { margin: 0; font-size: 14px; }
.spinner { width: 34px; height: 34px; border: 3px solid var(--line); border-top-color: var(--ink); border-radius: 50%; animation: spin .9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.preview { position: relative; }
.profile-grid { display: grid; grid-template-columns: minmax(260px, 380px) 1fr; gap: 28px; align-items: start; }
.avatar-big { position: relative; aspect-ratio: 3 / 4; background: radial-gradient(ellipse at 50% 35%, #fbfaf7 0%, #e9e4da 100%); border: 1px solid var(--line); display: grid; place-items: center; overflow: hidden; }
.avatar-big img { width: 100%; height: 100%; object-fit: cover; }
.fields.two { grid-template-columns: 1fr 1fr; margin: 18px 0 22px; }
.outfit-img.has-photo { padding: 0; }
.outfit-img img { display: block; width: 100%; height: 368px; object-fit: cover; object-position: top; }
.user-name { text-decoration: none; }

/* --- Responsive --- */
@media (max-width: 1180px) {
  .model-grid { grid-template-columns: 260px 1fr; }
  .model-grid > aside:last-child { grid-column: 1 / -1; }
}
@media (max-width: 760px) {
  .topbar { flex-wrap: wrap; height: auto; padding-top: 10px; gap: 10px; }
  .nav { order: 3; flex-basis: 100%; overflow-x: auto; padding-bottom: 6px; }
  .nav a { padding: 6px 8px; font-size: 12px; }
  .user { margin-left: auto; }
  .user-name { display: none; }
  .grid { grid-template-columns: repeat(2, 1fr); gap: 20px 12px; }
  .tools, .tools input { width: 100%; }
  .tools select { flex: 1; }
  .model-grid { grid-template-columns: 1fr; }
  .stage-col { position: static; order: -1; }
  .stage-svg { max-height: 70vh; }
  .tip, .cut-panel { grid-template-columns: 1fr; flex-direction: column; align-items: stretch; }
  .login { grid-template-columns: 1fr; }
  .profile-grid { grid-template-columns: 1fr; }
  .login-art { padding: 24px; order: 2; }
  .login-art svg { height: 50vh; }
}
.fields .check.wide { grid-column: 1 / -1; }
