
:root {
  --bg: #f7f9fc;
  --panel: #ffffff;
  --surface-alt: #f9fafb;
  --accent: #ff4f8b;
  --accent-2: #10b981;
  --accent-add: #ff7a1a;
  --hud: #a15fff;
  --screen-bg: #2dd4c4;
  --danger: #ef4444;
  --warning: #f59e0b;
  --text: #1f2937;
  --muted: #6b7280;
  --hairline: #e5e7eb;
  --outline: #111111;
  --tile-border: var(--outline);
  --calc-bg: #111827;
  --calc-text: #f9fafb;
  /* 2.0 outline system: every component border is bold; shadow tiers only vary depth. */
  --border-w-lg: 3px;
  --border-w-sm: 3px;
  --shadow-lg: 4px 4px 0 var(--outline);
  --shadow: var(--shadow-lg);
  --badge-green-bg: #10b981; --badge-green-text: #ffffff;
  --badge-red-bg: #ef4444; --badge-red-text: #ffffff;
  --badge-blue-bg: #a15fff; --badge-blue-text: #ffffff;
  --badge-amber-bg: #ffc83d; --badge-amber-text: #111827;
  --badge-gray-bg: #e5e7eb; --badge-gray-text: #111827;
  --app-height: 100vh;
  --category-size: clamp(112px, 17vh, 194px);
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 48px;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-pill: 999px;
  --shell-gutter: clamp(6px, 1.2vmin, 12px);
  --panel-gap: clamp(4px, 0.7vmin, 8px);
  --panel-inset: clamp(8px, 1.3vmin, 16px);
  /* Type scale */
  --font-h1: 800 34px/1.15 system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
  --font-h2: 800 22px/1.2 system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
  --font-h3: 700 17px/1.25 system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
  --font-body: 400 15px/1.4 system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
  --font-caption: 400 13px/1.3 system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
}

@supports (height: 100dvh) {
  :root {
    --app-height: 100dvh;
    --category-size: clamp(112px, 17dvh, 194px);
  }
}

:root[data-theme="dark"] {
  --bg: #0b0d12;
  --panel: #171a21;
  --surface-alt: #1e222b;
  --accent: #ff6fa8;
  --accent-2: #34d399;
  --accent-add: #ff9152;
  --hud: #b98bff;
  --screen-bg: #0f6e64;
  --danger: #f87171;
  --warning: #fbbf24;
  --text: #f5f6f8;
  --muted: #9aa1ac;
  --hairline: #262b35;
  /* Dark mode gets its own near-white outline — a black border is invisible against
     the dark surface/background, so this can't reuse light mode's #111. */
  --outline: #e8e9ee;
  --tile-border: var(--outline);
  --calc-bg: #0b0f19;
  --calc-text: #f5f6f8;
  --shadow-lg: 4px 4px 0 var(--outline);
  --shadow: var(--shadow-lg);
  --badge-green-bg: #34d399; --badge-green-text: #ffffff;
  --badge-red-bg: #f87171; --badge-red-text: #ffffff;
  --badge-blue-bg: #b98bff; --badge-blue-text: #ffffff;
  --badge-amber-bg: #ffc83d; --badge-amber-text: #3a2a06;
  --badge-gray-bg: #3a3f4a; --badge-gray-text: #e8e9ee;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }

/* Type scale utilities */
.h1 { font: var(--font-h1); margin: 0; }
.h2 { font: var(--font-h2); margin: 0; }
.h3 { font: var(--font-h3); margin: 0; }
.body-text { font: var(--font-body); }
.caption { font: var(--font-caption); color: var(--muted); }
.price { font-weight: 800; font-variant-numeric: tabular-nums; }
body {
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
  background: var(--screen-bg);
}
.app-page { width: 100%; height: 100%; overflow: hidden; overscroll-behavior: none; display: flex; flex-direction: column; }

#app {
  display: flex;
  flex-direction: column;
  height: auto;
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  overflow: hidden;
  padding-left: max(var(--shell-gutter), env(safe-area-inset-left));
  padding-right: max(var(--shell-gutter), env(safe-area-inset-right));
  padding-top: max(var(--shell-gutter), env(safe-area-inset-top));
  padding-bottom: max(var(--shell-gutter), env(safe-area-inset-bottom));
}

.panel {
  background: var(--panel);
  border: var(--border-w-lg) solid var(--outline);
  box-shadow: var(--shadow);
  margin: var(--panel-gap);
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
}

#bottom-row { display: flex; flex: 1 1 auto; min-height: 0; align-items: stretch; overflow: hidden; }
#output-panel { flex: 2.125 1 68%; min-width: 0; min-height: 0; padding: var(--panel-inset); overflow: hidden; }
#calc-panel { flex: 1 1 32%; min-width: 0; min-height: 0; padding: var(--panel-inset); overflow: hidden; }
#products-panel {
  flex: 0 0 clamp(190px, 31vh, 340px);
  min-height: 0;
  padding: var(--panel-inset);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
@supports (height: 100dvh) {
  #products-panel { flex-basis: clamp(190px, 31dvh, 340px); }
}

/* Calculator vertical stack */
#calc-panel { display: flex; flex-direction: column; }
/* Categories area now sits under top row and fills remaining height */
#products-panel .carousel { position: relative; display: flex; flex: 1 1 auto; min-height: 0; align-items: center; overflow: hidden; }
#products-panel .carousel-track { flex: 1; height: 100%; min-height: 0; display: flex; align-items: center; flex-wrap: nowrap; gap: 8px; overflow-x: auto; overflow-y: hidden; scroll-behavior: smooth; scrollbar-width: none; -webkit-overflow-scrolling: touch; padding: clamp(2px, 0.7vmin, 8px) 0; }
#products-panel .carousel-track::-webkit-scrollbar { display: none; }

/* Categories row */
#categories { display: flex; flex-wrap: nowrap; gap: 8px; }
#categories .category-tile { width: var(--category-size); height: var(--category-size); flex: 0 0 auto; }

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
.header h1 {
  font: var(--font-h2);
  margin: 0;
}
.screen-title { color: var(--hud); font: var(--font-h2); font-weight: 900; }
.header .actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
/* Keep title + adjacent buttons in a single row */
.header-left { display: flex; align-items: center; gap: 8px; flex-wrap: nowrap; }
/* Default button look. Deliberately a bare `button` type selector (not a `:not()` exclusion
   chain) so every single-class variant below (.tile, .ghost, .success, .danger, .edit-btn, …)
   naturally outranks it by specificity and doesn't need to be enumerated here to opt out. */
button, .btn {
  font-size: 1.1rem;
  padding: 14px 18px;
  border-radius: var(--radius-md);
  border: var(--border-w-lg) solid var(--outline);
  background: var(--accent);
  color: white;
  cursor: pointer;
  box-shadow: var(--shadow-lg);
}
button:disabled { opacity: 0.6; cursor: not-allowed; }
.file-btn { display: inline-flex; align-items: center; cursor: pointer; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
button.secondary { background: #4b5563; }
button.success { background: var(--accent-2); }
button.danger { background: var(--danger); }
button.ghost { background: var(--surface-alt); color: var(--text); }
button.block { width: 100%; }

.list {
  background: var(--surface-alt);
  border-radius: 12px;
  padding: 12px;
  overflow: auto;
  flex: 1;
  min-height: 0;
  -webkit-overflow-scrolling: touch;
}
.list .row {
  display: grid;
  grid-template-columns: 1fr 120px 100px 120px;
  gap: 8px;
  padding: 10px 8px;
  align-items: center;
  border-bottom: 1px solid var(--hairline);
}
.list .row .title { display: flex; align-items: center; gap: 10px; }
.list .row img { width: 40px; height: 40px; object-fit: cover; border: var(--border-w-lg) solid var(--outline); border-radius: 8px; background: var(--panel); }
/* Quantity controls: horizontal - minus | value | plus */
.qty-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.qty-btn {
  width: 40px;
  height: 40px;
  padding: 0;
  line-height: 1;
  font-size: 1.1rem;
  border-radius: var(--radius-md);
  background: var(--panel);
  color: var(--text);
  border: var(--border-w-lg) solid var(--outline);
  box-shadow: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.qty-value {
  min-width: 24px;
  text-align: center;
  font-weight: 700;
}

/* Cart action button: Entfernen – white schema and compact */
.list .row .danger {
  background: var(--panel);
  color: var(--text);
  border: var(--border-w-sm) solid var(--outline);
  box-shadow: none;
  padding: 8px 12px;
  font-size: 0.95rem;
  border-radius: var(--radius-sm);
}

.totals {
  margin-top: 10px;
  padding-top: 10px;
  border-top: var(--border-w-lg) solid var(--outline);
  display: flex; justify-content: space-between; align-items: center;
  font-weight: 800;
  font-size: 1.3rem;
  font-variant-numeric: tabular-nums;
}

#checkout-area { margin-top: 10px; }
#btn-new-session, #btn-order-pay { font-weight: 900; }

#categories {
  /* Grid layout removed in favor of horizontal carousel */
  gap: 8px;
  margin-top: 0;
}
#categories .category-tile { font-size: 1.2rem; padding: 12px; }

/* Generic white tile look */
.tile {
  background: var(--panel);
  color: var(--text);
  border: var(--border-w-lg) solid var(--outline);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
}

/* Ensure button tiles do not inherit default blue */
button.tile {
  background: var(--panel);
  color: var(--text);
  border: var(--border-w-lg) solid var(--outline);
}

/* Category tiles: image on top, label below */
#categories .category-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: var(--category-size);
  height: var(--category-size);
  flex: 0 0 var(--category-size);
  min-width: var(--category-size);
  text-align: center;
}
#categories .category-tile img {
  width: 100%;
  height: calc(var(--category-size) - 58px);
  object-fit: cover;
  background: var(--panel); /* ensure transparent thumbs render over panel bg */
  border-radius: 12px;
}
#categories .category-label { font-weight: 700; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

#calculator {
  display: grid;
  flex: 1 1 auto;
  min-height: 0;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(4, minmax(44px, 1fr));
  gap: 8px;
  margin-top: 8px;
}
#calc-display {
  grid-column: span 4;
  font-size: 2rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  padding: 12px;
  border-radius: var(--radius-md);
  background: var(--calc-bg);
  color: var(--calc-text);
  text-align: right;
  min-height: 64px;
}
.calc-btn {
  font-size: 1.4rem;
  font-weight: 800;
  padding: 18px;
  background: var(--panel);
  color: var(--text);
  border: var(--border-w-sm) solid var(--outline);
  border-radius: var(--radius-md);
  box-shadow: none;
}
.calc-btn-enter {
  background: var(--accent);
  color: #ffffff;
}

.modal {
  position: fixed; inset: 0 0 auto; height: var(--app-height); background: rgba(0,0,0,0.4);
  display: none; align-items: center; justify-content: center; padding: 20px;
  /* Must outrank any z-indexed content on the page behind it (e.g. .product-add-btn) —
     without this, elements with an explicit z-index paint above a z-index:auto .modal
     regardless of DOM order. */
  z-index: 1000;
}
.modal.open { display: flex; }
.modal .card { background: var(--panel); width: min(900px, 95vw); max-height: calc(var(--app-height) - 32px); overflow: auto; -webkit-overflow-scrolling: touch; border: var(--border-w-lg) solid var(--outline); border-radius: var(--radius-lg); padding: 16px; box-shadow: var(--shadow); }
/* Product detail: intrinsic height avoids a scrollbar when all content fits. */
.product-detail-card {
  width: min(760px, calc(100vw - 32px)) !important;
  max-height: calc(var(--app-height) - 32px) !important;
  overflow-y: auto !important;
  overflow-x: hidden !important;
  --pd-qr-size: 160px;
}
.product-detail-card .grid { display: block !important; overflow: visible; }
.product-detail-card > .header { position: static !important; }
.product-detail-grid { display: grid; gap: 16px; height: auto; }
.pd-media-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) calc(var(--pd-qr-size) + 24px);
  gap: 16px;
  align-items: stretch;
}
.product-detail-grid .pd-image {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  height: 216px;
  background: var(--surface-alt);
  border: var(--border-w-sm) solid var(--outline);
  border-radius: var(--radius-md);
  overflow: hidden;
}
.product-detail-grid .pd-image img { width: 100%; height: 100%; object-fit: cover; background: var(--surface-alt); }
.product-detail-grid .pd-content { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.pd-title { font: var(--font-h3); margin: 0; }
.pd-sub { font-size: 0.95rem; }
.pd-section-title { font-weight: 700; margin-top: 6px; }
.pd-desc { line-height: 1.4; }
.pd-price { font-size: 1.1rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.pd-qr-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: 0;
  padding: 8px;
  background: #ffffff;
  color: #111827;
  border: var(--border-w-sm) solid var(--outline);
  border-radius: var(--radius-md);
  overflow: hidden;
}
.pd-qr-label { font-size: 0.85rem; font-weight: 800; }
.pd-qr-wrap { display: flex; align-items: center; justify-content: center; width: var(--pd-qr-size); height: var(--pd-qr-size); flex: 0 0 var(--pd-qr-size); overflow: hidden; }
.pd-qr-wrap canvas,
.pd-qr-wrap img { width: var(--pd-qr-size) !important; height: var(--pd-qr-size) !important; max-width: 100%; }
.btn-group.pd-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  width: 100%;
  margin-top: 8px;
}
.pd-actions button { width: 100%; min-width: 0; white-space: normal; }

@media (max-width: 600px) {
  .product-detail-card {
    width: calc(100vw - 24px) !important;
    max-height: calc(var(--app-height) - 24px) !important;
    --pd-qr-size: 128px;
  }
  .pd-media-grid { grid-template-columns: minmax(0, 1fr) calc(var(--pd-qr-size) + 16px); gap: 8px; }
  .product-detail-grid .pd-image { height: 168px; }
  .pd-qr-panel { padding: 6px; gap: 4px; }
  .pd-actions { grid-template-columns: 1fr; }
}
/* Sticky header inside modal card */
.modal .card > .header {
  position: sticky;
  top: 0;
  background: var(--panel);
  z-index: 2;
  padding-top: 8px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--hairline);
}
.modal .grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
.modal .grid .item { display: flex; flex-direction: column; align-items: center; justify-content: space-between; gap: 6px; padding: 8px; }
.modal .grid .form-wrap { grid-column: 1 / -1; display: flex; flex-direction: column; gap: 12px; }

/* Checkout options */
.pay-tile { width: 100%; height: 200px; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.pay-img-wrap { position: relative; width: 100%; height: 110px; display: flex; align-items: center; justify-content: center; }
.pay-img-wrap .icon-emoji { font-size: 64px; line-height: 1; }
.pay-title-overlay { position: absolute; left: 0; right: 0; bottom: 0; padding: 4px 6px; background: rgba(0,0,0,0.65); color: #fff; font-weight: 700; font-size: 0.9rem; text-align: center; border-bottom-left-radius: 12px; border-bottom-right-radius: 12px; }

/* Cash keypad inside modal */
.cash-display { font-size: 1.3rem; font-weight: 800; font-variant-numeric: tabular-nums; background: var(--calc-bg); color: var(--calc-text); padding: 10px; border-radius: var(--radius-md); }
.cash-change { font-size: 1rem; }
.cash-keypad { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }

/* Sessions table in modal */
.session-table { grid-column: 1 / -1; width: 100%; }
.session-head, .session-row { display: grid; grid-template-columns: 2fr 1fr 1fr auto; gap: 8px; align-items: center; padding: 10px 8px; }
.session-head { font-weight: 700; background: var(--surface-alt); border-radius: 8px; }
.session-row { background: var(--surface-alt); border-radius: 8px; margin-top: 6px; }
.session-actions { display: flex; gap: 8px; justify-content: flex-end; }
.product-tile {
  width: 100%;
  /* Allow content to define height to avoid overflow/overlap */
  min-height: 200px;
  height: auto;
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding-bottom: 6px;
  overflow: visible; /* let the add-button pop past the image corner */
}
.product-img-wrap { position: relative; width: 100%; height: 110px; overflow: visible; border-radius: var(--radius-md); background: var(--panel); }
.product-img-wrap img { display: block; width: 100%; height: 100%; object-fit: cover; border-radius: inherit; background: var(--panel); }
.edit-btn {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-pill);
  background: var(--panel);
  color: var(--text);
  border: var(--border-w-sm) solid var(--outline);
  box-shadow: none;
}
.copy-btn {
  position: absolute;
  top: 6px;
  left: 6px;
  width: 28px; height: 28px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius-pill);
  background: var(--panel); color: var(--text); border: var(--border-w-sm) solid var(--outline);
  box-shadow: none;
}
.hide-btn {
  position: absolute;
  top: 6px;
  left: 42px;
  width: 28px; height: 28px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius-pill);
  background: var(--panel); color: var(--text); border: var(--border-w-sm) solid var(--outline);
  box-shadow: none;
}
/* 2.0 add control: square, high-contrast and locked to every image corner. */
.product-add-btn {
  position: absolute;
  right: -8px;
  bottom: -8px;
  width: 40px;
  height: 40px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  background: var(--accent-add);
  color: #ffffff;
  border: var(--border-w-lg) solid var(--outline);
  box-shadow: var(--shadow-lg);
  font-size: 1.55rem;
  font-weight: 900;
  line-height: 1;
}
.product-title { font-weight: 700; text-align: center; color: var(--text); margin-top: 4px; font-size: 0.95rem; display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical; overflow: hidden; }
.product-desc { font-size: 0.8rem; color: var(--muted); text-align: center; display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical; overflow: hidden; }
.product-price { text-align: center; font-size: 0.95rem; }

/* iPad/tablet landscape with Safari browser bars visible. */
@media (min-width: 601px) and (max-height: 900px) {
  :root { --category-size: clamp(112px, 17dvh, 154px); }
  .panel { margin: 4px; }
  #products-panel, #output-panel, #calc-panel { padding: 8px; }
  .header { margin-bottom: 6px; }
  button:not(.tile):not(.calc-btn):not(.qty-btn):not(.icon-btn):not(.chip), .btn {
    min-height: 44px;
    padding: 10px 14px;
    font-size: 1rem;
  }
  #categories { margin-top: 2px; }
  #products-panel .carousel-track { padding-top: 4px; padding-bottom: 4px; }
  #calc-display { min-height: 52px; padding: 8px 10px; font-size: 1.65rem; }
  #calculator { gap: 6px; margin-top: 6px; }
  .calc-btn { min-height: 44px; padding: 8px; font-size: 1.2rem; }
  .totals { margin-top: 6px; padding-top: 6px; }
  #checkout-area { margin-top: 6px; }
}

/* Extra-compact fallback for older/smaller iPad Air Safari viewports. */
@media (min-width: 601px) and (max-height: 720px) {
  :root { --category-size: 104px; }
  #app { padding: max(4px, env(safe-area-inset-top)) max(4px, env(safe-area-inset-right)) max(4px, env(safe-area-inset-bottom)) max(4px, env(safe-area-inset-left)); }
  .panel { margin: 3px; }
  #products-panel { flex-basis: 180px; padding: 6px; }
  #output-panel, #calc-panel { padding: 6px; }
  .header { margin-bottom: 4px; }
  .header h1, .header h2 { font-size: 1.05rem; }
  #products-panel .carousel-track { padding-top: 2px; padding-bottom: 2px; }
  #categories .category-tile { padding: 6px; font-size: 1rem; gap: 4px; }
  #categories .category-tile img { height: calc(var(--category-size) - 44px); }
  #calc-display { min-height: 46px; font-size: 1.4rem; }
  #calculator { gap: 4px; margin-top: 4px; }
  .calc-btn { min-height: 40px; padding: 5px; font-size: 1.1rem; }
}

.kiosk-only { display: block; overflow: visible; }
.terminal-only { display: none; }

/* Mode switching: kiosk shows either #app (Supermarkt) or #restaurant-app (Restaurant) */
#restaurant-app { display: none; }
body[data-mode="restaurant"] #app { display: none; }
body[data-mode="restaurant"] #restaurant-app { display: flex; }

/* Mobile terminal mode (<= 600px) */
@media (max-width: 600px) {
  #app { display: none; } /* hide kiosk UI */
  .kiosk-only { display: none; }
  .terminal-only { display: flex; }
  body[data-mode="restaurant"] #restaurant-app { display: none; }
}

#terminal {
  position: relative;
  height: var(--app-height); width: 100%; display: none; align-items: center; justify-content: center;
  background: var(--screen-bg); color: var(--text); padding: 24px;
}
#terminal .topbar { position: absolute; top: 12px; left: 16px; right: 16px; z-index: 10; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
#terminal .terminal-brand { display: flex; align-items: center; gap: 8px; font-weight: 900; }
#terminal .terminal-brand .logo { width: 36px; height: 36px; border-radius: var(--radius-sm); object-fit: cover; }
#terminal .terminal-topbar-actions { position: relative; display: flex; align-items: center; }
#terminal.open { display: flex; }
#terminal .wrap {
  width: min(420px, 100%); background: var(--panel); padding: 20px; border: var(--border-w-lg) solid var(--outline); border-radius: var(--radius-lg); box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 12px; text-align: center;
}
#terminal h2 { margin: 0; }
#terminal .amount { font-size: 2rem; font-weight: 800; font-variant-numeric: tabular-nums; }
#terminal .status { font-size: 1.1rem; color: var(--muted); }

.small { font-size: 0.9rem; color: var(--muted); }
.muted { color: var(--muted); }

/* Utility classes */
.hidden { display: none !important; }
.mt-12 { margin-top: 12px !important; }
.m-0 { margin: 0 !important; }
.bold { font-weight: 700 !important; }
.w-100 { width: 100% !important; }
.btn-group { display: flex; gap: 8px; flex-wrap: wrap; }
.scanner-video { width: 100%; max-height: 300px; }
.scanner-controls { display: flex; gap: 8px; margin-top: 12px; }
.scanner-controls input { flex: 1; min-width: 0; }
.photo-preview { width: 96px; height: 72px; object-fit: contain; border: var(--border-w-lg) solid var(--outline); border-radius: var(--radius-sm); background: #fff; }

/* Alert banner (top center) */
.alert-banner {
  position: fixed;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 9999;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  border: var(--border-w-lg) solid transparent;
}
.alert-error { background: #fee2e2; color: #7f1d1d; border-color: #fca5a5; }
.alert-success { background: #dcfce7; color: #14532d; border-color: #86efac; }
.alert-banner .close-btn {
  margin-left: 6px;
  width: 28px; height: 28px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: var(--radius-pill); cursor: pointer;
  background: var(--panel); color: var(--text); border: var(--border-w-sm) solid var(--outline); box-shadow: none;
}

input, select {
  padding: 12px 14px; border-radius: var(--radius-md); border: var(--border-w-lg) solid var(--outline); background: var(--panel); color: var(--text); font-size: 1rem; width: 100%;
}

label { font-weight: 600; font-size: 0.95rem; }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-row > div { display: flex; flex-direction: column; gap: 6px; }
.inline-field { display: flex; align-items: center; gap: 8px; }
.form-error { color: var(--danger); font-size: 0.9rem; margin-top: 4px; }
.security-warning { margin: 0; padding: 10px 12px; border: var(--border-w-lg) solid #f59e0b; border-radius: var(--radius-md); background: #fffbeb; color: #78350f; }

.badge { padding: 4px 8px; border-radius: var(--radius-pill); background: var(--badge-gray-bg); color: var(--badge-gray-text); border: var(--border-w-sm) solid var(--outline); font-size: 0.8rem; font-weight: 700; }
.badge.green { background: var(--badge-green-bg); color: var(--badge-green-text); }
.badge.red { background: var(--badge-red-bg); color: var(--badge-red-text); }
.badge.blue { background: var(--badge-blue-bg); color: var(--badge-blue-text); }
.badge.amber { background: var(--badge-amber-bg); color: var(--badge-amber-text); }

footer { margin-top: 8px; color: var(--muted); font-size: 0.85rem; }

/* Policy page */
.policy { max-width: 900px; margin: 20px auto; padding: 16px; background: #ffffff; border: var(--border-w-lg) solid var(--outline); border-radius: var(--radius-md); box-shadow: var(--shadow); }
.policy h1 { margin-top: 0; }
.policy-table { width: 100%; border-collapse: collapse; margin: 12px 0; }
.policy-table th, .policy-table td { border: 1px solid #e5e7eb; padding: 8px; text-align: left; }
.policy-table thead { background: #f3f4f6; }

#calc-panel .header-left { display: flex; align-items: center; gap: 8px; }
.icon-btn {
  width: 40px; height: 40px; padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--panel); color: var(--text); border: var(--border-w-lg) solid var(--outline); border-radius: var(--radius-pill); box-shadow: none;
  font-size: 1.2rem; line-height: 1;
}
.add-icon-btn {
  background: var(--accent-add);
  color: #ffffff;
  border-radius: var(--radius-pill);
  box-shadow: var(--shadow-lg);
  font-size: 1.55rem;
  font-weight: 900;
}

button:focus-visible,
.btn:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
[role="button"]:focus-visible {
  outline: 4px solid var(--hud);
  outline-offset: 3px;
}

/* ============ Topbar + quick settings ============ */
#topbar {
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-4);
  padding: var(--space-2) calc(var(--shell-gutter) + var(--space-2)) 0;
  flex: 0 0 auto;
}
#topbar .brand { display: flex; align-items: center; gap: 8px; font-weight: 800; }
#topbar .brand .logo { width: 32px; height: 32px; border-radius: 8px; display: block; object-fit: cover; }
#topbar .topbar-actions { position: relative; display: flex; align-items: center; gap: 8px; }
.settings-toggle-btn { font-size: 1rem; font-weight: 900; letter-spacing: 1px; }
.quick-settings-menu {
  position: fixed; top: 56px; right: max(16px, env(safe-area-inset-right)); z-index: 2000;
  width: min(360px, calc(100vw - 32px)); padding: var(--space-4);
  display: flex; flex-direction: column; gap: var(--space-2);
  background: var(--panel); color: var(--text);
  border: var(--border-w-lg) solid var(--outline); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
}
.quick-settings-title { font: var(--font-h3); padding: 2px 4px 8px; border-bottom: 1px solid var(--hairline); }
.quick-setting-row { display: flex; align-items: center; justify-content: space-between; gap: var(--space-4); padding: var(--space-2) 0; }
.quick-setting-row > div { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.quick-setting-row span { color: var(--muted); font-size: 0.78rem; }
.quick-setting-row button,
.quick-settings-link {
  flex: 0 0 auto;
  min-width: 112px;
  padding: 9px 12px;
  font-size: 0.9rem;
  font-weight: 800;
  text-align: center;
  text-decoration: none;
  background: var(--surface-alt);
  color: var(--text);
  border: var(--border-w-lg) solid var(--outline);
  border-radius: var(--radius-md);
  box-shadow: none;
}
.terminal-settings-menu { top: 64px; }
@media (max-width: 600px) {
  #topbar { display: none; }
  .quick-settings-menu { right: 16px; }
}

/* ============ Restaurant app shell ============ */
#restaurant-app {
  flex-direction: column;
  height: auto;
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  overflow: hidden;
  padding-left: max(var(--shell-gutter), env(safe-area-inset-left));
  padding-right: max(var(--shell-gutter), env(safe-area-inset-right));
  padding-top: max(var(--shell-gutter), env(safe-area-inset-top));
  padding-bottom: max(var(--shell-gutter), env(safe-area-inset-bottom));
}
.restaurant-view {
  flex: 1 1 auto;
  min-height: 0;
  display: none;
  flex-direction: column;
  gap: var(--space-3);
  padding: var(--panel-inset);
}
.restaurant-view.active { display: flex; }

.rest-nav { display: flex; gap: 8px; margin-bottom: 10px; flex: 0 0 auto; }
.rest-nav button { font-size: 0.95rem; padding: 10px 16px; }
.rest-nav button.active { background: var(--accent-2); }

/* Room tabs & filter chips */
.room-tabs, .filter-chips { display: flex; gap: var(--space-2); flex-wrap: wrap; }
.chip {
  font-size: 0.85rem; font-weight: 700; padding: 8px 14px; border-radius: var(--radius-pill); cursor: pointer;
  background: var(--surface-alt); color: var(--text); border: var(--border-w-lg) solid var(--outline); box-shadow: none;
}
.chip.active { background: var(--accent); color: #fff; border-color: var(--outline); }

/* Table overview grid */
.tables-header { display: flex; justify-content: space-between; align-items: center; gap: var(--space-3); flex-wrap: wrap; flex: 0 0 auto; }
.tables-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: var(--space-3); overflow: auto; flex: 1; align-content: start; padding: 0; }
.table-tile {
  width: 100%; box-sizing: border-box; padding: 16px 8px; border-radius: var(--radius-md); text-align: center;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
  background: var(--panel); border: var(--border-w-lg) solid var(--outline); box-shadow: var(--shadow-lg); cursor: pointer;
}
.table-tile .table-number { font-size: 1.4rem; font-weight: 800; }
.table-tile .table-seats { font-size: 0.8rem; color: var(--muted); }
.status-legend { display: flex; gap: var(--space-4); flex-wrap: wrap; padding-top: var(--space-3); border-top: 1px solid var(--hairline); flex: 0 0 auto; }
.status-legend .legend-item { display: flex; align-items: center; gap: 8px; font-size: 0.8rem; font-weight: 600; color: var(--muted); }
.status-dot { width: 12px; height: 12px; border-radius: 50%; flex: 0 0 auto; border: var(--border-w-lg) solid var(--outline); }
.status-dot.frei { background: var(--badge-green-bg); }
.status-dot.besetzt { background: var(--badge-blue-bg); }
.status-dot.rechnung { background: var(--badge-amber-bg); }
.status-dot.reserviert { background: var(--badge-gray-bg); }

/* Order view: a dedicated 2.0 context HUD above the menu/ticket surface. */
#view-order { padding: var(--space-2); }
.order-header {
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr) auto;
  align-items: center;
  gap: var(--space-4);
  min-height: 104px;
  padding: var(--space-5);
  flex: 0 0 auto;
  background: var(--panel);
  border: var(--border-w-lg) solid var(--outline);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
}
.order-header-back {
  width: 40px;
  height: 40px;
  min-height: 40px;
  padding: 0;
  border: var(--border-w-lg) solid var(--outline);
  border-radius: var(--radius-md);
  background: var(--surface-alt);
  color: var(--text);
  box-shadow: none;
  font-size: 1.75rem;
  font-weight: 900;
  line-height: 1;
}
.order-header h2 {
  color: var(--hud);
  font-size: clamp(1.75rem, 3.2vw, 3rem);
  font-weight: 900;
  line-height: 1.05;
}
.order-header .badge {
  padding: 10px 22px;
  border-width: var(--border-w-lg);
  font-size: 1.05rem;
  font-weight: 900;
}
.order-mobile-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-2);
  flex: 0 0 auto;
}
.order-mobile-tabs button {
  min-height: 48px;
  padding: 9px 14px;
  background: var(--panel);
  color: var(--text);
  border: var(--border-w-lg) solid var(--outline);
  border-radius: var(--radius-md);
  box-shadow: none;
  font-size: 1rem;
  font-weight: 900;
}
.order-mobile-tabs button.active { background: var(--accent); color: #fff; box-shadow: var(--shadow-lg); }
.order-tab-count {
  display: inline-flex;
  min-width: 24px;
  height: 24px;
  margin-left: var(--space-1);
  padding: 0 7px;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-pill);
  background: var(--surface-alt);
  color: var(--text);
  border: var(--border-w-sm) solid var(--outline);
  font-size: .78rem;
  line-height: 1;
}
.order-body { display: flex; flex-direction: row; gap: var(--space-4); flex: 1; min-height: 0; margin: 0; padding: var(--space-5); }
.menu-panel { flex: 1 1 auto; min-width: 0; min-height: 0; display: none; flex-direction: column; gap: var(--space-3); overflow: hidden; }
.order-panel { flex: 1 1 auto; min-width: 0; min-height: 0; display: none; grid-template-columns: minmax(0, 1.55fr) minmax(280px, .85fr); gap: var(--space-3); overflow: hidden; }
.order-body[data-order-pane="menu"] .menu-panel { display: flex; }
.order-body[data-order-pane="ticket"] .order-panel { display: grid; }
.ticket-list-column { display: flex; flex: 1 1 auto; min-width: 0; min-height: 150px; padding: var(--space-2); flex-direction: column; gap: var(--space-2); overflow: hidden; background: var(--surface-alt); border: var(--border-w-lg) solid var(--outline); border-radius: var(--radius-md); }
.ticket-controls-column { display: flex; flex: 0 1 auto; min-width: 0; min-height: 0; padding: var(--space-2); flex-direction: column; gap: var(--space-2); overflow: auto; background: var(--surface-alt); border: var(--border-w-lg) solid var(--outline); border-radius: var(--radius-md); }
.order-actions { display: flex; gap: var(--space-1); flex-wrap: wrap; justify-content: flex-end; }
.order-actions button { min-height: 40px; padding: 7px 10px; border-width: var(--border-w-lg); box-shadow: none; font-size: .78rem; }
.menu-cat-tabs { display: flex; gap: var(--space-3); overflow-x: auto; padding: 0 4px 5px 0; flex: 0 0 auto; }
.menu-cat-tabs .chip { padding: 11px 19px; border-width: var(--border-w-lg); font-size: 1rem; font-weight: 850; white-space: nowrap; }
.menu-items-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: var(--space-4); overflow: auto; flex: 1; align-content: start; padding: 2px 8px 8px 2px; }
.menu-items-grid .product-tile { min-height: 260px; padding: var(--space-3); gap: var(--space-2); }
.menu-items-grid .product-img-wrap { height: 160px; min-height: 160px; flex: 0 0 160px; }
.menu-items-grid .product-title { margin-top: var(--space-2); font-size: 1.05rem; font-weight: 850; }
.menu-items-grid .product-price { font-size: 1.05rem; font-weight: 900; }
.order-ticket-list { flex: 1; min-height: 0; overflow: auto; }
.order-ticket-list .row { grid-template-columns: 1fr 96px 64px 68px; gap: var(--space-2); padding: var(--space-2); }
.order-ticket-list .row .danger { padding: var(--space-2); font-size: 0.8rem; }
.kitchen-sent-label { color: var(--accent-add); font-weight: 700; }
.order-option-group { margin-top: var(--space-3); }
.order-option-label { margin-bottom: var(--space-1); font-size: .9rem; font-weight: 750; color: var(--text); }
.order-option-note { margin-top: var(--space-1); color: var(--muted); font-size: .78rem; line-height: 1.3; }
.order-chip-row { display: flex; gap: var(--space-2); flex-wrap: wrap; }
.order-chip-row .chip { flex: 1 1 auto; min-width: 70px; text-align: center; }
#order-split-chips { padding-right: 52px; }
.order-panel .totals { gap: 10px; }
.order-panel .totals > :first-child { flex: 0 0 auto; }
#order-total-amount { min-width: 0; text-align: right; line-height: 1.2; }

/* Kitchen monitor */
.kitchen-columns { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--space-3); flex: 1; min-height: 0; overflow: auto; align-items: start; }
.kitchen-column-header {
  font-size: 0.85rem; font-weight: 800; padding: 8px 12px;
  border: var(--border-w-sm) solid var(--outline); border-radius: var(--radius-sm); text-align: center;
}
.kitchen-column-header.blue { background: var(--badge-blue-bg); color: var(--badge-blue-text); }
.kitchen-column-header.amber { background: var(--badge-amber-bg); color: var(--badge-amber-text); }
.kitchen-column-header.green { background: var(--badge-green-bg); color: var(--badge-green-text); }
.kitchen-tickets { display: flex; flex-direction: column; gap: 12px; margin-top: 12px; }
.kds-ticket { background: var(--surface-alt); border: var(--border-w-lg) solid var(--outline); border-radius: var(--radius-md); box-shadow: var(--shadow-lg); padding: 12px; cursor: pointer; }
.kds-ticket .kds-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; font-weight: 800; }
.kds-ticket .kds-items { font-size: 0.85rem; line-height: 1.5; color: var(--muted); }
.kds-ticket .kds-action { margin-top: 10px; padding-top: 8px; border-top: 1px solid var(--hairline); color: var(--accent); font-size: 0.78rem; font-weight: 800; }

/* Keep both kiosk modes on the same compact spacing grid in short Safari viewports. */
@media (min-width: 601px) and (max-height: 900px) {
  .restaurant-view {
    gap: var(--space-2);
    padding: var(--space-2);
  }
  .tables-grid,
  .order-body,
  .menu-panel,
  .menu-items-grid,
  .kitchen-columns { gap: var(--space-2); }
  .status-legend { padding-top: var(--space-2); }
  .order-header { min-height: 76px; padding: var(--space-2) var(--space-4); }
  .order-header h2 { font-size: clamp(1.45rem, 2.5vw, 2.2rem); }
  .order-body { padding: var(--space-2); }
  .menu-items-grid { grid-template-columns: repeat(auto-fill, minmax(164px, 1fr)); }
  .menu-items-grid .product-tile { min-height: 218px; }
  .menu-items-grid .product-img-wrap { height: 118px; min-height: 118px; flex-basis: 118px; }
  .product-add-btn { width: 40px; height: 40px; font-size: 1.4rem; }
}

@media (max-width: 900px) {
  .kitchen-columns { grid-template-columns: 1fr; }
  #view-order { gap: var(--space-2); }
  .order-header { min-height: 70px; padding: var(--space-2) var(--space-4); }
  .order-header h2 { font-size: clamp(1.35rem, 5vw, 2rem); }
  .order-header .badge { padding: 7px 14px; font-size: .9rem; }
  .order-mobile-tabs button { min-height: 44px; padding: 8px 12px; font-size: .95rem; }
  .order-body { padding: var(--space-2); overflow: hidden; }
  .order-body .menu-panel,
  .order-body .order-panel { display: none; flex: 1 1 auto; min-height: 0; }
  .order-body[data-order-pane="menu"] .menu-panel,
  .order-body[data-order-pane="ticket"] .order-panel { display: flex; }
  .order-body[data-order-pane="ticket"] .order-panel {
    display: grid;
    grid-template-columns: minmax(0, 1.15fr) minmax(190px, .85fr);
    gap: var(--space-2);
    overflow: hidden;
  }
  .ticket-list-column,
  .ticket-controls-column {
    min-height: 0;
    padding: var(--space-2);
  }
  .ticket-controls-column { overflow: auto; padding-bottom: 56px; }
  .ticket-controls-column .order-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--space-2);
    justify-content: stretch;
  }
  .ticket-controls-column .order-actions button { width: 100%; min-width: 0; }
  .ticket-controls-column .totals { font-size: 1rem; border-top: var(--border-w-lg) solid var(--outline); }
  .ticket-controls-column #order-split-chips { padding-right: 0; }
  .order-ticket-list { padding: 0; }
  .order-ticket-list .row {
    grid-template-columns: minmax(0, 1fr) auto 40px;
    gap: var(--space-2);
    padding: var(--space-2) 0;
    border-bottom-width: var(--border-w-lg);
  }
  .order-ticket-list .row .title { grid-column: 1 / -1; min-width: 0; gap: var(--space-2); }
  .order-ticket-list .row .title > div { min-width: 0; overflow: hidden; }
  .order-ticket-list .row .title > div > :first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .order-ticket-list .row .qty-controls { grid-column: 1; grid-row: 2; }
  .order-ticket-list .qty-controls { justify-content: flex-start; }
  .order-ticket-list .row > :nth-child(3) { grid-column: 2; grid-row: 2; align-self: center; justify-self: end; white-space: nowrap; font-weight: 900; }
  .order-ticket-list .row > :nth-child(4) { grid-column: 3; grid-row: 2; align-self: center; justify-self: end; }
  .order-ticket-list .row .danger {
    width: 40px;
    height: 40px;
    padding: 0;
    color: var(--text);
    border-width: var(--border-w-lg);
    border-radius: var(--radius-md);
    font-size: 1.4rem;
    font-weight: 900;
  }
  .menu-items-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 700px) and (orientation: portrait) {
  .order-body[data-order-pane="ticket"] .order-panel {
    display: flex;
    flex-direction: column;
    overflow: auto;
  }
  .ticket-list-column { min-height: 240px; flex: 0 0 240px; }
  .ticket-controls-column { flex: 0 0 auto; overflow: visible; }
}
