:root {
  --bg: #f7f5f2;
  --card: #ffffff;
  --line: #e6e1da;
  --text: #2a2420;
  --muted: #8a8078;
  --primary: #d9531e;
  --primary-dark: #b84315;
  --success: #2e8b57;
  --danger: #c0392b;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

button { cursor: pointer; font-family: inherit; border: none; border-radius: 8px; }
button.primary { background: var(--primary); color: #fff; padding: 12px 18px; font-size: 15px; font-weight: 600; }
button.primary:hover { background: var(--primary-dark); }
button.secondary { background: #eee; color: var(--text); padding: 12px 18px; font-size: 15px; }
button.secondary:hover { background: #e0ddd8; }
button.danger { background: var(--danger); color: #fff; padding: 8px 12px; font-size: 13px; }
button.link { background: none; color: var(--muted); text-decoration: underline; padding: 4px; font-size: 13px; }
button:disabled { opacity: .5; cursor: not-allowed; }

input, select {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 15px;
  width: 100%;
  margin-bottom: 10px;
  font-family: inherit;
}

/* ---------- login ---------- */
.login-wrap { height: 100vh; display: flex; align-items: center; justify-content: center; }
.login-card { background: var(--card); padding: 32px; border-radius: 16px; width: 320px; box-shadow: 0 4px 20px rgba(0,0,0,.08); text-align: center; }
.login-logo { font-size: 24px; font-weight: 700; margin-bottom: 4px; }
.login-sub { color: var(--muted); margin-bottom: 20px; }
.error-text { color: var(--danger); font-size: 13px; min-height: 16px; }

/* ---------- topbar ---------- */
.topbar { display: flex; align-items: center; gap: 20px; padding: 14px 20px; background: var(--card); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.brand { font-weight: 700; font-size: 18px; }
.tabs { display: flex; gap: 6px; flex: 1; overflow-x: auto; }
.tab { padding: 8px 14px; border-radius: 8px; font-size: 14px; color: var(--muted); background: transparent; white-space: nowrap; }
.tab.active { background: var(--primary); color: #fff; }
.who { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--muted); }

main { padding: 20px; max-width: 1100px; margin: 0 auto; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 18px; margin-bottom: 16px; }
h2 { font-size: 18px; margin: 0 0 14px; }
h3 { font-size: 15px; margin: 0 0 10px; }
.row { display: flex; gap: 10px; align-items: center; }
.pill { display: inline-block; padding: 3px 10px; border-radius: 10px; font-size: 12px; background: #eee; }
.pill.open { background: #dff5e6; color: var(--success); }
.pill.closed { background: #f3e6e4; color: var(--danger); }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; }

/* оборачивает таблицы, чтобы на узком экране они скроллились вбок,
   а не сжимали поля ввода до нечитаемого состояния */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table-scroll table { min-width: 640px; }
.table-scroll td input { min-width: 100px; }

/* ---------- POS ---------- */
.pos-layout { display: grid; grid-template-columns: 1fr 340px; gap: 16px; align-items: start; }
.menu-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.menu-item { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 12px; cursor: pointer; text-align: left; transition: .1s; }
.menu-item:hover { border-color: var(--primary); }
.menu-item .name { font-weight: 600; font-size: 14px; margin-bottom: 6px; display: block; }
.menu-item .price { color: var(--primary); font-weight: 700; }
.category-title { font-size: 13px; color: var(--muted); text-transform: uppercase; margin: 16px 0 8px; }
.category-title:first-child { margin-top: 0; }

.cart-panel { position: sticky; top: 16px; }
.cart-item { display: flex; justify-content: space-between; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.cart-item .qty-controls { display: flex; align-items: center; gap: 6px; }
.qty-btn { width: 26px; height: 26px; border-radius: 6px; background: #eee; font-weight: 700; }
.cart-total { display: flex; justify-content: space-between; font-size: 18px; font-weight: 700; padding: 12px 0; }
.empty-cart { color: var(--muted); text-align: center; padding: 20px 0; font-size: 14px; }

.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.4); display: flex; align-items: center; justify-content: center; z-index: 50; }
.modal { background: #fff; border-radius: 14px; padding: 24px; width: 340px; max-width: 90vw; }
.pay-toggle { display: flex; gap: 8px; margin-bottom: 12px; }
.pay-toggle button { flex: 1; padding: 12px; background: #eee; border-radius: 8px; font-weight: 600; }
.pay-toggle button.selected { background: var(--primary); color: #fff; }

/* ---------- receipt ---------- */
.receipt-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.5); display: flex; flex-direction: column; align-items: center; justify-content: center; z-index: 100; gap: 16px; }
.receipt-paper { background: #fff; width: 300px; padding: 16px; font-family: "Courier New", monospace; font-size: 13px; max-height: 70vh; overflow-y: auto; }
.receipt-paper .line { display: flex; justify-content: space-between; }
.receipt-paper hr { border: none; border-top: 1px dashed #999; margin: 8px 0; }
.receipt-actions { display: flex; gap: 10px; }

/* ---------- mobile ---------- */
@media (max-width: 720px) {
  .pos-layout { grid-template-columns: 1fr; }
  .cart-panel { position: static; }
  main { padding: 12px; }
  .topbar { padding: 10px 12px; row-gap: 8px; }
  .brand { order: 1; }
  .who { order: 2; margin-left: auto; }
  .tabs { order: 3; flex-basis: 100%; width: 100%; }
  .tab { padding: 10px 14px; font-size: 14px; }
  .card { padding: 14px; }
  h2 { font-size: 16px; }
  .row { flex-wrap: wrap; }
  .row input, .row select { width: auto; flex: 1 1 120px; }
}

/* ---------- печать чека на чековом принтере ---------- */
@media print {
  body * { visibility: hidden; }
  .receipt-paper, .receipt-paper * { visibility: visible; }
  .receipt-paper {
    position: absolute; left: 0; top: 0;
    width: 58mm;
    max-height: none;
    padding: 2mm;
    font-size: 11px;
  }
  .no-print { display: none !important; }
  @page { size: 58mm auto; margin: 0; }
}
