/* ============================================================================
   ytSaver.css — Save-to-Library bottom sheet (ytSaver.js)
   Mobile-first; light/dark inherits the app's CSS variables.
   ============================================================================ */

/* ---------- Shell & backdrop ---------- */

#ytSaveShell {
  position: fixed;
  inset: 0;
  z-index: 12000;
  pointer-events: none;
  visibility: hidden;
  transition: visibility 0s linear 0.35s;
}

#ytSaveShell[data-mode="open"] {
  pointer-events: auto;
  visibility: visible;
  transition-delay: 0s;
}

#ytSaveBackdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  opacity: 0;
  transition: opacity 0.3s ease;
}

#ytSaveShell[data-mode="open"] #ytSaveBackdrop {
  opacity: 1;
}

body.ytsdScrollLocked {
  overflow: hidden;
}

/* ---------- Bottom sheet ---------- */

#ytSaveDrawer {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  max-height: min(85vh, 720px);
  background: rgba(var(--bg-surface, var(--bg-elevated)));
  color: rgba(var(--text-primary));
  border: 1px solid rgba(var(--border));
  border-bottom: none;
  border-radius: 1.25rem 1.25rem 0 0;
  box-shadow: 0 -12px 48px rgba(0, 0, 0, 0.45);
  transform: translateY(102%);
  transition: transform 0.35s cubic-bezier(0.32, 0.72, 0.35, 1);
  overflow: hidden;
}

#ytSaveShell[data-mode="open"] #ytSaveDrawer {
  transform: translateY(0);
}

.ytsdFocusSentinel {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

/* ---------- Sticky header + search form ---------- */

#ytSaveHeader {
  position: sticky;
  top: 0;
  z-index: 10;
  flex-shrink: 0;
  padding: 1rem 1rem 0.75rem;
  background: rgba(var(--bg-surface, var(--bg-elevated)));
  border-bottom: 1px solid rgba(var(--border-subtle));
}

.ytsdHeaderTop {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
}

#ytSaveKicker {
  margin: 0 0 0.15rem;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: rgba(var(--accent-coral));
}

#ytSaveTitle {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

#ytSaveClose {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  background: rgba(var(--bg-interactive));
  color: rgba(var(--text-secondary));
  border: none;
  border-radius: 50%;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease, transform 0.2s ease;
}

#ytSaveClose:hover {
  background: rgba(var(--bg-elevated));
  color: rgba(var(--text-primary));
  transform: scale(1.05);
}

#ytSaveSearchForm {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

#ytSaveSearchInput {
  flex: 1;
  min-width: 0;
  padding: 0.6rem 0.85rem;
  font-size: 0.875rem;
  font-family: inherit;
  color: rgba(var(--text-primary));
  background: rgba(var(--bg-interactive));
  border: 1px solid rgba(var(--border));
  border-radius: 0.75rem;
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

#ytSaveSearchInput::placeholder {
  color: rgba(var(--text-tertiary));
}

#ytSaveSearchInput:focus {
  border-color: rgba(var(--accent-coral));
  box-shadow: 0 0 0 3px rgba(var(--accent-coral) / 0.25);
}

#ytSaveSearchBtn {
  flex-shrink: 0;
  padding: 0.6rem 1.1rem;
  font-size: 0.85rem;
  font-weight: 600;
  font-family: inherit;
  color: #ffffff;
  background: linear-gradient(135deg, rgba(var(--accent-coral)), rgba(var(--accent-pink)));
  border: none;
  border-radius: 0.75rem;
  cursor: pointer;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

#ytSaveSearchBtn:hover {
  opacity: 0.9;
  transform: translateY(-1px);
}

#ytSaveSearchBtn:active {
  transform: translateY(0);
}

/* ---------- Body ---------- */

#ytSaveBody {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 0.85rem 1rem 1.25rem;
  -webkit-overflow-scrolling: touch;
}

.ytsdQueryEcho {
  margin: 0 0 0.6rem;
  font-size: 0.75rem;
  color: rgba(var(--text-tertiary));
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---------- Skeleton state ---------- */

.ytsdSkeletonList {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.ytsdSkeletonCard {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  padding: 0.75rem;
  background: rgba(var(--bg-interactive) / 0.5);
  border-radius: 0.9rem;
}

.ytsdSkeletonThumb {
  width: 96px;
  height: 54px;
  flex-shrink: 0;
  border-radius: 0.55rem;
  overflow: hidden;
}

.ytsdSkeletonLines {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.ytsdSkeletonLine {
  height: 0.75rem;
  border-radius: 0.375rem;
  overflow: hidden;
}

.ytsdSkeletonLine.short {
  width: 55%;
}

.ytsdSkeletonShimmer {
  width: 100%;
  height: 100%;
  background: linear-gradient(
    90deg,
    rgba(var(--bg-interactive)) 25%,
    rgba(var(--bg-elevated)) 50%,
    rgba(var(--bg-interactive)) 75%
  );
  background-size: 200% 100%;
  animation: ytsdShimmer 1.4s ease infinite;
}

@keyframes ytsdShimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ---------- Empty / error states ---------- */

.ytsdStateMsg {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 2.5rem 1rem;
  gap: 0.4rem;
}

.ytsdStateIcon {
  font-size: 2rem;
  margin-bottom: 0.35rem;
}

.ytsdStateTitle {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
}

.ytsdStateDesc {
  margin: 0;
  font-size: 0.85rem;
  color: rgba(var(--text-secondary));
}

.ytsdStateMsg.isError .ytsdStateTitle {
  color: #f0a8bb;
}

.ytsdRetryBtn {
  margin-top: 0.9rem;
  padding: 0.55rem 1.5rem;
  font-size: 0.85rem;
  font-weight: 600;
  font-family: inherit;
  color: rgba(var(--text-primary));
  background: rgba(var(--bg-interactive));
  border: 1px solid rgba(var(--border));
  border-radius: 9999px;
  cursor: pointer;
  transition: background 0.2s ease, transform 0.2s ease;
}

.ytsdRetryBtn:hover {
  background: rgba(var(--bg-elevated));
  transform: translateY(-1px);
}

/* ---------- Results grid ---------- */

.ytsdResultsGrid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.75rem;
}

.ytsdResultCard {
  position: relative;
  background: rgba(var(--bg-interactive) / 0.5);
  border: 1px solid rgba(var(--border-subtle));
  border-radius: 0.9rem;
  overflow: hidden;
  transition: border-color 0.2s ease;
}

.ytsdResultCard:hover {
  border-color: rgba(var(--border));
}

.ytsdResultHit {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  width: 100%;
  padding: 0.75rem;
  background: none;
  border: none;
  font-family: inherit;
  color: inherit;
  text-align: left;
  cursor: pointer;
}

.ytsdThumbWrap {
  position: relative;
  width: 96px;
  height: 54px;
  flex-shrink: 0;
  border-radius: 0.55rem;
  overflow: hidden;
  background: rgba(var(--bg-interactive));
}

.ytsdResultThumb {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.ytsdResultCopy {
  flex: 1;
  min-width: 0;
}

.ytsdResultCopy h4 {
  margin: 0 0 0.2rem;
  font-size: 0.85rem;
  font-weight: 600;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.ytsdChannel {
  margin: 0;
  font-size: 0.75rem;
  color: rgba(var(--text-secondary));
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ytsdResultTime {
  flex-shrink: 0;
  font-size: 0.72rem;
  color: rgba(var(--text-tertiary));
  font-variant-numeric: tabular-nums;
}

/* ---------- Card overlay (confirm / extracting / ready / error) ---------- */

.ytsdCardOverlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.55rem;
  padding: 0.85rem;
  text-align: center;
  background: rgba(var(--bg-surface, var(--bg-elevated)) / 0.97);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

.ytsdCardOverlay.isVisible {
  opacity: 1;
  pointer-events: auto;
}

.ytsdOverlayTitle {
  margin: 0;
  font-size: 0.85rem;
  font-weight: 700;
}

.ytsdOverlayActions {
  display: flex;
  gap: 0.5rem;
}

.ytsdBtn {
  padding: 0.45rem 1.1rem;
  font-size: 0.8rem;
  font-weight: 600;
  font-family: inherit;
  color: rgba(var(--text-primary));
  background: rgba(var(--bg-interactive));
  border: 1px solid rgba(var(--border));
  border-radius: 9999px;
  cursor: pointer;
  transition: background 0.2s ease, transform 0.2s ease, opacity 0.2s ease;
}

.ytsdBtn:hover {
  background: rgba(var(--bg-elevated));
  transform: translateY(-1px);
}

.ytsdBtn.isPrimary {
  color: #ffffff;
  background: linear-gradient(135deg, rgba(var(--accent-coral)), rgba(var(--accent-pink)));
  border: none;
}

.ytsdBtn.isPrimary:hover {
  opacity: 0.9;
  background: linear-gradient(135deg, rgba(var(--accent-coral)), rgba(var(--accent-pink)));
}

.ytsdBtn.isDownload {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  color: #ffffff;
  background: linear-gradient(135deg, rgba(var(--accent-coral)), rgba(var(--accent-pink)));
  border: none;
}

.ytsdBtn.isDownload:hover {
  opacity: 0.9;
}

.ytsdDownloadIcon {
  display: block;
}

.ytsdSpinner {
  width: 1.6rem;
  height: 1.6rem;
  border: 0.2rem solid rgba(var(--border));
  border-top-color: #dc143c;
  border-radius: 50%;
  animation: ytsdSpin 0.75s linear infinite;
}

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

.ytsdExtractMeta {
  margin: 0;
  font-size: 0.78rem;
  color: rgba(var(--text-secondary));
}

.ytsdProgressWrap {
  width: 100%;
  max-width: 260px;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.ytsdProgressTrack {
  width: 100%;
  height: 0.4rem;
  background: rgba(var(--bg-interactive));
  border-radius: 9999px;
  overflow: hidden;
}

.ytsdProgressFill {
  height: 100%;
  background: linear-gradient(90deg, rgba(var(--accent-coral)), rgba(var(--accent-pink)));
  border-radius: 9999px;
  transition: width 0.4s ease;
}

.ytsdStatusLine {
  margin: 0;
  font-size: 0.72rem;
  color: rgba(var(--text-tertiary));
  font-variant-numeric: tabular-nums;
}

.ytsdCancelLink {
  background: none;
  border: none;
  padding: 0.15rem 0.5rem;
  font-size: 0.75rem;
  font-family: inherit;
  color: rgba(var(--text-tertiary));
  text-decoration: underline;
  cursor: pointer;
  transition: color 0.2s ease;
}

.ytsdCancelLink:hover {
  color: rgba(var(--text-primary));
}

.ytsdInlineError {
  margin: 0;
  font-size: 0.8rem;
  color: #f0a8bb;
}

/* ---------- Saved-state affordances (app song rows) ---------- */

.ytsdCheckmarkBadge {
  position: absolute;
  top: 4px;
  right: 4px;
  z-index: 6;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 1.15rem;
  height: 1.15rem;
  font-size: 0.7rem;
  font-weight: 700;
  line-height: 1;
  color: #ffffff;
  background: linear-gradient(135deg, rgba(var(--accent-coral)), rgba(var(--accent-pink)));
  border-radius: 50%;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
  pointer-events: none;
}

.downloadBtn.is-hidden {
  display: none;
}

.downloadBtn.is-saved {
  opacity: 0.45;
  transform: none;
  cursor: default;
}

.song-row .downloadBtn.is-saved,
.rounded-3xl .downloadBtn.is-saved,
.songItem .right .downloadBtn.is-saved {
  opacity: 0.45;
}

/* ---------- Focus visibility ---------- */

#ytSaveDrawer button:focus-visible,
#ytSaveDrawer input:focus-visible,
#ytSaveDrawer [tabindex]:focus-visible,
.downloadBtn:focus-visible {
  outline: 2px solid rgba(var(--accent-coral));
  outline-offset: 2px;
}

/* ---------- Desktop ---------- */

@media (min-width: 640px) {
  #ytSaveDrawer {
    left: 50%;
    right: auto;
    bottom: 2rem;
    width: min(560px, calc(100vw - 2rem));
    max-height: min(80vh, 720px);
    border-radius: 1.25rem;
    border-bottom: 1px solid rgba(var(--border));
    transform: translate(-50%, calc(100% + 3rem));
  }

  #ytSaveShell[data-mode="open"] #ytSaveDrawer {
    transform: translate(-50%, 0);
  }

  #ytSaveHeader {
    padding: 1.25rem 1.25rem 0.85rem;
  }

  #ytSaveBody {
    padding: 1rem 1.25rem 1.5rem;
  }
}
