/* ==========================================================================
   MUSIC APP — DISEÑO ESTILO SPOTIFY (oct-2026)
   Rediseño visual completo para escritorio/web. La app原有的 functionality
   se mantiene: mismos IDs, mismas clases que usa el JS, mismos handlers.
   ========================================================================== */

:root {
  --bg-primary: #000000;
  --bg-secondary: #121212;
  --bg-tertiary: #181818;
  --bg-elevated: #242424;
  --bg-hover: #2a2a2a;
  --accent: #1ed760;
  --accent-hover: #3be477;
  --accent-secondary: #1db954;
  --text-primary: #FFFFFF;
  --text-secondary: #B3B3B3;
  --text-muted: #727272;
  --line: #292929;
  --sidebar-w: 240px;
  --player-h: 88px;
  --radius: 8px;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-user-select: none;
  user-select: none;
}

body {
  font-family: 'Circular Std', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  overflow: hidden;
}

input, textarea {
  -webkit-user-select: text;
  user-select: text;
}

/* ============ LOGIN SCREEN ============ */
#loginScreen {
  position: fixed;
  inset: 0;
  background: linear-gradient(135deg, #1a1a2e 0%, #121212 50%, #000 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 2000;
}

#loginScreen h1 {
  font-size: 48px;
  font-weight: 800;
  letter-spacing: -1px;
  margin-bottom: 40px;
  color: var(--accent);
}

#loginForm {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 320px;
}

#loginForm input {
  padding: 14px 16px;
  background: var(--bg-tertiary);
  border: 1px solid var(--line);
  border-radius: 4px;
  color: var(--text-primary);
  font-size: 14px;
  font-family: inherit;
}

#loginForm input:focus {
  outline: none;
  border-color: var(--text-primary);
}

#loginForm button {
  padding: 14px;
  background: var(--accent);
  color: #000;
  border: none;
  border-radius: 500px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
}

#loginForm button:hover {
  background: var(--accent-hover);
}

#loginError {
  color: #e74c3c;
  font-size: 13px;
  margin-top: 8px;
  min-height: 18px;
}

/* ============ USER SELECT ============ */
#userSelectScreen {
  position: fixed;
  inset: 0;
  background: var(--bg-primary);
  z-index: 1900;
  padding: 40px;
  overflow-y: auto;
}

#userSelectScreen h2 {
  font-size: 32px;
  font-weight: 800;
  margin-bottom: 32px;
}

#logoutBtn {
  position: absolute;
  top: 24px;
  right: 24px;
  padding: 10px 20px;
  background: var(--bg-tertiary);
  border: 1px solid var(--line);
  color: var(--text-primary);
  border-radius: 500px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
}

#logoutBtn:hover { background: var(--bg-hover); }

#userGrid {
  display: flex;
  flex-wrap: wrap;
  gap: 24px;
}

.user-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  padding: 16px;
  border-radius: 8px;
  transition: background .2s;
  min-width: 140px;
}

.user-card:hover { background: var(--bg-tertiary); }

.user-avatar {
  width: 120px;
  height: 120px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-secondary));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 48px;
  font-weight: 800;
  color: #000;
}

.user-card.admin .user-avatar {
  background: linear-gradient(135deg, #8B5CF6, #6366F1);
  color: #fff;
}

.user-card:hover .user-avatar { transform: scale(1.04); }

.user-name { font-size: 14px; font-weight: 600; }

#adminBtn {
  position: fixed;
  bottom: 24px;
  right: 24px;
  padding: 12px 24px;
  background: var(--accent);
  color: #000;
  border: none;
  border-radius: 500px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
}

#adminBtn:hover { background: var(--accent-hover); }

/* ============ ADMIN PANEL ============ */
#adminPanel {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.7);
  z-index: 3000;
  display: none;
  align-items: center;
  justify-content: center;
}

#adminPanel.show { display: flex; }

#adminContent {
  background: var(--bg-tertiary);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 24px;
  width: 420px;
  max-height: 80vh;
  overflow-y: auto;
}

#adminContent h3 {
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

#closeAdminBtn {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 28px;
  cursor:pointer;
  line-height: 1;
}

#closeAdminBtn:hover { color: var(--text-primary); }

.admin-user {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}

.admin-user-info { display: flex; align-items: center; gap: 12px; font-size: 14px; }
.admin-user-actions { display: flex; gap: 6px; }

.admin-user-actions button {
  padding: 6px 12px;
  border-radius: 4px;
  border: none;
  cursor: pointer;
  font-size: 12px;
  font-weight: 700;
  font-family: inherit;
}

.admin-user-actions .edit-btn { background: var(--bg-elevated); color: var(--text-primary); }
.admin-user-actions .delete-btn { background: rgba(231,76,60,.15); color: #e74c3c; }

#addUserForm { margin-top: 20px; display: flex; flex-direction: column; gap: 8px; }

#addUserForm input {
  padding: 10px 12px;
  background: var(--bg-elevated);
  border: 1px solid var(--line);
  border-radius: 4px;
  color: var(--text-primary);
  font-size: 14px;
  font-family: inherit;
}

#addUserForm button {
  padding: 10px;
  background: var(--accent);
  color: #000;
  border: none;
  border-radius: 500px;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
}

/* ============ OFFLINE INDICATOR ============ */
.offline-indicator {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-elevated);
  border: 1px solid var(--line);
  padding: 8px 16px;
  border-radius: 500px;
  display: none;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 600;
  z-index: 1500;
}

.offline-indicator.show { display: flex; }
.offline-indicator svg { width: 16px; height: 16px; fill: var(--text-secondary); }

/* ============ LAYOUT PRINCIPAL ============ */
#mainApp {
  display: flex;
  height: 100vh;
  padding-bottom: var(--player-h);
  gap: 8px;
  background: var(--bg-primary);
}

/* ============ SIDEBAR ============ */
#sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--bg-primary);
  display: flex;
  flex-direction: column;
  border-radius: 8px 0 0 0;
  overflow: hidden;
  transition: margin-left .25s ease;
}

/* En escritorio el sidebar SIEMPRE visible (el .open solo aplica en móvil) */
/* ---- MARCA (arriba del sidebar, estilo Spotify) ---- */
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 20px 12px;
  flex-shrink: 0;
}

.brand-mark {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent);
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.brand-mark svg { width: 18px; height: 18px; fill: #000; }
.brand-name { font-size: 19px; font-weight: 800; letter-spacing: -.4px; }

#sidebarHeader {
  display: none;
}

#closeSidebarBtn { display: none; }

.sidebar-nav {
  padding: 0 12px 8px;
  flex-shrink: 0;
}

/* El overlay solo existe en móvil; en escritorio nunca se muestra. */
#sidebarOverlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.6);
  z-index: 1100;
  display: none;
}

#sidebarOverlay.show { display: block; }

.sidebar-btn {
  display: flex;
  align-items: center;
  gap: 16px;
  width: 100%;
  padding: 10px 12px;
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  border-radius: 4px;
  text-align: left;
  font-family: inherit;
  transition: color .15s;
}

.sidebar-btn:hover { color: var(--text-primary); }

.sidebar-btn.active {
  color: var(--text-primary);
  background: var(--bg-tertiary);
}

.sidebar-btn svg {
  width: 24px;
  height: 24px;
  fill: currentColor;
  flex-shrink: 0;
}

/* ---- BIBLIOTECA (nuevo: las playlists en el sidebar) ---- */
.sidebar-library {
  flex: 1;
  overflow-y: auto;
  padding: 0 8px 16px;
  min-height: 0;
}

.sidebar-library-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 12px 8px 20px;
  color: var(--text-secondary);
  font-size: 15px;
  font-weight: 700;
}

.sidebar-library-header .lib-actions { display: flex; gap: 4px; }

.lib-icon-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  background: none;
  color: var(--text-secondary);
  cursor: pointer;
  display: grid;
  place-items: center;
}

.lib-icon-btn:hover { color: var(--text-primary); background: var(--bg-hover); }
.lib-icon-btn svg { width: 20px; height: 20px; fill: currentColor; }

.playlist-tabs {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.playlist-tab {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 8px 12px;
  background: none;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  text-align: left;
  font-family: inherit;
  color: var(--text-secondary);
}

.playlist-tab:hover { background: var(--bg-tertiary); }
.playlist-tab.active { background: var(--bg-tertiary); }

.playlist-tab-cover {
  width: 48px;
  height: 48px;
  border-radius: 4px;
  object-fit: cover;
  flex-shrink: 0;
  background: var(--bg-elevated);
}

.playlist-tab-text { min-width: 0; display: flex; flex-direction: column; }

.playlist-tab .playlist-name {
  font-size: 15px;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.playlist-tab .playlist-meta {
  font-size: 13px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ============ MAIN ============ */
main {
  flex: 1;
  min-width: 0;
  background: var(--bg-secondary);
  border-radius: 8px 8px 0 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

/* ---- TOP BAR ---- */
header {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 64px;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 24px;
  pointer-events: none;
  /* Fondo degradado para que los controles siempre se lean, incluso
     cuando el hero se sale de vista al hacer scroll. */
  background: linear-gradient(180deg, rgba(18,18,18,.92) 0%, rgba(18,18,18,.6) 60%, rgba(18,18,18,0) 100%);
}

header > * { pointer-events: auto; }

.header-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

.round-nav-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  background: rgba(0,0,0,.6);
  color: var(--text-primary);
  display: grid;
  place-items: center;
  cursor: pointer;
}

.round-nav-btn:hover { background: rgba(0,0,0,.85); }
.round-nav-btn svg { width: 18px; height: 18px; fill: currentColor; }

#hamburgerBtn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  background: rgba(0,0,0,.6);
  color: var(--text-primary);
  display: none;
  place-items: center;
  cursor: pointer;
}

#hamburgerBtn:hover { background: rgba(0,0,0,.85); }
#hamburgerBtn svg { width: 20px; height: 20px; fill: currentColor; }

.header-title {
  font-size: 19px;
  font-weight: 800;
  letter-spacing: -0.4px;
}

.user-info {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
}

.user-info .username {
  height: 32px;
  padding: 0 14px;
  border-radius: 500px;
  background: rgba(0,0,0,.6);
  border: 1px solid var(--line);
  color: var(--text-primary);
  font-size: 13px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.user-info .username:hover { background: rgba(0,0,0,.85); }

.user-avatar-circle {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-secondary));
  color: #000;
  display: grid;
  place-items: center;
  font-size: 13px;
  font-weight: 800;
}

/* ---- BUSCADOR PRINCIPAL (nuevo) ---- */
.main-search {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  width: 364px;
  max-width: calc(100% - 220px);
  height: 48px;
  background: var(--bg-elevated);
  border: 1px solid var(--line);
  border-radius: 500px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  z-index: 25;
}

.main-search:focus-within { border-color: var(--text-secondary); }
.main-search svg { width: 22px; height: 22px; fill: var(--text-secondary); flex-shrink: 0; }

.main-search input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-size: 14px;
  font-family: inherit;
  min-width: 0;
}

.main-search input::placeholder { color: var(--text-muted); }

.clear-search-btn {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: none;
  background: var(--bg-hover);
  color: var(--text-primary);
  cursor: pointer;
  display: none;
  place-items: center;
  font-size: 13px;
  line-height: 1;
  flex-shrink: 0;
}

.clear-search-btn.show { display: grid; }
.clear-search-btn:hover { background: #3a3a3a; }

/* ---- CONTENIDO ---- */
.section-container {
  display: none;
  flex: 1;
  overflow-y: auto;
  padding-top: 64px;
  flex-direction: column;
}

.section-container.active { display: flex; }

/* ============ HERO DE PLAYLIST (nuevo) ============ */
.playlist-hero {
  display: flex;
  align-items: flex-end;
  gap: 24px;
  padding: 32px 32px 24px;
  background: linear-gradient(180deg, #3a2f6e 0%, rgba(18,18,18,.85) 60%, var(--bg-secondary) 100%);
  flex-shrink: 0;
}

.playlist-hero-art {
  width: 208px;
  height: 208px;
  border-radius: 4px;
  object-fit: cover;
  flex-shrink: 0;
  background: var(--bg-elevated);
  box-shadow: 0 4px 60px rgba(0,0,0,.5);
}

.playlist-hero-info { min-width: 0; padding-bottom: 4px; }

.playlist-hero-kicker {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .1em;
}

.playlist-hero-title {
  font-size: clamp(32px, 5vw, 72px);
  font-weight: 800;
  letter-spacing: -.03em;
  line-height: 1.05;
  margin: 8px 0 12px;
  overflow-wrap: anywhere;
}

.playlist-hero-meta {
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.playlist-hero-meta b { font-weight: 700; }
.playlist-hero-meta .dot { color: var(--text-muted); }

/* ---- ACCIONES (play grande, shuffle, etc.) ---- */
.playlist-actions {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 0 32px 24px;
  flex-shrink: 0;
}

.big-play-btn {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  cursor: pointer;
  display: grid;
  place-items: center;
  box-shadow: 0 8px 8px rgba(0,0,0,.3);
  transition: transform .12s, background .15s;
}

.big-play-btn:hover { background: var(--accent-hover); transform: scale(1.05); }
.big-play-btn svg { width: 24px; height: 24px; fill: #000; }

.playlist-action-icon {
  width: 32px;
  height: 32px;
  border: none;
  background: none;
  color: var(--text-secondary);
  cursor: pointer;
  display: grid;
  place-items: center;
}

.playlist-action-icon:hover { color: var(--text-primary); }
.playlist-action-icon svg { width: 24px; height: 24px; fill: currentColor; }

/* ---- CABECERA DE TABLA ---- */
.playlist-table-head {
  display: grid;
  grid-template-columns: 40px minmax(0, 4fr) minmax(0, 2fr) 100px 40px;
  align-items: center;
  gap: 16px;
  padding: 0 32px 8px;
  margin-bottom: 8px;
  border-bottom: 1px solid var(--line);
  color: var(--text-secondary);
  font-size: 12px;
  letter-spacing: .05em;
  text-transform: uppercase;
  flex-shrink: 0;
}

/* ============ PLAYLIST SONGS (tabla) ============ */
.playlist-songs {
  padding-bottom: 40px;
}

.playlist-song {
  display: grid;
  grid-template-columns: 40px minmax(0, 4fr) minmax(0, 2fr) 100px 40px;
  align-items: center;
  gap: 16px;
  padding: 8px 32px;
  cursor: pointer;
  transition: background .12s;
}

.playlist-song:hover { background: rgba(255,255,255,.07); }

.song-number {
  display: grid;
  place-items: center;
  position: relative;
  color: var(--text-muted);
  font-size: 15px;
  font-variant-numeric: tabular-nums;
}

/* La fila completa es clicable, así que el número NO se oculta al hover:
   se reemplaza por el botón de play de la columna siguiente ( Spotify ). */
.song-main {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.song-actions {
  display: grid;
  place-items: center;
  opacity: 0;
  transition: opacity .12s;
}

.playlist-song:hover .song-actions { opacity: 1; }
.playlist-song:hover .song-number { visibility: hidden; }

.action-btn {
  background: none;
  border: none;
  color: var(--text-primary);
  cursor: pointer;
  display: grid;
  place-items: center;
  padding: 0;
}

.action-btn svg { width: 20px; height: 20px; fill: currentColor; }
.song-menu-btn:hover { transform: scale(1.08); }

.song-thumb-wrapper {
  position: relative;
  width: 40px;
  height: 40px;
  flex-shrink: 0;
}

.song-thumb {
  width: 40px;
  height: 40px;
  border-radius: 4px;
  object-fit: cover;
  display: block;
}

.song-info { min-width: 0; display: flex; flex-direction: column; gap: 2px; }

.song-title {
  font-size: 15px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.playlist-song.playing .song-title { color: var(--accent); }
.playlist-song.playing .song-number { color: var(--accent); }

/* La duración vive en su propia columna de la tabla; dentro de .song-info
   solo se muestra en móvil (donde la columna no cabe). */
.song-duration { display: none; }

.song-duration-cell {
  font-size: 14px;
  color: var(--text-muted);
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.song-album {
  font-size: 14px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.song-playing-indicator { display: none; align-items: center; }

.sound-bars { width: 20px; height: 14px; fill: var(--accent); }
.loading-dots { width: 20px; height: 12px; fill: var(--accent); }

.song-downloading-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-muted);
}

.song-downloading-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(0,0,0,.5);
  border-radius: 4px;
}

.song-downloading .song-thumb { filter: blur(4px) brightness(0.7); }

.song-downloaded svg { width: 16px; height: 16px; fill: var(--accent); }

/* ============ EMPTY STATE ============ */
.empty-playlist {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 60px 32px;
  color: var(--text-muted);
  text-align: center;
}

.empty-playlist svg { width: 48px; height: 48px; fill: var(--text-muted); }
.empty-playlist p { font-size: 15px; }

/* ============ SEARCH RESULTS (grid estilo Spotify) ============ */
.search-section { padding: 0 32px 40px; }

.search-results {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 20px;
  padding: 24px 0;
}

.search-results .song-card {
  position: relative;
  background: var(--bg-tertiary);
  border-radius: var(--radius);
  padding: 16px;
  cursor: pointer;
  transition: background .2s;
}

.search-results .song-card:hover { background: var(--bg-hover); }

.search-results .thumbnail {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 6px;
  display: block;
  background: var(--bg-elevated);
  margin-bottom: 14px;
}

.search-results .play-overlay {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--accent);
  display: grid;
  place-items: center;
  cursor: pointer;
  opacity: 0;
  transform: translateY(8px);
  transition: all .2s;
  z-index: 2;
}

.search-results .song-card:hover .play-overlay { opacity: 1; transform: translateY(0); }
.search-results .play-overlay svg { width: 20px; height: 20px; fill: #000; }

.search-results .add-btn {
  position: absolute;
  top: 16px;
  left: 16px;
  width: 32px;
  height: 32px;
  background: var(--accent);
  border: none;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2;
  opacity: 0;
  transition: opacity .2s;
}

.search-results .song-card:hover .add-btn { opacity: 1; }
.search-results .add-btn svg { width: 16px; height: 16px; fill: #000; }

.search-results .title {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.search-results .duration { font-size: 13px; color: var(--text-muted); }

.card-status {
  position: absolute;
  inset: 16px 16px auto 16px;
  aspect-ratio: 1;
  background: rgba(0,0,0,.72);
  border-radius: 6px;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 12px;
  z-index: 3;
}

.song-card.downloading .card-status { display: flex; }
.song-card.downloading .thumbnail { filter: blur(4px) brightness(0.7); }
.song-card.downloading .add-btn { opacity: 1; }
.song-card.downloaded .add-btn { background: var(--bg-elevated); }
.song-card.downloaded .add-btn svg { fill: var(--text-primary); }

.show-more-btn {
  grid-column: 1 / -1;
  justify-self: center;
  padding: 12px 28px;
  background: var(--bg-elevated);
  border: none;
  border-radius: 500px;
  color: var(--text-primary);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
}

.show-more-btn:hover { background: var(--bg-hover); }

/* ============ PLAYER BAR (estilo Spotify) ============ */
.player-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--player-h);
  background: var(--bg-tertiary);
  border-top: 1px solid var(--line);
  display: grid;
  grid-template-columns: minmax(180px, 1fr) minmax(0, 2fr) minmax(180px, 1fr);
  align-items: center;
  padding: 0 16px;
  gap: 16px;
  z-index: 100;
}

.now-playing {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.now-playing-thumb {
  width: 56px;
  height: 56px;
  border-radius: 4px;
  object-fit: cover;
  background: var(--bg-elevated);
  flex-shrink: 0;
}

.now-playing-info { min-width: 0; }

.now-playing-title {
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.now-playing-artist {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.player-controls {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.controls-row {
  display: flex;
  align-items: center;
  gap: 18px;
}

.controls-row button {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  padding: 0;
  transition: color .15s, transform .12s;
}

.controls-row button:hover { color: var(--text-primary); }
.controls-row button svg { width: 16px; height: 16px; fill: currentColor; }

.control-btn.play-pause {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--text-primary);
}

.control-btn.play-pause:hover { transform: scale(1.06); background: #fff; }
.control-btn.play-pause svg { width: 16px; height: 16px; fill: #000; }

#shuffleBtn.active, #repeatBtn.active { color: var(--accent); }
#shuffleBtn.active svg, #repeatBtn.active svg { fill: var(--accent); }

.progress-container {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  max-width: 620px;
}

.time {
  font-size: 11px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  min-width: 38px;
}

.progress-bar {
  flex: 1;
  height: 4px;
  border-radius: 2px;
  background: #4d4d4d;
  position: relative;
  cursor: pointer;
}

.progress {
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 0%;
  background: var(--text-primary);
  border-radius: 2px;
}

.progress-bar:hover .progress { background: var(--accent); }

.progress-bar::after {
  content: '';
  position: absolute;
  left: var(--knob, 0%);
  top: 50%;
  transform: translate(-50%, -50%);
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--text-primary);
  opacity: 0;
  transition: opacity .15s;
}

.progress-bar:hover::after { opacity: 1; }

.loading-spinner {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

.volume-container {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.volume-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  padding: 0;
}

.volume-btn:hover { color: var(--text-primary); }
.volume-btn svg { width: 18px; height: 18px; fill: currentColor; }

.volume-slider {
  width: 93px;
  height: 4px;
  border-radius: 2px;
  background: #4d4d4d;
  position: relative;
  cursor: pointer;
}

.volume-level {
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 50%;
  background: var(--text-primary);
  border-radius: 2px;
}

/* ============ SPINNER ============ */
.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid var(--text-muted);
  border-top-color: var(--text-primary);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}

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

.loading { display: grid; place-items: center; padding: 40px; grid-column: 1/-1; }
.loading-text { color: var(--text-muted); font-size: 14px; }

/* ============ MODALS ============ */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.7);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 2500;
}

.modal.show { display: flex; }

.modal-content {
  background: var(--bg-elevated);
  border-radius: 8px;
  padding: 24px;
  width: 400px;
}

.modal-content h3 { font-size: 20px; font-weight: 700; margin-bottom: 20px; }

.modal-content input {
  width: 100%;
  padding: 12px;
  background: var(--bg-tertiary);
  border: 1px solid var(--line);
  border-radius: 4px;
  color: var(--text-primary);
  font-size: 14px;
  font-family: inherit;
  margin-bottom: 16px;
}

.modal-content input:focus { outline: none; border-color: var(--text-primary); }

.modal-buttons { display: flex; gap: 12px; justify-content: flex-end; }

.modal-btn {
  padding: 10px 24px;
  border-radius: 500px;
  border: none;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
}

.modal-btn.cancel { background: var(--bg-hover); color: var(--text-primary); }
.modal-btn.cancel:hover { background: #3a3a3a; }
.modal-btn.confirm { background: var(--accent); color: #000; }
.modal-btn.confirm:hover { background: var(--accent-hover); }

/* ============ MENÚS CONTEXTUALES ============ */
.song-menu, .playlist-menu {
  position: fixed;
  background: var(--bg-elevated);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 4px;
  min-width: 180px;
  z-index: 3000;
  box-shadow: 0 8px 24px rgba(0,0,0,.5);
}

.song-menu button, .playlist-menu button {
  display: block;
  width: 100%;
  padding: 10px 14px;
  background: none;
  border: none;
  color: var(--text-primary);
  font-size: 13px;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
  border-radius: 4px;
  font-family: inherit;
}

.song-menu button:hover, .playlist-menu button:hover { background: var(--bg-hover); }
.song-menu button.danger, .playlist-menu button.danger { color: #e74c3c; }
.song-menu button.download-btn:disabled { color: var(--text-muted); cursor: default; }
.song-menu button.download-btn:disabled:hover { background: none; }

.user-dropdown {
  background: var(--bg-elevated) !important;
  border: 1px solid var(--line) !important;
  border-radius: 8px !important;
}

/* ============ RADIO ============ */
.radio-section { padding: 24px 32px 40px; }

.radio-section h2 {
  font-size: 24px;
  font-weight: 800;
  letter-spacing: -.02em;
  margin-bottom: 20px;
}

.radio-search-bar { display: flex; gap: 12px; margin-bottom: 24px; }

.radio-search-wrap {
  flex: 1;
  height: 44px;
  background: var(--bg-elevated);
  border: 1px solid var(--line);
  border-radius: 500px;
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 10px;
}

.radio-search-wrap input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-size: 14px;
  font-family: inherit;
}

.radio-search-bar button {
  padding: 0 24px;
  height: 44px;
  background: var(--accent);
  color: #000;
  border: none;
  border-radius: 500px;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
}

.radio-search-bar button:hover { background: var(--accent-hover); }

.radio-clear-btn {
  width: 22px; height: 22px;
  border-radius: 50%;
  border: none;
  background: var(--bg-hover);
  color: var(--text-primary);
  cursor: pointer;
  display: none;
  place-items: center;
  font-size: 12px;
}

.radio-clear-btn.show { display: grid; }

.radio-favorites h3 { font-size: 16px; font-weight: 700; margin: 20px 0 12px; }

.radio-results {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 12px;
}

.station-card {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--bg-tertiary);
  border-radius: 6px;
  padding: 12px;
  cursor: pointer;
  transition: background .2s;
}

.station-card:hover { background: var(--bg-hover); }
.station-card.playing { background: var(--bg-hover); }

.station-name {
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.station-meta { font-size: 13px; color: var(--text-muted); }
.station-tags { font-size: 12px; color: var(--text-muted); }
.station-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }

.station-play-btn {
  width: 34px; height: 34px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #000;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.station-play-btn:hover { background: var(--accent-hover); }
.station-play-btn svg { width: 14px; height: 14px; fill: #000; }

.station-fav-btn {
  width: 32px; height: 32px;
  border-radius: 50%;
  border: none;
  background: none;
  color: var(--text-muted);
  cursor: pointer;
  display: grid;
  place-items: center;
}

.station-fav-btn:hover { color: var(--text-primary); }
.station-fav-btn svg { width: 18px; height: 18px; fill: currentColor; }
.station-fav-btn.favorited { color: var(--accent); }
.station-fav-btn.favorited svg { fill: var(--accent); }

.radio-loading { padding: 40px; display: grid; place-items: center; grid-column: 1/-1; }
.radio-empty { padding: 40px; color: var(--text-muted); grid-column: 1/-1; }

/* ============ TV ============ */
.tv-section { padding: 24px 32px 40px; }

.tv-section h2 {
  font-size: 24px;
  font-weight: 800;
  letter-spacing: -.02em;
  margin-bottom: 20px;
}

.tv-toolbar { display: flex; gap: 12px; margin-bottom: 24px; flex-wrap: wrap; }

.tv-toolbar input, .tv-toolbar select {
  padding: 10px 14px;
  background: var(--bg-elevated);
  border: 1px solid var(--line);
  border-radius: 500px;
  color: var(--text-primary);
  font-size: 13px;
  font-family: inherit;
  outline: none;
}

.tv-toolbar input:focus, .tv-toolbar select:focus { border-color: var(--text-primary); }
.tv-toolbar input { min-width: 240px; }

.tv-loading { padding: 30px; text-align: center; color: var(--text-muted); }

.tv-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
}

.tv-card {
  background: var(--bg-tertiary);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: background .2s;
}

.tv-card:hover { background: var(--bg-hover); }

.tv-thumb {
  aspect-ratio: 16/9;
  background: var(--bg-elevated);
  display: grid;
  place-items: center;
  /* position:relative + overflow:hidden para que un logo cuadrado
     (512x512) no estire la caja y rompa la proporción 16:9 */
  position: relative;
  overflow: hidden;
}

.tv-thumb img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
}
.tv-thumb .emoji-thumb { font-size: 40px; }

.tv-info { padding: 12px; }

.tv-name {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 8px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tv-country-badge, .tv-category-badge {
  display: inline-block;
  padding: 3px 8px;
  background: var(--bg-elevated);
  border-radius: 500px;
  font-size: 11px;
  font-weight: 600;
  margin-right: 4px;
}

/* Estado de salud del canal (sondeo real del stream) */
.tv-status-badge {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 500px;
  font-size: 11px;
  font-weight: 700;
  margin-right: 4px;
}
.tv-status-badge.alive { background: rgba(30, 215, 96, .18); color: #1ed760; }
.tv-status-badge.dead { background: rgba(255, 82, 82, .18); color: #ff5252; }
.tv-status-badge.unknown { background: var(--bg-elevated); color: var(--text-muted); }

/* Canal caido: se apaga pero sigue visible cuando el filtro esta off */
.tv-card.is-dead { opacity: .45; }
.tv-card.is-dead:hover { opacity: .7; }
.tv-card.is-dead .tv-thumb img { filter: grayscale(1); }

/* Boton "Solo vivos" en la barra de filtros */
.tv-alive-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  background: var(--bg-elevated);
  border: 1px solid transparent;
  border-radius: 500px;
  color: var(--text-primary);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
.tv-alive-toggle:hover { background: var(--bg-hover); }
.tv-alive-toggle.on { background: rgba(30, 215, 96, .16); color: #1ed760; border-color: rgba(30, 215, 96, .35); }
.tv-alive-toggle .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--text-muted);
}
.tv-alive-toggle.on .dot { background: #1ed760; }

.tv-count {
  font-size: 13px;
  color: var(--text-muted);
  margin-left: auto;
  white-space: nowrap;
}

.tv-watch-btn {
  margin-top: 10px;
  width: 100%;
  padding: 8px;
  background: var(--bg-elevated);
  border: none;
  border-radius: 500px;
  color: var(--text-primary);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
}

.tv-watch-btn:hover { background: var(--bg-hover); }

.tv-show-more button {
  padding: 12px 28px;
  background: var(--bg-elevated);
  border: none;
  border-radius: 500px;
  color: var(--text-primary);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
}

.tv-show-more button:hover { background: var(--bg-hover); }

/* ============ TV PLAYER MODAL ============ */
#tvPlayerModal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.92);
  z-index: 2800;
  display: none;
  flex-direction: column;
}

#tvPlayerModal.show { display: flex; }

.tv-player-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 24px;
}

.tv-player-title { font-size: 18px; font-weight: 700; }

.tv-close-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 32px;
  cursor: pointer;
  line-height: 1;
}

.tv-close-btn:hover { color: var(--text-primary); }

#tvPlayerContainer { flex: 1; display: grid; place-items: center; }
#tvPlayerContainer video { width: 100%; height: 100%; max-height: 80vh; }
#tvPlayerContainer iframe { width: 100%; height: 100%; border: none; }

/* ============ TOAST ============ */
.toast {
  position: fixed;
  left: 50%;
  bottom: 110px;
  transform: translate(-50%, 20px);
  background: var(--accent);
  color: #000;
  padding: 12px 20px;
  border-radius: 4px;
  font-size: 13px;
  font-weight: 700;
  z-index: 4000;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
}

.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: #e74c3c; color: #fff; }

/* ============ RESPONSIVE (móvil / PWA) ============ */
@media (max-width: 900px) {
  #sidebar {
    position: fixed;
    top: 0;
    bottom: var(--player-h);
    left: 0;
    z-index: 1200;
    background: var(--bg-tertiary);
    box-shadow: 4px 0 24px rgba(0,0,0,.6);
    margin-left: calc(var(--sidebar-w) * -1);
  }

  #sidebar.open { margin-left: 0; }

  #sidebarHeader {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    font-size: 15px;
    font-weight: 700;
    flex-shrink: 0;
  }

  #closeSidebarBtn {
    display: grid;
    place-items: center;
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 26px;
    cursor: pointer;
    line-height: 1;
  }

  #hamburgerBtn { display: grid; }

  .main-search {
    position: static;
    transform: none;
    width: auto;
    max-width: none;
    margin: 12px 16px 0;
    height: 44px;
  }

  /* El buscador no debe empujar la barra superior: se encoge. */
  header {
    height: auto;
    flex-wrap: wrap;
    padding: 8px 16px 0;
    gap: 8px;
  }

  .main-search { order: 3; flex: 1 0 100%; }

  .user-info { margin-left: auto; }

  .user-info .username { display: none; }

  .section-container { padding-top: 16px; }

  .playlist-hero { flex-direction: column; align-items: flex-start; padding: 16px; }
  .playlist-hero-art { width: 140px; height: 140px; }
  .playlist-hero-title { font-size: 28px; }
  .playlist-actions { padding: 0 16px 16px; }
  .playlist-table-head { display: none; }

  .playlist-song {
    grid-template-columns: 30px minmax(0, 1fr) 60px 30px;
    padding: 8px 16px;
    gap: 10px;
  }

  .song-album { display: none; }
  .search-section { padding: 0 16px 40px; }
  .search-results { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; }

  .player-bar { grid-template-columns: 1fr auto; padding: 0 12px; gap: 10px; }
  .volume-container { display: none; }
  .progress-container { display: none; }
  .now-playing-thumb { width: 44px; height: 44px; }
}

@media (max-width: 560px) {
  .search-results { grid-template-columns: repeat(2, 1fr); }
  .radio-results { grid-template-columns: 1fr; }
  .tv-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
  .user-avatar { width: 88px; height: 88px; font-size: 36px; }
}

/* Pantallas anchas: sidebar siempre visible */
@media (min-width: 901px) {
  #sidebarOverlay { display: none !important; }
}
