:root {
  --bg: #15171c;
  --panel: #1e2128;
  --panel2: #262a33;
  --text: #e8eaed;
  --muted: #9aa0ab;
  --accent: #4f8cff;
  --accent-contrast: #ffffff;
  --border: #333844;
  --danger: #ff6b6b;
  --ok: #5ad17f;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.4;
}

header {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}

h1 { font-size: 20px; margin: 0; }
h2 { font-size: 16px; margin: 0 0 12px; }
.muted { color: var(--muted); font-weight: 400; font-size: 14px; }

/* "Signed in as <name>" + the items.json link, top-right of the header. */
.who { display: flex; align-items: center; gap: 12px; font-size: 13px; color: var(--muted); }
.who .whoLabel { color: var(--muted); }
.who .whoName { color: var(--text); font-weight: 600; }
.who .whoName.unset { color: var(--muted); font-weight: 400; }
.who a { color: var(--accent); text-decoration: none; }
.who a.hidden { display: none; }

/* Team picker in the header — which team's library is being edited (applies across the tabs). */
.teamBar { display: flex; align-items: center; gap: 8px; }
.teamBar select {
  font-size: 14px;
  font-weight: 600;
  padding: 6px 10px;
  color: var(--text);
  background: var(--panel2);
  border: 1px solid var(--border);
  border-radius: 8px;
  max-width: 60vw;
}
.teamBar select:disabled { color: var(--muted); font-weight: 400; }
.teamBar a { color: var(--accent); text-decoration: none; font-size: 13px; white-space: nowrap; }
.teamBar a:hover { text-decoration: underline; }

/* ---- Tab bar ---- */
/* The nav stays pinned to the top while scrolling (the header above may scroll away). On a wide
   screen it's a horizontal row of tabs; on a phone it collapses to a single bar with a ☰ button
   that drops the tabs down (see the media query below). The sticky container's measured height is
   published as --tabbar-h (app.js) so the section nav + band headers sit just below it. */
.navWrap {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 0 20px;
}
.tabs .tab {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  padding: 12px 14px;
  color: var(--muted);
  font-weight: 600;
}
.tabs .tab:hover { color: var(--text); border-bottom-color: var(--border); }
.tabs .tab.active { color: var(--text); border-bottom-color: var(--accent); }
/* Push "Settings" to the far right. */
.tabs .settingsTab { margin-left: auto; }

/* The ☰ menu button — shown only on narrow screens (see the media query below). */
.navToggle {
  display: none;
  width: 100%;
  align-items: center;
  gap: 10px;
  padding: 12px 20px;
  background: none;
  border: none;
  border-radius: 0;
  color: var(--text);
  font-weight: 700;
  text-align: left;
}
.navToggle:hover { border: none; }
.navToggle .navToggleIcon { font-size: 18px; line-height: 1; }
.navToggle .navToggleLabel { flex: 1 1 auto; }

/* A small count pill on the Review Flags tab. */
.tabBadge {
  display: inline-block;
  min-width: 18px;
  text-align: center;
  font-size: 12px;
  font-weight: 700;
  color: #ff8f00;
  border: 1px solid #ff8f00;
  border-radius: 999px;
  padding: 0 6px;
  margin-left: 2px;
}

/* Phones: collapse the tab row into a ☰ dropdown so it isn't a cramped two-row wrap.
   The list is absolutely positioned under the sticky bar so opening it overlays the page
   instead of shoving everything down. */
@media (max-width: 640px) {
  .navToggle { display: flex; }
  .tabs {
    display: none;
    position: absolute;
    left: 0; right: 0; top: 100%;
    flex-direction: column;
    flex-wrap: nowrap;
    gap: 0;
    padding: 0;
    max-height: calc(100vh - var(--tabbar-h, 48px));
    overflow-y: auto;
    background: var(--panel);
    border-bottom: 1px solid var(--border);
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.35);
  }
  .tabs.open { display: flex; }
  .tabs .tab {
    width: 100%;
    text-align: left;
    padding: 12px 20px;
    border-bottom: 1px solid var(--border);
    border-left: 3px solid transparent;
  }
  .tabs .tab:last-child { border-bottom: none; }
  .tabs .tab:hover { border-bottom-color: var(--border); border-left-color: var(--border); }
  .tabs .tab.active { border-bottom-color: var(--border); border-left-color: var(--accent); }
  .tabs .settingsTab { margin-left: 0; }
}

/* Only the active tab's panel is shown. */
.tabPanel { display: none; flex-direction: column; gap: 20px; }
.tabPanel.active { display: flex; }

main {
  max-width: 900px;
  margin: 0 auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
}
.panelHead { display: flex; flex-wrap: wrap; gap: 12px; justify-content: space-between; align-items: flex-start; }

input, select, button {
  font: inherit;
  color: var(--text);
  background: var(--panel2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
}
input::placeholder { color: var(--muted); }
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 0; }

button { cursor: pointer; background: var(--panel2); }
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); color: var(--accent-contrast); border-color: var(--accent); }
button.danger { color: var(--danger); }
button:disabled { opacity: 0.5; cursor: not-allowed; }

.addRow { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 10px; }
.checkLabel { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); white-space: nowrap; }
.addRow input[type="text"]:not(.start) { flex: 1 1 260px; }
/* A single input + button add row (e.g. "Add category") keeps the button beside the field instead
   of wrapping it below when the panel heading squeezes the row. The input shrinks instead. */
.addRow.tight { flex-wrap: nowrap; }
.addRow.tight input[type="text"]:not(.start) { flex: 1 1 auto; min-width: 0; }

/* The "All users" add row: name, email, password, then the button, all on one line. Email is the
   widest; name and password are equal and narrower. (input.* ties the generic 260px rule above on
   specificity, and wins by coming later.) */
.addRow.userAdd { flex-wrap: nowrap; }
.addRow.userAdd input.uName,
.addRow.userAdd input.uPass { flex: 2 1 150px; min-width: 0; }
.addRow.userAdd input.uEmail { flex: 3 1 200px; min-width: 0; }
.start { width: 120px; }
#addCategory { flex: 0 1 220px; }

.msg { min-height: 18px; margin: 4px 0 0; font-size: 13px; }
.msg.err { color: var(--danger); }
.msg.ok { color: var(--ok); }

.hidden { display: none; }

.preview {
  display: flex;
  gap: 12px;
  align-items: center;
  background: var(--panel2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  margin-bottom: 10px;
}
.preview img { width: 120px; border-radius: 6px; }
.preview .pt { font-weight: 600; }
.preview .pa { color: var(--muted); font-size: 13px; }

.categoryList { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.categoryList > li {
  background: var(--panel2); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px;
}
.categoryList button { padding: 4px 8px; }

/* Category band header */
.catHead { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.catHead .cname { flex: 1; font-weight: 600; }

/* Subcategories (the buttons) nested under a band */
.subList { list-style: none; margin: 8px 0 0; padding: 0 0 0 12px; display: flex; flex-direction: column; gap: 4px; border-left: 2px solid var(--border); }
.subList li.sub { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.subList li.sub .sname { flex: 1; }
.subList li.sub .dragHandle { cursor: grab; color: var(--muted); padding: 0 4px; line-height: 1; font-size: 18px; user-select: none; touch-action: none; }
.subList li.sub .dragHandle:active { cursor: grabbing; }
.subList li.sub.dragging { opacity: 0.5; }
.subList li.addSub { display: flex; gap: 6px; margin-top: 4px; }
.subList li.addSub input { flex: 1; }
.moveSel { padding: 3px 6px; }

/* Per-category button color square, just left of Rename. */
.swatch {
  width: 26px; height: 26px; flex: 0 0 auto;
  padding: 0; border: 1px solid var(--border); border-radius: 6px;
  cursor: pointer; vertical-align: middle; background: transparent;
}
input.swatch { -webkit-appearance: none; appearance: none; }
input.swatch::-webkit-color-swatch-wrapper { padding: 2px; }
input.swatch::-webkit-color-swatch { border: none; border-radius: 4px; }
input.swatch::-moz-color-swatch { border: none; border-radius: 4px; }
.swatch.empty { display: inline-block; background: #000; opacity: 0.6; cursor: default; }

/* ---- Edit Songs: left section nav + song list ----
   The songs panel keeps its original (centered, max-900 main) width; the nav row is pulled
   left by its own width so the nav sits in the gutter beside the panel rather than shrinking
   it. Below the breakpoint this collapses to a chip bar on top (see the media query). */
.editLayout { display: flex; gap: 16px; align-items: flex-start; margin-left: -206px; }
.songsPanel { flex: 1 1 auto; min-width: 0; }

.sectionNav {
  flex: 0 0 190px;
  position: sticky; top: calc(var(--tabbar-h, 45px) + 12px);
  max-height: calc(100vh - var(--tabbar-h, 45px) - 24px);
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
}
.sectionNav .navGroup { display: flex; flex-direction: column; gap: 2px; margin-bottom: 10px; }
.sectionNav .navGroup:last-child { margin-bottom: 0; }
.sectionNav button {
  text-align: left;
  background: none;
  border: none;
  border-radius: 6px;
  padding: 5px 8px;
  width: 100%;
  color: var(--text);
}
.sectionNav button:hover { background: var(--panel2); border: none; }
.sectionNav .navCat { font-weight: 700; }
.sectionNav .navCat.uncat { color: var(--muted); }
.sectionNav .navSub { padding-left: 16px; font-size: 13px; color: var(--muted); }
.sectionNav .navSub:hover { color: var(--text); }

/* Song search box pinned at the top of the section nav. The groups wrapper uses display:contents
   so the bands still lay out as direct children of .sectionNav (block on wide, flex-wrap on narrow). */
.sectionNav .songSearch { margin-bottom: 10px; }
.sectionNav #songSearch { width: 100%; }
#sectionNavGroups { display: contents; }
.sectionNav .navCount { padding: 2px 4px; }

/* Not enough gutter to the left of the centered 860px panel for the nav: drop it to a
   wrapping chip bar above the list, and let the panel take the full main width again. */
@media (max-width: 1280px) {
  .editLayout { flex-direction: column; margin-left: 0; gap: 12px; }
  .sectionNav {
    flex: 1 1 auto; width: 100%;
    position: static; max-height: none;
    display: flex; flex-wrap: wrap; gap: 4px;
  }
  .sectionNav .navGroup { flex-direction: row; flex-wrap: wrap; gap: 4px; margin-bottom: 0; }
  .sectionNav button { width: auto; border: 1px solid var(--border); }
  /* Full-width search box above the wrapping chip row. */
  .sectionNav .songSearch { flex: 1 1 100%; margin-bottom: 0; }
}

/* Each category is its own bounded, rounded card so a new band is obvious while scrolling. */
.catGroup {
  background: var(--panel);
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: 12px;
  padding: 0 14px 10px;
  margin-bottom: 22px;
}
.catGroup.uncat { border-left-color: var(--muted); }

/* Big category title, pinned just under the sticky tab bar while you scroll that band. */
.catGroup > h3 {
  position: sticky; top: var(--tabbar-h, 45px); z-index: 3;
  scroll-margin-top: var(--tabbar-h, 45px); /* jumped-to from the nav: clear the tab bar */
  margin: 0 -14px 10px; padding: 12px 16px;
  font-size: 22px; font-weight: 700; color: var(--text);
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  border-radius: 11px 11px 0 0;
}
.catGroup.uncat > h3 { color: var(--muted); }
.catGroup > h4 {
  font-size: 13px; margin: 12px 0 6px 2px; color: var(--muted);
  font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em;
  /* Jumped-to from the section nav: clear both the tab bar and the sticky band title above it. */
  scroll-margin-top: calc(var(--tabbar-h, 45px) + 60px);
}

/* Icon-only buttons (e.g. the song's red trashcan). */
.iconBtn { display: inline-flex; align-items: center; justify-content: center; padding: 6px 8px; }
.iconBtn svg { display: block; }
.iconBtn.fav { color: #e0245e; }
.iconBtn.fav:hover { border-color: #e0245e; }

/* Per-song flag-for-review picker; amber when the song is flagged. */
.flagSel { flex: 0 0 auto; width: auto; padding: 6px 8px; font-size: 13px; }
.flagSel.flagged { color: #ff8f00; border-color: #ff8f00; }

/* Flagged-for-review editor card: fix anything about the song, then save & clear the flag. */
.flagReview {
  background: var(--panel2);
  border: 1px solid var(--border);
  border-left: 4px solid #ff8f00;
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 10px;
}
.flagReviewHead {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}
.flagReviewHead .stamp {
  font-size: 11px;
  line-height: 1.35;
  color: var(--muted);
  opacity: 0.85;
}
.flagReviewBody { display: flex; gap: 12px; align-items: flex-start; }
.flagReviewLeft { display: flex; flex-direction: column; gap: 6px; flex: 0 0 auto; }
.flagReviewLeft img { width: 136px; border-radius: 6px; cursor: pointer; }
.flagReviewFields { flex: 1 1 auto; display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.flagReviewField { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.flagReviewLabel { font-size: 12px; color: var(--muted); }
.flagReviewField input, .flagReviewField select { width: 100%; }
.flagReviewRow { display: flex; gap: 10px; }
.flagReviewRow .flagReviewField:first-child { flex: 0 0 120px; }
.flagReviewRow .flagReviewField:last-child { flex: 1 1 auto; }
.flagReviewActions { display: flex; align-items: center; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.flagReviewSpacer { flex: 1 1 auto; }
@media (max-width: 560px) {
  .flagReviewBody { flex-direction: column; }
  .flagReviewLeft img { width: 100%; }
}

/* A conflict note on a proposed-edit card. */
.conflictNote { color: var(--danger); font-size: 12px; font-weight: 600; }

/* Proposed-edit diff: one "Field: old → new" line per changed field. */
.proposedDiffs { display: flex; flex-direction: column; gap: 4px; margin-top: 8px; }
.diffRow { display: grid; grid-template-columns: 90px 1fr auto 1fr; gap: 8px; align-items: baseline; font-size: 14px; }
.diffKey { color: var(--muted); font-size: 12px; }
.diffOld { color: var(--muted); text-decoration: line-through; word-break: break-word; }
.diffArrow { color: var(--muted); }
.diffNew { font-weight: 600; word-break: break-word; }
@media (max-width: 560px) { .diffRow { grid-template-columns: 1fr; } .diffArrow { display: none; } }

/* Changelog: filterable columns — When · User · Action · Was · Is · Item. */
.clogFilter { display: flex; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; }
.clogFilter select { flex: 0 0 auto; }
.clogFilter input { flex: 1 1 220px; }
.logRow {
  display: grid;
  grid-template-columns: 150px 115px 135px 1fr 1fr 1.2fr;
  gap: 10px;
  align-items: baseline;
  padding: 7px 4px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
.logHead { font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); font-weight: 600; border-bottom: 2px solid var(--border); }
.logWhen { color: var(--muted); font-size: 12px; }
.logWho { font-weight: 600; word-break: break-word; }
.logAction { font-weight: 600; }
/* was/is may list several "field: value" lines for a multi-field edit — keep the line breaks. */
.logWas, .logIs { color: var(--muted); word-break: break-word; white-space: pre-line; }
.logItem { color: var(--text); word-break: break-word; }
@media (max-width: 720px) {
  .logRow { grid-template-columns: 1fr 1fr; gap: 2px 10px; }
  .logHead { display: none; }
  .logWhen, .logItem { grid-column: 1 / -1; }
}

.song {
  display: grid;
  grid-template-columns: 136px 1fr auto;
  gap: 12px;
  align-items: start;
  background: var(--panel2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  margin-bottom: 8px;
}
.song .songLeft { display: flex; flex-direction: column; gap: 6px; }
.song img { width: 136px; border-radius: 6px; cursor: pointer; }
/* Who added / last edited this song, and when — small, light grey, under the thumbnail. */
.song .stamp { font-size: 11px; line-height: 1.35; color: var(--muted); opacity: 0.85; word-break: break-word; }
.song .title { font-weight: 600; }
.song .author { color: var(--muted); font-size: 13px; }
.song .controls { display: flex; flex-direction: column; align-items: stretch; gap: 6px; min-width: 240px; }
.song .ctrlRow { display: flex; gap: 6px; align-items: center; justify-content: space-between; }
.song .controls input.start { width: 90px; }
.song .ctrlRow.fields select { flex: 0 1 200px; max-width: 300px; }
.song .ctrlRow.flagicons .flagSel { flex: 0 0 auto; width: 150px; }
.song .iconGroup { display: flex; gap: 6px; align-items: center; }
.song .controls button { padding: 6px 8px; font-size: 13px; }
.song.dead { outline: 1px solid var(--danger); }

/* "▶ Preview" sits under the title and acts as a link, though it's a <button>. */
.ytlink { color: var(--accent); font-size: 13px; }
button.ytlink {
  display: inline-block; margin-top: 2px; padding: 0;
  background: none; border: none; cursor: pointer; text-align: left;
}
button.ytlink:hover { text-decoration: underline; border: none; }

dialog {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel);
  color: var(--text);
  padding: 0;
  width: min(720px, 92vw);
}
dialog::backdrop { background: rgba(0,0,0,0.6); }
.dialogHead { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--border); }
#previewFrame iframe { width: 100%; aspect-ratio: 16 / 9; border: 0; display: block; }

@media (max-width: 560px) {
  .song { grid-template-columns: 1fr; }
  .song img { width: 100%; }
}

/* ---- Sign-out link in the header ---- */
.linkBtn {
  background: none;
  border: none;
  color: var(--accent);
  padding: 0;
  font-size: 13px;
  cursor: pointer;
}
.linkBtn:hover { text-decoration: underline; border: none; }

/* ---- Users (admin) tab ---- */
.userList { list-style: none; margin: 12px 0 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.userRow {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  background: var(--panel2);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.userRow.off { opacity: 0.55; }
.userInfo { display: flex; flex-wrap: wrap; align-items: baseline; gap: 8px; }
.userInfo .userName { font-weight: 600; }
.userInfo .userEmail { color: var(--muted); font-size: 13px; }
.userInfo .userTag {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 1px 8px;
}
.userControls { display: flex; flex-wrap: wrap; gap: 6px; }
.userControls button, .userControls select { padding: 4px 8px; font-size: 13px; }

/* Teams (admin, Settings tab) */
.teamList { list-style: none; margin: 12px 0 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.teamRow {
  padding: 10px 12px;
  background: var(--panel2);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.teamHead {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
}
.teamControls { display: flex; flex-wrap: wrap; gap: 6px; }
.teamControls button { padding: 4px 8px; font-size: 13px; }
.teamMembers, .teamEdit { margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--border); }
.memberList { list-style: none; margin: 0 0 10px; padding: 0; display: flex; flex-direction: column; gap: 6px; }
/* Identity grows; Role and Remove size to their content (so the dropdown stays compact). */
.memberRow {
  display: grid;
  grid-template-columns: 1fr max-content max-content;
  gap: 10px;
  align-items: center;
}
.mIdent { display: flex; flex-direction: column; min-width: 0; }
.mIdent .mEmail { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.memberRow select { justify-self: start; }
.memberRow select, .memberRow button { padding: 4px 8px; font-size: 13px; }
