/* Общая дизайн-система zakazo: токены и компоненты для консоли владельца и панели заведения.
   Характер: спокойная, точная. Нейтральные поверхности, один акцент (бирюзовый),
   смысловые цвета только для статусов. Сетка 4px. Текст: 12 / 13 / 14 / 16 / 20 / 28, веса 400, 500, 600. */

:root {
  --bg: #f3f2ef;
  --surface: #ffffff;
  --surface-2: #f6f5f2;
  --sunken: #eceae6;
  --text: #1b1a18;
  --text-2: #5c5a55;
  --muted: #8a8781;
  --line: rgba(27, 26, 24, 0.09);
  --line-strong: rgba(27, 26, 24, 0.18);
  --accent: #0b6e75;
  --accent-soft: #e0eff0;
  --ok: #1b7a46;
  --ok-soft: #e1f1e7;
  --warn: #965800;
  --warn-soft: #faecd0;
  --danger: #b3322a;
  --danger-soft: #f9e4e1;
  --ink: #1b1a18;
  --ink-text: #f7f1e6;
  --brand-tile: #17130f;
  --brand-z: #f3e7d3;
  --shadow-pop: 0 8px 32px rgba(20, 18, 14, 0.16), 0 1px 3px rgba(20, 18, 14, 0.08);

  --r-ctl: 8px;
  --r-card: 12px;
  --r-sheet: 16px;

  --font: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --mono: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;

  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --t-fast: 120ms;
  --t-med: 220ms;

  --side-w: 240px;
  --tabbar-h: 60px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111110;
    --surface: #1a1a18;
    --surface-2: #20201e;
    --sunken: #0d0d0c;
    --text: #ecebe7;
    --text-2: #a9a7a0;
    --muted: #7d7b75;
    --line: rgba(236, 235, 231, 0.09);
    --line-strong: rgba(236, 235, 231, 0.18);
    --accent: #55bcc4;
    --accent-soft: #15292b;
    --ok: #55c283;
    --ok-soft: #14291d;
    --warn: #e0a64a;
    --warn-soft: #2c2310;
    --danger: #ee7b72;
    --danger-soft: #2f1816;
    --ink: #ecebe7;
    --ink-text: #1b1a18;
    --brand-tile: #2a2a28;
    --shadow-pop: 0 8px 32px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(236, 235, 231, 0.06);
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 14px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
}
h1, h2, h3, p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }
.hidden { display: none !important; }
.num { font-variant-numeric: tabular-nums; }
.mono { font-family: var(--mono); font-size: 0.92em; }
.muted { color: var(--text-2); }
.faint { color: var(--muted); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

.icon { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- логотип ---------- */
.logo { --lt: var(--brand-tile); --lz: var(--brand-z); display: block; height: 24px; width: auto; color: var(--text); }

/* ---------- кнопки ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 40px; padding: 0 16px;
  border: 1px solid var(--line-strong); border-radius: var(--r-ctl);
  background: var(--surface); color: var(--text);
  font-weight: 500; white-space: nowrap; cursor: pointer;
  transition: background-color var(--t-fast), border-color var(--t-fast), color var(--t-fast), transform var(--t-fast);
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: scale(0.98); }
.btn[disabled] { opacity: 0.5; cursor: default; pointer-events: none; }
.btn-primary { background: var(--ink); color: var(--ink-text); border-color: transparent; }
.btn-primary:hover { background: var(--ink); opacity: 0.88; }
.btn-quiet { border-color: transparent; background: transparent; color: var(--text-2); }
.btn-quiet:hover { background: var(--sunken); color: var(--text); }
.btn-danger { color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); border-color: transparent; }
.btn-danger-solid { background: var(--danger); color: #fff; border-color: transparent; }
.btn-danger-solid:hover { background: var(--danger); opacity: 0.9; }
.btn-ok-solid { background: var(--ok); color: #fff; border-color: transparent; }
.btn-ok-solid:hover { background: var(--ok); opacity: 0.9; }
.btn-ok { color: var(--ok); }
.btn-ok:hover { background: var(--ok-soft); border-color: transparent; }
.btn-sm { height: 32px; padding: 0 12px; font-size: 13px; }
.btn-block { width: 100%; }
.btn .spin { display: none; }
.btn.busy { pointer-events: none; opacity: 0.8; }
.btn.busy .spin { display: block; }
.icon-btn {
  display: inline-grid; place-items: center; width: 40px; height: 40px; flex: none;
  border: 0; border-radius: var(--r-ctl); background: transparent; color: var(--text-2); cursor: pointer;
  transition: background-color var(--t-fast), color var(--t-fast);
}
.icon-btn:hover { background: var(--sunken); color: var(--text); }

.spin { width: 16px; height: 16px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin 700ms linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- поля ---------- */
.field { display: grid; gap: 6px; }
.field > label, .field-label { font-size: 13px; font-weight: 500; color: var(--text-2); }
.input, .textarea, .select {
  width: 100%; height: 40px; padding: 0 12px;
  border: 1px solid var(--line-strong); border-radius: var(--r-ctl);
  background: var(--surface); color: var(--text);
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}
.textarea { height: auto; min-height: 88px; padding: 10px 12px; resize: vertical; line-height: 1.45; }
.input::placeholder, .textarea::placeholder { color: var(--muted); }
.input, .textarea, .select { -webkit-appearance: none; appearance: none; }
.input:hover:not(:focus):not([disabled]), .textarea:hover:not(:focus), .select:hover:not(:focus) { border-color: var(--muted); }
.input:focus, .textarea:focus, .select:focus, .input:focus-visible, .textarea:focus-visible, .select:focus-visible {
  outline: none; border-color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent); /* рамка становится толще на 1px без сдвига полей */
}
.select {
  padding-right: 36px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238a8781' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center; background-size: 16px;
}
/* автозаполнение браузера не должно красить поле в жёлтый или синий */
.input:-webkit-autofill, .textarea:-webkit-autofill { -webkit-text-fill-color: var(--text); box-shadow: inset 0 0 0 100px var(--surface); caret-color: var(--text); }
.input:-webkit-autofill:focus { box-shadow: inset 0 0 0 100px var(--surface), inset 0 0 0 1px var(--accent); }
input[type='search'].input::-webkit-search-cancel-button { -webkit-appearance: none; height: 16px; width: 16px; cursor: pointer; background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238a8781' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='M6 6l12 12M18 6L6 18'/%3E%3C/svg%3E") center / contain no-repeat; }
.input[type='date'], .input[type='datetime-local'] { min-height: 40px; }
.input[disabled] { background: var(--sunken); color: var(--muted); }
.input-affix { position: relative; }
.input-affix .input { padding-right: 56px; }
.input-affix .affix { position: absolute; right: 12px; top: 0; height: 40px; display: grid; place-items: center; color: var(--muted); pointer-events: none; }
.input-lead { position: relative; }
.input-lead .icon { position: absolute; left: 12px; top: 11px; color: var(--muted); pointer-events: none; }
.input-lead .input { padding-left: 38px; }
.hint { font-size: 12px; color: var(--muted); line-height: 1.4; }
.form-error { padding: 10px 12px; border-radius: var(--r-ctl); background: var(--danger-soft); color: var(--danger); font-size: 13px; }
.form { display: grid; gap: 16px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.seg { display: flex; gap: 2px; padding: 2px; border-radius: 10px; background: var(--sunken); }
.seg button {
  flex: 1; height: 32px; padding: 0 8px; border: 0; border-radius: 8px; background: transparent;
  color: var(--text-2); font-size: 13px; font-weight: 500; cursor: pointer;
  transition: background-color var(--t-fast), color var(--t-fast);
}
.seg button[aria-pressed='true'] { background: var(--surface); color: var(--text); box-shadow: 0 0 0 1px var(--line); }

.chip {
  display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 12px;
  border: 1px solid var(--line-strong); border-radius: 16px; background: transparent;
  color: var(--text-2); font-size: 13px; font-weight: 500; cursor: pointer; white-space: nowrap;
  transition: background-color var(--t-fast), color var(--t-fast), border-color var(--t-fast);
}
.chip:hover { background: var(--sunken); }
.chip[aria-pressed='true'] { background: var(--ink); color: var(--ink-text); border-color: transparent; }
.chip .count { font-family: var(--mono); font-size: 12px; opacity: 0.7; }

.switch { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 40px; cursor: pointer; }
.switch input { position: absolute; opacity: 0; }
.switch .track { flex: none; width: 40px; height: 24px; border-radius: 12px; background: var(--line-strong); position: relative; transition: background-color var(--t-fast); }
.switch .track::after { content: ''; position: absolute; top: 2px; left: 2px; width: 20px; height: 20px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.25); transition: transform var(--t-fast) var(--ease); }
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track::after { transform: translateX(16px); }
.switch input:focus-visible + .track { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- статусы ---------- */
.badge { display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 10px; border-radius: 12px; font-size: 12px; font-weight: 500; white-space: nowrap; }
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-ok { background: var(--ok-soft); color: var(--ok); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-neutral { background: var(--sunken); color: var(--text-2); }

/* Запас дней: тонкая шкала до 30 дней */
.runway { display: grid; gap: 6px; min-width: 0; }
.runway-bar { height: 6px; border-radius: 3px; background: var(--sunken); overflow: hidden; }
.runway-bar > i { display: block; height: 100%; border-radius: 3px; background: var(--ok); transition: width var(--t-med) var(--ease); }
.runway.warn .runway-bar > i { background: var(--warn); }
.runway.danger .runway-bar > i { background: var(--danger); }
.runway-text { font-size: 12px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }


/* ---------- карточки ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-card); }
.card-pad { padding: 20px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.card-head h2 { font-size: 14px; font-weight: 600; }
.card-head .sub { font-size: 13px; color: var(--muted); }

/* ---------- состояния ---------- */
.skel { background: linear-gradient(90deg, var(--sunken), var(--surface-2), var(--sunken)); background-size: 200% 100%; animation: shimmer 1.4s linear infinite; border-radius: 6px; }
@keyframes shimmer { to { background-position: -200% 0; } }
.skel-row { display: grid; grid-template-columns: minmax(0, 2fr) 128px minmax(0, 1.3fr); gap: 16px; align-items: center; min-height: 64px; padding: 0 20px; border-top: 1px solid var(--line); }
.skel-row:first-child { border-top: 0; }
.skel-line { height: 12px; }
.state { display: grid; justify-items: center; gap: 8px; padding: 56px 24px; text-align: center; }
.state .mark { width: 48px; height: 48px; border-radius: 12px; display: grid; place-items: center; background: var(--sunken); color: var(--text-2); margin-bottom: 8px; }
.state .mark.danger { background: var(--danger-soft); color: var(--danger); }
.state h3 { font-size: 16px; font-weight: 600; }
.state p { color: var(--text-2); max-width: 36ch; }
.state .btn { margin-top: 8px; }

.toasts { position: fixed; z-index: 100; left: 50%; bottom: 24px; transform: translateX(-50%); display: grid; gap: 8px; justify-items: center; pointer-events: none; width: max-content; max-width: calc(100vw - 32px); }
.toast { display: flex; align-items: center; gap: 8px; padding: 12px 16px; border-radius: 10px; background: var(--ink); color: var(--ink-text); font-weight: 500; box-shadow: var(--shadow-pop); animation: toast-in var(--t-med) var(--ease); }
.toast.error { background: var(--danger); color: #fff; }
.toast.out { opacity: 0; transform: translateY(8px); transition: opacity 200ms, transform 200ms; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* ---------- окна ---------- */
.dlg { border: 0; padding: 0; background: var(--surface); color: var(--text); box-shadow: var(--shadow-pop); width: 480px; max-width: calc(100vw - 32px); max-height: calc(100dvh - 48px); border-radius: var(--r-sheet); overflow: hidden; }
.dlg[open] { display: flex; flex-direction: column; animation: dlg-in var(--t-med) var(--ease); }
.dlg::backdrop { background: rgba(14, 13, 11, 0.5); animation: fade var(--t-med); }
.dlg-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 16px 12px 16px 24px; border-bottom: 1px solid var(--line); }
.dlg-head h2 { font-size: 16px; font-weight: 600; }
.dlg-body { padding: 24px; overflow: auto; display: grid; gap: 16px; }
.dlg-foot { display: flex; gap: 8px; justify-content: flex-end; }
.dlg-foot .btn { min-width: 96px; }
@keyframes dlg-in { from { opacity: 0; transform: translateY(8px) scale(0.98); } }
@keyframes fade { from { opacity: 0; } }

.preview { padding: 12px; border-radius: var(--r-ctl); background: var(--surface-2); border: 1px solid var(--line); display: flex; justify-content: space-between; gap: 12px; font-size: 13px; }
.preview b { font-weight: 600; }


/* Окна на телефоне становятся нижними листами */
@keyframes sheet-in { from { transform: translateY(24px); opacity: 0; } }
@media (max-width: 859px) {
  .dlg { width: 100%; max-width: 100%; margin: auto 0 0; border-radius: var(--r-sheet) var(--r-sheet) 0 0; max-height: 92dvh; }
  .dlg[open] { animation: sheet-in 280ms var(--ease); }
  .dlg-body { padding: 20px 16px calc(20px + env(safe-area-inset-bottom)); }
  .dlg-head { padding-left: 16px; }
  .dlg-foot .btn { flex: 1; }
  .input, .textarea, .select { font-size: 16px; } /* iOS не приближает поле при фокусе */
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}

/* ---------- вход ---------- */
.auth { min-height: 100dvh; display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 6fr); }
.auth-aside { background: var(--brand-tile); color: var(--brand-z); padding: 48px; display: flex; flex-direction: column; justify-content: space-between; }
@media (prefers-color-scheme: dark) { .auth-aside { background: #161615; border-right: 1px solid var(--line); } }
.auth-aside .logo { align-self: flex-start; --lt: var(--brand-z); --lz: #17130f; color: var(--brand-z); height: 28px; }
.auth-aside h2 { font-size: 28px; line-height: 36px; font-weight: 600; letter-spacing: -0.01em; max-width: 14ch; }
.auth-aside p { margin-top: 12px; max-width: 36ch; opacity: 0.7; }
.auth-ledger { display: grid; gap: 0; max-width: 360px; border-top: 1px solid rgba(243, 231, 211, 0.18); }
.auth-ledger div { display: flex; justify-content: space-between; gap: 16px; padding: 12px 0; border-bottom: 1px solid rgba(243, 231, 211, 0.18); font-size: 13px; }
.auth-ledger span:last-child { opacity: 0.6; font-family: var(--mono); }
.auth-main { display: grid; place-items: center; padding: 32px 24px; }
.auth-card { width: 100%; max-width: 360px; display: grid; gap: 24px; }
.auth-card h1 { font-size: 24px; line-height: 32px; font-weight: 600; letter-spacing: -0.01em; }
.auth-card .sub { color: var(--text-2); margin-top: 4px; }
.auth-card .logo.mobile-only { display: none; }
.code-box { position: relative; padding: 16px; padding-right: 56px; border-radius: var(--r-ctl); background: var(--sunken); font-family: var(--mono); font-size: 13px; overflow-wrap: anywhere; }
.code-box .icon-btn { position: absolute; right: 4px; top: 4px; width: 32px; height: 32px; }

@media (max-width: 859px) {
  .auth { grid-template-columns: minmax(0, 1fr); }
  .auth-aside { display: none; }
  .auth-card .logo.mobile-only { display: block; height: 24px; }
}

/* ---------- общие помощники ---------- */
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.stack { display: grid; gap: 12px; }
.chips { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; padding: 2px 0; }
.chips::-webkit-scrollbar { display: none; }
.chips.wrap { flex-wrap: wrap; overflow: visible; }
.switch-label { display: block; font-weight: 500; }
.switch-bare { position: relative; display: inline-flex; cursor: pointer; }
.switch-bare input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.switch-bare .track { flex: none; width: 40px; height: 24px; border-radius: 12px; background: var(--line-strong); position: relative; transition: background-color var(--t-fast); }
.switch-bare .track::after { content: ''; position: absolute; top: 2px; left: 2px; width: 20px; height: 20px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.25); transition: transform var(--t-fast) var(--ease); }
.switch-bare input:checked + .track { background: var(--ok); }
.switch-bare input:checked + .track::after { transform: translateX(16px); }
.switch-bare input:focus-visible + .track { outline: 2px solid var(--accent); outline-offset: 2px; }
.switch-bare input:disabled + .track { opacity: 0.45; }
.dlg-sm { width: 400px; }
.boot { min-height: 100dvh; align-content: center; }

/* ---------- общие формы и окна справа ---------- */
.stepper { display: inline-flex; align-items: center; border: 1px solid var(--line-strong); border-radius: var(--r-ctl); overflow: hidden; }
.stepper button { width: 36px; height: 36px; border: 0; background: var(--surface); color: var(--text); font-size: 18px; cursor: pointer; }
.stepper button:hover:not([disabled]) { background: var(--sunken); }
.stepper button[disabled] { opacity: 0.4; cursor: default; }
.stepper span { min-width: 40px; text-align: center; font-weight: 600; font-variant-numeric: tabular-nums; }
.drawer-form { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.drawer-form .dlg-body { flex: 1; align-content: start; }
.drawer-foot { display: flex; gap: 8px; justify-content: flex-end; padding: 16px 24px calc(16px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: var(--surface); }
.drawer-foot .btn-danger { margin-right: auto; }
.btn-wide { width: 100%; justify-content: space-between; height: 44px; }
.step { display: grid; gap: 12px; }
.step + .step { padding-top: 20px; border-top: 1px solid var(--line); }
.step-title { display: flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 600; }
.step-title .faint { font-weight: 400; font-size: 13px; }
.step-num { width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; background: var(--ink); color: var(--ink-text); font-size: 12px; font-family: var(--mono); font-weight: 500; }
.qty { display: inline-flex; align-items: center; border: 1px solid var(--line-strong); border-radius: var(--r-ctl); overflow: hidden; background: var(--surface); }
.qty button { width: 32px; height: 32px; border: 0; background: none; color: var(--text); font-size: 16px; cursor: pointer; }
.qty button:hover { background: var(--sunken); }
.qty span { min-width: 28px; text-align: center; font-weight: 600; font-variant-numeric: tabular-nums; }
.collapse { display: grid; grid-template-rows: 1fr; transition: grid-template-rows var(--t-med) var(--ease), opacity var(--t-med); }
.collapse.is-closed { grid-template-rows: 0fr; opacity: 0; }
.collapse-inner { overflow: hidden; min-height: 0; }
.collapse:not(.is-closed) .collapse-inner { overflow: visible; }
@media (min-width: 860px) {
  .drawer { width: 480px; max-width: 100vw; height: 100dvh; max-height: 100dvh; margin: 0 0 0 auto; border-radius: var(--r-sheet) 0 0 var(--r-sheet); }
  .drawer[open] { animation: drawer-in 280ms var(--ease); }
  .drawer-wide { width: 560px; }
}
@keyframes drawer-in { from { transform: translateX(32px); opacity: 0; } }
