/* JustDa — custom CSS, no framework. Dark, music-app feel. */

:root {
  --bg:        #14101f;
  --surface:   #1f1147;
  --surface-2: #2a1c5a;
  --accent:    #7c5cff;
  --text:      #f3f0ff;
  --muted:     #b3a9d6;
  --border:    #3a2c6e;
  --nav-h:     56px;
  --bottom-h:  62px;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* ── Views ─────────────────────────────────────────────────────────────────── */
.view[hidden] { display: none !important; }

.view-center {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px 16px;
}

.connect-inner { text-align: center; max-width: 440px; }
.brand-hero {
  font-size: 2.8rem;
  font-weight: 800;
  letter-spacing: -1px;
  margin-bottom: 16px;
}
.brand-dot { color: var(--accent); }
.connect-sub { color: var(--muted); margin-bottom: 28px; line-height: 1.6; }

/* ── Top nav ────────────────────────────────────────────────────────────────── */
.top-nav {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 8px;
  height: var(--nav-h);
  padding: 0 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.nav-brand {
  font-size: 1.15rem;
  font-weight: 800;
  letter-spacing: -0.5px;
  margin-right: 8px;
  white-space: nowrap;
}

.nav-links {
  display: flex;
  align-items: stretch;
  height: 100%;
  flex: 1;
}

.nav-link {
  appearance: none;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  padding: 0 16px;
  height: 100%;
  transition: color 0.15s, border-color 0.15s;
  white-space: nowrap;
}
.nav-link:hover { color: var(--text); }
.nav-link.active { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }

.nav-account {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: auto;
  font-size: 13px;
  color: var(--muted);
}

.avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  letter-spacing: 0.5px;
}

/* ── Panes ──────────────────────────────────────────────────────────────────── */
#view-app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.pane { flex: 1; }
.pane[hidden] { display: none !important; }

.pane-inner {
  max-width: 980px;
  margin: 0 auto;
  padding: 28px 20px 80px;
}

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

.pane-title { font-size: 1.4rem; font-weight: 700; margin: 0; }

.pane-player-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 50vh;
  color: var(--muted);
}

/* ── Bottom tab bar (mobile) ─────────────────────────────────────────────────── */
.bottom-nav {
  display: none;
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: var(--bottom-h);
  background: var(--surface);
  border-top: 1px solid var(--border);
  z-index: 20;
}

.tab {
  flex: 1;
  appearance: none;
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  font-size: 11px;
  padding: 8px 4px;
  transition: color 0.15s;
}
.tab.active { color: var(--accent); }
.tab-icon { width: 22px; height: 22px; }

/* ── Buttons ─────────────────────────────────────────────────────────────────── */
.btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  padding: 9px 16px;
  border-radius: 10px;
  font-size: 14px;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
  white-space: nowrap;
}
.btn:hover { border-color: var(--accent); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }

.link-btn {
  appearance: none;
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  font-size: inherit;
  padding: 0;
  text-decoration: underline;
}

.status { color: var(--muted); font-size: 13px; display: block; margin-top: 10px; }

/* ── Connection cards ────────────────────────────────────────────────────────── */
.connections { display: flex; flex-direction: column; gap: 10px; margin-bottom: 16px; }

.conn-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
}
.conn-meta { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.conn-label { font-weight: 600; font-size: 15px; }
.conn-sub { font-size: 13px; color: var(--muted); margin-top: 2px; }
.conn-actions { display: flex; gap: 8px; flex-shrink: 0; }

/* ── Folder picker ───────────────────────────────────────────────────────────── */
.crumbs {
  display: flex; flex-wrap: wrap; gap: 6px; align-items: center;
  margin-bottom: 12px; color: var(--muted); font-size: 14px;
}
.crumbs a { color: var(--accent); cursor: pointer; text-decoration: none; }
.crumbs span.sep { opacity: 0.5; }

.folder-list { list-style: none; margin: 0; padding: 0; }
.folder-list li {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 8px;
  background: var(--surface);
  cursor: pointer;
}
.folder-list li:hover { border-color: var(--accent); }

.icon { flex: 0 0 auto; width: 20px; height: 20px; opacity: 0.7; }
.icon-wrap { display: flex; align-items: center; }

/* ── Organizer bar ───────────────────────────────────────────────────────────── */
.organizer-bar {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  margin-bottom: 14px;
  padding: 10px 14px;
}
.organizer-bar[hidden] { display: none !important; }

.org-row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.org-group { display: flex; align-items: center; gap: 8px; }
.org-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  color: var(--muted);
  white-space: nowrap;
}
.org-divider { width: 1px; height: 24px; background: var(--border); flex-shrink: 0; }

.seg-group { display: flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.seg {
  appearance: none;
  background: transparent;
  border: none;
  border-right: 1px solid var(--border);
  color: var(--muted);
  padding: 5px 13px;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
  white-space: nowrap;
}
.seg:last-child { border-right: none; }
.seg:hover { background: var(--surface-2); color: var(--text); }
.seg.active { background: var(--accent); color: #fff; font-weight: 600; }

.filter-select {
  appearance: none;
  background: var(--surface-2) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%23b3a9d6' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E") no-repeat right 10px center;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 13px;
  padding: 5px 32px 5px 12px;
  cursor: pointer;
  max-width: 200px;
}
.filter-select:focus { outline: none; border-color: var(--accent); }
.filter-select[hidden] { display: none !important; }

.search-input {
  appearance: none;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 14px;
  padding: 5px 12px;
  min-width: 130px;
  flex: 1;
}
.search-input::placeholder { color: var(--muted); }
.search-input:focus { outline: none; border-color: var(--accent); }

/* ── Track table ─────────────────────────────────────────────────────────────── */
.track-table-wrap { overflow-x: auto; }

.track-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.track-table[hidden] { display: none !important; }

.track-table thead th {
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  color: var(--muted);
  padding: 0 12px 10px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.track-table tbody tr:not(.track-group-header) {
  border-bottom: 1px solid var(--border);
  transition: background 0.1s;
}
.track-table tbody tr:not(.track-group-header):hover { background: var(--surface); }

.track-table td {
  padding: 10px 12px;
  vertical-align: middle;
}

.col-title  { width: 38%; min-width: 180px; }
.col-album  { width: 22%; min-width: 120px; color: var(--muted); }
.col-tags   { width: 28%; min-width: 120px; }
.col-time   { width: 6%;  min-width: 50px;  text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }
.col-menu   { width: 4%;  min-width: 36px;  text-align: right; }

.track-name  { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 280px; }
.track-artist { font-size: 12px; color: var(--muted); margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 280px; }
.track-src   { font-size: 11px; color: var(--accent); margin-top: 1px; }

/* Group header row */
.track-group-header td {
  padding: 16px 12px 6px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  color: var(--accent);
}
.track-group-header + tr:not(.track-group-header) td { padding-top: 12px; }

/* Tags */
.tags-cell { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.tag-chip {
  display: inline-flex;
  align-items: center;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 11px;
  padding: 2px 8px;
  color: var(--muted);
  white-space: nowrap;
}
.tag-add {
  appearance: none;
  background: none;
  border: 1px dashed var(--border);
  border-radius: 20px;
  color: var(--muted);
  cursor: pointer;
  font-size: 11px;
  padding: 2px 8px;
  transition: border-color 0.15s, color 0.15s;
}
.tag-add:hover { border-color: var(--accent); color: var(--accent); }

/* ⋮ menu button */
.track-menu-btn {
  appearance: none;
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  padding: 4px 6px;
  border-radius: 6px;
  transition: background 0.12s, color 0.12s;
}
.track-menu-btn:hover { background: var(--surface-2); color: var(--text); }

/* ── Context menu ─────────────────────────────────────────────────────────────── */
.ctx-menu {
  position: fixed;
  z-index: 100;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 4px 0;
  min-width: 170px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}
.ctx-menu[hidden] { display: none !important; }

.ctx-item {
  appearance: none;
  background: none;
  border: none;
  color: var(--text);
  cursor: pointer;
  display: block;
  font-size: 14px;
  padding: 9px 16px;
  text-align: left;
  width: 100%;
  transition: background 0.1s;
}
.ctx-item:hover { background: var(--surface); }
.ctx-item:disabled { color: var(--muted); cursor: default; }
.ctx-item:disabled:hover { background: none; }

/* ── Playlist UI ─────────────────────────────────────────────────────────────────── */
.org-mode-bar {
  display: flex;
  gap: 0;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  align-self: flex-start;
  margin-bottom: 18px;
}
.org-mode-bar[hidden] { display: none !important; }

.org-mode-btn {
  appearance: none;
  background: transparent;
  border: none;
  border-right: 1px solid var(--border);
  color: var(--muted);
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  padding: 7px 20px;
  transition: background 0.12s, color 0.12s;
}
.org-mode-btn:last-child { border-right: none; }
.org-mode-btn:hover { background: var(--surface-2); color: var(--text); }
.org-mode-btn.active { background: var(--accent); color: #fff; font-weight: 600; }

.new-playlist-form {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 16px;
}
.new-playlist-form[hidden] { display: none !important; }
.new-playlist-form .sheet-input { flex: 1; max-width: 320px; }

.playlist-cards {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.playlist-card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  cursor: pointer;
  transition: border-color 0.15s;
}
.playlist-card:hover { border-color: var(--accent); }

.playlist-card-thumb {
  width: 44px; height: 44px;
  background: var(--surface-2);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  color: var(--accent);
  font-size: 20px;
}

.playlist-card-meta { flex: 1; min-width: 0; }
.playlist-card-name  { font-weight: 600; font-size: 15px; }
.playlist-card-count { font-size: 13px; color: var(--muted); margin-top: 2px; }

.playlist-card-actions { display: flex; gap: 6px; flex-shrink: 0; }
.playlist-delete-btn {
  appearance: none;
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 16px;
  padding: 4px 8px;
  border-radius: 6px;
  opacity: 0;
  transition: opacity 0.15s, color 0.15s;
}
.playlist-card:hover .playlist-delete-btn { opacity: 1; }
.playlist-delete-btn:hover { color: #ff6b6b; }

.playlist-detail-header {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}
.playlist-detail-header .pane-title { margin: 0; flex: 1; }

.col-pos { width: 40px; text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }
.col-remove { width: 36px; text-align: right; }

.pl-remove-btn {
  appearance: none;
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 16px;
  padding: 4px 6px;
  border-radius: 6px;
  opacity: 0;
  transition: opacity 0.15s, color 0.15s;
}
.track-table tbody tr:hover .pl-remove-btn { opacity: 1; }
.pl-remove-btn:hover { color: #ff6b6b; }

/* ── Sheet (tags & playlists) ────────────────────────────────────────────────────── */
.sheet-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(0,0,0,0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.sheet-overlay[hidden] { display: none !important; }

.sheet {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  width: 100%;
  max-width: 380px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}

.sheet-handle { display: none; }

.sheet-head { display: flex; flex-direction: column; gap: 4px; }
.sheet-title { font-size: 1.1rem; font-weight: 700; }
.sheet-sub   { font-size: 13px; color: var(--muted); }

.sheet-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 40px;
  max-height: 220px;
  overflow-y: auto;
}

.sheet-chip {
  appearance: none;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--muted);
  cursor: pointer;
  font-size: 13px;
  padding: 5px 14px;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
  white-space: nowrap;
}
.sheet-chip:hover  { border-color: var(--accent); color: var(--text); }
.sheet-chip.active { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }

.sheet-empty { color: var(--muted); font-size: 13px; margin: 0; }
.sheet-loading { color: var(--muted); font-size: 13px; }

.sheet-create {
  border-top: 1px solid var(--border);
  padding-top: 14px;
}

.sheet-input {
  appearance: none;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 14px;
  padding: 8px 12px;
  width: 100%;
}
.sheet-input::placeholder { color: var(--muted); }
.sheet-input:focus { outline: none; border-color: var(--accent); }

.sheet-footer { display: flex; gap: 8px; }
.sheet-done-btn { flex: 1; text-align: center; padding: 10px; }

/* ── Player ─────────────────────────────────────────────────────────────────── */
.player-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 60vh;
  color: var(--muted);
  text-align: center;
  padding: 24px;
}
.player-empty[hidden] { display: none !important; }

.player-wrap {
  display: grid;
  grid-template-columns: 380px 1fr;
  min-height: calc(100vh - var(--nav-h));
}
.player-wrap[hidden] { display: none !important; }

.player-main {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 48px 40px 40px;
  border-right: 1px solid var(--border);
  gap: 20px;
}

.player-art {
  width: 220px;
  height: 220px;
  border-radius: 16px;
  background: var(--surface-2);
  overflow: hidden;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.player-art img { width: 100%; height: 100%; object-fit: cover; border-radius: 16px; }
.player-art-icon { width: 100%; height: 100%; display: block; }

.player-info { text-align: center; width: 100%; }
.player-title {
  font-size: 1.1rem;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 300px;
  margin: 0 auto;
}
.player-meta {
  font-size: 13px;
  color: var(--muted);
  margin-top: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 300px;
  margin-left: auto;
  margin-right: auto;
}

.player-progress-row {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
}
.player-time-label {
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  min-width: 36px;
  white-space: nowrap;
}
.player-duration { text-align: right; }

.progress-bar {
  -webkit-appearance: none;
  appearance: none;
  flex: 1;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
}
.progress-bar::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  box-shadow: 0 0 0 3px rgba(124,92,255,0.25);
}
.progress-bar::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  border: none;
  cursor: pointer;
}

.player-controls {
  display: flex;
  align-items: center;
  gap: 12px;
}
.ctrl-btn {
  appearance: none;
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  border-radius: 50%;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s, background 0.15s;
}
.ctrl-btn:hover { color: var(--text); background: var(--surface-2); }
.ctrl-btn svg { width: 22px; height: 22px; }

.ctrl-play-pause {
  width: 56px;
  height: 56px;
  background: var(--accent);
  color: #fff;
}
.ctrl-play-pause:hover { background: #9070ff; color: #fff; }
.ctrl-play-pause svg { width: 26px; height: 26px; }

.player-queue-panel {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}
.queue-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 28px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.queue-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  color: var(--muted);
}
.queue-count { font-size: 13px; color: var(--muted); }

.queue-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  flex: 1;
}
.queue-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 28px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background 0.1s;
}
.queue-item:hover { background: var(--surface); }
.queue-item.now-playing { background: var(--surface); }
.queue-item.now-playing .queue-item-title { color: var(--accent); }
.queue-item-num {
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  min-width: 20px;
  text-align: center;
}
.queue-item.now-playing .queue-item-num { color: var(--accent); }
.queue-item-info { flex: 1; min-width: 0; }
.queue-item-title { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.queue-item-artist { font-size: 12px; color: var(--muted); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.queue-item-time { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; flex-shrink: 0; }

/* Playing indicator in Library table */
.track-row-playing .track-name { color: var(--accent); }

/* ── Responsive ────────────────────────────────────────────────────────────────── */
@media (max-width: 640px) {
  .top-nav { padding: 0 16px; }
  .nav-links { display: none; }
  .bottom-nav { display: flex; }

  .pane-inner { padding: 20px 14px calc(var(--bottom-h) + 20px); }

  .col-album { display: none; }
  .col-time  { display: none; }

  .track-name  { max-width: 55vw; }
  .track-artist { max-width: 55vw; }

  .conn-card { flex-wrap: wrap; }
  .conn-actions { width: 100%; justify-content: flex-start; }

  /* Bottom sheet on mobile */
  .sheet-overlay { align-items: flex-end; padding: 0; }
  .sheet {
    border-radius: 20px 20px 0 0;
    border-bottom: none;
    max-width: 100%;
    padding: 12px 20px 32px;
  }
  .sheet-handle {
    display: block;
    width: 36px; height: 4px;
    background: var(--border);
    border-radius: 2px;
    margin: 0 auto 4px;
  }
  .sheet-chips { max-height: 40vh; }

  /* Mobile player */
  .player-wrap {
    grid-template-columns: 1fr;
    min-height: unset;
  }
  .player-main {
    padding: 28px 20px;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .player-art { width: 160px; height: 160px; }
  .player-queue-panel { height: calc(45vh - var(--bottom-h)); }
  .queue-item  { padding: 10px 16px; }
  .queue-header { padding: 14px 16px 10px; }
}
