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

:root {
  --bg: #f7f8fa;
  --surface: #ffffff;
  --primary: #16a34a;
  --primary-dark: #15803d;
  --text: #1e293b;
  --text-muted: #64748b;
  --border: #e5e7eb;
  --danger: #ef4444;
  --radius: 12px;
}

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

/* ══════════════════════════════════════
   HEADER
══════════════════════════════════════ */
.header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
}
.header-inner {
  max-width: 960px;
  margin: 0 auto;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.menu-btn {
  background: none;
  border: none;
  font-size: 22px;
  cursor: pointer;
  padding: 4px 6px;
  color: var(--text);
  line-height: 1;
  flex-shrink: 0;
}
.header-brand {
  display: flex;
  align-items: center;
  gap: 7px;
  flex: 1;
}
.header-logo { font-size: 22px; }
.header-title { font-size: 16px; font-weight: 700; }

.cart-btn-header {
  display: flex;
  align-items: center;
  gap: 5px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 16px;
  cursor: pointer;
  flex-shrink: 0;
}
.cart-count {
  background: rgba(255,255,255,0.3);
  border-radius: 20px;
  padding: 1px 7px;
  font-size: 13px;
  font-weight: 600;
}

/* ══════════════════════════════════════
   SEARCH
══════════════════════════════════════ */
.search-section {
  max-width: 960px;
  margin: 0 auto;
  padding: 10px 14px 4px;
}
.search-bar input {
  width: 100%;
  padding: 11px 14px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  font-size: 15px;
  background: var(--surface);
  outline: none;
  transition: border-color 0.15s;
}
.search-bar input:focus { border-color: var(--primary); }

/* ══════════════════════════════════════
   CURRENT CATEGORY LABEL
══════════════════════════════════════ */
.current-cat-bar {
  max-width: 960px;
  margin: 0 auto;
  padding: 0 14px 8px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.current-cat-label {
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 5px;
}
.current-cat-label .cat-name {
  font-size: 12px;
  font-weight: 600;
  color: var(--primary);
  background: rgba(22,163,74,0.1);
  padding: 2px 8px;
  border-radius: 20px;
}
.clear-cat {
  background: none;
  border: none;
  font-size: 14px;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0 2px;
  line-height: 1;
}
.clear-cat:hover { color: var(--danger); }

/* ══════════════════════════════════════
   CATEGORIES (desktop horizontal strip)
══════════════════════════════════════ */
.categories {
  max-width: 960px;
  margin: 0 auto;
  padding: 6px 14px 12px;
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.cat-btn {
  padding: 6px 14px;
  border: 1.5px solid var(--border);
  border-radius: 20px;
  background: var(--surface);
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}
.cat-btn:hover { border-color: var(--primary); color: var(--primary); }
.cat-btn.active { background: var(--primary); border-color: var(--primary); color: #fff; }

/* Hide categories on mobile — they are in the drawer */
@media (max-width: 640px) { .categories { display: none; } }

/* ══════════════════════════════════════
   PRODUCT LIST
══════════════════════════════════════ */
.product-list {
  max-width: 960px;
  margin: 0 auto;
  padding: 6px 14px 100px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 10px;
}
.product-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 0;
}
.product-name {
  font-size: 13px;
  font-weight: 600;
  line-height: 1.35;
  color: var(--text);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  flex: 0 0 auto;
}
.product-meta {
  font-size: 11px;
  color: var(--text-muted);
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  flex: 0 0 auto;
}
.product-meta span {
  background: var(--bg);
  padding: 1px 6px;
  border-radius: 3px;
}
.product-meta .cat-badge {
  background: rgba(22,163,74,0.1);
  color: var(--primary-dark);
  font-weight: 500;
}
.product-bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  margin-top: auto;
  padding-top: 4px;
}
.product-price { font-size: 17px; font-weight: 700; color: var(--primary-dark); }
.product-unit { font-size: 12px; color: var(--text-muted); }
.add-btn {
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 8px 16px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.12s, transform 0.1s;
  white-space: nowrap;
}
.add-btn:hover { background: var(--primary-dark); }
.add-btn:active { transform: scale(0.96); }

/* ══════════════════════════════════════
   EMPTY STATE
══════════════════════════════════════ */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}
.empty-icon { font-size: 44px; margin-bottom: 10px; }
.empty-state p { font-size: 15px; }

/* ══════════════════════════════════════
   LOADING / ERROR STATES
══════════════════════════════════════ */
.catalog-loading, .catalog-error {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  gap: 14px;
  color: var(--text-muted);
  font-size: 14px;
}
.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); } }

/* ══════════════════════════════════════
   FLOATING CART BUTTON
══════════════════════════════════════ */
.floating-cart-btn {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 90;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 50%;
  width: 56px;
  height: 56px;
  font-size: 22px;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(22,163,74,0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, transform 0.15s;
}
.floating-cart-btn:hover { background: var(--primary-dark); transform: scale(1.05); }
.floating-badge {
  position: absolute;
  top: -3px;
  right: -3px;
  background: #ef4444;
  color: #fff;
  border-radius: 20px;
  width: 20px;
  height: 20px;
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--bg);
}
@media (min-width: 641px) { .floating-cart-btn { display: none; } }

/* ══════════════════════════════════════
   CATEGORY DRAWER (mobile)
══════════════════════════════════════ */
.cat-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 150;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}
.cat-overlay.open { opacity: 1; pointer-events: all; }

.cat-drawer {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: min(280px, 82vw);
  background: var(--surface);
  z-index: 151;
  display: flex;
  flex-direction: column;
  transform: translateX(-100%);
  transition: transform 0.28s cubic-bezier(0.32, 0.72, 0, 1);
  box-shadow: 4px 0 20px rgba(0,0,0,0.12);
}
.cat-drawer.open { transform: translateX(0); }

.cat-drawer-handle {
  width: 36px;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin: 10px auto 0;
  flex-shrink: 0;
}
.cat-drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 15px;
  font-weight: 700;
  flex-shrink: 0;
}
.cat-close {
  background: var(--bg);
  border: none;
  font-size: 15px;
  cursor: pointer;
  color: var(--text-muted);
  padding: 4px 8px;
  border-radius: 6px;
}
.cat-list {
  flex: 1;
  overflow-y: auto;
  padding: 6px 0;
}
.cat-item {
  padding: 12px 16px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  cursor: pointer;
  background: none;
  border: none;
  width: 100%;
  text-align: left;
  transition: background 0.1s;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.cat-item:hover { background: var(--bg); }
.cat-item.active { color: var(--primary); font-weight: 700; }
.cat-item.active::after { content: '✓'; font-size: 12px; }
.cat-item-all {
  font-weight: 700;
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
  padding-bottom: 12px;
}

/* ══════════════════════════════════════
   CART DRAWER
══════════════════════════════════════ */
.cart-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}
.cart-overlay.open { opacity: 1; pointer-events: all; }

.cart-drawer {
  position: fixed;
  right: 0; bottom: 0;
  width: min(400px, 100vw);
  height: 100dvh;
  background: var(--surface);
  z-index: 201;
  border-radius: 20px 20px 0 0;
  display: flex;
  flex-direction: column;
  transform: translateY(100%);
  transition: transform 0.28s cubic-bezier(0.32, 0.72, 0, 1);
  box-shadow: 0 -4px 24px rgba(0,0,0,0.12);
  overflow: hidden;
}
.cart-drawer.open { transform: translateY(0); }

@media (min-width: 641px) {
  .cart-drawer {
    top: 0; bottom: 0;
    height: 100vh;
    border-radius: 0;
    transform: translateX(100%);
  }
  .cart-drawer.open { transform: translateX(0); }
}

.cart-handle {
  width: 36px;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin: 10px auto 0;
  flex-shrink: 0;
}
@media (min-width: 641px) { .cart-handle { display: none; } }

.cart-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px 10px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.cart-header h2 { font-size: 17px; font-weight: 700; }
.cart-close {
  background: var(--bg);
  border: none;
  font-size: 15px;
  cursor: pointer;
  color: var(--text-muted);
  padding: 4px 8px;
  border-radius: 6px;
}

.cart-items {
  flex: 1;
  overflow-y: auto;
  padding: 10px 18px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.cart-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--text-muted);
  font-size: 14px;
  padding: 40px;
}
.cart-empty-icon { font-size: 44px; }

.cart-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 11px 0;
  border-bottom: 1px solid var(--border);
}
.cart-item:last-child { border-bottom: none; }
.cart-item-info { flex: 1; min-width: 0; }
.cart-item-name {
  font-size: 13px;
  font-weight: 600;
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cart-item-price { font-size: 11px; color: var(--text-muted); margin-top: 1px; display: flex; align-items: center; gap: 4px; }
.cart-item-unit { background: var(--bg); padding: 1px 5px; border-radius: 3px; font-size: 10px; }
.cart-item-total { font-size: 14px; font-weight: 700; color: var(--primary-dark); white-space: nowrap; }
.cart-qty { display: flex; align-items: center; gap: 5px; flex-shrink: 0; }
.qty-btn {
  width: 30px; height: 30px;
  border: 1.5px solid var(--border);
  border-radius: 7px;
  background: var(--bg);
  font-size: 15px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.qty-btn:hover { border-color: var(--primary); }
.qty-num { font-size: 14px; font-weight: 600; min-width: 22px; text-align: center; }
.cart-item-remove {
  background: none; border: none;
  color: var(--danger); font-size: 14px;
  cursor: pointer; padding: 4px;
  opacity: 0.7; flex-shrink: 0;
}
.cart-item-remove:hover { opacity: 1; }

.cart-footer {
  padding: 10px 16px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex-shrink: 0;
}
.cart-total {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 15px;
  font-weight: 600;
  padding: 2px 0;
}
.cart-total strong { color: var(--primary-dark); font-size: 19px; }

.order-form { display: flex; flex-direction: column; gap: 7px; }
.order-form input, .order-form textarea {
  padding: 10px 12px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  background: var(--bg);
  outline: none;
  transition: border-color 0.15s;
  width: 100%;
}
.order-form input:focus, .order-form textarea:focus { border-color: var(--primary); }

.submit-btn {
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 9px;
  padding: 12px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s;
  width: 100%;
}
.submit-btn:hover { background: var(--primary-dark); }
.submit-btn:disabled { opacity: 0.6; cursor: not-allowed; }

.order-success {
  background: #dcfce7;
  border: 1px solid #86efac;
  border-radius: 8px;
  padding: 12px;
  text-align: center;
  font-size: 14px;
  font-weight: 600;
  color: var(--primary-dark);
}

/* ══════════════════════════════════════
   MOBILE (max 640px)
══════════════════════════════════════ */
@media (max-width: 640px) {
  .header-inner { padding: 9px 12px; }
  .header-title { font-size: 15px; }
  .search-section { padding: 8px 12px 4px; }
  .product-list {
    grid-template-columns: 1fr;
    padding: 4px 12px 90px;
    gap: 8px;
  }
  .product-card { padding: 12px; }
  .product-name { font-size: 13px; }
  .floating-cart-btn { bottom: 16px; right: 16px; }
}

/* ══════════════════════════════════════
   LARGE DESKTOP
══════════════════════════════════════ */
@media (min-width: 1200px) {
  .product-list { grid-template-columns: repeat(4, 1fr); }
}
