/*
 * Barra de categorías y búsqueda (estilo de Test/ScienceSimulations).
 * Queda fija bajo la cabecera al hacer scroll. Las pastillas van siempre en una sola fila que se desliza;
 * cuando no caben aparecen flechas y un degradado en el borde.
 */

.toolbar {
  position: sticky;
  top: var(--header-h);
  z-index: 90;
  background: rgba(246, 248, 251, 0.9);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.toolbar-inner {
  display: flex;
  align-items: center;
  gap: 16px;
  padding-top: 12px;
  padding-bottom: 12px;
}

/* ---------- Pastillas ---------- */
.filters-wrap {
  position: relative;
  flex: 1;
  min-width: 0;
}

.filters {
  display: flex;
  flex-wrap: nowrap;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
  scroll-behavior: smooth;
  /* Que el foco del teclado y la sombra de la pastilla no queden recortados */
  padding: 2px;
  margin: -2px;
}
.filters::-webkit-scrollbar { display: none; }

.chip {
  display: inline-flex;
  flex-shrink: 0;
  align-items: center;
  gap: 7px;
  height: 38px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-2);
  font-size: 0.9rem;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.chip:hover { border-color: var(--border-strong); color: var(--text); }

.chip-count {
  min-width: 22px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-3);
  font-size: 0.75rem;
  font-weight: 600;
  text-align: center;
  line-height: 1.6;
}

.chip.is-active { background: var(--primary-ink); border-color: var(--primary-ink); color: #fff; }
.chip.is-active .chip-count { background: rgba(255, 255, 255, 0.18); color: #fff; }

/* Pastilla de la sección exclusiva (con sesión) */
.chip.is-premium::after {
  content: 'PRO';
  font-size: 0.6rem;
  font-weight: 700;
  letter-spacing: 0.4px;
  padding: 1px 5px;
  border-radius: 5px;
  background: var(--primary-ink);
  color: #fff;
}
.chip.is-premium.is-active::after { background: #fff; color: var(--primary-ink); }

/* ---------- Flechas y degradado cuando las pastillas no caben ---------- */
.scroller.can-next > .scroll-row {
  -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 72px), transparent);
          mask-image: linear-gradient(to right, #000 calc(100% - 72px), transparent);
}
.scroller.can-prev > .scroll-row {
  -webkit-mask-image: linear-gradient(to right, transparent, #000 72px);
          mask-image: linear-gradient(to right, transparent, #000 72px);
}
.scroller.can-prev.can-next > .scroll-row {
  -webkit-mask-image: linear-gradient(to right, transparent, #000 72px, #000 calc(100% - 72px), transparent);
          mask-image: linear-gradient(to right, transparent, #000 72px, #000 calc(100% - 72px), transparent);
}

.scroll-arrow {
  position: absolute;
  top: 50%;
  z-index: 2;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  margin-top: -18px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: background 0.15s, transform 0.15s;
}
.scroll-arrow:hover { background: var(--surface-2); }
.scroll-arrow:active { transform: scale(0.94); }
.scroll-arrow[hidden] { display: none; }
.scroll-arrow.prev { left: -6px; }
.scroll-arrow.next { right: -6px; }

/* ---------- Buscador ---------- */
.search {
  position: relative;
  display: flex;
  align-items: center;
  flex: 0 0 240px;
  color: var(--text-3);
}
.search svg { position: absolute; left: 12px; pointer-events: none; }
.search input {
  width: 100%;
  height: 38px;
  padding: 0 12px 0 36px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 0.92rem;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.search input::placeholder { color: var(--text-3); }
.search input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }

/* ---------- Responsive ---------- */
/* Tablets y celulares: buscador debajo de las pastillas */
@media (max-width: 960px) {
  .toolbar-inner { flex-direction: column; align-items: stretch; gap: 10px; }
  .search { flex-basis: auto; }
  html { scroll-padding-top: calc(var(--header-h) + 120px); }
}

/* Celulares: la cabecera no es fija, así que la barra se pega arriba del todo */
@media (max-width: 760px) {
  .toolbar { top: 0; }
  .toolbar-inner { padding-top: 10px; padding-bottom: 10px; }
  .filters { margin: 0 -16px; padding: 2px 16px; }
  html { scroll-padding-top: 120px; }
}

/* Pantallas táctiles: áreas cómodas de tocar */
@media (pointer: coarse) {
  .chip { height: 42px; }
  .search input { height: 44px; font-size: 16px; } /* 16 px evita el zoom automático de iOS al enfocar */
  .scroll-arrow { width: 40px; height: 40px; margin-top: -20px; }
}
