/* ── Theme ── */
:root {
  --bg: #0a0a0a;
  --bg-surface: #141414;
  --bg-raised: #1c1c1c;
  --bg-hover: #252525;
  --bg-active: #2a2a2a;
  --text: #e8e8e8;
  --text-2: #a0a0a0;
  --text-3: #606060;
  --primary: #7c3aed;
  --primary-hover: #6d28d9;
  --primary-dim: rgba(124, 58, 237, 0.12);
  --danger: #ef4444;
  --success: #22c55e;
  --border: #222;
  --radius: 6px;
  --sidebar-w: 240px;
  --player-h: 88px;
  --queue-w: 360px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  user-select: none;
}

.hidden { display: none !important; }

/* ── Auth ── */
.screen { display: flex; height: 100vh; }
.auth-box {
  margin: auto;
  background: var(--bg-surface);
  padding: 48px 56px;
  border-radius: 12px;
  text-align: center;
  width: 380px;
}
.auth-box h1 { font-size: 40px; font-weight: 700; letter-spacing: 6px; margin-bottom: 4px; }
.subtitle { color: var(--text-2); margin-bottom: 32px; font-size: 14px; }
.auth-box input {
  width: 100%; padding: 12px 16px; background: var(--bg-raised); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text); font-size: 14px; margin-bottom: 16px; outline: none;
}
.auth-box input:focus { border-color: var(--primary); }
.error-text { color: var(--danger); font-size: 13px; margin-top: 8px; min-height: 18px; }

/* ── Buttons ── */
.btn {
  padding: 8px 20px; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--bg-raised); color: var(--text); cursor: pointer; font-size: 13px;
  font-family: inherit; transition: all 0.15s; white-space: nowrap;
}
.btn:hover { background: var(--bg-hover); }
.btn:disabled { opacity: 0.35; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-sm { padding: 5px 12px; font-size: 12px; }
.btn-xs { padding: 3px 8px; font-size: 11px; }
.btn-ghost { background: none; border-color: transparent; }
.btn-ghost:hover { background: var(--bg-hover); }
.btn-active { color: var(--primary); border-color: var(--primary); }

.icon-btn {
  background: none; border: none; color: var(--text-2); cursor: pointer;
  padding: 6px; display: inline-flex; align-items: center; justify-content: center;
  border-radius: 50%; transition: all 0.15s; font-size: 18px;
}
.icon-btn:hover { color: var(--text); background: var(--bg-hover); }
.icon-btn svg { width: 18px; height: 18px; fill: currentColor; }
.icon-btn.active { color: var(--primary); }

/* ── Inputs ── */
.input {
  padding: 8px 12px; background: var(--bg-raised); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text); font-size: 13px; outline: none; width: 100%;
  font-family: inherit;
}
.input:focus { border-color: var(--primary); }
.select {
  padding: 5px 8px; background: var(--bg-raised); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text); font-size: 12px; cursor: pointer; outline: none;
}

/* ── Layout ── */
#main-app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: 1fr var(--player-h);
  height: 100vh;
}
#main-app.no-player { grid-template-rows: 1fr; }

/* ── Sidebar ── */
#sidebar {
  grid-row: 1 / -1;
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 20px 12px;
}
.sidebar-logo {
  font-size: 22px; font-weight: 700; letter-spacing: 4px;
  padding: 0 12px 24px; color: var(--text);
}
#nav { display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: flex; align-items: center; gap: 14px;
  padding: 10px 14px; border-radius: var(--radius);
  background: none; border: none; color: var(--text-2);
  font-size: 14px; font-weight: 500; cursor: pointer;
  font-family: inherit; text-align: left; transition: all 0.15s;
}
.nav-item svg { width: 20px; height: 20px; fill: currentColor; flex-shrink: 0; }
.nav-item:hover { color: var(--text); background: var(--bg-hover); }
.nav-item.active { color: var(--text); background: var(--bg-active); }

/* ── Main Area ── */
#main-area {
  display: flex;
  overflow: hidden;
  min-width: 0;
}
#content {
  flex: 1;
  overflow-y: auto;
  padding: 28px 32px;
  min-width: 0;
}

/* ── Toolbar ── */
.toolbar {
  display: flex; align-items: center; gap: 12px; margin-bottom: 20px;
}
.toolbar h2 { font-size: 24px; font-weight: 700; margin-right: auto; }
.toolbar-gap { flex: 1; }
.search-input {
  width: 280px; padding: 7px 14px; background: var(--bg-raised); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text); font-size: 13px; outline: none;
}
.search-input:focus { border-color: var(--primary); }

/* ── Track Table ── */
.track-count { font-size: 12px; color: var(--text-3); margin-bottom: 8px; }

.track-table-head {
  display: grid;
  grid-template-columns: 40px 1fr 200px 150px 70px 110px 40px;
  padding: 0 12px 6px;
  border-bottom: 1px solid var(--border);
  font-size: 11px; font-weight: 600; color: var(--text-3); text-transform: uppercase; letter-spacing: 0.5px;
}
.track-table-head > div { cursor: pointer; padding: 4px 0; }
.track-table-head > div:hover { color: var(--text-2); }
.track-table-head .sort-active { color: var(--text); }

.track-rows { margin-top: 2px; }

.track-row {
  display: grid;
  grid-template-columns: 40px 1fr 200px 150px 70px 110px 40px;
  align-items: center;
  padding: 6px 12px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.1s;
  min-height: 52px;
}
.track-row:hover { background: var(--bg-hover); }
.track-row.active { background: var(--primary-dim); }

.track-row:hover .row-num { display: none; }
.track-row:hover .row-play-btn { display: flex; }
.track-row.active .row-num { color: var(--primary); }

.col-num {
  font-size: 13px; color: var(--text-3); text-align: center; position: relative;
}
.row-play-btn {
  display: none; align-items: center; justify-content: center;
  background: none; border: none; color: var(--text); cursor: pointer;
  font-size: 11px; width: 100%;
}
.row-play-btn svg { width: 14px; height: 14px; fill: currentColor; }

.col-title {
  display: flex; align-items: center; gap: 12px; min-width: 0;
}
.row-thumb {
  width: 40px; height: 40px; border-radius: 4px; flex-shrink: 0;
  background: var(--bg-raised) center/cover no-repeat;
  position: relative; overflow: hidden;
}
.playing-indicator {
  position: absolute; inset: 0;
  display: flex; align-items: flex-end; justify-content: center; gap: 2px;
  padding-bottom: 6px; background: rgba(0,0,0,0.55);
}
.playing-indicator span {
  display: block; width: 3px; background: var(--primary); border-radius: 1px;
  animation: eq 0.6s ease infinite alternate;
}
.playing-indicator span:nth-child(1) { height: 10px; }
.playing-indicator span:nth-child(2) { height: 16px; animation-delay: 0.2s; }
.playing-indicator span:nth-child(3) { height: 7px; animation-delay: 0.4s; }
@keyframes eq { 0% { height: 3px; } 100% { height: 18px; } }

.title-text {
  font-size: 14px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.col-artist {
  font-size: 13px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.col-tags { display: flex; gap: 4px; flex-wrap: wrap; overflow: hidden; max-height: 24px; }
.tag-badge {
  display: inline-block; padding: 1px 7px; background: var(--bg-raised); border: 1px solid var(--border);
  border-radius: 10px; font-size: 11px; color: var(--text-2); white-space: nowrap;
}

.col-duration { font-size: 13px; color: var(--text-2); }
.col-date { font-size: 12px; color: var(--text-3); }

.col-actions { text-align: center; }
.track-row .col-actions .icon-btn { opacity: 0; transition: opacity 0.1s; }
.track-row:hover .col-actions .icon-btn { opacity: 1; }

/* Progress bar in track row */
.track-progress-bar {
  height: 2px; background: var(--bg-active); border-radius: 1px; margin-top: 3px; overflow: hidden;
  grid-column: 2 / -2;
}
.track-progress-fill { height: 100%; background: var(--primary); border-radius: 1px; }

/* ── Filter Pills ── */
.active-filters {
  display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; align-items: center;
}
.filter-pill {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 10px; background: var(--primary-dim); border: 1px solid rgba(124,58,237,0.3);
  border-radius: 12px; font-size: 12px; color: var(--primary); cursor: pointer;
}
.filter-pill:hover { background: var(--primary); color: #fff; }

/* ── Context Menu ── */
.context-menu {
  position: fixed; background: var(--bg-raised); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: 0 8px 32px rgba(0,0,0,0.5);
  z-index: 1000; min-width: 180px; overflow: hidden; padding: 4px 0;
}
.context-menu button {
  display: block; width: 100%; padding: 8px 16px; text-align: left;
  background: none; border: none; color: var(--text); font-size: 13px;
  cursor: pointer; font-family: inherit;
}
.context-menu button:hover { background: var(--bg-hover); }
.context-menu button.danger { color: var(--danger); }
.ctx-separator { height: 1px; background: var(--border); margin: 4px 0; }

/* ── Playlists ── */
.playlist-list { display: flex; flex-direction: column; gap: 2px; }
.playlist-row {
  display: flex; align-items: center; gap: 16px;
  padding: 12px 16px; border-radius: var(--radius); cursor: pointer; transition: background 0.1s;
}
.playlist-row:hover { background: var(--bg-hover); }
.playlist-name { font-size: 15px; font-weight: 500; }
.playlist-meta { font-size: 12px; color: var(--text-3); margin-top: 2px; }
.playlist-info { flex: 1; }

.playlist-pick-list { display: flex; flex-direction: column; gap: 4px; }
.playlist-pick-item {
  padding: 10px 14px; text-align: left; background: var(--bg-raised);
  border: 1px solid var(--border); border-radius: var(--radius);
  color: var(--text); font-size: 13px; cursor: pointer; font-family: inherit;
}
.playlist-pick-item:hover { border-color: var(--primary); }

/* ── Import ── */
.import-form { display: flex; gap: 10px; margin-bottom: 20px; }
.import-form .input { flex: 1; }

.import-jobs { display: flex; flex-direction: column; gap: 4px; }
.job-row {
  display: grid; grid-template-columns: 32px 1fr auto;
  align-items: center; gap: 14px; padding: 12px 16px;
  background: var(--bg-surface); border-radius: var(--radius);
}
.job-status { font-size: 18px; text-align: center; }
.job-info { min-width: 0; }
.job-title { font-size: 14px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.job-artist { font-size: 12px; color: var(--text-2); }
.job-error { font-size: 12px; color: var(--danger); margin-top: 2px; }
.job-progress-bar { height: 3px; background: var(--bg-active); border-radius: 2px; margin-top: 6px; overflow: hidden; }
.job-progress-fill { height: 100%; background: var(--primary); border-radius: 2px; transition: width 0.3s; }
.job-actions { display: flex; gap: 8px; align-items: center; }

[data-status="done"] .job-status { color: var(--success); }
[data-status="failed"] .job-status { color: var(--danger); }
[data-status="downloading"] .job-status { color: var(--primary); animation: pulse 1s infinite; }
[data-status="pending"] .job-status { color: var(--text-3); }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.4; } }

/* ── Tags View ── */
.tag-grid { display: flex; flex-wrap: wrap; gap: 8px; }
.tag-card {
  padding: 10px 20px; background: var(--bg-surface); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text); font-size: 14px;
  cursor: pointer; font-family: inherit; transition: all 0.15s;
}
.tag-card:hover { border-color: var(--primary); color: var(--primary); }

/* ── Artists ── */
.artist-form {
  display: flex; gap: 8px; margin-bottom: 16px;
}
.artist-form .input { flex: 1; }
.artist-grid { display: flex; flex-direction: column; gap: 4px; }
.artist-card {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; background: var(--bg-surface); border: 1px solid var(--border);
  border-radius: var(--radius); cursor: pointer; transition: all 0.15s;
}
.artist-card:hover { border-color: var(--primary); background: var(--bg-hover); }
.artist-card-name { font-size: 15px; font-weight: 500; }
.artist-card-meta { font-size: 12px; color: var(--text-2); margin-top: 2px; }
.artist-yt-link { color: var(--primary); text-decoration: none; }
.artist-yt-link:hover { text-decoration: underline; }
.artist-card-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.artist-card .art-del { opacity: 0; transition: opacity 0.15s; }
.artist-card:hover .art-del { opacity: 1; }
.toggle-label {
  display: flex; align-items: center; gap: 6px; cursor: pointer; font-size: 12px; color: var(--text-2);
}
.toggle-label input { display: none; }
.toggle-switch {
  width: 32px; height: 18px; background: var(--bg-hover); border-radius: 9px;
  position: relative; transition: background 0.2s; flex-shrink: 0;
}
.toggle-switch::after {
  content: ''; position: absolute; top: 2px; left: 2px;
  width: 14px; height: 14px; background: var(--text-3); border-radius: 50%;
  transition: all 0.2s;
}
.toggle-label input:checked + .toggle-switch { background: var(--primary); }
.toggle-label input:checked + .toggle-switch::after { left: 16px; background: #fff; }
.art-fetch { white-space: nowrap; }

/* ── Player Bar ── */
#player-bar {
  grid-column: 1 / -1;
  background: var(--bg-surface);
  border-top: 1px solid var(--border);
  display: grid;
  grid-template-columns: minmax(200px, 1fr) minmax(400px, 2fr) minmax(200px, 1fr);
  align-items: center;
  padding: 0 16px;
  gap: 16px;
}

.pb-track {
  display: flex; align-items: center; gap: 14px; min-width: 0;
}
.pb-thumb {
  width: 56px; height: 56px; border-radius: 4px; flex-shrink: 0;
  background: var(--bg-raised) center/cover no-repeat;
}
.pb-info { min-width: 0; }
.pb-title { font-size: 13px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pb-artist { font-size: 12px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.pb-center { display: flex; flex-direction: column; align-items: center; gap: 4px; max-width: 640px; margin: 0 auto; width: 100%; }

.pb-buttons { display: flex; align-items: center; gap: 12px; }
.pb-buttons .icon-btn svg { width: 16px; height: 16px; }
.pb-play {
  background: var(--text) !important; color: var(--bg) !important;
  width: 34px; height: 34px; border-radius: 50%;
}
.pb-play:hover { transform: scale(1.06); background: #fff !important; }
.pb-play svg { width: 16px; height: 16px; fill: var(--bg); }

.pb-seek { display: flex; align-items: center; gap: 8px; width: 100%; }
.pb-time { font-size: 11px; color: var(--text-3); width: 36px; flex-shrink: 0; }
.pb-time:last-child { text-align: right; }

.seek-track {
  flex: 1; height: 4px; background: var(--bg-active); border-radius: 2px;
  cursor: pointer; position: relative;
}
.seek-track:hover { height: 6px; margin: -1px 0; }
.seek-fill {
  height: 100%; background: var(--text-2); border-radius: 2px; width: 0%;
  transition: width 0.15s linear; pointer-events: none;
}
.seek-track:hover .seek-fill { background: var(--primary); }

.pb-right {
  display: flex; align-items: center; justify-content: flex-end; gap: 10px;
}
.pb-right .icon-btn svg { width: 18px; height: 18px; }
.pb-right select {
  background: transparent; border: 1px solid var(--border); border-radius: var(--radius);
  color: var(--text-2); padding: 3px 6px; font-size: 12px; cursor: pointer; outline: none;
}

.volume-wrap {
  display: flex; align-items: center; gap: 4px; width: 130px;
}
.volume-icon { width: 18px; height: 18px; fill: var(--text-2); flex-shrink: 0; }
#volume-slider {
  -webkit-appearance: none; appearance: none; width: 100%; height: 4px;
  background: var(--bg-active); border-radius: 2px; outline: none; cursor: pointer;
}
#volume-slider::-webkit-slider-thumb {
  -webkit-appearance: none; width: 12px; height: 12px;
  background: var(--text); border-radius: 50%; cursor: pointer;
}
#volume-slider::-moz-range-thumb {
  width: 12px; height: 12px; background: var(--text);
  border-radius: 50%; border: none; cursor: pointer;
}

#pb-repeat { position: relative; }
#pb-repeat[data-mode="one"]::after {
  content: "1"; font-size: 8px; position: absolute;
  top: 50%; left: 50%; transform: translate(-50%, -50%); font-weight: 700;
}

/* ── Queue Panel ── */
#queue-panel {
  width: var(--queue-w); flex-shrink: 0;
  background: var(--bg-surface); border-left: 1px solid var(--border);
  overflow-y: auto; padding: 20px;
}
.queue-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px;
}
.queue-header h3 { font-size: 16px; font-weight: 600; }

.queue-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: var(--radius); cursor: pointer;
}
.queue-item:hover { background: var(--bg-hover); }
.queue-item.active { background: var(--primary-dim); }
.queue-pos { font-size: 12px; color: var(--text-3); width: 22px; text-align: center; flex-shrink: 0; }
.queue-info { flex: 1; min-width: 0; }
.queue-title { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.queue-artist { font-size: 11px; color: var(--text-2); }

/* ── Modal ── */
#modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.55);
  z-index: 200; display: flex; align-items: center; justify-content: center;
}
.modal {
  background: var(--bg-raised); border-radius: 10px;
  width: 420px; max-width: 90vw; max-height: 80vh; overflow-y: auto;
  box-shadow: 0 12px 40px rgba(0,0,0,0.5); border: 1px solid var(--border);
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 15px; font-weight: 600; }
#modal-body { padding: 20px; }

.form-group { margin-bottom: 12px; }
.form-group label { display: block; font-size: 12px; color: var(--text-2); margin-bottom: 4px; }
.existing-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }

.tag-badge.removable { cursor: pointer; }
.tag-badge.removable:hover { border-color: var(--danger); color: var(--danger); }
.tag-badge.clickable {
  cursor: pointer; background: none; border: 1px solid var(--border);
  font-family: inherit; padding: 4px 12px; font-size: 13px; color: var(--text);
}
.tag-badge.clickable:hover { border-color: var(--primary); color: var(--primary); }

.filter-section { margin-bottom: 16px; }
.filter-section h4 { font-size: 13px; margin-bottom: 6px; color: var(--text-2); }
.filter-options { display: flex; flex-direction: column; gap: 4px; max-height: 180px; overflow-y: auto; }
.checkbox-label {
  display: flex; align-items: center; gap: 8px;
  font-size: 13px; cursor: pointer; padding: 3px 0;
}
.checkbox-label input[type="checkbox"] { accent-color: var(--primary); width: 15px; height: 15px; }
.tag-list-edit { display: flex; flex-wrap: wrap; gap: 6px; }

/* ── Toast ── */
#toast {
  position: fixed; bottom: calc(var(--player-h) + 20px); left: 50%;
  transform: translateX(-50%); background: var(--bg-raised);
  border: 1px solid var(--border); padding: 10px 24px; border-radius: var(--radius);
  font-size: 13px; z-index: 300; box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  animation: fadeIn 0.2s;
}
@keyframes fadeIn { from { opacity: 0; transform: translateX(-50%) translateY(8px); } }
#toast { display: flex; align-items: center; gap: 10px; }
.spinner {
  width: 14px; height: 14px; border: 2px solid var(--text-3); border-top-color: var(--text);
  border-radius: 50%; animation: spin 0.6s linear infinite; flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Empty ── */
.empty { text-align: center; color: var(--text-3); padding: 60px 16px; font-size: 14px; }
.empty-sm { color: var(--text-3); font-size: 13px; padding: 8px 0; }
