:root {
  --bg: #f7f7fb;
  --surface: #ffffff;
  --text: #1a1a2e;
  --muted: #6b7280;
  --border: #e5e7eb;
  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --success: #16a34a;
  --shadow: 0 2px 10px rgba(0,0,0,0.06);
  --radius: 12px;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px;
}

/* Header */
.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.header-inner {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 14px 20px;
  flex-wrap: wrap;
}

.logo {
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--text);
  text-decoration: none;
  white-space: nowrap;
}
.logo span { color: var(--primary); }

.search-wrap { flex: 1; min-width: 160px; }

#searchInput {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 0.95rem;
  outline: none;
}
#searchInput:focus { border-color: var(--primary); }

.cat-nav {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.cat-btn {
  border: 1px solid var(--border);
  background: var(--surface);
  padding: 8px 14px;
  border-radius: 999px;
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--text);
  transition: all 0.15s;
}
.cat-btn:hover { border-color: var(--primary); }
.cat-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
}

.cart-btn {
  position: relative;
  border: none;
  background: var(--primary);
  color: white;
  padding: 10px 16px;
  border-radius: 999px;
  cursor: pointer;
  font-size: 1rem;
  font-weight: 600;
}
.cart-btn:hover { background: var(--primary-dark); }
#cartCount {
  background: white;
  color: var(--primary);
  border-radius: 999px;
  padding: 1px 7px;
  font-size: 0.8rem;
  margin-left: 4px;
}

.welcome-msg {
  font-size: 0.85rem;
  color: var(--muted);
  white-space: nowrap;
}

.logout-btn {
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 8px 16px;
  font-size: 0.85rem;
  font-weight: 600;
}
.logout-btn:hover { border-color: var(--primary); color: var(--primary); }

/* Login page */
.login-body {
  background: linear-gradient(135deg, #eef2ff, #f5f3ff);
  min-height: 100vh;
}

.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.login-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 36px 32px;
  width: 100%;
  max-width: 380px;
  text-align: center;
}

.login-logo {
  display: inline-block;
  margin-bottom: 18px;
  text-decoration: none;
}

.login-card h1 {
  font-size: 1.4rem;
  margin: 0 0 6px;
}

.login-subtitle {
  color: var(--muted);
  font-size: 0.9rem;
  margin: 0 0 24px;
}

.login-card form {
  text-align: left;
}

.login-error {
  background: #fef2f2;
  color: #dc2626;
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 0.85rem;
  margin: 0 0 14px;
}

.demo-credentials {
  margin: 22px 0 0;
  padding: 14px;
  background: #f5f5fb;
  border-radius: 8px;
  font-size: 0.8rem;
  color: var(--muted);
  line-height: 1.6;
}
.demo-credentials code {
  background: #e5e7eb;
  padding: 2px 6px;
  border-radius: 4px;
  color: var(--text);
  font-weight: 600;
}

/* Hero */
.hero {
  text-align: center;
  padding: 40px 0 20px;
}
.hero h1 { font-size: 2rem; margin-bottom: 6px; }
.hero p { color: var(--muted); margin: 0; }

/* Product grid */
.product-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 20px;
  padding: 30px 0 60px;
}

.product-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: transform 0.15s;
}
.product-card:hover { transform: translateY(-3px); }

.product-image {
  height: 150px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 4rem;
  background: linear-gradient(135deg, #eef2ff, #f5f3ff);
}

.product-info {
  padding: 14px 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
}

.product-cat {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--primary);
  font-weight: 700;
}

.product-name { font-size: 1.02rem; font-weight: 700; margin: 0; }
.product-desc { font-size: 0.85rem; color: var(--muted); margin: 0; flex: 1; }

.product-bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 8px;
}

.product-price { font-weight: 800; font-size: 1.1rem; }

.empty-state {
  text-align: center;
  color: var(--muted);
  padding: 40px 0;
}

/* Buttons */
.btn {
  border: none;
  border-radius: 8px;
  padding: 10px 16px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
}
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-primary:disabled { background: #c7c7d9; cursor: not-allowed; }
.btn-block { width: 100%; }

.icon-btn {
  border: none;
  background: transparent;
  font-size: 1.1rem;
  cursor: pointer;
  color: var(--muted);
  padding: 4px 8px;
}
.icon-btn:hover { color: var(--text); }

/* Overlay */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 20;
}

/* Cart drawer */
.cart-drawer {
  position: fixed;
  top: 0;
  right: 0;
  height: 100%;
  width: min(400px, 100%);
  background: var(--surface);
  z-index: 21;
  display: flex;
  flex-direction: column;
  box-shadow: -4px 0 20px rgba(0,0,0,0.15);
  animation: slideIn 0.2s ease-out;
}
@keyframes slideIn {
  from { transform: translateX(100%); }
  to { transform: translateX(0); }
}

.cart-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.cart-header h2 { margin: 0; font-size: 1.2rem; }

.cart-items {
  flex: 1;
  overflow-y: auto;
  padding: 12px 20px;
}

.cart-empty {
  text-align: center;
  color: var(--muted);
  padding: 60px 0;
}

.cart-item {
  display: flex;
  gap: 12px;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}

.cart-item-emoji {
  font-size: 2rem;
  width: 50px;
  height: 50px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f5f5fb;
  border-radius: 8px;
  flex-shrink: 0;
}

.cart-item-info { flex: 1; }
.cart-item-name { font-weight: 700; font-size: 0.9rem; }
.cart-item-price { color: var(--muted); font-size: 0.85rem; }

.qty-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
}
.qty-btn {
  border: 1px solid var(--border);
  background: var(--surface);
  width: 24px;
  height: 24px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.9rem;
  line-height: 1;
}
.qty-btn:hover { border-color: var(--primary); }

.remove-btn {
  border: none;
  background: none;
  color: #ef4444;
  cursor: pointer;
  font-size: 0.8rem;
  align-self: flex-start;
}

.cart-footer {
  padding: 16px 20px 20px;
  border-top: 1px solid var(--border);
}
.cart-total-row {
  display: flex;
  justify-content: space-between;
  font-size: 1.05rem;
  margin-bottom: 14px;
}

/* Checkout modal */
.checkout-modal {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: var(--surface);
  z-index: 31;
  width: min(760px, 94vw);
  max-height: 90vh;
  overflow-y: auto;
  border-radius: var(--radius);
  padding: 30px 30px 36px;
}
#checkoutOverlay { z-index: 30; }

.modal-close {
  position: absolute;
  top: 14px;
  right: 14px;
  font-size: 1.3rem;
}

.checkout-layout {
  display: grid;
  grid-template-columns: 1.3fr 1fr;
  gap: 30px;
  margin-top: 16px;
}

.checkout-form h3 {
  font-size: 0.95rem;
  margin: 18px 0 10px;
  color: var(--text);
}
.checkout-form h3:first-child { margin-top: 0; }

.demo-tag {
  font-size: 0.7rem;
  font-weight: 500;
  color: var(--muted);
  text-transform: none;
}

.form-row { margin-bottom: 12px; }
.form-row-split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.form-row label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.82rem;
  color: var(--muted);
  font-weight: 600;
}

.form-row input {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.95rem;
  outline: none;
  color: var(--text);
}
.form-row input:focus { border-color: var(--primary); }

.order-summary {
  background: #f9f9fc;
  border-radius: var(--radius);
  padding: 18px;
  align-self: start;
}
.order-summary h3 { margin-top: 0; font-size: 0.95rem; }

.summary-items { margin-bottom: 12px; }
.summary-item {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
  padding: 6px 0;
  color: var(--muted);
}

.summary-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.9rem;
  padding: 6px 0;
}
.summary-row.total {
  font-size: 1.1rem;
  font-weight: 800;
  border-top: 1px solid var(--border);
  margin-top: 8px;
  padding-top: 10px;
  color: var(--text);
}

.success-box {
  text-align: center;
  padding: 30px 10px;
}
.success-icon {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: var(--success);
  color: white;
  font-size: 1.8rem;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 16px;
}
.muted { color: var(--muted); font-size: 0.85rem; }

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: white;
  padding: 10px 20px;
  border-radius: 999px;
  font-size: 0.9rem;
  z-index: 40;
  animation: fadeInUp 0.2s ease-out;
}
@keyframes fadeInUp {
  from { opacity: 0; transform: translate(-50%, 10px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

@media (max-width: 640px) {
  .checkout-layout { grid-template-columns: 1fr; }
  .cat-nav { order: 3; width: 100%; }
}
