:root {
  --bg: #f5f0e8;
  --panel: #fffaf2;
  --text: #2b2017;
  --muted: #7a6858;
  --primary: #8b4a22;
  --primary-dark: #643313;
  --success: #2f7d4f;
  --danger: #b93b30;
  --border: #eadcc9;
  --shadow: 0 14px 35px rgba(59, 36, 18, 0.12);
  --radius: 20px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: linear-gradient(135deg, #fff8ed, var(--bg));
  color: var(--text);
}

button, input { font: inherit; }

.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 20px clamp(16px, 3vw, 34px);
  background: #3a2417;
  color: white;
  position: sticky;
  top: 0;
  z-index: 10;
  box-shadow: 0 8px 24px rgba(0,0,0,.18);
}

.app-header h1 { margin: 0; font-size: clamp(24px, 4vw, 38px); }
.app-header p { margin: 4px 0 0; opacity: .82; }

.app-layout {
  display: grid;
  grid-template-columns: minmax(320px, 1.05fr) minmax(380px, 1.2fr) minmax(260px, .8fr);
  gap: 18px;
  padding: 18px;
  max-width: 1500px;
  margin: 0 auto;
}

.panel {
  background: rgba(255, 250, 242, .92);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  min-height: 220px;
}

.panel-title, .detail-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.panel-title h2, .panel-title h3, .detail-header h2 { margin: 0; }
.compact { margin-bottom: 10px; }

.badge {
  background: #f0dec9;
  color: var(--primary-dark);
  border-radius: 999px;
  padding: 7px 11px;
  font-weight: 700;
  white-space: nowrap;
}

.tables-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(90px, 1fr));
  gap: 12px;
}

.table-card {
  border: 2px solid var(--border);
  background: white;
  border-radius: 18px;
  padding: 16px 10px;
  min-height: 96px;
  cursor: pointer;
  text-align: left;
  transition: .15s ease;
  touch-action: manipulation;
}

.table-card:hover, .table-card.active {
  transform: translateY(-2px);
  border-color: var(--primary);
  box-shadow: 0 8px 20px rgba(139, 74, 34, .18);
}

.table-card.open { background: #fff2df; }
.table-card.closed { background: #f9fff9; }
.table-card strong { display: block; font-size: 24px; margin-bottom: 7px; }
.table-card span { color: var(--muted); font-weight: 650; }
.table-card small { display: block; color: var(--muted); margin-top: 7px; }

.empty-state {
  display: grid;
  place-content: center;
  min-height: 360px;
  text-align: center;
  color: var(--muted);
}
.empty-state h2 { color: var(--text); }

.detail-actions { display: flex; flex-wrap: wrap; gap: 8px; }

.btn {
  border: 0;
  border-radius: 14px;
  padding: 11px 14px;
  font-weight: 800;
  cursor: pointer;
  background: #eadcc9;
  color: var(--text);
  min-height: 44px;
  touch-action: manipulation;
}
.btn.primary { background: var(--primary); color: white; }
.btn.success { background: var(--success); color: white; }
.btn.danger { background: var(--danger); color: white; }
.btn.ghost { background: rgba(255,255,255,.18); border: 1px solid rgba(122,104,88,.25); }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.customer-row, .products-section, .ticket-section { margin-top: 16px; }
.customer-row label { display: block; font-weight: 800; margin-bottom: 6px; }
input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 13px 14px;
  background: white;
  color: var(--text);
}

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

.product-btn {
  background: white;
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 13px;
  text-align: left;
  cursor: pointer;
  min-height: 66px;
}
.product-btn strong { display: block; }
.product-btn span { color: var(--primary); font-weight: 850; }

.custom-form {
  display: grid;
  grid-template-columns: 1.2fr .8fr auto;
  gap: 8px;
  margin-top: 10px;
}

.cash-summary {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 16px;
}

.cash-summary > div {
  background: white;
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 13px;
}

.cash-summary small {
  display: block;
  color: var(--muted);
  font-weight: 750;
  margin-bottom: 5px;
}

.cash-summary strong {
  font-size: 24px;
  color: var(--success);
}

.history-title { margin-top: 18px; }

.items-list, .history-list {
  display: grid;
  gap: 8px;
  max-height: 430px;
  overflow: auto;
  padding-right: 3px;
}

.item-row, .history-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 8px;
  align-items: center;
  background: white;
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 11px;
}
.item-row small, .history-row small { color: var(--muted); display: block; }
.qty-controls { display: flex; align-items: center; gap: 6px; }
.qty-controls button, .remove-btn {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  border: 0;
  cursor: pointer;
  background: #eadcc9;
  font-weight: 900;
}
.remove-btn { background: #ffe0da; color: var(--danger); }

.history-row { grid-template-columns: 1fr auto; }
.history-row strong { color: var(--success); }
.cash-close-row { background: #f2fff6; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%);
  background: #2b2017;
  color: white;
  padding: 13px 18px;
  border-radius: 999px;
  box-shadow: var(--shadow);
  z-index: 50;
}

.hidden { display: none !important; }

@media (max-width: 1100px) {
  .app-layout { grid-template-columns: 1fr 1fr; }
  .history-panel { grid-column: 1 / -1; }
  .tables-grid { grid-template-columns: repeat(4, minmax(80px, 1fr)); }
}

@media (max-width: 760px) {
  .app-header { align-items: flex-start; flex-direction: column; }
  .app-layout { grid-template-columns: 1fr; padding: 12px; }
  .tables-grid { grid-template-columns: repeat(2, minmax(130px, 1fr)); }
  .quick-products { grid-template-columns: 1fr; }
  .cash-summary { grid-template-columns: 1fr; }
  .custom-form { grid-template-columns: 1fr; }
  .detail-header { align-items: flex-start; flex-direction: column; }
  .detail-actions, .detail-actions .btn { width: 100%; }
  .item-row { grid-template-columns: 1fr; }
}
