:root {
  --primary: #0f766e;
  --primary-dark: #0b5c56;
  --bg: #f7f7f5;
  --card-bg: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --danger: #dc2626;
  --whatsapp: #25d366;
  --radius: 14px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  padding-bottom: calc(70px + var(--safe-bottom));
}

.topbar {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: white;
  padding: 20px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar-inner h1 { margin: 0; font-size: 1.3rem; }
.tagline { margin: 4px 0 0; font-size: 0.85rem; opacity: 0.9; }

.cart-btn {
  background: rgba(255,255,255,0.2);
  border: none;
  color: white;
  font-size: 1.2rem;
  padding: 8px 12px;
  border-radius: 999px;
  position: relative;
  cursor: pointer;
}
.cart-count {
  background: var(--danger);
  color: white;
  font-size: 0.7rem;
  border-radius: 999px;
  padding: 1px 6px;
  position: absolute;
  top: -4px;
  right: -4px;
}

main { padding: 12px 16px; max-width: 720px; margin: 0 auto; }

.search-row { margin-bottom: 12px; }
.search-row input {
  width: 100%;
  padding: 12px 14px;
  border-radius: var(--radius);
  border: 1px solid #e5e7eb;
  font-size: 1rem;
  background: white;
}

.category-tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 8px;
  margin-bottom: 8px;
}
.category-tab {
  flex-shrink: 0;
  padding: 6px 14px;
  border-radius: 999px;
  border: 1px solid #e5e7eb;
  background: white;
  font-size: 0.85rem;
  cursor: pointer;
  color: var(--text);
}
.category-tab.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

.product-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
@media (min-width: 480px) {
  .product-grid { grid-template-columns: 1fr 1fr; }
}

.product-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
  display: flex;
  flex-direction: column;
}
.product-img {
  width: 100%;
  aspect-ratio: 1;
  background: #e5e7eb center/cover no-repeat;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  color: #9ca3af;
}
.product-info { padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 4px; flex: 1; }
.product-name { font-size: 0.92rem; font-weight: 600; margin: 0; line-height: 1.3; }
.product-price { color: var(--primary); font-weight: 700; font-size: 0.95rem; }
.product-desc { font-size: 0.78rem; color: var(--muted); margin: 0; flex: 1; }

.add-btn {
  margin-top: 6px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 0.85rem;
  cursor: pointer;
}
.add-btn:active { background: var(--primary-dark); }

.qty-control {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 6px;
  background: var(--primary);
  border-radius: 10px;
  overflow: hidden;
}
.qty-control button {
  background: transparent;
  border: none;
  color: white;
  font-size: 1rem;
  padding: 6px 12px;
  cursor: pointer;
}
.qty-control span { color: white; font-weight: 600; }

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 20;
}
.hidden { display: none !important; }

.drawer {
  position: fixed;
  right: 0;
  top: 0;
  bottom: 0;
  width: min(400px, 90vw);
  background: white;
  z-index: 21;
  display: flex;
  flex-direction: column;
  box-shadow: -4px 0 12px rgba(0,0,0,0.15);
}
.drawer-header, .modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px;
  border-bottom: 1px solid #eee;
}
.drawer-header h2, .modal-header h2 { margin: 0; font-size: 1.1rem; }
.icon-btn {
  background: none;
  border: none;
  font-size: 1.2rem;
  cursor: pointer;
  color: var(--muted);
}

.cart-items { flex: 1; overflow-y: auto; padding: 12px 16px; }
.cart-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid #f0f0f0;
}
.cart-item-info { flex: 1; }
.cart-item-name { font-weight: 600; font-size: 0.9rem; margin: 0; }
.cart-item-price { color: var(--muted); font-size: 0.8rem; margin: 2px 0 0; }
.cart-empty { text-align: center; color: var(--muted); padding: 40px 0; }

.cart-footer {
  padding: 16px;
  border-top: 1px solid #eee;
  padding-bottom: calc(16px + var(--safe-bottom));
}
.cart-total {
  display: flex;
  justify-content: space-between;
  margin-bottom: 12px;
  font-size: 1.05rem;
}

.btn-primary {
  width: 100%;
  background: var(--primary);
  color: white;
  border: none;
  padding: 14px;
  border-radius: 12px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
}
.btn-primary:disabled { background: #a7a7a7; cursor: not-allowed; }
.btn-secondary {
  width: 100%;
  background: #f3f4f6;
  color: var(--text);
  border: none;
  padding: 14px;
  border-radius: 12px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  margin-top: 8px;
}
.btn-whatsapp {
  width: 100%;
  background: var(--whatsapp);
  color: white;
  border: none;
  padding: 14px;
  border-radius: 12px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  margin-top: 8px;
}

.modal {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  background: white;
  width: min(420px, 92vw);
  max-height: 88vh;
  overflow-y: auto;
  border-radius: 16px;
  z-index: 31;
}
.modal-body { padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.modal-body label {
  font-size: 0.85rem;
  color: var(--text);
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.modal-body input, .modal-body textarea {
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid #e5e7eb;
  font-size: 0.95rem;
  font-family: inherit;
}
.error-text { color: var(--danger); font-size: 0.85rem; }

.success-body { text-align: center; }
.success-icon { font-size: 3rem; }

.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: white;
  border-top: 1px solid #eee;
  display: flex;
  padding-bottom: var(--safe-bottom);
  z-index: 5;
}
.nav-item {
  flex: 1;
  background: none;
  border: none;
  padding: 10px 0;
  font-size: 0.75rem;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  cursor: pointer;
}
.nav-item.active { color: var(--primary); }
