/* ====================================================
   Omni POS — Touch Cash Register UI  (pos.css)
   Uses design tokens from main.css
   ==================================================== */

/* ---- Full-screen POS wrapper ---- */
.pos-wrapper {
  height: calc(100vh - 54px);
  display: grid;
  grid-template-columns: 42% 58%;
  overflow: hidden;
  background: #eef2f7;
}

/* =============================================
   LEFT — Receipt / Scontrino
   ============================================= */
.pos-receipt-panel {
  display: flex;
  flex-direction: column;
  background: #fff;
  border-right: 2px solid #dde3ec;
  overflow: hidden;
  padding-bottom: 2rem;
}

.pos-receipt-header {
  flex-shrink: 0;
  padding: .65rem 1.1rem;
  border-bottom: 1px solid #e8ecf1;
  background: #f8fafc;
}

.pos-company-name {
  font-weight: 700;
  font-size: .95rem;
  color: var(--text);
  line-height: 1.2;
}

.pos-company-meta {
  font-size: .72rem;
  color: var(--text-muted);
  margin-top: 1px;
}

.pos-receipt-clock {
  font-size: .78rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  text-align: right;
  line-height: 1.4;
}

/* Items list */
.pos-items-area {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
}

.pos-items-area::-webkit-scrollbar { width: 4px; }
.pos-items-area::-webkit-scrollbar-track { background: #f1f5f9; }
.pos-items-area::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 2px; }

table.pos-receipt-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

table.pos-receipt-table thead th {
  padding: .4rem .9rem;
  font-size: .68rem;
  text-transform: uppercase;
  letter-spacing: .6px;
  color: var(--text-muted);
  font-weight: 600;
  background: #f1f5f9;
  border-bottom: 1px solid #e2e8f0;
  white-space: nowrap;
}

table.pos-receipt-table thead th:nth-child(1) { width: auto; }
table.pos-receipt-table thead th:nth-child(2) { width: 44px; text-align: center; }
table.pos-receipt-table thead th:nth-child(3) { width: 72px; text-align: right; }
table.pos-receipt-table thead th:nth-child(4) { width: 78px; text-align: right; }

table.pos-receipt-table tbody tr {
  border-bottom: 1px solid #f0f4f8;
  cursor: default;
  transition: background .1s;
}

table.pos-receipt-table tbody tr:hover { background: #f8fafc; }

table.pos-receipt-table tbody td {
  padding: .55rem .9rem;
  font-size: .88rem;
  vertical-align: middle;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

table.pos-receipt-table tbody td:nth-child(1) {
  font-weight: 500;
  color: var(--text);
}

table.pos-receipt-table tbody td:nth-child(2) {
  text-align: center;
  color: var(--text-muted);
  font-size: .8rem;
}

table.pos-receipt-table tbody td:nth-child(3) {
  text-align: right;
  color: var(--text-muted);
  font-size: .8rem;
}

table.pos-receipt-table tbody td:nth-child(4) {
  text-align: right;
  font-weight: 700;
  color: var(--primary);
}

/* Payment rows */
table.pos-receipt-table tbody tr[data-kind="PAYMENT"] td {
  color: #059669;
  font-style: italic;
  font-size: .82rem;
}

table.pos-receipt-table tbody tr[data-kind="ADJUSTMENT"] td:nth-child(4) {
  color: #dc2626;
}

/* Empty state */
.pos-empty-receipt {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: #cbd5e1;
  gap: .5rem;
  padding: 2rem;
}

.pos-empty-receipt-icon {
  font-size: 2.5rem;
  opacity: .4;
}

.pos-empty-receipt-text {
  font-size: .8rem;
  text-align: center;
  opacity: .7;
}

/* Receipt footer */
.pos-receipt-footer {
  flex-shrink: 0;
  border-top: 3px solid var(--primary);
  background: #1e1b4b;
  padding: .75rem 1.1rem;
}

.pos-subtotal-row {
  display: flex;
  justify-content: space-between;
  font-size: .78rem;
  color: rgba(255,255,255,.55);
  margin-bottom: .2rem;
}

.pos-total-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.pos-total-label-big {
  font-size: .78rem;
  font-weight: 700;
  color: rgba(255,255,255,.6);
  letter-spacing: 1.5px;
  text-transform: uppercase;
}

.pos-total-amount-big {
  font-size: 2.4rem;
  font-weight: 900;
  color: #fff;
  font-variant-numeric: tabular-nums;
  letter-spacing: .5px;
  line-height: 1;
}

/* =============================================
   RIGHT — Controls Panel
   ============================================= */
.pos-controls-panel {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* LCD Display */
.pos-display {
  flex-shrink: 0;
  background: #0f172a;
  padding: .7rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  border-bottom: 2px solid #1e293b;
  user-select: none;
}

.pos-display-left {
  display: flex;
  flex-direction: column;
  gap: .1rem;
}

.pos-display-label {
  font-size: .62rem;
  color: rgba(148, 163, 184, .7);
  text-transform: uppercase;
  letter-spacing: 1px;
  font-family: monospace;
}

.pos-display-input-val {
  font-family: 'Courier New', monospace;
  font-size: 1.15rem;
  font-weight: 700;
  color: #22d3ee;
  letter-spacing: 1px;
  min-width: 110px;
}

.pos-display-right {
  text-align: right;
}

.pos-display-total-val {
  font-family: 'Courier New', monospace;
  font-size: 1.9rem;
  font-weight: 900;
  color: #fff;
  letter-spacing: 1px;
  font-variant-numeric: tabular-nums;
}

/* Controls scroll area */
.pos-controls-body {
  flex: 1;
  overflow-y: auto;
  padding: clamp(.38rem, 1.1vh, .7rem) clamp(.42rem, .9vw, .75rem);
  display: flex;
  flex-direction: column;
  gap: clamp(.26rem, .7vh, .55rem);
}

.pos-controls-body::-webkit-scrollbar { width: 4px; }
.pos-controls-body::-webkit-scrollbar-track { background: #eef2f7; }
.pos-controls-body::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 2px; }

/* Section labels */
.pos-sec-label {
  font-size: .64rem;
  font-weight: 600;
  color: #94a3b8;
  text-transform: uppercase;
  letter-spacing: .9px;
  padding: 0 .2rem;
}

/* ---- PLU article shortcuts ---- */
.pos-plu-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: .4rem;
}

.pos-plu-btn {
  background: #e0e7ff;
  border: 1.5px solid #c7d2fe;
  color: #3730a3;
  border-radius: 9px;
  padding: .45rem .3rem;
  font-size: .72rem;
  font-weight: 600;
  text-align: center;
  cursor: pointer;
  transition: all .1s;
  min-height: 50px;
  line-height: 1.25;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.pos-plu-btn:hover { background: #c7d2fe; }
.pos-plu-btn:active { transform: scale(.93); background: #a5b4fc; }

.pos-plu-price {
  font-size: .64rem;
  opacity: .65;
  margin-top: 2px;
}

.pos-plu-free {
  background: #f0fdf4;
  border-color: #86efac;
  color: #15803d;
}

.pos-plu-free:hover { background: #dcfce7; }
.pos-plu-free:active { background: #bbf7d0; }

/* ---- Numpad ---- */
.pos-numpad {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: .4rem;
}

.pos-key {
  border: none;
  border-radius: 9px;
  cursor: pointer;
  font-weight: 800;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: clamp(42px, 7.1vh, 60px);
  line-height: 1.05;
  transition: all .1s;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.pos-key:active { transform: scale(.92); }

/* Number keys */
.pos-key-num {
  background: #fff;
  border: 1.5px solid #cbd5e1;
  color: var(--text);
  font-size: 1.3rem;
}

.pos-key-num:hover { background: #f1f5f9; border-color: #94a3b8; }

/* Function keys */
.pos-key-fn {
  background: #f1f5f9;
  border: 1.5px solid #94a3b8;
  color: var(--text);
  font-size: 1.1rem;
}

.pos-key-fn:hover { background: #e2e8f0; }

/* Delete / Clear */
.pos-key-del {
  background: #fff1f2;
  border: 1.5px solid #fecdd3;
  color: #dc2626;
  font-size: 1rem;
}

.pos-key-del:hover { background: #ffe4e6; }

/* Sticky footer: Contanti | Carta | TOT */
.pos-controls-footer {
  flex-shrink: 0;
  padding: .45rem .75rem .6rem;
  background: #f8fafc;
  border-top: 2px solid #e2e8f0;
}

.pos-pay-tot-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1.4fr;
  gap: .4rem;
  align-items: stretch;
}

/* TOT — big green */
.pos-key-tot {
  background: linear-gradient(135deg, #16a34a, #15803d);
  border: none;
  color: #fff;
  font-size: 1.3rem;
  letter-spacing: 3px;
  min-height: clamp(48px, 7.3vh, 62px);
  border-radius: 12px;
  box-shadow: 0 3px 10px rgba(22, 163, 74, .35);
  width: 100%;
  cursor: pointer;
}

.pos-key-tot:hover { box-shadow: 0 4px 14px rgba(22, 163, 74, .45); opacity: .94; }
.pos-key-tot:active { transform: scale(.97); }
.pos-key-tot:disabled { opacity: .45; cursor: not-allowed; box-shadow: none; }

/* ---- Departments ---- */
.pos-dept-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: .4rem;
}

.pos-dept-btn {
  background: linear-gradient(135deg, #0ea5e9, #0284c7);
  border: none;
  border-radius: 9px;
  color: #fff;
  font-weight: 700;
  font-size: .78rem;
  min-height: clamp(38px, 5.8vh, 54px);
  cursor: pointer;
  text-align: center;
  padding: .4rem .35rem;
  transition: all .1s;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: .18rem;
  line-height: 1.2;
}
.pos-dept-btn .dept-name {
  font-size: .78rem;
  font-weight: 700;
  letter-spacing: -.2px;
}
.pos-dept-btn .dept-vat {
  font-size: .62rem;
  font-weight: 500;
  opacity: .75;
  background: rgba(255,255,255,.18);
  border-radius: 4px;
  padding: .05rem .35rem;
  letter-spacing: .2px;
}

.pos-dept-btn:hover { opacity: .88; }
.pos-dept-btn:active { transform: scale(.93); }

/* ---- Function buttons ---- */
.pos-fn-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: .4rem;
}

.pos-fn-btn {
  background: #fff;
  border: 1.5px solid #cbd5e1;
  border-radius: 9px;
  color: var(--text);
  font-weight: 600;
  font-size: .72rem;
  min-height: clamp(38px, 5.2vh, 48px);
  cursor: pointer;
  text-align: center;
  line-height: 1.3;
  padding: .35rem .3rem;
  transition: all .1s;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.pos-fn-btn:hover { background: #f1f5f9; border-color: #94a3b8; }
.pos-fn-btn:active { transform: scale(.93); }

.pos-fn-btn.danger {
  background: #fff1f2;
  border-color: #fecdd3;
  color: #e11d48;
}

.pos-fn-btn.danger:hover { background: #ffe4e6; border-color: #fca5a5; }

/* ---- Payment buttons ---- */
.pos-pay-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: .4rem;
}

.pos-pay-btn {
  border: none;
  border-radius: 10px;
  font-weight: 700;
  font-size: .85rem;
  min-height: clamp(42px, 6vh, 56px);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
  transition: all .12s;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.pos-pay-btn:active { transform: scale(.95); }

.pos-pay-cash {
  background: linear-gradient(135deg, #059669, #047857);
  color: #fff;
  box-shadow: 0 2px 8px rgba(5, 150, 105, .3);
}

.pos-pay-cash:hover { opacity: .91; }

.pos-pay-card {
  background: linear-gradient(135deg, #4f46e5, #3730a3);
  color: #fff;
  box-shadow: 0 2px 8px rgba(79, 70, 229, .3);
}

.pos-pay-card:hover { opacity: .91; }

.pos-pay-online {
  background: #f0f9ff;
  border: 1.5px solid #bae6fd;
  color: #0369a1;
}

.pos-pay-online:hover { background: #e0f2fe; }

.pos-pay-suspended {
  background: #fffbeb;
  border: 1.5px solid #fde68a;
  color: #92400e;
}

.pos-pay-suspended:hover { background: #fef3c7; }

/* ---- Fiscal result ---- */
.pos-fiscal-wrap {
  border-radius: 10px;
  overflow: hidden;
}

.pos-fiscal-ok-box {
  background: #f0fdf4;
  border: 1.5px solid #86efac;
  border-radius: 10px;
  padding: .7rem .9rem;
  font-size: .78rem;
  color: #15803d;
}

.pos-fiscal-ok-box strong {
  display: block;
  font-size: .85rem;
  margin-bottom: .3rem;
}

.pos-fiscal-err-box {
  background: #fef2f2;
  border: 1.5px solid #fecaca;
  border-radius: 10px;
  padding: .7rem .9rem;
  font-size: .8rem;
  color: #dc2626;
}

/* ---- Modal for free-entry ---- */
.pos-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, .55);
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(2px);
}

.pos-modal {
  background: #fff;
  border-radius: 16px;
  padding: 1.5rem;
  width: min(380px, 92vw);
  box-shadow: 0 25px 60px rgba(0,0,0,.22);
  animation: posModalIn .18s ease;
}

@keyframes posModalIn {
  from { transform: scale(.92) translateY(10px); opacity: 0; }
  to   { transform: scale(1) translateY(0); opacity: 1; }
}

.pos-modal-title {
  font-size: 1.05rem;
  font-weight: 700;
  margin-bottom: 1rem;
  color: var(--text);
}

.pos-input-touch {
  width: 100%;
  padding: .75rem 1rem;
  border: 2px solid #e2e8f0;
  border-radius: 9px;
  font-size: .95rem;
  color: var(--text);
  background: #fff;
  outline: none;
  transition: border-color .15s;
  margin-bottom: .7rem;
}

.pos-input-touch:focus { border-color: var(--primary); }

/* ---- register-mini helper (used in settings.html) ---- */
.register-mini {
  display: flex;
  gap: .75rem;
  flex-wrap: wrap;
  align-items: center;
}

.register-mini input { max-width: 220px; }

/* Height-aware compression: keep all controls visible on short viewports */
@media (max-height: 820px) {
  .pos-sec-label {
    font-size: .58rem;
    letter-spacing: .7px;
    padding: 0 .12rem;
  }
  .pos-controls-footer {
    padding: .35rem .55rem .45rem;
  }
  .pos-dept-btn .dept-name { font-size: .7rem; }
  .pos-dept-btn .dept-vat  { font-size: .56rem; }
  .pos-fn-btn { font-size: .66rem; }
  .pos-pay-btn { font-size: .77rem; }
}

@media (max-height: 740px) {
  .pos-controls-body {
    gap: .22rem;
    padding: .3rem .45rem;
  }
  .pos-numpad,
  .pos-fn-grid,
  .pos-pay-grid,
  .pos-dept-grid,
  .pos-plu-grid,
  .pos-pay-tot-row {
    gap: .26rem;
  }
  .pos-key,
  .pos-key-tot,
  .pos-fn-btn,
  .pos-pay-btn,
  .pos-dept-btn {
    border-radius: 7px;
  }
}

/* =============================================
   RESPONSIVE — tablet portrait
   ============================================= */
@media (max-width: 860px) {
  .pos-wrapper {
    grid-template-columns: 1fr;
    grid-template-rows: 35vh calc(65vh - 54px);
  }

  .pos-receipt-panel {
    border-right: none;
    border-bottom: 2px solid #dde3ec;
    padding-bottom: 0; /* no extra padding on tablet — space is precious */
  }

  /* Barcode row: wrap fields so price+button are always visible */
  .pos-barcode-row { flex-wrap: wrap; row-gap: .3rem; }
  .pos-barcode-row #barcodeCode  { flex: 1 1 100px; min-width: 80px; }
  .pos-barcode-row #barcodeDesc  { flex: 2 1 130px; min-width: 100px; }
  .pos-barcode-row #barcodePrice { flex: 1 1 70px;  min-width: 60px; }

  .pos-plu-grid { grid-template-columns: repeat(3, 1fr); }
  .pos-numpad .pos-key { min-height: 52px; }
  .pos-key-tot { min-height: 58px; }
}

@media (max-width: 560px) {
  .pos-plu-grid { grid-template-columns: repeat(2, 1fr); }
  .pos-dept-grid { grid-template-columns: repeat(2, 1fr); }
  .pos-fn-grid { grid-template-columns: repeat(2, 1fr); }
}

/* =============================================
   PRINT — Thermal receipt 80mm
   ============================================= */
@media print {
  @page {
    size: 80mm auto;
    margin: 2mm;
  }

  html, body {
    width: 76mm;
    margin: 0 !important;
    padding: 0 !important;
    background: #fff !important;
  }

  .navbar,
  .flash-area,
  .pos-controls-panel,
  #lockOverlay {
    display: none !important;
  }

  .container,
  .pos-wrapper,
  .pos-receipt-panel {
    width: 100% !important;
    max-width: 100% !important;
    height: auto !important;
    display: block !important;
    overflow: visible !important;
    border: 0 !important;
    padding: 0 !important;
    margin: 0 !important;
    background: #fff !important;
  }

  .pos-items-area {
    overflow: visible !important;
    height: auto !important;
    max-height: none !important;
  }

  .pos-receipt-header {
    padding: 0 0 1.2mm 0 !important;
    border-bottom: 1px dashed #999 !important;
    background: #fff !important;
  }

  .pos-company-name {
    font-size: 10pt !important;
    font-weight: 700 !important;
  }

  .pos-company-meta,
  .pos-receipt-clock {
    font-size: 7.5pt !important;
    color: #111 !important;
  }

  table.pos-receipt-table thead th {
    padding: 1mm 0 !important;
    font-size: 7pt !important;
    color: #111 !important;
    background: #fff !important;
    border-bottom: 1px dashed #999 !important;
  }

  table.pos-receipt-table tbody td {
    padding: 1mm 0 !important;
    font-size: 8pt !important;
    color: #111 !important;
    white-space: normal !important;
  }

  table.pos-receipt-table tbody td:nth-child(5) {
    display: none !important;
  }

  .pos-receipt-footer {
    margin-top: 1.2mm !important;
    border-top: 1px dashed #999 !important;
    background: #fff !important;
    padding: 1.2mm 0 0 0 !important;
  }

  .pos-total-label-big,
  .pos-total-amount-big {
    color: #000 !important;
  }

  .pos-total-amount-big {
    font-size: 13pt !important;
    letter-spacing: 0 !important;
  }

  #receiptCustomerMeta {
    border-top: 1px dashed #999 !important;
    background: #fff !important;
    color: #000 !important;
    font-size: 7.5pt !important;
    padding: 1mm 0 0 0 !important;
  }
}
