/* ═══════════════════════════════════════════════════════════
   calculator.css — калькулятор стоимости (pages/calculator.js)

   Слева — карточки того, что входит в заказ, справа — итог.
   Главный элемент — карточка итога: крупная цена и полоса, из чего она сложена.
   Расходы на полосе — нейтральные оттенки текста, заработок — акцент, налог — штриховка.
   ═══════════════════════════════════════════════════════════ */

.cx {
  --cx-material: color-mix(in srgb, var(--c-text) 78%, transparent);
  --cx-print:    color-mix(in srgb, var(--c-text) 52%, transparent);
  --cx-modeling: color-mix(in srgb, var(--c-text) 34%, transparent);
  --cx-pp:       color-mix(in srgb, var(--c-text) 20%, transparent);
  --cx-profit:   var(--c-accent);
  --cx-stroke-s: color-mix(in srgb, var(--c-text) 10%, transparent);
  --cx-r-card:   20px;
  --cx-r-total:  28px;
  --cx-r-tile:   12px;
  max-width: 1320px;
}
/* появление — у блоков, не у .cx: transform на предке сделал бы его опорой для
   position:fixed, и плашка итога на телефоне прилипла бы к низу страницы, а не экрана */
.cx-head, .cx-blocks, .cx-grid { animation: cxIn .28s ease both; }
.cx [hidden] { display: none !important; }
.cx .cx-num, .cx input[type="number"] { font-variant-numeric: tabular-nums; }

@keyframes cxIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ── Шапка ─────────────────────────────────────────────── */
.cx-head {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: var(--sp-4); flex-wrap: wrap; margin-bottom: var(--sp-4);
}
.cx-head-text { min-width: 0; }
.cx-head-sub {
  display: flex; align-items: center; gap: var(--sp-3); flex-wrap: wrap;
  margin-top: 6px; color: var(--c-muted); font-size: 14px;
}
.cx-order-chip {
  display: inline-flex; align-items: center; gap: 6px; max-width: 100%;
  padding: 4px 12px 4px 10px; border-radius: var(--r-pill);
  background: var(--c-accent-s); color: var(--c-text); font-weight: 600; font-size: 13px;
  border: 1px solid color-mix(in srgb, var(--c-accent) 28%, transparent);
}
.cx-order-chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cx-order-chip svg { width: 14px; height: 14px; color: var(--c-accent); flex-shrink: 0; }

.cx-mode {
  display: inline-flex; padding: 4px; gap: 2px; border-radius: var(--r-pill);
  background: var(--c-base); border: 1px solid var(--cx-stroke-s);
}
.cx-mode-btn {
  border: 0; background: transparent; color: var(--c-muted); cursor: pointer;
  font: 600 13px/1 var(--f-ui); padding: 10px 18px; border-radius: var(--r-pill);
  min-height: 38px; transition: background var(--t-base), color var(--t-base);
}
.cx-mode-btn:hover { color: var(--c-text); }
.cx-mode-btn.is-on { background: var(--c-accent); color: #f8f8f8; }
.cx-mode-btn:focus-visible { outline: 2px solid var(--c-accent); outline-offset: 2px; }

/* ── Что входит ────────────────────────────────────────── */
.cx-blocks { display: flex; align-items: center; gap: var(--sp-2); flex-wrap: wrap; margin-bottom: var(--sp-5); }
.cx-blocks-label { color: var(--c-muted); font-size: 13px; margin-right: 4px; }
.cx-chip {
  display: inline-flex; align-items: center; gap: 6px; cursor: pointer; user-select: none;
  min-height: 36px; padding: 6px 14px; border-radius: var(--r-pill);
  border: 1px solid var(--cx-stroke-s); color: var(--c-muted); font-size: 13px; font-weight: 500;
  transition: border-color var(--t-base), color var(--t-base), background var(--t-base);
}
.cx-chip input { position: absolute; opacity: 0; pointer-events: none; }
.cx-chip svg { width: 15px; height: 15px; }
.cx-chip:hover { color: var(--c-text); }
.cx-chip.is-on { color: var(--c-text); background: var(--c-base); border-color: color-mix(in srgb, var(--c-accent) 45%, transparent); }
.cx-chip.is-on svg { color: var(--c-accent); }
.cx-chip:has(input:focus-visible) { outline: 2px solid var(--c-accent); outline-offset: 2px; }

/* ── Сетка ─────────────────────────────────────────────── */
.cx-grid { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: var(--sp-5); align-items: start; }
.cx-main, .cx-side { display: flex; flex-direction: column; gap: var(--sp-4); min-width: 0; }
.cx-side { position: sticky; top: calc(var(--topbar-h) + var(--sp-4)); }

/* ── Карточки ──────────────────────────────────────────── */
.cx-card {
  background: var(--c-base); border: 1px solid var(--cx-stroke-s); border-radius: var(--cx-r-card);
  padding: var(--sp-5); display: flex; flex-direction: column; gap: var(--sp-4); min-width: 0;
}
.cx-card--side { padding: var(--sp-4) var(--sp-5); gap: var(--sp-3); }
.cx-card-head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--sp-3); }
.cx-card-title { font: 700 16px/1.25 var(--f-brand); margin: 0; color: var(--c-text); }
.cx-card-sum { font-weight: 600; font-size: 14px; color: var(--c-text); font-variant-numeric: tabular-nums; }
.cx-card-meta { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; color: var(--c-muted); min-width: 0; }
.cx-card-meta svg { width: 13px; height: 13px; flex-shrink: 0; }

.cx-subhead {
  display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3);
  font-size: 13px; font-weight: 600; color: var(--c-text);
  padding-top: var(--sp-3); border-top: 1px solid var(--c-stroke);
}

/* ── Поля ──────────────────────────────────────────────── */
.cx-fields { display: grid; gap: var(--sp-3); }
.cx-fields--2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.cx-fields--3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.cx-field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.cx-label { font-size: 12px; font-weight: 500; color: var(--c-muted); }
.cx-hint { color: var(--c-muted); opacity: .75; font-weight: 400; }
.cx-input-wrap { position: relative; display: flex; align-items: center; min-width: 0; }
.cx-input-wrap .input { padding-right: 56px; min-height: 42px; }
.cx-unit {
  position: absolute; right: 12px; pointer-events: none; font-size: 12px; color: var(--c-muted);
  white-space: nowrap; max-width: 50%; overflow: hidden; text-overflow: ellipsis;
}
.cx-input-wrap--sm { width: 120px; flex-shrink: 0; }
.cx-input-wrap--sm .input { min-height: 36px; padding-top: 6px; padding-bottom: 6px; }
.cx-check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: 13px; color: var(--c-text); min-height: 32px; }
.cx-check input { width: 16px; height: 16px; accent-color: var(--c-accent); flex-shrink: 0; }
.cx-note { margin: 0; font-size: 12px; line-height: 1.5; color: var(--c-muted); }
.cx-urgency { display: flex; align-items: center; gap: var(--sp-3); flex-wrap: wrap; }

.cx-link {
  display: inline-flex; align-items: center; gap: 4px; border: 0; background: none; padding: 4px 0;
  font: 500 13px/1.3 var(--f-ui); color: var(--c-accent); cursor: pointer; text-align: left;
}
.cx-link svg { width: 14px; height: 14px; flex-shrink: 0; }
.cx-link:hover { text-decoration: underline; text-underline-offset: 3px; }
.cx-link--muted { color: var(--c-muted); }
.cx-link--muted:hover { color: var(--c-text); }
.cx-link--warn { color: var(--c-warn); }
.cx-icon-btn {
  display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0;
  width: 32px; height: 32px; border-radius: 10px; border: 0; background: transparent;
  color: var(--c-muted); cursor: pointer;
}
.cx-icon-btn:hover { background: var(--c-raised); color: var(--c-text); }
.cx-icon-btn svg { width: 16px; height: 16px; }
.cx-muted { color: var(--c-muted); }
.cx-ok { color: var(--c-ok-green, var(--c-ok)); font-weight: 600; }
.cx-empty-line { font-size: 13px; color: var(--c-muted); }

/* ── G-code ────────────────────────────────────────────── */
.cx-drop {
  display: flex; align-items: center; gap: var(--sp-3); cursor: pointer; min-height: 64px;
  padding: var(--sp-3) var(--sp-4); border-radius: var(--cx-r-tile);
  border: 1px dashed color-mix(in srgb, var(--c-text) 18%, transparent);
  transition: border-color var(--t-base), background var(--t-base);
}
.cx-drop:hover, .cx-drop.is-drag { border-color: var(--c-accent); background: var(--c-accent-s); }
.cx-drop:focus-visible { outline: 2px solid var(--c-accent); outline-offset: 2px; }
.cx-drop.is-loaded { border-style: solid; border-color: var(--cx-stroke-s); background: var(--c-bg); }
.cx-drop .spinner { margin: 0 auto; }
.cx-drop-icon {
  display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0;
  width: 40px; height: 40px; border-radius: 12px; background: var(--c-raised); color: var(--c-muted);
}
.cx-drop.is-loaded .cx-drop-icon { color: var(--c-accent); }
.cx-drop-icon svg { width: 20px; height: 20px; }
.cx-drop-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; flex: 1; font-size: 12px; color: var(--c-muted); }
.cx-drop-text strong { font-size: 14px; color: var(--c-text); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cx-drop-text span { overflow: hidden; text-overflow: ellipsis; }
.cx-tag {
  display: inline-block; font-size: 10px; font-weight: 700; padding: 1px 6px; margin-left: 4px; vertical-align: 2px;
  border-radius: var(--r-pill); color: var(--c-accent); background: var(--c-accent-s);
}

/* ── Принтеры и катушки ────────────────────────────────── */
.cx-printers { display: flex; flex-direction: column; gap: var(--sp-3); }
.cx-printer {
  display: flex; flex-direction: column; gap: var(--sp-3); padding: var(--sp-3);
  border-radius: 16px; background: var(--c-bg); border: 1px solid var(--c-stroke);
}
.cx-printer-head { display: flex; align-items: center; gap: var(--sp-2); }
.cx-printer-head .select { flex: 1; min-width: 0; min-height: 42px; font-weight: 600; }
.cx-units { position: relative; display: flex; align-items: center; width: 88px; flex-shrink: 0; }
.cx-units .input { min-height: 42px; padding-right: 34px; text-align: right; }
.cx-units span { position: absolute; right: 10px; font-size: 12px; color: var(--c-muted); pointer-events: none; }
.cx-printer-meta { font-size: 12px; color: var(--c-muted); margin-top: -4px; }
.cx-filter { font-size: 12px; color: var(--c-muted); display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.cx-filter .cx-link { font-size: 12px; padding: 0; }

.cx-mats { display: flex; flex-direction: column; gap: var(--sp-2); }
.cx-mat { display: flex; flex-direction: column; gap: 6px; }
.cx-mat + .cx-mat { padding-top: var(--sp-2); border-top: 1px solid var(--c-stroke); }
.cx-mat-head { display: flex; align-items: center; gap: var(--sp-2); min-height: 0; }
.cx-mat-idx { font-size: 12px; font-weight: 600; color: var(--c-muted); flex: 1; }
.cx-chain { display: flex; flex-direction: column; gap: 4px; }
.cx-chain.is-next { padding-left: var(--sp-4); border-left: 2px solid var(--c-stroke); margin-left: 5px; }
.cx-chain-row { display: flex; align-items: center; gap: var(--sp-2); }
.cx-chain-row .select { flex: 1; min-width: 0; min-height: 40px; }
.cx-swatch {
  width: 12px; height: 12px; border-radius: 4px; flex-shrink: 0;
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--c-text) 22%, transparent);
}
.cx-swatch.is-empty { background: transparent; box-shadow: inset 0 0 0 1px dashed; border: 1px dashed var(--c-muted); }
.cx-chain-info { display: flex; justify-content: space-between; gap: var(--sp-2); font-size: 12px; color: var(--c-muted); padding-left: 20px; }
.cx-chain-info .cx-num { color: var(--c-text); font-weight: 600; white-space: nowrap; }
.cx-warn { display: flex; align-items: flex-start; gap: 6px; font-size: 12px; line-height: 1.4; color: var(--c-warn); padding-left: 20px; }
.cx-warn svg { width: 14px; height: 14px; flex-shrink: 0; margin-top: 1px; }

/* ── Моделирование ─────────────────────────────────────── */
.cx-presets { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--sp-2); }
.cx-preset {
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px; cursor: pointer; text-align: left;
  padding: 10px 12px; border-radius: var(--cx-r-tile); min-height: 52px;
  background: var(--c-bg); border: 1px solid var(--c-stroke); color: var(--c-text); font: 600 13px/1.25 var(--f-ui);
  transition: border-color var(--t-base), background var(--t-base);
}
.cx-preset:hover { border-color: color-mix(in srgb, var(--c-accent) 35%, transparent); }
.cx-preset.is-on { border-color: var(--c-accent); background: var(--c-accent-s); }
.cx-preset-val { font-weight: 500; font-size: 12px; color: var(--c-muted); font-variant-numeric: tabular-nums; }

/* ── Постобработка ─────────────────────────────────────── */
.cx-pp { display: flex; flex-direction: column; gap: var(--sp-3); }
.cx-pp-row {
  display: flex; flex-direction: column; gap: var(--sp-3); padding: var(--sp-3);
  border-radius: 16px; background: var(--c-bg); border: 1px solid var(--c-stroke);
}
.cx-pp-head { display: flex; align-items: center; gap: var(--sp-2); }
.cx-pp-head .select { flex: 1; min-width: 0; min-height: 40px; font-weight: 600; }
.cx-pp-sum { font-size: 13px; font-weight: 600; white-space: nowrap; }

/* ── Итог — главный элемент ────────────────────────────── */
.cx-total {
  position: relative; overflow: hidden;
  background: var(--c-base); border: 1px solid var(--cx-stroke-s); border-radius: var(--cx-r-total);
  box-shadow: var(--shadow-md); padding: var(--sp-6) var(--sp-6) var(--sp-5);
  display: flex; flex-direction: column; gap: var(--sp-3);
  scroll-margin-top: calc(var(--topbar-h) + var(--sp-3));
}
.cx-total::before {
  content: ""; position: absolute; inset: 0 0 auto 0; height: 120px; pointer-events: none;
  background: radial-gradient(120% 100% at 0% 0%, var(--c-accent-s), transparent 70%);
}
.cx-total > * { position: relative; }
.cx-total-eyebrow { font-size: 13px; font-weight: 500; color: var(--c-muted); }
.cx-total-big {
  font: 800 clamp(36px, 4.2vw, 48px)/1.02 var(--f-brand); letter-spacing: -0.02em; color: var(--c-text);
  font-variant-numeric: tabular-nums; overflow-wrap: anywhere;
  animation: cxPop .24s ease both;
}
.cx-total-big.is-empty { color: var(--c-muted); }
@keyframes cxPop { from { opacity: .4; } to { opacity: 1; } }
.cx-total-sub { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 13px; color: var(--c-muted); font-variant-numeric: tabular-nums; }
.cx-total-sub:empty { display: none; }
.cx-total-empty { margin: 0; font-size: 13px; color: var(--c-muted); }

.cx-bar { display: flex; gap: 3px; height: 12px; margin-top: var(--sp-2); }
.cx-bar-seg { flex-basis: 0; min-width: 4px; border-radius: 4px; }
.cx-c-material { background: var(--cx-material); }
.cx-c-print    { background: var(--cx-print); }
.cx-c-modeling { background: var(--cx-modeling); }
.cx-c-pp       { background: var(--cx-pp); }
.cx-c-profit   { background: var(--cx-profit); }
.cx-c-tax {
  background: repeating-linear-gradient(135deg, var(--cx-print) 0 2px, transparent 2px 5px);
  box-shadow: inset 0 0 0 1px var(--cx-pp);
}

.cx-legend { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.cx-legend-row {
  display: grid; grid-template-columns: 10px minmax(0, 1fr) auto auto; align-items: baseline; gap: 10px;
  padding: 9px 0; border-bottom: 1px solid var(--c-stroke); font-size: 14px;
}
.cx-legend-row:last-child { border-bottom: 0; }
.cx-dot { width: 10px; height: 10px; border-radius: 3px; align-self: center; }
.cx-legend-label { color: var(--c-text); min-width: 0; }
.cx-legend-hint { display: block; font-size: 12px; color: var(--c-muted); margin-top: 2px; }
.cx-legend-pct { font-size: 12px; color: var(--c-muted); font-variant-numeric: tabular-nums; }
.cx-legend-val { font-weight: 600; font-variant-numeric: tabular-nums; text-align: right; min-width: 64px; }
.cx-legend-row.is-profit .cx-legend-label, .cx-legend-row.is-profit .cx-legend-val { color: var(--c-accent); font-weight: 700; }

.cx-total-note { margin: 0; font-size: 12px; color: var(--c-muted); }
.cx-total-note--warn { color: var(--c-warn); }
.cx-alert {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; padding: 10px 12px;
  border-radius: var(--cx-r-tile); font-size: 13px; color: var(--c-text);
  background: var(--c-warn-s); border: 1px solid color-mix(in srgb, var(--c-warn) 35%, transparent);
}
.cx-alert > svg { width: 15px; height: 15px; color: var(--c-warn); flex-shrink: 0; }
.cx-alert .cx-link { color: var(--c-warn); font-weight: 600; flex-basis: 100%; padding: 0; }

.cx-actions { display: flex; flex-direction: column; gap: var(--sp-2); margin-top: var(--sp-2); }
.cx-actions .btn { min-height: 44px; width: 100%; }
.cx-actions .cx-link { align-self: center; }
.cx-btn-main { font-weight: 600; font-size: 14px; }
.cx-bind { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: var(--sp-2); align-items: center; }
.cx-bind .select { min-height: 44px; }
.cx-bind .btn { width: auto; }
.cx-bind > .btn-ghost, .cx-bind > .cx-muted, .cx-bind > .spinner { grid-column: 1 / -1; }
.cx-bind > .spinner { margin: 4px auto; }

/* ── Завершение заказа ─────────────────────────────────── */
.cx-apply { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.cx-apply-row { display: grid; grid-template-columns: 16px minmax(0, 1fr) auto auto; align-items: center; gap: 8px; font-size: 13px; }
.cx-apply-row:has(.cx-apply-ic) { grid-template-columns: 16px minmax(0, 1fr) auto; }
.cx-apply-ic svg { width: 14px; height: 14px; color: var(--c-muted); display: block; }
.cx-apply-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--c-text); }
.cx-apply-row .cx-num { font-weight: 600; white-space: nowrap; }
.cx-apply-after { font-size: 12px; color: var(--c-muted); white-space: nowrap; }
.cx-apply-after.is-empty { color: var(--c-accent); }
.cx-card--side .btn { min-height: 44px; }

/* ── Окупаемость ───────────────────────────────────────── */
.cx-payback-list { display: flex; flex-direction: column; gap: var(--sp-4); }
.cx-payback-list:empty { display: none; }
.cx-payback-nums { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; font-size: 13px; font-variant-numeric: tabular-nums; }
.cx-payback-big { font: 800 26px/1 var(--f-brand); color: var(--c-text); }
.cx-payback-bar { position: relative; height: 8px; border-radius: var(--r-pill); background: var(--c-raised); overflow: hidden; }
.cx-payback-fill { position: absolute; inset: 0 auto 0 0; background: var(--cx-print); border-radius: inherit; }
.cx-payback-this { position: absolute; top: 0; bottom: 0; background: var(--c-accent); }
.cx-payback-foot { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; font-size: 12px; color: var(--c-muted); font-variant-numeric: tabular-nums; }
.cx-payback-plus { color: var(--c-accent); font-weight: 600; }
.cx-payback-line { font-size: 13px; color: var(--c-text); }

/* ── Адаптив ───────────────────────────────────────────── */
@media (max-width: 1180px) {
  .cx-grid { grid-template-columns: minmax(0, 1fr) 340px; }
}
@media (max-width: 980px) {
  .cx-grid { grid-template-columns: minmax(0, 1fr); }
  .cx-side { position: static; }
}
@media (max-width: 560px) {
  .cx-head { align-items: stretch; }
  .cx-mode { width: 100%; }
  .cx-mode-btn { flex: 1; padding: 10px 8px; }
  .cx-card { padding: var(--sp-4); border-radius: 18px; }
  .cx-total { padding: var(--sp-5) var(--sp-4) var(--sp-4); border-radius: 22px; }
  .cx-fields--3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .cx-fields--3 > :first-child { grid-column: 1 / -1; }
  .cx-presets { grid-template-columns: 1fr; }
  .cx-preset { flex-direction: row; justify-content: space-between; align-items: center; min-height: 44px; }
}
@media (max-width: 380px) {
  .cx-fields--2 { grid-template-columns: minmax(0, 1fr); }
}
/* плашка с итогом — только на узком экране и пока карточка итога не видна */
.cx-mini { display: none; }
@media (max-width: 980px) {
  .cx { padding-bottom: 84px; }
  .cx-mini {
    position: fixed; left: 12px; right: 12px; bottom: calc(12px + env(safe-area-inset-bottom, 0px)); z-index: 40;
    display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3);
    padding: 10px 10px 10px 18px; border-radius: 20px;
    background: color-mix(in srgb, var(--c-base) 92%, transparent); backdrop-filter: blur(14px);
    border: 1px solid var(--cx-stroke-s); box-shadow: var(--shadow-md);
    transform: translateY(calc(100% + 24px)); opacity: 0; pointer-events: none;
    transition: transform var(--t-slow), opacity var(--t-slow);
  }
  .cx-mini.is-away { transform: none; opacity: 1; pointer-events: auto; }
  .cx-mini-text { display: flex; flex-direction: column; min-width: 0; }
  .cx-mini-label { font-size: 11px; color: var(--c-muted); }
  .cx-mini-val { font: 800 20px/1.15 var(--f-brand); font-variant-numeric: tabular-nums; white-space: nowrap; }
  .cx-mini .btn { min-height: 44px; flex-shrink: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .cx-mini { transition: none; }
  .cx-head, .cx-blocks, .cx-grid, .cx-total-big { animation: none; }
}
