:root {
  --background: #FFFEEF;
  --panel: #ffffff;
  --text: #06204f;
  --muted: rgba(6, 32, 79, 0.66);
  --stroke: rgba(6, 32, 79, 0.09);
  --stroke-soft: rgba(6, 32, 79, 0.05);
  --azul-profertil: #003DA5;
  --azul-gradient: linear-gradient(180deg, #0a46ad, #003da5);
  --verde-profertil: #2D8035;
  --verde-gradient: linear-gradient(180deg, #378f40, #2d8035);
  --accent-color: #003DA5;

  --radius-xl: 28px;
  --radius-lg: 22px;
  --radius-md: 18px;

  --transition-fast: 0.15s ease;
  --transition-base: 0.3s ease;
  --transition-smooth: 0.6s cubic-bezier(0.16, 1, 0.3, 1);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--background);
  color: var(--text);
  font-family: "DM Sans", sans-serif;
  -webkit-font-smoothing: antialiased;
}

.eyebrow {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

.muted {
  color: var(--muted);
  font-size: 0.97rem;
  line-height: 1.45;
}

/* ---------- Layout ---------- */
.app {
  display: grid;
  grid-template-columns: 340px 1fr;
  gap: 22px;
  padding: 22px;
  min-height: 100vh;
  align-items: start;
}

/* ---------- Sidebar ---------- */
.sidebar {
  position: sticky;
  top: 22px;
  background: var(--panel);
  border: 1px solid var(--stroke-soft);
  border-radius: 34px;
  padding: 28px 24px;
  display: flex;
  flex-direction: column;
  gap: 22px;
  max-height: calc(100vh - 44px);
}

.brand-title {
  font-size: 2rem;
  letter-spacing: -0.04em;
  line-height: 0.96;
  margin: 10px 0 8px;
  font-weight: 700;
}

.sidebar-search {
  position: relative;
  display: flex;
  align-items: center;
}
.sidebar-search .search-ic {
  position: absolute;
  left: 16px;
  width: 18px;
  height: 18px;
  color: var(--muted);
  pointer-events: none;
}
#search,
.sidebar-search input {
  width: 100%;
  padding: 13px 16px 13px 44px;
  border: 1px solid var(--stroke);
  border-radius: 999px;
  background: var(--background);
  color: var(--text);
  font-family: inherit;
  font-size: 0.95rem;
  outline: none;
  transition: border-color var(--transition-base), background var(--transition-base);
}
#search:focus {
  border-color: var(--accent-color);
  background: var(--panel);
}

.categories {
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow-y: auto;
  margin: 0 -8px;
  padding: 0 8px;
}

.cat-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 11px 16px;
  border: none;
  background: transparent;
  border-radius: 999px;
  color: var(--text);
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  transition: background var(--transition-fast), color var(--transition-fast);
}
.cat-item:hover { background: var(--stroke-soft); }
.cat-item.active {
  background: var(--azul-gradient);
  color: #fff;
}
.cat-item .cat-count {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--muted);
  background: var(--stroke-soft);
  padding: 2px 9px;
  border-radius: 999px;
  transition: all var(--transition-fast);
}
.cat-item.active .cat-count {
  color: #fff;
  background: rgba(255, 255, 255, 0.2);
}

.export-all {
  margin-top: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px;
  border: none;
  border-radius: 999px;
  background: var(--verde-gradient);
  color: #fff;
  font-family: inherit;
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform var(--transition-fast), filter var(--transition-fast);
}
.export-all svg { width: 18px; height: 18px; }
.export-all:hover { filter: brightness(1.05); transform: translateY(-1px); }
.export-all:active { transform: translateY(0); }
.export-all:disabled { opacity: 0.6; cursor: progress; }

/* ---------- Main ---------- */
.main { min-width: 0; }

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  background: var(--panel);
  border: 1px solid var(--stroke-soft);
  border-radius: var(--radius-xl);
  padding: 16px 18px;
  margin-bottom: 22px;
}
.toolbar-info { display: flex; align-items: center; gap: 12px; }
.count-chip {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--muted);
  background: var(--background);
  border: 1px solid var(--stroke);
  padding: 4px 12px;
  border-radius: 999px;
}

.pill-group {
  display: inline-flex;
  gap: 6px;
  background: var(--background);
  border: 1px solid var(--stroke);
  border-radius: 999px;
  padding: 4px;
}
.pill {
  border: none;
  background: transparent;
  color: var(--muted);
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  padding: 8px 16px;
  border-radius: 999px;
  cursor: pointer;
  transition: all var(--transition-fast);
}
.pill:hover { color: var(--text); transform: translateY(-1px); }
.pill.active {
  background: var(--azul-gradient);
  color: #fff;
  transform: none;
}
.pill[data-color="verde"].active { background: var(--verde-gradient); }

/* ---------- Grid ---------- */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 16px;
}

.card {
  background: var(--panel);
  border: 1px solid var(--stroke-soft);
  border-radius: var(--radius-lg);
  padding: 18px 14px 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  transition: transform var(--transition-base), border-color var(--transition-base);
  opacity: 0;
  animation: itemSlideUp 0.5s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}
.card:hover {
  transform: translateY(-2px);
  border-color: rgba(6, 32, 79, 0.18);
}

.thumb {
  width: 100%;
  aspect-ratio: 1 / 1;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  background: var(--background);
  transition: background var(--transition-base), color var(--transition-base);
}
.thumb svg {
  width: 48px;
  height: 48px;
  display: block;
}
/* Original = blanco -> mostrar sobre tile oscuro para que sea visible */
.thumb.is-original { background: var(--azul-gradient); color: #fff; }
.thumb.is-azul { color: var(--azul-profertil); }
.thumb.is-verde { color: var(--verde-profertil); }

.card-name {
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text);
  text-align: center;
  line-height: 1.25;
  width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

@keyframes itemSlideUp {
  from { opacity: 0; transform: translateY(24px); }
  to { opacity: 1; transform: translateY(0); }
}

.empty {
  text-align: center;
  color: var(--muted);
  padding: 80px 20px;
  font-size: 1rem;
}

/* ---------- Modal ---------- */
[hidden] { display: none !important; }

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(6, 32, 79, 0.32);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 100;
  animation: fadeIn var(--transition-base);
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--stroke-soft);
  border-radius: 34px;
  width: 100%;
  max-width: 440px;
  padding: 30px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  animation: itemSlideUp 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}
.modal-close {
  position: absolute;
  top: 20px;
  right: 20px;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 999px;
  background: var(--background);
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition-fast);
}
.modal-close:hover { background: var(--stroke-soft); }
.modal-close svg { width: 18px; height: 18px; }

.modal-preview {
  aspect-ratio: 1 / 1;
  max-height: 240px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-xl);
  background: var(--background);
  transition: background var(--transition-base), color var(--transition-base);
}
.modal-preview svg { width: 120px; height: 120px; }
.modal-preview.is-original { background: var(--azul-gradient); color: #fff; }
.modal-preview.is-azul { color: var(--azul-profertil); }
.modal-preview.is-verde { color: var(--verde-profertil); }

.modal-body { display: flex; flex-direction: column; gap: 16px; }
.modal-name {
  font-size: 1.6rem;
  letter-spacing: -0.03em;
  line-height: 1;
  margin: 4px 0 0;
  font-weight: 700;
}
.modal-actions { display: flex; gap: 10px; }
.btn {
  flex: 1;
  padding: 14px;
  border: none;
  border-radius: 999px;
  font-family: inherit;
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform var(--transition-fast), filter var(--transition-fast);
}
.btn:hover { transform: translateY(-1px); }
.btn-ghost { background: var(--background); border: 1px solid var(--stroke); color: var(--text); }
.btn-green { background: var(--verde-gradient); color: #fff; }

/* ---------- Bong credit (idéntico al Pattern Generator) ---------- */
.bong-credit {
  position: fixed;
  right: 20px;
  bottom: 18px;
  z-index: 50;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid rgba(6, 32, 79, 0.06);
  color: #004831;
  text-decoration: none;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  backdrop-filter: blur(6px);
  transition: transform var(--transition-fast), border-color var(--transition-fast);
}
.bong-credit svg {
  width: 18px;
  height: auto;
  display: block;
  fill: currentColor;
}
.bong-credit:hover { transform: translateY(-1px); border-color: rgba(6, 32, 79, 0.18); }

/* ---------- Scrollbar ---------- */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--verde-profertil); border-radius: 999px; border: 2px solid var(--background); }
.categories::-webkit-scrollbar { width: 6px; }
.categories::-webkit-scrollbar-thumb { border: none; }

/* ---------- Responsive ---------- */
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: static;
    max-height: none;
    border-radius: var(--radius-xl);
    padding: 22px;
  }
  .categories {
    flex-direction: row;
    flex-wrap: wrap;
    overflow: visible;
  }
  .cat-item { flex: 0 0 auto; }
  .export-all { margin-top: 8px; }
}
@media (max-width: 480px) {
  .grid { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
  .toolbar { flex-direction: column; align-items: stretch; }
}
