/* ===== RESET & BASE ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg-main: #1a1a1a;
  --bg-sidebar: #2a2a2a;
  --bg-topbar: #3a3a3a;
  --bg-content: #111;
  --bg-row-hover: #2c2c2c;
  --bg-row-active: #1a4a7a;
  --text-primary: #e0e0e0;
  --text-secondary: #888;
  --text-accent: #5b9bd5;
  --border-color: #444;
  --btn-bg: #555;
  --btn-hover: #666;
  --scrollbar-bg: #222;
  --scrollbar-thumb: #555;
  --sidebar-width: 180px;
  --topbar-height: 72px;
  --font-size-base: 12px;
}

body.theme-light {
  --bg-main: #f0f0f0;
  --bg-sidebar: #ddd;
  --bg-topbar: #c8c8c8;
  --bg-content: #fafafa;
  --bg-row-hover: #e8e8e8;
  --bg-row-active: #b3d4f5;
  --text-primary: #111;
  --text-secondary: #555;
  --border-color: #bbb;
  --btn-bg: #ccc;
  --btn-hover: #bbb;
  --scrollbar-bg: #ddd;
  --scrollbar-thumb: #aaa;
}

body.theme-blue {
  --bg-main: #0d1b2a;
  --bg-sidebar: #112233;
  --bg-topbar: #1a3050;
  --bg-content: #0a1520;
  --bg-row-hover: #1a2d40;
  --bg-row-active: #1a5080;
  --text-primary: #c0d8f0;
  --text-secondary: #6090b0;
  --border-color: #2a4060;
  --btn-bg: #1a3050;
  --btn-hover: #2a4060;
}

body.font-small { --font-size-base: 11px; }
body.font-large { --font-size-base: 14px; }

html, body {
  height: 100%;
  overflow: hidden;
  font-family: 'Lucida Grande', 'Segoe UI', Arial, sans-serif;
  font-size: var(--font-size-base);
  background: var(--bg-main);
  color: var(--text-primary);
  user-select: none;
}

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--scrollbar-bg); }
::-webkit-scrollbar-thumb { background: var(--scrollbar-thumb); border-radius: 4px; }

/* ===== TOP BAR ===== */
#top-bar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--topbar-height);
  background: linear-gradient(to bottom, #4a4a4a 0%, #2e2e2e 100%);
  border-bottom: 1px solid #111;
  display: flex;
  align-items: center;
  padding: 0 12px;
  gap: 12px;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(0,0,0,0.6);
}

/* Controls */
#controls {
  display: flex;
  align-items: center;
  gap: 4px;
}

#controls button {
  background: radial-gradient(circle at 40% 35%, #888 0%, #444 60%, #222 100%);
  border: 1px solid #222;
  border-radius: 50%;
  width: 32px; height: 32px;
  color: #ddd;
  font-size: 10px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 2px 4px rgba(0,0,0,0.5), inset 0 1px 1px rgba(255,255,255,0.15);
  transition: all 0.1s;
}

#btn-play {
  width: 40px !important;
  height: 40px !important;
  font-size: 14px !important;
  background: radial-gradient(circle at 40% 35%, #aaa 0%, #666 60%, #333 100%) !important;
}

#controls button:hover { filter: brightness(1.2); }
#controls button:active { transform: scale(0.95); }

/* Volume */
#volume-section {
  display: flex;
  align-items: center;
  gap: 4px;
}
.icon-vol { font-size: 14px; color: var(--text-secondary); }
#volume { width: 70px; accent-color: var(--text-accent); }

/* Track info */
#track-info {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
  background: rgba(0,0,0,0.3);
  border-radius: 6px;
  padding: 4px 8px;
  border: 1px solid #222;
}

#album-art-small {
  width: 44px; height: 44px;
  background: #333;
  border-radius: 3px;
  flex-shrink: 0;
  background-size: cover;
  background-position: center;
  border: 1px solid #555;
}

#track-details { min-width: 0; }
#track-name {
  font-size: 13px;
  font-weight: bold;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 200px;
}
#track-artist {
  font-size: 11px;
  color: var(--text-secondary);
}

/* Progress */
#progress-section {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1.5;
}
#progress { flex: 1; accent-color: var(--text-accent); }
#time-current, #time-total {
  font-size: 11px;
  color: var(--text-secondary);
  min-width: 32px;
  text-align: center;
}

/* Extra controls */
#extra-controls {
  display: flex;
  align-items: center;
  gap: 6px;
}

.ctrl-btn {
  background: var(--btn-bg);
  border: 1px solid #333;
  border-radius: 4px;
  color: var(--text-secondary);
  width: 28px; height: 24px;
  cursor: pointer;
  font-size: 13px;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.15s;
}
.ctrl-btn:hover { background: var(--btn-hover); color: var(--text-primary); }
.ctrl-btn.active { color: var(--text-accent); background: #1a3a5a; border-color: var(--text-accent); }

#search {
  background: rgba(0,0,0,0.4);
  border: 1px solid #555;
  border-radius: 12px;
  color: var(--text-primary);
  padding: 3px 10px;
  font-size: 11px;
  width: 130px;
  outline: none;
}
#search:focus { border-color: var(--text-accent); }

/* ===== MAIN LAYOUT ===== */
#main-layout {
  display: flex;
  position: fixed;
  top: var(--topbar-height);
  left: 0; right: 0; bottom: 0;
}

/* ===== SIDEBAR ===== */
#sidebar {
  width: var(--sidebar-width);
  background: linear-gradient(to bottom, #2e2e2e 0%, #222 100%);
  border-right: 1px solid #111;
  overflow-y: auto;
  flex-shrink: 0;
  padding-bottom: 20px;
}

.sidebar-section { margin-top: 16px; }

.sidebar-title {
  font-size: 10px;
  font-weight: bold;
  color: #666;
  padding: 4px 12px;
  letter-spacing: 0.5px;
}

.sidebar-section ul { list-style: none; }

.sidebar-item {
  padding: 5px 12px;
  cursor: pointer;
  font-size: 12px;
  color: var(--text-secondary);
  border-radius: 4px;
  margin: 1px 4px;
  transition: background 0.15s, color 0.15s;
}
.sidebar-item:hover { background: rgba(255,255,255,0.07); color: var(--text-primary); }
.sidebar-item.active {
  background: linear-gradient(to bottom, #3a6ea8, #2a5a90);
  color: #fff;
}

#btn-new-playlist {
  background: none;
  border: none;
  color: var(--text-accent);
  font-size: 11px;
  cursor: pointer;
  padding: 4px 12px;
  margin-top: 4px;
}
#btn-new-playlist:hover { text-decoration: underline; }

/* ===== CONTENT ===== */
#content {
  flex: 1;
  overflow: hidden;
  position: relative;
  background: var(--bg-content);
}

.view { display: none; width: 100%; height: 100%; overflow: hidden; }
.view.active { display: flex; flex-direction: column; }

/* ===== COVERFLOW ===== */
#view-coverflow { background: linear-gradient(to bottom, #111 0%, #000 100%); }

#coverflow-container {
  height: 280px;
  position: relative;
  overflow: hidden;
  background: linear-gradient(to bottom, #1a1a1a 0%, #000 100%);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

#coverflow-track {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  position: relative;
  perspective: 800px;
}

/* Reflection line */
#coverflow-container::after {
  content: '';
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 1px;
  background: linear-gradient(to right, transparent, #444, transparent);
}

#coverflow-title {
  position: absolute;
  bottom: 8px;
  left: 50%;
  transform: translateX(-50%);
  text-align: center;
  color: #fff;
  font-size: 13px;
  font-weight: bold;
  text-shadow: 0 1px 3px rgba(0,0,0,0.8);
  white-space: nowrap;
  pointer-events: none;
}

.cf-item {
  position: absolute;
  width: 160px;
  height: 160px;
  cursor: pointer;
  transition: transform 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94),
              opacity 0.4s ease,
              left 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94);
  transform-style: preserve-3d;
  border: 1px solid rgba(255,255,255,0.1);
}

.cf-item img, .cf-item .cf-placeholder {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.cf-placeholder {
  background: linear-gradient(160deg, #3a3a5a 0%, #1a1a2e 60%, #0d0d1a 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  color: #555;
  border: 1px solid #2a2a3a;
}
.cf-placeholder::before {
  content: '♫';
  font-size: 52px;
  color: #4a4a6a;
  text-shadow: 0 2px 8px rgba(0,0,0,0.8);
  line-height: 1;
}
.cf-placeholder::after {
  content: attr(data-album);
  font-size: 10px;
  color: #444;
  text-align: center;
  padding: 0 8px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 140px;
}

.cf-reflection {
  position: absolute;
  top: 100%;
  left: 0; right: 0;
  height: 80px;
  background: linear-gradient(to bottom, rgba(255,255,255,0.15) 0%, transparent 100%);
  transform: scaleY(-1);
  opacity: 0.4;
  pointer-events: none;
}

/* Song list below coverflow */
#song-list-below {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}

.song-row-cf {
  display: flex;
  align-items: center;
  padding: 4px 20px;
  cursor: pointer;
  border-bottom: 1px solid rgba(255,255,255,0.03);
  transition: background 0.1s;
}
.song-row-cf:hover { background: var(--bg-row-hover); }
.song-row-cf.playing { color: var(--text-accent); }
.song-row-cf .sr-num { width: 28px; color: var(--text-secondary); font-size: 11px; }
.song-row-cf .sr-title { flex: 1; font-size: 12px; }
.song-row-cf .sr-artist { width: 140px; color: var(--text-secondary); font-size: 11px; }
.song-row-cf .sr-dur { width: 50px; text-align: right; color: var(--text-secondary); font-size: 11px; }

/* ===== LIST VIEW ===== */
#view-list { overflow: hidden; }

#song-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--font-size-base);
}

#song-table thead {
  position: sticky;
  top: 0;
  background: linear-gradient(to bottom, #3a3a3a, #2a2a2a);
  z-index: 10;
}

#song-table th {
  padding: 6px 10px;
  text-align: left;
  color: var(--text-secondary);
  font-weight: normal;
  border-bottom: 1px solid #111;
  cursor: pointer;
  white-space: nowrap;
  font-size: 11px;
}
#song-table th:hover { color: var(--text-primary); }
#song-table th.sorted-asc::after { content: ' ▲'; }
#song-table th.sorted-desc::after { content: ' ▼'; }

#view-list { overflow-y: auto; }

#song-table tbody tr {
  cursor: pointer;
  border-bottom: 1px solid rgba(255,255,255,0.03);
  transition: background 0.1s;
}
#song-table tbody tr:hover { background: var(--bg-row-hover); }
#song-table tbody tr.playing { background: var(--bg-row-active); color: #fff; }
#song-table tbody tr.selected { background: rgba(90,155,213,0.2); }

#song-table td {
  padding: 5px 10px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 200px;
}
#song-table td:first-child { color: var(--text-secondary); width: 36px; text-align: right; }

/* ===== ALBUMS GRID ===== */
#view-albums { overflow-y: auto; padding: 20px; }
#albums-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 16px;
}

.album-card {
  cursor: pointer;
  text-align: center;
  transition: transform 0.2s;
}
.album-card:hover { transform: scale(1.05); }
.album-card .album-cover {
  width: 100%;
  aspect-ratio: 1;
  background: linear-gradient(135deg, #2a2a4a, #1a1a2a);
  border-radius: 4px;
  display: flex; align-items: center; justify-content: center;
  font-size: 40px;
  color: #444;
  margin-bottom: 6px;
  overflow: hidden;
  border: 1px solid #333;
}
.album-card .album-cover img { width: 100%; height: 100%; object-fit: cover; }
.album-card .album-name { font-size: 11px; color: var(--text-primary); margin-bottom: 2px; }
.album-card .album-artist { font-size: 10px; color: var(--text-secondary); }

/* ===== ARTISTS / GENRES ===== */
#view-artists, #view-genres { overflow-y: auto; padding: 10px; }
#artists-list-view, #genres-list-view {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px;
}

.artist-chip, .genre-chip {
  background: var(--bg-sidebar);
  border: 1px solid var(--border-color);
  border-radius: 20px;
  padding: 6px 14px;
  cursor: pointer;
  font-size: 12px;
  transition: all 0.15s;
}
.artist-chip:hover, .genre-chip:hover {
  background: var(--bg-row-active);
  color: #fff;
  border-color: var(--text-accent);
}

/* ===== SETTINGS ===== */
#view-settings { overflow-y: auto; }
#settings-panel {
  max-width: 600px;
  margin: 20px auto;
  padding: 20px;
}
#settings-panel h2 {
  font-size: 18px;
  margin-bottom: 16px;
  color: var(--text-primary);
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 8px;
}

.settings-tabs {
  display: flex;
  gap: 2px;
  margin-bottom: 20px;
  border-bottom: 1px solid var(--border-color);
}
.stab {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-secondary);
  padding: 8px 16px;
  cursor: pointer;
  font-size: 12px;
  transition: all 0.15s;
  margin-bottom: -1px;
}
.stab:hover { color: var(--text-primary); }
.stab.active { color: var(--text-accent); border-bottom-color: var(--text-accent); }

.stab-content { display: none; }
.stab-content.active { display: block; }

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid rgba(255,255,255,0.05);
}
.setting-row label {
  color: var(--text-primary);
  font-size: 12px;
  flex: 1;
}
.setting-control {
  display: flex;
  align-items: center;
  gap: 8px;
}
.setting-control input[type="range"] { width: 120px; accent-color: var(--text-accent); }
.setting-control select, .setting-control input[type="number"] {
  background: var(--bg-sidebar);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 12px;
  outline: none;
}
.setting-control button {
  background: var(--btn-bg);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  padding: 5px 12px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 11px;
  transition: background 0.15s;
}
.setting-control button:hover { background: var(--btn-hover); }
.setting-control button.danger { background: #5a1a1a; border-color: #8a2a2a; }
.setting-control button.danger:hover { background: #7a2a2a; }
.setting-control input[type="checkbox"] {
  width: 16px; height: 16px;
  accent-color: var(--text-accent);
  cursor: pointer;
}

/* ===== CONTEXT MENU ===== */
#context-menu {
  display: none;
  position: fixed;
  background: #2a2a2a;
  border: 1px solid #555;
  border-radius: 6px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.6);
  z-index: 1000;
  min-width: 160px;
  overflow: hidden;
}
#context-menu ul { list-style: none; }
#context-menu li {
  padding: 8px 16px;
  cursor: pointer;
  font-size: 12px;
  color: var(--text-primary);
  transition: background 0.1s;
}
#context-menu li:hover { background: var(--bg-row-active); }

/* ===== MODAL ===== */
#modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
}
#modal-info {
  background: #2a2a2a;
  border: 1px solid #555;
  border-radius: 8px;
  padding: 24px;
  min-width: 320px;
  max-width: 480px;
}
#modal-info h3 { margin-bottom: 16px; font-size: 15px; }
#modal-body { font-size: 12px; line-height: 1.8; color: var(--text-secondary); }
#modal-body strong { color: var(--text-primary); }
#modal-close {
  margin-top: 16px;
  background: var(--btn-bg);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  padding: 6px 20px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
}
#modal-close:hover { background: var(--btn-hover); }

/* ===== VISUALIZER ===== */
#visualizer {
  position: fixed;
  bottom: 0; left: var(--sidebar-width); right: 0;
  height: 60px;
  pointer-events: none;
  z-index: 50;
  opacity: 0.5;
}

/* ===== DRAG OVER ===== */
body.drag-over::after {
  content: 'Suelta los archivos de audio aquí';
  position: fixed;
  inset: 0;
  background: rgba(30, 80, 150, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  color: #fff;
  z-index: 9999;
  pointer-events: none;
}

/* ===== EMPTY STATE ===== */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-secondary);
  gap: 8px;
}
.empty-state .es-icon { font-size: 64px; opacity: 0.3; }
.empty-state p { font-size: 14px; }
.empty-state button {
  background: var(--text-accent);
  border: none;
  color: #fff;
  padding: 8px 20px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  transition: filter 0.15s;
}
.empty-state button:hover { filter: brightness(1.2); }

/* ===== PLAYING INDICATOR ===== */
@keyframes eq-bar {
  0%, 100% { transform: scaleY(0.3); }
  50% { transform: scaleY(1); }
}
.eq-icon {
  display: inline-flex;
  align-items: flex-end;
  gap: 1px;
  height: 12px;
  margin-right: 4px;
}
.eq-icon span {
  display: block;
  width: 2px;
  background: var(--text-accent);
  transform-origin: bottom;
  animation: eq-bar 0.6s ease-in-out infinite;
}
.eq-icon span:nth-child(2) { animation-delay: 0.2s; }
.eq-icon span:nth-child(3) { animation-delay: 0.4s; }
