:root {
  --bg: #f4f7f6;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #0f766e;
  --primary-dark: #0d5f58;
  --danger: #b91c1c;
  --success: #166534;
  --warn: #92400e;
  --radius: 12px;
  --shadow: 0 8px 30px rgba(15, 23, 42, 0.08);
  --bottom-nav-h: 64px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "DM Sans", system-ui, sans-serif;
  color: var(--text);
  background: var(--bg);
  padding-left: var(--safe-left);
  padding-right: var(--safe-right);
}

.hidden { display: none !important; }
.muted { color: var(--muted); }

/* Gate */
.gate {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: calc(24px + var(--safe-top)) 24px calc(24px + var(--safe-bottom));
  background:
    radial-gradient(circle at 10% 10%, rgba(15, 118, 110, 0.12), transparent 40%),
    radial-gradient(circle at 90% 90%, rgba(14, 165, 233, 0.08), transparent 35%),
    var(--bg);
}

.gate-card {
  width: min(420px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) + 4px);
  padding: 28px;
  box-shadow: var(--shadow);
}

.gate-copy { margin: 12px 0 20px; line-height: 1.5; }
.hint { font-size: 0.85rem; color: var(--muted); margin-top: 16px; }

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand strong { display: block; }
.brand small { color: var(--muted); font-size: 0.78rem; }

.brand-mark,
.brand-logo {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  flex-shrink: 0;
  object-fit: cover;
}

.brand-mark {
  background: var(--primary);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 700;
}

.brand-lg .brand-mark,
.brand-lg .brand-logo { width: 48px; height: 48px; }

.brand-lg .brand-mark { font-size: 1.2rem; }

/* App shell — mobile first */
.app {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  max-width: 720px;
  margin: 0 auto;
  background: var(--bg);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: calc(16px + var(--safe-top)) 16px 8px;
  background: rgba(244, 247, 246, 0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}

.topbar h1 {
  margin: 0;
  font-size: 1.25rem;
}

.topbar p { margin: 4px 0 0; font-size: 0.85rem; }

.view-root {
  flex: 1;
  padding: 12px 16px calc(var(--bottom-nav-h) + var(--safe-bottom) + 16px);
}

.pwa-install-hint {
  margin: 0 16px 12px;
  padding: 12px 14px;
  border-radius: var(--radius);
  border: 1px solid #99f6e4;
  background: #f0fdfa;
  color: #115e59;
  font-size: 0.86rem;
  line-height: 1.45;
}

.pwa-install-hint-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 6px;
}

.pwa-install-hint strong {
  font-size: 0.92rem;
}

.pwa-install-hint p {
  margin: 0;
}

.pwa-install-hint .btn-sm {
  flex-shrink: 0;
}

.pwa-shortcut-warning {
  margin: 0 16px 12px;
  padding: 12px 14px;
  border-radius: var(--radius);
  border: 1px solid #fde68a;
  background: #fffbeb;
  color: #92400e;
  font-size: 0.86rem;
  line-height: 1.45;
}

.pwa-shortcut-warning p {
  margin: 6px 0 10px;
}

.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  max-width: 720px;
  margin: 0 auto;
  height: calc(var(--bottom-nav-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  background: var(--surface);
  border-top: 1px solid var(--border);
  box-shadow: 0 -4px 20px rgba(15, 23, 42, 0.06);
}

.bottom-nav-item {
  position: relative;
  border: 0;
  background: transparent;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: 0.72rem;
  color: var(--muted);
  cursor: pointer;
  padding: 8px 4px;
}

.bottom-nav-item.active { color: var(--primary); font-weight: 600; }
.nav-icon { font-size: 1.1rem; line-height: 1; }

.badge {
  position: absolute;
  top: 6px;
  right: calc(50% - 22px);
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--primary);
  color: #fff;
  font-size: 0.65rem;
  font-weight: 700;
  display: grid;
  place-items: center;
}

/* Forms & buttons */
.form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.85rem;
  font-weight: 500;
}

input, textarea, select {
  font: inherit;
  font-size: max(16px, 1rem);
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
}

textarea { resize: vertical; min-height: 64px; }

.checkbox-row {
  flex-direction: row;
  align-items: center;
  gap: 8px;
  font-weight: 400;
}

.btn {
  font: inherit;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 10px 14px;
  cursor: pointer;
  font-weight: 600;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

.btn-primary:hover { background: var(--primary-dark); }

.btn-ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--text);
}

.btn-danger-ghost {
  background: transparent;
  border-color: #fecaca;
  color: var(--danger);
}

.btn-block { width: 100%; }
.btn-sm { padding: 6px 10px; font-size: 0.82rem; }
.btn-icon { width: 40px; height: 40px; padding: 0; font-size: 1.1rem; }

.alert {
  margin: 0 16px 8px;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 0.9rem;
}

.alert.error { background: #fef2f2; color: var(--danger); border: 1px solid #fecaca; }
.alert.success { background: #f0fdf4; color: var(--success); border: 1px solid #bbf7d0; }

.toast {
  position: fixed;
  top: calc(12px + var(--safe-top));
  left: calc(12px + var(--safe-left));
  right: calc(12px + var(--safe-right));
  z-index: 9999;
  padding: 12px 14px;
  border-radius: 10px;
  font-size: 0.92rem;
  box-shadow: var(--shadow);
}

.toast.error { background: #fef2f2; color: var(--danger); border: 1px solid #fecaca; }
.toast.success { background: #f0fdf4; color: var(--success); border: 1px solid #bbf7d0; }

.btn:disabled {
  opacity: 0.65;
  cursor: wait;
}

.info-banner {
  padding: 10px 12px;
  border-radius: 10px;
  background: #fffbeb;
  color: var(--warn);
  border: 1px solid #fde68a;
  font-size: 0.88rem;
  margin-bottom: 12px;
}

/* Catalog */
.search-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
  align-items: center;
}

.category-menu-btn {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  font-size: 1.25rem;
  padding: 0;
}

.search-bar input {
  flex: 1;
}

.catalog-main {
  position: relative;
  min-height: 120px;
}

.category-panel {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: grid;
  grid-template-columns: min(260px, 82vw) 1fr;
}

.category-panel.hidden {
  display: none;
}

.category-drawer {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: calc(12px + var(--safe-top)) 16px calc(12px + var(--safe-bottom));
  overflow-y: auto;
  box-shadow: 4px 0 24px rgba(15, 23, 42, 0.08);
}

.category-drawer-title {
  margin: 0 0 10px;
  font-size: 0.95rem;
}

.category-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.category-item {
  width: 100%;
  text-align: left;
  padding: 10px 12px;
  border: none;
  border-radius: 10px;
  background: #f8fafc;
  color: var(--text);
  font: inherit;
  font-size: 0.92rem;
  cursor: pointer;
}

.category-item:hover {
  background: #f1f5f9;
}

.category-item.active {
  background: var(--primary);
  color: #fff;
  font-weight: 600;
}

.category-backdrop {
  border: none;
  background: rgba(15, 23, 42, 0.4);
  cursor: pointer;
  padding: 0;
}

.catalog-stats {
  font-size: 0.82rem;
  margin-bottom: 10px;
}

.product-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.product-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  text-align: left;
}

.product-card h3 {
  margin: 0 0 4px;
  font-size: 0.98rem;
}

.product-meta { margin: 0; font-size: 0.82rem; }

.price-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 6px;
  align-items: baseline;
}

.price-sale { font-weight: 700; color: var(--primary-dark); }
.price-wholesale { font-size: 0.82rem; color: var(--muted); }

.stock-pill {
  font-size: 0.72rem;
  font-weight: 600;
  padding: 4px 8px;
  border-radius: 999px;
  white-space: nowrap;
}

.stock-ok { background: #dcfce7; color: var(--success); }
.stock-low { background: #fef3c7; color: var(--warn); }
.stock-out { background: #fee2e2; color: var(--danger); }

.empty-inline, .empty-state {
  text-align: center;
  padding: 32px 16px;
  color: var(--muted);
}

/* Cart */
.cart-list { display: flex; flex-direction: column; gap: 10px; }

.cart-line {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.cart-line-actions {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
}

.qty-input { width: 72px; text-align: center; }

.cart-footer {
  margin-top: 16px;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.cart-total {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 1.05rem;
}

/* Orders */
.orders-list { display: flex; flex-direction: column; gap: 10px; }

.order-card {
  width: 100%;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  text-align: left;
  font: inherit;
}

.order-card-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
}

.status-pill {
  font-size: 0.72rem;
  font-weight: 600;
  padding: 4px 8px;
  border-radius: 999px;
  background: #ecfeff;
  color: var(--primary-dark);
}

/* Account */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
}

.panel h2 {
  margin: 0 0 12px;
  font-size: 1rem;
}

.profile-dl {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px 16px;
  margin: 0;
  font-size: 0.9rem;
}

.profile-dl dt { color: var(--muted); }
.profile-dl dd { margin: 0; }

/* Dialogs */
.dialog {
  border: 0;
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 0;
  width: min(720px, 100%);
  max-height: 90vh;
  margin: auto auto 0;
}

.dialog::backdrop {
  background: rgba(15, 23, 42, 0.45);
}

.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(16px + var(--safe-top)) 16px 16px;
  border-bottom: 1px solid var(--border);
}

.sheet-head h2 { margin: 0; font-size: 1.05rem; }

.sheet-body {
  padding: 16px calc(16px + var(--safe-right)) calc(16px + var(--safe-bottom)) calc(16px + var(--safe-left));
  overflow: auto;
  max-height: calc(90vh - 60px - var(--safe-top));
}

.product-image {
  width: 100%;
  max-height: 220px;
  object-fit: contain;
  border-radius: 10px;
  margin-bottom: 12px;
  background: #f8fafc;
}

.product-desc {
  margin: 12px 0 0;
  line-height: 1.5;
  font-size: 0.92rem;
}

.qty-row {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  margin-top: 16px;
}

.qty-row label { flex: 1; }

.section-title {
  margin: 16px 0 8px;
  font-size: 0.95rem;
}

.order-lines { display: flex; flex-direction: column; gap: 10px; }

.order-line {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

@media (min-width: 721px) {
  .dialog {
    border-radius: var(--radius);
    margin: auto;
  }
}
