/* Mini App «Империя Дыма». Цвета берутся из темы Telegram (--tg-*), бренд — только в карте гостя. */
:root {
  --bg: var(--tg-bg, #ffffff);
  --bg2: var(--tg-secondary-bg, #f2f1f4);
  --section: var(--tg-section-bg, #ffffff);
  --text: var(--tg-text, #18151c);
  --hint: var(--tg-hint, #8a8590);
  --link: var(--tg-link, #8a5a1f);
  --btn: var(--tg-button, #8a5a1f);
  --btn-text: var(--tg-button-text, #ffffff);
  --accent: var(--tg-accent, #b7792f);
  --danger: var(--tg-destructive, #d33c3c);
  --ok: #2e9e5b;
  --line: color-mix(in srgb, var(--text) 10%, transparent);
  --soft: color-mix(in srgb, var(--btn) 12%, var(--section));
  --brand-1: #231c27;
  --brand-2: #4b3523;
  --brand-gold: #e9c47e;
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: var(--tg-bg, #17141a); --bg2: var(--tg-secondary-bg, #0f0d11); --section: var(--tg-section-bg, #1f1b23);
    --text: var(--tg-text, #f3eff5); --hint: var(--tg-hint, #9b94a0); --link: var(--tg-link, #e2b46b);
    --btn: var(--tg-button, #c48a3f); --btn-text: var(--tg-button-text, #1b130a); --accent: var(--tg-accent, #e2b46b);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: var(--tg-bg, #17141a); --bg2: var(--tg-secondary-bg, #0f0d11); --section: var(--tg-section-bg, #1f1b23);
  --text: var(--tg-text, #f3eff5); --hint: var(--tg-hint, #9b94a0); --link: var(--tg-link, #e2b46b);
  --btn: var(--tg-button, #c48a3f); --btn-text: var(--tg-button-text, #1b130a); --accent: var(--tg-accent, #e2b46b);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg2); color: var(--text);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent;
  min-height: 100vh;
}
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--link); }
.num { font-variant-numeric: tabular-nums; }

/* ---------- Каркас ---------- */
.topbar {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 12px;
  padding: 10px max(16px, env(safe-area-inset-right, 0px)) 10px max(16px, env(safe-area-inset-left, 0px));
  background: var(--bg2);
}
.topbar-title { font-weight: 700; font-size: 17px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mode-switch {
  border: 0; border-radius: 999px; padding: 6px 12px; background: var(--soft); color: var(--link);
  font-weight: 600; font-size: 13px; white-space: nowrap;
}
.screen {
  padding: 4px max(16px, env(safe-area-inset-right, 0px)) calc(84px + env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px));
  max-width: 1100px; margin: 0 auto; display: flex; flex-direction: column; gap: 14px;
}
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; display: flex;
  background: var(--section); border-top: 1px solid var(--line);
  padding: 6px max(6px, env(safe-area-inset-right, 0px)) calc(6px + env(safe-area-inset-bottom, 0px)) max(6px, env(safe-area-inset-left, 0px));
}
.tab {
  flex: 1; min-width: 0; border: 0; background: none; padding: 6px 2px; border-radius: 10px;
  display: flex; flex-direction: column; align-items: center; gap: 2px; color: var(--hint); font-size: 11px;
}
.tab svg { width: 24px; height: 24px; }
.tab[aria-current="page"] { color: var(--btn); }
.tab span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }

/* ---------- Блоки ---------- */
.section { background: var(--section); border-radius: var(--radius); padding: 14px 16px; }
.section > h2, .h2 { margin: 0 0 10px; font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--hint); font-weight: 600; }
.h1 { margin: 6px 0 0; font-size: 22px; font-weight: 750; text-wrap: balance; }
.muted { color: var(--hint); }
.small { font-size: 13px; }
.row { display: flex; align-items: center; gap: 12px; }
.row > .grow, .item > .grow { flex: 1; min-width: 0; }
.list { display: flex; flex-direction: column; }
.list > .item { display: flex; align-items: center; gap: 12px; padding: 11px 0; border-top: 1px solid var(--line); }
.list > .item:first-child { border-top: 0; padding-top: 2px; }
.item .title { font-weight: 600; }
.item .sub { color: var(--hint); font-size: 13px; }
.chips { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  border: 1px solid var(--line); background: var(--section); border-radius: 999px; padding: 7px 13px;
  font-size: 14px; white-space: nowrap; flex: none;
}
.chip[aria-pressed="true"] { background: var(--btn); color: var(--btn-text); border-color: var(--btn); }
.badge { display: inline-block; border-radius: 999px; padding: 2px 9px; font-size: 12px; font-weight: 600; background: var(--soft); color: var(--link); white-space: nowrap; }
.badge.ok { background: color-mix(in srgb, var(--ok) 15%, transparent); color: var(--ok); }
.badge.bad { background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); }
.badge.wait { background: color-mix(in srgb, var(--accent) 18%, transparent); color: var(--accent); }

.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%;
  border: 0; border-radius: 12px; padding: 13px 16px; background: var(--btn); color: var(--btn-text);
  font-weight: 650; font-size: 16px;
}
.btn.secondary { background: var(--soft); color: var(--link); }
.btn.small { width: auto; padding: 8px 12px; font-size: 14px; border-radius: 10px; }
.btn.danger { background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); }
.btn:disabled { opacity: .55; }
.btns { display: flex; gap: 8px; }
.btns > .btn { flex: 1; }

/* ---------- Карта гостя ---------- */
.card {
  position: relative; overflow: hidden; border-radius: 20px; padding: 20px; color: #fbf5ea;
  background: radial-gradient(120% 90% at 100% 0%, #6a4a2c 0%, transparent 60%),
              radial-gradient(90% 80% at 0% 100%, #3b2a40 0%, transparent 65%),
              linear-gradient(135deg, var(--brand-1), var(--brand-2));
  box-shadow: 0 10px 30px -14px rgba(30, 18, 8, .7);
  min-height: 196px; display: flex; flex-direction: column; gap: 14px;
}
.card::after { /* лёгкий «дым» */
  content: ""; position: absolute; inset: -40% -20% auto auto; width: 70%; height: 140%;
  background: radial-gradient(closest-side, rgba(255,255,255,.07), transparent); transform: rotate(-18deg); pointer-events: none;
}
.card-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.card-brand { font-size: 13px; letter-spacing: .18em; text-transform: uppercase; color: var(--brand-gold); font-weight: 650; }
.card-level { font-size: 12px; border: 1px solid rgba(233,196,126,.45); color: var(--brand-gold); border-radius: 999px; padding: 3px 10px; white-space: nowrap; }
.card-balance { font-size: 44px; font-weight: 760; line-height: 1; letter-spacing: -.02em; }
.card-balance small { font-size: 16px; font-weight: 600; color: rgba(251,245,234,.7); letter-spacing: 0; margin-left: 6px; }
.card-bottom { display: flex; flex-direction: column; gap: 2px; margin-top: auto; }
.card-name { font-weight: 650; font-size: 16px; }
.card-phone { font-size: 22px; white-space: nowrap; font-weight: 650; letter-spacing: .02em; color: var(--brand-gold); }
.card-hint { font-size: 12px; color: rgba(251,245,234,.65); }
.stats3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat { background: var(--section); border-radius: 12px; padding: 10px 12px; min-width: 0; }
.stat b { display: block; font-size: 18px; }
.stat span { color: var(--hint); font-size: 12px; }

.switch { position: relative; width: 50px; height: 30px; flex: none; }
.switch input { opacity: 0; width: 100%; height: 100%; margin: 0; position: absolute; cursor: pointer; z-index: 1; }
.switch i { position: absolute; inset: 0; border-radius: 999px; background: color-mix(in srgb, var(--hint) 45%, transparent); transition: background .2s; }
.switch i::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; transition: transform .2s; box-shadow: 0 1px 3px rgba(0,0,0,.25); }
.switch input:checked + i { background: var(--ok); }
.switch input:checked + i::after { transform: translateX(20px); }
.switch input:focus-visible + i { outline: 2px solid var(--btn); outline-offset: 2px; }

/* ---------- Акции и меню ---------- */
.promo { position: relative; padding-left: 14px; }
.promo::before { content: ""; position: absolute; left: 0; top: 3px; bottom: 3px; width: 4px; border-radius: 4px; background: var(--line); }
.promo.today::before { background: var(--accent); }
.promo .title { font-weight: 650; font-size: 16px; }
.promo p { margin: 4px 0 0; }
.menu-item { display: flex; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); align-items: baseline; }
.menu-item:first-of-type { border-top: 0; }
.menu-item .name { flex: 1; min-width: 0; }
.menu-item .price { font-weight: 650; white-space: nowrap; }

/* ---------- Формы ---------- */
.field { display: flex; flex-direction: column; gap: 6px; }
.field > label, .label { font-size: 13px; color: var(--hint); font-weight: 600; }
.input, select.input, textarea.input {
  width: 100%; border: 1px solid var(--line); border-radius: 12px; padding: 12px 13px; background: var(--bg);
  outline: none; min-width: 0;
}
.input:focus { border-color: var(--btn); }
textarea.input { resize: vertical; min-height: 76px; }
.form { display: flex; flex-direction: column; gap: 14px; }
.stepper { display: flex; align-items: center; gap: 0; border: 1px solid var(--line); border-radius: 12px; width: fit-content; overflow: hidden; }
.stepper button { border: 0; background: var(--soft); color: var(--link); width: 46px; height: 44px; font-size: 22px; }
.stepper output { width: 56px; text-align: center; font-weight: 700; font-size: 18px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* ---------- История ---------- */
.amount { font-weight: 700; white-space: nowrap; }
.amount.plus { color: var(--ok); }
.amount.minus { color: var(--danger); }
.day-label { font-size: 13px; color: var(--hint); font-weight: 600; margin: 4px 0 -4px; }
.notice { border-radius: 12px; padding: 12px 14px; background: color-mix(in srgb, var(--accent) 14%, var(--section)); }
.notice.bad { background: color-mix(in srgb, var(--danger) 12%, var(--section)); }
.empty { text-align: center; color: var(--hint); padding: 26px 10px; }
.empty .big { font-size: 40px; display: block; margin-bottom: 6px; }

/* ---------- Дашборд ---------- */
.kpis { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
@media (min-width: 640px) { .kpis { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.kpi { background: var(--section); border-radius: var(--radius); padding: 12px 14px; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.kpi .k-label { color: var(--hint); font-size: 12.5px; }
.kpi .k-value { font-size: 23px; font-weight: 750; letter-spacing: -.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi .k-delta { font-size: 12.5px; font-weight: 600; color: var(--hint); }
.kpi .k-delta.up { color: var(--ok); }
.kpi .k-delta.down { color: var(--danger); }
.dash-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; }
@media (min-width: 820px) { .dash-grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.chart { width: 100%; height: auto; display: block; overflow: visible; max-width: 100%; }
.chart text { fill: var(--hint); font-size: 10px; font-family: inherit; }
.chart .axis { stroke: var(--line); }
.chart .bar { fill: var(--btn); }
.chart .bar.dim { fill: color-mix(in srgb, var(--btn) 35%, transparent); }
.chart .line { fill: none; stroke: var(--accent); stroke-width: 2; }
.chart .val { fill: var(--text); font-weight: 600; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12.5px; color: var(--hint); margin-top: 8px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.hbar { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 10px; align-items: center; }
.hbar .track { grid-column: 1 / -1; height: 8px; border-radius: 6px; background: var(--bg2); overflow: hidden; }
.hbar .fill { height: 100%; background: var(--btn); border-radius: 6px; }
.hbar .lbl { font-size: 13.5px; min-width: 0; }
.hbar .v { font-weight: 650; font-size: 13.5px; }
.stack { display: flex; flex-direction: column; gap: 10px; }

.table-wrap { overflow-x: auto; margin: 0 -16px; padding: 0 16px; }
table.t { border-collapse: collapse; width: 100%; min-width: 640px; font-size: 13.5px; }
table.t th { text-align: left; color: var(--hint); font-weight: 600; font-size: 12px; padding: 8px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; user-select: none; }
table.t th.sortable { cursor: pointer; }
table.t th .arrow { opacity: .8; margin-left: 2px; }
table.t td { padding: 9px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.t td.r, table.t th.r { text-align: right; white-space: nowrap; }
table.t tr:last-child td { border-bottom: 0; }
table.t .who b { display: block; font-weight: 600; }
table.t .who span { color: var(--hint); font-size: 12.5px; white-space: nowrap; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.toolbar .input { flex: 1; min-width: 160px; padding: 10px 12px; }
.period { display: flex; flex-direction: column; gap: 8px; }
.period .custom { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.period .custom .input { width: auto; flex: 1; min-width: 130px; padding: 9px 10px; }
.stars { color: var(--accent); letter-spacing: 1px; white-space: nowrap; }
.editor-item { border: 1px solid var(--line); border-radius: 12px; padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.days { display: flex; gap: 6px; flex-wrap: wrap; }
.days label { display: flex; align-items: center; gap: 4px; border: 1px solid var(--line); border-radius: 8px; padding: 5px 8px; font-size: 13px; }
.menu-edit-row { display: grid; grid-template-columns: minmax(0, 1fr) 96px 40px; gap: 6px; align-items: center; }
.icon-btn { border: 0; background: none; color: var(--danger); font-size: 20px; padding: 6px; border-radius: 8px; }

/* ---------- Прочее ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(86px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%);
  max-width: calc(100% - 32px); background: color-mix(in srgb, var(--text) 88%, transparent); color: var(--bg);
  padding: 10px 16px; border-radius: 12px; font-size: 14px; z-index: 20; text-align: center;
}
.loader { display: flex; justify-content: center; gap: 6px; padding: 60px 0; }
.loader span { width: 8px; height: 8px; border-radius: 50%; background: var(--hint); animation: pulse 1s infinite ease-in-out; }
.loader span:nth-child(2) { animation-delay: .15s; } .loader span:nth-child(3) { animation-delay: .3s; }
@keyframes pulse { 0%, 80%, 100% { opacity: .25; transform: scale(.8); } 40% { opacity: 1; transform: scale(1); } }
@media (prefers-reduced-motion: reduce) { .loader span { animation: none; opacity: .6; } .switch i, .switch i::after { transition: none; } }
.center-screen { min-height: 70vh; display: flex; flex-direction: column; justify-content: center; align-items: center; text-align: center; gap: 12px; padding: 0 12px; }
.center-screen .big { font-size: 54px; }

.item.wrap { flex-wrap: wrap; }
.item.wrap > .grow { flex-basis: 60%; }

/* Лента разделов меню закреплена под шапкой */
.menu-nav {
  position: sticky; top: var(--topbar-h, 52px); z-index: 4;
  margin: -6px calc(-1 * max(16px, env(safe-area-inset-right, 0px))) -4px calc(-1 * max(16px, env(safe-area-inset-left, 0px)));
  padding: 6px max(16px, env(safe-area-inset-right, 0px)) 8px max(16px, env(safe-area-inset-left, 0px));
  background: var(--bg2); box-shadow: 0 1px 0 var(--line);
}
.menu-nav .chips { scroll-behavior: smooth; }

/* ---------- Блюдо: строка меню, карточка, редактор ---------- */
.menu-item.tappable { width: 100%; border: 0; border-top: 1px solid var(--line); background: none; padding: 10px 0; text-align: left; align-items: center; font: inherit; color: inherit; }
.menu-item.tappable:first-of-type { border-top: 0; }
.menu-item.tappable:active { opacity: .6; }
.menu-item .desc { color: var(--hint); font-size: 13px; margin-top: 2px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.thumb { width: 56px; height: 56px; border-radius: 10px; object-fit: cover; flex: none; background: var(--bg2); }
.thumb.big { width: 96px; height: 96px; border-radius: 12px; }
.thumb.empty { display: flex; align-items: center; justify-content: center; color: var(--hint); font-size: 12px; text-align: center; }
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 30; display: flex; align-items: flex-end; justify-content: center;
  background: rgba(0, 0, 0, 0); transition: background .2s;
}
.sheet-backdrop.open { background: rgba(0, 0, 0, .45); }
.sheet {
  position: relative; width: 100%; max-width: 560px; max-height: 88vh; overflow-y: auto; overscroll-behavior: contain;
  background: var(--section); border-radius: 18px 18px 0 0; padding-bottom: env(safe-area-inset-bottom, 0px);
  transform: translateY(100%); transition: transform .22s ease-out;
}
.sheet-backdrop.open .sheet { transform: none; }
.sheet-close {
  position: absolute; top: 10px; right: 10px; z-index: 1; width: 34px; height: 34px; border-radius: 50%; border: 0;
  background: color-mix(in srgb, var(--section) 80%, transparent); color: var(--text); font-size: 16px;
}
.sheet-photo { display: block; width: 100%; max-width: 100%; aspect-ratio: 4 / 3; object-fit: cover; background: var(--bg2); }
.sheet-body { padding: 16px max(16px, env(safe-area-inset-right, 0px)) 20px max(16px, env(safe-area-inset-left, 0px)); display: flex; flex-direction: column; gap: 8px; }
.sheet-body > .row:first-child { padding-right: 36px; }
.sheet-photo + .sheet-body > .row:first-child { padding-right: 0; }
.sheet-title { font-size: 20px; font-weight: 750; text-wrap: balance; }
.sheet-price { font-size: 18px; font-weight: 700; white-space: nowrap; }
.sheet-text { margin: 0; line-height: 1.45; }
.sheet-body .label { margin-top: 6px; }
.nutri { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
.nutri > div { background: var(--bg2); border-radius: 10px; padding: 8px 6px; text-align: center; min-width: 0; }
.nutri b { display: block; font-size: 17px; }
.nutri span { color: var(--hint); font-size: 11.5px; }
@media (prefers-reduced-motion: reduce) { .sheet, .sheet-backdrop { transition: none; } }
.dish-edit { display: flex; flex-direction: column; gap: 4px; padding: 6px 0; border-top: 1px solid var(--line); }
.dish-edit:first-of-type { border-top: 0; }
.link-btn { border: 0; background: none; color: var(--link); padding: 2px 0; font-size: 13.5px; font-weight: 600; align-self: flex-start; text-align: left; }
.link-btn .muted { font-weight: 400; }
.dish-details { display: flex; flex-direction: column; gap: 10px; padding: 8px 0 6px; }
.photo-row { display: flex; gap: 12px; align-items: center; }
.file-btn { position: relative; overflow: hidden; }
.file-btn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.grid4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
.grid4 .input, .grid2 .input { padding: 10px 8px; }
