/* === Reset & Base === */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg-primary: #f5f0fa;
  --bg-secondary: #ede5f5;
  --bg-sidebar: #efe6f7;
  --bg-card: #ffffff;
  --bg-player: #ddd0ee;
  --text-primary: #3d2a5c;
  --text-secondary: #7a6895;
  --accent: #9b72cf;
  --accent-light: #c4a8e6;
  --accent-hover: #8455b8;
  --accent-glow: rgba(155, 114, 207, 0.3);
  --border: #e0d4f0;
  --shadow: rgba(100, 60, 150, 0.08);
  --radius: 12px;
  --radius-sm: 8px;
  --transition: 0.2s ease;
  --sidebar-width: 280px;
  --player-height: 76px;
}

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

.app {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  grid-template-rows: 1fr auto;
  grid-template-areas:
    "sidebar main"
    "player player";
  height: 100vh;
}

/* === Sidebar === */
.sidebar {
  grid-area: sidebar;
  background: var(--bg-sidebar);
  border-right: 1.5px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-header {
  padding: 20px 20px 12px;
  border-bottom: 1px solid var(--border);
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-icon {
  width: 26px;
  height: 26px;
  color: var(--accent);
}

.logo h1 {
  font-size: 20px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.5px;
}

.sidebar-nav {
  padding: 12px 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  border-bottom: 1px solid var(--border);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  background: none;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  text-align: left;
  transition: background var(--transition), color var(--transition);
}

.nav-item svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.nav-item:hover {
  background: rgba(155, 114, 207, 0.1);
  color: var(--text-primary);
}

.nav-item.active {
  background: var(--accent);
  color: white;
}

.sidebar-section {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 14px 12px 12px;
}

.sidebar-section-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px 10px;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-secondary);
}

.sidebar-section-header svg {
  width: 14px;
  height: 14px;
  color: var(--accent);
}

.sidebar-section-header .fav-count {
  margin-left: auto;
  background: var(--accent-light);
  color: white;
  font-size: 11px;
  font-weight: 700;
  padding: 1px 7px;
  border-radius: 10px;
  min-width: 20px;
  text-align: center;
  text-transform: none;
  letter-spacing: 0;
}

.favorites-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding-right: 2px;
}

.fav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--transition);
  position: relative;
}

.fav-item:hover {
  background: rgba(155, 114, 207, 0.12);
}

.fav-item.playing {
  background: var(--accent);
  color: white;
}

.fav-item.playing .fav-item-name,
.fav-item.playing .fav-item-meta {
  color: white;
}

.fav-item.dragging {
  opacity: 0.4;
}

.fav-item.drag-over {
  border-top: 2px solid var(--accent);
}

.fav-drag-handle {
  cursor: grab;
  color: var(--accent-light);
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

.fav-drag-handle:active {
  cursor: grabbing;
}

.fav-drag-handle svg {
  width: 14px;
  height: 14px;
}

.fav-item.playing .fav-drag-handle {
  color: rgba(255, 255, 255, 0.7);
}

.fav-item-body {
  flex: 1;
  min-width: 0;
}

.fav-item-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.fav-item-meta {
  font-size: 11px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 1px;
}

.fav-item-remove {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  opacity: 0;
  transition: opacity var(--transition), background var(--transition);
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

.fav-item:hover .fav-item-remove {
  opacity: 1;
}

.fav-item-remove:hover {
  background: rgba(0, 0, 0, 0.08);
}

.fav-item.playing .fav-item-remove {
  color: rgba(255, 255, 255, 0.8);
}

.fav-item.playing .fav-item-remove:hover {
  background: rgba(255, 255, 255, 0.15);
}

.fav-item-remove svg {
  width: 14px;
  height: 14px;
}

.empty-state-mini {
  padding: 20px 10px;
  text-align: center;
  color: var(--text-secondary);
  font-size: 13px;
}

/* === Main === */
.main {
  grid-area: main;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  position: relative;
}

.view {
  display: none;
  flex: 1;
  overflow-y: auto;
  flex-direction: column;
}

.view.active {
  display: flex;
}

/* === Search view === */
.search-header {
  padding: 24px 32px 16px;
}

.search-box {
  display: flex;
  align-items: center;
  background: var(--bg-card);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 4px 4px 4px 14px;
  gap: 8px;
  transition: border-color var(--transition), box-shadow var(--transition);
  max-width: 640px;
}

.search-box:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.search-icon {
  width: 18px;
  height: 18px;
  color: var(--text-secondary);
  flex-shrink: 0;
}

#searchInput {
  flex: 1;
  border: none;
  outline: none;
  font-size: 15px;
  background: transparent;
  color: var(--text-primary);
}

#searchInput::placeholder {
  color: var(--accent-light);
}

.btn-search {
  background: var(--accent);
  color: white;
  border: none;
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition);
}

.btn-search:hover {
  background: var(--accent-hover);
}

.station-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 8px 32px 24px;
}

/* === Station Card === */
.station-card {
  display: flex;
  align-items: center;
  background: var(--bg-card);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  gap: 12px;
  cursor: pointer;
  transition: border-color var(--transition), box-shadow var(--transition), transform var(--transition);
}

.station-card:hover {
  border-color: var(--accent-light);
  box-shadow: 0 2px 12px var(--shadow);
}

.station-card.playing {
  border-color: var(--accent);
  background: linear-gradient(135deg, #faf7ff 0%, #f0e8fa 100%);
}

.station-play-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: background var(--transition), transform var(--transition);
}

.station-play-btn:hover {
  background: var(--accent-hover);
  transform: scale(1.05);
}

.station-play-btn svg {
  width: 18px;
  height: 18px;
}

.station-info {
  flex: 1;
  min-width: 0;
}

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

.station-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 3px;
}

.station-bitrate {
  font-size: 12px;
  color: var(--text-secondary);
  background: var(--bg-secondary);
  padding: 2px 8px;
  border-radius: 4px;
  font-weight: 500;
}

.station-country {
  font-size: 12px;
  color: var(--text-secondary);
}

.station-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.btn-icon {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
}

.btn-icon:hover {
  background: var(--bg-secondary);
  color: var(--accent);
}

.btn-icon.is-favorite {
  color: var(--accent);
}

.btn-icon svg {
  width: 18px;
  height: 18px;
}

/* === Now Playing View === */
.now-playing {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
}

.np-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  max-width: 480px;
  width: 100%;
  gap: 24px;
}

.np-artwork {
  width: 220px;
  height: 220px;
  border-radius: 24px;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-hover) 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  box-shadow: 0 12px 40px var(--accent-glow);
  position: relative;
  overflow: hidden;
}

.np-artwork img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.np-artwork svg {
  width: 90px;
  height: 90px;
  opacity: 0.95;
}

.np-artwork.is-playing {
  animation: pulse 2.4s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 12px 40px var(--accent-glow); }
  50% { box-shadow: 0 12px 60px rgba(155, 114, 207, 0.55); }
}

.np-title {
  font-size: 24px;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.2;
  word-break: break-word;
}

.np-meta {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
  color: var(--text-secondary);
  font-size: 14px;
}

.np-meta span {
  background: var(--bg-secondary);
  padding: 4px 12px;
  border-radius: 12px;
  font-weight: 500;
}

.np-actions {
  display: flex;
  gap: 12px;
  align-items: center;
}

.np-big-play {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background var(--transition), transform var(--transition);
}

.np-big-play:hover {
  background: var(--accent-hover);
  transform: scale(1.05);
}

.np-big-play svg {
  width: 32px;
  height: 32px;
}

.np-fav-btn {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--bg-card);
  border: 1.5px solid var(--border);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all var(--transition);
}

.np-fav-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.np-fav-btn.is-favorite {
  color: var(--accent);
  border-color: var(--accent);
}

.np-fav-btn svg {
  width: 20px;
  height: 20px;
}

/* === Empty State === */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  color: var(--text-secondary);
  text-align: center;
  flex: 1;
}

.empty-icon {
  width: 48px;
  height: 48px;
  color: var(--accent-light);
  margin-bottom: 12px;
}

.empty-state p {
  font-size: 15px;
}

.empty-state .empty-hint {
  font-size: 13px;
  margin-top: 6px;
  opacity: 0.8;
}

/* === Loading === */
.loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px;
  gap: 12px;
  position: absolute;
  inset: 0;
  background: var(--bg-primary);
  z-index: 5;
}

.loading.hidden {
  display: none;
}

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.loading p {
  font-size: 14px;
  color: var(--text-secondary);
}

/* === Player Bar === */
.player-bar {
  grid-area: player;
  background: var(--bg-player);
  border-top: 1.5px solid var(--border);
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.player-bar.no-station .player-info,
.player-bar.no-station #playPauseBtn {
  opacity: 0.45;
  pointer-events: none;
}

.player-info {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  flex: 1;
}

.now-playing-indicator {
  display: flex;
  align-items: flex-end;
  gap: 2px;
  height: 18px;
}

.now-playing-indicator .bar {
  width: 3px;
  background: var(--accent);
  border-radius: 2px;
  animation: equalizer 0.8s ease-in-out infinite alternate;
}

.now-playing-indicator .bar:nth-child(1) { height: 8px; animation-delay: 0s; }
.now-playing-indicator .bar:nth-child(2) { height: 14px; animation-delay: 0.2s; }
.now-playing-indicator .bar:nth-child(3) { height: 10px; animation-delay: 0.4s; }

.player-bar.paused .now-playing-indicator .bar {
  animation-play-state: paused;
}

@keyframes equalizer {
  0% { height: 4px; }
  100% { height: 18px; }
}

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

.player-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.player-bitrate {
  font-size: 12px;
  color: var(--text-secondary);
}

.player-controls {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.btn-play {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background var(--transition), transform var(--transition);
}

.btn-play:hover {
  background: var(--accent-hover);
  transform: scale(1.05);
}

.btn-play svg {
  width: 22px;
  height: 22px;
}

.btn-play svg.hidden {
  display: none;
}

.volume-control {
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-mute {
  background: none;
  border: none;
  padding: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  border-radius: 6px;
  transition: background var(--transition), color var(--transition);
}

.btn-mute:hover {
  background: rgba(155, 114, 207, 0.15);
  color: var(--accent);
}

.btn-mute.muted {
  color: var(--accent);
}

.volume-icon {
  width: 18px;
  height: 18px;
}

.volume-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 130px;
  height: 6px;
  background: var(--accent-light);
  border-radius: 3px;
  outline: none;
  cursor: pointer;
  flex-shrink: 0;
}

.volume-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: 2px solid white;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
  transition: transform var(--transition);
}

.volume-slider::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: 2px solid white;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.volume-slider::-webkit-slider-thumb:hover {
  transform: scale(1.15);
}

.volume-value {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  min-width: 28px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* === Scrollbar === */
.view::-webkit-scrollbar,
.favorites-list::-webkit-scrollbar {
  width: 6px;
}

.view::-webkit-scrollbar-track,
.favorites-list::-webkit-scrollbar-track {
  background: transparent;
}

.view::-webkit-scrollbar-thumb,
.favorites-list::-webkit-scrollbar-thumb {
  background: var(--accent-light);
  border-radius: 3px;
}

/* === Hidden utility === */
.hidden {
  display: none !important;
}

/* === Responsive === */
@media (max-width: 720px) {
  :root { --sidebar-width: 220px; }
  .search-header { padding: 16px 20px 12px; }
  .station-list { padding: 8px 20px 20px; }
  .np-artwork { width: 180px; height: 180px; }
  .np-title { font-size: 20px; }
}
