/* ─── Reset & Base ───────────────────────────── */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --primary: #0066FF;
  --primary-light: #E8F0FE;
  --secondary: #00D4AA;
  --bg: #F6F8FA;
  --card: #FFFFFF;
  --text: #1F2937;
  --text-secondary: #6B7280;
  --border: #E5E7EB;
  --danger: #EF4444;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-lg: 0 4px 12px rgba(0,0,0,0.12);
  --radius: 12px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html, body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang TC', 'Microsoft JhengHei', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

#app {
  max-width: 480px;
  margin: 0 auto;
  position: relative;
  min-height: 100dvh;
}

/* ─── Screens ────────────────────────────────── */
.screen {
  display: none;
  min-height: 100dvh;
}
.screen.active {
  display: flex;
  flex-direction: column;
}

/* ─── Loading ────────────────────────────────── */
#loading-screen {
  justify-content: center;
  align-items: center;
  gap: 16px;
}
#loading-screen p {
  color: var(--text-secondary);
  font-size: 15px;
}
.loading-spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ─── Error ──────────────────────────────────── */
#error-screen {
  justify-content: center;
  align-items: center;
  gap: 12px;
  padding: 40px;
  text-align: center;
}
#error-screen p {
  color: var(--text-secondary);
  font-size: 15px;
}

/* ─── Header ─────────────────────────────────── */
.header {
  background: var(--primary);
  color: #fff;
  padding: 20px 16px 16px;
  text-align: center;
}
.header-brand {
  font-size: 12px;
  opacity: 0.7;
  letter-spacing: 1px;
  margin-bottom: 2px;
}
.header h1 {
  font-size: 22px;
  font-weight: 700;
}

/* ─── Category Tabs ──────────────────────────── */
.category-tabs {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
  scroll-snap-type: x proximity;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
  scrollbar-width: none;
  -ms-overflow-style: none;
  touch-action: pan-x;
}
.category-tabs::-webkit-scrollbar {
  display: none;
}
.cat-tab {
  flex-shrink: 0;
  padding: 8px 18px;
  border-radius: 20px;
  font-size: 14px;
  font-weight: 500;
  background: var(--bg);
  color: var(--text-secondary);
  border: none;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
  scroll-snap-align: center;
  -webkit-user-select: none;
  user-select: none;
}
.cat-tab.active {
  background: var(--primary);
  color: #fff;
}

/* ─── Product Grid ───────────────────────────── */
.product-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  padding: 12px 12px 100px;
}
.product-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 12px;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.product-card:active {
  transform: scale(0.97);
  box-shadow: var(--shadow-lg);
}
.product-img {
  width: 100%;
  aspect-ratio: 1;
  border-radius: 8px;
  overflow: hidden;
  margin-bottom: 6px;
}
.product-img img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.product-name {
  font-size: 15px;
  font-weight: 600;
  line-height: 1.3;
  color: var(--text);
}
.product-spec {
  font-size: 12px;
  color: var(--text-secondary);
}
.product-price {
  font-size: 18px;
  font-weight: 700;
  color: var(--primary);
  margin-top: auto;
}
.product-tags {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}
.product-tag {
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--primary-light);
  color: var(--primary);
}

/* ─── Cart Float Button ──────────────────────── */
.cart-float {
  position: fixed;
  bottom: calc(20px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%);
  z-index: 50;
  max-width: 480px;
  width: calc(100% - 32px);
}
.cart-float-inner {
  background: var(--primary);
  color: #fff;
  border-radius: 16px;
  padding: 14px 20px;
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(0, 102, 255, 0.35);
  transition: transform 0.15s;
}
.cart-float-inner:active {
  transform: scale(0.97);
}
#cart-count {
  background: #fff;
  color: var(--primary);
  font-weight: 700;
  font-size: 13px;
  width: 24px;
  height: 24px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.cart-float-total {
  margin-left: auto;
  font-size: 18px;
  font-weight: 700;
}

/* ─── Modal ──────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.modal-content {
  background: var(--card);
  width: 100%;
  max-width: 480px;
  max-height: 85dvh;
  border-radius: 20px 20px 0 0;
  display: flex;
  flex-direction: column;
  animation: slideUp 0.25s ease-out;
}
@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 20px 12px;
  border-bottom: 1px solid var(--border);
}
.modal-header h2 {
  font-size: 18px;
  font-weight: 700;
}
.modal-close {
  width: 32px;
  height: 32px;
  border: none;
  background: var(--bg);
  border-radius: 16px;
  font-size: 20px;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal-body {
  padding: 16px 20px;
  overflow-y: auto;
  flex: 1;
}
.modal-product-img {
  width: 100%;
  max-height: 200px;
  object-fit: cover;
  border-radius: 8px;
  margin-bottom: 12px;
}
.modal-price {
  font-size: 24px;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 16px;
}
.modal-spec {
  display: inline-block;
  padding: 4px 10px;
  background: var(--bg);
  border-radius: 6px;
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 16px;
}

/* Flavor / Taste sections */
.option-section {
  margin-bottom: 16px;
}
.option-title {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--text);
}
.option-subtitle {
  font-size: 12px;
  color: var(--text-secondary);
  font-weight: 400;
  margin-left: 4px;
}
.option-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.option-chip {
  padding: 8px 14px;
  border-radius: 8px;
  border: 1.5px solid var(--border);
  background: var(--card);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s;
  color: var(--text);
}
.option-chip.selected {
  border-color: var(--primary);
  background: var(--primary-light);
  color: var(--primary);
  font-weight: 600;
}
.option-chip .chip-price {
  font-size: 11px;
  color: var(--text-secondary);
  margin-left: 2px;
}
.option-chip.selected .chip-price {
  color: var(--primary);
}

/* Quantity */
.quantity-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  font-size: 15px;
  font-weight: 600;
}
.quantity-ctrl {
  display: flex;
  align-items: center;
  gap: 16px;
}
.quantity-ctrl button {
  width: 36px;
  height: 36px;
  border-radius: 18px;
  border: 1.5px solid var(--border);
  background: var(--card);
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text);
  transition: all 0.15s;
}
.quantity-ctrl button:active {
  background: var(--bg);
}
.quantity-ctrl span {
  font-size: 18px;
  font-weight: 700;
  min-width: 24px;
  text-align: center;
}

.modal-footer {
  padding: 12px 20px calc(12px + var(--safe-bottom));
  border-top: 1px solid var(--border);
}
.btn-add-cart {
  width: 100%;
  padding: 14px;
  border: none;
  border-radius: 12px;
  background: var(--primary);
  color: #fff;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  transition: opacity 0.15s;
}
.btn-add-cart:active {
  opacity: 0.85;
}

/* ─── Cart Panel ─────────────────────────────── */
.cart-content {
  background: var(--card);
  width: 100%;
  max-width: 480px;
  max-height: 85dvh;
  border-radius: 20px 20px 0 0;
  display: flex;
  flex-direction: column;
  animation: slideUp 0.25s ease-out;
}
.cart-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 20px 12px;
  border-bottom: 1px solid var(--border);
}
.cart-header h2 {
  font-size: 18px;
  font-weight: 700;
}
.cart-items {
  flex: 1;
  overflow-y: auto;
  padding: 12px 20px;
  min-height: 100px;
  max-height: 45dvh;
}
.cart-empty {
  text-align: center;
  color: var(--text-secondary);
  padding: 32px 0;
  font-size: 14px;
}
.cart-item {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.cart-item:last-child {
  border-bottom: none;
}
.cart-item-info {
  flex: 1;
}
.cart-item-name {
  font-size: 14px;
  font-weight: 600;
}
.cart-item-detail {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 2px;
}
.cart-item-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
}
.cart-item-price {
  font-size: 15px;
  font-weight: 700;
  color: var(--primary);
}
.cart-item-qty {
  display: flex;
  align-items: center;
  gap: 8px;
}
.cart-item-qty button {
  width: 26px;
  height: 26px;
  border-radius: 13px;
  border: 1px solid var(--border);
  background: var(--card);
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.cart-item-qty span {
  font-size: 14px;
  font-weight: 600;
  min-width: 18px;
  text-align: center;
}
.cart-item-remove {
  width: 26px;
  height: 26px;
  border: none;
  background: none;
  color: var(--danger);
  cursor: pointer;
  font-size: 16px;
}

.cart-note-row {
  padding: 0 20px 8px;
}
.cart-note-row input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  outline: none;
  transition: border-color 0.2s;
}
.cart-note-row input:focus {
  border-color: var(--primary);
}

.cart-footer {
  padding: 12px 20px calc(12px + var(--safe-bottom));
  border-top: 1px solid var(--border);
}
.cart-footer-total {
  display: flex;
  justify-content: space-between;
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 12px;
}
.btn-submit {
  width: 100%;
  padding: 14px;
  border: none;
  border-radius: 12px;
  background: var(--secondary);
  color: #fff;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  transition: opacity 0.15s;
}
.btn-submit:active {
  opacity: 0.85;
}
.btn-submit:disabled {
  background: var(--border);
  color: var(--text-secondary);
  cursor: not-allowed;
}

/* ─── Confirm Screen ─────────────────────────── */
#confirm-screen {
  justify-content: center;
  align-items: center;
  padding: 32px 20px;
}
.confirm-box {
  text-align: center;
  width: 100%;
}
.confirm-icon {
  margin-bottom: 16px;
}
.confirm-box h2 {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 8px;
}
.confirm-order-no {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 20px;
}
.confirm-items {
  text-align: left;
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}
.confirm-item-row {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  font-size: 14px;
}
.confirm-item-row .item-name {
  flex: 1;
}
.confirm-item-row .item-qty {
  color: var(--text-secondary);
  margin: 0 12px;
}
.confirm-item-row .item-price {
  font-weight: 600;
}
.confirm-total {
  font-size: 20px;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 16px;
}
.confirm-note {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 24px;
}
.btn-new-order {
  padding: 12px 32px;
  border: 2px solid var(--primary);
  border-radius: 12px;
  background: transparent;
  color: var(--primary);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}
.btn-new-order:active {
  background: var(--primary-light);
}

/* ─── 桌號點餐 ──────────────────────────────── */
.table-badge {
  display: inline-block;
  margin-top: 8px;
  padding: 4px 14px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.2);
  font-size: 16px;
  font-weight: 700;
}
.table-badge[hidden],
.confirm-table[hidden] {
  display: none;
}
.confirm-table {
  font-size: 18px;
  font-weight: 700;
  margin: -12px 0 16px;
}
