:root {
  --bg: #f4f1ea; --card: #fff; --ink: #1d1b16; --muted: #6b665c; --line: #e2ddd2;
  --accent: #c2410c; --accent-ink: #fff; --ok: #15803d; --err: #b91c1c;
  font-family: "Segoe UI", "Nirmala UI", system-ui, sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); }
.ta { font-family: "Nirmala UI", "Latha", sans-serif; color: var(--muted); font-weight: 400; }
header { display: flex; align-items: center; gap: 20px; padding: 10px 20px; background: #1d1b16; color: #fff; position: sticky; top: 0; z-index: 5; flex-wrap: wrap; }
header .brand { display: flex; flex-direction: column; line-height: 1.2; }
header .brand .ta { color: #d6cfbf; font-size: 13px; }
nav { display: flex; gap: 4px; flex-wrap: wrap; }
nav button { background: transparent; color: #d6cfbf; border: 0; padding: 8px 14px; border-radius: 6px; font-size: 14px; cursor: pointer; }
nav button.active, nav button:hover { background: #3a362d; color: #fff; }
.link { margin-left: auto; font-size: 13px; color: #d6cfbf; }
main { padding: 20px; display: grid; grid-template-columns: minmax(0, 1fr) 420px; gap: 20px; align-items: start; }
.tab { display: none; grid-column: 1; }
.tab.active { display: block; }
.preview-wrap { grid-column: 2; grid-row: 1 / span 6; position: sticky; top: 76px; }
.preview-wrap h3 { margin: 0 0 8px; font-size: 15px; }
.preview-wrap small { color: var(--muted); font-weight: 400; }
.preview { background: #d9d4c7; padding: 16px; border-radius: 8px; display: flex; flex-direction: column; align-items: center; gap: 14px; max-height: calc(100vh - 130px); overflow: auto; min-height: 200px; }
.preview canvas { image-rendering: pixelated; box-shadow: 0 8px 20px rgba(16,24,40,.12); background: #fff; max-width: 100%; padding: 8px 8px 16px; border: 1px solid #ddd;
  /* torn paper edge, same as the virtual dispenser slip */
  -webkit-mask: linear-gradient(#000 0 0) top / 100% calc(100% - 8px) no-repeat, radial-gradient(circle 6px at 8px 100%, transparent 98%, #000) bottom / 16px 8px repeat-x;
  mask: linear-gradient(#000 0 0) top / 100% calc(100% - 8px) no-repeat, radial-gradient(circle 6px at 8px 100%, transparent 98%, #000) bottom / 16px 8px repeat-x;
  animation: slip-out .5s ease-out; }
@keyframes slip-out { from { transform: translateY(-30px); opacity: 0; } }
.preview .empty { color: var(--muted); font-size: 14px; margin-top: 60px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 16px; }
.card h3 { margin: 0 0 6px; font-size: 16px; }
.card p, .hint { margin: 0 0 10px; color: var(--muted); font-size: 13px; line-height: 1.45; }
button { font: inherit; font-size: 14px; padding: 8px 14px; border-radius: 6px; border: 1px solid var(--ink); background: var(--ink); color: #fff; cursor: pointer; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
button.ghost { background: transparent; color: var(--ink); border-color: var(--line); }
button.ghost:hover { border-color: var(--ink); }
button.danger { color: var(--err); }
button.big { padding: 12px 20px; font-size: 16px; font-weight: 600; }
button:disabled { opacity: .5; cursor: wait; }
.row { display: flex; gap: 10px; align-items: end; flex-wrap: wrap; }
.row.space { justify-content: space-between; align-items: center; margin-bottom: 10px; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); margin-bottom: 10px; }
label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--ink); }
input, select, textarea { font: inherit; font-size: 14px; padding: 7px 9px; border: 1px solid var(--line); border-radius: 6px; color: var(--ink); background: #fff; }
textarea { width: 100%; font-family: "Nirmala UI", "Segoe UI", sans-serif; margin-bottom: 8px; }

.counter-grid { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 16px; align-items: start; }
.menu-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.food { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 14px 12px; text-align: left; color: var(--ink); cursor: pointer; display: flex; flex-direction: column; gap: 4px; min-height: 104px; position: relative; }
.food:hover { border-color: var(--accent); }
.food .t { font-family: "Nirmala UI", sans-serif; font-size: 18px; font-weight: 700; }
.food .e { font-size: 13px; color: var(--muted); }
.food .p { margin-top: auto; font-weight: 600; }
.food .q { position: absolute; top: 8px; right: 8px; background: var(--accent); color: #fff; border-radius: 99px; min-width: 24px; height: 24px; display: grid; place-items: center; font-size: 13px; font-weight: 700; }
.food .c { position: absolute; bottom: 10px; right: 10px; font-size: 11px; color: var(--muted); }
.cart { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 16px; position: sticky; top: 76px; }
.cart-head { display: flex; justify-content: space-between; align-items: baseline; }
.cart-head h2 { margin: 0 0 10px; font-size: 18px; }
.next { font-size: 13px; color: var(--muted); }
.next b { color: var(--accent); font-size: 18px; }
.cart-lines { min-height: 80px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); padding: 6px 0; margin-bottom: 10px; }
.cart-line { display: grid; grid-template-columns: 1fr auto auto; gap: 8px; align-items: center; padding: 6px 0; }
.cart-line .n { font-family: "Nirmala UI", sans-serif; font-weight: 600; }
.cart-line .n small { display: block; color: var(--muted); font-weight: 400; font-family: "Segoe UI", sans-serif; }
.qty { display: flex; align-items: center; gap: 6px; }
.qty button { padding: 2px 9px; background: transparent; color: var(--ink); border-color: var(--line); }
.cart-empty { color: var(--muted); font-size: 14px; padding: 20px 0; text-align: center; }
.cart-total { display: flex; justify-content: space-between; font-size: 18px; margin-bottom: 10px; }
.status { margin-top: 12px; font-size: 13px; line-height: 1.4; word-break: break-word; }
.status.ok { color: var(--ok); }
.status.err { color: var(--err); }

.tests { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.tests .wide { grid-column: 1 / -1; }
.tests .card { display: flex; flex-direction: column; }
.tests .card > button { margin-top: auto; align-self: start; }
.settings { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 14px; }
.settings input:not([type=checkbox]):not([type=range]):not([type=file]), .settings select { width: 100%; }
.settings .row label { flex: 1; }
.sticky-save { position: sticky; bottom: 0; padding: 14px 0; background: linear-gradient(transparent, var(--bg) 40%); }
#logoPreview { max-height: 60px; max-width: 200px; }
#logoPreview:not([src]), #logoPreview[src=""] { display: none; }
.menu-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.menu-table th { text-align: left; color: var(--muted); font-weight: 500; padding: 6px; border-bottom: 1px solid var(--line); }
.menu-table td { padding: 4px 6px; border-bottom: 1px solid var(--line); }
.menu-table input { width: 100%; }
.menu-table td.ta-cell input { font-family: "Nirmala UI", sans-serif; }
#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 8px; font-size: 14px; z-index: 20; max-width: 80vw; }
#toast.err { background: var(--err); }

@media (max-width: 1100px) {
  main { grid-template-columns: 1fr; }
  .preview-wrap { grid-column: 1; grid-row: auto; position: static; }
  .counter-grid { grid-template-columns: 1fr; }
  .cart { position: static; }
}
