:root {
  --bg: #f7f7f7;
  --bg-elevated: #ffffff;
  --text: #333333;
  --muted: #6c757d;
  --accent: #229ac8;
  --accent-hover: #1a7fa8;
  --accent-soft: #e8f4fa;
  --border: #dddddd;
  --sidebar-bg: #ffffff;
  --sidebar-border: #e5e5e5;
  --danger: #dc3545;
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  --radius: 4px;
  --header-h: 56px;
  --sidebar-w: 260px;
  --nav-h: 56px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: "Open Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100dvh;
}

body.sidebar-open {
  overflow: hidden;
}

a {
  color: var(--accent);
}

img {
  max-width: 100%;
  display: block;
}

/* Header — OpenCart style */
.site-header {
  position: sticky;
  top: 0;
  z-index: 40;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
}

.site-header__inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0.4rem 0.65rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-height: var(--header-h);
}

.header-icon-btn {
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-elevated);
  cursor: pointer;
  display: grid;
  place-items: center;
  padding: 0;
}

.header-icon-btn__bars {
  display: block;
  width: 18px;
  height: 2px;
  background: var(--text);
  box-shadow: 0 -6px 0 var(--text), 0 6px 0 var(--text);
}

@media (min-width: 992px) {
  .header-icon-btn {
    display: none;
  }
}

.site-logo {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  text-decoration: none;
  color: var(--text);
  min-width: 0;
  flex-shrink: 0;
}

.site-logo__mark {
  width: 34px;
  height: 34px;
  border-radius: var(--radius);
  background: var(--accent);
  color: #fff;
  font-size: 0.65rem;
  font-weight: 800;
  display: grid;
  place-items: center;
}

.site-logo__text {
  font-weight: 700;
  font-size: 0.95rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 120px;
}

@media (min-width: 480px) {
  .site-logo__text {
    max-width: 200px;
  }
}

.header-search {
  flex: 1 1 auto;
  display: flex;
  min-width: 0;
  max-width: 520px;
  margin: 0 auto;
}

.header-search__input {
  flex: 1;
  min-width: 0;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-right: none;
  border-radius: var(--radius) 0 0 var(--radius);
  font-size: 0.9rem;
  background: #fff;
}

.header-search__input:focus {
  outline: none;
  border-color: var(--accent);
}

.header-search__btn {
  flex: 0 0 auto;
  padding: 0 0.85rem;
  border: 1px solid var(--accent);
  border-radius: 0 var(--radius) var(--radius) 0;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  font-size: 1rem;
}

.header-search__btn:hover {
  background: var(--accent-hover);
}

.site-header__actions {
  display: flex;
  gap: 0.35rem;
  flex-shrink: 0;
}

.header-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.4rem 0.55rem;
  border-radius: var(--radius);
  text-decoration: none;
  color: var(--text);
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  font-size: 0.8rem;
  position: relative;
}

.header-btn__icon {
  font-size: 1.05rem;
}

.header-btn__label {
  display: none;
}

@media (min-width: 768px) {
  .header-btn__label {
    display: inline;
  }
}

.cart-pill {
  position: absolute;
  top: -5px;
  right: -5px;
  min-width: 17px;
  height: 17px;
  padding: 0 4px;
  border-radius: 999px;
  background: #f56b2a;
  color: #fff;
  font-size: 0.65rem;
  font-weight: 700;
  display: grid;
  place-items: center;
}

/* Shell: sidebar + content */
.store-shell {
  max-width: 1400px;
  margin: 0 auto;
  display: flex;
  align-items: flex-start;
  min-height: calc(100dvh - var(--header-h));
}

.store-shell--no-sidebar .category-sidebar,
.store-shell--no-sidebar .sidebar-backdrop {
  display: none !important;
}

.store-content {
  flex: 1;
  min-width: 0;
  width: 100%;
}

.sidebar-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 45;
}

.sidebar-backdrop[hidden] {
  display: none !important;
}

.category-sidebar {
  flex: 0 0 var(--sidebar-w);
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  border-right: 1px solid var(--sidebar-border);
  position: sticky;
  top: var(--header-h);
  align-self: flex-start;
  max-height: calc(100dvh - var(--header-h));
  overflow: hidden;
  display: flex;
  flex-direction: column;
  z-index: 50;
}

.category-sidebar__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--sidebar-border);
  background: #f8f8f8;
}

.category-sidebar__title {
  font-weight: 700;
  font-size: 0.95rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: #555;
}

.sidebar-close {
  width: 32px;
  height: 32px;
  border: none;
  background: transparent;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  color: var(--muted);
}

@media (min-width: 992px) {
  .sidebar-close {
    display: none;
  }
}

.category-sidebar__nav {
  overflow-y: auto;
  padding: 0.35rem 0 1rem;
  -webkit-overflow-scrolling: touch;
}

.sidebar-loading {
  padding: 1rem;
  margin: 0;
}

/* Category tree — OpenCart-like */
.side-cat-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.side-cat-list--child {
  display: none;
  background: #fafafa;
  border-top: 1px solid #eee;
}

.side-cat-item.is-expanded > .side-cat-list--child {
  display: block;
}

.side-cat-item.is-active > .side-cat-row > .side-cat-link {
  color: var(--accent);
  font-weight: 700;
}

.side-cat-row {
  display: flex;
  align-items: stretch;
  border-bottom: 1px solid #f0f0f0;
}

.side-cat-link {
  flex: 1;
  display: block;
  padding: 0.55rem 0.75rem;
  text-decoration: none;
  color: var(--text);
  font-size: 0.875rem;
  line-height: 1.35;
  min-width: 0;
}

.side-cat-link:hover {
  background: var(--accent-soft);
  color: var(--accent);
}

.side-cat-count {
  flex: 0 0 auto;
  align-self: center;
  font-size: 0.72rem;
  color: var(--muted);
  padding-right: 0.25rem;
}

.side-cat-toggle {
  flex: 0 0 auto;
  width: 36px;
  border: none;
  border-left: 1px solid #f0f0f0;
  background: transparent;
  cursor: pointer;
  color: var(--muted);
  font-size: 0.85rem;
  transition: transform 0.15s;
}

.side-cat-item.is-expanded > .side-cat-row .side-cat-toggle {
  transform: rotate(90deg);
}

.side-cat-toggle[hidden] {
  display: none;
}

.side-cat-all .side-cat-link {
  font-weight: 600;
}

/* Mobile drawer */
@media (max-width: 991px) {
  .category-sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    max-height: none;
    height: 100dvh;
    width: min(88vw, var(--sidebar-w));
    transform: translateX(-105%);
    transition: transform 0.22s ease;
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.15);
  }

  .category-sidebar__head {
    padding-top: calc(0.5rem + env(safe-area-inset-top, 0px));
  }

  body.sidebar-open .category-sidebar {
    transform: translateX(0);
  }
}

@media (min-width: 992px) {
  .sidebar-backdrop {
    display: none !important;
  }
}

/* Main content */
.page-main {
  padding: 1rem;
  padding-bottom: calc(1rem + var(--nav-h) + var(--safe-bottom));
}

@media (min-width: 992px) {
  .page-main {
    padding: 1.25rem 1.5rem 2rem;
    padding-bottom: 2rem;
  }

  .mobile-nav {
    display: none;
  }
}

.site-footer {
  border-top: 1px solid var(--border);
  background: var(--bg-elevated);
  margin-bottom: calc(var(--nav-h) + var(--safe-bottom));
}

@media (min-width: 992px) {
  .site-footer {
    margin-bottom: 0;
  }
}

.site-footer__inner {
  padding: 1rem 1.5rem;
  font-size: 0.9rem;
}

.site-footer__name {
  font-weight: 700;
  margin: 0 0 0.35rem;
}

.site-footer__line {
  margin: 0.2rem 0;
}

/* Mobile bottom nav */
.mobile-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 35;
  display: flex;
  flex-wrap: nowrap;
  background: var(--bg-elevated);
  border-top: 1px solid var(--border);
  padding-bottom: var(--safe-bottom);
}

.mobile-nav__item {
  flex: 1 1 0;
  min-width: 64px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.1rem;
  padding: 0.4rem 0.25rem;
  text-decoration: none;
  color: var(--muted);
  font-size: 0.65rem;
  position: relative;
  border: none;
  background: transparent;
  font-family: inherit;
  cursor: pointer;
}

.mobile-nav__item.is-active {
  color: var(--accent);
}

.mobile-nav__icon {
  font-size: 1.15rem;
}

.mobile-nav__badge {
  position: absolute;
  top: 2px;
  left: 55%;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 999px;
  background: #f56b2a;
  color: #fff;
  font-size: 0.62rem;
  font-weight: 700;
  display: grid;
  place-items: center;
}

/* Breadcrumbs */
.breadcrumb {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem;
  margin: 0 0 1rem;
  padding: 0;
  list-style: none;
  font-size: 0.82rem;
  color: var(--muted);
}

.breadcrumb a {
  color: var(--muted);
  text-decoration: none;
}

.breadcrumb a:hover {
  color: var(--accent);
}

.breadcrumb__sep {
  opacity: 0.5;
}

.breadcrumb__current {
  color: var(--text);
}

.catalog-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 1rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
}

.catalog-toolbar h1 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 400;
}

.catalog-status {
  font-size: 0.85rem;
  color: var(--muted);
}

.page-title {
  margin: 0 0 1rem;
  font-size: clamp(1.2rem, 4vw, 1.6rem);
  font-weight: 400;
}

.page-lead {
  margin: -0.5rem 0 1rem;
  color: var(--muted);
  font-size: 0.95rem;
}

.muted {
  color: var(--muted);
  font-size: 0.875rem;
}

.error {
  color: var(--danger);
  font-size: 0.9rem;
}

.store-hero-compact {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.85rem 1rem;
  margin-bottom: 1rem;
  font-size: 0.9rem;
}

.store-hero-compact a {
  font-weight: 600;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  padding: 0.55rem 1rem;
  border-radius: var(--radius);
  border: none;
  background: var(--accent);
  color: #fff;
  text-decoration: none;
  cursor: pointer;
  font-size: 0.95rem;
  font-weight: 600;
  transition: background 0.15s;
}

.btn:hover {
  background: var(--accent-hover);
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-ghost {
  background: var(--bg-elevated);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-ghost:hover {
  background: #f0f0f0;
}

.btn-block {
  width: 100%;
}

.btn-sm {
  padding: 0.35rem 0.65rem;
  font-size: 0.85rem;
}

.card {
  background: var(--bg-elevated);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 0.75rem;
  border: 1px solid var(--border);
}

.card--flat {
  box-shadow: none;
}

.catalog-grid {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

@media (min-width: 600px) {
  .catalog-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (min-width: 1100px) {
  .catalog-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

.product-card {
  display: flex;
  flex-direction: column;
  padding: 0;
  overflow: hidden;
  cursor: pointer;
  transition: box-shadow 0.15s;
  text-decoration: none;
  color: inherit;
  border-radius: var(--radius);
}

.product-card:hover {
  box-shadow: var(--shadow);
}

.product-card__media {
  aspect-ratio: 1;
  background: #fff;
  border-bottom: 1px solid var(--border);
  display: grid;
  place-items: center;
  overflow: hidden;
}

.product-card__media img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  padding: 0.35rem;
}

.product-card__placeholder {
  font-size: 2rem;
  opacity: 0.3;
}

.product-card__body {
  padding: 0.6rem 0.65rem 0.7rem;
  display: flex;
  flex-direction: column;
  flex: 1;
  gap: 0.2rem;
  background: #fff;
}

.product-card__name {
  margin: 0;
  font-size: 0.82rem;
  font-weight: 400;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  min-height: 3.2em;
}

.product-card__price {
  font-weight: 700;
  color: var(--text);
  font-size: 1.05rem;
  margin-top: auto;
}

.product-card__stock {
  font-size: 0.72rem;
  color: var(--muted);
}

.stock-ok {
  color: #28a745;
}

.stock-low {
  color: #e67e22;
}

.product-page {
  display: grid;
  gap: 1rem;
}

@media (min-width: 768px) {
  .product-page {
    grid-template-columns: 1fr 1fr;
    align-items: start;
  }
}

.product-gallery {
  background: #fff;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  overflow: hidden;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
}

.product-gallery img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  padding: 0.5rem;
}

.product-detail h1 {
  margin: 0 0 0.5rem;
  font-size: 1.2rem;
  font-weight: 400;
  line-height: 1.3;
}

.product-detail__price {
  font-size: 1.65rem;
  font-weight: 700;
  color: var(--text);
  margin: 0 0 0.75rem;
}

.qty-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 1rem 0;
}

.qty-row__ctrl {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: #fff;
}

.qty-row__btn {
  width: 38px;
  height: 38px;
  border: none;
  background: #f5f5f5;
  font-size: 1.2rem;
  cursor: pointer;
  color: var(--text);
}

.qty-row__val {
  min-width: 36px;
  text-align: center;
  font-weight: 700;
}

.cart-line {
  display: grid;
  grid-template-columns: 72px 1fr auto;
  gap: 0.75rem;
  align-items: center;
}

.cart-line__thumb {
  width: 72px;
  height: 72px;
  border-radius: var(--radius);
  overflow: hidden;
  background: #fff;
  border: 1px solid var(--border);
  display: grid;
  place-items: center;
}

.cart-line__thumb img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.cart-line__title {
  font-weight: 600;
  font-size: 0.9rem;
  margin: 0 0 0.25rem;
}

.cart-summary {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 1rem 0 0.5rem;
  font-size: 1.1rem;
  border-top: 1px solid var(--border);
  margin-top: 0.5rem;
}

.cart-summary strong {
  font-size: 1.35rem;
}

.form label {
  display: block;
  margin: 0.75rem 0 0.25rem;
  font-size: 0.875rem;
  font-weight: 600;
}

.form input,
.form textarea {
  width: 100%;
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 1rem;
  font-family: inherit;
  background: #fff;
}

.form input:focus,
.form textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft);
}

.auth-wrap {
  max-width: 440px;
  margin: 0 auto;
}

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  margin-bottom: 0.75rem;
  text-decoration: none;
  font-size: 0.9rem;
  color: var(--muted);
}

.back-link:hover {
  color: var(--accent);
}

.load-more-wrap {
  text-align: center;
  margin: 1.5rem 0;
}

.empty-state {
  text-align: center;
  padding: 2.5rem 1rem;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.empty-state__icon {
  font-size: 2.5rem;
  margin-bottom: 0.5rem;
}

.success-card {
  text-align: center;
  padding: 1.5rem 1rem;
}

.success-card__icon {
  font-size: 2.5rem;
  margin-bottom: 0.5rem;
}

.skeleton {
  background: linear-gradient(90deg, #eee 25%, #f5f5f5 50%, #eee 75%);
  background-size: 200% 100%;
  animation: shimmer 1.2s infinite;
  border-radius: var(--radius);
  min-height: 180px;
}

@keyframes shimmer {
  0% {
    background-position: 200% 0;
  }
  100% {
    background-position: -200% 0;
  }
}
