:root {
  --primary: #e67e22;
  --primary-dark: #d35400;
  --secondary: #2c3e50;
  --success: #27ae60;
  --danger: #e74c3c;
  --warning: #f39c12;
  --info: #3498db;
  --light: #ecf0f1;
  --dark: #2c3e50;
  --bg: #f5f6fa;
  --card-bg: #ffffff;
  --text: #2c3e50;
  --text-light: #7f8c8d;
  --border: #dcdde1;
  --radius: 12px;
  --shadow: 0 2px 10px rgba(0,0,0,0.08);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  min-height: -webkit-fill-available;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

html {
  height: -webkit-fill-available;
}

/* ===== HEADER ===== */
.header {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: white;
  padding: 16px 20px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 10px rgba(0,0,0,0.15);
}

.header h1 {
  font-size: 1.3rem;
  font-weight: 700;
}

.header .subtitle {
  font-size: 0.85rem;
  opacity: 0.9;
}

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

/* ===== CONTAINER ===== */
.container {
  max-width: 600px;
  margin: 0 auto;
  padding: 16px;
}

.container.wide {
  max-width: 1000px;
}

/* ===== CARDS ===== */
.card {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 12px;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

/* ===== BUTTONS ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 20px;
  border: none;
  border-radius: 8px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  text-decoration: none;
  white-space: nowrap;
}

.btn:active { transform: scale(0.97); }

.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); }

.btn-success { background: var(--success); color: white; }
.btn-danger { background: var(--danger); color: white; }
.btn-warning { background: var(--warning); color: white; }
.btn-info { background: var(--info); color: white; }
.btn-secondary { background: var(--secondary); color: white; }

.btn-outline {
  background: transparent;
  border: 2px solid var(--primary);
  color: var(--primary);
}

.btn-sm { padding: 6px 12px; font-size: 0.8rem; }
.btn-lg { padding: 14px 28px; font-size: 1.1rem; }
.btn-block { width: 100%; }

.btn-group {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* ===== FORMS ===== */
.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-weight: 600;
  margin-bottom: 6px;
  font-size: 0.9rem;
  color: var(--text);
}

.form-control {
  width: 100%;
  padding: 12px 14px;
  border: 2px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
  transition: border-color 0.2s;
  background: white;
}

.form-control:focus {
  outline: none;
  border-color: var(--primary);
}

select.form-control {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%237f8c8d' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}

/* ===== PIN INPUT ===== */
.pin-container {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin: 24px 0;
}

.pin-input {
  width: 60px;
  height: 70px;
  text-align: center;
  font-size: 1.8rem;
  font-weight: 700;
  border: 3px solid var(--border);
  border-radius: 12px;
  background: white;
}

.pin-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(230, 126, 34, 0.2);
}

/* ===== CATEGORIES TABS ===== */
.categories-tabs {
  display: flex;
  flex-wrap: nowrap;
  gap: 8px;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 12px 4px;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  -ms-overflow-style: none;
  scroll-snap-type: x mandatory;
  position: relative;
}

.categories-tabs::-webkit-scrollbar { display: none; }

.cat-tab {
  padding: 8px 18px;
  border-radius: 20px;
  border: 2px solid var(--border);
  background: white;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s;
  flex-shrink: 0;
  scroll-snap-align: start;
}

.cat-tab.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

/* ===== PRODUCT CARD ===== */
.product-card {
  background: white;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
  margin-bottom: 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.product-img {
  width: 60px;
  height: 60px;
  border-radius: 8px;
  overflow: hidden;
  flex-shrink: 0;
}

.product-img img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.product-info {
  flex: 1;
}

.product-name {
  font-weight: 600;
  font-size: 1rem;
  margin-bottom: 2px;
}

.product-desc {
  font-size: 0.8rem;
  color: var(--text-light);
}

.product-price {
  font-weight: 700;
  color: var(--primary);
  font-size: 1.1rem;
  white-space: nowrap;
}

.product-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.qty-control {
  display: flex;
  align-items: center;
  gap: 0;
  border: 2px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.qty-btn {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: var(--light);
  font-size: 1.2rem;
  font-weight: 700;
  cursor: pointer;
  color: var(--text);
}

.qty-btn:active { background: var(--border); }

.qty-value {
  width: 36px;
  text-align: center;
  font-weight: 700;
  font-size: 1rem;
  background: white;
}

/* ===== CART ===== */
.cart-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--secondary);
  color: white;
  padding: 14px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  z-index: 100;
  box-shadow: 0 -4px 20px rgba(0,0,0,0.15);
  transform: translateY(100%);
  transition: transform 0.3s ease;
}

.cart-bar.visible { transform: translateY(0); }

.cart-count {
  background: var(--primary);
  color: white;
  border-radius: 50%;
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.85rem;
  margin-right: 8px;
}

.cart-total {
  font-size: 1.1rem;
  font-weight: 700;
}

.cart-btn {
  background: var(--primary);
  color: white;
  border: none;
  padding: 10px 24px;
  border-radius: 8px;
  font-weight: 700;
  font-size: 1rem;
  cursor: pointer;
}

/* ===== ORDER STATUS ===== */
.status-badge {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
}

.status-pending { background: #fef3cd; color: #856404; }
.status-confirmed { background: #d1ecf1; color: #0c5460; }
.status-preparing { background: #fff3cd; color: #856404; }
.status-ready { background: #d4edda; color: #155724; }
.status-delivered { background: #e2e3e5; color: #383d41; }
.status-cancelled { background: #f8d7da; color: #721c24; }
.status-paid { background: #d4edda; color: #155724; border: 1px solid #28a745; }

/* ===== ORDER CARD ===== */
.order-card {
  background: white;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 12px;
  border-left: 4px solid var(--warning);
}

.order-card.status-confirmed { border-left-color: var(--info); }
.order-card.status-preparing { border-left-color: var(--warning); }
.order-card.status-ready { border-left-color: var(--success); }
.order-card.status-delivered { border-left-color: var(--text-light); }
.order-card.status-paid { border-left-color: var(--success); opacity: 0.7; }

.order-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.order-table {
  font-size: 1.2rem;
  font-weight: 700;
}

.order-time {
  font-size: 0.8rem;
  color: var(--text-light);
}

.order-items-list {
  list-style: none;
  margin: 10px 0;
}

.order-items-list li {
  padding: 4px 0;
  display: flex;
  justify-content: space-between;
  font-size: 0.9rem;
}

.order-item-qty {
  font-weight: 700;
  color: var(--primary);
  margin-right: 6px;
}

.order-total {
  font-weight: 700;
  font-size: 1.1rem;
  text-align: right;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

/* ===== MODAL ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
}

.modal-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.modal {
  background: white;
  border-radius: 16px 16px 0 0;
  width: 100%;
  max-width: 600px;
  max-height: 85vh;
  overflow-y: auto;
  padding: 20px;
  transform: translateY(100%);
  transition: transform 0.3s ease;
}

.modal-overlay.active .modal {
  transform: translateY(0);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

.modal-header h2 {
  font-size: 1.2rem;
}

.modal-close {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: var(--light);
  font-size: 1.3rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ===== TABLES GRID ===== */
.tables-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 12px;
  margin: 16px 0;
}

.table-card {
  background: white;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
  border: 2px solid transparent;
}

.table-card:hover { border-color: var(--primary); }
.table-card.active { border-color: var(--primary); background: #fff5eb; }
.table-card.has-orders { border-color: var(--warning); }

.table-number {
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--primary);
}

.table-name {
  font-size: 0.8rem;
  color: var(--text-light);
}

.table-order-count {
  background: var(--warning);
  color: white;
  border-radius: 50%;
  width: 24px;
  height: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 700;
  margin-top: 4px;
}

/* ===== SCREEN VIEWS ===== */
.screen {
  display: none;
}

.screen.active {
  display: block;
}

/* ===== PIN SCREEN ===== */
.pin-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 60vh;
  text-align: center;
  padding: 40px 20px;
}

.pin-screen h2 {
  font-size: 1.5rem;
  margin-bottom: 8px;
}

.pin-screen p {
  color: var(--text-light);
  margin-bottom: 24px;
}

.pin-error {
  color: var(--danger);
  font-weight: 600;
  margin-top: 12px;
  min-height: 20px;
}

/* ===== LOADING ===== */
.loading {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 40px;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ===== TOAST ===== */
.toast {
  position: fixed;
  top: 20px;
  right: 20px;
  padding: 14px 20px;
  border-radius: 8px;
  color: white;
  font-weight: 600;
  z-index: 300;
  transform: translateX(120%);
  transition: transform 0.3s ease;
  max-width: 350px;
}

.toast.show { transform: translateX(0); }
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }
.toast.warning { background: var(--warning); }
.toast.info { background: var(--info); }

/* ===== EMPTY STATE ===== */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-light);
}

.empty-state .icon {
  font-size: 3rem;
  margin-bottom: 12px;
}

/* ===== ADMIN TABS ===== */
.admin-tabs {
  display: flex;
  gap: 0;
  background: white;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  margin-bottom: 16px;
}

.admin-tab {
  flex: 1;
  padding: 12px 8px;
  text-align: center;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.85rem;
  background: white;
  border: none;
  border-bottom: 3px solid transparent;
  transition: all 0.2s;
}

.admin-tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
  background: #fff8f0;
}

/* ===== TABLE LIST (ADMIN) ===== */
.list-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}

.list-item:last-child { border-bottom: none; }

.list-item-info { flex: 1; }
.list-item-title { font-weight: 600; }
.list-item-sub { font-size: 0.8rem; color: var(--text-light); }

/* ===== QR CODE ===== */
.qr-card {
  background: white;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
  text-align: center;
  margin-bottom: 16px;
}

.qr-card img {
  max-width: 250px;
  margin: 12px auto;
}

.qr-card .table-label {
  font-size: 1.3rem;
  font-weight: 700;
  margin-bottom: 8px;
}

/* ===== CONFIRMATION SCREEN ===== */
.confirmation {
  text-align: center;
  padding: 40px 20px;
}

.confirmation .check-icon {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: var(--success);
  color: white;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 2.5rem;
  margin-bottom: 16px;
}

/* ===== RESPONSIVE ===== */
@media (min-width: 768px) {
  .container { padding: 24px; }

  .products-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
  }

  .modal {
    border-radius: 16px;
    max-width: 500px;
    margin-bottom: 40px;
  }

  .modal-overlay {
    align-items: center;
  }
}

/* ===== HIDE SCROLLBAR ===== */
.no-scrollbar {
  scrollbar-width: none;
}
.no-scrollbar::-webkit-scrollbar { display: none; }

/* ===== UTILITY ===== */
.text-center { text-align: center; }
.text-right { text-align: right; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mb-8 { margin-bottom: 8px; }
.mb-16 { margin-bottom: 16px; }
.flex { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.gap-8 { gap: 8px; }
.hidden { display: none !important; }

/* ===== CART ITEM ===== */
.cart-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.cart-item:last-child { border-bottom: none; }

.cart-item-name { font-weight: 600; flex: 1; }
.cart-item-qty { margin: 0 12px; font-weight: 600; }
.cart-item-price { font-weight: 700; color: var(--primary); }

.cart-remove {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: none;
  background: var(--danger);
  color: white;
  font-size: 1rem;
  cursor: pointer;
  margin-left: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Cart bottom padding when bar visible */
/* ===== WAITER CALL SECTION ===== */
.waiter-call-section {
  background: white;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 16px;
  margin-top: 20px;
  margin-bottom: 16px;
  border: 2px solid var(--border);
}

.waiter-call-section > div {
  display: flex;
  align-items: center;
  gap: 12px;
}

.waiter-call-icon {
  font-size: 1.8rem;
  flex-shrink: 0;
}

.waiter-call-text {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.waiter-call-text strong {
  font-size: 0.95rem;
}

.waiter-call-text span {
  font-size: 0.8rem;
  color: var(--text-light);
}

.has-cart { padding-bottom: 100px; }

/* ===== SWITCH ===== */
.switch {
  position: relative;
  width: 50px;
  height: 28px;
}

.switch input { display: none; }

.switch-slider {
  position: absolute;
  inset: 0;
  background: var(--border);
  border-radius: 28px;
  cursor: pointer;
  transition: 0.3s;
}

.switch-slider::before {
  content: '';
  position: absolute;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: white;
  top: 3px;
  left: 3px;
  transition: 0.3s;
}

.switch input:checked + .switch-slider {
  background: var(--success);
}

.switch input:checked + .switch-slider::before {
  transform: translateX(22px);
}

/* ===== PEOPLE SELECTOR ===== */
.people-selector {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  margin-bottom: 20px;
}

.people-btn {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: 3px solid var(--border);
  background: white;
  font-size: 1.2rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
}

.people-btn.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
  transform: scale(1.1);
}

.people-btn:hover {
  border-color: var(--primary);
}

/* ===== PIN DISPLAY (condivisione) ===== */
.pin-display {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin: 24px 0 16px;
}

.pin-digit {
  width: 64px;
  height: 80px;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: white;
  font-size: 2.2rem;
  font-weight: 800;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 15px rgba(230, 126, 34, 0.3);
}

.pin-hint {
  color: var(--text-light);
  font-size: 0.85rem;
  max-width: 300px;
  text-align: center;
  margin: 0 auto;
  line-height: 1.4;
}

/* ===== RECEIPT (ricevuta di servizio) ===== */
.receipt-card {
  background: white;
  border-radius: 0;
  box-shadow: 0 2px 20px rgba(0,0,0,0.1);
  max-width: 400px;
  margin: 20px auto;
  padding: 0;
  position: relative;
  overflow: hidden;
}

.receipt-card::before,
.receipt-card::after {
  content: '';
  display: block;
  height: 8px;
  background: repeating-linear-gradient(
    -45deg,
    var(--primary),
    var(--primary) 5px,
    var(--primary-dark) 5px,
    var(--primary-dark) 10px
  );
}

.receipt-header {
  text-align: center;
  padding: 20px 20px 12px;
}

.receipt-bar-name {
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--secondary);
}

.receipt-subtitle {
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 3px;
  text-transform: uppercase;
  color: var(--primary);
  margin-top: 4px;
}

.receipt-divider {
  border-bottom: 2px dashed var(--border);
  margin: 0 16px;
}

.receipt-info {
  padding: 12px 20px;
  font-size: 0.9rem;
  color: var(--text);
}

.receipt-info-row {
  display: flex;
  justify-content: space-between;
  padding: 2px 0;
}

.receipt-info-label {
  color: var(--text-light);
}

.receipt-info-value {
  font-weight: 600;
}

.receipt-items {
  padding: 12px 20px;
}

.receipt-item {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  font-size: 0.95rem;
}

.receipt-item-name {
  flex: 1;
}

.receipt-item-qty {
  font-weight: 700;
  color: var(--primary);
  min-width: 30px;
}

.receipt-item-price {
  font-weight: 600;
  min-width: 70px;
  text-align: right;
}

.receipt-total {
  padding: 14px 20px;
  display: flex;
  justify-content: space-between;
  font-size: 1.3rem;
  font-weight: 800;
}

.receipt-total-price {
  color: var(--primary);
}

.receipt-footer {
  text-align: center;
  padding: 16px 20px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-light);
  background: var(--bg);
}

/* Print iframe */
.print-frame {
  position: fixed;
  left: -9999px;
  top: -9999px;
  width: 80mm;
  height: 0;
}
