/* ============================================================
   СОБЕРИ ДОМ — стили 3D-конструктора
   ============================================================ */

/* ---- Раскладка раздела ---- */
.ctor-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(320px, 0.85fr);
  gap: 28px;
  align-items: start;
}
@media (max-width: 980px) {
  .ctor-layout { grid-template-columns: 1fr; }
}

/* ---- Контролы геометрии ---- */
.ctl-card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 16px 18px;
  display: flex;
  flex-wrap: wrap;
  gap: 14px 22px;
  align-items: flex-end;
}
.ctl-group { display: flex; flex-direction: column; gap: 6px; }
.ctl-group > label, .ctl-label {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-soft);
}
.arch-seg { display: flex; gap: 4px; background: var(--bg-soft); border-radius: 10px; padding: 4px; }
.arch-btn, .roof-btn, .sdir-btn {
  border: 0; background: transparent; border-radius: 8px;
  padding: 8px 12px; font: 600 13px/1.2 var(--font-text);
  color: var(--ink-soft); cursor: pointer; transition: background .15s, color .15s, box-shadow .15s;
}
.arch-btn:hover, .roof-btn:hover, .sdir-btn:hover { color: var(--ink); }
/* выбранный вариант подсвечивается акцентным цветом — сразу видно, что выбрано */
.arch-btn.active, .roof-btn.active, .sdir-btn.active {
  background: var(--accent); color: #fff;
  box-shadow: 0 2px 8px color-mix(in oklab, var(--accent) 38%, transparent);
}
.dim-row { display: flex; gap: 10px; flex-wrap: wrap; }
.dim-field { display: flex; flex-direction: column; gap: 4px; }
.dim-field span { font-size: 11px; color: var(--ink-soft); }
.dim-field input {
  width: 74px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px;
  font: 600 14px/1 var(--font-text); color: var(--ink); background: #fff;
}
.dim-field input:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }
.win-row { display: flex; gap: 10px; flex-wrap: wrap; }
.win-step { display: flex; align-items: center; gap: 6px; }
.win-step .ws-label { font-size: 11px; color: var(--ink-soft); min-width: 34px; }
.win-step button {
  width: 26px; height: 26px; border-radius: 7px; border: 1px solid var(--line);
  background: #fff; font: 700 14px/1 var(--font-text); color: var(--ink); cursor: pointer;
}
.win-step button:hover { border-color: var(--accent); color: var(--accent); }
.win-step output { font: 700 14px/1 var(--font-text); min-width: 14px; text-align: center; }

/* ---- Сцена ---- */
.scene-wrap { position: relative; margin-top: 16px; }
#scene {
  position: relative;
  height: clamp(360px, 52vh, 560px);
  border-radius: 20px;
  background: linear-gradient(180deg, #7FB8E3 0%, #A9D0EC 38%, #DCEAE6 64%, #CCDFC2 82%, #BCD3AE 100%);
  border: 1px solid var(--line);
  overflow: hidden;
  perspective: 1200px;
  touch-action: none;
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
}
#scene.night {
  background: linear-gradient(180deg, #0D1524 0%, #161F33 52%, #1F2838 78%, #232B38 100%);
}
#scene:active { cursor: grabbing; }
#pivot {
  position: absolute; left: 50%; top: 50%;
  transform-style: preserve-3d;
}
#house { position: absolute; transform-style: preserve-3d; }

.face {
  position: absolute;
  transform-origin: 0 0;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
}
.face .skin {
  position: absolute; inset: 0;
  background-repeat: repeat;
  background-color: #C9C2B4;
}
.shade { position: absolute; inset: 0; pointer-events: none; }
.shade-front  { background: linear-gradient(180deg, rgba(255,255,255,.10), rgba(0,0,0,.04)); }
.shade-back   { background: rgba(0,0,0,.30); }
.shade-left   { background: rgba(0,0,0,.34); }
.shade-right  { background: rgba(0,0,0,.14); }
.shade-roof-front { background: linear-gradient(180deg, rgba(255,255,255,.20), rgba(255,255,255,.02) 45%, rgba(0,0,0,.12)); }
.shade-roof-back  { background: rgba(0,0,0,.30); }

.f-gable { clip-path: polygon(0 100%, 50% 0, 100% 100%); }
.f-roof .skin { box-shadow: inset 0 -3px 0 rgba(0,0,0,.25); }
.f-ridge {
  position: absolute; height: 14px; border-radius: 3px;
  transform-origin: 0 0;
  background: #3A3530;
  box-shadow: 0 0 6px rgba(0,0,0,.2);
}
.f-shadow {
  position: absolute;
  transform-origin: 0 0;
  background: radial-gradient(ellipse at center, rgba(20,22,25,.35) 0%, rgba(20,22,25,0) 68%);
  pointer-events: none;
}

.f-plinth, .f-plinth-band {
  background-repeat: repeat;
  background-color: #8B8884;
}
.f-plinth-band {
  box-shadow: inset 0 3px 5px rgba(0,0,0,.3), inset 0 -2px 3px rgba(0,0,0,.2);
}
.f-plinth {
  position: absolute; left: 0; right: 0; bottom: 0;
  box-shadow: 0 -1px 3px rgba(0,0,0,.2);
  z-index: 0;
}
.f-wall::after {
  content: ""; position: absolute; left: 0; right: 0; top: 0; height: 9%;
  background: linear-gradient(180deg, rgba(0,0,0,.28), transparent);
  pointer-events: none;
}
.f-win {
  position: absolute;
  background: #F2F3F0;
  border: 1px solid rgba(0, 0, 0, .24);
  box-sizing: border-box;
  padding: 5%;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.12), 0 2px 5px rgba(0,0,0,.16);
}
.win-glass {
  position: absolute; inset: 8%;
  background: linear-gradient(135deg, #AEC4D1 0%, #5E7888 52%, #93ADBC 100%);
}
.win-bar {
  position: absolute; left: 47%; top: 8%; bottom: 8%; width: 5%;
  background: linear-gradient(90deg, rgba(255,255,255,.5), rgba(0,0,0,.15));
}
.win-bar-v {
  position: absolute; top: 47%; left: 8%; right: 8%; height: 5%;
  background: linear-gradient(180deg, rgba(255,255,255,.5), rgba(0,0,0,.15));
}
.f-door {
  position: absolute;
  background: #45322E;
  border: 1px solid rgba(0,0,0,.3);
  box-sizing: border-box;
  box-shadow: inset 0 0 0 3px rgba(255,255,255,.08), 0 2px 6px rgba(0,0,0,.25);
}
.door-glass {
  position: absolute; left: 32%; top: 12%; width: 36%; height: 22%;
  background: linear-gradient(135deg, #AEC4D1, #5E7888);
  border: 1px solid rgba(0,0,0,.25);
}
.gut-bar {
  height: 11px;
  border-radius: 6px 6px 7px 7px;
  background: linear-gradient(180deg, #7d6b62 0%, #51403a 45%, #2e221d 100%);
  box-shadow: 0 3px 6px rgba(0,0,0,.4), inset 0 1px 0 rgba(255,255,255,.35);
  z-index: 2;
}
.gut-pipe {
  position: absolute; top: 9px; bottom: 0; width: 8px;
  border-radius: 4px;
  background: linear-gradient(90deg, #2e221d, #6a554b 45%, #827066 55%, #2e221d);
  transform: translateZ(8px);
  box-shadow: 1px 1px 4px rgba(0,0,0,.4);
}
.gut-funnel {
  position: absolute; top: -7px; width: 13px; height: 16px;
  border-radius: 0 0 5px 5px;
  background: linear-gradient(180deg, #5a463d, #2e221d);
  transform: translateZ(7px);
  box-shadow: 1px 1px 3px rgba(0,0,0,.3), inset 0 1px 0 rgba(255,255,255,.2);
}
.f-soffit {
  backface-visibility: visible !important;
  -webkit-backface-visibility: visible !important;
  background-color: #F0F1EE;
  background-image: repeating-linear-gradient(90deg, rgba(0,0,0,.13) 0 2px, transparent 2px 13px);
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.10);
}
.snowguard {
  position: absolute; height: 9px;
  border-radius: 4px;
  background: linear-gradient(180deg, #E8E9EB, #8E9094 55%, #5A5C60);
  border: 1px solid rgba(0,0,0,.4);
  box-shadow: 0 3px 5px rgba(0,0,0,.5), inset 0 1px 0 rgba(255,255,255,.7);
  transform: translateZ(7px);
  z-index: 3;
}
.snowguard::after {
  content: ""; position: absolute; left: 0; right: 0; top: 3px; height: 2px;
  background: repeating-linear-gradient(90deg, rgba(0,0,0,.45) 0 3px, transparent 3px 10px);
}
.door-lamp {
  position: absolute; left: 112%; top: 4%;
  width: 7px; height: 11px;
  background: #D8D4C8;
  border: 1px solid rgba(0,0,0,.3);
  border-radius: 2px;
  transition: background .4s, box-shadow .4s;
}
.f-grass {
  position: absolute;
  background: radial-gradient(ellipse at center, #98BD6D 0%, #8CB161 42%, rgba(140,177,97,.55) 60%, rgba(140,177,97,0) 74%);
  pointer-events: none;
}

/* —— Небо: облака, луна, звёзды —— */
.sky { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.sky::before {
  content: ""; position: absolute; inset: 0;
  background-image:
    radial-gradient(1.5px 1.5px at 12% 22%, #fff, transparent),
    radial-gradient(1px 1px at 28% 9%, #fff, transparent),
    radial-gradient(1.5px 1.5px at 41% 30%, #fff, transparent),
    radial-gradient(1px 1px at 57% 14%, #fff, transparent),
    radial-gradient(1.5px 1.5px at 66% 26%, #fff, transparent),
    radial-gradient(1px 1px at 79% 8%, #fff, transparent),
    radial-gradient(1.5px 1.5px at 90% 19%, #fff, transparent),
    radial-gradient(1px 1px at 48% 5%, #fff, transparent);
  opacity: 0; transition: opacity .7s;
}
.night .sky::before { opacity: .9; }
.cloud {
  position: absolute; height: 26px; width: 120px;
  background: transparent;
  transition: opacity .7s;
  opacity: .62;
  filter: blur(1.5px) drop-shadow(0 8px 12px rgba(120,140,160,.18));
}
.cloud::before, .cloud::after { content: ""; position: absolute; border-radius: 50%;
  background: radial-gradient(ellipse at 42% 30%, rgba(255,255,255,.95), rgba(244,248,251,.75) 55%, rgba(226,233,239,.25) 85%, rgba(226,233,239,0));
}
.cloud::before { width: 100%; height: 100%; left: 0; top: 0;
  border-radius: 60px 60px 56px 56px / 44px 44px 40px 40px;
  box-shadow: 26px 8px 0 -4px rgba(244,247,250,.7), -24px 9px 0 -5px rgba(238,243,247,.6);
}
.cloud::after { width: 52px; height: 52px; left: 28px; top: -24px;
  box-shadow: 30px 8px 0 -8px rgba(246,249,251,.65); }
.c1 { left: 9%; top: 14%; }
.c2 { left: 54%; top: 7%; transform: scale(.72); opacity: .48; }
.c3 { left: 78%; top: 22%; transform: scale(1.25); opacity: .42; }
@media (prefers-reduced-motion: no-preference) {
  .cloud { animation: cloud-drift 46s ease-in-out infinite alternate; }
  .c2 { animation-duration: 64s; }
  .c3 { animation-duration: 38s; }
}
@keyframes cloud-drift { from { margin-left: 0; } to { margin-left: 46px; } }
.night .cloud { opacity: .07; }
.moon {
  position: absolute; right: 11%; top: 12%;
  width: 38px; height: 38px; border-radius: 50%;
  background: radial-gradient(circle at 38% 36%, #FBF6E2, #E8DFB8);
  box-shadow: 0 0 26px 6px rgba(244,239,217,.45);
  opacity: 0; transition: opacity .7s;
}
.night .moon { opacity: 1; }

/* —— Ночной режим: приглушаем дом, зажигаем окна —— */
.face .skin, .f-plinth, .f-door, .gut-bar, .gut-pipe, .gut-funnel,
.f-soffit, .f-ridge, .snowguard, .f-grass { transition: filter .7s; }
.night .face .skin, .night .f-plinth, .night .f-door,
.night .gut-bar, .night .gut-pipe, .night .gut-funnel,
.night .f-soffit, .night .f-ridge, .night .snowguard {
  filter: brightness(.38) saturate(.85);
}
.night .f-grass { filter: brightness(.3) saturate(.7); }
.night .f-shadow { opacity: .35; }
.win-glass, .door-glass { transition: background .7s, box-shadow .7s; }
.night .win-glass {
  background: linear-gradient(165deg, #FFE3A1 0%, #F2B65E 55%, #D89B45 100%);
  box-shadow: 0 0 16px 3px rgba(255,200,110,.5);
}
.night .door-glass {
  background: linear-gradient(180deg, #FFE3A1, #D89B45);
  box-shadow: 0 0 10px 2px rgba(255,200,110,.5);
}
.night .door-lamp {
  background: #FFE7A8;
  box-shadow: 0 0 16px 6px rgba(255,214,130,.55);
}

/* —— Переключатель день/ночь —— */
.scene-mode {
  position: absolute; top: 12px; right: 12px; z-index: 6;
  display: flex; gap: 3px;
  background: rgba(255,255,255,.82);
  border: 1px solid var(--line);
  border-radius: 99px; padding: 4px;
  backdrop-filter: blur(4px);
  transition: background .5s;
}
.mode-btn {
  border: 0; background: transparent; cursor: pointer;
  border-radius: 99px; padding: 6px 14px;
  font: 600 12.5px/1 var(--font-text); color: var(--ink-soft);
  transition: background .2s, color .2s;
}
.mode-btn.active { background: var(--graphite); color: #fff; }
.night .scene-mode { background: rgba(22,27,38,.7); border-color: rgba(255,255,255,.16); }
.night .mode-btn { color: rgba(255,255,255,.6); }
.night .mode-btn.active { background: var(--accent); color: #fff; }
.scene-zoom { position: absolute; left: 12px; top: 12px; z-index: 6; display: flex; gap: 3px;
  background: rgba(255,255,255,.82); border: 1px solid var(--line); border-radius: 99px; padding: 4px; backdrop-filter: blur(4px); transition: background .5s; }
.zoom-btn { border: 0; background: transparent; cursor: pointer; border-radius: 99px; width: 30px; height: 30px;
  font: 700 18px/1 var(--font-text); color: var(--ink-soft); display: flex; align-items: center; justify-content: center; transition: background .2s, color .2s; }
.zoom-btn:hover { background: var(--bg-soft); color: var(--ink); }
.zoom-btn:active { background: var(--accent); color: #fff; }
.night .scene-zoom { background: rgba(22,27,38,.7); border-color: rgba(255,255,255,.16); }
.night .zoom-btn { color: rgba(255,255,255,.7); }

/* зоны: подсветка при перетаскивании / кисти */
[data-zone].can-drop { outline: 2px dashed color-mix(in oklab, var(--accent) 55%, transparent); outline-offset: -2px; }
[data-zone].drop-hot { outline: 3px solid var(--accent); filter: brightness(1.06); }
body.brush-on #scene { cursor: crosshair; }

/* перетаскиваемые элементы дома (дверь, окна) */
.drag-part { cursor: grab; }
.drag-part:hover { outline: 2px solid color-mix(in oklab, var(--accent) 60%, transparent); outline-offset: 1px; }
.part-active { cursor: grabbing; outline: 2px solid var(--accent); z-index: 5; }

.drag-ghost {
  position: fixed; width: 58px; height: 58px;
  border-radius: 12px;
  transform: translate(-50%, -65%);
  pointer-events: none;
  z-index: 1200;
  border: 2px solid #fff;
  box-shadow: 0 10px 28px rgba(20,22,25,.35);
  opacity: .96;
}
.drag-ghost.ok { border-color: var(--accent); }
body.dragging { cursor: grabbing !important; user-select: none; -webkit-user-select: none; }
body.dragging .swatch { pointer-events: none; }

#scene-hint {
  position: absolute; left: 50%; bottom: 14px;
  transform: translateX(-50%) translateY(8px);
  background: rgba(28, 30, 33, .88); color: #fff;
  font: 500 13px/1.3 var(--font-text);
  padding: 8px 14px; border-radius: 99px;
  opacity: 0; pointer-events: none;
  transition: opacity .25s, transform .25s;
  max-width: 90%;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
#scene-hint.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* Редактор размеров окна/двери */
#part-editor {
  position: absolute; top: 12px; left: 12px; z-index: 6;
  width: 210px;
  background: rgba(255,255,255,.97);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 12px 30px rgba(20,22,25,.22);
  padding: 14px 14px 12px;
  display: none;
}
#part-editor.open { display: block; }
#part-editor h4 { margin: 0 0 10px; font: 700 14px/1 var(--font-text); }
#pe-close {
  position: absolute; top: 9px; right: 9px;
  width: 24px; height: 24px; border: 0; border-radius: 7px;
  background: var(--bg-soft); color: var(--ink-soft);
  cursor: pointer; font-size: 13px;
}
#pe-close:hover { background: var(--line); }
.pe-row { display: flex; gap: 8px; }
.pe-row label {
  flex: 1; display: flex; flex-direction: column; gap: 4px;
  font: 600 10.5px/1.2 var(--font-text); color: var(--ink-soft);
}
.pe-row input {
  width: 100%; padding: 7px 8px; border: 1px solid var(--line);
  border-radius: 8px; font: 600 14px/1 var(--font-text); color: var(--ink);
}
.pe-row input:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }
#pe-hint { margin: 9px 0 0; font: 400 11px/1.4 var(--font-text); color: var(--ink-soft); }

/* Редактор: створки, область применения, изделие */
#part-editor { width: 252px; }
.pe-label {
  display: block; margin: 10px 0 5px;
  font: 700 10px/1 var(--font-text); letter-spacing: .06em; text-transform: uppercase; color: var(--ink-soft);
}
.pe-seg { display: flex; gap: 4px; }
.pe-seg button {
  flex: 1; padding: 7px 4px; border: 1px solid var(--line); border-radius: 8px;
  background: #fff; font: 600 11.5px/1 var(--font-text); color: var(--ink); cursor: pointer;
}
.pe-seg button:hover { border-color: var(--accent); }
.pe-seg button.active { background: var(--accent); border-color: var(--accent); color: #fff; }
#pe-product {
  width: 100%; padding: 7px 8px; border: 1px solid var(--line); border-radius: 8px;
  font: 600 12px/1.2 var(--font-text); color: var(--ink); background: #fff;
}
.pe-add {
  display: flex; align-items: center; gap: 7px; margin-top: 9px;
  font: 700 12.5px/1.2 var(--font-text); color: var(--ink); cursor: pointer;
}
.pe-add input { width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer; }

/* Вертикальные импосты окна (створки) */
.win-mull {
  position: absolute; top: 6%; bottom: 6%; width: 6%;
  transform: translateX(-50%);
  background: linear-gradient(90deg, rgba(255,255,255,.55), rgba(0,0,0,.18));
}

/* Живая подпись применённого размера */
#pe-size {
  margin: 7px 0 0;
  font: 700 11.5px/1.2 var(--font-text);
  color: #1F8A5B;
}

/* Подсветка редактируемого элемента на доме */
.part-selected {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
  z-index: 3;
}

/* Дверь ПВХ — белый профиль со стеклом */
.f-door.door-pvh {
  border: 2px solid #C6CAC7;
  box-sizing: border-box;
}
.f-door.door-pvh .door-glass {
  position: absolute; left: 16%; right: 16%; top: 9%; height: 52%;
  background: linear-gradient(135deg, #AEC4D1 0%, #5E7888 52%, #93ADBC 100%);
  border: 2px solid rgba(255,255,255,.75);
  box-sizing: border-box;
}
.f-door.door-pvh::after {
  content: ""; position: absolute; left: 16%; right: 16%; top: 68%; height: 22%;
  background: linear-gradient(180deg, rgba(0,0,0,.06), rgba(0,0,0,.13));
  border: 1px solid rgba(0,0,0,.12);
}

.ctl-note {
  margin: 8px 0 0;
  font: 400 11.5px/1.45 var(--font-text);
  color: var(--ink-soft);
}

/* ---- Пристройки и доп. площади (стены/скаты с кнопками «+») ---- */
.ctl-extra { width: 100%; }
.extra-block + .extra-block { margin-top: 12px; }
.extra-bar { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 7px; }
.extra-name { font-size: 11px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--ink-soft); }
.btn-add {
  border: 1px solid var(--accent);
  background: color-mix(in oklab, var(--accent) 8%, #fff);
  color: var(--accent);
  border-radius: 8px; padding: 6px 12px;
  font: 700 12px/1 var(--font-text); cursor: pointer;
  transition: background .15s, color .15s;
}
.btn-add:hover { background: var(--accent); color: #fff; }
.extra-list { display: flex; flex-direction: column; gap: 6px; }
.extra-list:empty { display: none; }
.extra-row { display: flex; align-items: center; gap: 8px; }
.extra-in {
  width: 92px; padding: 7px 9px;
  border: 1px solid var(--line); border-radius: 8px;
  font: 600 14px/1 var(--font-text); color: var(--ink); background: #fff;
}
.extra-in:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }
.extra-unit { font-size: 12px; color: var(--ink-soft); }
.extra-del {
  width: 28px; height: 28px; margin-left: auto;
  border: 1px solid var(--line); border-radius: 7px;
  background: #fff; color: #B9BDC2; cursor: pointer; font-size: 12px; line-height: 1;
}
.extra-del:hover { background: #F6E4DA; color: #B3441E; border-color: #e7c3b2; }

.scene-tip {
  margin-top: 10px;
  font-size: 13px; color: var(--ink-soft);
  display: flex; align-items: center; gap: 8px;
}
.scene-tip::before {
  content: ""; width: 8px; height: 8px; border-radius: 50%;
  background: var(--accent); flex: none;
}

/* ---- Панель образцов ---- */
.palette {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 16px;
  overflow: hidden;
  position: sticky;
  top: 86px;
}
.pal-head {
  padding: 14px 18px 0;
}
.pal-head h3 { margin: 0 0 10px; font: 700 15px/1.2 var(--font-text); }
#pal-tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); padding: 0 12px; }
.pal-tab {
  border: 0; background: transparent; cursor: pointer;
  font: 600 13px/1 var(--font-text); color: var(--ink-soft);
  padding: 10px 12px 12px;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.pal-tab:hover { color: var(--ink); }
.pal-tab.active { color: var(--accent); border-bottom-color: var(--accent); }
#pal-body { padding: 6px 16px 16px; max-height: 520px; overflow-y: auto; }
.pal-cat {
  display: flex; align-items: baseline; gap: 8px;
  margin: 14px 0 8px;
}
.pal-cat span { font: 700 13px/1.2 var(--font-text); }
.pal-cat em { font: 400 11px/1.2 var(--font-text); color: var(--ink-soft); font-style: normal; }
.pal-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(62px, 1fr));
  gap: 8px;
}
.swatch {
  position: relative;
  border: 0; padding: 0; background: transparent;
  cursor: grab;
  display: flex; flex-direction: column; gap: 4px;
  text-align: left;
}
.swatch:active { cursor: grabbing; }
.sw-face {
  display: block; width: 100%; aspect-ratio: 1;
  border-radius: 10px;
  border: 1px solid rgba(20,22,25,.14);
  background-repeat: repeat;
  transition: transform .15s, box-shadow .15s;
}
.swatch:hover .sw-face { transform: translateY(-2px); box-shadow: 0 6px 14px rgba(20,22,25,.16); }
.swatch:focus-visible .sw-face { outline: 2px solid var(--accent); outline-offset: 2px; }
.swatch.selected .sw-face { outline: 3px solid var(--accent); outline-offset: -1px; }
.swatch.in-use .sw-face { box-shadow: inset 0 0 0 2px #fff, inset 0 0 0 4px rgba(20,22,25,.35); }
.sw-name {
  font: 500 10.5px/1.25 var(--font-text);
  color: var(--ink-soft);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden;
  min-height: 2.4em;
}
.sw-dot {
  position: absolute; top: 4px; right: 4px;
  min-width: 10px; height: 10px;
  border-radius: 99px;
  border: 1.5px solid #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,.25);
}
.sw-dot.in { background: #2FA45B; }
.sw-dot.ord {
  background: #9AA0A6;
  height: auto; min-width: 0;
  color: #fff; font: 700 8px/1 var(--font-text);
  padding: 2px 4px;
}

/* ---- Легенда ---- */
.legend-card {
  margin-top: 16px;
  background: #fff; border: 1px solid var(--line); border-radius: 16px;
  padding: 16px 18px;
}
.legend-card h3 { margin: 0 0 12px; font: 700 15px/1.2 var(--font-text); }
#legend { display: grid; gap: 8px; }
.lg-item {
  display: grid;
  grid-template-columns: 26px minmax(90px, 130px) 1fr auto;
  align-items: center; gap: 10px;
  font-size: 13px;
  padding: 4px 0;
  border-bottom: 1px dashed var(--line);
}
.lg-item:last-child { border-bottom: 0; }
.lg-thumb {
  width: 26px; height: 26px; border-radius: 7px;
  border: 1px solid rgba(20,22,25,.14);
  background-color: #ddd;
  flex: none;
}
.lg-zone { font-weight: 700; }
.lg-mat { color: var(--ink-soft); }

/* статусы наличия */
.st { display: inline-flex; align-items: center; gap: 5px; font: 600 12px/1 var(--font-text); white-space: nowrap; }
.st i { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.st-in { color: #1E7A43; }
.st-in i { background: #2FA45B; }
.st-ord { color: #6B7076; }
.st-ord i { background: #9AA0A6; }

/* ---- Похожие цвета в наличии ---- */
#alts {
  margin-top: 16px;
  background: color-mix(in oklab, var(--accent) 7%, #fff);
  border: 1px solid color-mix(in oklab, var(--accent) 30%, var(--line));
  border-radius: 16px;
  padding: 16px 18px;
  display: grid; gap: 14px;
}
.alt-head { font-size: 13.5px; margin-bottom: 8px; }
.alt-list { display: flex; flex-wrap: wrap; gap: 8px; }
.alt-btn {
  display: inline-flex; align-items: center; gap: 8px;
  border: 1px solid var(--line); border-radius: 10px;
  background: #fff; padding: 6px 10px;
  font: 500 12.5px/1.2 var(--font-text); color: var(--ink);
  cursor: pointer;
  transition: border-color .15s, box-shadow .15s;
}
.alt-btn:hover { border-color: var(--accent); box-shadow: 0 3px 10px rgba(20,22,25,.10); }
.alt-btn em { font-style: normal; color: var(--accent); font-weight: 700; }

/* ---- Смета ---- */
.estimate {
  margin-top: 28px;
  background: #fff; border: 1px solid var(--line); border-radius: 20px;
  overflow: hidden;
}
.est-head {
  display: flex; flex-wrap: wrap; align-items: baseline; gap: 8px 20px;
  padding: 22px 26px 4px;
}
.est-head h3 { margin: 0; font: 600 22px/1.2 var(--font-display); }
.est-total {
  margin-left: auto;
  font: 700 clamp(26px, 3.4vw, 38px)/1.1 var(--font-display);
  color: var(--accent);
  white-space: nowrap;
}
.est-note { padding: 0 26px; font-size: 13px; color: var(--ink-soft); }
.est-table-wrap { overflow-x: auto; padding: 10px 14px 6px; }
.estimate table { width: 100%; border-collapse: collapse; min-width: 680px; table-layout: fixed; }
.estimate .col-name { width: auto; }
.estimate .col-qty { width: 124px; }
.estimate .col-price { width: 104px; }
.estimate .col-sum { width: 116px; }
.estimate .col-stock { width: 132px; }
.estimate .col-del { width: 44px; }
.estimate th {
  text-align: left; font: 700 11px/1.3 var(--font-text);
  text-transform: uppercase; letter-spacing: .05em;
  color: var(--ink-soft);
  padding: 10px 12px; border-bottom: 1px solid var(--line);
}
.estimate td { padding: 11px 12px; border-bottom: 1px solid var(--bg-soft); font-size: 14px; vertical-align: top; }
.estimate tr:last-child td { border-bottom: 0; }
.estimate .num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.estimate .strong { font-weight: 700; }
.est-name { display: block; font-weight: 600; }
.est-sub { display: block; font-size: 12px; color: var(--ink-soft); margin-top: 2px; }
.est-actions {
  display: flex; flex-wrap: wrap; gap: 12px;
  padding: 16px 26px 24px;
  border-top: 1px solid var(--bg-soft);
}

/* ---- Методика расчёта ---- */
.method {
  margin-top: 18px;
  background: #fff; border: 1px solid var(--line); border-radius: 18px;
  overflow: hidden;
}
.method > summary {
  list-style: none; cursor: pointer;
  display: flex; align-items: center; gap: 14px;
  padding: 18px 24px;
}
.method > summary::-webkit-details-marker { display: none; }
.method-kick {
  font: 700 11px/1 var(--font-text); letter-spacing: .08em; text-transform: uppercase;
  color: var(--accent);
  border: 1px solid color-mix(in oklab, var(--accent) 40%, var(--line));
  border-radius: 99px; padding: 6px 10px;
}
.method-title { font: 600 18px/1.2 var(--font-display); }
.method-chev { margin-left: auto; width: 12px; height: 12px; border-right: 2px solid var(--ink-soft); border-bottom: 2px solid var(--ink-soft); transform: rotate(45deg); transition: transform .2s; }
.method[open] .method-chev { transform: rotate(-135deg); }
.method-body { padding: 0 24px 24px; }
.method-intro { margin: 0 0 18px; color: var(--ink-soft); font-size: 14.5px; max-width: 820px; text-wrap: pretty; }
.method-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
@media (max-width: 860px) { .method-grid { grid-template-columns: 1fr 1fr; } }
@media (max-width: 560px) { .method-grid { grid-template-columns: 1fr; } }
.method-step {
  background: var(--bg-soft); border-radius: 12px; padding: 16px 16px 18px;
  position: relative;
}
.method-step h5 { margin: 0 0 6px; font: 700 14px/1.3 var(--font-text); padding-left: 26px; }
.method-step h5::before {
  content: counter(ms); counter-increment: ms;
  position: absolute; left: 16px; top: 15px;
  width: 18px; height: 18px; border-radius: 6px;
  background: var(--graphite); color: #fff;
  font: 700 10px/18px var(--font-text); text-align: center;
}
.method-grid { counter-reset: ms; }
.method-step p { margin: 0; font-size: 13px; color: var(--ink-soft); }
.method-note {
  margin: 18px 0 0; padding: 14px 16px;
  background: color-mix(in oklab, var(--accent) 7%, #fff);
  border: 1px solid color-mix(in oklab, var(--accent) 26%, var(--line));
  border-radius: 12px;
  font-size: 13.5px; color: var(--ink); text-wrap: pretty;
}

/* —— Ручная правка количества и удаление строк —— */
.qty-wrap { display: inline-flex; align-items: baseline; gap: 5px; justify-content: flex-end; }
.qty-in {
  width: 70px; padding: 6px 8px;
  text-align: right; flex: none;
  border: 1px solid var(--line); border-radius: 8px;
  font: 600 13.5px/1 var(--font-text); text-align: right;
  background: #fff; color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.qty-in:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.qty-wrap em { font-style: normal; font-size: 12px; color: var(--ink-soft); white-space: nowrap; width: 30px; text-align: left; flex: none; }
tr.edited .qty-in { border-color: var(--accent); background: color-mix(in oklab, var(--accent) 6%, #fff); }
.row-del {
  width: 26px; height: 26px;
  border: 0; border-radius: 7px;
  background: transparent; color: #B9BDC2;
  cursor: pointer; font-size: 13px; line-height: 1;
}
.row-del:hover { background: #F6E4DA; color: #B3441E; }
#est-removed {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px;
  padding: 10px 26px;
  font-size: 13px; color: var(--ink-soft);
  border-top: 1px dashed var(--line);
}
#est-removed button {
  border: 0; background: transparent; cursor: pointer; padding: 0;
  font: 700 13px/1.2 var(--font-text);
  color: var(--accent); text-decoration: underline;
}
.sr-only {
  position: absolute; width: 1px; height: 1px;
  margin: -1px; padding: 0; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.snow-toggle {
  display: flex; align-items: center; gap: 8px;
  font: 500 13.5px/1.3 var(--font-text); color: var(--ink);
  padding: 9px 0; cursor: pointer;
}
.snow-toggle input { width: 16px; height: 16px; accent-color: var(--accent); margin: 0; }
.sw-face { position: relative; }
.sw-face.sw-soffit::after {
  content: ""; position: absolute; inset: 0; border-radius: inherit;
  background: repeating-linear-gradient(90deg, rgba(0,0,0,.16) 0 2px, transparent 2px 10px);
}

@media (max-width: 640px) {
  .est-head { padding: 18px 18px 4px; }
  .est-note { padding: 0 18px; }
  .est-actions { padding: 14px 18px 20px; }
  #est-removed { padding: 10px 18px; }
  #pal-body { max-height: none; }
  .palette { position: static; }

  /* Смета вписывается в экран телефона — без горизонт. прокрутки и зума */
  .est-table-wrap { padding: 8px 10px 4px; }
  .estimate table { min-width: 0; table-layout: auto; font-size: 13px; }
  .estimate col { width: auto !important; }
  /* колонка «Наличие» (5-я) на телефоне скрыта — статус не критичен для предварит. расчёта */
  .estimate .col-stock,
  .estimate thead th:nth-child(5),
  .estimate tbody td:nth-child(5) { display: none; }
  .estimate th, .estimate td { padding: 9px 7px; }
  .estimate .num { font-size: 13px; }
  .qty-wrap { gap: 3px; }
  .qty-in { width: 46px; padding: 6px 6px; }
  .qty-wrap em { width: 26px; }
  .est-actions .btn { flex: 1 1 100%; }
  /* анти-зум iOS: поля >=16px, чтобы экран не масштабировался при фокусе */
  .qty-in, #part-editor input, #part-editor select, .ctl-card input, .ctl-card select, .ctl-card textarea, .estimate input { font-size: 16px; }
}

/* На тач-устройствах нет :hover — показываем, что окна/двери редактируются (тап) */
@media (hover: none) {
  .drag-part { outline: 1.5px dashed color-mix(in oklab, var(--accent) 55%, transparent); outline-offset: 1px; }
  [data-zone].can-drop { outline-width: 3px; }
}
