/* ========== [COMPONENT: GRID] ========== */

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 180px));
  gap: 12px;
}

/* Library grid — wrapping grid with scroll for large collections */
.library-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, 150px);
  gap: 12px;
  max-height: 70vh;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.08) transparent;
  padding-right: 4px;
}
.library-grid::-webkit-scrollbar { width: 4px; }
.library-grid::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 2px; }

.grid-item {
  background: var(--bg-card);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: transform .15s, box-shadow .15s;
  border: 1px solid transparent;
}

.grid-item:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow);
  border-color: var(--border);
}

.grid-item .cover {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  background: #222;
  display: block;
}

.grid-item .cover-placeholder {
  width: 100%;
  aspect-ratio: 1;
  background: linear-gradient(135deg, #1a1a2e, #16213e);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 48px;
  color: #444;
}

.grid-item .info {
  padding: 10px 12px;
}

.grid-item .info .title {
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.grid-item .info .subtitle {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.grid-item .chord-badge {
  display: inline-block;
  font-size: 10px;
  background: var(--accent);
  color: #fff;
  padding: 1px 6px;
  border-radius: 10px;
  margin-top: 4px;
}

/* ========== [END: GRID] ========== */


/* ========== [COMPONENT: TRACK LIST] ========== */

.track-list {
  list-style: none;
  max-height: 70vh;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.08) transparent;
}
.track-list::-webkit-scrollbar { width: 4px; }
.track-list::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 2px; }

.track-list li {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background .15s;
}

.track-list li:hover {
  background: var(--bg-hover);
}

.track-list .track-num {
  width: 28px;
  text-align: right;
  color: var(--text-dim);
  font-size: 13px;
}

.track-list .track-title {
  flex: 1;
  font-size: 14px;
}

.track-list .track-duration {
  color: var(--text-dim);
  font-size: 13px;
}

/* ========== [END: TRACK LIST] ========== */


/* ========== [COMPONENT: SEARCH RESULTS] ========== */

.search-results {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  max-height: 400px;
  overflow-y: auto;
  z-index: 200;
  box-shadow: var(--shadow);
  display: none;
}

.search-results.show { display: block; }

.search-results .result-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  cursor: pointer;
  transition: background .15s;
}

.search-results .result-item:hover {
  background: var(--bg-hover);
}

.search-results .result-item .r-cover {
  width: 36px;
  height: 36px;
  border-radius: 4px;
  object-fit: cover;
  background: #222;
}

.search-results .result-item .r-info {
  flex: 1;
  min-width: 0;
}

.search-results .result-item .r-title {
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.search-results .result-item .r-artist {
  font-size: 11px;
  color: var(--text-dim);
}

/* User's own uploaded analyses — green "本機" tag + subtle tint so they're
   unmistakable at the top of the results. */
.search-results .result-item.is-upload {
  background: rgba(45, 125, 70, 0.08);
}
.search-results .result-item.is-upload:hover {
  background: rgba(45, 125, 70, 0.16);
}
.r-upload-badge {
  display: inline-block;
  background: #2d7d46;
  color: #fff;
  font-size: 10px;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 3px;
  margin-left: 6px;
  vertical-align: middle;
}

/* Modal variant: when user triggered from local-track list, hide YT URL row
   + drop zone so there's only the "selected file + 分析" path (avoids two
   duplicate 分析 buttons). */
.beta-fab-panel.add-song-modal.file-only #betaDropZone,
.beta-fab-panel.add-song-modal.file-only .add-song-yt-row {
  display: none !important;
}

/* `analyzing` — hide inputs while the progress row is active, so the user
   isn't tempted to start a second upload or paste another URL mid-analysis
   (and so the modal isn't cluttered with duplicate 分析 buttons). */
.beta-fab-panel.add-song-modal.analyzing #betaDropZone,
.beta-fab-panel.add-song-modal.analyzing .add-song-yt-row,
.beta-fab-panel.add-song-modal.analyzing .beta-file-info {
  display: none !important;
}

/* Local tracks list (beta homepage — user-picked audio files, persisted) */
.local-track-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.local-track-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: var(--bg-card, rgba(255,255,255,0.03));
  border: 1px solid var(--border);
  border-radius: 8px;
}
.local-track-item .lt-info {
  flex: 1 1 auto;
  min-width: 0;
}
.local-track-item .lt-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.local-track-item .lt-meta {
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 2px;
}
.local-track-item .lt-state { font-weight: 600; }
.local-track-item .lt-state.lt-done { color: #4caf50; }
.local-track-item .lt-state.lt-pending { color: #ff9800; }
.local-track-item .lt-action {
  flex-shrink: 0;
  font-size: 12px;
  padding: 4px 10px;
}
.local-track-item .lt-remove {
  flex-shrink: 0;
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 18px;
  cursor: pointer;
  padding: 0 6px;
  line-height: 1;
}
.local-track-item .lt-remove:hover { color: #f44336; }

/* Analyzed-local-track cards: small × overlay (match grid-item layout) */
.grid-item.local-analyzed-card .la-remove {
  position: absolute;
  top: 4px;
  right: 4px;
  background: rgba(0,0,0,0.6);
  color: #fff;
  border: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 13px;
  line-height: 1;
  padding: 0;
  opacity: 0;
  transition: opacity 0.15s;
  z-index: 2;
}
.grid-item.local-analyzed-card:hover .la-remove { opacity: 1; }
.grid-item.local-analyzed-card .la-remove:hover { background: #f44336; }

/* YouTube playlist cards (beta homepage) */
.yt-playlist-list { display: flex; flex-direction: column; gap: 10px; }
.yt-pl-card {
  background: var(--bg-card, rgba(255,255,255,0.03));
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}
.yt-pl-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  cursor: default;
}
.yt-pl-title {
  flex: 1 1 auto;
  min-width: 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.yt-pl-meta {
  flex-shrink: 0;
  font-size: 11px;
  color: var(--text-dim);
}
.yt-pl-refresh, .yt-pl-remove, .yt-pl-toggle {
  flex-shrink: 0;
  background: transparent;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 14px;
  padding: 2px 8px;
  line-height: 1;
}
.yt-pl-refresh:hover, .yt-pl-remove:hover, .yt-pl-toggle:hover { color: var(--text); }
.yt-pl-remove:hover { color: #f44336; }
.yt-pl-videos { display: none; border-top: 1px solid var(--border); }
.yt-pl-card.open .yt-pl-videos { display: block; }
.yt-pl-video {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-top: 1px solid rgba(255,255,255,0.04);
}
.yt-pl-video:first-child { border-top: none; }
.yt-pl-video.is-done { background: rgba(45, 125, 70, 0.06); }
.yt-pl-video .ytv-info { flex: 1 1 auto; min-width: 0; }
.yt-pl-video .ytv-title {
  font-size: 13px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.yt-pl-video .ytv-meta { font-size: 11px; color: var(--text-dim); margin-top: 2px; }
.yt-pl-video .ytv-action { flex-shrink: 0; font-size: 12px; padding: 4px 10px; }

/* ========== [END: SEARCH RESULTS] ========== */


/* ========== [COMPONENT: EMPTY STATE & LOADING] ========== */

.empty {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-dim);
}

.empty .icon { font-size: 48px; margin-bottom: 12px; }
.empty .msg { font-size: 15px; }

.loading {
  text-align: center;
  padding: 40px;
  color: var(--text-dim);
}

.spinner {
  display: inline-block;
  width: 24px;
  height: 24px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ========== [END: EMPTY STATE & LOADING] ========== */

/* ========== [COMPONENT: DASHBOARD] ========== */

.dashboard-layout {
  padding-bottom: 80px;
}

.dash-section {
  margin-bottom: 32px;
}

.dash-section:last-child {
  margin-bottom: 0px;
}

.dash-title {
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 14px;
  color: #fff;
  display: flex;
  align-items: center;
}

.horizontal-scroll {
  display: flex;
  overflow-x: auto;
  gap: 12px;
  padding-bottom: 4px;
  scrollbar-width: none;
  -ms-overflow-style: none;
  cursor: grab;
}
.horizontal-scroll::-webkit-scrollbar {
  display: none;
}

/* horizontal cards */
.horizontal-scroll .grid-item {
  flex: 0 0 150px;
  width: 150px;
}

.horizontal-scroll .grid-item .info {
  padding: 8px 10px;
}

.horizontal-scroll .grid-item .info .title {
  white-space: normal;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  font-size: 13px;
  line-height: 1.3;
}

.horizontal-scroll .grid-item .info .difficulty {
  display: block;
  margin-left: 0 !important;
  margin-top: 4px;
}

/* ========== [COMPONENT: ADD-SONG MODAL] ========== */
/* Was the beta FAB panel — now a centered modal opened from the search
   empty-state CTA. Separate #betaFabBackdrop element handles dimming + click
   to dismiss; panel itself is just the card. */

.add-song-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 2000;
  display: none;
}
.add-song-backdrop.open { display: block; }

.beta-fab-panel.add-song-modal {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 360px;
  max-width: calc(100vw - 32px);
  max-height: calc(100vh - 48px);
  overflow-y: auto;
  background: rgb(22, 27, 34);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 18px 16px;
  box-shadow: 0 12px 48px rgba(0,0,0,0.6);
  z-index: 2001;
  display: none;
}
.beta-fab-panel.add-song-modal.open { display: block; }

.add-song-close {
  position: absolute;
  top: 6px;
  right: 8px;
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 22px;
  cursor: pointer;
  padding: 2px 8px;
  line-height: 1;
}
.add-song-close:hover { color: var(--text); }

/* Search empty-state CTA (beta non-admin) */
.search-empty {
  padding: 14px 12px;
  text-align: center;
}
.search-empty-msg {
  color: var(--text-dim);
  font-size: 0.88rem;
  margin-bottom: 10px;
}
.search-empty-btn {
  background: var(--accent, #4caf50);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 8px 16px;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
}
.search-empty-btn:hover { filter: brightness(1.1); }

.fab-panel-title {
  font-size: 0.9rem;
  font-weight: 600;
  margin-bottom: 10px;
  color: var(--text);
}

.fab-section {
  border: 2px dashed var(--border);
  border-radius: 8px;
  padding: 14px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
  font-size: 0.85rem;
  color: var(--text-dim);
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.fab-section:hover, .fab-section.dragover {
  border-color: var(--accent);
  background: rgba(33, 150, 243, 0.05);
}
.upload-hint { font-size: 0.75rem; color: var(--text-dim); opacity: 0.5; }

.beta-file-info {
  margin-top: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  background: var(--bg-hover);
  border-radius: 8px;
  font-size: 0.9rem;
}

.btn-small {
  padding: 7px 16px;
  border: none;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.btn-accent {
  background: var(--accent);
  color: #fff;
}
.btn-accent:hover { opacity: 0.85; }

.beta-progress { margin-top: 12px; }
.progress-bar {
  height: 6px;
  background: var(--bg-hover);
  border-radius: 3px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 3px;
  transition: width 0.3s;
  width: 0%;
}
.progress-info {
  display: flex;
  justify-content: space-between;
  margin-top: 4px;
  font-size: 0.8rem;
  color: var(--text-dim);
}

/* History cards for beta — same style as horizontal-scroll */
#historyGrid .grid-item .title {
  font-size: 13px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#historyGrid .grid-item .subtitle {
  font-size: 0.75rem;
  color: var(--text-dim);
  margin-top: 2px;
}

/* ========== [END: DASHBOARD] ========== */

/* ========== [COMPONENT: MOBILE RESPONSIVE] ========== */

@media (max-width: 640px) {
  .beta-fab-panel.add-song-modal {
    width: auto;
    max-width: calc(100vw - 24px);
    padding: 14px 12px 12px;
  }
  .fab-panel-title { font-size: 0.85rem; margin-bottom: 8px; }
  .fab-section { padding: 10px; font-size: 0.8rem; }
  .upload-hint { font-size: 0.7rem; }
  .progress-info { font-size: 0.7rem; line-height: 1.3; }
  .beta-file-info { font-size: 0.8rem; padding: 6px 10px; }
}

/* ========== [END: MOBILE RESPONSIVE] ========== */
