/* Guarda-Roupa Virtual. Sem dependencias externas. */
:root {
  --bg: #faf8f5;
  --surface: #ffffff;
  --surface-2: #f0ede7;
  --text: #1d1b19;
  --muted: #77726a;
  --line: #e6e1d8;
  --accent: #7b2d3b;
  --accent-ink: #ffffff;
  --accent-text: #7b2d3b;
  --garment-bg: #f0ede7;
  --toast-bg: #222;
  --toast-line: transparent;
  --danger: #b3261e;
  --radius: 14px;
  --nav-h: 56px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121110;
    --surface: #1b1a18;
    --surface-2: #272522;
    --text: #f1eee8;
    --muted: #9b958b;
    --line: #2f2d2a;
    --accent: #9a3a4c;
    --accent-text: #d58a98;
    --garment-bg: #4a4540;
    --toast-bg: #3a3735;
    --toast-line: rgba(255, 255, 255, 0.08);
    --danger: #f08a80;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  overscroll-behavior: none;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  padding-top: env(safe-area-inset-top);
}
#main {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 0 max(16px, env(safe-area-inset-right)) 28px max(16px, env(safe-area-inset-left));
  outline: none;
}
.screen { max-width: 560px; margin: 0 auto; animation: screen-in .22s ease-out; }
@keyframes screen-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------- Navegacao inferior ---------- */
#nav {
  display: flex;
  border-top: 1px solid var(--line);
  background: var(--bg);
  padding-bottom: env(safe-area-inset-bottom);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}
.nav-item {
  flex: 1;
  min-height: var(--nav-h);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: var(--muted);
  text-decoration: none;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: .01em;
}
.nav-item.on { color: var(--accent-text); font-weight: 600; }
.nav-ico { width: 24px; height: 24px; }

/* ---------- Tipografia e estrutura ---------- */
h1.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
h1 { font-size: 34px; line-height: 1.08; font-weight: 700; letter-spacing: -.022em; margin: 0; }
h2, h3 { margin: 0; letter-spacing: -.01em; }
h3 { font-size: 17px; font-weight: 600; }
.h2 { font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 10px; }
p { margin: 0; }
.lead { color: var(--muted); font-size: 16px; padding-bottom: 14px; }
.muted { color: var(--muted); }
.small-txt { font-size: 13px; }
.hint { color: var(--muted); font-size: 14px; padding: 10px 0 4px; }
.screen-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 18px 0 14px; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; }
.gap { gap: 8px; }
.wrap { flex-wrap: wrap; }
.center { align-items: center; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.count { font-size: 13px; padding: 4px 0 10px; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.card.pad { padding: 16px; margin-bottom: 14px; display: flex; flex-direction: column; gap: 12px; }

.label {
  display: flex; justify-content: space-between; gap: 8px;
  font-size: 13px; font-weight: 600; color: var(--muted);
  margin-bottom: 6px;
}
.label em { font-style: normal; text-transform: none; letter-spacing: 0; font-weight: 400; }
.field { display: block; }
.field-err { color: var(--danger); font-size: 13px; min-height: 0; }
.field-err:not(:empty) { padding-top: 4px; }

/* ---------- Botoes e campos ---------- */
.btn {
  min-height: 44px;
  padding: 0 18px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 550;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-decoration: none;
  cursor: pointer;
  transition: transform .12s ease-out, opacity .12s;
}
.btn:active { transform: scale(.97); }
.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.ghost { background: transparent; }
.btn.small { padding: 0 14px; font-size: 15px; }
.btn.big { min-height: 54px; font-size: 17px; }
.btn.block { display: flex; width: 100%; }
.btn.danger-text { color: var(--danger); }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.input {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 16px; /* evita zoom do iOS ao focar */
  appearance: none;
  -webkit-appearance: none;
}
textarea.input { resize: vertical; min-height: 84px; }
.input.invalid { border-color: var(--danger); }
.select {
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 34px;
}
.search { margin-bottom: 10px; }
.color-input { width: 56px; height: 44px; padding: 2px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); }

.chips { display: flex; gap: 8px; }
.chips.wrap { flex-wrap: wrap; }
.chips.scroll, .chip-row { overflow-x: auto; scrollbar-width: none; padding: 2px 0; }
.chips.scroll::-webkit-scrollbar, .chip-row::-webkit-scrollbar { display: none; }
.chip-row { display: flex; gap: 8px; margin-bottom: 8px; }
.chip, .seg {
  position: relative;
  flex: 0 0 auto;
  min-height: 44px;
  padding: 0 16px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 15px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  cursor: pointer;
}
.chip.on, .seg.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; border: 1px solid rgba(0,0,0,.15); margin-right: 4px; vertical-align: -1px; }
.chip .dot { margin-right: 0; }

.swatches { display: flex; gap: 4px; }
.swatch { width: 44px; height: 44px; padding: 0; border: 0; background: none; display: grid; place-items: center; cursor: pointer; }
.swatch::before { content: ""; width: 32px; height: 32px; border-radius: 50%; background: var(--c); border: 1px solid rgba(0,0,0,.12); }
.swatch.on::before { box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--accent); }

.tag { display: inline-block; margin-left: 8px; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; background: var(--accent); color: var(--accent-ink); vertical-align: 2px; }

.slider { display: block; padding: 6px 0 2px; }
.slider output { font-weight: 500; }
.slider input[type=range] { width: 100%; height: 44px; margin: 0; accent-color: var(--accent); }

.segs { display: flex; gap: 6px; }

.link-row { display: flex; flex-direction: column; gap: 2px; padding: 16px; margin-top: 16px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); color: var(--text); text-decoration: none; font-weight: 550; min-height: 44px; }
.notice { display: block; margin-bottom: 12px; padding: 12px 14px; border-radius: 12px; background: var(--surface-2); color: var(--text); text-decoration: none; font-size: 14px; }
.notice strong { color: var(--accent-text); }
.status { color: var(--muted); font-size: 14px; min-height: 1.4em; }

.info { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 0; font-size: 15px; }
.info dt { color: var(--muted); }
.info dd { margin: 0; }

.empty { text-align: center; padding: 48px 16px; display: flex; flex-direction: column; align-items: center; gap: 12px; color: var(--muted); }
.empty h2 { color: var(--text); font-size: 20px; }

/* ---------- Guarda-roupa ---------- */
.grid-items { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
@media (min-width: 480px) { .grid-items { grid-template-columns: repeat(3, 1fr); } }
.tile { display: block; color: inherit; text-decoration: none; }
.tile-img { aspect-ratio: 4 / 5; background: var(--surface-2); border-radius: var(--radius); display: flex; align-items: center; justify-content: center; padding: 12px; }
.tile-img img { max-width: 100%; max-height: 100%; object-fit: contain; }
.tile-meta { padding: 8px 2px 0; display: flex; flex-direction: column; font-size: 14px; }
.tile-meta strong { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile-meta .muted { font-size: 13px; }

/* ---------- Cadastro de peca ---------- */
.checker {
  background-color: #fff;
  background-image:
    linear-gradient(45deg, #dcd9d2 25%, transparent 25%, transparent 75%, #dcd9d2 75%),
    linear-gradient(45deg, #dcd9d2 25%, transparent 25%, transparent 75%, #dcd9d2 75%);
  background-size: 20px 20px;
  background-position: 0 0, 10px 10px;
}
.cut-wrap { position: relative; display: flex; justify-content: center; border-radius: var(--radius); overflow: hidden; touch-action: none; border: 1px solid var(--line); }
.cut-canvas { display: block; max-width: 100%; max-height: 50vh; max-height: 50dvh; width: auto; height: auto; touch-action: none; user-select: none; -webkit-user-select: none; }
.brush-ring { display: none; position: absolute; left: 0; top: 0; border: 2px solid var(--accent); border-radius: 50%; pointer-events: none; background: rgba(255,255,255,.25); }
.tools { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 8px 0; }
.item-preview-wrap { display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 4px 0 18px; }
.item-preview { width: 100%; max-height: 260px; object-fit: contain; background: var(--surface-2); border-radius: var(--radius); padding: 14px; }

/* ---------- Perfis e looks ---------- */
.profile-card, .look-card { display: flex; gap: 14px; padding: 12px; align-items: stretch; }
.profile-card.is-active { border-color: var(--accent); }
.profile-thumb { flex: 0 0 64px; height: 128px; background: var(--surface-2); border-radius: 12px; padding: 4px; display: flex; justify-content: center; }
.look-thumb { flex: 0 0 96px; height: 192px; background: var(--surface-2); border-radius: 12px; display: flex; justify-content: center; overflow: hidden; }
.profile-thumb svg, .look-thumb svg { height: 100%; width: auto; }
.profile-info, .look-info { display: flex; flex-direction: column; gap: 6px; min-width: 0; flex: 1; justify-content: center; }
.profile-info h3, .look-info h3 { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.profile-edit { display: grid; gap: 16px; }
.profile-preview { height: 250px; background: var(--surface-2); border-radius: 18px; display: flex; justify-content: center; padding: 8px 0; transition: opacity .15s; }
.profile-preview.stale { opacity: .55; }
.profile-preview svg { height: 100%; width: auto; }
.profile-form { display: flex; flex-direction: column; gap: 14px; }

/* ---------- Montar look ---------- */
.bar { display: flex; gap: 10px; padding: 12px 0 8px; }
.bar .select { flex: 1; }
.stage {
  height: 46vh; height: min(46dvh, 500px);
  display: flex; justify-content: center;
  background: var(--surface-2);
  border-radius: 18px;
  touch-action: none;
  user-select: none; -webkit-user-select: none;
  overflow: hidden;
}
.stage-svg { height: 100%; width: auto; aspect-ratio: 1 / 2; display: block; touch-action: none; -webkit-touch-callout: none; }
.stage-svg .layer image { pointer-events: all; }
.sel-box { fill: none; stroke: var(--accent); stroke-width: 1.5; stroke-dasharray: 6 4; vector-effect: non-scaling-stroke; pointer-events: none; }
.adjust-bar { display: none; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; padding: 8px 0 0; }
.adjust-bar.on { display: flex; }
.worn { padding: 12px 0 4px; display: flex; flex-direction: column; gap: 4px; }
.strip-box { padding-top: 10px; }
.strip { display: flex; gap: 10px; overflow-x: auto; padding: 10px 0 8px; scrollbar-width: none; }
.strip::-webkit-scrollbar { display: none; }
.strip-item { flex: 0 0 80px; border: 2px solid transparent; border-radius: 12px; background: var(--surface-2); padding: 6px; color: var(--text); font: inherit; display: flex; flex-direction: column; align-items: center; gap: 4px; cursor: pointer; min-height: 44px; }
.strip-item.on { border-color: var(--accent); }
.strip-item img { width: 100%; height: 72px; object-fit: contain; }
.strip-item span { font-size: 12px; max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.strip-empty { display: flex; align-items: center; gap: 12px; padding: 8px 0; }
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; padding-top: 8px; }
.actions .block { grid-column: 1 / -1; }

/* ---------- Dialogos, avisos, instalacao ---------- */
#layer { position: relative; z-index: 100; }
.backdrop { position: fixed; inset: 0; z-index: 90; background: rgba(0,0,0,.42); display: flex; align-items: center; justify-content: center; padding: 16px; animation: fade .18s ease-out; }
.backdrop.out, .install.out { opacity: 0; transition: opacity .18s; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.dialog { width: min(100%, 380px); background: var(--surface); color: var(--text); border-radius: 18px; padding: 20px; animation: pop .2s ease-out; }
@keyframes pop { from { opacity: 0; transform: scale(.96); } to { opacity: 1; transform: none; } }
.dlg-title { font-size: 19px; font-weight: 650; }
.dlg-text { color: var(--muted); padding-top: 8px; font-size: 15px; }
.dialog .input { margin-top: 14px; }
.dlg-actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; margin-top: 18px; }
.toast { position: fixed; left: 50%; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 14px); transform: translateX(-50%); max-width: calc(100vw - 32px); z-index: 95; background: #222; color: #fff; padding: 12px 16px; border-radius: 12px; font-size: 15px; animation: toast-in .2s ease-out; }
.toast.out { opacity: 0; transition: opacity .25s; }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }
.update-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 16px; background: var(--accent); color: var(--accent-ink); font-size: 15px; }
.update-bar .btn { background: #fff; color: var(--accent); border-color: #fff; min-height: 44px; }
.install { position: fixed; inset: 0; z-index: 80; background: var(--bg); display: flex; align-items: center; justify-content: center; padding: max(24px, env(safe-area-inset-top)) 24px max(24px, env(safe-area-inset-bottom)); overflow-y: auto; animation: fade .2s ease-out; }
.install-card { width: min(100%, 400px); display: flex; flex-direction: column; gap: 14px; }
.install-icon { border-radius: 16px; }
.steps { list-style: none; margin: 4px 0 8px; padding: 0; display: flex; flex-direction: column; gap: 12px; }
.steps li { display: flex; gap: 12px; align-items: flex-start; font-size: 16px; }
.step-n { flex: 0 0 28px; height: 28px; border-radius: 50%; border: 1px solid var(--accent); color: var(--accent); display: grid; place-items: center; font-size: 14px; font-weight: 600; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}

/* ======================= Rodada 2: correcoes e design ======================= */
.nav-path { fill: none; stroke-width: 1.6; }
.nav-item.on .nav-path { fill: currentColor; fill-opacity: .14; stroke-width: 2; }
.swatch.on::before { box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--accent-text); }
.slider input[type=range] { accent-color: var(--accent-text); }
.link-row .muted { font-weight: 400; }

/* botoes de cabecalho: texto sem borda */
.screen-head .btn { border: 0; background: transparent; color: var(--accent-text); padding: 0 4px; font-weight: 600; }
.screen-head .btn:active { opacity: .6; transform: none; }

/* chip ativo em grafite (guarda-roupa e filtros) */
.chip.graphite.on { background: var(--text); border-color: var(--text); color: var(--bg); }
.chip.graphite .dot { margin-right: 0; }
.chip-row { margin-bottom: 4px; }
.search-row { display: flex; gap: 8px; margin-bottom: 8px; }
.search-row .search { margin-bottom: 0; flex: 1; }
.filter-btn.on { border-color: var(--text); font-weight: 600; }
.filter-btn { flex: 0 0 auto; }

/* grade: 3 colunas, 3:4 */
.grid-items { grid-template-columns: repeat(3, 1fr); gap: 8px; }
.tile-img { aspect-ratio: 3 / 4; background: var(--garment-bg); border-radius: 12px; padding: 8px; }
.tile-name { display: block; font-size: 13px; font-weight: 500; padding: 6px 2px 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.count { padding-top: 2px; }
.count[hidden] { display: none; }

/* mascara de fade nas listas que rolam */
.fade-x { -webkit-mask-image: linear-gradient(90deg, #000 calc(100% - 28px), transparent 100%); mask-image: linear-gradient(90deg, #000 calc(100% - 28px), transparent 100%); }

/* fluxo de cadastro */
body.flow #nav { display: none; }
.flow-bar { position: sticky; top: 0; z-index: 5; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px; padding: 6px 0; margin-bottom: 8px; background: var(--bg); min-height: 52px; }
.bar-btn { min-height: 44px; padding: 0 4px; border: 0; background: transparent; color: var(--text); font: inherit; font-size: 17px; cursor: pointer; justify-self: start; }
.bar-btn.accent { color: var(--accent-text); font-weight: 600; justify-self: end; }
.bar-btn:disabled { opacity: .4; }
.bar-title { display: flex; flex-direction: column; align-items: center; line-height: 1.2; }
.bar-title h1 { font-size: 17px; font-weight: 600; letter-spacing: 0; line-height: 1.2; }
.bar-title span { font-size: 13px; color: var(--muted); }
.adv { margin: 6px 0 12px; border-top: 1px solid var(--line); padding-top: 4px; }
.adv summary { min-height: 44px; display: flex; align-items: center; cursor: pointer; color: var(--accent-text); font-weight: 600; list-style: none; }
.adv summary::-webkit-details-marker { display: none; }
.center-x { justify-content: center; }
.item-preview { background: var(--garment-bg); }

/* montar */
.bar { align-items: center; }
.bar .select { flex: 1; min-width: 0; }
.txt-btn { min-height: 44px; padding: 0 8px; border: 0; background: transparent; font: inherit; font-size: 16px; cursor: pointer; }
.txt-btn.muted-btn { color: var(--muted); }
.txt-btn.accent-btn { color: var(--accent-text); font-weight: 650; }
.icon-btn { width: 44px; height: 44px; display: grid; place-items: center; border: 0; background: transparent; color: var(--accent-text); cursor: pointer; }
.icon-btn:disabled { opacity: .4; }
.stage { position: relative; height: 54vh; height: min(54dvh, 560px); background: var(--garment-bg); }
.stage-svg .layer image { filter: drop-shadow(0 1px 2px rgba(0, 0, 0, .28)); }
.stage-svg.gesturing .layer image { filter: none; }
.sel-box { fill: none; stroke: var(--accent-text); stroke-width: 1.5; stroke-dasharray: none; vector-effect: non-scaling-stroke; pointer-events: none; }
.sel-handle { fill: var(--bg); stroke: var(--accent-text); stroke-width: 1.5; vector-effect: non-scaling-stroke; pointer-events: none; }
.adjust-bar { position: absolute; left: 10px; right: 10px; bottom: 10px; display: none; justify-content: center; gap: 8px; padding: 6px; border-radius: 16px; background: color-mix(in srgb, var(--bg) 72%, transparent); -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px); }
.adjust-bar.on { display: flex; }
.layers { padding: 10px 0 0; display: flex; flex-direction: column; gap: 4px; }
.layers .chips { padding: 0; }
.strip-box { padding-top: 8px; }
.strip-item { background: var(--garment-bg); }
.strip-item.on { border-color: var(--accent-text); }
.profile-thumb, .look-thumb, .profile-preview { background: var(--garment-bg); }

/* toast no topo, dialogos e folhas */
.toast { top: calc(env(safe-area-inset-top) + 10px); bottom: auto; background: var(--toast-bg); border: 1px solid var(--toast-line); }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, -8px); } to { opacity: 1; transform: translate(-50%, 0); } }
.backdrop.bottom { align-items: flex-end; padding: 0; }
.sheet { width: 100%; max-width: 560px; margin: 0 auto; background: var(--surface); color: var(--text); border-radius: 18px 18px 0 0; padding: 16px 16px calc(16px + env(safe-area-inset-bottom)); animation: sheet-up .22s ease-out; max-height: 80dvh; overflow-y: auto; }
@keyframes sheet-up { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.sheet-head .btn { border: 0; background: transparent; color: var(--accent-text); font-weight: 600; }
.sheet-body { display: flex; flex-direction: column; gap: 14px; }

.grid-items .empty { grid-column: 1 / -1; }
