:root {
  --bg: #14161a;
  --panel: #1d2026;
  --panel-2: #232730;
  --line: #313643;
  --text: #e6e8ec;
  --muted: #8b93a3;
  --accent: #4363d8;
  --row-h: 40px;
  --name-w: 300px;
  --col-w: 150px;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 system-ui, "Segoe UI", Roboto, sans-serif;
}
.hidden { display: none !important; }
.error { color: #ff6b6b; }

/* Login */
.login { height: 100vh; display: grid; place-items: center; }
.login-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 28px;
  width: 320px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.login-card h1 { font-size: 18px; margin: 0 0 6px; }
.login-card label { display: flex; flex-direction: column; gap: 5px; font-size: 12px; color: var(--muted); }
.login-card input {
  background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
  border-radius: 6px; padding: 9px 10px; font-size: 14px;
}
button {
  background: var(--accent); color: #fff; border: 0; border-radius: 6px;
  padding: 9px 14px; font-size: 14px; cursor: pointer;
}
button:hover { filter: brightness(1.1); }
button.ghost { background: var(--panel-2); border: 1px solid var(--line); color: var(--text); }

/* App shell */
.app { height: 100vh; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 14px; border-bottom: 1px solid var(--line); background: var(--panel);
}
.topbar .spacer { flex: 1; }
.topbar input[type="search"] {
  background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
  border-radius: 6px; padding: 7px 10px; width: 280px;
}
.whoami { color: var(--muted); font-size: 13px; }

/* Grid */
.grid { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.grid-header { overflow: hidden; border-bottom: 1px solid var(--line); background: var(--panel); }
.grid-scroll { flex: 1; overflow: auto; position: relative; }
.grid-canvas { }

.row, .header-row { display: flex; height: var(--row-h); align-items: stretch; }
.header-row { height: var(--row-h); }

.cell-name, .cell-user, .corner, .colhead {
  flex: 0 0 auto; display: flex; align-items: center;
  padding: 0 10px; border-right: 1px solid var(--line); overflow: hidden;
}
.cell-name, .corner { width: var(--name-w); position: sticky; left: 0; z-index: 2; background: var(--panel); }
.cell-user, .colhead { width: var(--col-w); }

.row { border-bottom: 1px solid var(--line); }
.row:hover .cell-name { background: var(--panel-2); }
.row.selected .cell-name { background: #2a3550; }
.cell-name { background: var(--panel); }
.row:nth-child(even) .cell-user { background: rgba(255,255,255,0.012); }

.cell-name .evt { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cell-name .grp { color: var(--muted); font-size: 11px; margin-left: 6px; }

.colhead { font-weight: 600; gap: 8px; }
.colhead .swatch { width: 10px; height: 10px; border-radius: 50%; flex: 0 0 auto; }
.corner { font-weight: 600; color: var(--muted); }

.cell-user { color: var(--muted); flex-direction: column; justify-content: center; gap: 2px; cursor: default; }
.cell-user .cell-main { display: flex; align-items: center; justify-content: center; gap: 6px; }
.cell-user.mine { cursor: pointer; }
.cell-user .dur { font-variant-numeric: tabular-nums; font-size: 12px; }
.cell-user.empty .dur { opacity: 0.35; }
.cell-user.drop { outline: 2px dashed var(--accent); outline-offset: -2px; background: rgba(67,99,216,0.12); }
.cell-user.rec-active { background: rgba(255,107,107,0.14); }

.cell-btn {
  background: transparent; border: 0; color: var(--text); cursor: pointer;
  padding: 2px 6px; font-size: 13px; border-radius: 4px; line-height: 1;
}
.cell-btn:hover { background: var(--panel-2); filter: none; }
.cell-btn.play { color: var(--accent); }
.cell-btn.rec, .cell-btn.rec-mini { color: #ff6b6b; }
.cell-btn.rec { border: 1px solid var(--line); }
.cell-btn.rec-mini { opacity: 0.5; font-size: 11px; }
.cell-btn.rec-mini:hover { opacity: 1; }
/* Favorite star — dim by default, gold when active */
.cell-btn.fav { color: var(--muted); opacity: 0.55; font-size: 14px; }
.cell-btn.fav:hover { opacity: 1; color: #f1c40f; }
.cell-btn.fav.on { color: #f1c40f; opacity: 1; }
/* Topbar favorites filter button */
.favorites-btn { font-size: 13px; min-width: 95px; }
.favorites-btn.active { border-color: #f1c40f; color: #f1c40f; }
.cell-user .take-count {
  font-size: 10px; background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 8px; padding: 0 5px; color: var(--muted); cursor: pointer;
}
.cell-btn.vote { color: var(--muted); font-size: 13px; }
.cell-btn.vote.voted { color: #ff6b6b; }
.cell-user .dots { display: inline-flex; gap: 2px; align-items: center; justify-content: center; min-height: 7px; }
.cell-user .dots .dot { width: 7px; height: 7px; border-radius: 50%; display: inline-block; }
.cell-user.winner { box-shadow: inset 0 0 0 2px #d9b310; }

/* Work area: grid + editor sidebar */
.workarea { flex: 1; display: flex; overflow: hidden; }
.workarea .grid { flex: 1; }

/* Editor sidebar */
.editor {
  width: 340px; flex: 0 0 340px; border-left: 1px solid var(--line);
  background: var(--panel); overflow-y: auto; padding: 12px 14px;
}
.ed-head { display: flex; align-items: center; gap: 8px; }
.ed-title { font-weight: 600; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ed-sub { color: var(--muted); font-size: 12px; margin: 2px 0 10px; }
.ed-empty { color: var(--muted); font-size: 13px; padding: 16px 0; }
.ed-lbl { display: block; font-size: 11px; color: var(--muted); margin: 8px 0 3px; }
.ed-wave { position: relative; background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px; min-height: 50px; }
.ed-wave-ref { min-height: 36px; max-height: 50px; overflow: hidden; }
.ed-window {
  position: absolute; top: 0; bottom: 0; left: 0; width: 100%;
  background: rgba(67,99,216,0.18); border-left: 2px solid var(--accent);
  border-right: 2px solid var(--accent); pointer-events: none;
}
.ed-wave-msg {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  text-align: center; padding: 0 10px; color: var(--muted); font-size: 12px; pointer-events: none;
}

/* Take history list inside the editor */
.ed-takes { display: flex; flex-direction: column; gap: 3px; max-height: 132px; overflow-y: auto; }
.ed-take {
  display: flex; align-items: center; gap: 7px; padding: 3px 5px; border-radius: 5px;
  border: 1px solid transparent; cursor: pointer;
}
.ed-take:hover { background: var(--panel-2); }
.ed-take.editing { background: rgba(67,99,216,0.14); border-color: var(--accent); }
.ed-take.multi-selected {
  background: rgba(243,156,18,0.18);
  border-color: #f39c12;
  box-shadow: inset 0 0 0 1px #f39c12;
}
.ed-take.multi-selected.editing {
  /* If a row is both being-edited and in the multi-select set, the orange
     selection takes visual priority since deletion is the active intent. */
  background: rgba(243,156,18,0.22);
}
.ed-take-lbl { flex: 1; font-size: 12px; font-variant-numeric: tabular-nums; user-select: none; }
.ed-take-active { color: #d9b310; }
.ed-take-bulk {
  display: flex; gap: 8px; align-items: center;
  padding: 6px 8px; margin-bottom: 4px;
  background: rgba(243,156,18,0.10); border: 1px solid rgba(243,156,18,0.4);
  border-radius: 6px; font-size: 12px;
}
.ed-take-bulk .ghost.danger { color: #f39c12; }
.ed-take-bulk .ghost.danger:hover { background: rgba(243,156,18,0.18); color: #ff6b6b; }
.cell-btn.del { opacity: 0.35; font-size: 11px; }
.cell-btn.del:hover { opacity: 1; color: #ff6b6b; }
.ed-controls { margin-top: 10px; }
.ed-row { margin: 8px 0; }
.ed-row label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 3px; }
.ed-row input[type="range"] { width: 100%; }
.ed-row select { width: 100%; background: var(--panel-2); border: 1px solid var(--line); color: var(--text); border-radius: 6px; padding: 6px; }
.ed-val { color: var(--text); font-variant-numeric: tabular-nums; }
.ed-check { display: flex; align-items: center; gap: 7px; font-size: 13px; margin: 10px 0; }
/* Inline "link to speed" checkbox in the pitch row */
.ed-row label .ed-val { float: right; }
.ed-pitch-lock { float: right; display: inline-flex; align-items: center; gap: 4px; margin-left: 10px; font-size: 11px; color: var(--muted); cursor: pointer; }
.ed-pitch-lock input { accent-color: var(--accent); cursor: pointer; }
.ed-row input[type="range"]:disabled { opacity: 0.4; cursor: not-allowed; }
.ed-actions { display: flex; gap: 8px; margin-top: 10px; }
.ed-actions button { padding: 7px 10px; font-size: 13px; }
.ed-status { margin-top: 8px; font-size: 12px; color: var(--muted); min-height: 16px; }

/* History popup */
.history-pop {
  position: fixed; z-index: 50; background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 8px; padding: 8px; width: 230px; box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}
.history-pop .hp-title { font-size: 11px; color: var(--muted); margin-bottom: 6px; }
.hp-row { display: flex; align-items: center; gap: 6px; padding: 3px 4px; border-radius: 4px; }
.hp-row.active { background: rgba(217,179,16,0.12); }
.hp-row .hp-lbl { flex: 1; font-size: 12px; }

/* Modal */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,0.55); display: grid; place-items: center; z-index: 100; }
.modal-card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; width: 580px; max-height: 80vh; display: flex; flex-direction: column; padding: 18px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; }
.modal-head h2 { font-size: 16px; margin: 0; }
.modal-new { display: flex; gap: 8px; margin: 8px 0; }
.modal-new:first-of-type { margin-top: 14px; }
.modal-new input { flex: 1; background: var(--panel-2); border: 1px solid var(--line); color: var(--text); border-radius: 6px; padding: 8px; }
.groups-list { overflow-y: auto; display: flex; flex-direction: column; gap: 16px; margin-top: 8px; }
.cat-block { display: flex; flex-direction: column; gap: 6px; }
.cat-head { display: flex; align-items: center; gap: 8px; padding: 0 2px 4px 2px; border-bottom: 1px solid var(--line); }
.cat-title { flex: 1; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text); }
.cat-empty { padding: 8px 12px; font-style: italic; }
.group-row { display: flex; align-items: center; gap: 8px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 10px; }
.group-main { flex: 1; min-width: 0; }
.group-name { font-weight: 600; }
.group-meta { font-size: 12px; color: var(--muted); margin-top: 3px; }
.group-move { background: var(--panel); border: 1px solid var(--line); color: var(--text); border-radius: 6px; padding: 5px 8px; font-size: 12px; max-width: 140px; }
.group-assign { background: var(--panel); border: 1px solid var(--line); color: var(--text); border-radius: 6px; padding: 5px 8px; font-size: 12px; max-width: 130px; }
.group-assign:disabled { opacity: 0.7; cursor: default; }
/* Export modal */
.export-card { width: 720px; max-width: 92vw; }
.export-body { overflow-y: auto; max-height: 60vh; }
.export-summary { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin: 16px 0; }
.export-stat { background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: 12px; text-align: center; }
.export-stat-n { font-size: 22px; font-weight: 700; color: var(--text); font-variant-numeric: tabular-nums; }
.export-stat div:last-child { font-size: 11px; color: var(--muted); margin-top: 2px; }
.export-stat.ok { border-color: #2ecc71; }
.export-stat.ok .export-stat-n { color: #2ecc71; }
.export-stat.warn { border-color: #f39c12; }
.export-stat.warn .export-stat-n { color: #f39c12; }
.export-stat-row { display: flex; gap: 16px; align-items: center; font-size: 12px; margin: 8px 0 16px 0; flex-wrap: wrap; }
.export-h3 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); margin: 16px 0 8px 0; font-weight: 600; }
.export-groups { display: flex; flex-direction: column; gap: 6px; }
.export-group { background: var(--panel-2); border: 1px solid var(--line); border-left-width: 3px; border-radius: 6px; padding: 8px 12px; }
.export-group.ok { border-left-color: #2ecc71; }
.export-group.warn { border-left-color: #f39c12; }
.export-group-name { font-weight: 600; font-size: 13px; }
.export-group-meta { font-size: 11px; color: var(--muted); margin-top: 2px; }
.export-actions { display: flex; gap: 12px; align-items: center; margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--line); }
.badge { font-size: 10px; border: 1px solid var(--line); border-radius: 6px; padding: 1px 6px; color: var(--muted); margin-left: 6px; }
.badge.ok { color: #2ecc71; border-color: #2ecc71; }
.muted { color: var(--muted); font-size: 13px; }
.group-row .swatch { width: 12px; height: 12px; border-radius: 50%; flex: 0 0 auto; }

/* Reference play button on event rows */
.cell-name .cell-btn.play.ref { font-size: 11px; padding: 0 4px; margin-right: 4px; opacity: 0.75; flex: 0 0 auto; }
.cell-name .cell-btn.play.ref:hover { opacity: 1; background: var(--panel-2); }
.cell-name .cell-btn.play.ref.playing { opacity: 1; color: var(--accent, #e06c75); }

/* Any play button currently playing audio shows ■ in a stop-orange tint and
   a subtle highlight to make "click to stop" obvious. Applies to submission
   cells, the history popup, and the reference button (above) alike. */
.cell-btn.play.playing { color: #f39c12; background: var(--panel-2); }
.cell-btn.play.playing:hover { color: #ff6b6b; }

/* Topbar sort select */
.topbar-sort {
  background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
  border-radius: 6px; padding: 7px 8px; font-size: 13px; cursor: pointer;
}
#profile-btn { padding: 6px 10px; }
#profile-btn .whoami { color: var(--text); }

/* User / profile forms */
.user-form { display: flex; flex-direction: column; gap: 10px; margin: 14px 0; }
.uf-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 10px; }
.uf-grid label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.uf-grid input {
  background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
  border-radius: 6px; padding: 7px 8px; font-size: 14px;
}
.uf-grid input[type="color"] { padding: 2px; height: 34px; cursor: pointer; }
.uf-actions { display: flex; align-items: center; gap: 12px; }
.ed-status.error { color: #ff6b6b; }

/* ── Hierarchical grid rows ───────────────────────────────────────────────── */

/* Event header row */
.event-header { cursor: pointer; user-select: none; }
/* The count badge sits inside the .cell-user flex column (which already
   center-aligns its child), so we don't need to redefine layout here.
   Just leave the cell transparent so the right-border still spans the
   full 40px row height and the column dividers stay continuous through
   collapsed event headers. */
.event-header-cell { background: transparent; }
.event-header-count {
  font-size: 11px; font-weight: 600;
  color: var(--muted); font-variant-numeric: tabular-nums;
  line-height: 1.4;
  letter-spacing: 0.02em;
}
/* No box / border / fill — just the number, so it reads as "info" rather
   than a separate UI element pinned to a different background colour. */
.event-header.expanded .event-header-count { opacity: 0.5; }
.event-header:hover .cell-name { background: var(--panel-2); }
.event-header .cell-name { font-weight: 600; }

.expand-arrow {
  font-size: 10px; width: 16px; text-align: center; flex: 0 0 16px;
  color: var(--muted); margin-right: 4px;
}

/* Group sub-header row */
.group-sub-header { height: 28px; }
.group-sub-header .cell-name { height: 28px; }
.group-name-cell { font-size: 12px; color: var(--muted); font-weight: 600; }
.group-indent { width: 20px; flex: 0 0 20px; }
.group-label { text-transform: uppercase; letter-spacing: 0.5px; font-size: 11px; }
.group-header-cell { background: transparent; }

/* Variant row */
.variant-row .cell-name { font-weight: normal; }
.variant-indent { width: 20px; flex: 0 0 20px; }
.variant-indent-grouped { width: 32px; flex: 0 0 32px; }
.variant-name-cell { font-size: 13px; }

/* Dot menu button */
.cell-btn.dot-menu {
  opacity: 0; font-size: 14px; padding: 0 4px; margin-left: auto;
  flex: 0 0 auto; transition: opacity 0.1s;
}
.variant-row:hover .cell-btn.dot-menu { opacity: 0.5; }
.cell-btn.dot-menu:hover { opacity: 1 !important; background: var(--panel-2); }

/* Dot menu popup */
.dot-menu-pop .hp-row:hover { background: var(--panel); cursor: pointer; }

/* Load more sentinel */
.load-more { justify-content: center; border-bottom: none; }

/* Group filter checkbox dropdown */
.group-filter-wrap { position: relative; }
.group-filter-btn { font-size: 13px; min-width: 90px; text-align: left; }
.group-filter-btn.active { border-color: var(--accent); color: var(--accent); }
.group-filter-drop {
  position: absolute; top: 100%; left: 0; z-index: 60;
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 8px; padding: 4px 0; margin-top: 4px;
  min-width: 240px; max-height: 70vh; overflow-y: auto;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}
.gf-cat { border-bottom: 1px solid var(--line); }
.gf-cat:last-child { border-bottom: 0; }
.gf-cat-head {
  display: flex; align-items: center; gap: 6px;
  padding: 7px 10px; font-size: 11px; font-weight: 600;
  color: var(--text); cursor: pointer; user-select: none;
  text-transform: uppercase; letter-spacing: 0.05em;
}
/* Subtle hover/expanded highlight — just a hairline border on the bottom so
   the section reads as "active" without painting a contrasting block over
   the dropdown background. */
.gf-cat-head:hover { background: rgba(255,255,255,0.04); }
.gf-cat-head.expanded { background: rgba(255,255,255,0.03); }
.gf-cat-caret { width: 10px; color: var(--muted); font-size: 10px; }
.gf-cat-label { flex: 1; }
/* Count badge — plain number, no pill background. Reads as info rather
   than a separate UI chip pasted on top. */
.gf-cat-count {
  font-size: 11px; font-weight: 500; color: var(--muted);
  font-variant-numeric: tabular-nums;
  text-transform: none; letter-spacing: 0;
}
.gf-cat-count.active { color: var(--accent); font-weight: 700; }
.gf-cat-body { padding: 2px 0 4px 0; }
.gf-item {
  display: flex; align-items: center; gap: 8px;
  padding: 5px 12px; font-size: 13px; cursor: pointer; user-select: none;
}
.gf-cat-body .gf-item { padding-left: 28px; }
.gf-item:hover { background: var(--panel); }
.gf-item input { accent-color: var(--accent); cursor: pointer; }
.gf-clear {
  display: block; width: 100%; text-align: center; padding: 6px 0;
  font-size: 12px; color: var(--muted); border: 0; background: transparent;
  cursor: pointer; border-top: 1px solid var(--line); margin-top: 4px;
}
.gf-clear:hover { color: var(--text); }
