:root {
  --bg: #000; --panel: #111; --panel2: #1a1a1a; --line: #2a2a2a;
  --red: #e3262b; --red-d: #b51c20; --white: #fff; --muted: #9a9a9a; --green: #22c55e;
  --radius: 14px; --cart-w: 380px; --top-h: 64px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--white);
  font-family: -apple-system, "Segoe UI", Roboto, "Noto Sans", Arial, sans-serif; overscroll-behavior: none; }
body { user-select: none; -webkit-user-select: none; }
input, textarea, select { user-select: text; -webkit-user-select: text; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; touch-action: manipulation; }
.hidden { display: none !important; }

#app { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }

/* ---------- top bar ---------- */
.topbar { height: var(--top-h); flex: none; display: flex; align-items: center; gap: 12px; padding: 0 14px;
  border-bottom: 2px solid var(--red); background: #050505; padding-top: env(safe-area-inset-top); }
.brand { display: flex; align-items: center; gap: 10px; }
.logo { width: 46px; height: 46px; border-radius: 50%; }
.brand-text { display: flex; flex-direction: column; line-height: 1.05; }
.brand-text b { font-size: 22px; letter-spacing: 3px; }
.brand-text small { color: var(--red); font-weight: 700; text-transform: uppercase; font-size: 12px; letter-spacing: 1px; }
.top-info { flex: 1; display: flex; gap: 18px; justify-content: center; color: var(--muted); font-size: 15px; }
.top-info b { color: var(--white); font-size: 18px; }
.next-no { white-space: nowrap; }
.clock { font-variant-numeric: tabular-nums; }
.top-actions { display: flex; align-items: center; gap: 8px; }
.tbtn { white-space: nowrap; min-height: 44px; padding: 0 16px; border-radius: 10px; background: var(--panel2); border: 1px solid var(--line); font-weight: 600; }
.tbtn.icon { width: 48px; padding: 0; font-size: 22px; }
.tbtn.active { background: var(--red); border-color: var(--red); }
.lang { display: flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.lang button { min-height: 44px; min-width: 50px; font-weight: 700; background: var(--panel2); }
.lang button.on { background: var(--white); color: #000; }

/* ---------- layout ---------- */
.layout { flex: 1; min-height: 0; display: grid; grid-template-columns: 1fr var(--cart-w); }
.menu-pane { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.tabs { flex: none; display: flex; gap: 8px; padding: 10px 12px; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab { flex: none; min-height: 54px; padding: 0 20px; border-radius: 12px; background: var(--panel2); border: 1px solid var(--line);
  font-size: 17px; font-weight: 700; display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.tab.on { background: var(--red); border-color: var(--red); }
.stop-banner { margin: 0 12px 8px; padding: 10px 14px; border-radius: 10px; background: #3a0d0e; border: 1px dashed var(--red); color: #ffb3b5; font-weight: 600; }
.grid { flex: 1; overflow-y: auto; padding: 4px 12px 16px; display: grid; gap: 12px; align-content: start;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); -webkit-overflow-scrolling: touch; }
.item { position: relative; display: flex; flex-direction: column; text-align: left; border-radius: var(--radius); overflow: hidden;
  background: var(--panel); border: 1px solid var(--line); min-height: 170px; transition: transform .06s; }
.item:active { transform: scale(.97); border-color: var(--red); }
.item .pic { height: 92px; display: flex; align-items: center; justify-content: center; font-size: 48px;
  background: radial-gradient(circle at 50% 60%, #2b0b0c, #111 70%); }
.item .pic img { width: 100%; height: 100%; object-fit: cover; }
.item .nm { padding: 8px 10px 0; font-weight: 700; font-size: 16px; line-height: 1.2; flex: 1; }
.item .pr { padding: 4px 10px 10px; color: var(--red); font-weight: 800; font-size: 17px; }
.item .badge-sz { position: absolute; top: 8px; right: 8px; background: rgba(0,0,0,.7); border: 1px solid var(--line); border-radius: 8px; padding: 2px 7px; font-size: 12px; color: #ddd; }
.item.out { opacity: .38; filter: grayscale(1); }
.item.out::after { content: attr(data-out); position: absolute; top: 34px; left: 50%; transform: translateX(-50%) rotate(-8deg);
  background: var(--red); color: #fff; font-weight: 800; padding: 4px 10px; border-radius: 6px; font-size: 14px; white-space: nowrap; filter: none; }
.grid.stopmode .item { border: 2px dashed #555; }
.grid.stopmode .item.out { opacity: .6; border-color: var(--red); }
.empty-cat { color: var(--muted); padding: 30px; grid-column: 1 / -1; text-align: center; }

/* ---------- cart ---------- */
.cart-pane { display: flex; flex-direction: column; min-height: 0; background: var(--panel); border-left: 2px solid var(--line); }
.cart-head { display: flex; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--line); gap: 10px; }
.cart-head h2 { margin: 0; font-size: 20px; flex: 1; }
.cart-close { display: none; width: 44px; height: 44px; font-size: 22px; border-radius: 10px; background: var(--panel2); }
.link-btn { color: var(--muted); padding: 10px 12px; border-radius: 8px; border: 1px solid var(--line); }
.cart-lines { flex: 1; overflow-y: auto; padding: 8px 12px; }
.cart-empty { color: var(--muted); text-align: center; margin-top: 40px; padding: 0 20px; line-height: 1.5; }
.line { background: var(--panel2); border-radius: 12px; padding: 10px 12px; margin-bottom: 8px; border: 1px solid var(--line); }
.line-top { display: flex; gap: 8px; align-items: flex-start; }
.line-name { flex: 1; font-weight: 700; font-size: 16px; line-height: 1.25; }
.line-name small { display: block; color: #ffb3b5; font-weight: 600; font-size: 14px; }
.line-sum { font-weight: 800; white-space: nowrap; }
.line-bot { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.qty { display: flex; align-items: center; background: #000; border-radius: 10px; border: 1px solid var(--line); }
.qty button { width: 46px; height: 42px; font-size: 22px; font-weight: 700; }
.qty span { min-width: 30px; text-align: center; font-weight: 800; font-size: 17px; }
.note-btn { flex: 1; min-height: 42px; border-radius: 10px; border: 1px dashed #555; color: var(--muted); padding: 0 10px; text-align: left; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.note-btn.has { border-style: solid; border-color: var(--red); color: #fff; background: #2a0b0c; }
.cart-foot { padding: 12px 16px calc(14px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); }
.total-row { display: flex; justify-content: space-between; align-items: baseline; font-size: 18px; margin-bottom: 10px; }
.total-row b { font-size: 30px; }
.btn-primary { background: var(--red); color: #fff; font-weight: 800; border-radius: 12px; min-height: 50px; padding: 0 20px; font-size: 18px; }
.btn-primary:active { background: var(--red-d); }
.btn-primary:disabled { background: #444; color: #888; }
.btn-primary.big { width: 100%; min-height: 64px; font-size: 22px; letter-spacing: .5px; }
.btn { background: var(--panel2); border: 1px solid var(--line); border-radius: 12px; min-height: 50px; padding: 0 18px; font-weight: 700; font-size: 17px; }
.btn.danger { color: #ff7b7f; border-color: #5a1c1e; }
.cart-bar, .cart-backdrop { display: none; }

/* ---------- modal ---------- */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.75); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 16px; }
.modal-card { background: var(--panel); border: 1px solid #333; border-top: 4px solid var(--red); border-radius: 18px; width: min(640px, 100%);
  max-height: calc(100dvh - 32px); overflow-y: auto; padding: 20px; box-shadow: 0 20px 60px rgba(0,0,0,.6); }
.modal-card.wide { width: min(980px, 100%); }
.modal-card h3 { margin: 0 0 4px; font-size: 24px; }
.modal-card .sub { color: var(--muted); margin-bottom: 14px; }
.lbl { color: var(--muted); font-size: 14px; font-weight: 600; margin: 14px 0 8px; text-transform: uppercase; letter-spacing: .5px; }
.choices { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.choice { min-height: 74px; border-radius: 12px; background: var(--panel2); border: 2px solid var(--line); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; }
.choice b { font-size: 20px; }
.choice span { color: var(--red); font-weight: 800; font-size: 18px; }
.choice.on { border-color: var(--red); background: #2a0b0c; }
.choice.on span { color: #fff; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; }
.modal-actions .btn-primary { min-width: 180px; }
.txt { width: 100%; min-height: 50px; border-radius: 10px; border: 1px solid #444; background: #000; color: #fff; padding: 10px 12px; font-size: 18px; }
textarea.txt { min-height: 70px; resize: vertical; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.chip { padding: 10px 14px; border-radius: 22px; background: var(--panel2); border: 1px solid var(--line); font-size: 15px; }
.qty.big button { width: 60px; height: 54px; font-size: 26px; }
.qty.big span { min-width: 50px; font-size: 22px; }

/* payment */
.pay-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.pay-sum { background: #000; border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; margin-bottom: 10px; }
.pay-sum small { color: var(--muted); display: block; font-size: 14px; }
.pay-sum b { font-size: 34px; font-variant-numeric: tabular-nums; }
.pay-sum.change { border-color: var(--green); }
.pay-sum.change b { color: var(--green); font-size: 44px; }
.pay-sum.change.bad { border-color: var(--red); }
.pay-sum.change.bad b { color: var(--red); font-size: 22px; }
.bills { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 8px; }
.bill { min-height: 54px; border-radius: 10px; background: #f5f5f5; color: #000; font-weight: 800; font-size: 19px; }
.bill.exact { background: var(--white); border: 2px solid var(--red); font-size: 16px; }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.keypad button { min-height: 58px; border-radius: 10px; background: var(--panel2); border: 1px solid var(--line); font-size: 24px; font-weight: 700; }
.keypad button:active, .bill:active, .choice:active, .chip:active { filter: brightness(1.3); }

/* done / ticket preview */
.done { display: grid; grid-template-columns: 1fr auto; gap: 20px; align-items: start; }
.done-big { font-size: 22px; }
.done-no { font-size: 96px; font-weight: 900; color: var(--red); line-height: 1; margin: 6px 0 12px; }
.preview { background: #fff; color: #000; border-radius: 6px; padding: 8px 0; max-height: 72dvh; overflow-y: auto; }
.preview .ticket { width: 72mm; }

/* admin */
.adm-tabs { display: flex; gap: 8px; margin: 10px 0 14px; flex-wrap: wrap; }
.adm-list { display: flex; flex-direction: column; gap: 8px; }
.adm-row { display: flex; align-items: center; gap: 10px; background: var(--panel2); border: 1px solid var(--line); border-radius: 12px; padding: 8px 10px; }
.adm-row .th { width: 48px; height: 48px; border-radius: 8px; background: #000; display: flex; align-items: center; justify-content: center; font-size: 26px; overflow: hidden; flex: none; }
.adm-row .th img { width: 100%; height: 100%; object-fit: cover; }
.adm-row .grow { flex: 1; min-width: 0; }
.adm-row .grow small { color: var(--muted); display: block; }
.adm-row.off { opacity: .5; }
.adm-row .btn { min-height: 44px; padding: 0 12px; font-size: 15px; }
.size-row { display: grid; grid-template-columns: 1fr 120px 50px; gap: 8px; margin-bottom: 8px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.check { display: flex; align-items: center; gap: 10px; min-height: 50px; font-size: 17px; }
.check input { width: 26px; height: 26px; accent-color: var(--red); }
.photo-prev { width: 120px; height: 90px; border-radius: 10px; background: #000; border: 1px solid var(--line); display: flex; align-items: center; justify-content: center; font-size: 40px; overflow: hidden; }
.photo-prev img { width: 100%; height: 100%; object-fit: cover; }
.orders-table { width: 100%; border-collapse: collapse; font-size: 15px; }
.orders-table td, .orders-table th { padding: 8px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.pin-display { font-size: 40px; letter-spacing: 16px; text-align: center; min-height: 56px; margin: 8px 0 12px; }

.toast { position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%); background: #fff; color: #000; padding: 12px 22px; border-radius: 12px; font-weight: 700; z-index: 80; box-shadow: 0 8px 30px rgba(0,0,0,.5); }

/* ---------- 80mm ticket ---------- */
#printRoot { display: none; }
.ticket { width: 72mm; margin: 0 auto; padding: 2mm 3mm; font-family: "Courier New", ui-monospace, monospace; font-size: 13px; color: #000; background: #fff; line-height: 1.3; }
.t-center { text-align: center; }
.t-cafe { font-size: 20px; font-weight: 900; letter-spacing: 2px; }
.t-small { font-size: 12px; }
.t-rule { border-top: 1px dashed #000; margin: 6px 0; }
.t-num-label { font-size: 14px; font-weight: 700; }
.t-num { font-size: 54px; font-weight: 900; line-height: 1; margin: 2px 0 6px; }
.t-row { display: flex; justify-content: space-between; gap: 6px; }
.t-line { margin: 4px 0 6px; }
.t-item { font-size: 15px; }
.t-sum { white-space: nowrap; }
.t-note { font-size: 15px; font-weight: 900; padding-left: 14px; text-transform: uppercase; }
.t-total { font-size: 18px; font-weight: 900; }

@media print {
  @page { size: 80mm auto; margin: 0; }
  html, body { background: #fff !important; height: auto; }
  #app, #modal, #toast { display: none !important; }
  #printRoot { display: block !important; }
}

/* ---------- tablet portrait / small tablets ---------- */
@media (max-width: 1000px) { :root { --cart-w: 330px; } .grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); } }

/* ---------- phone: full-width menu, cart as bottom bar + drawer ---------- */
@media (max-width: 760px) {
  :root { --top-h: 56px; }
  .topbar { gap: 6px; padding: 0 8px; }
  .logo { width: 38px; height: 38px; }
  .brand-text small { display: none; }
  .brand-text b { font-size: 18px; letter-spacing: 2px; }
  .top-info { font-size: 13px; gap: 8px; }
  .top-info .clock { display: none; }
  .next-no span { display: none; }
  .next-no::before { content: '№ '; }
  .tbtn { padding: 0 10px; font-size: 14px; }
  .tbtn.icon { width: 44px; }
  .lang button { min-width: 40px; }
  .layout { display: block; position: relative; }
  .menu-pane { height: 100%; }
  .tabs { padding: 8px; }
  .tab { min-height: 48px; padding: 0 14px; font-size: 15px; }
  .grid { grid-template-columns: repeat(2, 1fr); gap: 8px; padding: 4px 8px 96px; }
  .item { min-height: 150px; }
  .item .pic { height: 74px; font-size: 40px; }
  .cart-bar { display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; align-items: center; gap: 10px;
    padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); background: #0b0b0b; border-top: 2px solid var(--red); }
  .cart-bar .cb-info { flex: 1; font-size: 17px; color: var(--muted); }
  .cart-bar .cb-info b { color: #fff; font-size: 22px; }
  .cart-bar .btn-primary { min-height: 52px; }
  .cart-pane { position: fixed; left: 0; right: 0; bottom: 0; height: 88dvh; z-index: 40; border-left: 0; border-top: 3px solid var(--red);
    border-radius: 18px 18px 0 0; transform: translateY(105%); transition: transform .22s ease; }
  body.cart-open .cart-pane { transform: none; }
  body.cart-open .cart-backdrop { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 30; }
  .cart-close { display: block; }
  .modal { padding: 0; align-items: flex-end; }
  .modal-card { border-radius: 18px 18px 0 0; max-height: 94dvh; padding: 16px; }
  .pay-grid, .done, .form-grid { grid-template-columns: 1fr; }
  .done-no { font-size: 72px; }
  .preview { max-height: none; }
  .choices { grid-template-columns: repeat(2, 1fr); }
  .modal-actions { position: sticky; bottom: -16px; background: var(--panel); margin: 12px -16px -16px; padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); }
  .modal-actions .btn-primary { flex: 1; min-width: 0; }
  .keypad button { min-height: 50px; }
  .pay-sum { padding: 8px 12px; margin-bottom: 8px; }
  .pay-sum b { font-size: 26px; }
  .pay-sum.change b { font-size: 34px; }
  .bill { min-height: 48px; }
}

@media (max-width: 420px) { .brand-text { display: none; } .top-info { justify-content: flex-start; } }
