:root {
  --bg: #faf9f6;
  --bg-soft: #f1efe9;
  --surface: #ffffff;
  --ink: #17160f;
  --ink-soft: #6b675e;
  --line: #e8e3d8;
  --accent: #0f8f5f;
  --accent-dark: #0b6b47;
  --accent-soft: #e6f5ee;
  --danger: #c23b3b;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow-sm: 0 1px 2px rgba(23,22,15,0.05), 0 1px 8px rgba(23,22,15,0.04);
  --shadow-md: 0 4px 16px rgba(23,22,15,0.08), 0 1px 3px rgba(23,22,15,0.06);
  --shadow-lg: 0 16px 48px rgba(23,22,15,0.16), 0 2px 8px rgba(23,22,15,0.08);
}
* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button { transition: transform 0.08s ease, box-shadow 0.15s ease, filter 0.15s ease; }
button:active { transform: scale(0.97); }
header.topbar {
  position: sticky; top: 0; z-index: 10;
  background: rgba(255,255,255,0.92); backdrop-filter: saturate(180%) blur(10px);
  border-bottom: 1px solid var(--line);
  padding: 0.9rem 1.4rem;
  display: flex; align-items: center; justify-content: space-between;
}
.brand { display: flex; align-items: center; gap: 0.65rem; }
.brand .logo {
  width: 38px; height: 38px; border-radius: 11px;
  background: linear-gradient(150deg, var(--accent) 0%, var(--accent-dark) 100%); color: white; display: flex;
  align-items: center; justify-content: center; font-weight: 800; font-size: 1.15rem;
  box-shadow: var(--shadow-sm);
}
.brand .name { font-weight: 800; font-size: 1.15rem; letter-spacing: -0.01em; }
.brand .tagline { font-size: 0.72rem; color: var(--ink-soft); }
.header-actions { display: flex; align-items: center; gap: 0.6rem; }
.cart-btn {
  position: relative;
  background: linear-gradient(150deg, var(--accent) 0%, var(--accent-dark) 100%); color: white; border: none;
  padding: 0.6rem 1.1rem; border-radius: 999px; font-weight: 700; cursor: pointer;
  display: flex; align-items: center; gap: 0.4rem; font-size: 0.9rem; box-shadow: var(--shadow-sm);
}
.cart-btn:hover { box-shadow: var(--shadow-md); }
.account-btn {
  background: var(--surface); color: var(--ink); border: 1px solid var(--line);
  padding: 0.6rem 0.95rem; border-radius: 999px; font-weight: 600; cursor: pointer;
  display: flex; align-items: center; gap: 0.4rem; font-size: 0.9rem;
}
.account-btn:hover { background: var(--bg-soft); }
.account-form .field { margin-bottom: 0.9rem; }
.account-form label { display: block; font-size: 0.8rem; font-weight: 600; margin-bottom: 0.3rem; }
.account-form input {
  width: 100%; padding: 0.6rem 0.8rem; border: 1px solid var(--line); border-radius: 8px; font-size: 0.92rem;
}
.account-tabs { display: flex; gap: 0.5rem; margin-bottom: 1.1rem; }
.account-tab {
  flex: 1; text-align: center; padding: 0.5rem; border-radius: 8px; cursor: pointer;
  font-weight: 600; font-size: 0.85rem; border: 1px solid var(--line);
}
.account-tab.selected { background: var(--accent); color: white; border-color: var(--accent); }
.account-profile-row { display: flex; justify-content: space-between; padding: 0.5rem 0; border-bottom: 1px solid var(--line); font-size: 0.88rem; }
.order-history-item {
  border: 1px solid var(--line); border-radius: var(--radius); padding: 0.8rem 0.9rem; margin-bottom: 0.7rem;
}
.order-history-item .oh-top { display: flex; justify-content: space-between; font-weight: 700; margin-bottom: 0.3rem; }
.order-history-item .oh-meta { font-size: 0.78rem; color: var(--ink-soft); margin-bottom: 0.4rem; }
.order-history-item .oh-items { font-size: 0.82rem; color: var(--ink); }
.logout-link { color: var(--danger); font-size: 0.82rem; background: none; border: none; cursor: pointer; padding: 0; margin-top: 1rem; }

.promo-row { display: flex; gap: 0.5rem; margin-bottom: 0.4rem; }
.promo-row input {
  flex: 1; padding: 0.5rem 0.7rem; border: 1px solid var(--line); border-radius: 8px; font-size: 0.85rem;
}
.promo-apply-btn {
  background: var(--ink); color: white; border: none; border-radius: 8px; padding: 0.5rem 0.9rem;
  font-weight: 600; font-size: 0.82rem; cursor: pointer;
}
.promo-applied { color: var(--accent-dark); font-weight: 700; font-size: 0.85rem; flex: 1; display: flex; align-items: center; }
.promo-remove { background: none; border: none; color: var(--danger); font-size: 0.78rem; cursor: pointer; }
.order-status-badge { padding: 0.15rem 0.55rem; border-radius: 999px; font-size: 0.7rem; font-weight: 700; }
.order-status-badge.paid { background: #fbeee0; color: #b9791a; }
.order-status-badge.out_for_delivery { background: #e4ecfb; color: #2d4f9e; }
.order-status-badge.delivered { background: var(--accent-soft); color: var(--accent-dark); }
.order-status-badge.cancelled { background: #fbeaea; color: var(--danger); }
.cart-count {
  background: white; color: var(--accent); border-radius: 999px;
  min-width: 20px; height: 20px; font-size: 0.72rem; font-weight: 800;
  display: flex; align-items: center; justify-content: center; padding: 0 4px;
}
main { max-width: 1100px; margin: 0 auto; padding: 1.4rem; }
.delivery-note {
  background: var(--accent-soft); border-radius: var(--radius);
  padding: 0.75rem 1.1rem; font-size: 0.85rem; margin-bottom: 1.4rem; color: var(--accent-dark); font-weight: 600;
}
.category-block { margin-bottom: 2.2rem; }
.category-title {
  font-size: 1.1rem; font-weight: 800; margin: 0 0 0.9rem; letter-spacing: -0.01em;
  padding-bottom: 0.4rem; border-bottom: 2px solid var(--accent);
  display: inline-block;
}
.product-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 1rem;
}
.product-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1rem; display: flex; flex-direction: column; gap: 0.45rem;
  box-shadow: var(--shadow-sm); transition: box-shadow 0.15s ease, transform 0.1s ease, border-color 0.15s ease;
}
.product-card:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); border-color: var(--line); }
.product-emoji { font-size: 2.1rem; }
.product-photo { width: 100%; height: 96px; object-fit: cover; border-radius: 10px; background: var(--bg-soft); }
.product-name { font-weight: 600; font-size: 0.92rem; line-height: 1.3; }
.product-price { color: var(--accent-dark); font-weight: 800; font-size: 0.96rem; }
.product-stock { font-size: 0.72rem; color: var(--ink-soft); }
.product-stock.low { color: var(--danger); }
.add-row { display: flex; align-items: center; gap: 0.5rem; margin-top: auto; }
.qty-stepper {
  display: flex; align-items: center; border: 1px solid var(--line); border-radius: var(--radius-sm); overflow: hidden;
}
.qty-stepper button {
  background: var(--bg-soft); border: none; width: 28px; height: 28px; cursor: pointer; font-size: 1rem;
}
.qty-stepper span { width: 26px; text-align: center; font-size: 0.85rem; }
.add-btn {
  flex: 1; background: linear-gradient(150deg, var(--accent) 0%, var(--accent-dark) 100%); color: white; border: none; border-radius: var(--radius-sm);
  padding: 0.45rem 0.5rem; font-weight: 700; cursor: pointer; font-size: 0.82rem;
}
.add-btn:disabled { background: #bbb; cursor: not-allowed; }

/* Cart drawer */
.overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.35); z-index: 20;
  display: none;
}
.overlay.open { display: block; }
.drawer {
  position: fixed; top: 0; right: 0; height: 100%; width: min(420px, 100%);
  background: var(--surface); z-index: 21; transform: translateX(100%);
  transition: transform 0.25s ease; display: flex; flex-direction: column;
  box-shadow: -8px 0 24px rgba(0,0,0,0.15);
}
.drawer.open { transform: translateX(0); }
.drawer-header {
  padding: 1rem 1.25rem; border-bottom: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between;
}
.drawer-header h2 { margin: 0; font-size: 1.1rem; }
.drawer-close { background: none; border: none; font-size: 1.4rem; cursor: pointer; color: var(--ink-soft); }
.drawer-body { flex: 1; overflow-y: auto; padding: 1rem 1.25rem; }
.cart-line { display: flex; justify-content: space-between; align-items: center; padding: 0.6rem 0; border-bottom: 1px solid var(--line); gap: 0.5rem; }
.cart-line .info { flex: 1; }
.cart-line .name { font-weight: 600; font-size: 0.88rem; }
.cart-line .price { font-size: 0.78rem; color: var(--ink-soft); }
.cart-line .remove { background: none; border: none; color: var(--danger); cursor: pointer; font-size: 0.78rem; }
.drawer-footer { border-top: 1px solid var(--line); padding: 1rem 1.25rem; }
.totals-row { display: flex; justify-content: space-between; font-size: 0.88rem; margin-bottom: 0.3rem; color: var(--ink-soft); }
.totals-row.grand { font-weight: 700; font-size: 1.05rem; color: var(--ink); margin-top: 0.5rem; }
.checkout-btn {
  width: 100%; background: linear-gradient(150deg, var(--accent) 0%, var(--accent-dark) 100%); color: white; border: none; border-radius: var(--radius-sm);
  padding: 0.8rem; font-weight: 800; font-size: 0.95rem; cursor: pointer; margin-top: 0.8rem; box-shadow: var(--shadow-md);
}
.checkout-btn:disabled { background: #bbb; cursor: not-allowed; box-shadow: none; }
.empty-cart { text-align: center; color: var(--ink-soft); padding: 3rem 1rem; font-size: 0.9rem; }

/* Checkout form */
.field { margin-bottom: 0.8rem; }
.field label { display: block; font-size: 0.8rem; font-weight: 600; margin-bottom: 0.3rem; }
.field input, .field select, .field textarea {
  width: 100%; padding: 0.55rem 0.7rem; border: 1px solid var(--line); border-radius: 8px; font-size: 0.9rem;
  font-family: inherit;
}
.pay-options { display: flex; gap: 0.5rem; }
.pay-option {
  flex: 1; border: 1px solid var(--line); border-radius: 8px; padding: 0.5rem; text-align: center;
  cursor: pointer; font-size: 0.82rem; font-weight: 600;
}
.pay-option.selected { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-dark); }
.back-link { background: none; border: none; color: var(--accent-dark); cursor: pointer; font-size: 0.85rem; padding: 0; margin-bottom: 0.8rem; }

/* Confirmation */
.confirm-box { text-align: center; padding: 2rem 1rem; }
.confirm-icon { font-size: 3rem; margin-bottom: 0.5rem; }
.confirm-order-no { font-size: 1.3rem; font-weight: 800; color: var(--accent-dark); margin: 0.4rem 0; }
.confirm-sync {
  display: inline-flex; align-items: center; gap: 0.4rem; font-size: 0.78rem; color: var(--ink-soft);
  background: var(--bg); border-radius: 999px; padding: 0.3rem 0.7rem; margin-top: 0.6rem;
}
.dot { width: 8px; height: 8px; border-radius: 999px; background: #ccc; }
.dot.synced { background: #2e9e5b; }
.dot.syncing { background: #d8a230; animation: pulse 1s infinite; }
.dot.error { background: var(--danger); }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.3; } }

footer { text-align: center; padding: 2rem 1rem; color: var(--ink-soft); font-size: 0.78rem; }

@media (max-width: 480px) {
  .product-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
}
