/* ==================================================================
   Garde-robe — feuille de style unique, pensée cellulaire d'abord.
   ================================================================== */

:root {
  --bg: #f4efe6;
  --surface: #fffdf9;
  --surface-2: #ece5d8;
  --photo-bg: radial-gradient(circle at 50% 40%, #ffffff 0%, #efe9df 100%);
  --ink: #1f1d1a;
  --muted: #6f685e;
  --line: #e0d8ca;
  --accent: #2f5a43;
  --accent-ink: #ffffff;
  --accent-soft: #dfe9e1;
  --danger: #b3382c;
  --warn: #9a6a12;
  --warn-soft: #f7ecd2;
  --shadow: 0 1px 2px rgb(40 30 10 / .06), 0 4px 16px rgb(40 30 10 / .06);
  --radius: 16px;
  --serif: ui-serif, "New York", "Iowan Old Style", Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --tabbar-h: 64px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1a18;
    --surface: #252320;
    --surface-2: #322f2b;
    --photo-bg: radial-gradient(circle at 50% 40%, #3a3631 0%, #2a2724 100%);
    --ink: #f1ece4;
    --muted: #a59d90;
    --line: #3a3631;
    --accent: #8cc4a2;
    --accent-ink: #12261a;
    --accent-soft: #23372b;
    --danger: #ef7d70;
    --warn: #e7b65a;
    --warn-soft: #3a311f;
    --shadow: 0 1px 2px rgb(0 0 0 / .3);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 var(--sans);
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 16px);
  -webkit-tap-highlight-color: transparent;
}
h1, h2, h3 { font-family: var(--serif); font-weight: 600; line-height: 1.2; margin: 0; }
p { margin: 0 0 .5em; }
a { color: var(--accent); }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
img { max-width: 100%; display: block; }

/* ---------- Structure ---------- */

.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.topbar-title { font-size: 1.5rem; }

main { max-width: 1100px; margin: 0 auto; padding: 16px; }
.view { display: flex; flex-direction: column; gap: 16px; }

.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(4, 1fr);
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface);
  border-top: 1px solid var(--line);
}
.tabbar button {
  position: relative;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  border: 0; background: none; color: var(--muted); font: 500 .72rem var(--sans);
}
.tabbar button span { font-size: 1.35rem; line-height: 1; filter: grayscale(1); opacity: .7; }
.tabbar button.on { color: var(--accent); }
.tabbar button.on span { filter: none; opacity: 1; }
.tabbar button[data-badge]:not([data-badge=""])::after {
  content: attr(data-badge);
  position: absolute; top: 6px; left: calc(50% + 8px);
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--danger); color: #fff; font-size: .7rem; line-height: 18px; text-align: center;
}

@media (min-width: 900px) {
  /* Sur grand écran, la barre d'onglets devient une barre centrée en bas, plus discrète. */
  .tabbar { left: 50%; right: auto; transform: translateX(-50%); width: 520px; border: 1px solid var(--line); border-radius: 20px 20px 0 0; }
}

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

/* ---------- Contrôles ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 18px;
  border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink);
  font: 600 .95rem var(--sans); cursor: pointer; text-decoration: none;
}
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.small { min-height: 36px; padding: 0 12px; font-size: .85rem; }
.btn.wide { width: 100%; }
.btn:disabled { opacity: .5; pointer-events: none; }
.link { background: none; border: 0; color: var(--muted); text-decoration: underline; font: inherit; font-size: .85rem; cursor: pointer; }

.icon-btn {
  width: 40px; height: 40px; flex: none;
  display: inline-grid; place-items: center;
  border: 0; border-radius: 10px; background: transparent; color: var(--muted);
  font-size: 1.1rem; cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn.small { width: 30px; height: 30px; font-size: .9rem; }

.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.row.end { justify-content: flex-end; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips.scroll { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin: 0 -16px; padding: 0 16px 2px; }
.chips.scroll::-webkit-scrollbar { display: none; }
.chip {
  flex: none;
  min-height: 36px; padding: 0 14px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  font: 500 .88rem var(--sans); cursor: pointer;
}
.chip.on { background: var(--ink); border-color: var(--ink); color: var(--bg); }

.segmented { display: flex; background: var(--surface-2); border-radius: 12px; padding: 3px; gap: 2px; }
.segmented button {
  flex: 1; min-height: 34px; border: 0; border-radius: 9px; background: none; color: var(--muted);
  font: 600 .85rem var(--sans); cursor: pointer;
}
.segmented button.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }

.field { display: flex; flex-direction: column; gap: 6px; border: 0; padding: 0; margin: 0; min-width: 0; }
.field > span, .field > legend, fieldset > legend { font-size: .82rem; font-weight: 600; color: var(--muted); padding: 0; margin-bottom: 6px; }
fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
input, select, textarea {
  width: 100%; min-height: 44px; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 12px;
  background: var(--surface); color: var(--ink);
  font: 16px var(--sans); /* 16 px : évite le zoom automatique d'iOS */
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.input-with-btn { display: flex; gap: 8px; }

.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch .track { width: 42px; height: 26px; flex: none; border-radius: 13px; background: var(--surface-2); border: 1px solid var(--line); position: relative; transition: background .2s; }
.switch .track::after { content: ""; position: absolute; top: 2px; left: 2px; width: 20px; height: 20px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgb(0 0 0 / .25); transition: transform .2s; }
.switch input:checked + .track { background: var(--accent); border-color: var(--accent); }
.switch input:checked + .track::after { transform: translateX(16px); }
.switch input:focus-visible + .track { outline: 2px solid var(--accent); outline-offset: 2px; }
.switch-label { font-size: .85rem; }

.sync {
  border: 1px solid var(--line); background: var(--surface); color: var(--muted);
  border-radius: 999px; padding: 6px 12px; font: 600 .78rem var(--sans); cursor: pointer; white-space: nowrap;
}
.sync[data-state="pending"] { color: var(--warn); border-color: var(--warn); }
.sync[data-state="auth"] { background: var(--warn-soft); color: var(--warn); border-color: var(--warn); }

.spinner { width: 18px; height: 18px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; display: inline-block; animation: spin .8s linear infinite; vertical-align: middle; }
@keyframes spin { to { transform: rotate(360deg); } }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 12px); z-index: 50;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  max-width: min(92vw, 480px); padding: 12px 16px; border-radius: 12px;
  background: var(--ink); color: var(--bg); font-size: .9rem; box-shadow: var(--shadow);
  transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: var(--danger); color: #fff; }

.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: .75rem; font-weight: 600; }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.notice { background: var(--warn-soft); color: var(--ink); border-radius: 12px; padding: 10px 14px; font-size: .88rem; margin: 0; }
.warning { background: var(--warn-soft); border-radius: 10px; padding: 10px 12px; }

/* ---------- Accueil ---------- */

.welcome { position: fixed; inset: 0; z-index: 40; background: var(--bg); display: grid; place-items: center; padding: 24px; overflow: auto; }
.welcome-inner { width: min(380px, 100%); display: flex; flex-direction: column; align-items: center; gap: 12px; text-align: center; }
.welcome-logo { border-radius: 22px; box-shadow: var(--shadow); }
.welcome h1 { font-size: 2.2rem; }
.welcome-msg { font-size: .88rem; color: var(--muted); min-height: 1.2em; }

/* ---------- Aujourd'hui ---------- */

.weather-main { display: flex; align-items: center; gap: 14px; }
.weather-main > div { flex: 1; }
.weather-icon { font-size: 2.6rem; line-height: 1; }
.weather-temp { font: 600 2rem var(--serif); }
.weather-temp small { font: 500 .95rem var(--sans); color: var(--muted); }
.weather-day { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 14px 0 0; }
.weather-day div { background: var(--surface-2); border-radius: 10px; padding: 8px; }
.weather-day dt { font-size: .7rem; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.weather-day dd { margin: 0; font-weight: 600; font-size: .88rem; }
.advice { margin: 12px 0 0; font-size: .9rem; }
@media (max-width: 380px) { .weather-day { grid-template-columns: repeat(2, 1fr); } }

/* Conversation */
.chat { display: flex; flex-direction: column; gap: 12px; }
.chat > * { scroll-margin-top: 80px; scroll-margin-bottom: 150px; } /* sous la barre du haut, au-dessus de la zone de saisie */
.bubble { max-width: 86%; padding: 10px 14px; border-radius: 18px; font-size: .95rem; line-height: 1.4; }
.bubble.bot { align-self: flex-start; background: var(--surface); border: 1px solid var(--line); border-bottom-left-radius: 6px; }
.bubble.me { align-self: flex-end; background: var(--accent); color: var(--accent-ink); border-bottom-right-radius: 6px; white-space: pre-wrap; }
.bubble.typing { display: flex; align-items: center; gap: 8px; color: var(--muted); }
.chat-hint { font-size: .82rem; color: var(--muted); margin: -4px 0 0 4px; }
.chat-actions { display: flex; justify-content: space-between; padding: 0 4px; }
.composer {
  position: sticky; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 8px); z-index: 5;
  display: flex; gap: 8px; align-items: flex-end;
  background: var(--surface); border: 1px solid var(--line); border-radius: 24px; padding: 6px 6px 6px 14px;
  box-shadow: 0 6px 24px rgb(40 30 10 / .12);
}
.composer textarea { border: 0; outline: none; padding: 8px 0; min-height: 40px; resize: none; overflow-y: hidden; background: transparent; line-height: 1.35; }
.composer textarea:focus { outline: none; }
.composer .send { width: 42px; height: 42px; min-height: 42px; padding: 0; border-radius: 50%; font-size: 1.2rem; flex: none; }
.history-context { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }

.outfit h3 { font-size: 1.25rem; margin-bottom: 12px; }
.pieces { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 10px; margin-bottom: 12px; }
.piece { margin: 0; }
.piece-img { aspect-ratio: 1; background: var(--photo-bg); border-radius: 12px; padding: 8px; display: grid; place-items: center; }
.piece-img img { max-height: 100%; object-fit: contain; filter: drop-shadow(0 4px 6px rgb(0 0 0 / .12)); }
.piece figcaption { font-size: .75rem; color: var(--muted); margin-top: 4px; line-height: 1.25; }
.explanation { font-size: .95rem; }
.fixes { font-size: .78rem; color: var(--muted); }
.excluded { font-size: .88rem; color: var(--muted); }
.excluded summary { cursor: pointer; }
.excluded ul { margin: 8px 0 0; padding-left: 18px; }

.history summary { cursor: pointer; font: 600 1.05rem var(--serif); }
.history-row { padding: 12px 0; border-top: 1px solid var(--line); }
.history-row:first-child { margin-top: 10px; }
.history-head { display: flex; align-items: center; gap: 8px; }
.history-head strong { display: inline-block; }
.history-head strong::first-letter { text-transform: uppercase; } /* « Mercredi 21 octobre », pas « Octobre » */
.history-head .icon-btn { margin-left: auto; }
.history-pieces { display: flex; gap: 6px; margin-top: 6px; overflow-x: auto; }
.history-pieces img { width: 52px; height: 52px; object-fit: contain; background: var(--photo-bg); border-radius: 8px; padding: 4px; flex: none; }

/* ---------- Dressing ---------- */

.filters { display: flex; flex-direction: column; gap: 10px; }
.count { margin: -4px 0 0; font-size: .85rem; }
.grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
@media (min-width: 640px) { .grid { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 960px) { .grid { grid-template-columns: repeat(4, 1fr); } }

.item { padding: 0; overflow: hidden; display: flex; flex-direction: column; }
.item-img { position: relative; aspect-ratio: 1; background: var(--photo-bg); padding: 12px; display: grid; place-items: center; }
.item-tools { position: absolute; top: 6px; right: 6px; display: flex; gap: 4px; }
.item-tools .icon-btn { width: 32px; height: 32px; font-size: .9rem; background: color-mix(in srgb, var(--surface) 85%, transparent); box-shadow: var(--shadow); }
.item-img img { max-height: 100%; object-fit: contain; filter: drop-shadow(0 6px 8px rgb(0 0 0 / .12)); }
.item-img img.img-error { opacity: .2; }
.item-body { padding: 10px 12px 8px; display: flex; flex-direction: column; gap: 2px; flex: 1; }
.item h3 { font-size: 1rem; }
.meta { font-size: .78rem; color: var(--muted); margin: 0; }
.tags { display: flex; flex-wrap: wrap; gap: 4px 10px; font-size: .75rem; color: var(--muted); margin: 4px 0 0; }
.tags span { display: inline-flex; align-items: center; gap: 4px; }
.swatch { width: 10px; height: 10px; border-radius: 50%; display: inline-block; border: 1px solid rgb(0 0 0 / .15); }
.item-actions { display: flex; align-items: center; margin-top: auto; padding-top: 6px; }
.item-actions .switch-label { font-size: .8rem; }
.item.laundry .item-img img { opacity: .4; }
.item.laundry h3 { color: var(--muted); }

.empty { grid-column: 1 / -1; text-align: center; padding: 40px 16px; display: flex; flex-direction: column; align-items: center; gap: 12px; }

/* ---------- Ajouter ---------- */

.dropzone {
  border: 2px dashed var(--line); border-radius: var(--radius); background: var(--surface);
  padding: 24px 16px; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 8px;
}
.dropzone.over { border-color: var(--accent); background: var(--accent-soft); }
.dropzone .row { justify-content: center; margin: 8px 0; }
.desktop-only { display: none; }
@media (hover: hover) and (pointer: fine) { .desktop-only { display: block; } }

.model-status { display: flex; flex-direction: column; gap: 6px; font-size: .85rem; color: var(--muted); }
.model-status progress { width: 100%; accent-color: var(--accent); }

.queue { display: flex; flex-direction: column; gap: 8px; }
.queue-item { display: flex; align-items: center; gap: 12px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 8px 10px; }
.queue-thumb { width: 56px; height: 56px; flex: none; border-radius: 10px; background: var(--photo-bg); display: grid; place-items: center; overflow: hidden; }
.queue-thumb img { max-height: 100%; object-fit: contain; }
.queue-info { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.queue-info strong { font-size: .9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.queue-info .state { font-size: .78rem; color: var(--muted); }
.queue-item.review { border-color: var(--accent); }
.queue-item.error .state { color: var(--danger); }
.queue-item.done .state { color: var(--accent); }

/* ---------- Feuilles modales ---------- */

dialog { border: 0; padding: 0; color: var(--ink); background: var(--surface); }
dialog::backdrop { background: rgb(20 15 5 / .45); }
.sheet {
  width: 100%; max-width: 560px; max-height: 92vh; margin: auto auto 0; border-radius: 20px 20px 0 0;
}
@media (min-width: 640px) { .sheet { margin: auto; border-radius: 20px; } }
.sheet form { display: flex; flex-direction: column; max-height: 92vh; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px 8px; }
.sheet-body { overflow-y: auto; padding: 0 16px 16px; display: flex; flex-direction: column; gap: 14px; }
.sheet-foot { display: flex; gap: 8px; justify-content: flex-end; padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); }
.preview-wrap { background: var(--photo-bg); border-radius: 14px; padding: 12px; display: flex; flex-direction: column; align-items: center; gap: 8px; }
.preview-wrap img { max-height: 34vh; object-fit: contain; }
.preview-toggle { font-size: .85rem; }
.preview-toggle input { width: auto; min-height: 0; margin-right: 6px; }
.ai-note { font-size: .82rem; color: var(--muted); background: var(--accent-soft); border-radius: 10px; padding: 8px 12px; margin: 0; }

.confirm { width: min(92vw, 400px); border-radius: 18px; padding: 20px; margin: auto; }
.confirm p { margin-bottom: 16px; }

/* ---------- Réglages ---------- */

.settings-block { display: flex; flex-direction: column; gap: 10px; }
.settings-block h2 { font-size: 1.15rem; }
.settings-block p { margin: 0; }

/* ---------- Illustrations et fiche enrichie ---------- */

.preview-pair { display: flex; gap: 10px; justify-content: center; align-items: center; width: 100%; }
.preview-pair img { flex: 1; min-width: 0; max-height: 30vh; object-fit: contain; }
.preview-pair .drawing-preview { flex: 0 0 34%; background: var(--surface); border-radius: 12px; padding: 8px; }
.field.group { border: 1px solid var(--line); border-radius: 14px; padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 10px; }
.field.group > legend { padding: 0 6px; margin: 0; }
.swatch-input { flex: 0 0 48px; width: 48px; padding: 4px; }
.reference { background: var(--accent-soft); border-radius: 12px; padding: 10px 12px; display: flex; flex-direction: column; gap: 6px; }
.reference p { margin: 0; }
.ref-title { font-weight: 600; }
.ref-facts { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin: 0; }
.ref-facts dt { font-size: .7rem; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.ref-facts dd { margin: 0; font-size: .85rem; }
.reference a { word-break: break-word; }
.error-text { color: var(--danger); }
.variant { font-size: .88rem; color: var(--muted); font-style: italic; }
img.is-drawing { filter: none !important; }
