*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'PingFang SC', 'Microsoft YaHei', sans-serif;
  font-size: 16px;
  background: #f0f2f0;
  color: #222;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.hidden {
  display: none !important;
}

.screen {
  min-height: 100%;
}

.muted {
  color: #666;
  font-size: 0.9em;
}

.error {
  color: #c62828;
  margin-top: 12px;
}

.links-row {
  margin-top: 16px;
  text-align: center;
  font-size: 0.88em;
}
.links-row a {
  color: #1a7f37;
  text-decoration: none;
}
.links-row a:hover {
  text-decoration: underline;
}

/* Login */
.login-card {
  max-width: 420px;
  margin: 0 auto;
  padding: 48px 24px;
}

.login-card h1 {
  margin: 0 0 8px;
  color: #1a7f37;
}

.field {
  display: block;
  margin: 16px 0;
}

.field span {
  display: block;
  margin-bottom: 6px;
  font-weight: 600;
}

.field input {
  width: 100%;
  padding: 14px 16px;
  font-size: 18px;
  border: 1px solid #ccc;
  border-radius: 10px;
}

.field-optional {
  opacity: 0.85;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 0 20px;
  border: none;
  border-radius: 10px;
  font-size: 17px;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
}

.btn:active {
  transform: scale(0.98);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-primary {
  background: #1a7f37;
  color: #fff;
}

.btn-secondary {
  background: #e8e8e8;
  color: #333;
}

.btn-warn {
  background: #ffebee;
  color: #c62828;
}

.btn-ghost {
  background: transparent;
  color: #555;
  min-height: 44px;
}

.btn-lg {
  width: 100%;
  min-height: 56px;
  font-size: 18px;
}

.btn-sm {
  min-height: 40px;
  padding: 0 14px;
  font-size: 15px;
}

/* App shell */
.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: #1a7f37;
  color: #fff;
  flex-wrap: wrap;
}

.topbar-left {
  flex: 1;
  min-width: 120px;
}

.topbar-left .muted {
  color: rgba(255, 255, 255, 0.8);
  margin-left: 8px;
}

.tabs {
  display: flex;
  gap: 8px;
}

.tab {
  min-height: 44px;
  padding: 0 20px;
  border: none;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.2);
  color: #fff;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
}

.tab.on {
  background: #fff;
  color: #1a7f37;
}

.badge {
  display: inline-block;
  min-width: 20px;
  padding: 0 6px;
  margin-left: 4px;
  border-radius: 10px;
  background: #e65100;
  color: #fff;
  font-size: 12px;
  vertical-align: middle;
}

/* Order panel layout */
.panel-order {
  display: grid;
  grid-template-columns: 140px 1fr 280px;
  gap: 0;
  height: calc(100vh - 64px);
  height: calc(100dvh - 64px);
}

.col-tables,
.col-cart {
  background: #fff;
  padding: 12px;
  overflow: auto;
  border-right: 1px solid #e0e0e0;
}

.col-cart {
  border-right: none;
  border-left: 1px solid #e0e0e0;
  display: flex;
  flex-direction: column;
}

.col-menu {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: #f8f9f8;
}

.col-tables h2,
.col-cart h2 {
  margin: 0 0 12px;
  font-size: 15px;
}

.table-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.table-chip {
  min-height: 48px;
  border: none;
  border-radius: 8px;
  background: #f0f0f0;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
}

.table-chip.on {
  background: #1a7f37;
  color: #fff;
}

.input-table {
  width: 100%;
  margin-top: 10px;
  padding: 12px;
  font-size: 16px;
  border: 1px solid #ddd;
  border-radius: 8px;
}

.cat-scroll {
  display: flex;
  gap: 8px;
  padding: 10px 12px;
  overflow-x: auto;
  background: #fff;
  border-bottom: 1px solid #e0e0e0;
  flex-shrink: 0;
}

.cat-btn {
  flex-shrink: 0;
  min-height: 44px;
  padding: 0 18px;
  border: none;
  border-radius: 22px;
  background: #eee;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}

.cat-btn.on {
  background: #1a7f37;
  color: #fff;
}

.product-grid {
  flex: 1;
  overflow: auto;
  padding: 12px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px;
  align-content: start;
}

.product-card {
  min-height: 88px;
  padding: 12px;
  border: none;
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
  text-align: left;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.product-card:active {
  background: #e8f5e9;
}

.product-card .name {
  font-size: 15px;
  font-weight: 600;
  line-height: 1.3;
}

.product-card .price {
  font-size: 17px;
  color: #1a7f37;
  font-weight: 700;
  margin-top: 6px;
}

.product-card .tag {
  font-size: 11px;
  color: #e65100;
}

.cart-list {
  list-style: none;
  margin: 0;
  padding: 0;
  flex: 1;
  overflow: auto;
}

.cart-line {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 0;
  border-bottom: 1px solid #eee;
}

.cart-line .info {
  flex: 1;
  min-width: 0;
}

.cart-line .name {
  font-weight: 600;
  font-size: 15px;
}

.cart-line .qty-ctrl {
  display: flex;
  gap: 4px;
}

.qty-btn {
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 8px;
  background: #eee;
  font-size: 22px;
  cursor: pointer;
}

.cart-empty {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.cart-total {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 12px 0;
  font-size: 18px;
  border-top: 2px solid #1a7f37;
  margin-top: 8px;
}

.cart-total strong {
  font-size: 28px;
  color: #1a7f37;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 8px 0;
  font-size: 14px;
}

.check-row input {
  width: 22px;
  height: 22px;
}

.cart-actions {
  display: grid;
  grid-template-columns: 1fr 1.4fr;
  gap: 10px;
}

/* Orders panel */
.panel-orders {
  padding: 16px;
  height: calc(100vh - 64px);
  height: calc(100dvh - 64px);
  overflow: auto;
}

.order-card {
  background: #fff;
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
}

.order-card .head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.order-card .no {
  font-size: 20px;
  font-weight: 700;
}

.order-card .status {
  padding: 4px 12px;
  border-radius: 8px;
  background: #eee;
  font-size: 14px;
}

.order-card .status.awaiting {
  background: #fff8e6;
  color: #e65100;
}

.order-card .status.paid {
  background: #e8f5e9;
  color: #1a7f37;
}

.order-card .meta {
  font-size: 14px;
  color: #666;
  margin-bottom: 8px;
}

.order-card .items {
  font-size: 14px;
  margin-bottom: 12px;
}

.order-card .actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 32px;
  transform: translateX(-50%);
  max-width: 90%;
  padding: 14px 24px;
  background: rgba(0, 0, 0, 0.85);
  color: #fff;
  border-radius: 10px;
  font-size: 16px;
  z-index: 9999;
  pointer-events: none;
}

/* Option picker modal */
.option-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
}

.option-overlay.hidden {
  display: none !important;
}

.option-sheet {
  width: 100%;
  max-width: 560px;
  max-height: 85vh;
  background: #fff;
  border-radius: 16px 16px 0 0;
  display: flex;
  flex-direction: column;
  box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.15);
}

.option-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  border-bottom: 1px solid #eee;
  flex-shrink: 0;
}

.option-head h3 {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
}

.option-close {
  width: 40px;
  height: 40px;
  border: none;
  background: #f0f0f0;
  border-radius: 50%;
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
  color: #666;
}

.option-body {
  flex: 1;
  overflow: auto;
  padding: 12px 18px;
  -webkit-overflow-scrolling: touch;
}

.option-group {
  margin-bottom: 18px;
}

.option-group-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  font-size: 15px;
}

.opt-tag {
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 4px;
  background: #ffebee;
  color: #c62828;
  font-weight: 600;
}

.opt-tag--multi {
  background: #e3f2fd;
  color: #1565c0;
}

.opt-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.opt-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  padding: 8px 14px;
  border: 2px solid #e0e0e0;
  border-radius: 10px;
  background: #fff;
  font-size: 15px;
  cursor: pointer;
  touch-action: manipulation;
}

.opt-chip.on {
  border-color: #1a7f37;
  background: #e8f5e9;
  color: #1a7f37;
  font-weight: 600;
}

.opt-chip.sold-out {
  opacity: 0.45;
  cursor: not-allowed;
}

.opt-delta {
  font-size: 13px;
  color: #666;
}

.opt-chip.on .opt-delta {
  color: #2e7d32;
}

.option-foot {
  padding: 12px 18px 20px;
  padding-bottom: max(20px, env(safe-area-inset-bottom));
  border-top: 1px solid #eee;
  flex-shrink: 0;
}

.option-summary {
  margin: 0 0 10px;
  font-size: 14px;
  min-height: 1.2em;
}

@media (min-width: 600px) {
  .option-overlay {
    align-items: center;
    padding: 24px;
  }

  .option-sheet {
    border-radius: 16px;
    max-height: 80vh;
  }
}

@media (max-width: 900px) {
  .panel-order {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr auto;
    height: auto;
    min-height: calc(100dvh - 64px);
  }

  .col-tables {
    border-right: none;
    border-bottom: 1px solid #e0e0e0;
  }

  .col-tables .table-grid {
    grid-template-columns: repeat(5, 1fr);
  }

  .col-cart {
    border-left: none;
    border-top: 1px solid #e0e0e0;
    max-height: 42vh;
  }

  .col-menu {
    min-height: 40vh;
  }
}
