/* Мерч-пакет Metakultura.
   Ідея: сторінка «надрукована» двома фарбами — чорною та фірмовою жовтою, як базовий
   двоколірний принт; поле примірки — зелений розкрійний килимок із сантиметровою сіткою. */

/* Фірмовий шрифт для заголовків і сум. Покладіть файл у frontend/assets/fonts/
   з назвою NAMU-1990.woff2 (або .woff / .otf / .ttf). Поки файлу немає, працює запасний Unbounded. */
@font-face {
  font-family: "NAMU 1990";
  src: url("fonts/NAMU-1990.woff2") format("woff2"),
       url("fonts/NAMU-1990.woff") format("woff"),
       url("fonts/NAMU-1990.otf") format("opentype"),
       url("fonts/NAMU-1990.ttf") format("truetype");
  font-weight: 100 900; /* одне накреслення на всі товщини, без штучного жирного */
  font-style: normal;
  font-display: swap;
}

:root {
  --paper: #F3F4F1;
  --surface: #FFFFFF;
  --ink: #000000;
  --text: #2B2C29;
  --muted: #676A63;
  --rule: #CDD0C9;
  --rule-strong: #9EA29A;
  --accent: #F8E61F;       /* фірмовий жовтий Metakultura */
  --accent-text: #6B5E00;  /* жовтий для тексту на світлому фоні */
  --accent-wash: #FCF4B4;
  --mat: #2F6150;
  --mat-dark: #244C3F;
  --danger: #B3261E;
  --focus: #1F5EFF;

  --display: "NAMU 1990", "Unbounded", "Arial Black", system-ui, sans-serif;
  --body: "Manrope", system-ui, -apple-system, "Segoe UI", sans-serif;

  --step-0: 1rem;
  --step-1: 1.125rem;
  --step-2: 1.5rem;
  --step-3: 2rem;
  --step-4: clamp(2.25rem, 5.5vw, 4.25rem);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #121311;
    --surface: #1B1C1A;
    --ink: #F3F4F1;
    --text: #DADCD6;
    --muted: #9C9F98;
    --rule: #30322E;
    --rule-strong: #4B4E48;
    --accent-text: #F8E61F;
    --accent-wash: #3A3510;
    --danger: #FF8A80;
    --focus: #7EA2FF;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #121311; --surface: #1B1C1A; --ink: #F3F4F1; --text: #DADCD6; --muted: #9C9F98;
  --rule: #30322E; --rule-strong: #4B4E48; --accent-text: #F8E61F; --accent-wash: #3A3510;
  --danger: #FF8A80; --focus: #7EA2FF; color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--text);
  font: 400 var(--step-0)/1.55 var(--body);
  font-feature-settings: "tnum" 1;
}
img, canvas { display: block; max-width: 100%; }
button, input, textarea, select { font: inherit; color: inherit; }
a { color: var(--ink); text-underline-offset: 3px; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

.wrap {
  width: 100%; max-width: 1240px; margin: 0 auto;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}
@media (min-width: 720px) {
  .wrap {
    padding-left: max(32px, env(safe-area-inset-left, 0px));
    padding-right: max(32px, env(safe-area-inset-right, 0px));
  }
}

/* ---------- шапка ---------- */
.masthead { padding: 40px 0 32px; border-bottom: 2px solid var(--ink); }
.brand { margin: 0 0 28px; display: flex; flex-wrap: wrap; gap: 4px 12px; align-items: baseline; }
.brand-mark { font: 700 var(--step-1)/1 var(--display); color: var(--ink); }
.brand-sub { color: var(--muted); font-size: .9375rem; }
.headline {
  margin: 0;
  max-width: 14ch;
  font: 800 var(--step-4)/1.02 var(--display);
  letter-spacing: -0.02em;
  color: var(--ink);
  /* друга фарба лягла з легким зсувом — як у справжній шовкографії */
  text-shadow: .05em .035em 0 var(--accent);
}
.lede { max-width: 62ch; margin: 24px 0 0; font-size: var(--step-1); }

/* ---------- основна сітка ---------- */
.layout { display: grid; gap: 40px; padding-top: 40px; padding-bottom: 56px; }
@media (min-width: 960px) {
  .layout { grid-template-columns: minmax(0, 1fr) 340px; gap: 48px; align-items: start; }
}
.section-title { margin: 0 0 16px; font: 700 var(--step-2)/1.2 var(--display); color: var(--ink); }
.loading { color: var(--muted); }

/* ---------- рядки позицій ---------- */
.lines { border-top: 1px solid var(--rule-strong); }
.line { border-bottom: 1px solid var(--rule); position: relative; }
.line::before {
  content: ""; position: absolute; left: -16px; top: -1px; bottom: -1px; width: 6px;
  background: var(--accent); transform: scaleY(0); transform-origin: top; transition: transform .25s ease;
}
.line.is-on::before { transform: scaleY(1); }
@media (max-width: 719px) { .line::before { left: -16px; width: 4px; } }

.line-head {
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 4px 16px;
  align-items: center; padding: 18px 0; cursor: pointer;
}
.line-name { margin: 0; font: 700 var(--step-1)/1.25 var(--display); color: var(--ink); }
.line-meta { margin: 2px 0 0; color: var(--muted); font-size: .875rem; }
.line-sum { text-align: right; white-space: nowrap; }
.line-sum strong { display: block; font: 700 var(--step-1)/1.2 var(--display); color: var(--ink); }
.line-sum span { color: var(--muted); font-size: .8125rem; }
.line:not(.is-on) .line-sum strong { color: var(--muted); font-weight: 500; font-family: var(--body); font-size: .9375rem; }

/* перемикач */
.switch { position: relative; width: 48px; height: 28px; flex: none; }
.switch input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; z-index: 1; }
.switch-track {
  position: absolute; inset: 0; border: 2px solid var(--ink); border-radius: 14px; background: var(--surface);
  transition: background .2s ease;
}
.switch-track::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%;
  background: var(--ink); transition: transform .2s ease;
}
.switch input:checked + .switch-track { background: var(--accent); }
.switch input:checked + .switch-track::after { transform: translateX(20px); background: #000; }
.switch input:focus-visible + .switch-track { outline: 3px solid var(--focus); outline-offset: 2px; }

.line-body { display: none; padding: 0 0 22px 64px; }
.line.is-on .line-body { display: block; }
@media (max-width: 719px) { .line-body { padding-left: 0; } }

.specs { margin: 0 0 16px; padding: 0; list-style: none; color: var(--text); font-size: .9375rem; }
.specs li { padding-left: 14px; position: relative; }
.specs li::before { content: ""; position: absolute; left: 0; top: .7em; width: 6px; height: 2px; background: var(--ink); }

.group-label { display: block; margin: 0 0 8px; font-weight: 700; font-size: .875rem; color: var(--ink); }
.tiers { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin: 0 0 18px; border: 0; padding: 0; }
.tier { position: relative; }
.tier input { position: absolute; opacity: 0; }
.tier span {
  display: block; padding: 10px 12px; border: 2px solid var(--rule-strong); border-radius: 4px;
  cursor: pointer; background: var(--surface); transition: border-color .15s, background .15s;
}
.tier b { display: block; font: 700 var(--step-1)/1.2 var(--display); color: var(--ink); }
.tier small { color: var(--muted); font-size: .8125rem; }
.tier input:checked + span { border-color: var(--ink); background: var(--accent-wash); box-shadow: 3px 3px 0 var(--accent); }
.tier input:focus-visible + span { outline: 3px solid var(--focus); outline-offset: 2px; }
.tier span:hover { border-color: var(--ink); }

.opts { margin: 0 0 16px; padding: 0; border: 0; display: grid; gap: 6px; }
.check { display: flex; gap: 10px; align-items: flex-start; cursor: pointer; font-size: .9375rem; }
.check input { width: 20px; height: 20px; margin: 2px 0 0; accent-color: var(--accent); flex: none; }
.check em { font-style: normal; color: var(--muted); white-space: nowrap; }
.choice-row { display: flex; flex-wrap: wrap; gap: 8px 20px; }

.line-actions { display: flex; flex-wrap: wrap; gap: 8px 20px; margin-top: 4px; }
.btn-link {
  border: 0; background: none; padding: 4px 0; cursor: pointer; font-weight: 700; color: var(--ink);
  text-decoration: underline; text-decoration-thickness: 2px; text-decoration-color: var(--accent); text-underline-offset: 4px;
}
.btn-link:hover { color: var(--accent-text); }
.btn-link.danger { color: var(--danger); text-decoration-color: currentColor; font-weight: 600; }
.btn-link[disabled] { color: var(--muted); text-decoration-color: var(--rule-strong); cursor: default; }

/* ---------- квитанція ---------- */
.ticket { position: relative; }
@media (min-width: 960px) { .ticket { position: sticky; top: 24px; } }
.ticket-inner {
  position: relative; background: var(--surface); border: 2px solid var(--ink); padding: 24px;
}
/* хрести суміщення по кутах — як на друкарському аркуші */
.ticket-inner::before, .ticket-inner::after {
  content: ""; position: absolute; width: 18px; height: 18px;
  background:
    linear-gradient(var(--ink), var(--ink)) center/2px 100% no-repeat,
    linear-gradient(var(--ink), var(--ink)) center/100% 2px no-repeat;
}
.ticket-inner::before { top: -10px; left: -10px; }
.ticket-inner::after { bottom: -10px; right: -10px; }
.ticket-title { margin: 0 0 12px; font: 700 var(--step-1)/1.2 var(--display); color: var(--ink); }
.ticket-lines { list-style: none; margin: 0; padding: 0; }
.ticket-lines li {
  display: flex; justify-content: space-between; gap: 12px; padding: 8px 0;
  border-bottom: 1px dashed var(--rule); font-size: .9375rem;
}
.ticket-lines li span:last-child { white-space: nowrap; font-weight: 600; color: var(--ink); }
.ticket-lines small { display: block; color: var(--muted); font-size: .8125rem; }
.ticket-empty { margin: 0 0 8px; color: var(--muted); font-size: .9375rem; }
.ticket-totals { margin: 12px 0 20px; }
.ticket-totals div { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding: 4px 0; }
.ticket-totals dt { color: var(--muted); }
.ticket-totals dd { margin: 0; color: var(--ink); font-weight: 600; text-align: right; }
.ticket-totals .total { padding-top: 12px; margin-top: 8px; border-top: 2px solid var(--ink); }
.ticket-totals .total dt { color: var(--ink); font-weight: 700; }
.ticket-totals .total dd { font: 800 var(--step-3)/1 var(--display); }
.ticket-note { margin: 14px 0 0; color: var(--muted); font-size: .8125rem; line-height: 1.5; }

/* ---------- кнопки ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 12px 22px; border-radius: 4px; border: 2px solid var(--ink);
  font-weight: 700; cursor: pointer; text-decoration: none;
  transition: transform .1s ease, box-shadow .1s ease;
}
.btn-block { width: 100%; }
.btn-primary { background: #000; color: #fff; border-color: #000; box-shadow: 4px 4px 0 var(--accent); }
.btn-primary:hover:not([disabled]) { transform: translate(-1px, -1px); box-shadow: 5px 5px 0 var(--accent); }
.btn-primary:active:not([disabled]) { transform: translate(3px, 3px); box-shadow: 1px 1px 0 var(--accent); }
.btn-secondary { background: var(--surface); color: var(--ink); }
.btn[disabled] { opacity: .45; cursor: not-allowed; box-shadow: none; }
:root[data-theme="dark"] .btn-primary { border-color: var(--ink); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .btn-primary { border-color: var(--ink); } }

/* ---------- примірка ---------- */
.studio { border-top: 2px solid var(--ink); padding: 40px 0 64px; }
.studio-head { margin-bottom: 24px; }
.studio-lede { max-width: 66ch; margin: 0; }
.studio-grid { display: grid; gap: 24px; }
.studio-grid > *, .layout > * { min-width: 0; }
@media (min-width: 960px) { .studio-grid { grid-template-columns: 300px minmax(0, 1fr); gap: 40px; } }

.drop {
  display: grid; gap: 4px; padding: 20px; border: 2px dashed var(--rule-strong); border-radius: 4px;
  background: var(--surface); cursor: pointer; text-align: left; transition: border-color .15s, background .15s;
}
.drop:hover, .drop.is-over { border-color: var(--accent); background: var(--accent-wash); }
.drop:focus-within { outline: 3px solid var(--focus); outline-offset: 2px; }
.drop-title { font: 700 var(--step-1)/1.2 var(--display); color: var(--ink); }
.drop-hint { color: var(--muted); font-size: .875rem; }
.file-error { margin: 10px 0 0; color: var(--danger); font-size: .875rem; }

.file-list { list-style: none; margin: 16px 0 0; padding: 0; display: grid; gap: 8px; }
.file-item {
  display: grid; grid-template-columns: 48px minmax(0, 1fr); gap: 12px; align-items: center;
  padding: 8px; border: 2px solid var(--rule); border-radius: 4px; background: var(--surface);
  cursor: pointer; text-align: left; width: 100%;
}
.file-item[aria-pressed="true"] { border-color: var(--ink); box-shadow: 3px 3px 0 var(--accent); }
.file-thumb {
  width: 48px; height: 48px; object-fit: contain; border-radius: 2px;
  background: repeating-conic-gradient(#d9dbd6 0% 25%, #fff 0% 50%) 50% / 12px 12px;
}
.file-name { font-weight: 600; font-size: .875rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink); }
.file-sub { display: block; color: var(--muted); font-size: .8125rem; font-weight: 400; }

.file-tools { margin-top: 16px; padding: 16px; border: 1px solid var(--rule); border-radius: 4px; display: grid; gap: 10px; }
.tools-title { margin: 0; font-size: .875rem; font-weight: 700; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tool-sub { display: grid; gap: 10px; padding-left: 30px; }
.range { display: grid; gap: 4px; font-size: .875rem; color: var(--muted); }
.range input { width: 100%; accent-color: var(--accent); }

.tabs { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 12px; scrollbar-width: thin; }
.tab {
  flex: none; padding: 8px 14px; border: 2px solid var(--rule-strong); border-radius: 4px; background: var(--surface);
  cursor: pointer; font-weight: 600; font-size: .9375rem; display: inline-flex; align-items: center; gap: 8px;
}
.tab[aria-selected="true"] { border-color: var(--ink); background: var(--ink); color: var(--paper); }
.tab .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); border: 1.5px solid currentColor; }

.stage-bar { display: flex; flex-wrap: wrap; gap: 8px 20px; align-items: center; margin-bottom: 12px; min-height: 36px; }
.seg { display: inline-flex; border: 2px solid var(--ink); border-radius: 4px; overflow: hidden; }
.seg button { border: 0; background: var(--surface); padding: 6px 14px; cursor: pointer; font-weight: 600; font-size: .875rem; }
.seg button + button { border-left: 2px solid var(--ink); }
.seg button[aria-pressed="true"] { background: var(--accent); color: #000; }
.seg button[disabled] { color: var(--muted); cursor: not-allowed; }
.color-field { display: inline-flex; gap: 8px; align-items: center; font-size: .875rem; font-weight: 600; }
.color-field input { width: 36px; height: 32px; padding: 0; border: 2px solid var(--ink); border-radius: 4px; background: none; cursor: pointer; }
.bar-hint { color: var(--muted); font-size: .8125rem; }

.stage {
  position: relative; background: var(--mat-dark); border-radius: 4px; overflow: hidden;
  aspect-ratio: 1 / 1; max-height: 78vh; margin: 0 auto;
}
.stage canvas { width: 100%; height: 100%; object-fit: contain; touch-action: none; cursor: grab; }
.stage canvas.is-dragging { cursor: grabbing; }
.stage-empty {
  position: absolute; left: 16px; right: 16px; bottom: 16px; margin: 0; padding: 10px 14px;
  background: rgba(0,0,0,.6); color: #fff; border-radius: 4px; font-size: .9375rem; text-align: center;
}

.stage-controls { display: grid; gap: 12px; margin-top: 16px; }
@media (min-width: 720px) { .stage-controls { grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr) auto; align-items: end; } }
.stage-controls label { display: grid; gap: 4px; font-size: .875rem; font-weight: 600; color: var(--ink); }
.stage-controls .check { display: flex; align-items: center; font-weight: 600; }
.stage-controls > * { min-width: 0; }
.stage-controls select {
  width: 100%; min-width: 0; text-overflow: ellipsis;
  min-height: 40px; padding: 6px 10px; border: 2px solid var(--rule-strong); border-radius: 4px; background: var(--surface);
}
.stage-controls input[type="range"] { width: 100%; accent-color: var(--accent); }
.readout { font-weight: 400; color: var(--muted); }
.ctrl-buttons { display: flex; gap: 8px; flex-wrap: wrap; }
.btn-small { min-height: 40px; padding: 6px 14px; font-size: .875rem; box-shadow: none; }
.stage-controls.is-calibrating { grid-template-columns: 1fr; }
.calib { display: grid; gap: 12px; padding: 16px; border: 2px solid var(--ink); border-radius: 4px; background: var(--accent-wash); }
.calib p { margin: 0; max-width: 70ch; font-size: .9375rem; }
.calib textarea { width: 100%; padding: 10px; border: 2px solid var(--rule-strong); border-radius: 4px; background: var(--surface); font: 500 .875rem/1.5 ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace; }
.calib button { justify-self: start; }
.stage-warn { min-height: 1.5em; margin: 10px 0 0; color: var(--ink); font-weight: 600; font-size: .9375rem; }
.stage-warn:not(:empty) { padding: 8px 12px; background: var(--accent-wash); border-left: 4px solid var(--accent); }

/* ---------- футер і мобільна панель ---------- */
.footer { border-top: 1px solid var(--rule); padding: 24px 0 120px; color: var(--muted); font-size: .875rem; }
@media (min-width: 960px) { .footer { padding-bottom: 32px; } }

.mobile-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 12px max(16px, env(safe-area-inset-right, 0px)) calc(12px + env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px));
  background: var(--surface); border-top: 2px solid var(--ink);
}
.mobile-total { display: block; font: 800 var(--step-1)/1.1 var(--display); color: var(--ink); }
.mobile-meta { display: block; color: var(--muted); font-size: .8125rem; }
@media (min-width: 960px) { .mobile-bar { display: none; } }

/* ---------- діалоги ---------- */
.dialog {
  width: min(560px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); padding: 0;
  border: 2px solid var(--ink); border-radius: 4px; background: var(--surface); color: var(--text);
  box-shadow: 8px 8px 0 var(--accent);
}
.dialog::backdrop { background: rgba(10, 10, 10, .55); }
.dialog[open] { animation: rise .2s ease-out; }
@keyframes rise { from { transform: translateY(12px); opacity: 0; } }
.dialog-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 18px 20px 0; }
.dialog-head h2 { margin: 0; font: 700 var(--step-2)/1.2 var(--display); color: var(--ink); }
.dialog-close { width: 40px; height: 40px; border: 0; background: none; font-size: 1.75rem; line-height: 1; cursor: pointer; color: var(--ink); }
.dialog-body { padding: 16px 20px 8px; display: grid; gap: 14px; }
.dialog-foot { padding: 8px 20px 20px; }

.recap { padding: 12px 14px; background: var(--accent-wash); border-radius: 4px; font-size: .9375rem; }
.recap strong { font-family: var(--display); color: var(--ink); }
.recap p { margin: 0; }
.recap p + p { margin-top: 4px; color: var(--text); }

.field { display: grid; gap: 6px; font-weight: 600; font-size: .9375rem; color: var(--ink); }
.field em { font-style: normal; font-weight: 400; color: var(--muted); }
.field input, .field textarea {
  width: 100%; padding: 11px 12px; border: 2px solid var(--rule-strong); border-radius: 4px;
  background: var(--paper); font-weight: 400; color: var(--text);
}
.field input:focus, .field textarea:focus { border-color: var(--ink); outline: none; box-shadow: 3px 3px 0 var(--accent); }
.field input[aria-invalid="true"] { border-color: var(--danger); }
.field textarea { resize: vertical; min-height: 84px; }
.hp { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }
.form-error { margin: 0; color: var(--danger); font-weight: 600; font-size: .9375rem; }

.sent { padding: 32px 24px 28px; }
.sent h2 { margin: 0 0 12px; font: 800 var(--step-3)/1.1 var(--display); color: var(--ink); text-shadow: .05em .035em 0 var(--accent); }
.sent p { margin: 0 0 24px; max-width: 44ch; }

.dialog-gallery { width: min(960px, calc(100vw - 24px)); }
.gallery { padding: 16px 20px 20px; display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.gallery img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 2px; background: var(--paper); }
.gallery-empty { color: var(--muted); grid-column: 1 / -1; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
