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

:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --border: #e2e8f0;
  --border-hover: #cbd5e1;
  --text: #0f172a;
  --text-secondary: #64748b;
  --text-muted: #94a3b8;
  --primary: #0f172a;
  --primary-hover: #1e293b;
  --accent: #3b82f6;
  --danger: #ef4444;
  --danger-bg: #fef2f2;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,0.04), 0 1px 2px rgba(0,0,0,0.02);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.05);
}

body {
  background: var(--bg);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  padding: 1.5rem;
}

.auth-gate {
  min-height: calc(100vh - 3rem);
  display: grid;
  place-items: center;
}

.auth-card {
  width: min(92vw, 420px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}

.auth-card h2 {
  font-size: 1.2rem;
}

.auth-card p {
  color: var(--text-secondary);
  font-size: 0.9rem;
}

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

.auth-config {
  display: flex;
  gap: 0.45rem;
  align-items: center;
}

.auth-config input {
  flex: 1;
  min-width: 0;
  padding: 0.55rem 0.7rem;
  font-size: 0.85rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #f8fafc;
}

.app {
  max-width: 1440px;
  margin: 0 auto;
}

/* Header */
.header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.75rem;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.header h1 {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--text);
}

.header-badge {
  background: #e2e8f0;
  color: var(--text-secondary);
  font-size: 0.75rem;
  font-weight: 500;
  padding: 0.2rem 0.7rem;
  border-radius: 999px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.upload-option {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  color: var(--text-secondary);
  font-size: 0.75rem;
  cursor: pointer;
  white-space: nowrap;
}

.upload-option input {
  accent-color: var(--primary);
}

.library-tools {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

/* Buttons */
.btn-primary,
.btn-secondary,
.btn-ghost,
.btn-danger-sm {
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 500;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  border: none;
  outline: none;
}

.btn-primary {
  background: var(--primary);
  color: white;
  padding: 0.55rem 1.25rem;
}

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

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 0.5rem 1rem;
}

.btn-secondary:hover {
  border-color: var(--border-hover);
  background: #f8fafc;
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  padding: 0.5rem 0.9rem;
  border: 1px solid transparent;
}

.btn-ghost:hover {
  color: var(--text);
  background: #f1f5f9;
}

.btn-close {
  padding: 0.25rem 0.5rem;
  font-size: 1rem;
  line-height: 1;
}

.btn-danger-sm {
  background: transparent;
  color: var(--danger);
  border: 1px solid #fecaca;
  padding: 0.25rem 0.7rem;
  font-size: 0.75rem;
  border-radius: 6px;
}

.btn-danger-sm:hover {
  background: var(--danger-bg);
}

/* Layout — 2 or 3 columns */
.layout {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 1.25rem;
  align-items: start;
  transition: grid-template-columns 0.2s ease;
}

.layout.has-detail {
  grid-template-columns: 320px 1fr 300px;
}

@media (max-width: 1100px) {
  .layout.has-detail {
    grid-template-columns: 280px 1fr 260px;
  }
}

@media (max-width: 900px) {
  .layout,
  .layout.has-detail {
    grid-template-columns: 1fr;
  }
  .right-panel {
    order: -1;
  }
}

.left-panel,
.right-panel {
  position: sticky;
  top: 1.5rem;
}

/* Panels */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  gap: 1rem;
  flex-wrap: wrap;
}

.panel-header h2 {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.count-pill {
  background: #f1f5f9;
  color: var(--text-secondary);
  font-size: 0.7rem;
  font-weight: 600;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
}

.panel-footer {
  display: flex;
  justify-content: space-between;
  padding: 0.75rem 1.25rem;
  border-top: 1px solid var(--border);
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* Form */
.form-panel form {
  padding: 1.25rem;
}

.field {
  margin-bottom: 1rem;
}

.field label {
  display: block;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-secondary);
  margin-bottom: 0.3rem;
}

.req {
  color: var(--danger);
}

.field input,
.field select,
.field textarea {
  width: 100%;
  padding: 0.55rem 0.75rem;
  font-size: 0.9rem;
  font-family: inherit;
  color: var(--text);
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: #94a3b8;
  box-shadow: 0 0 0 3px rgba(148, 163, 184, 0.15);
  background: white;
}

.field textarea {
  resize: vertical;
  min-height: 70px;
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.form-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

/* ========== DETAIL PANEL (right) ========== */
.detail-panel {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.detail-header {
  background: #f8fafc;
}

.detail-body {
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  max-height: 70vh;
  overflow-y: auto;
}

.detail-title {
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
  line-height: 1.3;
}

.detail-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.detail-artist {
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.detail-section {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.detail-label {
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.detail-value {
  font-size: 0.9rem;
  color: var(--text);
  line-height: 1.5;
}

.detail-lyrics {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.75rem 1rem;
  font-size: 0.85rem;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 180px;
  overflow-y: auto;
  line-height: 1.55;
}

.detail-cover {
  background: #f0f4fc;
  border: 1px solid #e2e8f0;
  border-radius: var(--radius-sm);
  padding: 0.6rem 0.9rem;
  font-size: 0.85rem;
  color: #334155;
}

.detail-image-link {
  display: block;
  width: min(100%, 260px);
}

.detail-image {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #f8fafc;
}

.detail-drive-link {
  color: var(--primary);
  font-size: 0.78rem;
  text-decoration: none;
}

.detail-drive-link:hover {
  text-decoration: underline;
}

.detail-media {
  display: block;
  width: 100%;
  max-width: 420px;
}

.detail-tracks-list {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-top: 0.25rem;
}

.detail-track-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.4rem 0.6rem;
  background: #f8fafc;
  border-radius: 6px;
  font-size: 0.85rem;
  cursor: pointer;
  transition: background 0.12s;
}

.detail-track-row:hover {
  background: #f1f5f9;
}

.detail-album-track {
  padding: 0.25rem 0 0.85rem;
  border-bottom: 1px solid var(--border);
}

.detail-album-track + .detail-album-track {
  margin-top: 0.75rem;
}

.detail-track-row {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  align-items: center;
}

.detail-track-open {
  color: var(--text-muted);
  font-size: 0.7rem;
  font-weight: 500;
}

.detail-track-meta {
  display: flex;
  gap: 0.6rem;
  margin: 0.35rem 0 0.45rem;
  color: var(--text-muted);
  font-size: 0.75rem;
}

.detail-track-lyrics,
.detail-track-prompt {
  color: var(--text-secondary);
  font-size: 0.78rem;
  line-height: 1.5;
  white-space: pre-wrap;
}

.detail-track-prompt {
  margin-top: 0.45rem;
  color: var(--text-muted);
}

.detail-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

/* View switcher */
.view-switcher {
  display: flex;
  background: #f1f5f9;
  border-radius: 8px;
  padding: 3px;
  gap: 2px;
}

.view-btn {
  font-family: inherit;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-secondary);
  background: transparent;
  border: none;
  padding: 0.35rem 0.7rem;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s;
}

.view-btn:hover {
  color: var(--text);
}

.view-btn.active {
  background: white;
  color: var(--text);
  box-shadow: 0 1px 2px rgba(0,0,0,0.06);
}

/* Library container */
.library-container {
  max-height: 620px;
  overflow-y: auto;
  padding: 0.75rem;
}

.library-container::-webkit-scrollbar {
  width: 5px;
}
.library-container::-webkit-scrollbar-track {
  background: transparent;
}
.library-container::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 10px;
}

.empty-state {
  text-align: center;
  padding: 3.5rem 1rem;
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* ========== TABLE VIEW ========== */
.view-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.view-table th {
  text-align: left;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  padding: 0.6rem 0.75rem;
  border-bottom: 1px solid var(--border);
  background: #f8fafc;
  position: sticky;
  top: 0;
}

.view-table td {
  padding: 0.7rem 0.75rem;
  border-bottom: 1px solid #f1f5f9;
  vertical-align: middle;
}

.view-table tr {
  cursor: pointer;
  transition: background 0.1s;
}

.view-table tr:hover td {
  background: #f8fafc;
}

.view-table tr.selected td {
  background: #eff6ff;
}

.view-table .col-title {
  font-weight: 600;
  color: var(--text);
  max-width: 180px;
}

.view-table .col-artist {
  color: var(--text-secondary);
  max-width: 120px;
}

.view-table .col-type {
  white-space: nowrap;
}

.view-table .col-genre {
  color: var(--text-secondary);
  font-size: 0.8rem;
}

.view-table .col-actions {
  text-align: right;
  white-space: nowrap;
}

.type-badge {
  display: inline-block;
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
}

.type-badge.single {
  background: #eff6ff;
  color: #2563eb;
}

.type-badge.album {
  background: #f5f3ff;
  color: #7c3aed;
}

.type-badge.track {
  background: #f0fdf4;
  color: #16a34a;
}

.album-tag {
  display: inline-block;
  margin-top: 0.25rem;
  color: #7c3aed;
  font-size: 0.7rem;
  font-weight: 500;
}

.album-group-row td {
  background: #f8fafc !important;
  font-weight: 600;
  border-bottom: 1px solid var(--border);
}

.track-row td:first-child {
  padding-left: 1.75rem;
}

.track-row .col-title {
  font-weight: 500;
  color: var(--text-secondary);
}

/* ========== GRID VIEW ========== */
.view-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 0.75rem;
}

.grid-card {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 1rem;
  transition: border-color 0.15s, box-shadow 0.15s;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  cursor: pointer;
}

.grid-card:hover {
  border-color: var(--border-hover);
  box-shadow: var(--shadow-md);
}

.grid-card.selected {
  border-color: #93c5fd;
  background: #eff6ff;
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.15);
}

.grid-card.album-card {
  background: linear-gradient(135deg, #f5f3ff 0%, #faf5ff 100%);
  border-color: #e9e5f5;
}

.grid-card.album-card.selected {
  border-color: #c4b5fd;
  background: linear-gradient(135deg, #ede9fe 0%, #f5f3ff 100%);
}

.grid-card .card-type {
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}

.grid-card .card-title {
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text);
  line-height: 1.3;
}

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

.grid-card .card-genre {
  font-size: 0.7rem;
  color: var(--text-muted);
}

.grid-card .card-actions {
  margin-top: auto;
  padding-top: 0.5rem;
  display: flex;
  justify-content: flex-end;
}

.album-tracks {
  margin-top: 0.5rem;
  padding-top: 0.5rem;
  border-top: 1px dashed #e2e8f0;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.album-track-item {
  font-size: 0.75rem;
  color: var(--text-secondary);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
}

/* ========== LIST VIEW ========== */
.view-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.list-item {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.85rem 1rem;
  transition: border-color 0.15s, background 0.15s;
  cursor: pointer;
}

.list-item:hover {
  border-color: var(--border-hover);
}

.list-item.selected {
  border-color: #93c5fd;
  background: #eff6ff;
}

.list-item.album-item {
  background: linear-gradient(135deg, #f5f3ff 0%, #faf5ff 100%);
  border-color: #e9e5f5;
}

.list-item.album-item.selected {
  border-color: #c4b5fd;
  background: linear-gradient(135deg, #ede9fe 0%, #f5f3ff 100%);
}

.list-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
}

.list-main {
  flex: 1;
  min-width: 0;
}

.list-title {
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text);
}

.list-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.25rem;
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.list-lyrics {
  margin-top: 0.5rem;
  font-size: 0.8rem;
  color: var(--text-secondary);
  background: white;
  border: 1px solid #f1f5f9;
  border-radius: 6px;
  padding: 0.5rem 0.75rem;
  max-height: 60px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

.list-cover {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.3rem;
}

.list-tracks {
  margin-top: 0.6rem;
  padding-left: 0.75rem;
  border-left: 2px solid #ddd6fe;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.list-track {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.8rem;
  color: var(--text-secondary);
  padding: 0.2rem 0;
  cursor: pointer;
}

.list-track:hover {
  color: var(--text);
}

/* Toast */
.toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--primary);
  color: white;
  font-size: 0.85rem;
  font-weight: 500;
  padding: 0.6rem 1.25rem;
  border-radius: 999px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.15);
  opacity: 0;
  pointer-events: none;
  transition: all 0.25s ease;
  z-index: 1000;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* Copy button + label row */
.detail-label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.btn-copy {
  font-family: inherit;
  font-size: 0.7rem;
  font-weight: 500;
  color: var(--text-secondary);
  background: #f1f5f9;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.15rem 0.55rem;
  cursor: pointer;
  transition: all 0.12s;
}

.btn-copy:hover {
  background: #e2e8f0;
  color: var(--text);
}

/* Edit form inside detail uses same field styles */
.detail-body .field {
  margin-bottom: 0.85rem;
}

.detail-body .field label {
  display: block;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-secondary);
  margin-bottom: 0.25rem;
}

.detail-body .field input,
.detail-body .field select,
.detail-body .field textarea {
  width: 100%;
  padding: 0.5rem 0.7rem;
  font-size: 0.9rem;
  font-family: inherit;
  color: var(--text);
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  outline: none;
}

.detail-body .field input:focus,
.detail-body .field select:focus,
.detail-body .field textarea:focus {
  border-color: #94a3b8;
  box-shadow: 0 0 0 3px rgba(148, 163, 184, 0.15);
  background: white;
}

.detail-body .field textarea {
  resize: vertical;
  min-height: 80px;
}
