/* ============================================
   Spotify Playlist Manager — Design System
   ============================================ */

/* --- CSS Custom Properties --- */
:root {
  /* Colors */
  --spotify-green: #1DB954;
  --spotify-green-dark: #1AA34A;
  --spotify-green-glow: rgba(29, 185, 84, 0.3);

  --bg-primary: #0a0a0f;
  --bg-secondary: #12121a;
  --bg-card: rgba(255, 255, 255, 0.04);
  --bg-card-hover: rgba(255, 255, 255, 0.07);
  --bg-glass: rgba(255, 255, 255, 0.06);
  --bg-input: rgba(255, 255, 255, 0.08);

  --border-color: rgba(255, 255, 255, 0.08);
  --border-color-hover: rgba(255, 255, 255, 0.15);

  --text-primary: #e8e8ed;
  --text-secondary: #8b8b9e;
  --text-muted: #5a5a6e;

  --color-success: #1DB954;
  --color-error: #e74c5e;
  --color-warning: #f0a030;

  /* Spacing */
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 16px;
  --space-lg: 24px;
  --space-xl: 32px;
  --space-2xl: 48px;

  /* Border Radius */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --radius-full: 50%;

  /* Transitions */
  --transition-fast: 150ms ease;
  --transition-normal: 250ms ease;
  --transition-slow: 400ms cubic-bezier(0.4, 0, 0.2, 1);

  /* Shadows */
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.5);
  --shadow-glow: 0 0 20px var(--spotify-green-glow);
}

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

html {
  font-size: 16px;
  scroll-behavior: smooth;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Subtle animated gradient background */
body::before {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background:
    radial-gradient(ellipse at 20% 0%, rgba(29, 185, 84, 0.08) 0%, transparent 50%),
    radial-gradient(ellipse at 80% 100%, rgba(29, 185, 84, 0.05) 0%, transparent 50%);
  pointer-events: none;
  z-index: 0;
}

/* --- Typography --- */
h1 {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

h2 {
  font-size: 1.15rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.text-muted {
  color: var(--text-muted);
  font-size: 0.875rem;
}

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: var(--space-sm);
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-normal);
  text-decoration: none;
  white-space: nowrap;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--spotify-green);
  color: #000;
}

.btn-primary:hover:not(:disabled) {
  background: var(--spotify-green-dark);
  box-shadow: var(--shadow-glow);
  transform: translateY(-1px);
}

.btn-outline {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border-color);
}

.btn-outline:hover:not(:disabled) {
  border-color: var(--border-color-hover);
  color: var(--text-primary);
  background: var(--bg-card);
}

.btn-danger {
  background: transparent;
  color: var(--color-error);
  border: 1px solid rgba(231, 76, 94, 0.3);
}

.btn-danger:hover:not(:disabled) {
  background: rgba(231, 76, 94, 0.1);
  border-color: var(--color-error);
}

.btn-sm {
  padding: 6px 12px;
  font-size: 0.8rem;
}

.btn-icon {
  padding: 8px;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border-color);
}

.btn-icon:hover {
  color: var(--text-primary);
  background: var(--bg-card);
  border-color: var(--border-color-hover);
}

.btn-spotify {
  background: var(--spotify-green);
  color: #000;
  font-size: 1rem;
  font-weight: 600;
  padding: 14px 32px;
  border-radius: var(--radius-lg);
}

.btn-spotify:hover {
  background: var(--spotify-green-dark);
  box-shadow: var(--shadow-glow);
  transform: translateY(-2px);
}

/* --- Select / Input --- */
.select {
  flex: 1;
  padding: 10px 16px;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.875rem;
  outline: none;
  cursor: pointer;
  transition: border-color var(--transition-fast);
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%238b8b9e' viewBox='0 0 24 24'%3E%3Cpath d='M7 10l5 5 5-5z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}

.select:focus {
  border-color: var(--spotify-green);
}

.select option {
  background: var(--bg-secondary);
  color: var(--text-primary);
}

/* --- Alerts --- */
.alert {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-md);
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  margin-bottom: var(--space-lg);
  animation: slideDown 0.3s ease;
}

.alert-success {
  background: rgba(29, 185, 84, 0.1);
  border: 1px solid rgba(29, 185, 84, 0.3);
  color: var(--spotify-green);
}

.alert-error {
  background: rgba(231, 76, 94, 0.1);
  border: 1px solid rgba(231, 76, 94, 0.3);
  color: var(--color-error);
}

/* --- Badge --- */
.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 24px;
  height: 24px;
  padding: 0 8px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-full);
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary);
}

/* ============================================
   Login Page
   ============================================ */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}

.login-container {
  position: relative;
  z-index: 1;
}

.login-card {
  background: var(--bg-glass);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-xl);
  padding: var(--space-2xl) var(--space-xl);
  text-align: center;
  max-width: 420px;
  width: 90vw;
  box-shadow: var(--shadow-lg);
  animation: fadeInUp 0.6s ease;
}

.login-icon {
  margin-bottom: var(--space-lg);
  animation: pulse 3s ease-in-out infinite;
}

.login-card h1 {
  font-size: 1.75rem;
  margin-bottom: var(--space-sm);
}

.login-subtitle {
  color: var(--text-secondary);
  font-size: 0.9rem;
  margin-bottom: var(--space-xl);
  line-height: 1.5;
}

.login-card .alert {
  margin-bottom: var(--space-lg);
  text-align: left;
}

.login-card .btn-spotify {
  width: 100%;
  justify-content: center;
}

/* ============================================
   Header
   ============================================ */
.header {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-md) var(--space-xl);
  background: rgba(10, 10, 15, 0.8);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border-color);
}

.header-left {
  display: flex;
  align-items: center;
  gap: var(--space-md);
}

.header-right {
  display: flex;
  align-items: center;
}

.user-info {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-full);
  object-fit: cover;
  border: 2px solid var(--border-color);
}

.user-avatar-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-card);
  color: var(--text-secondary);
  font-size: 0.875rem;
  font-weight: 600;
}

.user-name {
  font-size: 0.875rem;
  color: var(--text-secondary);
  font-weight: 500;
}

/* ============================================
   Main Content
   ============================================ */
.main {
  position: relative;
  z-index: 1;
  max-width: 960px;
  margin: 0 auto;
  padding: var(--space-xl);
}

/* --- Sections --- */
.section {
  margin-bottom: var(--space-xl);
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-md);
  gap: var(--space-md);
}

/* --- Add Playlist --- */
.add-playlist-container {
  display: flex;
  gap: var(--space-md);
  align-items: center;
}

/* --- Playlists Grid --- */
.playlists-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: var(--space-md);
}

/* --- Playlist Card --- */
.playlist-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  overflow: hidden;
  transition: all var(--transition-normal);
  animation: fadeInUp 0.4s ease;
}

.playlist-card:hover {
  background: var(--bg-card-hover);
  border-color: var(--border-color-hover);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.playlist-card-header {
  display: flex;
  gap: var(--space-md);
  padding: var(--space-md);
}

.playlist-card-image {
  width: 64px;
  height: 64px;
  border-radius: var(--radius-sm);
  object-fit: cover;
  flex-shrink: 0;
  background: var(--bg-input);
}

.playlist-card-image-placeholder {
  width: 64px;
  height: 64px;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
  background: var(--bg-input);
  display: flex;
  align-items: center;
  justify-content: center;
}

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

.playlist-card-name {
  font-size: 0.95rem;
  font-weight: 600;
  margin-bottom: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.playlist-card-meta {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.playlist-card-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-sm) var(--space-md) var(--space-md);
  gap: var(--space-sm);
}

.playlist-card-actions-left {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

/* --- Toggle Switch --- */
.toggle {
  position: relative;
  display: inline-block;
  width: 40px;
  height: 22px;
}

.toggle input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: 22px;
  transition: all var(--transition-normal);
}

.toggle-slider::before {
  content: '';
  position: absolute;
  width: 16px;
  height: 16px;
  left: 2px;
  bottom: 2px;
  background: var(--text-secondary);
  border-radius: var(--radius-full);
  transition: all var(--transition-normal);
}

.toggle input:checked + .toggle-slider {
  background: rgba(29, 185, 84, 0.2);
  border-color: var(--spotify-green);
}

.toggle input:checked + .toggle-slider::before {
  transform: translateX(18px);
  background: var(--spotify-green);
}

.toggle-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-left: var(--space-xs);
}

/* --- Status Indicators --- */
.status-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: var(--radius-full);
  margin-right: 4px;
}

.status-dot.active {
  background: var(--spotify-green);
  box-shadow: 0 0 6px var(--spotify-green-glow);
}

.status-dot.inactive {
  background: var(--text-muted);
}

/* --- Logs --- */
.logs-container {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.log-item {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  padding: var(--space-md);
  border-bottom: 1px solid var(--border-color);
  font-size: 0.85rem;
  transition: background var(--transition-fast);
}

.log-item:last-child {
  border-bottom: none;
}

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

.log-status {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.log-status.success {
  background: rgba(29, 185, 84, 0.15);
  color: var(--spotify-green);
}

.log-status.error {
  background: rgba(231, 76, 94, 0.15);
  color: var(--color-error);
}

.log-name {
  flex: 1;
  color: var(--text-primary);
  font-weight: 500;
}

.log-tracks {
  color: var(--text-secondary);
  font-size: 0.8rem;
}

.log-time {
  color: var(--text-muted);
  font-size: 0.8rem;
  white-space: nowrap;
}

/* --- Empty State --- */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-2xl);
  color: var(--text-muted);
  grid-column: 1 / -1;
}

.empty-state p {
  font-size: 0.9rem;
}

/* --- Toast Notifications --- */
#toast-container {
  position: fixed;
  bottom: var(--space-xl);
  right: var(--space-xl);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

.toast {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-md) var(--space-lg);
  background: var(--bg-glass);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  box-shadow: var(--shadow-lg);
  animation: slideInRight 0.3s ease;
  min-width: 280px;
}

.toast.success {
  border-color: rgba(29, 185, 84, 0.3);
}

.toast.error {
  border-color: rgba(231, 76, 94, 0.3);
}

.toast.fade-out {
  animation: slideOutRight 0.3s ease forwards;
}

/* --- Loading Spinner --- */
.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid var(--border-color);
  border-top-color: var(--spotify-green);
  border-radius: var(--radius-full);
  animation: spin 0.8s linear infinite;
}

.spinner-lg {
  width: 32px;
  height: 32px;
  border-width: 3px;
}

.loading-overlay {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-xl);
}

/* ============================================
   Animations
   ============================================ */
@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(16px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes slideDown {
  from {
    opacity: 0;
    transform: translateY(-8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes slideInRight {
  from {
    opacity: 0;
    transform: translateX(40px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes slideOutRight {
  from {
    opacity: 1;
    transform: translateX(0);
  }
  to {
    opacity: 0;
    transform: translateX(40px);
  }
}

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

@keyframes pulse {
  0%, 100% {
    transform: scale(1);
    opacity: 1;
  }
  50% {
    transform: scale(1.05);
    opacity: 0.8;
  }
}

/* ============================================
   Responsive
   ============================================ */
@media (max-width: 640px) {
  .main {
    padding: var(--space-md);
  }

  .header {
    padding: var(--space-md);
  }

  .add-playlist-container {
    flex-direction: column;
  }

  .select {
    width: 100%;
  }

  .btn-primary {
    width: 100%;
    justify-content: center;
  }

  .playlists-grid {
    grid-template-columns: 1fr;
  }

  .user-name {
    display: none;
  }

  #toast-container {
    right: var(--space-md);
    left: var(--space-md);
  }

  .toast {
    min-width: auto;
  }
}
