:root {
  --bg: #f3efe6;
  --card: #fffaf3;
  --ink: #221c16;
  --muted: #6f675e;
  --line: #e4d8c8;
  --accent: #9a3412;
  --accent-dark: #7c2d12;
  --good: #1f6b4a;
  --bad: #9b2c2c;
  --warn: #8a5a12;
  --shadow: 0 12px 30px rgba(60, 40, 20, 0.06);
  --radius: 16px;
  color-scheme: light;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 16px;
  line-height: 1.45;
}
body.app { min-height: 100vh; }
img { max-width: 100%; display: block; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent-dark); }
h1, h2, h3, p { margin: 0; }
h1 { font-size: 1.7rem; letter-spacing: -0.03em; }
h2 { font-size: 1.15rem; margin-bottom: 10px; }
h3 { font-size: 1rem; }

.top {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: #241c16;
  color: #f6f1e8;
  position: sticky;
  top: 0;
  z-index: 20;
}
.brand {
  color: inherit;
  text-decoration: none;
  font-family: Georgia, "Palatino Linotype", Palatino, serif;
  font-size: 1.25rem;
  font-weight: 700;
}
.nav {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  align-items: center;
  flex: 1;
}
.nav a, .logout-form button, .clock {
  color: #f6f1e8;
  text-decoration: none;
  background: transparent;
  border: 0;
  border-radius: 999px;
  padding: 8px 12px;
  white-space: nowrap;
  cursor: pointer;
}
.nav a.active, .nav a:hover, .logout-form button:hover { background: rgba(255,255,255,.12); }
.clock { margin-left: auto; color: #d9cbb8; font-variant-numeric: tabular-nums; }
.logout-form { margin: 0; }

main { padding: 16px; max-width: 1180px; margin: 0 auto; }
body:has(.order-layout) main { max-width: 1480px; }
.page-head, .filters, .form-actions, .presets, .choice, .line-actions, .pay-methods {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
.page-head { justify-content: space-between; margin-bottom: 14px; align-items: flex-end; }
.muted, .eyebrow { color: var(--muted); }
.eyebrow { text-transform: uppercase; letter-spacing: .08em; font-size: .78rem; font-weight: 700; }
.back { display: inline-block; margin-bottom: 4px; text-decoration: none; font-weight: 700; }
.num { font-variant-numeric: tabular-nums; }
.bad { color: var(--bad); }

.btn, summary.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 48px;
  padding: 10px 14px;
  border-radius: 12px;
  border: 1px solid transparent;
  background: #efe6d8;
  color: var(--ink);
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
  list-style: none;
}
summary.btn::-webkit-details-marker { display: none; }
.btn.primary { background: var(--accent); color: white; }
.btn.good { background: var(--good); color: white; }
.btn.ghost { background: transparent; border-color: var(--line); }
.btn.danger { background: white; color: var(--bad); border-color: #efc7c7; }
.btn.small { min-height: 40px; padding: 6px 10px; font-size: .92rem; }
.btn:disabled { opacity: .55; }

.card, .login-card, .tcard, .product, .bill {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card { padding: 14px; margin-bottom: 14px; }
.flash, .help {
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 12px;
}
.flash.ok { background: #e7f5ea; color: #14532d; }
.flash.err { background: #fde8e8; color: #7f1d1d; }
.help { background: #f7f1e6; border: 1px dashed #ddcbb3; color: #4a4036; }
.help p + p { margin-top: 8px; }
.empty { color: var(--muted); padding: 8px 0; }

label { display: flex; flex-direction: column; gap: 6px; font-size: .92rem; font-weight: 700; }
label.check { flex-direction: row; align-items: center; min-height: 44px; }
input[type="text"], input[type="password"], input[type="date"], input[type="search"],
input:not([type]), select, textarea {
  width: 100%;
  min-height: 48px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: white;
  font-weight: 560;
}
label.check input { width: 20px; height: 20px; min-height: 0; }
.form { display: grid; gap: 12px; }
.narrow { max-width: 520px; }
.grid-2 { display: grid; gap: 12px; }
.current-photo { display: flex; gap: 12px; align-items: center; }
.current-photo img, .thumb { width: 72px; height: 72px; object-fit: cover; border-radius: 12px; }
.thumb { width: 48px; height: 48px; }
.avatar {
  width: 64px; height: 64px; border-radius: 14px;
  display: grid; place-items: center;
  background: #f0e4d4; color: #6d4c32; font-weight: 800;
}
.avatar.small { width: 48px; height: 48px; border-radius: 12px; }

.tables, .products, .chooser, .stat-grid, .split {
  display: grid;
  gap: 12px;
}
.tables, .products { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.chooser { grid-template-columns: 1fr; }
.stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.tcard { position: relative; min-height: 132px; overflow: hidden; }
.tcard.busy { background: #fff4e6; border-color: #efc08a; }
.tcard > a {
  display: flex; flex-direction: column; gap: 4px;
  min-height: 132px; padding: 14px 14px 42px;
  color: inherit; text-decoration: none;
}
.tcard strong { font-size: 1.15rem; }
.tcard em { font-style: normal; font-size: 1.25rem; font-weight: 800; }
.tcard .rename { position: absolute; right: 8px; bottom: 8px; }
.tcard .rename summary {
  list-style: none; cursor: pointer; font-weight: 700; color: var(--accent-dark);
}
.tcard .rename form { display: grid; gap: 6px; min-width: 160px; padding: 8px; }

.tile {
  display: flex; flex-direction: column; gap: 6px;
  padding: 28px 20px; border-radius: 20px;
  background: var(--card); border: 1px solid var(--line);
  text-decoration: none; color: inherit; box-shadow: var(--shadow);
  min-height: 140px;
}
.tile strong { font-size: 1.8rem; }
.tile:first-child { background: #9a3412; color: white; }
.tile:first-child span { color: #ffd7c2; }

.order-layout { display: grid; gap: 12px; align-items: start; }
.cats { display: flex; gap: 6px; overflow: auto; }
.cat {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  text-align: left; border: 1px solid var(--line); background: var(--card);
  border-radius: 12px; padding: 10px 12px; cursor: pointer; font-weight: 700;
  white-space: nowrap;
}
.cat em { font-style: normal; color: var(--muted); font-size: .8rem; }
.cat.on { background: var(--accent); color: white; border-color: var(--accent); }
.cat.on em { color: #ffd7c2; }
.catalog input[type="search"] { margin-bottom: 12px; width: 100%; }
.order-products { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 10px; }
.product { padding: 12px; display: grid; gap: 8px; }
.order-products .product h3 { min-height: 2.4em; }
.bill-sum {
  display: flex; justify-content: space-between; align-items: baseline;
  padding: 4px 0 12px; border-bottom: 1px solid var(--line);
  font-size: 1.45rem; font-weight: 800;
}
.adds { display: grid; gap: 6px; }
.add-btn {
  width: 100%; min-height: 52px; border-radius: 12px;
  border: 1px solid var(--line); background: white;
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 10px; cursor: pointer; font-weight: 700;
}
.bill { padding: 14px; }
.bill-head, .line-main, .pays li, .plain li, .table-rename {
  display: flex; justify-content: space-between; gap: 8px; align-items: center;
}
.lines { list-style: none; margin: 0; padding: 0; }
.lines li { padding: 10px 0; border-bottom: 1px solid var(--line); }
.line-main b { margin-left: auto; }
.badge {
  font-style: normal; background: #f3e7d3; color: var(--warn);
  border-radius: 999px; padding: 2px 8px; font-size: .78rem; font-weight: 800;
}
.comp .line-main b { color: var(--muted); text-decoration: line-through; }
.qty { min-width: 1.6rem; text-align: center; font-weight: 800; }
.totals { margin: 12px 0; }
.totals div { display: flex; justify-content: space-between; padding: 4px 0; }
.totals .grand, .totals .due { font-size: 1.15rem; font-weight: 800; }
.pays { list-style: none; margin: 0 0 12px; padding: 0; }
.pays li { padding: 6px 0; }
.bill-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.bill-actions > form .btn, .bill-actions > details > summary { width: 100%; }
.bill-actions details[open] { grid-column: 1 / -1; background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 8px; }
.bill-actions details form { display: grid; gap: 8px; margin-top: 8px; }
.pay-methods .btn { flex: 1; }
.inline-form, .price-form { display: flex; gap: 6px; align-items: center; }
.inline-form input, .price-form input { max-width: 110px; }
.price-form label { flex-direction: row; align-items: center; margin: 0; font-size: .78rem; font-weight: 600; color: var(--muted); }
.price-form input { width: 96px; min-height: 40px; padding: 6px 8px; }

.mobile-total {
  display: none;
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 15;
  background: #241c16; color: white; text-decoration: none;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  justify-content: space-between; align-items: center;
}

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 640px; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: .82rem; color: var(--muted); font-weight: 700; }
.actions-cell, .actions-cell form { display: flex; gap: 6px; flex-wrap: wrap; }
.muted-row { opacity: .55; }
.warn-row td { background: #fff1f1; }
.plain { list-style: none; margin: 0; padding: 0; }
.plain li { padding: 8px 0; border-bottom: 1px solid var(--line); }
.table-rename { padding: 10px 0; border-bottom: 1px solid var(--line); }
.table-rename label { flex: 1; }
.stat-grid article {
  background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 12px;
  display: flex; flex-direction: column; gap: 4px;
}
.stat-grid span { color: var(--muted); font-size: .85rem; }
.stat-grid strong { font-size: 1.25rem; }
.unit-row, .ing-row {
  display: grid; gap: 8px; padding: 12px; margin-bottom: 8px;
  border: 1px solid var(--line); border-radius: 14px; background: white;
}
.filters label { min-width: 140px; }
.product-group { margin-bottom: 16px; }
.product-group h2 { margin: 8px 0; }

body.login main {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 24px;
}
.login-card { width: min(420px, 100%); padding: 22px; }
.login-card h1 { margin: 4px 0 8px; }
.pin-label { margin: 14px 0; }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.keypad button {
  min-height: 64px; font-size: 1.3rem; font-weight: 800;
  border-radius: 14px; border: 1px solid var(--line); background: white; cursor: pointer;
}

:focus-visible { outline: 3px solid #c2410c; outline-offset: 2px; }

@media (min-width: 720px) {
  .tables { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .chooser, .split, .grid-2 { grid-template-columns: 1fr 1fr; }
  .stat-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
@media (min-width: 960px) {
  .tables { grid-template-columns: repeat(5, minmax(0, 1fr)); }
  .products { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .unit-row { grid-template-columns: 1.1fr .8fr auto auto .8fr auto; align-items: end; }
  .ing-row { grid-template-columns: 1.4fr .7fr auto; align-items: end; }
}
@media (min-width: 980px) {
  .order-layout { grid-template-columns: 190px minmax(0, 1fr) minmax(280px, 340px); }
  .cats, .bill {
    position: sticky; top: 74px; max-height: calc(100vh - 90px); overflow: auto;
  }
  .cats { flex-direction: column; }
  .cat { white-space: normal; }
}
@media (max-width: 979px) {
  .mobile-total { display: flex; }
  body:has(.mobile-total) main { padding-bottom: 84px; }
  .cats {
    position: sticky; top: 52px; z-index: 12;
    background: var(--bg); padding: 4px 0 8px;
  }
}
@media print {
  .top, .noprint, .catalog, .cats, .mobile-total, .filters { display: none !important; }
  body, main { background: white; padding: 0; }
  .card, .bill { box-shadow: none; }
  .order-layout { display: block; }
  .bill { position: static; max-height: none; overflow: visible; }
}

body.order-screen {
  height: 100dvh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
body.order-screen main {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  max-width: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
}
.order-top {
  position: relative;
  top: auto;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
  min-height: 48px;
  padding: 6px 8px;
  flex: 0 0 auto;
}
.order-back, .order-top .logout-form button {
  border-radius: 0;
  border: 1px solid rgba(255, 255, 255, .35);
  padding: 6px 12px;
  color: #f6f1e8;
  text-decoration: none;
  font-weight: 700;
  background: transparent;
}
.order-back { justify-self: start; }
.order-top .logout-form { justify-self: end; margin: 0; }
.order-table {
  margin: 0;
  color: #f6f1e8;
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: 0;
  text-align: center;
  white-space: nowrap;
}
body.order-screen .order-toast {
  position: fixed;
  z-index: 40;
  top: 56px;
  left: 50%;
  transform: translateX(-50%);
  margin: 0;
  max-width: min(480px, calc(100% - 24px));
}
body.order-screen .order-layout {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-columns: 200px minmax(0, 1fr) minmax(580px, 640px);
  gap: 0;
  align-items: stretch;
}
body.order-screen .cats {
  display: flex;
  flex-direction: column;
  gap: 0;
  height: 100%;
  min-height: 0;
  overflow: hidden;
  padding: 0;
  background: #fffaf3;
  border-right: 1px solid var(--line);
}
body.order-screen .cat {
  flex: 1 1 0;
  width: 100%;
  min-height: 0;
  margin: 0;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 0;
  padding: 0 10px;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  background: #fffaf3;
  box-shadow: none;
  text-align: left;
  white-space: nowrap;
}
body.order-screen .cat span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
body.order-screen .cat.on {
  background: #c41212;
  color: #fff;
  border-bottom-color: #c41212;
}
body.order-screen .catalog {
  min-width: 0;
  min-height: 0;
  height: 100%;
  overflow: auto;
  padding: 8px;
  scrollbar-gutter: stable;
}
body.order-screen .catalog input[type="search"] {
  position: sticky;
  top: 0;
  z-index: 2;
  margin: 0 0 8px;
  min-height: 36px;
  border-radius: 0;
  background: white;
}
body.order-screen .product-group { margin: 0; }
body.order-screen .bill {
  min-width: 0;
  min-height: 0;
  height: 100%;
  margin: 0;
  padding: 8px 10px 10px;
  border-radius: 0;
  box-shadow: none;
  border-top: 0;
  border-bottom: 0;
  border-right: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
body.order-screen .bill-head,
body.order-screen .bill-sum,
body.order-screen .totals,
body.order-screen .pays,
body.order-screen .bill-actions { flex: 0 0 auto; }
body.order-screen .bill-head h2,
body.order-screen .totals { margin-bottom: 0; }
body.order-screen .bill-sum { padding: 2px 0 8px; }
body.order-screen .lines {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  scrollbar-gutter: stable;
}
body.order-screen .lines li { padding: 4px 0; }
body.order-screen .line-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
body.order-screen .line-tools {
  display: flex;
  align-items: center;
  gap: 0;
  flex: 0 0 auto;
}
body.order-screen .line-tools form { display: flex; margin: 0; }
body.order-screen .line-tools .btn {
  min-height: 32px;
  padding: 0 8px;
  border-radius: 0;
  font-size: .82rem;
}
body.order-screen .line-tools .qty { padding: 0 6px; }
body.order-screen .line-name {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  align-items: baseline;
  gap: 6px;
}
body.order-screen .line-name strong {
  flex: 0 1 auto;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
body.order-screen .line-name span {
  color: var(--muted);
  font-size: .82rem;
  flex: 0 0 auto;
  white-space: nowrap;
}
body.order-screen .badge { flex: 0 0 auto; border-radius: 0; }
body.order-screen .price-form { flex: 0 0 auto; gap: 4px; }
body.order-screen .price-form input {
  width: 72px;
  min-height: 32px;
  padding: 2px 6px;
  border-radius: 0;
}
body.order-screen .line-total { flex: 0 0 auto; white-space: nowrap; }
body.order-screen .comp .line-total { color: var(--muted); text-decoration: line-through; }
body.order-screen .bill-actions details[open] { border-radius: 0; }

@media (max-width: 1180px) {
  body.order-screen .order-layout { grid-template-columns: 160px minmax(0, 1fr) 560px; }
}
@media (max-width: 900px) {
  body.order-screen { height: auto; min-height: 100dvh; overflow: auto; }
  body.order-screen main { display: block; }
  body.order-screen .order-layout { display: flex; flex-direction: column; height: auto; }
  body.order-screen .cats {
    flex-direction: row;
    height: auto;
    overflow-x: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
  body.order-screen .cat {
    flex: 0 0 auto;
    width: auto;
    min-height: 40px;
    border-bottom: 0;
    border-right: 1px solid var(--line);
  }
  body.order-screen .catalog, body.order-screen .bill { height: auto; overflow: visible; }
  body.order-screen .lines { overflow: visible; }
}
@media print {
  body.order-screen, body.order-screen main { height: auto; overflow: visible; display: block; }
  body.order-screen .order-layout, body.order-screen .bill, body.order-screen .lines, body.order-screen .catalog {
    height: auto;
    overflow: visible;
    display: block;
  }
}

.combo { position: relative; width: 100%; }
.combo > select {
  position: absolute;
  width: 1px;
  height: 1px;
  min-height: 0;
  padding: 0;
  margin: 0;
  border: 0;
  opacity: 0;
  pointer-events: none;
  overflow: hidden;
}
.combo.open { z-index: 40; }
.combo-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  min-height: 48px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: white;
  font-weight: 560;
  text-align: left;
  cursor: pointer;
}
.combo.open .combo-toggle { border-color: #c4a484; box-shadow: 0 0 0 3px rgba(154, 52, 18, 0.12); }
.combo-value {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.combo-caret {
  flex: 0 0 auto;
  width: 8px;
  height: 8px;
  margin-right: 4px;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: translateY(-2px) rotate(45deg);
}
.combo-pop {
  position: absolute;
  z-index: 2;
  left: 0;
  right: 0;
  top: calc(100% + 4px);
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 8px;
  background: white;
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
}
.combo-pop.up { top: auto; bottom: calc(100% + 4px); }
input.combo-search { min-height: 42px; }
.combo-list {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-height: 240px;
  overflow: auto;
}
.combo-opt {
  display: block;
  width: 100%;
  padding: 8px 10px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  text-align: left;
  font-weight: 650;
  cursor: pointer;
}
.combo-opt:hover, .combo-opt.active { background: #f3e7d3; }
.combo-opt.on { background: #f6e2d4; color: var(--accent-dark); }
.combo-empty { color: var(--muted); padding: 8px 10px; font-weight: 650; }
