:root {
  --bg: #F6F5F2;
  --card: #FFFFFF;
  --ink: #1F1E1B;
  --muted: #74706A;
  --line: #E4E1DA;
  --accent: #35439B;
  --accent-soft: #E9EBF7;
  --danger: #B23A32;
  --ok: #2F7D4E;
  --tabbar: 62px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--ink); font: 16px/1.4 -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; }
body { overscroll-behavior-y: contain; }
button { font: inherit; color: inherit; }
img { display: block; }
[hidden] { display: none !important; }
/* визуально скрытое поле файла: остаётся «живым» для label — display:none ломает выбор файла в Safari */
.vh { position: fixed; top: 0; left: 0; width: 1px; height: 1px; margin: 0; padding: 0; border: 0; opacity: 0; overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; pointer-events: none; }
label.btn { display: block; cursor: pointer; }

/* ---------- вход ---------- */
.login { min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.login-box { width: 100%; max-width: 320px; display: grid; gap: 12px; text-align: center; }
.login-logo { font-size: 34px; font-weight: 700; letter-spacing: .02em; color: var(--accent); }
.login-hint { margin: 0; color: var(--muted); }
.login-box input { font-size: 22px; text-align: center; padding: 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--card); letter-spacing: .2em; }
.login-err { margin: 0; color: var(--danger); }
.ver { color: var(--muted); font-size: 12px; margin: 8px 0 0; }
.install-cta { margin-top: 4px; }
.install-bar { display: flex; align-items: center; gap: 10px; margin: 8px 12px 0; padding: 10px 12px; background: var(--accent-soft); border: 1px solid var(--line); border-radius: 12px; }
.install-bar-txt { flex: 1; font-size: 13px; color: var(--ink); }
.install-bar .btn.primary { padding: 8px 14px; white-space: nowrap; }
.install-bar-x { border: 0; background: none; color: var(--muted); font-size: 15px; line-height: 1; padding: 4px 6px; }

/* ---------- каркас ---------- */
.top { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between; padding: 12px 16px 8px; background: var(--bg); }
.top-title { font-size: 22px; font-weight: 700; }
.top-right { display: flex; gap: 8px; align-items: center; color: var(--muted); font-size: 14px; }
main { padding: 0 12px calc(var(--tabbar) + var(--safe-b) + 84px); }
.tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: grid; grid-template-columns: repeat(3, 1fr); height: calc(var(--tabbar) + var(--safe-b)); padding-bottom: var(--safe-b); background: var(--card); border-top: 1px solid var(--line); }
.tab { border: 0; background: none; color: var(--muted); font-size: 12px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; }
.tab-ic { font-size: 20px; line-height: 1; }
.tab.active { color: var(--accent); font-weight: 600; }
.fab { position: fixed; right: 18px; bottom: calc(var(--tabbar) + var(--safe-b) + 18px); z-index: 31; width: 58px; height: 58px; border-radius: 50%; border: 0; background: var(--accent); color: #fff; font-size: 32px; line-height: 1; box-shadow: 0 6px 18px rgba(53, 67, 155, .35); }
.fab:active { transform: scale(.96); }

.btn { border: 1px solid var(--line); background: var(--card); border-radius: 12px; padding: 10px 14px; font-weight: 600; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { color: var(--danger); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--accent); }
.btn.wide { width: 100%; }
.btn:disabled { opacity: .5; }
.row { display: flex; gap: 8px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.spacer { flex: 1; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* ---------- чипы ---------- */
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chips.scroll { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; padding: 2px 0; }
.chips.scroll::-webkit-scrollbar { display: none; }
.chip { border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 6px 12px; font-size: 14px; white-space: nowrap; display: inline-flex; align-items: center; gap: 6px; }
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.chip .sw { width: 14px; height: 14px; border-radius: 50%; border: 1px solid rgba(0,0,0,.15); display: inline-block; }
.chip.multi .sw { background: conic-gradient(#e33, #fc3, #3c6, #36c, #c3c, #e33); }

/* ---------- шкаф ---------- */
.section-title { font-weight: 700; margin: 14px 4px 8px; display: flex; align-items: center; gap: 8px; }
.grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
@media (min-width: 560px) { .grid { grid-template-columns: repeat(4, 1fr); } }
@media (min-width: 800px) { .grid { grid-template-columns: repeat(6, 1fr); } }
.card { position: relative; background: var(--card); border: 1px solid var(--line); border-radius: 12px; aspect-ratio: 3 / 4; padding: 6px; overflow: hidden; }
.card img { width: 100%; height: 100%; object-fit: contain; }
.card .badge { position: absolute; left: 6px; top: 6px; background: var(--danger); color: #fff; font-size: 10px; padding: 2px 6px; border-radius: 999px; }
.card .cat { position: absolute; right: 6px; bottom: 6px; background: rgba(255,255,255,.9); color: var(--muted); font-size: 10px; padding: 2px 6px; border-radius: 999px; }
.card.processing img { opacity: .45; }
.card .proc { position: absolute; left: 6px; right: 6px; top: 50%; transform: translateY(-50%); background: rgba(53,67,155,.92); color: #fff; font-size: 11px; padding: 4px 6px; border-radius: 8px; text-align: center; }
.card .proc.err { background: rgba(178,58,50,.92); }
.empty { text-align: center; color: var(--muted); padding: 40px 16px; }
.empty b { display: block; color: var(--ink); font-size: 18px; margin-bottom: 6px; }

/* новые вещи — тегирование */
.tray { background: var(--accent-soft); border-radius: 14px; padding: 10px; margin-top: 8px; display: grid; gap: 10px; }
.tray-item { display: grid; grid-template-columns: 84px 1fr; gap: 10px; background: var(--card); border-radius: 12px; padding: 8px; }
.tray-item .card { aspect-ratio: 3 / 4; }
.tray-item .chips { margin-top: 4px; }
.tray-item .chip { padding: 5px 10px; font-size: 13px; }
.tray-item .lbl { font-size: 12px; color: var(--muted); margin-bottom: 2px; }
.tray-item.done { opacity: .55; }

/* очередь загрузки */
.queue { display: grid; gap: 6px; margin-top: 8px; }
.q { display: flex; align-items: center; gap: 10px; background: var(--card); border-radius: 12px; padding: 8px 10px; font-size: 14px; }
.q img { width: 40px; height: 40px; object-fit: cover; border-radius: 8px; background: var(--bg); }
.q .bar { flex: 1; height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; }
.q .bar i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.q.err { color: var(--danger); }

/* ---------- сборка: слоты ---------- */
.builder-filters { position: sticky; top: 50px; z-index: 15; background: var(--bg); padding: 4px 0 8px; }
.slot { background: var(--card); border: 1px solid var(--line); border-radius: 14px; margin-bottom: 8px; padding: 6px 0 4px; }
.slot-head { display: flex; align-items: center; gap: 8px; padding: 0 10px 2px; font-size: 13px; color: var(--muted); }
.slot-head b { color: var(--ink); font-weight: 600; }
.slot-head .lock { margin-left: auto; border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 3px 10px; font-size: 12px; }
.slot-head .lock.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.slot.locked { border-color: var(--accent); }
.strip { display: flex; gap: 8px; overflow-x: auto; scroll-snap-type: x mandatory; scrollbar-width: none; padding: 4px calc(50% - 56px); scroll-padding: 0 calc(50% - 56px); }
.strip::-webkit-scrollbar { display: none; }
.strip .s { flex: 0 0 112px; height: 124px; scroll-snap-align: center; border-radius: 12px; border: 2px solid transparent; padding: 4px; background: var(--card); opacity: .45; transition: opacity .15s, transform .15s; }
.strip .s img { width: 100%; height: 100%; object-fit: contain; }
.strip .s.sel { opacity: 1; border-color: var(--accent); transform: scale(1.04); }
.strip .s.none { display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 13px; background: var(--bg); }
.slot-empty { padding: 12px 14px 14px; color: var(--muted); font-size: 14px; }
.slot-empty button { margin-left: 8px; }
.builder-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 4px; }

/* ---------- образы ---------- */
.ogrid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
@media (min-width: 640px) { .ogrid { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 900px) { .ogrid { grid-template-columns: repeat(4, 1fr); } }
.collage { position: relative; aspect-ratio: 3 / 4; background: var(--card); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }
.collage img { position: absolute; object-fit: contain; }
.collage .c-top { left: 26%; top: 3%; width: 50%; height: 46%; }
.collage .c-bottom { left: 26%; top: 47%; width: 50%; height: 50%; }
.collage .c-bag { left: 2%; top: 10%; width: 25%; height: 32%; }
.collage .c-shoes { left: 71%; top: 64%; width: 27%; height: 32%; }
.collage.big { max-width: 360px; margin: 0 auto; }
.ocap { font-size: 12px; color: var(--muted); margin: 4px 2px 0; }

/* ---------- шторка ---------- */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 40; }
.sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 41; background: var(--card); border-radius: 18px 18px 0 0; padding: 12px 16px calc(16px + var(--safe-b)); max-height: 88dvh; overflow-y: auto; }
.sheet::before { content: ""; display: block; width: 40px; height: 4px; border-radius: 2px; background: var(--line); margin: 0 auto 12px; }
.sheet h3 { margin: 4px 0 10px; font-size: 18px; }
.sheet .field { display: grid; gap: 4px; margin: 10px 0; }
.sheet .field label { font-size: 12px; color: var(--muted); }
.sheet input[type=text], .sheet input[type=number], .sheet textarea { font: inherit; padding: 10px; border: 1px solid var(--line); border-radius: 10px; width: 100%; background: var(--bg); }
.sheet .menu { display: grid; gap: 8px; }
.sheet .menu .btn { padding: 14px; text-align: left; font-size: 16px; }
.detail-img { width: 100%; max-height: 40dvh; object-fit: contain; background: var(--bg); border-radius: 12px; padding: 8px; }
.detail-actions { display: grid; gap: 8px; margin-top: 12px; }

/* ---------- обрезка ---------- */
.crop { position: fixed; inset: 0; z-index: 50; background: #111; color: #fff; display: flex; flex-direction: column; }
.crop-top { display: flex; align-items: center; justify-content: space-between; padding: 10px 8px; }
.crop-top .btn.ghost { color: #fff; }
.crop-title { font-weight: 600; }
.crop-stage { position: relative; flex: 1; overflow: hidden; touch-action: none; }
.crop-stage canvas { position: absolute; left: 0; top: 0; }
.crop-box { position: absolute; border: 2px solid #fff; box-shadow: 0 0 0 9999px rgba(0,0,0,.55); }
.crop-box .h { position: absolute; width: 28px; height: 28px; background: #fff; border-radius: 50%; border: 3px solid var(--accent); }
.crop-box .nw { left: -14px; top: -14px; } .crop-box .ne { right: -14px; top: -14px; }
.crop-box .sw { left: -14px; bottom: -14px; } .crop-box .se { right: -14px; bottom: -14px; }
.crop-bottom { padding: 10px 16px calc(14px + var(--safe-b)); }

.toast { position: fixed; left: 50%; bottom: calc(var(--tabbar) + var(--safe-b) + 90px); transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 999px; font-size: 14px; z-index: 60; max-width: 90vw; text-align: center; }
