:root {
  --bg: #f4f3ef;
  --surface: #ffffff;
  --surface-2: #f8f7f4;
  --text: #1b1b1b;
  --muted: #6b6b6b;
  --border: #e2e0da;
  --accent: #e2701b;
  --accent-text: #ffffff;
  --accent-soft: #fdeede;
  --danger: #c0392b;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 16px rgba(0,0,0,.05);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161615;
    --surface: #212120;
    --surface-2: #2a2a28;
    --text: #efeeea;
    --muted: #a09e98;
    --border: #3a3936;
    --accent: #f08a3a;
    --accent-text: #1b1b1b;
    --accent-soft: #3d2a1a;
    --danger: #ef6b5b;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
button, input, select, textarea { font: inherit; color: inherit; }
h2 { font-size: 18px; margin: 0 0 12px; }
h3 { font-size: 15px; margin: 24px 0 8px; }
.muted { color: var(--muted); }
.empty { color: var(--muted); text-align: center; padding: 16px 8px; margin: 0; }

/* ---------- Каркас ---------- */
.topbar {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 5;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 18px; letter-spacing: .04em; }
.tabs { display: flex; gap: 4px; margin-left: auto; }
.tabs button {
  border: 0; background: transparent; padding: 8px 14px; border-radius: 8px; cursor: pointer; font-weight: 600; color: var(--muted);
}
.tabs button.active { background: var(--accent-soft); color: var(--text); }
main { padding: 16px; max-width: 1400px; margin: 0 auto; }
.tab { display: none; }
.tab.active { display: block; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow);
}

/* ---------- Кнопки и поля ---------- */
.btn {
  border: 1px solid var(--border); background: var(--surface-2); padding: 9px 14px; border-radius: 9px;
  cursor: pointer; font-weight: 600;
}
.btn:hover { filter: brightness(.97); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn.big { width: 100%; padding: 16px; font-size: 18px; }

input, select, textarea {
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; min-width: 0;
}
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.w-price { width: 110px; text-align: right; }

.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.toolbar input:not(.w-price) { flex: 1 1 180px; }
.spacer { flex: 1; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.fields { display: grid; gap: 12px; }
.fields label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
.fields label > * { color: var(--text); font-size: 15px; justify-self: start; }

/* ---------- Касса ---------- */
.pos { display: grid; grid-template-columns: 1fr 380px; gap: 16px; align-items: start; }
.dishes { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.dish {
  display: flex; flex-direction: column; justify-content: space-between; gap: 8px; min-height: 96px; text-align: left;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px;
  cursor: pointer; box-shadow: var(--shadow); transition: transform .05s;
}
.dish:hover { border-color: var(--accent); }
.dish:active { transform: scale(.97); background: var(--accent-soft); }
.dish-name { font-weight: 700; font-size: 16px; overflow-wrap: anywhere; }
.dish-price { color: var(--muted); font-variant-numeric: tabular-nums; }
.dishes-empty {
  grid-column: 1 / -1; text-align: center; padding: 48px 16px; color: var(--muted);
  border: 2px dashed var(--border); border-radius: var(--radius);
}
.dishes-empty .btn { margin-top: 12px; }

.cart { position: sticky; top: 72px; display: flex; flex-direction: column; gap: 14px; }
.cart-head { display: flex; justify-content: space-between; align-items: center; }
.cart-head h2 { margin: 0; }
#next-number { color: var(--accent); }
.cart-items { max-height: 45vh; overflow-y: auto; }
.cart-line {
  display: grid; grid-template-columns: 1fr auto 84px; gap: 8px; align-items: center;
  padding: 8px 0; border-bottom: 1px solid var(--border);
}
.cart-name { font-weight: 600; overflow-wrap: anywhere; }
.cart-name small { display: block; color: var(--muted); font-weight: 400; }
.cart-sum { text-align: right; font-variant-numeric: tabular-nums; }
.qty { display: flex; align-items: center; gap: 6px; }
.qty span { min-width: 22px; text-align: center; font-weight: 700; font-variant-numeric: tabular-nums; }
.qty-btn {
  width: 34px; height: 34px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface-2);
  cursor: pointer; font-size: 18px; line-height: 1;
}
.discounts { display: flex; align-items: center; gap: 10px; }
.discounts .label { color: var(--muted); font-size: 13px; }
.discount-fixed { display: flex; align-items: center; justify-content: flex-end; gap: 10px; color: var(--muted); font-size: 13px; }
.discount-fixed[hidden] { display: none; }
.t-row.t-error { color: var(--danger); font-size: 13px; }
/* Предупреждение на кассе: чек не напечатается (терминал не подключён или автопечать выключена) */
.print-warning { margin: 0; background: var(--accent-soft); border-radius: 8px; padding: 8px 10px; font-size: 13px; }
.print-warning[hidden] { display: none; }
.seg { display: flex; flex: 1; border: 1px solid var(--border); border-radius: 9px; overflow: hidden; }
.seg button { flex: 1; border: 0; background: transparent; padding: 9px 0; cursor: pointer; font-weight: 600; }
.seg button + button { border-left: 1px solid var(--border); }
.seg button.active { background: var(--accent); color: var(--accent-text); }
.totals { border-top: 2px solid var(--text); padding-top: 8px; }
.t-row { display: flex; justify-content: space-between; padding: 2px 0; font-variant-numeric: tabular-nums; }
.t-total { font-size: 24px; font-weight: 800; }

/* ---------- Таблицы ---------- */
.table-wrap { overflow-x: auto; }
table.list { width: 100%; border-collapse: collapse; }
.list th, .list td { padding: 8px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
.list th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; }
.list .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.list td input:not(.w-price) { width: 100%; }
.strong { font-weight: 700; }
.nowrap { white-space: nowrap; }
.row-actions { text-align: right; }
.row-actions > * + * { margin-left: 4px; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.stat { background: var(--surface-2); border-radius: 10px; padding: 10px 12px; display: grid; gap: 2px; }
.stat span { color: var(--muted); font-size: 13px; }
.stat b { font-size: 20px; font-variant-numeric: tabular-nums; }

#tab-menu .card { max-width: 820px; }
/* Меню: название забирает всю свободную ширину, цена — узкая (и в таблице, и в форме добавления) */
#tab-menu .m-name-cell { width: 100%; }
#tab-menu .w-price { width: 80px; }
#tab-menu .del-icon { display: none; }
/* Настройки — карточки по темам: на компьютере в несколько колонок, на телефоне в одну */
.settings-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 16px; align-items: start; }

/* ---------- Mercado Pago ---------- */
.btn.mp { background: #009ee3; border-color: #009ee3; color: #fff; }
.pay-row { display: flex; gap: 8px; margin-top: -6px; }
.pay-row:not(:has(button:not([hidden]))) { display: none; }
.pay-row .btn.big { flex: 1; padding: 14px 8px; font-size: 16px; }
h4 { margin: 14px 0 6px; font-size: 14px; }
.check { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.modal {
  position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: 16px;
  background: rgba(0,0,0,.55);
}
.modal[hidden] { display: none; }
.modal-box {
  background: var(--surface); border-radius: var(--radius); padding: 20px; width: min(460px, 100%);
  box-shadow: 0 10px 40px rgba(0,0,0,.3); text-align: center;
}
.modal-box .actions { justify-content: center; }
.mp-amount { font-size: 26px; font-weight: 800; margin: 4px 0 12px; font-variant-numeric: tabular-nums; }
.spinner {
  width: 42px; height: 42px; margin: 8px auto; border-radius: 50%;
  border: 4px solid var(--border); border-top-color: #009ee3; animation: spin 0.9s linear infinite;
}
.spinner[hidden] { display: none; }
@keyframes spin { to { transform: rotate(360deg); } }
.mp-qr-preview { display: block; width: 160px; height: 160px; background: #fff; padding: 6px; border-radius: 8px; }
.file-btn { position: relative; overflow: hidden; display: inline-flex; align-items: center; }
.file-btn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.banner {
  background: #fff3cd; color: #5c4400; padding: 10px 16px; border-bottom: 1px solid #e8d48a;
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px;
}
.banner[hidden] { display: none; }
a.btn { text-decoration: none; display: inline-flex; align-items: center; color: inherit; }

/* ---------- Вход ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.auth[hidden] { display: none; }
.auth-box { width: 100%; max-width: 380px; }
.auth-box [hidden] { display: none; }
.auth-box .fields label > input { justify-self: stretch; }
/* Язык RU / ES — в шапке справа, перед «Выйти» */
.lang-select { padding: 4px 6px; font-size: 13px; border-radius: 8px; }
.topbar .lang-select { margin-left: auto; }
.auth-lang { float: right; margin: -4px 0 0 8px; }
#email-form label > input { justify-self: stretch; max-width: 320px; }

/* ---------- Мастер настройки ---------- */
.wizard-box { max-width: 640px; margin: 0 auto; }
.wz-steps { display: flex; flex-wrap: wrap; gap: 6px; list-style: none; padding: 0; margin: 0 0 16px; }
.wz-steps button {
  border: 1px solid var(--border); background: var(--surface-2); border-radius: 999px;
  padding: 4px 10px; font-size: 13px; cursor: pointer;
}
.wz-steps button:disabled { cursor: default; opacity: .55; }
.wz-steps .done button { border-color: var(--accent); }
.wz-steps .viewing button { background: var(--accent); color: var(--accent-text); border-color: var(--accent); opacity: 1; }
.wz-body-fields label > input, .wz-body-fields label > textarea { justify-self: stretch; }
.wz-steps-text { margin: 0 0 12px; padding-left: 20px; }
.wz-steps-text li + li { margin-top: 6px; }
.warn { background: var(--accent-soft); border-radius: 8px; padding: 10px 12px; }
.csr { width: 100%; min-height: 120px; font: 12px/1.3 ui-monospace, Consolas, monospace; }
.check-list { list-style: none; padding: 0; margin: 0 0 12px; }
.check-list li::before { content: '○ '; color: var(--muted); }
.check-list li.ok::before { content: '✓ '; color: var(--accent); font-weight: 700; }

/* ---------- Уведомление ---------- */
#toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; transition: .2s; max-width: calc(100% - 32px);
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.error { background: var(--danger); color: #fff; }

/* ---------- Comprobante заказа, период, вкладка «Comprobantes» ---------- */
.factura-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.factura-row .btn { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.buyer-form { background: var(--surface-2); border-radius: 10px; padding: 12px; }
.buyer-form label > input, .buyer-form label > select { justify-self: stretch; }
.period { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; margin-bottom: 12px; }
.period-presets { flex: 0 1 auto; }
.period-presets button { padding: 8px 12px; }
.period-dates { display: flex; gap: 8px; flex-wrap: wrap; }
.period-dates label { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; }
tr.cancelled td { color: var(--muted); }
tr.highlight td { background: var(--accent-soft); transition: background .3s; }

@media (max-width: 900px) {
  .pos, .settings-grid { grid-template-columns: 1fr; }
  .cart { position: static; }
  .tabs { margin-left: 0; }
}

/* Вкладка «Comprobantes»: последние пять сверху, список за период ниже */
.stack { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; }   /* minmax: широкая таблица не растягивает колонку */
.recent-actions { display: flex; gap: 6px; }
.recent-actions .btn { flex: 1; white-space: nowrap; }

/* Телефон — основное устройство кассира (ADR 0005) */
@media (max-width: 600px) {
  .topbar { gap: 8px; padding: 8px 12px; }
  .brand { flex: 1; min-width: 0; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; }
  .tabs { order: 3; width: 100%; overflow-x: auto; }
  .tabs { gap: 0; }
  .tabs button { padding: 8px 6px; font-size: 13px; flex: 1 0 auto; }
  main { padding: 12px; }
  .card { padding: 14px; }
  .dishes { grid-template-columns: repeat(2, 1fr); }
  .dish { min-height: 80px; }
  .period-presets { width: 100%; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .stat b { font-size: 17px; }
  /* Меню на телефоне: «Удалить» — значком ✕, отступы меньше, чтобы названию досталось больше места */
  #tab-menu .list th, #tab-menu .list td { padding-left: 4px; padding-right: 4px; }
  #tab-menu .del-text { display: none; }
  #tab-menu .del-icon { display: inline; }
  /* Последние comprobantes на телефоне — карточками: дата и тип, CAE и сумма, статус, крупные кнопки */
  .recent-list thead { display: none; }
  .recent-list, .recent-list tbody { display: block; }
  .recent-list tr { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; padding: 12px 0; border-bottom: 1px solid var(--border); }
  .recent-list td { border: 0; padding: 0; }
  .recent-list td.recent-status, .recent-list td.recent-actions { grid-column: 1 / -1; }
  .recent-actions .btn { padding: 10px 6px; }
}
