:root {
  --ui-scale: 1;
  --text: #f0f0f0;
  --panel: linear-gradient(180deg, #312e36 0%, #18151c 100%);
  --panel-border: #5c5562;
  --panel-soft: rgba(255, 255, 255, 0.08);
  --button-face: linear-gradient(180deg, #f6f6f6 0%, #cdcdcd 100%);
  --button-border: #7a7a7a;
  --danger: linear-gradient(180deg, #ff6f20 0%, #f34300 100%);
  --warn: linear-gradient(180deg, #fff08a 0%, #f5cf00 100%);
  --info: linear-gradient(180deg, #7be9f0 0%, #2bc4cf 100%);
  --success: linear-gradient(180deg, #92f436 0%, #45c800 100%);
  --cyan: linear-gradient(180deg, #75e0f0 0%, #18b8d7 100%);
  --red: linear-gradient(180deg, #ff7c7c 0%, #df2121 100%);

  /* Touch target minimo raccomandato (48px) */
  --touch-min: 48px;
}

* {
  box-sizing: border-box;
  /* Previene il ritardo di 300ms sui tap Android */
  touch-action: manipulation;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  font-family: "Arial Narrow", Arial, sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top, rgba(80, 42, 27, 0.55), transparent 30%),
    linear-gradient(180deg, #2f241f 0%, #161214 100%);
  /* Evita selezione accidentale di testo durante i tap */
  -webkit-user-select: none;
  user-select: none;
  /* Previene zoom indesiderato sul doppio tap */
  -webkit-text-size-adjust: 100%;
}

/* Ri-abilita selezione per i campi input e testo */
input, textarea {
  -webkit-user-select: text;
  user-select: text;
}

.screen {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
  padding-top: max(24px, env(safe-area-inset-top));
  padding-bottom: max(24px, env(safe-area-inset-bottom));
}

.device {
  width: min(100%, 440px);
  aspect-ratio: 480 / 800;
  background: linear-gradient(180deg, #211d24 0%, #120f14 100%);
  border-radius: 22px;
  padding: 18px 14px 24px;
  box-shadow:
    0 30px 60px rgba(0, 0, 0, 0.45),
    inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

.title-bar {
  display: none;
}

.app-shell {
  height: 100%;
  width: 100%;
  max-width: 100%;
  background: linear-gradient(180deg, #1e1820 0%, #140f15 100%);
  border: 1px solid #59525f;
  padding: 10px 8px 8px;
  overflow: hidden;
}


.layout {
  height: 100%;
  width: 100%;
  max-width: 100%;
  display: grid;
  grid-template-columns: 82px minmax(0, 1fr) 44px;
  gap: 6px;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
  position: relative;
}

.left-column {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-height: 0;
  overflow: hidden;
}

.left-column:not(.tables) {
  --left-slot-height: 30px;
}

.left-column.tables {
  justify-content: space-between;
  padding: 4px 0 18px;
}

.build-label {
  font-size: 11px;
  line-height: 1.2;
  color: #d5d5d5;
  text-align: center;
  padding: 4px 2px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.05);
}

.center-column {
  display: grid;
  grid-template-rows: minmax(0, 1fr) clamp(30px, 5vh, 36px) clamp(158px, 30.5vh, 202px);
  gap: 6px;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

.content-panel {
  overflow: hidden;
  display: grid;
  height: 100%;
  width: 100%;
  max-width: 100%;
  min-height: 0;
  min-width: 0;
  border: 1px solid var(--panel-border);
  background: var(--panel);
  position: relative;
}

.order-panel {
  height: 100%;
  min-height: 0;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
}

.order-total-bar {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  min-height: 28px;
  padding: 4px 8px 6px;
  border-top: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(0, 0, 0, 0.12);
}

.order-total-value {
  font-size: calc(14px * var(--ui-scale));
  line-height: 1.25;
  text-align: right;
}

.menu-panel {
  height: 100%;
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

.content-modal {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(10, 9, 12, 0.66);
  z-index: 2;
}

.modal-card {
  width: min(88%, 240px);
  border: 1px solid #8b8b8b;
  background: linear-gradient(180deg, #f4f4f4 0%, #d0d0d0 100%);
  color: #222;
  border-radius: 6px;
  padding: 12px;
  box-shadow: 0 16px 30px rgba(0, 0, 0, 0.35);
}

.debug-dialog-overlay {
  z-index: 40;
}

.debug-dialog-card {
  width: min(94%, 520px);
  max-height: min(88dvh, 640px);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 8px;
}

.debug-dialog-content {
  margin: 0;
  padding: 8px;
  background: #fff;
  border: 1px solid #8b8b8b;
  color: #202020;
  font-size: 12px;
  line-height: 1.35;
  overflow: auto;
  white-space: pre-wrap;
}

.display-mode-card {
  width: min(92%, 300px);
  display: grid;
  gap: 10px;
}

.display-mode-subtitle {
  font-size: 13px;
  line-height: 1.3;
}

.display-mode-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

.memo-editor-text {
  width: 100%;
  min-height: 180px;
  border: 1px solid #8b8b8b;
  background: #fff;
  color: #202020;
  font-size: 14px;
  line-height: 1.35;
  padding: 8px;
  resize: vertical;
}

.memo-editor-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.table-preview-card {
  width: min(94%, 420px);
  max-height: min(84dvh, 560px);
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  gap: 8px;
}

.table-preview-meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 13px;
  color: #2f2f2f;
}

.table-preview-scroll {
  min-height: 0;
  overflow: auto;
  border: 1px solid #8b8b8b;
  background: #ffffff;
}

.preview-order-list {
  margin: 0;
  padding: 4px 8px;
  list-style: none;
  font-size: 14px;
  color: #111111;
}

.preview-order-entry {
  display: grid;
  grid-template-columns: 1fr 30px 56px;
  gap: 0;
  align-items: center;
  min-height: 20px;
  padding: 0;
  color: #111111;
}

.preview-order-entry.separator {
  display: block;
  height: 2px;
  margin: 0;
  padding: 0;
  border-bottom: 1px solid #666666;
}

.preview-order-name {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.preview-order-qty,
.preview-order-price {
  text-align: right;
}

.modal-title {
  font-size: 15px;
  font-weight: 700;
  margin-bottom: 10px;
}

.modal-value {
  width: 100%;
  min-height: 34px;
  border: 1px solid #8b8b8b;
  background: #fff;
  padding: 6px 8px;
  text-align: right;
  font-size: 20px;
}

.tables-panel {
  height: 100%;
  min-height: 0;
  display: grid;
  grid-template-rows: minmax(0, 1fr);
}

.content-scroll {
  height: 100%;
  min-height: 0;
  overflow: auto;
  /* Scroll fluido su Android/iOS */
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.empty-state {
  padding: 12px 10px;
  color: #d0d0d0;
  font-size: 13px;
}

.button,
.key {
  border: 1px solid var(--button-border);
  border-radius: 4px;
  background: var(--button-face);
  color: #393939;
  cursor: pointer;
  /* Feedback visivo immediato su touch */
  -webkit-tap-highlight-color: rgba(0, 0, 0, 0.15);
}

.button {
  min-height: clamp(32px, 5.4vh, 40px);
  padding: 8px 6px;
  font-size: 14px;
  line-height: 1.05;
}

.button.small {
  min-height: clamp(26px, 4.5vh, 34px);
  font-size: 13px;
}

.button.green {
  background: var(--success);
  color: #fff;
}

.button.cyan {
  background: var(--cyan);
  color: #fff;
}

.button.red {
  background: var(--red);
  color: #fff;
}

.button.orange {
  background: var(--danger);
  color: #fff;
}

.button.info {
  background: var(--info);
  color: #fff;
}

.button.warn {
  background: var(--warn);
}

.button.bis-active {
  background: var(--info);
  color: #fff;
}

.button.small.category-button {
  min-height: var(--left-slot-height);
  height: var(--left-slot-height);
  text-align: left;
  padding-left: 8px;
}

.category-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  display: grid;
  grid-template-rows: repeat(var(--category-count, 12), var(--left-slot-height));
  gap: 1px;
  align-content: start;
}

.left-footer {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding-top: 2px;
}

.category-button.active {
  background: linear-gradient(180deg, #ffffff 0%, #d9d9d9 100%);
  color: #101010;
}

.tables-list,
.order-list,
.menu-list {
  margin: 0;
  padding: 8px 10px;
  list-style: none;
}

.tables-list {
  font-size: calc(24px * var(--ui-scale));
  line-height: 1.45;
}

.table-entry,
.menu-entry,
.order-entry {
  display: grid;
  align-items: center;
}

.table-entry {
  grid-template-columns: 1fr;
  gap: 0;
  font-weight: 700;
  padding: 2px 4px;
}

.table-entry.selected,
.menu-entry.selected,
.order-entry.selected {
  background: var(--panel-soft);
}

.table-entry.selected {
  background: linear-gradient(180deg, #f2f2f2 0%, #d9d9d9 100%);
  color: #111111;
  border-radius: 4px;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.85),
    0 0 0 1px rgba(0, 0, 0, 0.28);
}

.table-number {
  text-align: right;
}

.order-list {
  font-size: calc(14px * var(--ui-scale));
  line-height: 1.25;
}

.order-entry {
  grid-template-columns: 1fr 26px 48px;
  gap: 8px;
  min-height: 28px;
  padding: 2px 6px;
}

.order-entry.separator {
  display: block;
  height: 18px;
  position: relative;
}

.order-entry.separator::before {
  content: "";
  position: absolute;
  left: 6px;
  right: 6px;
  top: 8px;
  border-top: 2px solid rgba(255, 255, 255, 0.9);
}

.order-name {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.order-qty,
.order-price {
  text-align: right;
}

.menu-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px 4px;
  font-weight: 700;
}

.menu-close {
  border: 1px solid #8f2a2a;
  background: linear-gradient(180deg, #ff7b53 0%, #d72b00 100%);
  color: #fff;
  width: 22px;
  height: 22px;
  border-radius: 3px;
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
  padding: 0;
}

.menu-scroll {
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.menu-list {
  padding-top: 4px;
  font-size: calc(14px * var(--ui-scale));
}

.menu-entry {
  padding: 4px 6px;
  min-height: calc(28px * min(var(--ui-scale), 1.35));
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.input-row {
  display: grid;
  grid-template-columns: 1fr 56px;
  gap: 2px;
}

.field {
  border: 1px solid #979797;
  background: linear-gradient(180deg, #f7f7f7 0%, #cfcfcf 100%);
  color: #4f4f4f;
  font-size: 17px;
  padding: 0 8px;
}

.field.price {
  text-align: right;
  font-size: 15px;
}

.filter-field {
  border: none;
  background: rgba(255, 255, 255, 0.95);
  font-size: 15px;
  padding: 0 8px;
}

.category-search-overlay {
  position: absolute;
  inset: 0;
  z-index: 35;
  background: linear-gradient(180deg, #1f1a22 0%, #151117 100%);
  border: 1px solid var(--panel-border);
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 4px;
  overflow: hidden;
}

.category-search-results {
  flex: 1 1 0;
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: linear-gradient(180deg, #2a2530 0%, #1a161f 100%);
}

.category-search-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 6px 8px 4px;
  font-weight: 700;
}

.category-search-input-wrap {
  border-top: 1px solid rgba(255, 255, 255, 0.2);
  padding: 2px 0 0;
  flex: 0 0 auto;
}

.split-overlay {
  position: absolute;
  inset: 0;
  z-index: 45;
  background: rgba(11, 9, 14, 0.82);
  backdrop-filter: blur(2px);
}

.split-shell {
  height: 100%;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 8px;
  padding: 8px;
}

.split-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  background: linear-gradient(180deg, rgba(46, 39, 54, 0.96) 0%, rgba(23, 19, 28, 0.96) 100%);
}

.split-title {
  font-size: calc(18px * var(--ui-scale));
  font-weight: 700;
}

.split-subtitle {
  margin-top: 4px;
  font-size: calc(12px * var(--ui-scale));
  color: rgba(240, 240, 240, 0.78);
}

.split-header-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.split-header-actions .button {
  min-height: 52px;
  min-width: 104px;
  font-size: calc(20px * var(--ui-scale));
  padding: 8px 14px;
}

.split-body {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 72px minmax(0, 1fr);
  gap: 8px;
}

.split-pane {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  background: linear-gradient(180deg, #2b2530 0%, #17131c 100%);
  overflow: hidden;
}

.split-pane-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  padding: 8px 10px 6px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

.split-pane-title {
  font-size: calc(15px * var(--ui-scale));
  font-weight: 700;
}

.split-pane-meta {
  display: flex;
  gap: 8px;
  font-size: calc(12px * var(--ui-scale));
  color: rgba(240, 240, 240, 0.78);
  white-space: nowrap;
}

.split-pane-scroll {
  min-height: 0;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

.split-order-list {
  margin: 0;
  padding: 8px 10px;
  list-style: none;
}

.split-order-entry {
  cursor: pointer;
}

.order-entry.split-order-entry.selected {
  background: linear-gradient(180deg, #f2f2f2 0%, #d9d9d9 100%);
  color: #111111;
  border-radius: 4px;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.85),
    0 0 0 1px rgba(0, 0, 0, 0.28);
}

.split-controls {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 6px;
}

.split-controls .button {
  min-height: 42px;
  font-size: calc(20px * var(--ui-scale));
  padding: 4px 0;
}

.split-controls .split-fraction-button {
  min-height: 36px;
  font-size: calc(16px * var(--ui-scale));
}

.keypad {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  grid-template-rows: repeat(4, 1fr);
  gap: 2px;
}

.key {
  display: grid;
  place-items: center;
  font-size: 28px;
  user-select: none;
}

.key.wide-text {
  font-size: 23px;
}

.key.danger {
  background: var(--danger);
  color: #fff;
}

.key.warn {
  background: var(--warn);
}

.key.info {
  background: var(--info);
}

.key.success {
  background: var(--success);
  color: #fff;
  grid-row: span 2;
  font-size: 34px;
}

.right-column {
  display: flex;
  flex-direction: column;
  gap: 0;
  min-height: 0;
  min-width: 0;
  width: 100%;
  overflow-y: auto;
  overflow-x: hidden;
}

.right-column .button {
  min-height: clamp(28px, 4.8vh, 34px);
  padding: 4px 3px;
  font-size: 12px;
  width: 100%;
}

.right-column .button.separator-button {
  display: flex;
  align-items: center;
  justify-content: center;
}

.separator-button-line {
  display: block;
  width: 56%;
  height: 4px;
  border-radius: 999px;
  background: #111;
}

.right-column .button.rc-gap-sm {
  margin-bottom: 14px;
}

.right-column .button.rc-gap-md {
  margin-bottom: 28px;
}

.right-column .button.rc-gap-xl {
  margin-bottom: 42px;
}

.left-footer .button {
  min-height: var(--left-slot-height);
  height: var(--left-slot-height);
}

.muted {
  color: #c3c3c3;
}

.button:active,
.key:active {
  transform: translateY(1px);
  opacity: 0.85;
}

/* ============================================================
   TABLET — portrait (600px–900px) e landscape (900px–1200px)
   pointer:coarse cattura tutti i touch screen indipendentemente
   dalla larghezza, inclusi tablet grandi in landscape
   ============================================================ */

/* --- Tablet landscape: larghezza ≥ 900px con touch --- */
@media (min-width: 900px) and (pointer: coarse) {
  body {
    background: #17151b;
  }

  .screen {
    padding: 0;
    min-height: 100dvh;
  }

  .device {
    width: 100vw;
    min-height: 100dvh;
    aspect-ratio: auto;
    background: #17151b;
    border-radius: 0;
    padding: 0;
    box-shadow: none;
  }

  .app-shell {
    height: calc(100dvh - env(safe-area-inset-top) - env(safe-area-inset-bottom));
    border: none;
    padding: calc(6px + env(safe-area-inset-top)) 6px calc(6px + env(safe-area-inset-bottom));
    position: relative;
  }

  /* In landscape il tablet ha spazio: right-column nel flusso normale */
  .layout {
    grid-template-columns: 110px minmax(0, 1fr) 70px;
    gap: 6px;
  }

  /* Right column nel flusso, non assoluta */
  .right-column {
    position: static;
    width: 70px;
    max-height: none;
    overflow-y: auto;
    background: transparent;
  }

  /* Bottoni della right column più grandi su tablet */
  .right-column .button {
    min-height: var(--touch-min);
    font-size: 13px;
    padding: 6px 4px;
  }

  /* No padding-right extra perché right-column è nel flusso */
  .content-panel {
    padding-right: 0;
  }

  .center-column {
    grid-template-rows: minmax(0, 1fr) clamp(40px, 5.5vh, 50px) clamp(200px, 32vh, 260px);
    gap: 6px;
  }

  /* Touch targets 48px su tutta la left-column */
  .left-column:not(.tables) {
    --left-slot-height: 48px;
  }

  .button {
    min-height: var(--touch-min);
    font-size: 15px;
    padding: 10px 8px;
  }

  .button.small {
    min-height: 40px;
    font-size: 14px;
  }

  .key {
    font-size: 30px;
  }

  .key.wide-text {
    font-size: 25px;
  }

  .key.success {
    font-size: 38px;
  }

  .order-list {
    font-size: calc(16px * var(--ui-scale));
  }

  .order-entry {
    grid-template-columns: 1fr 30px 56px;
    min-height: 36px;
    gap: 8px;
    padding: 4px 8px;
  }

  .menu-entry {
    min-height: 44px;
    padding: 6px 8px;
  }

  .menu-close {
    width: 32px;
    height: 32px;
    font-size: 15px;
  }

  .field {
    font-size: 18px;
  }

  .input-row {
    grid-template-columns: 1fr 68px;
  }

  .table-entry {
    padding: 4px 6px;
  }
}

/* --- Tablet portrait: larghezza < 900px con touch --- */
@media (max-width: 899px) and (pointer: coarse) {
  body {
    background: #17151b;
  }

  .screen {
    padding: 0;
    min-height: 100dvh;
  }

  .device {
    width: 100vw;
    min-height: 100dvh;
    aspect-ratio: auto;
    background: #17151b;
    border-radius: 0;
    padding: 0;
    box-shadow: none;
  }

  .app-shell {
    height: calc(100dvh - env(safe-area-inset-top) - env(safe-area-inset-bottom));
    border: none;
    padding: calc(4px + env(safe-area-inset-top)) 3px calc(3px + env(safe-area-inset-bottom));
    position: relative;
  }

  /* In portrait lo spazio e' limitato: right-column assoluta, allineata solo al content-panel */
  .layout {
    grid-template-columns: 82px minmax(0, 1fr);
    gap: 4px;
  }

  /* bottom calcolato = padding(3px) + safe-area + keypad + gap(4px) + input-row + gap(4px)
     cosi' la right-column termina esattamente dove finisce il content-panel */
  .right-column {
    position: absolute;
    top: calc(4px + env(safe-area-inset-top));
    right: calc(3px + env(safe-area-inset-right));
    bottom: calc(3px + env(safe-area-inset-bottom) + clamp(186px, 34vh, 230px) + 4px + clamp(38px, 5.5vh, 48px) + 4px);
    width: 66px;
    z-index: 20;
    overflow-y: auto;
    overflow-x: hidden;
    background: transparent;
  }

  .content-panel {
    padding-right: 68px;
  }

  /* Touch targets 48px anche in portrait */
  .left-column:not(.tables) {
    --left-slot-height: 44px;
  }

  .center-column {
    grid-template-rows: minmax(0, 1fr) clamp(38px, 5.5vh, 48px) clamp(186px, 34vh, 230px);
    gap: 4px;
  }

  .button {
    min-height: var(--touch-min);
    padding: 8px 5px;
    font-size: 13px;
  }

  .button.small {
    min-height: 40px;
    font-size: 13px;
  }

  .right-column .button {
    min-height: 44px;
    font-size: 12px;
    width: 100%;
    min-width: 0;
    white-space: nowrap;
  }

  .tables-list {
    font-size: calc(20px * var(--ui-scale));
  }

  .key {
    font-size: 26px;
  }

  .key.wide-text {
    font-size: 21px;
  }

  .key.success {
    font-size: 32px;
  }

  .order-list {
    font-size: calc(14px * var(--ui-scale));
  }

  .order-entry {
    grid-template-columns: 1fr 26px 48px;
    min-height: 32px;
    gap: 6px;
    padding: 3px 5px;
  }

  .menu-entry {
    min-height: 40px;
    padding: 5px 6px;
  }

  .menu-close {
    width: 28px;
    height: 28px;
    font-size: 14px;
  }

  .field {
    font-size: 16px;
    padding: 0 6px;
  }

  .field.price {
    font-size: 15px;
  }

  .input-row {
    grid-template-columns: 1fr 58px;
  }

  .split-shell {
    padding: 5px;
    gap: 5px;
  }

  .split-header {
    padding: 8px;
  }

  .split-body {
    grid-template-columns: minmax(0, 1fr) 52px minmax(0, 1fr);
    gap: 5px;
  }

  .split-pane-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
  }

  .split-pane-meta {
    gap: 6px;
    white-space: normal;
  }

  .split-order-list {
    padding: 6px;
  }

  .split-controls .button {
    min-height: 40px;
    font-size: 20px;
  }

}

/* ============================================================
   TELEFONO — max-width 599px con touch (o qualsiasi touch < 900px
   non già gestito sopra viene coperto dai blocchi tablet portrait)
   Qui raffiniamo ulteriormente per schermi piccoli
   ============================================================ */
@media (max-width: 599px) and (pointer: coarse) {
  .layout {
    grid-template-columns: 72px minmax(0, 1fr);
    gap: 3px;
  }

  .right-column {
    position: absolute;
    top: calc(4px + env(safe-area-inset-top));
    right: calc(3px + env(safe-area-inset-right));
    /* keypad phone: clamp(168px,33vh,210px), input-row: clamp(36px,5vh,44px), gap: 3px */
    bottom: calc(3px + env(safe-area-inset-bottom) + clamp(168px, 33vh, 210px) + 3px + clamp(36px, 5vh, 44px) + 3px);
    width: 62px;
    z-index: 20;
    overflow-y: auto;
    overflow-x: hidden;
    background: transparent;
  }

  .content-panel {
    padding-right: 64px;
  }

  .left-column:not(.tables) {
    --left-slot-height: 40px;
  }

  .center-column {
    grid-template-rows: minmax(0, 1fr) clamp(36px, 5vh, 44px) clamp(168px, 33vh, 210px);
    gap: 3px;
  }

  .button {
    min-height: 40px;
    padding: 6px 4px;
    font-size: 12px;
  }

  .button.small {
    min-height: 36px;
    font-size: 12px;
  }

  .right-column .button {
    min-height: 38px;
    font-size: 11px;
  }

  .key {
    font-size: 22px;
  }

  .key.wide-text {
    font-size: 18px;
  }

  .key.success {
    font-size: 28px;
  }

  .tables-list,
  .menu-list,
  .order-list {
    font-size: calc(12px * var(--ui-scale));
    padding: 6px 6px;
  }

  .tables-list {
    font-size: calc(17px * var(--ui-scale));
  }

  .order-entry {
    grid-template-columns: 1fr 22px 42px;
    gap: 5px;
    min-height: 28px;
    padding: 2px 4px;
  }

  .menu-entry {
    min-height: 36px;
  }

  .menu-close {
    width: 24px;
    height: 24px;
    font-size: 12px;
  }

  .field {
    font-size: 15px;
  }

  .field.price {
    font-size: 14px;
  }

  .input-row {
    grid-template-columns: 1fr 52px;
  }

  .split-header {
    flex-direction: column;
    align-items: stretch;
  }

  .split-header-actions {
    width: 100%;
  }

  .split-header-actions .button {
    flex: 1 1 0;
  }

  .split-body {
    grid-template-columns: minmax(0, 1fr) 44px minmax(0, 1fr);
    gap: 4px;
  }

  .split-controls .button {
    min-height: 34px;
    font-size: 18px;
  }

}

/* ============================================================
   FALLBACK — desktop/laptop con mouse (comportamento originale)
   Manteniamo il media query originale per retrocompatibilità
   ============================================================ */
@media (max-width: 900px) and (pointer: fine) {
  body {
    background: #17151b;
  }

  .screen {
    padding: 0;
    min-height: 100dvh;
  }

  .device {
    width: 100vw;
    min-height: 100dvh;
    aspect-ratio: auto;
    background: #17151b;
    border-radius: 0;
    padding: 0;
    box-shadow: none;
  }

  .app-shell {
    height: calc(100dvh - env(safe-area-inset-top) - env(safe-area-inset-bottom));
    border: none;
    padding: calc(4px + env(safe-area-inset-top)) 3px calc(3px + env(safe-area-inset-bottom));
    position: relative;
  }

  .layout {
    grid-template-columns: 72px minmax(0, 1fr);
    gap: 4px;
  }

  .right-column {
    position: absolute;
    top: calc(4px + env(safe-area-inset-top));
    right: calc(3px + env(safe-area-inset-right));
    /* keypad: clamp(168px,33vh,208px), input-row: clamp(30px,5vh,34px), gap: 4px */
    bottom: calc(3px + env(safe-area-inset-bottom) + clamp(168px, 33vh, 208px) + 4px + clamp(30px, 5vh, 34px) + 4px);
    width: 62px;
    z-index: 20;
    overflow-y: auto;
    overflow-x: hidden;
    background: transparent;
  }

  .content-panel {
    padding-right: 64px;
  }

  .center-column {
    grid-template-rows: minmax(0, 1fr) clamp(30px, 5vh, 34px) clamp(168px, 33vh, 208px);
    gap: 4px;
  }

  .button {
    min-height: 34px;
    padding: 6px 4px;
    font-size: 12px;
  }

  .button.small {
    min-height: 0;
    font-size: 12px;
  }

  .right-column .button {
    min-height: clamp(24px, 4.3vh, 30px);
    font-size: 11px;
    width: 100%;
    min-width: 0;
    white-space: nowrap;
  }

  .tables-list,
  .menu-list,
  .order-list {
    font-size: calc(12px * var(--ui-scale));
    padding: 6px 6px;
  }

  .tables-list {
    font-size: calc(17px * var(--ui-scale));
  }

  .order-entry {
    grid-template-columns: 1fr 22px 42px;
    gap: 6px;
    min-height: 24px;
    padding: 1px 4px;
  }

  .input-row {
    grid-template-columns: 1fr 52px;
  }

  .field {
    font-size: 15px;
    padding: 0 6px;
  }

  .field.price {
    font-size: 14px;
  }

  .key {
    font-size: 24px;
  }

  .key.wide-text {
    font-size: 19px;
  }

  .key.success {
    font-size: 28px;
  }
}

/* ============================================================
   DESKTOP — pointer:fine, larghezza ≥ 900px
   Layout 3 colonne ampliate. Nessuna modifica al HTML generato.
   ============================================================ */
@media (min-width: 900px) and (pointer: fine) {

  /* ── Sfondo e schermo ── */
  body {
    background:
      radial-gradient(ellipse at 20% 0%, rgba(80, 42, 27, 0.35), transparent 50%),
      radial-gradient(ellipse at 80% 100%, rgba(40, 20, 60, 0.3), transparent 50%),
      linear-gradient(180deg, #1a1520 0%, #0e0b11 100%);
    user-select: none;
  }

  input, textarea {
    user-select: text;
  }

  .screen {
    padding: 0;
    min-height: 100vh;
    align-items: stretch;
  }

  /* ── Device frame: sparisce, l'app occupa tutto ── */
  .device {
    width: 100vw;
    min-height: 100vh;
    aspect-ratio: auto;
    background: transparent;
    border-radius: 0;
    padding: 0;
    box-shadow: none;
  }

  .title-bar {
    display: flex;
    align-items: center;
    height: 32px;
    padding: 0 16px;
    background: rgba(0, 0, 0, 0.35);
    border-bottom: 1px solid rgba(255, 255, 255, 0.07);
    font-size: 12px;
    color: rgba(255, 255, 255, 0.35);
    letter-spacing: 0.05em;
    flex-shrink: 0;
  }

  /* ── App shell: occupa lo spazio sotto la title-bar ── */
  .app-shell {
    height: calc(100vh - 32px);
    border: none;
    background: transparent;
    padding: 10px 12px 10px;
    position: relative;
  }

  /* ── Layout principale: 3 colonne ── */
  .layout {
    grid-template-columns: 160px minmax(0, 1fr) 200px;
    gap: 10px;
    height: 100%;
  }

  /* ── Colonna sinistra: categorie più larghe e leggibili ── */
  .left-column:not(.tables) {
    --left-slot-height: 36px;
  }

  .left-column.tables {
    padding: 6px 0 24px;
    gap: 4px;
  }

  .category-scroll {
    gap: 3px;
  }

  .category-button {
    font-size: 14px;
    padding-left: 12px;
    border-radius: 6px;
    transition: background 0.12s, color 0.12s;
  }

  .category-button:hover:not(.active) {
    background: linear-gradient(180deg, #e8e8e8 0%, #c8c8c8 100%);
  }

  .category-button.active {
    background: linear-gradient(180deg, #ffffff 0%, #d4d4d4 100%);
    color: #101010;
    font-weight: 700;
    box-shadow: inset 0 1px 0 rgba(255,255,255,0.8), 0 1px 3px rgba(0,0,0,0.2);
  }

  .totals {
    font-size: 18px;
    font-weight: 700;
    height: auto;
    min-height: auto;
    padding: 6px 2px 4px;
    color: #f0f0f0;
    border-top: 1px solid rgba(255, 255, 255, 0.12);
    margin-top: 4px;
  }

  .left-footer {
    gap: 4px;
    padding-top: 4px;
  }

  .left-footer .button {
    height: auto;
    min-height: 34px;
    font-size: 14px;
    border-radius: 6px;
  }

  /* ── Colonna centrale: respira ── */
  .center-column {
    grid-template-rows: minmax(0, 1fr) 38px clamp(200px, 28vh, 260px);
    gap: 8px;
  }

  /* Lista tavoli ── */
  .tables-list {
    font-size: 18px;
    line-height: 1.5;
    padding: 10px 14px;
  }

  .table-entry {
    padding: 5px 8px;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.1s;
  }

  .table-entry:hover {
    background: rgba(255, 255, 255, 0.1);
  }

  .table-entry.selected {
    background: linear-gradient(180deg, #f4f4f4 0%, #d8d8d8 100%);
    color: #111111;
    box-shadow:
      inset 0 1px 0 rgba(255, 255, 255, 0.9),
      0 0 0 1px rgba(0, 0, 0, 0.2);
  }

  /* Lista ordini ── */
  .order-list {
    font-size: 16px;
    line-height: 1.35;
    padding: 8px 14px;
  }

  .order-entry {
    grid-template-columns: 1fr 36px 72px;
    min-height: 34px;
    padding: 4px 8px;
    border-radius: 4px;
    cursor: pointer;
    transition: background 0.1s;
  }

  .order-entry:hover:not(.separator):not(.split-order-entry) {
    background: rgba(255, 255, 255, 0.06);
  }

  .order-entry.selected {
    background: rgba(255, 255, 255, 0.11);
  }

  .order-entry.separator {
    height: 20px;
  }

  .order-entry.separator::before {
    border-top-width: 1px;
    border-color: rgba(255, 255, 255, 0.5);
  }

  /* Campo input ── */
  .input-row {
    grid-template-columns: 1fr 80px;
    gap: 4px;
  }

  .field {
    font-size: 18px;
    padding: 0 10px;
    border-radius: 4px;
  }

  .field.price {
    font-size: 17px;
  }

  /* Keypad ── */
  .keypad {
    gap: 4px;
  }

  .key {
    font-size: 22px;
    border-radius: 6px;
    transition: background 0.08s, transform 0.06s, box-shadow 0.08s;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
  }

  .key:hover {
    filter: brightness(1.08);
    box-shadow: 0 3px 8px rgba(0, 0, 0, 0.3);
  }

  .key:active {
    transform: translateY(1px);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
  }

  .key.wide-text {
    font-size: 17px;
  }

  .key.success {
    font-size: 28px;
  }

  /* ── Colonna destra: nel flusso, pulsanti operativi ── */
  .right-column {
    position: static;
    width: 100%;
    max-height: none;
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding-top: 0;
  }

  .right-column .button {
    min-height: 40px;
    font-size: 17px;
    padding: 8px 6px;
    border-radius: 6px;
    transition: filter 0.1s, transform 0.06s;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
  }

  .right-column .button:hover {
    filter: brightness(1.08);
  }

  /* No padding-right extra — right-column è nel flusso */
  .content-panel {
    padding-right: 0;
    border-radius: 8px;
  }

  /* ── Bottoni generici desktop ── */
  .button {
    min-height: 32px;
    font-size: 14px;
    padding: 6px 8px;
    border-radius: 6px;
    transition: filter 0.1s, transform 0.06s;
  }

  .button:hover {
    filter: brightness(1.08);
  }

  .button:active {
    transform: translateY(1px);
  }

  .button.small {
    min-height: 28px;
    font-size: 13px;
  }

  /* ── Menu overlay ricerca ── */
  .menu-entry {
    min-height: 30px;
    padding: 5px 8px;
    cursor: pointer;
    transition: background 0.1s;
    border-radius: 3px;
  }

  .menu-entry:hover {
    background: rgba(255, 255, 255, 0.08);
  }

  .menu-list {
    font-size: 15px;
  }

  .category-search-header .button.small {
    min-height: 26px;
  }

  .filter-field {
    font-size: 16px;
  }

  /* ── Pannello tavoli in modalità tables ── */
  .left-column.tables .button {
    font-size: 14px;
    min-height: 34px;
    border-radius: 6px;
  }

  /* ── Hover su voci della lista tavoli ── */
  .tables-list .table-entry {
    cursor: pointer;
  }

  /* ── Separatori ordine ── */
  .order-entry.separator::before {
    left: 8px;
    right: 8px;
  }

  /* ── Build label ── */
  .build-label {
    font-size: 10px;
    color: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.1);
    margin-top: 2px;
  }

  /* ── Modal ── */
  .modal-card {
    width: min(88%, 320px);
    border-radius: 10px;
    padding: 18px;
  }

  .modal-title {
    font-size: 17px;
  }

  .modal-value {
    font-size: 24px;
    min-height: 44px;
    border-radius: 6px;
  }

  .memo-editor-text {
    font-size: 15px;
    min-height: 220px;
    border-radius: 6px;
  }

  .split-shell {
    padding: 12px;
    gap: 10px;
  }

  .split-body {
    grid-template-columns: minmax(0, 1fr) 92px minmax(0, 1fr);
    gap: 10px;
  }

  .split-controls .button {
    min-height: 52px;
    font-size: 24px;
    border-radius: 8px;
  }
}

/* ============================================================
   DEVICE PROFILE — Tablet
   ============================================================ */
@media (max-width: 899px) and (pointer: coarse) {
  .device-profile-tablet .layout {
    grid-template-columns: 98px minmax(0, 1fr);
  }

  .device-profile-tablet .right-column {
    width: 79px;
  }

  .device-profile-tablet .content-panel {
    padding-right: 81px;
  }

  .device-profile-tablet .button.small.category-button {
    background: linear-gradient(180deg, #262626 0%, #050505 100%);
    border-color: #4a4a4a;
    color: #ffffff;
    font-size: 17px;
  }

  .device-profile-tablet .category-button.active {
    background: linear-gradient(180deg, #3a3a3a 0%, #101010 100%);
    color: #ffffff;
  }

  .device-profile-tablet .left-footer {
    gap: 3px;
  }

  .device-profile-tablet .left-footer .button {
    min-height: calc(var(--left-slot-height) * 1.1);
    height: calc(var(--left-slot-height) * 1.1);
    font-size: 17px;
  }

  .device-profile-tablet .left-column.tables .button {
    font-size: 17px;
  }

  .device-profile-tablet .right-column .button {
    font-size: 17px;
  }

  .device-profile-tablet .tables-list {
    font-size: calc(14px * var(--ui-scale));
    line-height: 1.25;
  }
}

/* ============================================================
   DEVICE PROFILE — PC
   ============================================================ */
.device-profile-pc {
  --pc-key-size: 66px;
  --pc-key-gap: 6px;
  --pc-left-width: 160px;
  --pc-right-width: 132px;
  --pc-tables-right-width: 200px;
  --pc-input-height: 42px;
  --pc-layout-gap: 12px;
  --pc-table-button-height: 68px;
  --pc-category-height-factor: 0.9;
  --pc-footer-height-factor: 1.4;
  --pc-right-button-height: 50px;
  --pc-right-gap-sm: 10px;
  --pc-right-gap-xl: 28px;
  --pc-order-panel-gap: 16px;
  --pc-keypad-height: calc(var(--pc-key-size) * 4 + var(--pc-key-gap) * 3);
  --pc-keypad-width: calc(var(--pc-key-size) * 5 + var(--pc-key-gap) * 4);
}

.device-profile-pc .layout.screen-tables {
  --pc-tables-panel-width: var(--pc-keypad-width);
  --pc-tables-layout-width: calc(var(--pc-tables-panel-width) + var(--pc-keypad-width) + var(--pc-layout-gap));
  grid-template-columns: var(--pc-left-width) var(--pc-tables-layout-width) var(--pc-tables-right-width);
  justify-content: center;
}

.device-profile-pc .layout.screen-tables .center-column {
  grid-template-columns: var(--pc-tables-panel-width) var(--pc-keypad-width);
  grid-template-rows: var(--pc-input-height) var(--pc-keypad-height) calc(var(--pc-input-height) + var(--pc-keypad-height));
  grid-template-areas:
    "panel input"
    "panel keypad"
    "panel .";
  column-gap: var(--pc-layout-gap);
  row-gap: 8px;
  justify-items: stretch;
}

.device-profile-pc .layout.screen-tables .left-column.tables {
  justify-content: flex-start;
  gap: 8px;
  padding: 0;
}

.device-profile-pc .layout.screen-tables .left-column.tables .button {
  min-height: var(--pc-table-button-height);
  font-size: 17px;
}

.device-profile-pc .layout.screen-tables .content-panel,
.device-profile-pc .layout.screen-tables .input-row,
.device-profile-pc .layout.screen-tables .keypad {
  max-width: 100%;
}

.device-profile-pc .layout.screen-tables .content-panel {
  grid-area: panel;
  width: var(--pc-tables-panel-width);
}

.device-profile-pc .layout.screen-tables .input-row {
  grid-area: input;
  width: var(--pc-keypad-width);
}

.device-profile-pc .layout.screen-tables .keypad {
  grid-area: keypad;
  width: var(--pc-keypad-width);
}

.device-profile-pc .layout.screen-tables .tables-panel {
  width: 100%;
}

.device-profile-pc .layout.screen-order .left-column:not(.tables) .button {
  background: linear-gradient(180deg, #262626 0%, #050505 100%);
  border-color: #4a4a4a;
  color: #ffffff;
  font-size: 17px;
}

.device-profile-pc .layout.screen-order .left-column:not(.tables) .category-scroll .button {
  min-height: calc(var(--left-slot-height) * var(--pc-category-height-factor));
  height: calc(var(--left-slot-height) * var(--pc-category-height-factor));
  padding-left: 6px;
  padding-right: 4px;
}

.device-profile-pc .layout.screen-order .left-column:not(.tables) .category-scroll {
  grid-template-rows: repeat(var(--category-count, 12), calc(var(--left-slot-height) * var(--pc-category-height-factor)));
  gap: 1px;
}

.device-profile-pc .layout.screen-order .left-column:not(.tables) .category-button.active {
  background: linear-gradient(180deg, #3a3a3a 0%, #101010 100%);
  color: #ffffff;
}

.device-profile-pc .layout.screen-order .left-column:not(.tables) .left-footer .button {
  min-height: calc(var(--left-slot-height) * var(--pc-footer-height-factor));
  height: calc(var(--left-slot-height) * var(--pc-footer-height-factor));
  font-size: 17px;
}

.device-profile-pc .layout.screen-order .left-column:not(.tables) .left-footer #save-button {
  background: var(--success);
  color: #ffffff;
}

.device-profile-pc .layout.screen-order .left-column:not(.tables) .left-footer #print-button {
  background: var(--cyan);
  color: #ffffff;
}

.device-profile-pc .layout.screen-order .left-column:not(.tables) .left-footer #cancel-button {
  background: var(--red);
  color: #ffffff;
}

.device-profile-pc .layout.screen-order {
  --pc-order-stack-width: var(--pc-keypad-width);
  grid-template-columns: var(--pc-left-width) var(--pc-order-stack-width) var(--pc-right-width);
  justify-content: center;
}

.device-profile-pc .layout.screen-order .center-column {
  grid-template-rows:
    minmax(0, calc(100% - var(--pc-input-height) - var(--pc-keypad-height) - var(--pc-order-panel-gap)))
    var(--pc-input-height)
    var(--pc-keypad-height);
  justify-items: center;
}

.device-profile-pc .layout.screen-order .content-panel,
.device-profile-pc .layout.screen-order .input-row {
  width: var(--pc-order-stack-width);
  max-width: 100%;
}

.device-profile-pc .keypad {
  width: var(--pc-keypad-width);
  max-width: 100%;
  grid-template-columns: repeat(5, var(--pc-key-size));
  grid-template-rows: repeat(4, var(--pc-key-size));
  gap: var(--pc-key-gap);
  justify-content: center;
  justify-items: center;
  align-items: stretch;
}

.device-profile-pc .layout.screen-order .keypad {
  width: var(--pc-order-stack-width);
}

.device-profile-pc .layout.screen-order .right-column {
  width: var(--pc-right-width);
}

.device-profile-pc .layout.screen-order .right-column .button {
  min-height: var(--pc-right-button-height);
  padding: 6px 8px;
  border-radius: 8px;
}

.device-profile-pc .layout.screen-order .right-column .button.rc-gap-sm {
  margin-bottom: var(--pc-right-gap-sm);
}

.device-profile-pc .layout.screen-order .right-column .button.rc-gap-xl {
  margin-bottom: var(--pc-right-gap-xl);
}

.device-profile-pc .keypad .key {
  width: 100%;
  height: 100%;
  aspect-ratio: auto;
}

.device-profile-pc .layout.screen-order .keypad .key.success {
  grid-row: span 2;
  width: 100%;
  font-size: 22px;
}

.device-profile-pc .layout.screen-tables .keypad .key.success {
  grid-row: span 2;
  width: 100%;
  font-size: 22px;
}

@media (min-width: 900px) and (pointer: fine) and (max-height: 860px) {
  .device-profile-pc {
    --pc-key-size: 58px;
    --pc-key-gap: 4px;
    --pc-left-width: 148px;
    --pc-right-width: 118px;
    --pc-tables-right-width: 178px;
    --pc-input-height: 38px;
    --pc-layout-gap: 10px;
    --pc-table-button-height: 56px;
    --pc-category-height-factor: 0.82;
    --pc-footer-height-factor: 1.12;
    --pc-right-button-height: 42px;
    --pc-right-gap-sm: 8px;
    --pc-right-gap-xl: 18px;
    --pc-order-panel-gap: 12px;
  }

  .device-profile-pc .layout.screen-order .left-column:not(.tables) .button,
  .device-profile-pc .layout.screen-order .right-column .button,
  .device-profile-pc .layout.screen-tables .left-column.tables .button {
    font-size: 16px;
  }

  .device-profile-pc .field {
    font-size: 16px;
  }

  .device-profile-pc .field.price,
  .device-profile-pc .keypad .key.success {
    font-size: 20px;
  }

  .device-profile-pc .keypad .key {
    font-size: 20px;
  }
}

@media (min-width: 900px) and (pointer: fine) and (max-height: 720px) {
  .device-profile-pc {
    --pc-key-size: 50px;
    --pc-key-gap: 4px;
    --pc-left-width: 136px;
    --pc-right-width: 108px;
    --pc-tables-right-width: 166px;
    --pc-input-height: 34px;
    --pc-layout-gap: 8px;
    --pc-table-button-height: 48px;
    --pc-category-height-factor: 0.74;
    --pc-footer-height-factor: 1;
    --pc-right-button-height: 36px;
    --pc-right-gap-sm: 6px;
    --pc-right-gap-xl: 12px;
    --pc-order-panel-gap: 8px;
  }

  .device-profile-pc .layout.screen-order .left-column:not(.tables) .button,
  .device-profile-pc .layout.screen-order .right-column .button,
  .device-profile-pc .layout.screen-tables .left-column.tables .button {
    font-size: 15px;
  }

  .device-profile-pc .left-column.tables {
    gap: 6px;
  }

  .device-profile-pc .order-list,
  .device-profile-pc .tables-list {
    font-size: 15px;
    padding: 6px 10px;
  }

  .device-profile-pc .order-entry {
    min-height: 30px;
    padding: 3px 6px;
  }

  .device-profile-pc .field {
    font-size: 15px;
    padding: 0 8px;
  }

  .device-profile-pc .field.price,
  .device-profile-pc .keypad .key.success {
    font-size: 18px;
  }

  .device-profile-pc .keypad .key {
    font-size: 18px;
  }
}
