:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --text: #1c2026;
  --muted: #687080;
  --line: #e2e5ea;
  --accent: #e8590c;
  --accent-soft: #fff1e8;
  --ok: #2b8a3e;
  --warn: #b7791f;
  --bad: #c92a2a;
  --info: #1971c2;
  --log-bg: #15181d;
  --log-text: #d8dde4;
  --drawer-h: 260px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121418;
    --panel: #1b1e24;
    --text: #e4e7ec;
    --muted: #9aa1ad;
    --line: #2c313a;
    --accent: #ff7a2f;
    --accent-soft: #3a2416;
    --ok: #51cf66;
    --warn: #fcc419;
    --bad: #ff6b6b;
    --info: #4dabf7;
    --log-bg: #0c0e11;
  }
}

* {
  box-sizing: border-box;
}
body {
  margin: 0;
  font:
    14px/1.45 -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    Roboto,
    sans-serif;
  background: var(--bg);
  color: var(--text);
  padding-bottom: calc(var(--drawer-h) + 16px);
}
body.drawer-closed {
  padding-bottom: 56px;
}
a {
  color: var(--info);
}
input,
select,
button {
  font: inherit;
  color: inherit;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 5px 8px;
}
button {
  cursor: pointer;
  white-space: nowrap;
}
button:hover:not(:disabled) {
  border-color: var(--muted);
}
button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
button.danger {
  color: var(--bad);
}
button.link {
  border: 0;
  background: none;
  padding: 0;
  color: var(--info);
}
button.small {
  padding: 2px 7px;
  font-size: 12px;
}

.top {
  display: flex;
  align-items: center;
  gap: 20px;
  flex-wrap: wrap;
  padding: 12px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.top h1 {
  margin: 0;
  font-size: 18px;
}
.top h1 span {
  color: var(--muted);
  font-weight: 500;
}
.stats {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  color: var(--muted);
}
.stats b {
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
.job-pill {
  margin-left: auto;
  padding: 3px 10px;
  border-radius: 99px;
  background: var(--line);
  font-size: 12px;
}
.job-pill.running {
  background: var(--accent);
  color: #fff;
  animation: pulse 1.4s infinite;
}
@keyframes pulse {
  50% {
    opacity: 0.65;
  }
}

.tabs {
  display: flex;
  gap: 2px;
  padding: 0 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
}
.tabs button {
  border: 0;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  background: none;
  padding: 10px 14px;
  color: var(--muted);
}
.tabs button.active {
  color: var(--text);
  border-bottom-color: var(--accent);
  font-weight: 600;
}

main {
  padding: 16px 20px;
}
.tab {
  display: none;
}
.tab.active {
  display: block;
}

.toolbar {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  flex-wrap: wrap;
  margin-bottom: 10px;
}
.toolbar label {
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 12px;
  color: var(--muted);
}
.toolbar label.grow {
  flex: 1 1 220px;
}
.toolbar label input,
.toolbar label select {
  color: var(--text);
}
.pair {
  display: flex;
  gap: 4px;
}
.pair input {
  width: 5em;
}
.hint {
  color: var(--muted);
  font-size: 12.5px;
  margin: 0 0 12px;
}

.banner {
  padding: 10px 14px;
  border-radius: 8px;
  margin-bottom: 12px;
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}
.banner.warn {
  background: var(--accent-soft);
  border: 1px solid var(--accent);
}
.banner.info {
  background: var(--panel);
  border: 1px solid var(--line);
}
.banner.error {
  background: var(--panel);
  border: 1px solid var(--bad);
  color: var(--bad);
}
.banner.error b {
  color: var(--text);
}

.summary {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 10px;
  align-items: center;
}

table {
  width: 100%;
  border-collapse: collapse;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}
th,
td {
  padding: 6px 8px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}
th {
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
  background: var(--bg);
  position: sticky;
  top: 0;
  user-select: none;
}
th.sortable {
  cursor: pointer;
}
th.sorted::after {
  content: " ▾";
}
th.sorted.asc::after {
  content: " ▴";
}
tr.clickable {
  cursor: pointer;
}
tbody tr:hover {
  background: var(--bg);
}
td.num,
th.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}
td.chk,
th.chk {
  width: 28px;
}
td.art {
  width: 44px;
  padding: 3px 6px;
}
td.art img {
  width: 36px;
  height: 36px;
  border-radius: 4px;
  display: block;
}
td .sub {
  color: var(--muted);
  font-size: 12px;
}
.ellipsis {
  max-width: 280px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.table-bar {
  display: flex;
  gap: 10px;
  align-items: center;
  margin: 8px 0;
  flex-wrap: wrap;
}
.table-bar .spacer {
  flex: 1;
}
.pager {
  display: flex;
  gap: 6px;
  align-items: center;
  color: var(--muted);
}

.badge {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 99px;
  font-size: 11.5px;
  font-weight: 600;
  border: 1px solid currentColor;
  white-space: nowrap;
}
.badge.new {
  color: var(--ok);
}
.badge.in-catalog,
.badge.added {
  color: var(--info);
}
.badge.no-bpm,
.badge.duplicate {
  color: var(--warn);
}
.badge.alt-version,
.badge.removed,
.badge.rejected-genre {
  color: var(--muted);
}
.badge.failed {
  color: var(--bad);
}
.chip {
  display: inline-block;
  padding: 0 6px;
  margin: 1px 2px 1px 0;
  border-radius: 4px;
  background: var(--bg);
  border: 1px solid var(--line);
  font-size: 11.5px;
}

.histogram {
  display: flex;
  align-items: flex-end;
  gap: 2px;
  height: 90px;
  padding: 8px;
  margin-bottom: 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.histogram .bar {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  height: 100%;
  cursor: pointer;
}
.histogram .bar div {
  width: 100%;
  background: var(--accent);
  opacity: 0.75;
  border-radius: 3px 3px 0 0;
  min-height: 1px;
}
.histogram .bar:hover div,
.histogram .bar.on div {
  opacity: 1;
}
.histogram .bar span {
  font-size: 9.5px;
  color: var(--muted);
  margin-top: 2px;
}

.drawer {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: var(--drawer-h);
  background: var(--panel);
  border-top: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  z-index: 5;
}
body.drawer-closed .drawer {
  height: 44px;
}
body.drawer-closed .log {
  display: none;
}
.drawer-bar {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 7px 16px;
  border-bottom: 1px solid var(--line);
}
.drawer-bar .spacer {
  flex: 1;
}
.job-status {
  color: var(--muted);
}
.log {
  flex: 1;
  margin: 0;
  padding: 8px 16px;
  overflow: auto;
  background: var(--log-bg);
  color: var(--log-text);
  font:
    12px/1.45 ui-monospace,
    Menlo,
    monospace;
  white-space: pre-wrap;
}
.log .err {
  color: #ff8787;
}
.log .cmd {
  color: #ffa94d;
}

dialog {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  color: var(--text);
  max-width: 640px;
  width: calc(100% - 32px);
  padding: 20px;
}
dialog::backdrop {
  background: rgba(0, 0, 0, 0.4);
}
dialog .close {
  float: right;
  border: 0;
  background: none;
  font-size: 16px;
}
.details-head {
  display: flex;
  gap: 16px;
  margin-bottom: 14px;
}
.details-head img {
  width: 120px;
  height: 120px;
  border-radius: 8px;
}
.details-head h2 {
  margin: 0 0 4px;
  font-size: 18px;
}
dl.fields {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 3px 14px;
  margin: 0;
  font-size: 13px;
}
dl.fields dt {
  color: var(--muted);
}
dl.fields dd {
  margin: 0;
  word-break: break-all;
}
.feat {
  display: inline-block;
  width: 120px;
  height: 7px;
  background: var(--line);
  border-radius: 4px;
  vertical-align: middle;
  margin-right: 6px;
}
.feat i {
  display: block;
  height: 100%;
  background: var(--accent);
  border-radius: 4px;
}

.toast {
  position: fixed;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 8px 16px;
  border-radius: 8px;
  opacity: 0;
  transition: opacity 0.2s;
  pointer-events: none;
  z-index: 20;
  max-width: 90vw;
}
.toast.show {
  opacity: 1;
}
.toast.error {
  background: var(--bad);
  color: #fff;
}
.empty {
  padding: 30px;
  text-align: center;
  color: var(--muted);
  background: var(--panel);
  border: 1px dashed var(--line);
  border-radius: 8px;
}

td.play {
  width: 36px;
  padding-right: 0;
}
.play-btn {
  width: 28px;
  padding: 2px 0;
}
.play-btn.on {
  background: #1db954;
  border-color: #1db954;
  color: #fff;
}
.play-btn-wide {
  background: #1db954;
  border-color: #1db954;
  color: #fff;
  font-weight: 600;
  margin-right: 8px;
}
.play-btn-wide.on {
  background: #179443;
}

.player {
  position: fixed;
  right: 16px;
  bottom: calc(var(--drawer-h) + 12px);
  width: min(440px, calc(100vw - 32px));
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 8px;
  z-index: 6;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.25);
}
.player[hidden] {
  display: none;
}
body.drawer-closed .player {
  bottom: 56px;
}
.player iframe {
  display: block;
  border: 0;
  border-radius: 12px;
}
.player-side {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-top: 6px;
  font-size: 12px;
}
.player-title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
}
body.playing {
  padding-bottom: calc(var(--drawer-h) + 150px);
}
body.playing.drawer-closed {
  padding-bottom: 190px;
}

/* Genres board: cards shaped like genres.json groups */
.gboard {
  display: grid;
  grid-template-columns: 250px 1fr;
  gap: 14px;
  align-items: start;
}
.glist {
  display: flex;
  flex-direction: column;
  gap: 2px;
  position: sticky;
  top: 8px;
  max-height: calc(100vh - 90px);
  overflow: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 6px;
}
.gitem {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  width: 100%;
  text-align: left;
  border: 1px solid transparent;
  background: none;
  border-radius: 7px;
  padding: 6px 10px;
}
.gitem:hover:not(.on) {
  background: var(--bg);
  border-color: transparent;
}
.gitem.on {
  background: var(--accent-soft);
  border-color: var(--accent);
  font-weight: 600;
}
.gitem-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.gitem-n {
  color: var(--muted);
  font-size: 12px;
  font-weight: 400;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.gitem.changed .gitem-name::after {
  content: " ●";
  color: var(--accent);
}
.gitem.special .gitem-name {
  color: var(--muted);
}
.gitem.special.on .gitem-name {
  color: var(--text);
}
.glist-sep {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  padding: 10px 10px 4px;
  border-top: 1px solid var(--line);
  margin-top: 4px;
}
.gdetail-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 12px;
  align-items: start;
}
.gdetail-cards.single {
  grid-template-columns: 1fr;
}
.gdetail-cards.single .gchip {
  font-size: 13.5px;
  padding: 4px 10px;
}
.gtip {
  margin-top: 10px;
}
.gpanel,
.gcard {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
}
.gpanel h3 {
  margin: 0;
  font-size: 13.5px;
}
.gpanel h3 span,
.gcount {
  color: var(--muted);
  font-weight: 500;
  font-size: 12px;
}
.gpanel .hint {
  margin: 2px 0 8px;
  font-size: 12px;
}
.gpanel.rejected .gchip {
  color: var(--muted);
  text-decoration: line-through;
}
.gcard.changed,
.gchip.changed {
  border-color: var(--accent);
}
.gcard-head {
  display: flex;
  align-items: center;
  gap: 6px;
}
.gcard > .gcount {
  display: block;
  margin: 1px 0 8px;
}
.warn-list {
  margin: 4px 0 0;
  padding-left: 18px;
  font-size: 13px;
}
.gcard-head .spacer {
  flex: 1;
}
.gcard-head button.small {
  padding: 1px 7px;
  font-size: 11.5px;
}
.gname {
  font-size: 14.5px;
  font-weight: 700;
  color: var(--text) !important;
}
.gname:hover {
  text-decoration: underline;
}
.gchips {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  min-height: 26px;
}
.gchip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 8px;
  border: 1px solid var(--line);
  border-radius: 99px;
  background: var(--bg);
  font-size: 12.5px;
  cursor: grab;
  user-select: none;
}
.gchip:has(.gx) {
  padding-right: 2px;
}
.gchip b {
  color: var(--muted);
  font-weight: 600;
  font-size: 11.5px;
  font-variant-numeric: tabular-nums;
}
.gchip.namesake {
  font-weight: 600;
  border-style: dashed;
}
.gchip.dim {
  opacity: 0.3;
}
.gchip.hit {
  border-color: var(--info);
}
.gchip.dragging {
  opacity: 0.35;
}
.gx {
  border: 0;
  background: none;
  padding: 0 5px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1;
}
.gx:hover {
  color: var(--bad);
}
.gadd {
  width: 100%;
  margin-top: 8px;
  font-size: 12.5px;
  padding: 4px 8px;
}
.gempty {
  color: var(--muted);
  font-size: 12px;
  padding: 3px 0;
}
[data-drop].over {
  outline: 2px dashed var(--accent);
  outline-offset: 2px;
  background: var(--accent-soft);
}
@media (max-width: 800px) {
  .gboard {
    grid-template-columns: 1fr;
  }
  .glist {
    position: static;
    max-height: 260px;
  }
}
code {
  font-size: 12px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 0 4px;
}

@media (max-width: 700px) {
  main {
    padding: 12px 16px;
  }
  .top {
    padding: 10px 16px;
  }
  .hide-sm {
    display: none;
  }
}

/* Status tab: live runs and the run log */
h2 {
  font-size: 15px;
  margin: 18px 0 8px;
}
.run-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 12px;
}
.run-card table {
  border: 0;
  border-radius: 0;
}
.run-head {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  align-items: baseline;
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 6px;
}
.run-head b {
  color: var(--text);
}
.run-head .sub {
  font-size: 12px;
}
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin: 4px 0 8px;
}
.chips .chip {
  color: var(--muted);
}
.chips .chip.on {
  color: var(--text);
}
.chips .chip b {
  font-variant-numeric: tabular-nums;
}
.status-table td .sub {
  font-size: 12px;
}
.status-table td.num {
  white-space: nowrap;
}
#logoutBtn {
  margin-left: 8px;
}
/* ---- status tab: batches, run dialog ---- */
dialog.wide {
  width: min(96vw, 1100px);
  max-width: 96vw;
}
dialog.wide #detailsBody {
  max-height: 80vh;
  overflow: auto;
}
dialog.wide table {
  width: 100%;
}
dialog.wide .details-head h2 {
  margin-top: 0;
}
.status-table td .wrap {
  white-space: normal;
  overflow-wrap: anywhere;
}
.batch-table td:last-child {
  max-width: 420px;
}
.played-line {
  margin: 6px 2px 2px;
  font-size: 13px;
  line-height: 1.8;
  overflow-wrap: anywhere;
}
.played-line .played-item a {
  color: var(--text);
  text-decoration: none;
  border-bottom: 1px dotted var(--muted);
}
.played-line .played-item a:hover {
  border-bottom-style: solid;
}
.played-line .badge {
  padding: 0 5px;
  font-size: 10px;
  margin-left: 2px;
}
.run-card .empty {
  padding: 14px;
}

/* active runs: one row per run, the open one shows its batches underneath */
.runs-table .caret {
  color: var(--muted);
  display: inline-block;
  width: 1em;
}
.runs-table tr.open td {
  background: color-mix(in srgb, var(--accent) 8%, transparent);
}
.runs-table tr.run-detail td {
  padding: 10px 12px 14px;
  background: var(--panel);
}
.runs-table tr.run-detail:hover td {
  background: var(--panel);
}
