/* portfolio.css — Interactive portfolio component styles (TASK-0020)
 * Supplements site.css with JS-enhanced slider and infinite scroll UI.
 * Loaded only on /portfolio and /portfolio/{slug} pages.
 */

/* ---------------------------------------------------------------------------
 * 1. Before/After Comparison Slider
 * Progressively enhanced: the .before-after-fallback renders side-by-side
 * images without JS. When JS initialises the slider it adds .ba-js-active
 * to the container and builds the overlay DOM inside it.
 * --------------------------------------------------------------------------- */

.before-after-container {
  position: relative;
  overflow: hidden;
  border-radius: 0.5rem;
  background: var(--surface);
  touch-action: pan-y; /* allow vertical scroll but intercept horizontal drag */
  user-select: none;
  -webkit-user-select: none;
}

/* No-JS / fallback: side-by-side grid */
.before-after-fallback {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

@media (max-width: 480px) {
  .before-after-fallback {
    grid-template-columns: 1fr;
  }
}

/* When JS is active, hide the fallback and show the slider canvas */
.ba-js-active .before-after-fallback {
  display: none;
}

/* Slider canvas – absolutely fills the container */
.ba-canvas {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  border-radius: 0.5rem;
}

/* Both images fill the canvas */
.ba-img-before,
.ba-img-after {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  pointer-events: none;
}

/* The "after" image sits on top and is clipped by clip-path */
.ba-img-after {
  clip-path: inset(0 50% 0 0); /* start at 50% — updated by JS via CSS var */
}

/* Handle track */
.ba-handle-track {
  position: absolute;
  inset: 0;
  cursor: ew-resize;
  touch-action: none;
}

/* Vertical divider line */
.ba-handle-line {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%; /* updated by JS */
  width: 2px;
  background: rgba(255, 255, 255, 0.9);
  transform: translateX(-50%);
  pointer-events: none;
  transition: left 0.05s linear;
}

/* Draggable circle */
.ba-handle-circle {
  position: absolute;
  top: 50%;
  left: 50%; /* updated by JS */
  width: 2.75rem;
  height: 2.75rem;
  border-radius: 50%;
  background: white;
  border: 3px solid rgba(0, 0, 0, 0.15);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
  transform: translate(-50%, -50%);
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  transition: left 0.05s linear;
  cursor: ew-resize;
  font-size: 0.7rem;
  color: #333;
  gap: 0.15rem;
}

.ba-handle-circle::before {
  content: '◀';
}

.ba-handle-circle::after {
  content: '▶';
}

/* Keyboard-focusable track receives visible focus ring */
.ba-handle-track:focus {
  outline: 3px solid var(--accent, #2563eb);
  outline-offset: 2px;
}

.ba-handle-track:focus-visible {
  outline: 3px solid var(--accent, #2563eb);
  outline-offset: 2px;
}

/* Labels */
.ba-label {
  position: absolute;
  top: 0.6rem;
  padding: 0.2rem 0.55rem;
  border-radius: 0.25rem;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  pointer-events: none;
  z-index: 2;
}

.ba-label-before {
  left: 0.6rem;
}

.ba-label-after {
  right: 0.6rem;
}

/* Reduced-motion: skip all transitions on the slider */
@media (prefers-reduced-motion: reduce) {
  .ba-handle-line,
  .ba-handle-circle {
    transition: none;
  }
}

/* ---------------------------------------------------------------------------
 * 2. Infinite Scroll / Load More
 * --------------------------------------------------------------------------- */

.portfolio-load-more-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  padding: 2rem 0 1rem;
}

.button-load-more {
  min-width: 12rem;
}

/* Spinner / loading indicator */
.portfolio-loading-indicator {
  display: none;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
  color: var(--muted);
}

.portfolio-loading-indicator.is-loading {
  display: flex;
}

.portfolio-spinner {
  width: 1.25rem;
  height: 1.25rem;
  border: 2px solid var(--border);
  border-top-color: var(--accent, #2563eb);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  flex-shrink: 0;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

@media (prefers-reduced-motion: reduce) {
  .portfolio-spinner {
    animation: none;
    border-top-color: var(--muted);
  }
}

/* End-of-results message */
.portfolio-end-message {
  display: none;
  font-size: 0.9rem;
  color: var(--muted);
  text-align: center;
  padding: 0.5rem 0;
}

.portfolio-end-message.visible {
  display: block;
}

/* Live status region (aria-live) */
#portfolio-scroll-status {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* Error message for failed loads */
.portfolio-load-error {
  display: none;
  font-size: 0.9rem;
  color: var(--error, #dc2626);
  text-align: center;
  padding: 0.5rem 0;
}

.portfolio-load-error.visible {
  display: block;
}

/* ---------------------------------------------------------------------------
 * 3. JS-enhanced progressive state
 * --------------------------------------------------------------------------- */

/* When JS runs, indicate that interactive enhancements are active */
html.js .portfolio-pagination {
  /* Hide server-rendered pagination when JS infinite scroll is active */
  /* Only hide when we have a load-more button present */
}

html.js .portfolio-timeline-js-enhanced .portfolio-pagination {
  display: none;
}
