/* ---------- Шрифт (локальный, работает без интернета) ---------- */
@font-face {
  font-family: Inter;
  src: url(../fonts/inter.woff2) format('woff2');
  font-weight: 100 900;
  font-display: swap;
}

/* ---------- Токены ---------- */
:root {
  --r-lg: 12px; --r-md: 8px; --r-sm: 6px;
  --ease: cubic-bezier(.2, .8, .2, 1); --spring: cubic-bezier(.34, 1.4, .5, 1);
  --font: Inter, system-ui, -apple-system, 'Segoe UI', sans-serif;
  --side-w: 244px; --viewer-w: 430px;
  --button-accent-rgb: 255 166 87; --button-accent: rgb(var(--button-accent-rgb)); --on-button-accent: #201207;
}
[data-theme='dark'] {
  --bg: #0b0b0b; --panel: #121212; --card: #181818; --card-2: #222222; --line: #2c2c2c; --line-2: #414141;
  --fg: #f4f4f4; --fg-2: #c8c8c8; --fg-3: #a3a3a3; --inv: #0b0b0b;
  --accent-rgb: var(--button-accent-rgb); --accent: var(--button-accent); --on-accent: var(--on-button-accent);
  --copper: #b57958;
  --danger: #ffa0b7; --danger-fill: #a23257; --ok: #79dfa8; --warn: #f3c577;
  --shadow: 0 1px 0 rgba(255,255,255,.03) inset, 0 20px 40px -24px rgba(0,0,0,.8);
  --glow: 0 0 0 1px rgb(var(--accent-rgb) / .35), 0 0 20px -8px rgb(var(--accent-rgb) / .30);
  color-scheme: dark;
}
[data-theme='light'] {
  --bg: #eeeeee; --panel: #f7f7f7; --card: #fff; --card-2: #f1f1f1; --line: #dedede; --line-2: #c6c6c6;
  --fg: #181818; --fg-2: #454545; --fg-3: #626262; --inv: #fff;
  --accent-rgb: 164 71 10; --accent: rgb(var(--accent-rgb)); --on-accent: #fff;
  --copper: #8e563b;
  --danger: #a6254d; --danger-fill: #a6254d; --ok: #176b45; --warn: #805211;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 18px 36px -24px rgba(0,0,0,.25);
  --glow: 0 0 0 1px rgb(var(--accent-rgb) / .4), 0 0 20px -8px rgb(var(--accent-rgb) / .25);
  color-scheme: light;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  font: 14px/1.45 var(--font); color: var(--fg); background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
[data-theme='dark'] body {
  background-image: radial-gradient(ellipse 90% 75% at 50% 100%, rgb(var(--accent-rgb) / .15), transparent 82%);
  background-attachment: fixed;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; }
a { color: inherit; }
.label { font-size: 11px; font-weight: 650; letter-spacing: .09em; text-transform: uppercase; color: var(--fg-3); }
.ic { width: 18px; height: 18px; flex: none; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow); }
::selection { background: var(--accent); color: var(--on-accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
input::placeholder { color: var(--fg-3); }
/* Без стрелочек у числовых полей */
input[type=number]::-webkit-outer-spin-button, input[type=number]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
input[type=number] { -moz-appearance: textfield; appearance: textfield; }

/* ---------- Каркас ---------- */
.app:has(.viewer-body[hidden]) { grid-template-columns: var(--side-w) minmax(0, 1fr); }
.app:has(.viewer-body[hidden]) .title-wrap { padding-right: 38px; }
.app { display: grid; grid-template-columns: var(--side-w) minmax(0, 1fr) var(--viewer-w); gap: 20px; padding: 20px; min-height: 100vh; align-items: start; }

/* ---------- Сайдбар ---------- */
.side { position: sticky; top: 20px; height: calc(100vh - 40px); display: flex; flex-direction: column; gap: 10px; padding: 18px 14px 14px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--r-lg); }
.brand { display: flex; align-items: center; gap: 10px; padding: 2px 6px 14px; border-bottom: 1px solid var(--line); margin-bottom: 4px; font-size: 19px; font-weight: 730; letter-spacing: -.035em; }
.brand img { display: block; flex: none; }
.side-label { padding: 4px 6px 0; }
.build-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; display: flex; flex-direction: column; gap: 3px; min-height: 80px; scrollbar-width: thin; }
.build-item { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 2px 8px; padding: 9px 10px; border-radius: var(--r-md); cursor: pointer; border: 1px solid transparent; transition: background .2s, border-color .2s; position: relative; }
.build-item:hover { background: var(--card-2); }
.build-item.active { background: var(--card-2); border-color: var(--line-2); }
.build-item.active::before { content: ''; position: absolute; left: -1px; top: 10px; bottom: 10px; width: 2px; border-radius: 2px; background: var(--accent); }
.build-item .bn { font-weight: 550; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.build-item .bs { font: 11px var(--font); color: var(--fg-3); grid-column: 1 / -1; }
.build-item .bc { font: 11px var(--font); color: var(--fg-3); }
.build-item input { width: 100%; background: var(--bg); border: 1px solid var(--accent); border-radius: var(--r-sm); padding: 2px 6px; outline: 0; }
.side-actions { display: flex; flex-direction: column; gap: 3px; padding-top: 10px; border-top: 1px solid var(--line); }
.side-btn { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: var(--r-md); color: var(--fg-2); transition: background .2s, color .2s; text-align: left; }
.web-home { margin-left: auto; flex: none; text-decoration: none; }
.web-home:hover { background: var(--card-2); }
.web-storage { color: var(--fg-3); margin: 0 6px; font-size: .875rem; }
.side-btn:hover { background: var(--card-2); color: var(--fg); }
.side-btn.primary { background: var(--button-accent); color: var(--on-button-accent); font-weight: 600; margin-bottom: 4px; }
.side-btn.danger:hover { color: var(--danger); }
.side-btn .chev { margin-left: auto; width: 14px; height: 14px; opacity: .6; }
.currency-field { position: relative; margin-top: 6px; }
.currency-icon { display: flex; }
.currency-field select { appearance: none; position: absolute; inset: 0; width: 100%; border: 0; border-radius: inherit; background: transparent; color: transparent; cursor: pointer; }
.currency-value { margin-left: auto; padding-right: 18px; font: 11px var(--font); }
.currency-field option { background: var(--panel); color: var(--fg); }
.currency-field:focus-within { background: var(--card-2); }
#currencyChevron { position: absolute; right: 10px; display: flex; pointer-events: none; }
.side-foot { display: flex; align-items: center; justify-content: space-between; padding-top: 10px; border-top: 1px solid var(--line); }

.icon-btn { width: 32px; height: 32px; display: inline-grid; place-items: center; border-radius: var(--r-md); border: 1px solid var(--line-2); color: var(--fg-2); transition: color .2s, border-color .2s, background .2s, transform .2s var(--spring); }
.icon-btn:hover { color: var(--fg); border-color: var(--fg-3); }
.icon-btn:active { transform: scale(.92); }
.icon-btn.ghost { border-color: transparent; }
.icon-btn.ghost:hover { background: var(--card-2); }

/* Сегментированный переключатель */
.seg { display: inline-flex; padding: 2px; border-radius: var(--r-md); background: var(--bg); border: 1px solid var(--line-2); gap: 2px; }
.seg button { padding: 5px 10px; border-radius: var(--r-sm); color: var(--fg-3); font-size: 12px; font-weight: 600; transition: background .2s, color .2s; white-space: nowrap; }
.seg button:hover { color: var(--fg); }
.seg button.on { background: var(--fg); color: var(--inv); }
.seg.mini button { padding: 4px 9px; font-size: 11px; }

/* ---------- Шапка ---------- */
.main { min-width: 0; display: flex; flex-direction: column; gap: 16px; }
.head { display: flex; flex-direction: column; gap: 14px; }
.title-wrap { display: flex; align-items: center; gap: 8px; min-height: 52px; padding: 0 2px; }
.build-title, .title-input { flex: 1; min-width: 0; font: 720 clamp(29px, 3.3vw, 49px)/1.1 var(--font); letter-spacing: -.048em; }
.build-title { margin: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; cursor: text; border-radius: var(--r-sm); }
.title-wrap .icon-btn { flex: none; }
.title-input { background: transparent; border: 0; border-bottom: 2px solid var(--accent); outline: 0; padding: 6px 0; }

.summary { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(240px, 1fr); overflow: hidden; border-color: color-mix(in srgb, var(--copper) 38%, var(--line)); }
.sum-main { padding: 18px 20px 16px; display: flex; flex-direction: column; gap: 12px; border-right: 1px solid var(--line); min-width: 0; container-type: inline-size; }
.total-amount { color: var(--accent); font: 680 clamp(26px, 11cqi, 49px)/1.12 var(--font); letter-spacing: -.045em; overflow-wrap: anywhere; }
.dist { display: flex; gap: 2px; height: 6px; flex-wrap: nowrap; }
.dist i { flex: 1; height: 6px; border-radius: 1px; background: var(--line); max-width: 12px; transition: background .5s var(--ease); }
.dist-legend { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 10.5px; color: var(--fg-3); min-height: 15px; }
.dist-legend span { display: inline-flex; align-items: center; gap: 5px; }
.dist-legend b { width: 7px; height: 7px; border-radius: 2px; display: inline-block; }
.sum-side { display: flex; flex-direction: column; }
.stat { display: flex; flex-direction: column; gap: 4px; padding: 13px 18px; border-bottom: 1px solid var(--line); }
.stat:last-child { border-bottom: 0; }
.stat.row { flex-direction: row; align-items: center; justify-content: space-between; flex: 1; }
.stat-val { font: 600 18px var(--font); letter-spacing: -.02em; }
.stat-sub { font: 11.5px var(--font); color: var(--fg-3); }
.stat-sub.over { color: var(--danger); }
.stat-sub.under { color: var(--ok); }
.budget-field { display: flex; align-items: baseline; gap: 6px; }
.budget-field input { width: 100%; font: 600 18px var(--font); background: transparent; border: 0; outline: 0; padding: 0; letter-spacing: -.02em; border-bottom: 1px dashed transparent; transition: border-color .2s; }
.budget-field input:hover, .budget-field input:focus { border-bottom-color: var(--fg-3); }
.budget-field .cur { font: 600 16px var(--font); color: var(--fg-3); }
.meter { display: block; height: 3px; border-radius: 3px; background: var(--line); overflow: hidden; margin-top: 4px; }
.meter i { display: block; height: 100%; width: 0; background: var(--fg); border-radius: 3px; transition: width .6s var(--ease), background .3s; }
.meter.over i { background: var(--danger); }
.meter.ok i { background: var(--ok); }
.parts-count { font-size: 12px; color: var(--fg-2); }
.chip-btn { display: inline-flex; align-items: center; gap: 6px; padding: 6px 10px; border-radius: var(--r-sm); border: 1px solid var(--line-2); font-size: 12px; color: var(--fg-2); transition: all .2s; }
.chip-btn:hover { color: var(--fg); border-color: var(--fg-3); }
.chip-btn .ic { width: 14px; height: 14px; }
.chip-btn.busy .ic { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Строка добавления (composer) ---------- */
.addbar { position: sticky; top: 12px; z-index: 30; }
.addbar::before { content: ''; position: absolute; inset: -12px -6px -6px; background: linear-gradient(var(--bg) 70%, transparent); z-index: -1; pointer-events: none; }
.composer { background: var(--card); border: 1px solid var(--line-2); border-radius: var(--r-lg); box-shadow: var(--shadow); transition: border-color .25s, box-shadow .25s; }
.composer:focus-within { border-color: var(--fg-3); }
.composer.open { box-shadow: var(--glow); border-color: rgb(var(--accent-rgb) / .6); }
.cmp-row { display: flex; align-items: center; gap: 8px; padding: 8px; }
.cmp-cat { display: inline-flex; align-items: center; gap: 7px; padding: 0 10px; height: 38px; border-radius: var(--r-md); background: var(--card-2); border: 1px solid var(--line); font-size: 13px; font-weight: 550; white-space: nowrap; transition: border-color .2s; }
.cmp-cat:hover { border-color: var(--fg-3); }
.cmp-cat .chev { width: 14px; height: 14px; opacity: .5; }
.cmp-cat .auto { font: 10px var(--font); color: var(--fg-3); text-transform: uppercase; letter-spacing: .08em; }
.cmp-src { flex: 1; display: flex; align-items: center; gap: 8px; min-width: 0; height: 38px; padding: 0 10px; border-radius: var(--r-md); }
.cmp-src .fav { width: 18px; height: 18px; }
.cmp-src input { flex: 1; min-width: 0; height: 100%; background: transparent; border: 0; outline: 0; font-size: 14.5px; }
.cmp-go { height: 38px; padding: 0 16px; border-radius: var(--r-md); background: var(--button-accent); color: var(--on-button-accent); font-weight: 650; display: inline-flex; align-items: center; gap: 6px; transition: box-shadow .2s, transform .2s var(--spring); }
.side-btn.primary:hover, .cmp-go:hover { box-shadow: 0 0 0 2px rgb(var(--accent-rgb) / .4); }
.cmp-go:active { transform: scale(.95); }
.cmp-go .ic { width: 16px; height: 16px; }
.cmp-body { display: grid; grid-template-rows: 0fr; transition: grid-template-rows .35s var(--ease); }
.composer.open .cmp-body { grid-template-rows: 1fr; }
.cmp-inner { overflow: hidden; min-height: 0; }
.cmp-fields { padding: 4px 12px 12px; display: grid; grid-template-columns: minmax(0, 1fr) 150px; gap: 10px; border-top: 1px solid var(--line); padding-top: 12px; margin: 0 8px; }
.composer.open .cmp-inner { overflow: visible; }
.cmp-status { grid-column: 1 / -1; display: flex; align-items: center; gap: 8px; font: 11.5px var(--font); color: var(--fg-3); min-height: 16px; }
.cmp-status.loading::before { content: ''; width: 34px; height: 6px; border-radius: 3px; background: linear-gradient(90deg, var(--line-2) 0 30%, var(--accent) 50%, var(--line-2) 70% 100%); background-size: 300% 100%; animation: shimmer 1.1s linear infinite; }
.cmp-status.ok { color: var(--ok); }
.cmp-status.fail { color: var(--warn); }
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: -50% 0; } }
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field > span { font: 10.5px var(--font); letter-spacing: .1em; text-transform: uppercase; color: var(--fg-3); }
.field input { height: 38px; padding: 0 11px; border-radius: var(--r-md); background: var(--bg); border: 1px solid var(--line-2); outline: 0; transition: border-color .2s, box-shadow .2s; min-width: 0; }
.field input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgb(var(--accent-rgb) / .15); }
.field.price input { font-weight: 600; font-variant-numeric: tabular-nums; }
.field .with-suffix { position: relative; }
.field .with-suffix input { width: 100%; padding-right: 46px; }
.field .with-suffix em { position: absolute; right: 11px; top: 50%; transform: translateY(-50%); font: normal 13px var(--font); color: var(--fg-3); pointer-events: none; }
.field.wide { grid-column: 1 / -1; }
.field.invalid input { border-color: var(--danger); animation: shake .35s; }
@keyframes shake { 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }
.cmp-specs { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 10px 14px; align-items: flex-end; }
.cmp-specs:empty { display: none; }
.cmp-specs .field input { width: 110px; }
.cmp-specs .seg { height: 38px; align-items: stretch; }
.cmp-specs .seg button { padding: 0 12px; }
.cmp-foot { grid-column: 1 / -1; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.cmp-foot .hint { font: 11px var(--font); color: var(--fg-3); margin-left: auto; }
.cmp-foot .hint kbd { font: inherit; padding: 1px 5px; border: 1px solid var(--line-2); border-radius: 4px; color: var(--fg-2); }
.qty { display: inline-flex; align-items: center; border: 1px solid var(--line-2); border-radius: var(--r-md); height: 32px; }
.qty button { width: 28px; height: 100%; display: grid; place-items: center; color: var(--fg-2); }
.qty button:hover { color: var(--fg); }
.qty button .ic { width: 14px; height: 14px; }
.qty input, .qty span { width: 30px; text-align: center; font: 600 13px var(--font); background: transparent; border: 0; outline: 0; padding: 0; }
.btn { height: 34px; padding: 0 14px; border-radius: var(--r-md); border: 1px solid var(--line-2); font-weight: 600; font-size: 13px; transition: all .2s; display: inline-flex; align-items: center; gap: 6px; }
.btn:hover { border-color: var(--fg-3); }
.btn.solid { background: var(--fg); color: var(--inv); border-color: var(--fg); }
.btn.solid:hover { background: var(--button-accent); border-color: var(--button-accent); color: var(--on-button-accent); }

/* ---------- Категории ---------- */
.cats { display: grid; grid-template-columns: repeat(auto-fill, minmax(420px, 1fr)); gap: 14px; align-items: start; }
.cat { padding: 0; overflow: visible; transition: border-color .3s, box-shadow .3s; scroll-margin-top: 110px; }
.cat.flash { animation: catflash 1s var(--ease); }
@keyframes catflash { 0% { box-shadow: var(--glow); border-color: var(--accent); } 100% { box-shadow: var(--shadow); } }
.cat-head { display: flex; align-items: center; gap: 12px; padding: 12px 12px 12px 14px; }
.cat-ic { width: 40px; height: 40px; border-radius: var(--r-md); display: grid; place-items: center; position: relative; color: var(--fg-2); flex: none; }
.cat-ic::before { content: ''; position: absolute; inset: 0; border-radius: inherit; border: 1px solid var(--line-2); transition: border-color .3s; }
.cat.filled .cat-ic { color: var(--fg); background: var(--card-2); }
.cat-ic .ic { width: 21px; height: 21px; }
.cat-title { min-width: 0; flex: 1; }
.cat-title h3 { margin: 0; font-size: 15px; font-weight: 650; letter-spacing: -.01em; }
.cat-title p { margin: 1px 0 0; font: 11.5px var(--font); color: var(--fg-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cat-sum { font: 600 14px var(--font); white-space: nowrap; }
.cat-sum.zero { color: var(--fg-3); }
.cat-add { width: 32px; height: 32px; border-radius: var(--r-md); display: grid; place-items: center; border: 1px solid var(--line-2); color: var(--fg-2); transition: all .2s var(--spring); }
.cat-add:hover { background: var(--fg); color: var(--inv); border-color: var(--fg); transform: rotate(90deg); }
.cat.adding .cat-add { background: var(--button-accent); color: var(--on-button-accent); border-color: var(--button-accent); transform: rotate(45deg); }
.cat-body { border-top: 1px solid var(--line); }
.cat-body:empty { display: none; }
.cat-empty { padding: 14px 16px; font: 12px var(--font); color: var(--fg-3); display: flex; align-items: center; gap: 10px; }
.cat-empty::before { content: ''; width: 24px; height: 2px; border-radius: 2px; background: var(--line-2); }
.cat .composer { margin: 10px; box-shadow: none; }
.cat-wide { grid-column: 1 / -1; }

/* ---------- Позиции ---------- */
.items { list-style: none; margin: 0; padding: 4px; }
.item { display: grid; grid-template-columns: 30px minmax(0, 1fr) auto auto; align-items: center; gap: 4px 12px; padding: 9px 10px; border-radius: var(--r-md); position: relative; transition: background .2s, opacity .3s; }
.item:hover { background: var(--card-2); }
.item + .item::before { content: ''; position: absolute; left: 52px; right: 10px; top: 0; border-top: 1px dashed var(--line); }
.item:hover::before, .item:hover + .item::before { opacity: 0; }
.item.enter { animation: itemIn .55s var(--spring); }
@keyframes itemIn { from { opacity: 0; transform: translateY(-6px) scale(.98); background: rgb(var(--accent-rgb) / .12); } }
.item.leaving { animation: itemOut .3s var(--ease) forwards; }
@keyframes itemOut { to { opacity: 0; transform: translateX(16px); } }
.item.is-bought .item-name { color: var(--fg-2); }
.fav { width: 30px; height: 30px; border-radius: var(--r-sm); background: var(--bg); border: 1px solid var(--line); display: grid; place-items: center; overflow: hidden; flex: none; font: 700 12px var(--font); color: var(--fg-2); text-transform: uppercase; }
.fav img { width: 18px; height: 18px; object-fit: contain; }
.cmp-src .fav { width: 22px; height: 22px; border-radius: 5px; }
.cmp-src .fav img { width: 14px; height: 14px; }
.cmp-src .fav:empty { display: none; }
.item-main { min-width: 0; }
.item-name { display: block; font-weight: 550; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-decoration: none; }
a.item-name:hover { color: var(--accent); }
.item-meta { display: flex; align-items: center; gap: 6px; margin-top: 3px; flex-wrap: wrap; font: 11px var(--font); color: var(--fg-3); }
.tag { padding: 1px 6px; border-radius: 4px; border: 1px solid var(--line-2); color: var(--fg-2); font: 10.5px var(--font); white-space: nowrap; }
.tag.cond { cursor: pointer; transition: all .2s; background: none; }
.tag.cond.new { border-style: dashed; color: var(--fg-3); }
.tag.cond:hover { border-color: var(--fg-3); }
.tag.cond.used { color: var(--warn); border-color: rgba(255,176,32,.45); }
.tag.prev { border-style: dashed; }
.tag.prev.down { color: var(--ok); border-color: rgba(61,220,132,.4); }
.tag.prev.up { color: var(--accent); border-color: rgb(var(--accent-rgb) / .4); }
.item-price { text-align: right; white-space: nowrap; }
.item-price b { font: 600 14px var(--font); display: block; }
.item-price small { font: 11px var(--font); color: var(--fg-3); }
.item-price.changed b { animation: priceFlash 1.6s var(--ease); }
@keyframes priceFlash { 0%, 40% { color: var(--accent); } }
.item-side { display: flex; align-items: center; gap: 2px; }
.item-main { position: relative; }
.item-tools { position: absolute; right: -6px; top: 50%; transform: translate(6px, -50%); display: flex; gap: 2px; padding: 3px 3px 3px 28px; opacity: 0; pointer-events: none; transition: opacity .2s, transform .25s var(--ease);
  background: linear-gradient(90deg, transparent, var(--card-2) 26px); border-radius: var(--r-md); }
.item:hover .item-tools, .item:focus-within .item-tools { opacity: 1; pointer-events: auto; transform: translate(0, -50%); }
.item-tools .icon-btn { width: 28px; height: 28px; border: 0; color: var(--fg-3); }
.item-tools .icon-btn:hover { color: var(--fg); background: var(--line); }
.item-tools .icon-btn .ic { width: 16px; height: 16px; }
.item-tools .icon-btn[data-act=del]:hover { color: var(--danger); }
.check { width: 20px; height: 20px; border-radius: 50%; border: 1.5px solid var(--line-2); display: grid; place-items: center; color: transparent; transition: all .25s var(--spring); margin-right: 4px; }
.check .ic { width: 12px; height: 12px; stroke-width: 3; }
.check:hover { border-color: var(--ok); }
.check.on { background: var(--ok); border-color: var(--ok); color: #000; transform: scale(1.05); }
.item .qty { height: 26px; }
.item .qty button { width: 22px; }
.item-edit { padding: 4px; }
.item-edit .composer { margin: 0; }

/* ---------- 3D-панель ---------- */
.viewer { position: sticky; top: 20px; height: calc(100vh - 40px); display: flex; flex-direction: column; overflow: hidden; background: var(--panel); }
.viewer:has(.viewer-body[hidden]) { position: fixed; top: 20px; right: 20px; z-index: 2; height: auto; }
.viewer:has(.viewer-body[hidden]) .viewer-head { padding: 0; }
.viewer:has(.viewer-body[hidden]) .viewer-head .label { display: none; }
.viewer-head { display: flex; align-items: center; gap: 8px; padding: 8px 10px 8px 16px; }
.viewer-head .label { margin-right: auto; }
.viewer-head .icon-btn { width: 28px; height: 28px; }
.viewer-body { display: flex; flex: 1; flex-direction: column; min-height: 0; }
.viewer-count { font-size: 12px; color: var(--fg-2); }
.viewer-count b { color: var(--accent); font-weight: 600; }
.viewer-chips { display: flex; flex-wrap: wrap; gap: 5px; padding: 4px 16px 8px; }
.viewer-chips span { font: 10px var(--font); padding: 2px 6px; border-radius: 4px; border: 1px solid var(--line-2); color: var(--fg-3); transition: all .4s var(--ease); letter-spacing: .05em; }
.viewer-chips span.on { color: var(--fg); background: var(--card-2); border-color: var(--line-2); }
.viewer-stage { flex: 1; position: relative; min-height: 0; cursor: grab; touch-action: pan-y; }
.viewer-stage.drag { cursor: grabbing; }
.viewer-stage canvas { display: block; width: 100% !important; height: 100% !important; }
.viewer-stage::after { content: ''; position: absolute; inset: 0; pointer-events: none; background: radial-gradient(ellipse at 50% 105%, rgb(127 127 127 / .10), transparent 64%); }
.viewer-msg { position: absolute; inset: 0; display: grid; place-items: center; padding: 30px; text-align: center; color: var(--fg-3); font-size: 12px; }
.viewer-ctrl { display: flex; align-items: center; gap: 10px; padding: 8px 14px 14px; }
.viewer-ctrl input[type=range] { flex: 1; -webkit-appearance: none; appearance: none; height: 22px; background: transparent; cursor: ew-resize; }
.viewer-ctrl input[type=range]::-webkit-slider-runnable-track { height: 4px; border-radius: 2px; background: var(--line-2); }
.viewer-ctrl input[type=range]::-moz-range-track { height: 4px; border-radius: 2px; background: var(--line-2); }
.viewer-ctrl input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 16px; height: 16px; border-radius: 50%; background: var(--fg); border: 3px solid var(--panel); box-shadow: 0 0 0 1px var(--fg-3); margin-top: -6px; transition: transform .2s; }
.viewer-ctrl input[type=range]::-moz-range-thumb { width: 12px; height: 12px; border-radius: 50%; background: var(--fg); border: 3px solid var(--panel); box-shadow: 0 0 0 1px var(--fg-3); }
.viewer-ctrl input[type=range]:active::-webkit-slider-thumb { transform: scale(1.2); background: var(--accent); }

/* ---------- Меню, тосты ---------- */
.menu { position: fixed; z-index: 100; min-width: 210px; padding: 5px; background: var(--card); border: 1px solid var(--line-2); border-radius: var(--r-lg); box-shadow: 0 24px 48px -12px rgba(0,0,0,.55); animation: menuIn .18s var(--ease); max-height: 70vh; overflow-y: auto; }
@keyframes menuIn { from { opacity: 0; transform: translateY(-4px) scale(.98); } }
.menu button { display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 10px; border-radius: var(--r-md); text-align: left; color: var(--fg-2); transition: background .15s, color .15s; }
.menu button:hover, .menu button:focus-visible { background: var(--card-2); color: var(--fg); outline: 0; }
.menu button.cur { color: var(--fg); }
.menu button.cur::after { content: ''; margin-left: auto; width: 6px; height: 6px; border-radius: 50%; background: var(--accent); }
.menu button small { display: block; font: 11px var(--font); color: var(--fg-3); }
.menu hr { border: 0; border-top: 1px solid var(--line); margin: 4px 6px; }
.menu .ic { width: 17px; height: 17px; }

.toasts { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; }
.toast { pointer-events: auto; display: flex; align-items: center; gap: 12px; padding: 10px 12px 10px 16px; border-radius: var(--r-lg); background: var(--fg); color: var(--inv); font-weight: 550; box-shadow: 0 16px 40px -12px rgba(0,0,0,.5); animation: toastIn .35s var(--spring); max-width: min(560px, 92vw); }
.toast.out { animation: toastOut .25s var(--ease) forwards; }
.toast.err { background: var(--danger-fill); color: #fff; }
.toast button { font: 600 12px var(--font); text-transform: uppercase; letter-spacing: .06em; padding: 5px 9px; border-radius: var(--r-sm); background: rgba(127,127,127,.18); }
.toast button:hover { background: var(--button-accent); color: var(--on-button-accent); }
@keyframes toastIn { from { opacity: 0; transform: translateY(14px) scale(.96); } }
@keyframes toastOut { to { opacity: 0; transform: translateY(10px); } }

.flyer { position: fixed; z-index: 150; pointer-events: none; display: flex; align-items: center; gap: 8px; padding: 7px 12px; border-radius: var(--r-md); background: var(--fg); color: var(--inv); font-weight: 600; font-size: 13px; white-space: nowrap; max-width: 320px; overflow: hidden; text-overflow: ellipsis; box-shadow: var(--glow); }
.flyer .ic { width: 16px; height: 16px; }

.tip { font-size: 11.5px; color: var(--fg-3); text-align: center; margin: 4px 0 24px; }

.fatal { position: fixed; left: 12px; bottom: 12px; z-index: 999; max-width: 70vw; white-space: pre-wrap; font: 12px var(--font); background: #2a0d0b; color: #ffb4ae; border: 1px solid var(--danger); border-radius: var(--r-md); padding: 10px 12px; margin: 0; }

.total-amount, .stat-val, .budget-field input, .cat-sum, .item-price, .item-price b, .item-price small, .build-item .bs, .qty input, .qty span { font-variant-numeric: tabular-nums; }

/* ---------- Полупрозрачные панели ---------- */
@media not (prefers-reduced-transparency: reduce) {
  @supports ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
    .side, .viewer, .summary {
      background: linear-gradient(155deg, rgb(255 255 255 / .055), transparent 55%),
        color-mix(in srgb, var(--panel) 66%, transparent);
      -webkit-backdrop-filter: blur(16px);
      backdrop-filter: blur(16px);
    }
    .cat {
      background: color-mix(in srgb, var(--card) 85%, transparent);
    }
    .addbar::before { content: none; }
    .addbar > .composer, .menu {
      background: color-mix(in srgb, var(--card) 88%, transparent);
      -webkit-backdrop-filter: blur(14px);
      backdrop-filter: blur(14px);
    }
  }
}

/* ---------- Адаптивность ---------- */
@media (max-width: 1279px) {
  .app { grid-template-columns: var(--side-w) minmax(0, 1fr); }
  .app:has(.viewer-body[hidden]) .title-wrap { padding-right: 2px; }
  .viewer { display: none; }            /* на узких экранах 3D-макет убираем */
}
@media (max-width: 1000px) {
  .cats { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 860px) {
  .app, .app:has(.viewer-body[hidden]) { grid-template-columns: 1fr; padding: 12px; gap: 12px; }
  .side { position: static; height: auto; }
  .build-list { max-height: 180px; }
  .side-actions { flex-direction: row; flex-wrap: wrap; }
  .side-btn.primary { margin: 0; }
  .summary { grid-template-columns: 1fr; }
  .sum-main { border-right: 0; border-bottom: 1px solid var(--line); }
  .cmp-fields { grid-template-columns: 1fr; }
  .item { grid-template-columns: 30px minmax(0, 1fr) auto; }
  .item-side { grid-column: 2 / -1; justify-content: flex-end; }
  .item-tools { position: static; transform: none; opacity: 1; pointer-events: auto; background: none; padding: 0; margin-top: 4px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
