/* ==========================================================================
   SoundMatch Core CSS System & Tokens
   ========================================================================== */

:root {
  --font-family: 'Outfit', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  
  /* Color Palette */
  --bg-primary: #0a0814;
  --bg-secondary: #120f26;
  --text-primary: #ffffff;
  --text-secondary: #a09eb5;
  --text-muted: #6b6982;
  
  --color-primary: #8a2be2;      /* Neon Violet */
  --color-secondary: #00f2fe;    /* Electric Cyan */
  --color-success: #00e676;      /* Spring Green */
  --color-failed: #ff9100;       /* Neon Orange */
  --color-error: #ff1744;        /* Crimson Red */
  
  /* Glow Shadows */
  --glow-primary: 0 0 30px rgba(138, 43, 226, 0.4);
  --glow-secondary: 0 0 30px rgba(0, 242, 254, 0.4);
  --glow-success: 0 0 35px rgba(0, 230, 118, 0.35);
  
  /* Glassmorphism Styles */
  --glass-bg: rgba(255, 255, 255, 0.03);
  --glass-border: rgba(255, 255, 255, 0.06);
  --glass-glow-border: rgba(138, 43, 226, 0.2);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-family);
  background-color: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;
  position: relative;
}

/* ==========================================================================
   Background Ambient Glowing Spheres
   ========================================================================== */

.glow-sphere {
  position: absolute;
  border-radius: 50%;
  filter: blur(120px);
  z-index: 0;
  pointer-events: none;
  opacity: 0.4;
}

.glow-sphere-1 {
  width: 400px;
  height: 400px;
  background: var(--color-primary);
  top: -100px;
  right: -50px;
}

.glow-sphere-2 {
  width: 500px;
  height: 500px;
  background: var(--color-secondary);
  bottom: -150px;
  left: -100px;
}

/* ==========================================================================
   Layout Containers
   ========================================================================== */

.app-container {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  position: relative;
  z-index: 1;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 24px;
}

/* Header & Navigation */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 24px 0;
  border-bottom: 1px solid var(--glass-border);
}

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

.logo-icon {
  font-size: 28px;
  animation: float 3s ease-in-out infinite;
}

.logo h1 {
  font-size: 24px;
  font-weight: 800;
  letter-spacing: -0.5px;
  background: linear-gradient(135deg, var(--text-primary) 30%, var(--color-secondary) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.nav-tabs {
  display: flex;
  gap: 8px;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--glass-border);
  padding: 6px;
  border-radius: 50px;
  backdrop-filter: blur(10px);
}

.tab-btn {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  padding: 10px 20px;
  font-family: var(--font-family);
  font-size: 14px;
  font-weight: 600;
  border-radius: 50px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.tab-btn:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.04);
}

.tab-btn.active {
  color: var(--text-primary);
  background: var(--color-primary);
  box-shadow: var(--glow-primary);
}

/* Content Area */
.app-content {
  flex-grow: 1;
  padding: 40px 0;
}

.tab-content {
  display: none;
  animation: fadeIn 0.4s ease-out forwards;
}

.tab-content.active {
  display: block;
}

/* Glassmorphic Panels */
.glass-panel {
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: 20px;
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}

/* ==========================================================================
   IDENTIFY VIEW (Song Recognition Tab)
   ========================================================================== */

.identify-view {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 55vh;
}

.search-stage {
  width: 100%;
  max-width: 680px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.text-center {
  text-align: center;
}

.recognition-state {
  display: none;
  min-height: 80px;
}

.recognition-state.active {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.state-hint {
  font-size: 18px;
  font-weight: 500;
  color: var(--text-secondary);
  max-width: 480px;
  line-height: 1.5;
}

.pulse-text {
  animation: textPulse 1.5s infinite ease-in-out;
}

.timer-display {
  font-size: 14px;
  font-weight: 600;
  color: var(--color-secondary);
  margin-top: 8px;
  background: rgba(0, 242, 254, 0.1);
  padding: 4px 12px;
  border-radius: 20px;
  border: 1px solid rgba(0, 242, 254, 0.2);
}

/* Microphone Pulsing Button */
.button-wrapper {
  margin: 50px 0;
  position: relative;
  width: 200px;
  height: 200px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.mic-button {
  width: 150px;
  height: 150px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-secondary) 100%);
  color: var(--text-primary);
  cursor: pointer;
  outline: none;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  z-index: 2;
  transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.mic-svg {
  width: 60px;
  height: 60px;
  z-index: 3;
}

.mic-glow {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-secondary) 100%);
  filter: blur(10px);
  opacity: 0.6;
  z-index: 1;
  transition: all 0.4s ease;
}

/* Pulse states */
.mic-button.idle:hover {
  transform: scale(1.08);
}

.mic-button.idle:hover .mic-glow {
  transform: scale(1.15);
  opacity: 0.9;
}

.mic-button.listening {
  animation: pulseListen 1.5s infinite cubic-bezier(0.4, 0, 0.6, 1);
}

.mic-button.listening .mic-glow {
  animation: glowPulse 1.5s infinite ease-in-out;
}

/* Processing state spinner surrounding mic */
.spinner {
  width: 50px;
  height: 50px;
  border: 4px solid rgba(255, 255, 255, 0.05);
  border-top: 4px solid var(--color-secondary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin-top: 16px;
}

/* Wave Sound Visualizer */
.wave-container {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  height: 40px;
  margin-top: 16px;
}

.wave-bar {
  width: 4px;
  height: 8px;
  background-color: var(--color-secondary);
  border-radius: 2px;
  animation: wavePulse 1s ease-in-out infinite alternate;
}

.wave-bar:nth-child(2) { animation-delay: 0.1s; height: 16px; }
.wave-bar:nth-child(3) { animation-delay: 0.2s; height: 24px; }
.wave-bar:nth-child(4) { animation-delay: 0.3s; height: 32px; }
.wave-bar:nth-child(5) { animation-delay: 0.4s; height: 40px; }
.wave-bar:nth-child(6) { animation-delay: 0.3s; height: 32px; }
.wave-bar:nth-child(7) { animation-delay: 0.2s; height: 24px; }
.wave-bar:nth-child(8) { animation-delay: 0.1s; height: 16px; }
.wave-bar:nth-child(9) { animation-delay: 0s; height: 8px; }

/* Buttons & Interactive Elements */
.action-btn {
  font-family: var(--font-family);
  font-size: 15px;
  font-weight: 600;
  padding: 12px 28px;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.3s ease;
  border: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.primary-btn {
  background: var(--color-primary);
  color: var(--text-primary);
  box-shadow: var(--glow-primary);
}

.primary-btn:hover {
  background: #9b42fc;
  transform: translateY(-2px);
  box-shadow: 0 0 35px rgba(138, 43, 226, 0.6);
}

.secondary-btn {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--glass-border);
  color: var(--text-primary);
}

.secondary-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.2);
}

.compact-btn {
  padding: 8px 16px;
  font-size: 13px;
  border-radius: 8px;
}

.hidden {
  display: none !important;
}

.mt-6 { margin-top: 24px; }
.mt-4 { margin-top: 16px; }

/* Result Details Card */
.result-card {
  width: 100%;
  padding: 30px;
  margin-top: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  animation: slideUp 0.4s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.card-body {
  display: flex;
  gap: 32px;
  width: 100%;
  text-align: left;
  align-items: center;
}

.artwork-wrapper {
  position: relative;
  flex-shrink: 0;
  width: 160px;
  height: 160px;
}

.artwork-wrapper img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 12px;
  position: relative;
  z-index: 2;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.artwork-glow {
  position: absolute;
  top: 10px;
  left: 10px;
  width: calc(100% - 20px);
  height: calc(100% - 20px);
  background: inherit;
  filter: blur(25px);
  z-index: 1;
  opacity: 0.8;
}

.song-metadata {
  flex-grow: 1;
}

.song-metadata h2 {
  font-size: 26px;
  font-weight: 800;
  letter-spacing: -0.5px;
  margin-bottom: 4px;
}

.song-metadata h3 {
  font-size: 18px;
  font-weight: 500;
  color: var(--color-secondary);
  margin-bottom: 20px;
}

.meta-row {
  display: flex;
  margin-bottom: 6px;
  font-size: 14px;
}

.meta-label {
  width: 80px;
  color: var(--text-muted);
  font-weight: 500;
}

.meta-val {
  color: var(--text-secondary);
}

/* External Listening Links */
.external-links {
  display: flex;
  gap: 12px;
  margin-top: 20px;
}

.provider-link {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  color: var(--text-primary);
  border: 1px solid var(--glass-border);
  background: rgba(255, 255, 255, 0.02);
  transition: all 0.3s ease;
}

.provider-link:hover {
  transform: translateY(-2px);
  background: rgba(255, 255, 255, 0.06);
  border-color: rgba(255, 255, 255, 0.15);
}

/* Error Match Card */
.error-card {
  padding: 40px;
  max-width: 480px;
}

.error-icon {
  font-size: 54px;
  margin-bottom: 16px;
  animation: float 4s ease-in-out infinite;
}

.error-card h2 {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 8px;
}

.error-card p {
  color: var(--text-secondary);
  font-size: 14px;
  line-height: 1.5;
}

.error-meta {
  font-size: 12px;
  background: rgba(255, 23, 68, 0.05);
  border: 1px solid rgba(255, 23, 68, 0.1);
  padding: 8px 16px;
  border-radius: 8px;
  text-align: left;
  width: 100%;
}

/* ==========================================================================
   HISTORY VIEW (History Tab)
   ========================================================================== */

.section-header {
  margin-bottom: 30px;
}

.section-header h2 {
  font-size: 26px;
  font-weight: 800;
  letter-spacing: -0.5px;
}

.section-header p {
  color: var(--text-secondary);
  font-size: 15px;
  margin-top: 4px;
}

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

/* History Card */
.history-card {
  padding: 16px;
  display: flex;
  gap: 16px;
  align-items: center;
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  cursor: pointer;
  border: 1px solid var(--glass-border);
}

.history-card:hover {
  transform: translateY(-4px);
  border-color: var(--glass-glow-border);
  box-shadow: 0 10px 20px rgba(138, 43, 226, 0.05);
  background: rgba(255, 255, 255, 0.04);
}

.history-artwork {
  width: 70px;
  height: 70px;
  border-radius: 8px;
  object-fit: cover;
  flex-shrink: 0;
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.history-details {
  min-width: 0; /* Enable text truncation */
  flex-grow: 1;
}

.history-details h4 {
  font-size: 16px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 2px;
}

.history-details p {
  font-size: 13px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-time {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 6px;
}

.empty-state {
  padding: 60px;
  text-align: center;
  max-width: 500px;
  margin: 40px auto;
}

.empty-icon {
  font-size: 60px;
  margin-bottom: 16px;
  display: block;
}

.empty-state h3 {
  font-size: 20px;
  margin-bottom: 8px;
}

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

/* ==========================================================================
   ADMIN PANEL VIEW (Admin Tab)
   ========================================================================== */

/* Metrics Cards Row */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 20px;
  margin-bottom: 30px;
}

.metric-card {
  padding: 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.metric-info h3 {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  color: var(--text-muted);
  letter-spacing: 0.5px;
  margin-bottom: 6px;
}

.metric-number {
  font-size: 32px;
  font-weight: 800;
  letter-spacing: -0.5px;
}

.metric-icon {
  font-size: 28px;
  background: rgba(255, 255, 255, 0.03);
  width: 50px;
  height: 50px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--glass-border);
}

/* Insights grid columns */
.insights-grid {
  display: grid;
  grid-template-columns: 1.5fr 1fr;
  gap: 20px;
  margin-bottom: 30px;
}

.insight-card {
  padding: 24px;
}

.insight-card h3 {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 20px;
  border-bottom: 1px solid var(--glass-border);
  padding-bottom: 12px;
}

/* Top searched track rows */
.top-songs-list {
  list-style: none;
}

.top-song-item {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.02);
}

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

.top-song-index {
  font-weight: 800;
  color: var(--text-muted);
  font-size: 14px;
  width: 20px;
}

.top-song-img {
  width: 44px;
  height: 44px;
  border-radius: 6px;
  object-fit: cover;
}

.top-song-info {
  flex-grow: 1;
  min-width: 0;
}

.top-song-name {
  font-weight: 600;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.top-song-artist {
  font-size: 12px;
  color: var(--text-secondary);
}

.top-song-count {
  background: rgba(138, 43, 226, 0.1);
  border: 1px solid rgba(138, 43, 226, 0.2);
  color: var(--color-primary);
  font-size: 12px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 20px;
}

/* Provider Status settings */
.status-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.status-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.status-item .status-label {
  font-size: 14px;
  color: var(--text-secondary);
  font-weight: 500;
}

.status-badge {
  font-size: 12px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--glass-border);
}

.provider-badge {
  background: rgba(0, 242, 254, 0.1);
  border-color: rgba(0, 242, 254, 0.2);
  color: var(--color-secondary);
}

.db-badge {
  background: rgba(138, 43, 226, 0.1);
  border-color: rgba(138, 43, 226, 0.2);
  color: var(--color-primary);
}

.health-badge.online {
  background: rgba(0, 230, 118, 0.1);
  border-color: rgba(0, 230, 118, 0.2);
  color: var(--color-success);
}

/* System Logs Table Section */
.logs-section {
  padding: 24px;
}

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

.table-wrapper {
  overflow-x: auto;
  border-radius: 12px;
  border: 1px solid var(--glass-border);
}

.logs-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 13px;
}

.logs-table th {
  background: rgba(255, 255, 255, 0.02);
  padding: 14px 16px;
  font-weight: 600;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--glass-border);
}

.logs-table td {
  padding: 12px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.02);
  color: var(--text-secondary);
  max-width: 250px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.logs-table tbody tr:hover {
  background: rgba(255, 255, 255, 0.01);
}

.logs-table tbody tr:last-child td {
  border-bottom: none;
}

.status-tag {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  padding: 2px 6px;
  border-radius: 4px;
  letter-spacing: 0.5px;
}

.status-tag.success {
  background: rgba(0, 230, 118, 0.1);
  color: var(--color-success);
}

.status-tag.failed {
  background: rgba(255, 145, 0, 0.1);
  color: var(--color-failed);
}

.status-tag.error {
  background: rgba(255, 23, 68, 0.1);
  color: var(--color-error);
}

/* ==========================================================================
   Footer
   ========================================================================== */

.app-footer {
  text-align: center;
  padding: 40px 0;
  border-top: 1px solid var(--glass-border);
  color: var(--text-muted);
  font-size: 13px;
}

/* ==========================================================================
   Animations & Transitions
   ========================================================================== */

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

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

@keyframes float {
  0% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
  100% { transform: translateY(0); }
}

@keyframes textPulse {
  0%, 100% { opacity: 0.6; }
  50% { opacity: 1; }
}

@keyframes pulseListen {
  0% { box-shadow: 0 0 0 0 rgba(138, 43, 226, 0.6), 0 0 0 0 rgba(0, 242, 254, 0.3); }
  70% { box-shadow: 0 0 0 25px rgba(138, 43, 226, 0), 0 0 0 15px rgba(0, 242, 254, 0); }
  100% { box-shadow: 0 0 0 0 rgba(138, 43, 226, 0), 0 0 0 0 rgba(0, 242, 254, 0); }
}

@keyframes glowPulse {
  0%, 100% { filter: blur(10px) scale(1); opacity: 0.6; }
  50% { filter: blur(20px) scale(1.1); opacity: 0.9; }
}

@keyframes wavePulse {
  from { transform: scaleY(0.2); }
  to { transform: scaleY(1); }
}

/* Custom Scrollbar */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: var(--bg-primary);
}

::-webkit-scrollbar-thumb {
  background: var(--glass-border);
  border-radius: 10px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* ==========================================================================
   Responsive Media Queries
   ========================================================================== */

@media (max-width: 768px) {
  .app-header {
    flex-direction: column;
    gap: 16px;
    padding: 16px 0;
  }
  
  .card-body {
    flex-direction: column;
    text-align: center;
    gap: 20px;
  }

  .song-metadata {
    display: flex;
    flex-direction: column;
    align-items: center;
  }

  .meta-row {
    justify-content: center;
  }

  .external-links {
    flex-wrap: wrap;
    justify-content: center;
  }

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

  .nav-tabs {
    width: 100%;
    justify-content: space-around;
  }

  .tab-btn {
    padding: 8px 12px;
    font-size: 13px;
  }
}
