/* Shared accessible horizontal scroll rails */

.scroll-rail {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}

.scroll-rail__viewport {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x proximity;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
  padding-bottom: 2px;
  outline: none;

  /* Hide native scrollbar — custom controls below */
  scrollbar-width: none;
}

.scroll-rail__viewport::-webkit-scrollbar {
  display: none;
}

.scroll-rail__viewport:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 3px;
  border-radius: var(--radius-sm);
}

.scroll-rail__controls {
  display: none;
  align-items: center;
  gap: 10px;
  min-height: 40px;
}

.scroll-rail.is-overflow .scroll-rail__controls {
  display: flex;
}

.scroll-rail__btn {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--card-bg);
  color: var(--text);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition:
    background 0.15s ease,
    border-color 0.15s ease,
    color 0.15s ease;
}

.scroll-rail__btn:hover:not(:disabled) {
  background: var(--primary-soft);
  border-color: var(--primary);
  color: var(--primary-hover);
}

.scroll-rail__btn:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.scroll-rail__btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.scroll-rail__track {
  position: relative;
  flex: 1 1 auto;
  height: 10px;
  padding: 2px 0;
  border-radius: 999px;
  background: var(--soft-bg);
  cursor: pointer;
  transition:
    background 0.15s ease,
    box-shadow 0.15s ease;
  touch-action: none;
}

.scroll-rail__track:hover,
.scroll-rail__track:focus-visible,
.scroll-rail.is-scrubbing .scroll-rail__track {
  background: #d7e3d4;
  box-shadow: inset 0 0 0 1px var(--border-strong);
}

.scroll-rail__track:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.scroll-rail__thumb {
  position: absolute;
  top: 2px;
  left: 0;
  height: calc(100% - 4px);
  min-width: 36px;
  border-radius: 999px;
  background: var(--text);
  transform: translateX(0);
  cursor: grab;
  pointer-events: auto;
  touch-action: none;
  /* No transform transition — fights scroll updates and feels jerky */
  transition:
    background 0.2s ease,
    box-shadow 0.2s ease,
    height 0.15s ease,
    top 0.15s ease;
  will-change: transform;
}

.scroll-rail__track:hover .scroll-rail__thumb,
.scroll-rail__thumb:hover,
.scroll-rail.is-scrubbing .scroll-rail__thumb {
  background: #000;
  box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.16);
}

.scroll-rail.is-scrubbing .scroll-rail__thumb {
  cursor: grabbing;
  transition: none;
}

.scroll-rail.is-scrubbing .scroll-rail__viewport {
  scroll-behavior: auto;
  scroll-snap-type: none;
  user-select: none;
}

@media (prefers-reduced-motion: reduce) {
  .scroll-rail__viewport {
    scroll-behavior: auto;
  }

  .scroll-rail__thumb {
    transition: background 0.15s ease, box-shadow 0.15s ease;
  }
}
