/**
 * Reusable UI Components
 * Common component styles that can be used across the application
 */

/* ==================== Cards ==================== */

.card {
  background: var(--surface);
  backdrop-filter: blur(18px);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg, 28px);
  box-shadow: var(--shadow, 0 30px 80px rgba(0, 0, 0, 0.35));
  padding: 28px;
  transition: transform 180ms ease, box-shadow 180ms ease;
}

.card:hover {
  transform: translateY(-2px);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
}

.card-sm {
  padding: 18px;
  border-radius: var(--radius-md, 20px);
}

.card-lg {
  padding: 42px;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 20px;
}

.card-title {
  margin: 0;
  font-size: clamp(1.2rem, 2vw, 1.6rem);
  letter-spacing: -0.02em;
}

.card-subtitle {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

/* ==================== Buttons ==================== */

.btn-group {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.btn-sm {
  padding: 10px 14px;
  font-size: 0.85rem;
  border-radius: 12px;
}

.btn-lg {
  padding: 16px 24px;
  font-size: 1.1rem;
  border-radius: 18px;
}

.btn-icon {
  width: 42px;
  height: 42px;
  padding: 0;
  display: inline-grid;
  place-items: center;
  border-radius: 12px;
}

.btn-ghost {
  background: transparent;
  border: 1px solid transparent;
  color: var(--muted);
}

.btn-ghost:hover {
  background: rgba(255, 255, 255, 0.06);
  border-color: var(--line);
  color: var(--text);
}

.btn-gradient {
  background: linear-gradient(135deg, var(--primary), var(--primary-strong));
  color: #04111d;
  border: 0;
}

.btn-gradient:hover {
  filter: brightness(1.1);
}

/* ==================== Badges ==================== */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 0.85rem;
  color: var(--muted);
}

.badge-success {
  background: color-mix(in srgb, var(--primary) 20%, transparent);
  border-color: color-mix(in srgb, var(--primary) 40%, transparent);
  color: #b7ffe4;
}

.badge-warning {
  background: rgba(255, 193, 7, 0.15);
  border-color: rgba(255, 193, 7, 0.3);
  color: #ffd54f;
}

.badge-danger {
  background: rgba(255, 107, 122, 0.15);
  border-color: rgba(255, 107, 122, 0.3);
  color: #ffd2d8;
}

.badge-info {
  background: rgba(63, 210, 255, 0.15);
  border-color: rgba(63, 210, 255, 0.3);
  color: #80d8ff;
}

/* ==================== Forms ==================== */

.form-group {
  display: grid;
  gap: 8px;
  margin-bottom: 16px;
}

.form-label {
  font-weight: 500;
  color: var(--text);
  font-size: 0.95rem;
}

.form-hint {
  font-size: 0.85rem;
  color: var(--muted);
  margin-top: 4px;
}

.form-error {
  font-size: 0.85rem;
  color: #ff8361;
  margin-top: 4px;
}

.input-group {
  position: relative;
}

.input-group .input-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  pointer-events: none;
}

.input-group input {
  padding-left: 42px;
}

.input-with-btn {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: end;
}

/* ==================== Avatars ==================== */

.avatar-xs {
  width: 28px;
  height: 28px;
  font-size: 0.8rem;
}

.avatar-sm {
  width: 36px;
  height: 36px;
  font-size: 1rem;
}

.avatar-md {
  width: 48px;
  height: 48px;
  font-size: 1.4rem;
}

.avatar-lg {
  width: 80px;
  height: 80px;
  font-size: 2rem;
}

.avatar-xl {
  width: 120px;
  height: 120px;
  font-size: 3rem;
  border: 4px solid var(--surface);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
}

.avatar-group {
  display: flex;
}

.avatar-group .avatar {
  border: 2px solid var(--surface);
  margin-left: -10px;
}

.avatar-group .avatar:first-child {
  margin-left: 0;
}

/* ==================== Stats ==================== */

.stats-row {
  display: flex;
  gap: 24px;
  flex-wrap: wrap;
}

.stat {
  display: grid;
  text-align: center;
  gap: 4px;
}

.stat-value {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--primary);
  letter-spacing: -0.03em;
}

.stat-label {
  font-size: 0.85rem;
  color: var(--muted);
}

/* ==================== Empty States ==================== */

.empty-state-card {
  padding: 40px 24px;
  text-align: center;
  border: 1px dashed var(--line);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.02);
}

.empty-state-icon {
  font-size: 3rem;
  color: var(--muted);
  opacity: 0.5;
  margin-bottom: 16px;
}

.empty-state-title {
  margin: 0 0 8px;
  font-size: 1.2rem;
  color: var(--text);
}

.empty-state-text {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
}

/* ==================== Loading ==================== */

.loading-spinner {
  display: grid;
  place-items: center;
  padding: 40px;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--line);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

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

.loading-dots {
  display: flex;
  gap: 8px;
  justify-content: center;
  padding: 20px;
}

.loading-dots span {
  width: 8px;
  height: 8px;
  background: var(--primary);
  border-radius: 50%;
  animation: bounce 1.4s infinite ease-in-out both;
}

.loading-dots span:nth-child(1) { animation-delay: -0.32s; }
.loading-dots span:nth-child(2) { animation-delay: -0.16s; }

@keyframes bounce {
  0%, 80%, 100% { transform: scale(0); }
  40% { transform: scale(1); }
}

/* ==================== Tooltips ==================== */

.tooltip {
  position: relative;
}

.tooltip::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  padding: 8px 12px;
  background: var(--surface-strong, rgba(8, 18, 34, 0.95));
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 0.85rem;
  color: var(--text);
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease;
  z-index: 100;
}

.tooltip:hover::after {
  opacity: 1;
}

/* ==================== Dropdowns ==================== */

.dropdown {
  position: relative;
}

.dropdown-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 200px;
  background: var(--surface-strong, rgba(8, 18, 34, 0.95));
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow, 0 30px 80px rgba(0, 0, 0, 0.35));
  padding: 8px;
  display: none;
  z-index: 50;
}

.dropdown-menu.show {
  display: block;
}

.dropdown-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-radius: 10px;
  color: var(--text);
  transition: background 180ms ease;
  cursor: pointer;
  border: 0;
  background: transparent;
  width: 100%;
  font: inherit;
}

.dropdown-item:hover {
  background: rgba(255, 255, 255, 0.06);
}

.dropdown-item.danger {
  color: #ff8361;
}

.dropdown-header {
  padding: 8px 14px 6px;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.playlist-option {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: 10px;
  cursor: pointer;
  transition: background 180ms ease;
}

.playlist-option:hover {
  background: rgba(255, 255, 255, 0.06);
}

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

.playlist-option-name {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.playlist-option-count {
  font-size: 0.72rem;
  color: var(--muted);
  margin-top: 2px;
}

.playlist-option-add {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: 10px;
  cursor: pointer;
  transition: background 180ms ease;
  color: var(--primary);
  font-size: 0.85rem;
  font-weight: 500;
  border-top: 1px solid var(--line);
  margin-top: 4px;
}

.playlist-option-add:hover {
  background: rgba(120, 240, 197, 0.08);
}

.playlist-option-add i {
  font-size: 0.75rem;
}

.playlist-dropdown {
  position: relative;
}

.dropdown-loading {
  padding: 12px 14px;
  font-size: 0.8rem;
  color: var(--muted);
  text-align: center;
}

.dropdown-divider {
  height: 1px;
  background: var(--line);
  margin: 8px 0;
}

/* ==================== Tabs ==================== */

.tab-content {
  padding: 20px 0;
}

/* ==================== Grids ==================== */

.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 20px;
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 20px;
}

.grid-4 {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 20px;
}

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

/* ==================== Dividers ==================== */

.divider {
  height: 1px;
  background: var(--line);
  margin: 24px 0;
}

.divider-vertical {
  width: 1px;
  background: var(--line);
  margin: 0 16px;
}

/* ==================== Skeleton Loaders ==================== */

.skeleton {
  background: linear-gradient(90deg, rgba(255, 255, 255, 0.04) 25%, rgba(255, 255, 255, 0.08) 50%, rgba(255, 255, 255, 0.04) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: 8px;
}

.skeleton-text {
  height: 14px;
  margin-bottom: 8px;
}

.skeleton-title {
  height: 20px;
  width: 60%;
  margin-bottom: 12px;
}

.skeleton-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
}

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ==================== Responsive ==================== */

@media (max-width: 760px) {
  .grid-2,
  .grid-3,
  .grid-4 {
    grid-template-columns: 1fr;
  }

  .stats-row {
    gap: 16px;
  }

  .btn-group {
    flex-direction: column;
  }

  .input-with-btn {
    grid-template-columns: 1fr;
  }
}
