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

:root {
  --primary: #E8751A;
  --primary-light: #FFF3E0;
  --primary-dark: #BF5F0E;
  --green: #2E7D32;
  --green-light: #E8F5E9;
  --red: #D32F2F;
  --red-light: #FFEBEE;
  --gold: #FFA000;
  --gold-light: #FFF8E1;
  --text: #3E2723;
  --text-secondary: #6D4C41;
  --bg: #FEFCF8;
  --card-bg: #FFFFFF;
  --border: #F0E6D6;
  --shadow: 0 2px 12px rgba(62, 39, 35, 0.08);
  --radius: 16px;
  --radius-sm: 10px;
  --max-width: 480px;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  padding-bottom: env(safe-area-inset-bottom);
}

.container {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 16px;
}

/* Header */
.header {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  color: white;
  padding: 20px 16px;
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-content {
  max-width: var(--max-width);
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.header-title {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.header-title span {
  font-size: 1.5rem;
  margin-right: 6px;
}

.header-subtitle {
  font-size: 0.75rem;
  opacity: 0.85;
  margin-top: 2px;
}

.user-info {
  text-align: right;
}

.user-name {
  font-size: 0.85rem;
  font-weight: 600;
}

.points-badge {
  background: rgba(255,255,255,0.2);
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 0.85rem;
  font-weight: 700;
  margin-top: 4px;
  display: inline-block;
}

.points-badge .coin {
  margin-right: 4px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 12px 24px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
}

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

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

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

.btn-green {
  background: var(--green);
  color: white;
}

.btn-green:hover {
  background: #1B5E20;
}

.btn-danger {
  background: var(--red);
  color: white;
}

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

.btn-block {
  width: 100%;
}

.btn-sm {
  padding: 8px 16px;
  font-size: 0.85rem;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Category tabs */
.category-tabs {
  display: flex;
  gap: 8px;
  padding: 16px 0;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

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

.category-tab {
  flex-shrink: 0;
  padding: 8px 18px;
  border-radius: 20px;
  border: 2px solid var(--border);
  background: var(--card-bg);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  color: var(--text-secondary);
  font-family: inherit;
}

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

/* Menu grid */
.menu-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  padding-bottom: 160px;
}

.menu-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: all 0.2s;
  border: 2px solid transparent;
}

.menu-card:active {
  transform: scale(0.97);
}

.menu-card.out-of-stock {
  opacity: 0.5;
  text-decoration: line-through;
}

.menu-card .card-img {
  width: 100%;
  height: 120px;
  object-fit: cover;
  display: block;
  background: var(--primary-light);
}

.card-icon-bg {
  width: 100%;
  height: 120px;
  background: linear-gradient(135deg, #FFF3E0 0%, #FFE0B2 100%);
  display: flex;
  align-items: center;
  justify-content: center;
}

.card-icon {
  font-size: 3.2rem;
  line-height: 1;
}

.menu-card .card-body {
  padding: 12px;
}

.menu-card .item-name {
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.menu-card .item-desc {
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-bottom: 8px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.menu-card .item-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.menu-card .item-price {
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--primary);
}

.menu-card .item-price .unit {
  font-size: 0.75rem;
  font-weight: 600;
}

.menu-card .add-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--primary);
  color: white;
  border: none;
  font-size: 1.2rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.menu-card .add-btn:active {
  transform: scale(0.9);
}

/* Cart */
.cart-overlay {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--card-bg);
  border-radius: var(--radius) var(--radius) 0 0;
  box-shadow: 0 -4px 20px rgba(0,0,0,0.1);
  z-index: 200;
  max-height: 50vh;
  display: flex;
  flex-direction: column;
  transition: transform 0.3s;
}

.cart-overlay.collapsed .cart-body {
  display: none;
}

.cart-handle {
  padding: 12px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
}

.cart-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

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

.cart-total {
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--primary);
}

.cart-body {
  overflow-y: auto;
  padding: 8px 16px;
  flex: 1;
}

.cart-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}

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

.cart-item-name {
  font-weight: 600;
  flex: 1;
}

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

.cart-item-qty {
  display: flex;
  align-items: center;
  gap: 8px;
}

.qty-btn {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: white;
  font-size: 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  color: var(--text);
}

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

.qty-num {
  font-weight: 700;
  min-width: 20px;
  text-align: center;
}

.cart-footer {
  padding: 12px 16px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.cart-note-input {
  width: 100%;
  padding: 10px 14px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-family: inherit;
  resize: none;
  outline: none;
  transition: border-color 0.2s;
}

.cart-note-input:focus {
  border-color: var(--primary);
}

/* Order History */
.section-title {
  font-size: 1.1rem;
  font-weight: 700;
  margin: 24px 0 12px;
  color: var(--text);
}

.order-card {
  background: var(--card-bg);
  border-radius: var(--radius-sm);
  padding: 14px;
  margin-bottom: 10px;
  box-shadow: var(--shadow);
  border-left: 4px solid var(--primary);
}

.order-card.status-confirmed { border-left-color: var(--gold); }
.order-card.status-cooking { border-left-color: var(--primary); }
.order-card.status-done { border-left-color: var(--green); }
.order-card.status-cancelled { border-left-color: var(--red); opacity: 0.6; }

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

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

.order-status {
  font-size: 0.75rem;
  padding: 2px 10px;
  border-radius: 10px;
  font-weight: 600;
}

.order-status.pending { background: var(--gold-light); color: var(--gold); }
.order-status.confirmed { background: var(--gold-light); color: var(--gold); }
.order-status.cooking { background: var(--primary-light); color: var(--primary); }
.order-status.done { background: var(--green-light); color: var(--green); }
.order-status.cancelled { background: var(--red-light); color: var(--red); }

.order-items {
  font-size: 0.9rem;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.order-total {
  font-weight: 700;
  color: var(--primary);
  font-size: 0.9rem;
}

/* Toast */
.toast {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(-100px);
  background: var(--text);
  color: white;
  padding: 12px 24px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  z-index: 999;
  transition: transform 0.3s;
  max-width: 90%;
  text-align: center;
}

.toast.show {
  transform: translateX(-50%) translateY(0);
}

.toast.success { background: var(--green); }
.toast.error { background: var(--red); }
.toast.info { background: var(--text); }

/* Loading */
.loading {
  text-align: center;
  padding: 60px 0;
  color: var(--text-secondary);
}

.loading-spinner {
  display: inline-block;
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-bottom: 12px;
}

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

/* Admin Styles */
.admin-layout {
  display: flex;
  min-height: 100vh;
}

.admin-sidebar {
  width: 72px;
  background: var(--text);
  color: white;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 16px 0;
  gap: 8px;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 50;
}

.admin-logo {
  font-size: 1.5rem;
  margin-bottom: 12px;
}

.admin-nav-item {
  width: 56px;
  height: 56px;
  border-radius: var(--radius-sm);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: 0.65rem;
  cursor: pointer;
  transition: all 0.2s;
  color: rgba(255,255,255,0.6);
  border: none;
  background: none;
  font-family: inherit;
}

.admin-nav-item .nav-icon {
  font-size: 1.3rem;
}

.admin-nav-item.active {
  background: rgba(255,255,255,0.15);
  color: white;
}

.admin-main {
  margin-left: 72px;
  flex: 1;
  padding-bottom: 40px;
}

.admin-header {
  background: var(--card-bg);
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

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

.admin-content {
  padding: 20px 24px;
  max-width: 800px;
}

/* Stats cards */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--card-bg);
  padding: 16px;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
}

.stat-card .stat-label {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.stat-card .stat-value {
  font-size: 1.8rem;
  font-weight: 800;
  color: var(--primary);
}

.stat-card .stat-sub {
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-top: 2px;
}

.stat-card .stat-icon {
  font-size: 1.5rem;
}

/* Admin table */
.admin-table {
  width: 100%;
  border-collapse: collapse;
}

.admin-table th {
  text-align: left;
  padding: 10px 12px;
  font-size: 0.8rem;
  color: var(--text-secondary);
  border-bottom: 2px solid var(--border);
}

.admin-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}

.admin-table tr:hover {
  background: var(--primary-light);
}

/* Form styles */
.form-group {
  margin-bottom: 16px;
}

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

.form-input, .form-select, .form-textarea {
  width: 100%;
  padding: 10px 14px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s;
  background: white;
}

.form-input:focus, .form-select:focus, .form-textarea:focus {
  border-color: var(--primary);
}

.form-textarea {
  resize: vertical;
  min-height: 80px;
}

.form-row {
  display: flex;
  gap: 12px;
}

.form-row > * {
  flex: 1;
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 24px;
  max-width: 400px;
  width: 100%;
  max-height: 80vh;
  overflow-y: auto;
}

.modal h3 {
  margin-bottom: 16px;
  font-size: 1.1rem;
}

.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 20px;
}

.modal-actions .btn {
  flex: 1;
}

/* QR Code page */
.qr-page {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 40px 20px;
  text-align: center;
}

.qr-page h1 {
  font-size: 2rem;
  margin-bottom: 8px;
}

.qr-page p {
  color: var(--text-secondary);
  margin-bottom: 20px;
}

.qr-code {
  padding: 20px;
  background: white;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 20px;
}

.qr-hint {
  font-size: 0.9rem;
  color: var(--text-secondary);
  margin-bottom: 12px;
}

.qr-print-btn {
  margin-top: 20px;
}

@media print {
  .qr-print-btn, .no-print { display: none !important; }
  .qr-page { padding: 0; }
  .qr-code { box-shadow: none; border: 1px solid #ddd; }
}

/* Responsive */
@media (min-width: 600px) {
  .menu-grid {
    grid-template-columns: 1fr 1fr 1fr;
  }
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 40px 0;
  color: var(--text-secondary);
}

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

/* Points history list */
.tx-list {
  list-style: none;
}

.tx-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

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

.tx-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.tx-icon {
  font-size: 1.3rem;
}

.tx-reason {
  font-weight: 600;
  font-size: 0.9rem;
}

.tx-time {
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.tx-amount {
  font-weight: 800;
  font-size: 1rem;
}

.tx-amount.positive { color: var(--green); }
.tx-amount.negative { color: var(--red); }

/* Points earn panel */
.earn-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 20px;
}

.earn-card {
  background: var(--card-bg);
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
}

.earn-card:active {
  transform: scale(0.97);
}

.earn-card.selected {
  border-color: var(--primary);
  background: var(--primary-light);
}

.earn-card .earn-icon {
  font-size: 1.8rem;
  margin-bottom: 4px;
}

.earn-card .earn-action {
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 2px;
}

.earn-card .earn-points {
  font-size: 0.8rem;
  color: var(--green);
  font-weight: 700;
}

.select-user {
  margin-bottom: 20px;
}
