/* Дымок27 — витрина Mini App.
   Без препроцессоров и сборки: обычный CSS с переменными, тема — через
   prefers-color-scheme (MAX умеет обе). Цвета — из палитры assets/logo.svg:
   уголь #2A2522, янтарь #E8963F, светлый фон #F5E9D8.
*/

* {
  box-sizing: border-box;
}

html,
body,
h1,
h2,
h3,
p,
ul,
form,
fieldset {
  margin: 0;
  padding: 0;
}

fieldset {
  border: none;
}

button {
  font: inherit;
  color: inherit;
}

:root {
  --coal: #2a2522;
  --amber: #e8963f;
  --cream: #f5e9d8;

  --bg: var(--cream);
  --surface: #ffffff;
  --surface-alt: #fbf3e7;
  --text: var(--coal);
  --text-muted: #7a6e62;
  --border: #e4d3ba;

  --accent: var(--amber);
  --accent-contrast: var(--coal);
  --danger: #c0392b;
  --success: #3e8e5a;
  --info: #3e72c4;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #201c1a;
    --surface: #2e2824;
    --surface-alt: #362f29;
    --text: #f5e9d8;
    --text-muted: #b7a996;
    --border: #473c33;

    --accent: var(--amber);
    --accent-contrast: #201c1a;
    --danger: #e5695a;
    --success: #55b67d;
    --info: #6fa0e8;
  }
}

/* Виджет темы в самом артефакте-превью выставляет data-theme на <html> —
   тот же приоритет учитываем и здесь, MAX сам решает через prefers-color-scheme. */
:root[data-theme="dark"] {
  --bg: #201c1a;
  --surface: #2e2824;
  --surface-alt: #362f29;
  --text: #f5e9d8;
  --text-muted: #b7a996;
  --border: #473c33;
  --accent-contrast: #201c1a;
  --danger: #e5695a;
  --success: #55b67d;
  --info: #6fa0e8;
}

:root[data-theme="light"] {
  --bg: var(--cream);
  --surface: #ffffff;
  --surface-alt: #fbf3e7;
  --text: var(--coal);
  --text-muted: #7a6e62;
  --border: #e4d3ba;
  --accent-contrast: var(--coal);
  --danger: #c0392b;
  --success: #3e8e5a;
  --info: #3e72c4;
}

html {
  height: 100%;
  /* iOS зумит инпуты мельче 16px при фокусе — держим базовый размер не ниже */
  font-size: 16px;
}

body {
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font-family:
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    Roboto,
    Helvetica,
    Arial,
    sans-serif;
  line-height: 1.4;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- шапка ---------- */

#head {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: calc(0.75rem + var(--safe-top)) 1rem 0.75rem;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  max-width: 560px;
  width: 100%;
  margin-inline: auto;
}

#back {
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 50%;
  background: var(--surface-alt);
  color: var(--text);
  font-size: 1.2rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

#back[hidden] {
  display: none;
}

#head-titles h1 {
  font-size: 1.15rem;
  font-weight: 700;
}

#head-titles p {
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* ---------- контент ---------- */

#screen {
  flex: 1 1 auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  max-width: 560px;
  width: 100%;
  margin-inline: auto;
  padding: 0.75rem 1rem calc(1.5rem + var(--safe-bottom));
}

/* ---------- нижняя панель ---------- */

#bar {
  flex: 0 0 auto;
  padding: 0.6rem 1rem calc(0.6rem + var(--safe-bottom));
  background: var(--bg);
  border-top: 1px solid var(--border);
  max-width: 560px;
  width: 100%;
  margin-inline: auto;
}

#bar[hidden] {
  display: none;
}

#to-cart {
  width: 100%;
  min-height: 48px;
  border: none;
  border-radius: 12px;
  background: var(--accent);
  color: var(--accent-contrast);
  font-weight: 700;
  font-size: 1rem;
}

/* ---------- кнопки общего вида ---------- */

.btn {
  min-height: 48px;
  padding: 0 1.25rem;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
  font-size: 0.95rem;
}

.btn-accent {
  background: var(--accent);
  color: var(--accent-contrast);
  border: none;
}

.btn-block {
  width: 100%;
  display: block;
}

.btn:disabled {
  opacity: 0.45;
}

/* ---------- категории: быстрый переход ---------- */

.cat-nav {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  gap: 0.5rem;
  overflow-x: auto;
  padding: 0.25rem 0 0.75rem;
  margin: 0 -1rem 0.5rem;
  padding-inline: 1rem;
  background: var(--bg);
  scrollbar-width: none;
}

.cat-nav::-webkit-scrollbar {
  display: none;
}

.chip {
  flex: 0 0 auto;
  min-height: 40px;
  padding: 0 0.9rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 0.9rem;
  white-space: nowrap;
}

.cat-heading {
  font-size: 1.05rem;
  font-weight: 700;
  padding: 0.75rem 0 0.5rem;
  scroll-margin-top: 3.25rem;
}

.cat-section:first-of-type .cat-heading {
  padding-top: 0.1rem;
}

.cat-products {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

/* ---------- карточка товара ---------- */

.card {
  display: flex;
  gap: 0.75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 0.7rem;
}

.card-photo {
  flex: 0 0 auto;
  width: 68px;
  height: 68px;
  border-radius: 10px;
  object-fit: cover;
  background: var(--surface-alt);
}

.card-photo--placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.6rem;
}

.card-body {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.card-title {
  font-size: 1rem;
  font-weight: 700;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
}

.card-desc {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.card-price {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
}

.card-note {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-style: italic;
}

.badge {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  background: var(--surface-alt);
  color: var(--text-muted);
  border: 1px solid var(--border);
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

/* ---------- варианты и счётчик количества ---------- */

.variant-row {
  padding-top: 0.35rem;
  border-top: 1px dashed var(--border);
  margin-top: 0.25rem;
}

.variant-row:first-of-type {
  border-top: none;
  margin-top: 0;
  padding-top: 0;
}

.variant-row-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.5rem;
  font-size: 0.85rem;
  margin-bottom: 0.3rem;
}

.variant-label {
  font-weight: 600;
}

.variant-caption {
  color: var(--text-muted);
  white-space: nowrap;
}

.stepper-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.stepper-add {
  min-height: 44px;
  padding: 0 1.1rem;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-contrast);
  border: none;
  font-weight: 700;
  font-size: 0.9rem;
}

.stepper {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--surface-alt);
  border-radius: 999px;
  padding: 0.2rem;
}

.stepper-btn {
  width: 40px;
  height: 40px;
  flex: 0 0 auto;
  border-radius: 50%;
  border: none;
  background: var(--surface);
  color: var(--text);
  font-size: 1.15rem;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.stepper-btn--danger {
  color: var(--danger);
}

.stepper-btn:disabled {
  opacity: 0.35;
}

.stepper-value {
  min-width: 4.2em;
  text-align: center;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  font-size: 0.92rem;
}

.stepper-total {
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--text);
}

/* ---------- корзина ---------- */

.cart-lines {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.cart-line {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 0.65rem 0.7rem;
}

.cart-line-info {
  flex: 1 1 auto;
  min-width: 0;
}

.cart-line-name {
  font-weight: 700;
  font-size: 0.95rem;
}

.cart-line-price {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-top: 0.1rem;
}

.cart-remove {
  flex: 0 0 auto;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  background: var(--surface-alt);
  color: var(--danger);
  font-size: 1.1rem;
}

.cart-total-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 0.2rem;
  font-size: 1.05rem;
  font-weight: 700;
  border-top: 1px solid var(--border);
  margin-top: 0.75rem;
}

/* ---------- форма оформления ---------- */

.field {
  display: block;
  margin-bottom: 0.85rem;
}

.field-label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 0.3rem;
}

.field-hint {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 0.3rem;
}

.field[hidden] {
  display: none;
}

input[type="text"],
input[type="tel"],
textarea {
  width: 100%;
  min-height: 44px;
  padding: 0.6rem 0.75rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 1rem;
  font-family: inherit;
}

textarea {
  resize: vertical;
}

.field-invalid {
  border-color: var(--danger);
}

.segmented {
  display: flex;
  gap: 0.5rem;
}

.segmented-btn {
  flex: 1 1 0;
  min-height: 48px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
  font-size: 0.92rem;
}

.segmented-btn.is-active {
  background: var(--accent);
  color: var(--accent-contrast);
  border-color: var(--accent);
}

.checkout-total {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 0.1rem;
  font-size: 1.05rem;
  font-weight: 700;
  margin-bottom: 0.85rem;
}

/* ---------- уведомления ---------- */

.banner {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.6rem;
  padding: 0.7rem 0.85rem;
  border-radius: 10px;
  border-left: 4px solid var(--accent);
  background: var(--surface-alt);
  font-size: 0.88rem;
  margin-bottom: 0.75rem;
}

.banner--error {
  border-left-color: var(--danger);
}

.banner--info {
  border-left-color: var(--info);
}

.banner[hidden] {
  display: none;
}

.banner-close {
  flex: 0 0 auto;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 1rem;
  width: 32px;
  height: 32px;
}

/* ---------- пустые состояния и статусы ---------- */

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 1rem;
  padding: 3rem 1rem;
  color: var(--text-muted);
}

.success-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 0.6rem;
  padding: 3rem 1.5rem;
}

.success-badge {
  font-size: 2.6rem;
}

.success-state h2 {
  font-size: 1.2rem;
}

.success-state .btn {
  margin-top: 1rem;
}
