:root {
  --bg: #e8f6f5;
  --panel: #ffffff;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #dbe8ea;
  --brand: #08756f;
  --brand-dark: #064e4a;
  --brand-2: #0f988d;
  --wa: #25d366;
  --soft: #e8f6f4;
  --shadow: 0 16px 38px rgba(15, 23, 42, .10);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  font-family: "Inter", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 15% 0%, rgba(15, 152, 141, .18), transparent 28%),
    linear-gradient(180deg, #e8f6f5 0%, #d6eeee 100%);
}

.site-header {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 12px clamp(14px, 3vw, 34px);
  background: rgba(255, 255, 255, .92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--brand-dark), var(--brand-2));
  color: white;
  font-weight: 900;
  letter-spacing: .04em;
}

.brand h1 {
  margin: 0;
  font-size: 19px;
}

.brand p {
  margin: 1px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 9px;
}

.ghost-btn,
.wa-small,
.primary-btn,
.danger-btn {
  border: 0;
  border-radius: 999px;
  padding: 10px 15px;
  font-weight: 800;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}

.ghost-btn {
  color: var(--brand);
  background: var(--soft);
}

#instagramHeader {
  background: linear-gradient(45deg, #f09433, #e6683c, #dc2743, #cc2366, #bc1888);
  color: white;
}

.wa-small,
.primary-btn {
  color: white;
  background: var(--wa);
}

.danger-btn {
  color: #991b1b;
  background: #fee2e2;
}

/* Banner más chico y menos pesado */
.hero {
  max-width: 1380px;
  margin: 18px auto 0;
  padding: 0 18px;
}

.hero > div {
  min-height: 235px;
  border-radius: 26px;
  padding: clamp(24px, 4vw, 42px);
  background:
    radial-gradient(circle at 88% 18%, rgba(255, 255, 255, .16), transparent 26%),
    linear-gradient(135deg, #064e4a 0%, #0f766e 58%, #10856f 100%);
  color: white;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.pill {
  display: inline-block;
  width: fit-content;
  padding: 7px 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .16);
  font-weight: 800;
  font-size: 13px;
}

.hero h2 {
  margin: 12px 0 8px;
  max-width: 960px;
  font-size: clamp(36px, 5.2vw, 64px);
  line-height: 1.04;
  letter-spacing: -.04em;
}

.hero p {
  margin: 0;
  max-width: 760px;
  font-size: 18px;
  opacity: .9;
}

/* Layout */
.layout {
  display: grid;
  grid-template-columns: 270px minmax(0, 1fr);
  gap: 22px;
  max-width: 1380px;
  margin: 22px auto 40px;
  padding: 0 18px;
}

.sidebar,
.filters,
.current-path,
.product-card,
.admin-dialog {
  background: rgba(255, 255, 255, .96);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.sidebar {
  align-self: start;
  position: sticky;
  top: 78px;
  max-height: calc(100vh - 96px);
  overflow: auto;
  border-radius: 24px;
  padding: 16px;
  scrollbar-width: thin;
}

.sidebar-title {
  font-size: 13px;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: .12em;
  color: var(--brand);
  margin-bottom: 12px;
}
.sidebar-toggle {
  display: none;
  width: 100%;
  padding: 12px 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, .96);
  color: var(--brand);
  font-weight: 800;
  font-size: 14px;
  cursor: pointer;
  margin-bottom: 12px;
}

.category-tree {
  display: grid;
  gap: 5px;
}

.cat-group {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.cat-row {
  display: flex;
  align-items: center;
  gap: 4px;
}
.cat-toggle {
  width: 24px;
  height: 24px;
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.cat-subs {
  padding-left: 12px;
  display: none;
  gap: 2px;
}
.cat-btn {
  width: 100%;
  border: 0;
  border-radius: 13px;
  padding: 10px 11px;
  text-align: left;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  font-weight: 800;
  transition: background .15s ease, color .15s ease;
}

.cat-btn:hover,
.cat-btn.active {
  background: var(--soft);
  color: var(--brand);
}

.cat-lvl-0 {
  font-size: 14px;
}

.cat-lvl-1 {
  padding-left: 22px;
  font-size: 13px;
  color: #334155;
}

.cat-lvl-2 {
  padding-left: 34px;
  font-size: 12px;
  color: var(--muted);
}

.content {
  min-width: 0;
}

.filters {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 210px;
  gap: 12px;
  border-radius: 22px;
  padding: 13px;
}

.filters input,
.filters select,
.admin-login input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 15px;
  padding: 13px 14px;
  font-size: 14px;
  outline: none;
  background: white;
}

.current-path {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin: 15px 0;
  padding: 14px 18px;
  border-radius: 20px;
  color: var(--brand);
  font-weight: 900;
}

.current-path strong {
  color: var(--ink);
}

/* Cards más parejas, imagen sin deformar */
.product-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(255px, 1fr));
  gap: 20px;
}

.product-card {
  overflow: hidden;
  border-radius: 24px;
  display: flex;
  flex-direction: column;
  min-height: 100%;
  transition: transform .2s ease, box-shadow .2s ease;
}
.product-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 20px 40px rgba(15, 23, 42, .15);
}

.product-image-wrap {
  height: 210px;
  padding: 18px;
  background: linear-gradient(180deg, #f3fbfd 0%, #e3f2f5 100%);
  display: flex;
  align-items: center;
  justify-content: center;
}

.product-image-wrap img {
  display: block;
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
  object-position: center;
}
.img-fallback {
  display: none;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
}
.img-fallback svg {
  width: 64px;
  height: 64px;
  color: var(--muted);
  opacity: 0.4;
}

.product-body {
  padding: 22px 22px 24px;
  display: flex;
  flex-direction: column;
  flex: 1;
}

.route {
  color: var(--brand);
  font-weight: 900;
  font-size: 11px;
  text-transform: uppercase;
  line-height: 1.35;
  min-height: 30px;
}

.product-title {
  margin: 10px 0 11px;
  font-size: 18px;
  line-height: 1.32;
}

.meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}

.badge {
  border-radius: 999px;
  padding: 8px 10px;
  font-size: 12px;
  background: #edf2f7;
  color: #475569;
  font-weight: 900;
}

.badge.stock {
  color: #166534;
  background: #dcfce7;
}

.price {
  margin-top: auto;
  font-size: 28px;
  font-weight: 950;
  letter-spacing: -.04em;
}

.wa-btn {
  display: block;
  text-align: center;
  margin-top: 15px;
  border-radius: 18px;
  padding: 15px 12px;
  color: white;
  background: var(--wa);
  text-decoration: none;
  font-weight: 950;
  font-size: 16px;
  transition: transform .15s ease, filter .15s ease;
}

.wa-btn:hover {
  transform: translateY(-1px);
  filter: brightness(.98);
}

.empty {
  grid-column: 1 / -1;
  padding: 32px;
  border-radius: 24px;
  background: white;
  border: 1px dashed var(--line);
  color: var(--muted);
  text-align: center;
}

/* Admin */
.admin-dialog {
  width: min(920px, calc(100vw - 26px));
  border: 0;
  border-radius: 26px;
  padding: 0;
}

.admin-dialog::backdrop {
  background: rgba(15, 23, 42, .55);
  backdrop-filter: blur(5px);
}

.admin-login,
.admin-panel {
  padding: 28px;
  position: relative;
}

.dialog-close {
  position: absolute;
  right: 18px;
  top: 16px;
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 999px;
  background: #eef2f7;
  font-size: 24px;
  cursor: pointer;
}

.admin-login h2,
.admin-panel h2 {
  margin: 0 0 8px;
}

.admin-login p {
  color: var(--muted);
}

.admin-login label {
  display: grid;
  gap: 7px;
  font-weight: 900;
  margin: 18px 0;
}

.login-error {
  color: #b91c1c;
  min-height: 20px;
}

.hidden {
  display: none;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin: 20px 0;
}

.stats-grid article {
  background: var(--soft);
  border-radius: 20px;
  padding: 18px;
}

.stats-grid span {
  color: var(--muted);
  font-weight: 800;
  font-size: 13px;
}

.stats-grid strong {
  display: block;
  font-size: 32px;
  margin-top: 6px;
}

.top-products,
.category-stats {
  display: grid;
  gap: 8px;
}

.stat-row {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  padding: 11px 13px;
  border-radius: 14px;
  background: #f8fafc;
  border: 1px solid var(--line);
}

.admin-actions {
  margin-top: 20px;
}

footer {
  text-align: center;
  color: var(--muted);
  padding: 28px;
}

@media (max-width: 920px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    max-height: 280px;
  }

  .filters {
    grid-template-columns: 1fr;
  }

  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .hero > div {
    min-height: auto;
  }
}

@media (max-width: 560px) {
  .site-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .top-actions {
    width: 100%;
  }

  .ghost-btn,
  .wa-small {
    flex: 1;
    text-align: center;
  }

  .product-grid {
    grid-template-columns: 1fr;
  }

  .stats-grid {
    grid-template-columns: 1fr;
  }

  .hero {
    margin-top: 12px;
  }

  .hero h2 {
    font-size: 31px;
  }
}


/* Menú plano de categorías */
.cat-lvl-0,
.cat-lvl-1,
.cat-lvl-2 {
  padding-left: 11px;
  font-size: 14px;
  color: var(--ink);
}

.hero,
.hero > div {
  width: 100%;
}

/* Loading */
.loading {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(255, 255, 255, .9);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  gap: 16px;
}
.loading.hidden { display: none; }
.spinner {
  width: 48px;
  height: 48px;
  border: 5px solid var(--line);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading p { color: var(--muted); font-weight: 800; }

/* Skeleton loader */
.skeleton-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(255px, 1fr));
  gap: 20px;
}
.skeleton-card {
  background: rgba(255, 255, 255, .96);
  border: 1px solid var(--line);
  border-radius: 24px;
  overflow: hidden;
}
.skeleton-img {
  height: 210px;
  background: linear-gradient(90deg, var(--line) 25%, #eef2f7 50%, var(--line) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
}
.skeleton-body { padding: 22px 22px 24px; }
.skeleton-line {
  height: 14px;
  background: var(--line);
  border-radius: 8px;
  margin-bottom: 10px;
}
.skeleton-line.short { width: 60%; }
.skeleton-line.title { height: 20px; width: 85%; }
.skeleton-line.price { height: 30px; width: 50%; margin-top: 16px; }
.skeleton-line.btn { height: 48px; margin-top: 18px; }
@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}
body.dark .skeleton-card { background: #1e293b; border-color: #334155; }
body.dark .skeleton-img,
body.dark .skeleton-line { background: linear-gradient(90deg, #334155 25%, #475569 50%, #334155 75%); background-size: 200% 100%; }

/* Paginación */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-top: 28px;
  padding: 18px;
  background: rgba(255, 255, 255, .96);
  border: 1px solid var(--line);
  border-radius: 20px;
}
.page-btn {
  padding: 10px 18px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: white;
  color: var(--brand);
  font-weight: 800;
  cursor: pointer;
  transition: all .15s ease;
}
.page-btn:hover { background: var(--soft); border-color: var(--brand); }
.page-info { color: var(--muted); font-weight: 800; font-size: 14px; }

/* Modo oscuro */
body.dark {
  --bg: #0f172a;
  --panel: #1e293b;
  --ink: #f1f5f9;
  --muted: #94a3b8;
  --line: #334155;
  --soft: #1e293b;
  background: #0f172a;
}
body.dark .site-header,
body.dark .sidebar,
body.dark .filters,
body.dark .product-card,
body.dark .admin-dialog,
body.dark .current-path,
body.dark .pagination {
  background: #1e293b;
  border-color: #334155;
}
body.dark .hero > div { background: linear-gradient(135deg, #0f766e 0%, #115e59 58%, #0d9488 100%); }
body.dark .product-image-wrap { background: linear-gradient(180deg, #1e293b 0%, #0f172a 100%); }
body.dark .filters input,
body.dark .filters select,
body.dark .admin-login input {
  background: #0f172a;
  border-color: #334155;
  color: #f1f5f9;
}
body.dark .category-tree,
body.dark .stats-grid,
body.dark .top-products,
body.dark .category-stats { gap: 6px; }
body.dark .cat-btn { color: #f1f5f9; }
body.dark .cat-btn:hover,
body.dark .cat-btn.active { background: #334155; color: #2dd4bf; }
body.dark .stat-row { background: #0f172a; border-color: #334155; }
body.dark .badge { background: #334155; color: #e2e8f0; }
body.dark .dialog-close { background: #334155; }
body.dark .spinner { border-color: #334155; border-top-color: #2dd4bf; }
body.dark .loading { background: rgba(15, 23, 42, .95); }
body.dark .loading p { color: #94a3b8; }
body.dark .empty { background: #1e293b; border-color: #334155; color: #94a3b8; }
body.dark footer { color: #64748b; }
