:root {
  --bg: #f6f4f0;
  --card: #ffffff;
  --ink: #1d1b18;
  --muted: #6f6a62;
  --line: #e2ddd4;
  --line-strong: #cfc8bc;
  --accent: #e8590c;
  --accent-soft: #fff1e8;
  --accent-ink: #ffffff;
  --ok: #2f7d32;
  --warn: #b45309;
  --warn-soft: #fff7ed;
  --radius: 14px;
  --tap: 44px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  -webkit-text-size-adjust: 100%;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); line-height: 1.4; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 55%, transparent); outline-offset: 2px; }

/* ---------- Шапка ---------- */
.top { background: var(--card); border-bottom: 1px solid var(--line); }
.top-inner { max-width: 1100px; margin: 0 auto; padding: 12px 16px; display: flex; align-items: baseline; gap: 12px; }
.brand { font-weight: 800; letter-spacing: .04em; }
.top-title { color: var(--muted); font-size: 14px; }

/* ---------- Сітка ---------- */
.layout {
  display: grid; gap: 16px 24px; padding: 20px 16px 40px;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr);
  grid-template-areas: "intro intro" "preview config" "preview manager";
  max-width: 1100px; margin: 0 auto;
}
.intro { grid-area: intro; }
.intro h1 { font-size: 28px; line-height: 1.15; margin: 0 0 6px; }
.intro p { margin: 0; color: var(--muted); max-width: 60ch; }
.preview { grid-area: preview; min-width: 0; grid-template-columns: minmax(0, 1fr); position: sticky; top: 16px; align-self: start; display: grid; gap: 12px; }
.config { grid-area: config; display: grid; gap: 12px; grid-template-columns: minmax(0, 1fr); min-width: 0; }
.manager { grid-area: manager; }

/* ---------- Коробка ---------- */
.box-stage { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 12px; }
#box { width: 100%; height: auto; display: block; max-height: 340px; }
.stage-note { margin: 0 0 4px; text-align: center; color: var(--muted); font-size: 13px; min-height: 1.2em; }

/* ---------- Ціна ---------- */
.price-card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.price-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.price-main { display: grid; gap: 2px; min-width: 0; }
.price-per { font-size: 32px; font-weight: 750; line-height: 1.1; font-variant-numeric: tabular-nums; transition: opacity .15s; }
.price-total { color: var(--muted); font-size: 15px; font-variant-numeric: tabular-nums; }
.price-card.loading .price-per, .price-card.loading .price-total { opacity: .45; }
.price-card.invalid .price-per { font-size: 20px; color: var(--muted); }

.cta {
  background: var(--accent); color: var(--accent-ink); border: 0; border-radius: 12px;
  min-height: var(--tap); padding: 12px 22px; font-size: 16px; font-weight: 650; white-space: nowrap;
  transition: filter .15s, transform .05s;
}
.cta:hover { filter: brightness(1.06); }
.cta:active { transform: translateY(1px); }
.cta:disabled { background: var(--line-strong); cursor: not-allowed; }

.price-toggle { display: none; }
.price-details { margin-top: 12px; }
.price-lines { list-style: none; padding: 0; margin: 0; font-size: 14px; }
.price-lines li { display: flex; justify-content: space-between; gap: 12px; padding: 5px 0; border-bottom: 1px dashed var(--line); }
.price-lines li span:last-child { font-variant-numeric: tabular-nums; white-space: nowrap; }
.price-lines li.good span:last-child { color: var(--ok); font-weight: 600; }
.price-lines li.side { color: var(--muted); }
.price-status { margin: 8px 0 0; font-size: 14px; }
.price-status:empty { display: none; }
.price-status.error { color: var(--warn); background: var(--warn-soft); padding: 10px 12px; border-radius: 10px; }

.ladder-wrap { margin-top: 14px; }
.ladder-title { margin: 0 0 6px; font-size: 13px; color: var(--muted); }
.ladder { display: flex; gap: 8px; flex-wrap: wrap; }
.ladder button {
  border: 1px solid var(--line); background: var(--bg); border-radius: 10px;
  min-height: 40px; padding: 6px 12px; font-size: 14px; text-align: left;
}
.ladder button:hover { border-color: var(--accent); }
.ladder button b { color: var(--ok); }
.assure { margin: 14px 0 0; font-size: 13px; color: var(--muted); }

/* ---------- Кроки форми ---------- */
.step, .more, .manager { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
.step { padding: 16px; }
.step h2 { display: flex; align-items: center; gap: 10px; font-size: 18px; margin: 0 0 12px; }
.num {
  display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 50%;
  background: var(--ink); color: #fff; font-size: 14px; font-weight: 700; flex: none;
}
.step-hint { margin: -6px 0 10px; color: var(--muted); font-size: 14px; }
.field-hint { margin: 10px 0 0; color: var(--muted); font-size: 13px; }
.field-error { margin: 10px 0 0; color: var(--warn); font-size: 14px; }

/* Популярні розміри */
.presets { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.presets button {
  flex: none; display: grid; gap: 1px; text-align: left;
  border: 1.5px solid var(--line); background: var(--card); border-radius: 12px; padding: 8px 12px; min-height: var(--tap);
}
.presets button b { font-size: 15px; font-variant-numeric: tabular-nums; }
.presets button span { font-size: 12px; color: var(--muted); }
.presets button:hover { border-color: var(--line-strong); }
.presets button.active { border-color: var(--accent); background: var(--accent-soft); }

/* Розміри */
.dims { display: grid; grid-template-columns: 1fr auto 1fr auto 1fr; align-items: end; gap: 8px; }
.dim { display: grid; gap: 4px; font-size: 13px; color: var(--muted); min-width: 0; }
.times { padding-bottom: 12px; color: var(--muted); }
.unit-input { position: relative; display: block; }
.unit-input i { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); font-style: normal; color: var(--muted); font-size: 14px; pointer-events: none; }
input[type=number] {
  width: 100%; min-height: var(--tap); padding: 8px 36px 8px 12px; font-size: 18px; font-weight: 600;
  border: 1.5px solid var(--line-strong); border-radius: 10px; background: var(--card); color: var(--ink);
  font-variant-numeric: tabular-nums; -moz-appearance: textfield;
}
input[type=number]::-webkit-inner-spin-button, input[type=number]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
input[type=number]:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }
input[aria-invalid=true] { border-color: var(--warn); background: var(--warn-soft); }

/* Тираж */
.qty-row { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.stepper { display: flex; align-items: stretch; border: 1.5px solid var(--line-strong); border-radius: 10px; overflow: hidden; background: var(--card); }
.stepper:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.stepper button { width: var(--tap); border: 0; background: var(--bg); font-size: 20px; }
.stepper button:hover { background: var(--line); }
.stepper input { width: 96px; border: 0; border-radius: 0; text-align: center; padding: 8px; }
.stepper input:focus { box-shadow: none; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chips button {
  border: 1.5px solid var(--line); background: var(--card); border-radius: 99px;
  min-height: 38px; padding: 4px 14px; font-size: 15px; font-variant-numeric: tabular-nums;
}
.chips button:hover { border-color: var(--line-strong); }
.chips button.active { border-color: var(--accent); background: var(--accent-soft); }

/* Картки-вибір */
.cards { display: grid; gap: 8px; }
.cards-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.cards-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.card {
  position: relative; display: grid; gap: 2px; align-content: start;
  border: 1.5px solid var(--line); border-radius: 12px; padding: 10px 12px; min-height: 60px; cursor: pointer;
  transition: border-color .15s, background .15s;
}
.card:hover { border-color: var(--line-strong); }
.card input { position: absolute; opacity: 0; pointer-events: none; }
.card:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.card:has(input:focus-visible) { outline: 3px solid color-mix(in srgb, var(--accent) 55%, transparent); outline-offset: 2px; }
.card-title { font-weight: 650; font-size: 15px; }
.card-sub { font-size: 12px; color: var(--muted); }
.card-icon { justify-items: start; }
.card-icon svg { width: 48px; height: 36px; margin-bottom: 4px; }
.ic-body { fill: #ece8e1; stroke: #8a8378; stroke-width: 1.5; stroke-linejoin: round; }
.ic-lid { fill: #fff; stroke: #8a8378; stroke-width: 1.5; stroke-linejoin: round; }
.card:has(input:checked) .ic-lid { fill: #ffd8bf; stroke: var(--accent); }
.ic-dot { fill: #8a8378; }
.ic-arrow { fill: none; stroke: var(--accent); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.sides { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px 12px; margin-top: 12px; padding: 12px; background: var(--bg); border-radius: 10px; }
.sides label { display: flex; gap: 8px; align-items: center; min-height: 36px; font-size: 15px; cursor: pointer; }
input[type=checkbox], input[type=radio] { accent-color: var(--accent); width: 20px; height: 20px; flex: none; margin: 0; }

/* ---------- Додатково ---------- */
.more summary {
  display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 12px;
  list-style: none; cursor: pointer; padding: 14px 44px 14px 16px; position: relative; min-height: var(--tap);
}
.more summary::-webkit-details-marker { display: none; }
.more summary::after {
  content: ""; position: absolute; right: 18px; top: 50%; width: 9px; height: 9px;
  border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted);
  transform: translateY(-70%) rotate(45deg); transition: transform .15s;
}
.more[open] summary::after { transform: translateY(-30%) rotate(-135deg); }
.more-title { font-weight: 650; font-size: 16px; }
.more-summary { color: var(--muted); font-size: 13px; }
.more-body { padding: 0 16px 16px; display: grid; gap: 16px; }
.more-label { margin: 0 0 6px; font-size: 14px; font-weight: 600; }

.seg { display: flex; max-width: 420px; background: var(--bg); border-radius: 10px; padding: 3px; gap: 3px; }
.seg label { position: relative; cursor: pointer; flex: 1 1 0; min-width: 0; text-align: center; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { display: block; height: 100%; padding: 8px 10px; border-radius: 8px; font-size: 15px; min-height: 38px; }
.seg em { display: block; font-style: normal; color: var(--muted); font-size: 12px; font-weight: 400; }
.seg em:empty { display: none; }
.seg label:has(input:checked) span { background: var(--card); box-shadow: 0 1px 3px rgb(0 0 0 / .12); font-weight: 600; }
.seg label:has(input:focus-visible) span { outline: 3px solid color-mix(in srgb, var(--accent) 55%, transparent); }

.checks { display: grid; gap: 4px; }
.checks label { display: flex; gap: 10px; align-items: flex-start; min-height: 36px; padding: 6px 0; cursor: pointer; font-size: 15px; }
.checks label input { margin-top: 1px; }
.checks em { display: block; font-style: normal; color: var(--muted); font-size: 13px; }
.checks .field-hint { margin: -4px 0 4px 30px; }
label.disabled { opacity: .45; cursor: not-allowed; }

/* ---------- Внутрішній розрахунок ---------- */
.manager { padding: 12px 16px; font-size: 14px; }
.manager summary { cursor: pointer; color: var(--muted); }
.manager table { width: 100%; border-collapse: collapse; margin-top: 8px; }
.manager td { padding: 3px 0; border-bottom: 1px solid var(--line); }
.manager td:last-child { text-align: right; font-variant-numeric: tabular-nums; }
.sheet-svg { width: 100%; height: auto; margin-top: 10px; border: 1px solid var(--line); border-radius: 6px; background: #fbfaf7; }
.manager .hint { color: var(--muted); font-size: 13px; }

/* ---------- Заявка ---------- */
dialog { border: 0; border-radius: var(--radius); padding: 20px; width: min(440px, calc(100vw - 32px)); }
dialog::backdrop { background: rgb(0 0 0 / .4); }
dialog h2 { margin: 0 0 4px; }
.lead-summary { margin: 0 0 6px; padding: 10px 12px; background: var(--bg); border-radius: 10px; font-size: 14px; }
#lead-form { display: grid; gap: 12px; }
#lead-form label { display: grid; gap: 4px; font-size: 14px; font-weight: 600; }
.optional { font-weight: 400; color: var(--muted); }
#lead-form input, #lead-form textarea {
  font-size: 16px; padding: 10px 12px; min-height: var(--tap); font-weight: 400;
  border: 1.5px solid var(--line-strong); border-radius: 10px;
}
#lead-form input:focus, #lead-form textarea:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }
.ghost { background: none; border: 1.5px solid var(--line-strong); border-radius: 12px; min-height: var(--tap); padding: 10px 18px; }
#lead-result { font-size: 12px; background: var(--bg); padding: 8px; border-radius: 8px; white-space: pre-wrap; max-height: 240px; overflow: auto; }

/* ---------- Планшет і телефон ---------- */
@media (max-width: 860px) {
  .layout {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: "intro" "preview" "config" "manager";
    padding: 16px 16px calc(110px + env(safe-area-inset-bottom));
  }
  .intro h1 { font-size: 23px; }
  .preview { position: static; }
  #box { max-height: 250px; }

  /* Ціна — липка панель знизу, деталі розгортаються */
  .price-card {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
    border-radius: 18px 18px 0 0; border-bottom: 0;
    box-shadow: 0 -6px 24px rgb(0 0 0 / .1);
    padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
    max-height: 85vh; overflow-y: auto;
  }
  .price-per { font-size: 24px; }
  .price-total { font-size: 13px; }
  .price-toggle {
    display: block; width: 100%; margin-top: 6px; padding: 4px 0 0; border: 0; background: none;
    color: var(--muted); font-size: 13px; text-align: left; text-decoration: underline; text-underline-offset: 3px;
  }
  .price-details { display: none; }
  .price-card.expanded .price-details { display: block; }
  /* Помилку показуємо завжди, навіть у згорнутій панелі */
  .price-card.invalid .price-details { display: block; }
  .price-card.invalid .price-lines, .price-card.invalid .assure { display: none; }
}

@media (max-width: 560px) {
  /* Популярні розміри — стрічкою, що гортається вбік */
  .presets { flex-wrap: nowrap; overflow-x: auto; margin: 0 -16px 14px; padding: 0 16px 4px; scrollbar-width: none; }
  .cards-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .cards-3 .card-sub { display: none; }
  .card { padding: 10px; }
  .sides { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dims { gap: 6px; }
  .times { display: none; }
  .dims { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  input[type=number] { padding-right: 30px; font-size: 17px; }
  .unit-input i { right: 9px; font-size: 13px; }
  .qty-row { gap: 10px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
.muted { color: var(--muted); font-size: 13px; }
