:root {
  --bg: #f6f7f9; --panel: #fff; --text: #16181d; --muted: #6b7280; --line: #e3e5ea;
  --accent: #0e7c86; --accent-text: #fff; --ok: #1f8a4c; --warn: #b45309; --bad: #c0392b;
  --owned: #e8f5ee;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111317; --panel: #1a1d23; --text: #e8eaed; --muted: #9aa0a9; --line: #2b2f37;
    --accent: #22a6b3; --accent-text: #061416; --owned: #15301f;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; font: 15px/1.45 system-ui, -apple-system, Segoe UI, sans-serif; background: var(--bg); color: var(--text); }
a { color: var(--accent); }
button, input, select {
  font: inherit; color: inherit; background: var(--panel); border: 1px solid var(--line);
  border-radius: 8px; padding: 8px 12px;
}
button { cursor: pointer; }
button:hover { border-color: var(--accent); }
button:disabled { opacity: .5; cursor: default; }
button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }
button.link { border: 0; background: none; color: var(--muted); padding: 4px; }
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

header {
  display: flex; align-items: center; gap: 24px; padding: 10px 24px;
  background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5;
  flex-wrap: wrap;
}
h1 { font-size: 20px; margin: 0; letter-spacing: -.02em; }
h1 span { color: var(--accent); font-weight: 400; }
nav { display: flex; gap: 4px; }
nav button { border: 0; background: none; color: var(--muted); }
nav button.active { color: var(--text); background: var(--bg); font-weight: 600; }
.account { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.account form { margin: 0; }
.quality-pick { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.quality-pick select { padding: 4px 8px; }
.confirm-list { max-height: 50vh; overflow: auto; }
.pill { font-size: 13px; padding: 3px 10px; border-radius: 99px; border: 1px solid var(--line); cursor: default; }
.pill.ok { color: var(--ok); border-color: currentColor; cursor: pointer; }
.pill.warn { color: var(--warn); border-color: currentColor; }
.badge { background: var(--accent); color: var(--accent-text); border-radius: 99px; padding: 0 7px; font-size: 12px; }

.banner {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  margin: 16px 24px 0; padding: 14px 18px; border-radius: 10px;
  background: var(--panel); border: 1px solid var(--warn);
}
main { padding: 20px 24px 60px; max-width: 1400px; margin: 0 auto; }

.searchbar { display: flex; gap: 8px; }
.searchbar input { flex: 1; min-width: 0; }
.hint { margin: 8px 0 16px; font-size: 13px; color: var(--muted); }

.artists { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
.artist { display: flex; align-items: center; gap: 8px; padding: 4px 12px 4px 4px; border-radius: 99px; }
.artist img, .artist .noimg { width: 32px; height: 32px; border-radius: 50%; object-fit: cover; background: var(--line); }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 16px; }
.album { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; display: flex; flex-direction: column; }
.album.owned { background: var(--owned); border-color: var(--ok); }
.album .cover { position: relative; aspect-ratio: 1; background: var(--line); }
.album .cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.album .meta { padding: 10px 12px 6px; flex: 1; }
.album .title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.album button { margin: 0 12px 12px; }
.tag { position: absolute; top: 8px; left: 8px; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 6px; }
.owned-tag { background: var(--ok); color: #fff; }

.row, .job {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; margin-bottom: 8px;
}
.job-main { min-width: 0; flex: 1; }
.job-actions { display: flex; gap: 6px; }
.job .status { font-weight: 600; margin-right: 8px; }
.job.running .status { color: var(--accent); }
.job.done .status { color: var(--ok); }
.job.partial .status { color: var(--warn); }
.job.failed .status { color: var(--bad); }
.job.cancelled .status, .job.queued .status { color: var(--muted); }
.tail { margin: 6px 0 0; font-size: 12px; color: var(--muted); white-space: pre-wrap; overflow: hidden; max-height: 4.5em; }

.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.toolbar h2 { margin: 0; font-size: 18px; }
#lib-filter, #m-filter { flex: 1; min-width: 180px; }
.toolbar.wrap { flex-wrap: wrap; }
.spacer { flex: 1; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border-radius: 99px; padding: 5px 12px; font-size: 14px; }
.chip.active { background: var(--text); color: var(--bg); border-color: var(--text); }
.chip b { font-weight: 700; margin-left: 4px; }
.album.uncertain { border-color: var(--warn); }
.album.ignored, .album.unavailable { opacity: .55; }
.uncertain-tag { background: var(--warn); color: #fff; }
.queued-tag { background: var(--accent); color: var(--accent-text); }
.album .why { font-size: 12px; color: var(--muted); margin-top: 4px; }
.album .why .warn { color: var(--warn); }
.album .actions { display: flex; gap: 6px; margin: 0 12px 12px; }
.album .actions button { margin: 0; flex: 1; padding: 6px 8px; font-size: 13px; }
#m-more { text-align: center; margin-top: 16px; }
.lib-error { margin-top: 8px; padding: 10px 14px; border: 1px solid var(--bad); border-radius: 8px; color: var(--bad); background: var(--panel); }
#library { columns: 360px; column-gap: 24px; margin-top: 12px; }
.lib-artist { break-inside: avoid; margin-bottom: 14px; }
.lib-artist h3 { font-size: 15px; margin: 0 0 4px; }
.lib-artist ul { list-style: none; margin: 0; padding: 0; }
.lib-artist li { display: flex; justify-content: space-between; gap: 8px; padding: 2px 0; border-bottom: 1px solid var(--line); }
.lib-artist li span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lib-artist li span:last-child { white-space: nowrap; }

dialog { border: 1px solid var(--line); border-radius: 12px; background: var(--panel); color: var(--text); max-width: min(720px, 92vw); width: 100%; }
dialog::backdrop { background: rgba(0, 0, 0, .45); }
dialog h3 { margin-top: 0; }
dialog .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
#log-body { max-height: 60vh; overflow: auto; font-size: 12px; background: var(--bg); padding: 12px; border-radius: 8px; white-space: pre-wrap; }

.open-album { cursor: pointer; }
.artist-link { color: inherit; text-decoration: none; }
.artist-link:hover { color: var(--accent); text-decoration: underline; }
.album .title.open-album:hover { text-decoration: underline; }
.album-dialog { max-width: min(860px, 94vw); padding: 0; }
.ad-head { display: flex; gap: 20px; padding: 20px; border-bottom: 1px solid var(--line); }
.ad-head img, .ad-head .noimg { width: 160px; height: 160px; border-radius: 8px; object-fit: cover; background: var(--line); flex: none; }
.ad-head h3 { margin: 0 0 4px; font-size: 20px; }
.ad-info { display: flex; flex-direction: column; gap: 4px; min-width: 0; flex: 1; }
.ad-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: auto; padding-top: 10px; }
.ad-note { font-size: 13px; padding: 6px 10px; border-radius: 6px; background: var(--owned); color: var(--text); }
.ad-note.warn { background: transparent; border: 1px solid var(--warn); }
.ad-close { position: absolute; top: 10px; right: 12px; border: 0; background: none; font-size: 20px; color: var(--muted); }
.album-dialog { position: relative; }
.tracks { width: 100%; border-collapse: collapse; font-size: 14px; }
.tracks td { padding: 6px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tracks tr.disc td { font-weight: 600; color: var(--muted); padding-top: 14px; }
.tracks tr.unavailable { opacity: .5; }
.tracks .num { width: 32px; text-align: right; color: var(--muted); }
.tracks .dur { width: 56px; text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }
.tracks .sel { width: 28px; }
.tracks .add { width: 40px; text-align: right; }
.tracks .add button { padding: 2px 9px; }
.tracks .t-artist { color: var(--muted); font-size: 13px; }
.ad-tracks { max-height: 55vh; overflow: auto; padding: 4px 12px 16px; }
.pl-layout { display: grid; grid-template-columns: minmax(260px, 340px) 1fr; gap: 20px; align-items: start; margin-top: 8px; }
.pl-list { display: flex; flex-direction: column; gap: 6px; position: sticky; top: 70px; max-height: calc(100vh - 90px); overflow: auto; }
.pl-list input { margin-bottom: 4px; }
.pl-item { display: flex; gap: 10px; align-items: center; text-align: left; padding: 8px; width: 100%; }
.pl-item.active { border-color: var(--accent); box-shadow: inset 3px 0 0 var(--accent); }
.pl-item img, .pl-item .noimg { width: 44px; height: 44px; border-radius: 6px; object-fit: cover; background: var(--line); flex: none; display: grid; place-items: center; }
.pl-item .pl-text { min-width: 0; flex: 1; }
.pl-item .pl-name { display: block; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pl-item .pl-text > .muted, .pl-item .pl-bar { display: block; }
.pl-bar { height: 4px; border-radius: 2px; background: var(--line); margin-top: 4px; overflow: hidden; }
.pl-bar span { display: block; height: 100%; background: var(--ok); }
.badge-s { font-size: 11px; padding: 1px 7px; border-radius: 99px; border: 1px solid currentColor; white-space: nowrap; }
.badge-s.synced { color: var(--ok); }
.badge-s.changed, .badge-s.name_exists { color: var(--warn); }
.badge-s.not_synced { color: var(--muted); }
.pl-detail { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 16px; min-width: 0; }
.pl-head { display: flex; gap: 16px; align-items: flex-start; flex-wrap: wrap; }
.pl-head h2 { margin: 0 0 4px; font-size: 20px; }
.pl-head .spacer { min-width: 10px; }
.pl-tracks { width: 100%; border-collapse: collapse; font-size: 14px; margin-top: 12px; }
.pl-tracks td { padding: 6px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.pl-tracks .num { width: 30px; color: var(--muted); text-align: right; }
.pl-tracks .st { width: 26px; text-align: center; }
.pl-tracks .ok { color: var(--ok); }
.pl-tracks .no { color: var(--bad); }
.pl-tracks tr.missing td { background: color-mix(in srgb, var(--bad) 6%, transparent); }
.pl-tracks .sub { color: var(--muted); font-size: 12px; }
.pl-tracks .sub.warn { color: var(--warn); }
.pl-tracks .acts { white-space: nowrap; text-align: right; }
.pl-tracks .acts button { padding: 3px 9px; font-size: 13px; }
.pl-nd h4 { margin: 14px 0 6px; font-size: 13px; color: var(--muted); font-weight: 600; }
.pl-nd div { font-size: 13px; padding: 3px 0; display: flex; justify-content: space-between; gap: 8px; }
.login-body { display: grid; place-items: center; min-height: 100vh; }
.login-card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 28px; width: min(360px, 92vw); display: grid; gap: 14px; }
.login-card label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
.login-card input { color: var(--text); }
.error { color: var(--bad); margin: 0; }

@media (max-width: 640px) {
  header { padding: 10px 16px; gap: 10px; }
  main { padding: 16px; }
  .banner { margin: 12px 16px 0; flex-direction: column; align-items: stretch; }
  .searchbar { flex-wrap: wrap; }
  .searchbar input { flex-basis: 100%; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
  nav { overflow-x: auto; max-width: 100%; }
  nav button { padding: 6px 8px; white-space: nowrap; }
  .album .actions { flex-direction: column; }
  .ad-head { flex-direction: column; }
  .pl-layout { grid-template-columns: 1fr; }
  .pl-list { position: static; max-height: 40vh; }
  .pl-tracks .alb { display: none; }
  .ad-head img, .ad-head .noimg { width: 120px; height: 120px; }
}
