/* spot — dark, dense, practical theme.
   Aesthetic: information-dense, low-chrome, monospace numerals, thin borders.
   Inspired by imgui density + modern terminal dashboards. */

:root {
  --bg: #0d1017;
  --bg-panel: #131722;
  --bg-panel-2: #171c29;
  --bg-hover: #1d2333;
  --bg-active: #232b40;
  --border: #262d3f;
  --border-soft: #1e2434;
  --text: #d7dce6;
  --text-dim: #8b93a7;
  --text-faint: #5c6478;
  --accent: #4f8cff;
  --accent-2: #38d39f;
  --accent-3: #f5a524;
  --accent-4: #e5484d;
  --accent-5: #b16cea;
  --plot-line: #4f8cff;
  --plot-fill: rgba(79, 140, 255, 0.12);
  --grid: #1c2230;
  --mono: "SFMono-Regular", "JetBrains Mono", "Fira Code", Consolas, "Liberation Mono", monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 13px;
  line-height: 1.45;
}

.hidden { display: none !important; }
.mono { font-family: var(--mono); }

/* ============================ UPLOAD SCREEN ============================ */

#upload-screen {
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(1200px 600px at 20% 0%, rgba(79, 140, 255, 0.06), transparent 60%),
    radial-gradient(1000px 500px at 90% 100%, rgba(56, 211, 159, 0.05), transparent 60%),
    var(--bg);
}

.upload-box {
  width: 520px;
  max-width: calc(100vw - 48px);
  text-align: center;
}

.upload-box h1 {
  font-size: 40px;
  font-weight: 700;
  letter-spacing: -1px;
  margin: 0 0 4px;
  color: var(--text);
}

.upload-sub {
  color: var(--text-dim);
  margin: 0 0 28px;
}

.dropzone {
  border: 1.5px dashed var(--border);
  border-radius: 10px;
  background: var(--bg-panel);
  padding: 44px 24px;
  transition: border-color 0.15s, background 0.15s;
  cursor: pointer;
}

.dropzone.dragover {
  border-color: var(--accent);
  background: var(--bg-active);
}

.dz-inner { display: flex; flex-direction: column; align-items: center; gap: 10px; }

.dz-title { font-size: 15px; font-weight: 600; }
.dz-sub { color: var(--text-faint); font-size: 12px; }

.upload-status {
  margin-top: 8px;
  min-height: 8px;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-dim);
}
.upload-status.err { color: var(--accent-4); }
.upload-status.ok { color: var(--accent-2); }

.upload-example {
  margin-top: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
}
.upload-example-sep {
  color: var(--text-faint);
  font-size: 12px;
}

.upload-hint {
  margin-top: 22px;
  color: var(--text-faint);
  font-size: 11.5px;
}

.howto {
  margin-top: 28px;
  text-align: left;
  background: var(--bg-panel);
  border: 1px solid var(--border-soft);
  border-radius: 10px;
  padding: 16px 18px;
}
.howto h2 {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-dim);
  margin: 0 0 10px;
}
.howto ol {
  margin: 0;
  padding-left: 20px;
  display: flex;
  flex-direction: column;
  gap: 7px;
}
.howto li {
  font-size: 12.5px;
  color: var(--text-dim);
  line-height: 1.5;
}
.howto li b { color: var(--text); font-weight: 600; }
.howto a { color: var(--accent); text-decoration: none; }
.howto a:hover { text-decoration: underline; }
.howto-note {
  margin: 12px 0 0;
  font-size: 11.5px;
  color: var(--text-faint);
  line-height: 1.5;
}

/* ============================ BUTTONS ============================ */

.btn {
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  background: var(--bg-panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 7px 16px;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
}
.btn:hover { background: var(--bg-hover); border-color: var(--text-faint); }
.btn:active { background: var(--bg-active); }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.btn-primary:hover { background: #629aff; border-color: #629aff; }

.btn-small {
  font-size: 11.5px;
  font-weight: 500;
  padding: 4px 10px;
}

/* ============================ APP SHELL ============================ */

.app {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

.sidebar {
  width: 188px;
  flex: 0 0 188px;
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}

.brand {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.5px;
  padding: 16px 18px 12px;
  border-bottom: 1px solid var(--border-soft);
  cursor: pointer;
  user-select: none;
  transition: color 0.1s;
}
.brand:hover { color: var(--accent); }

.nav {
  flex: 1;
  padding: 10px 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow-y: auto;
}

.nav-item {
  text-align: left;
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 500;
  color: var(--text-dim);
  background: transparent;
  border: none;
  border-left: 2px solid transparent;
  border-radius: 0 5px 5px 0;
  padding: 7px 12px;
  cursor: pointer;
  transition: background 0.1s, color 0.1s;
}
.nav-item:hover { background: var(--bg-hover); color: var(--text); }
.nav-item.active {
  background: var(--bg-active);
  color: var(--text);
  border-left-color: var(--accent);
  font-weight: 600;
}
.nav-item.disabled {
  color: var(--text-faint);
  cursor: default;
  opacity: 0.55;
}
.nav-item.disabled:hover { background: transparent; color: var(--text-faint); }

.sidebar-foot {
  padding: 12px 14px;
  border-top: 1px solid var(--border-soft);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.topbar {
  min-height: 44px;
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 20px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
}
.topbar-title { font-size: 14px; font-weight: 600; white-space: nowrap; }
.topbar-meta {
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--text-faint);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}
/* Mobile-only "New upload" button (the sidebar one is hidden on mobile). */
.topbar-new-upload { display: none; }
.topbar-tz { display: flex; align-items: center; gap: 6px; }
.topbar-tz label { font-size: 11px; color: var(--text-faint); }
.tz-select {
  background: var(--bg); color: var(--text);
  border: 1px solid var(--border); border-radius: 4px;
  font-family: var(--mono); font-size: 11px; padding: 2px 6px;
  max-width: 180px;
}
.hour12-select { max-width: none; width: auto; }
.tz-label { font-size: 11px; color: var(--accent); }

/* Full-screen plot overlay: covers the whole browser window. */
.plot-overlay {
  position: fixed; inset: 0; z-index: 1000;
  background: var(--bg);
  display: flex; flex-direction: column;
  padding: 16px 20px;
}
.plot-overlay-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 10px;
}
.plot-overlay-title { font-size: 14px; font-weight: 600; }
.plot-overlay-close {
  box-sizing: border-box; height: 26px; min-width: 44px; padding: 0 10px;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--bg-panel); border: 1px solid var(--border); color: var(--text-dim);
  border-radius: 4px; cursor: pointer; font-family: var(--mono); font-size: 12px; line-height: 1;
}
.plot-overlay-close:hover { color: var(--text); border-color: var(--accent); background: var(--bg-hover); }
.plot-overlay-body { flex: 1; display: flex; align-items: stretch; justify-content: center; overflow: hidden; }
.plot-overlay-body > canvas { max-width: 100%; width: 100% !important; height: 100% !important; }
/* Full-screen button on each plot panel. */
/* Plot buttons (↺ X / ↺ Y / ⛶): one shared look, one shared size, laid out
   as a single right-aligned row over the plot's top margin. */
.plot-fs-btn, .zoom-reset-btn {
  box-sizing: border-box;
  height: 26px; min-width: 44px; padding: 0 10px;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--bg-panel); border: 1px solid var(--border); color: var(--text-dim);
  border-radius: 4px; cursor: pointer;
  font-family: var(--mono); font-size: 12px; line-height: 1;
}
.plot-fs-btn:hover, .zoom-reset-btn:hover { color: var(--text); border-color: var(--accent); background: var(--bg-hover); }
.plot-fs-btn {
  position: absolute; top: 8px; right: 8px; z-index: 5;
  opacity: 0; transition: opacity 0.12s;
}
.plot-wrap:hover .plot-fs-btn { opacity: 1; }
.zoom-ctrls {
  position: absolute; top: 8px; right: 58px; z-index: 5; /* 8 + 44 + 6 gap */
  display: flex; gap: 6px;
  opacity: 0; transition: opacity 0.12s;
}
.plot-wrap:hover .zoom-ctrls { opacity: 1; }
/* In the fullscreen overlay head, zoom controls are inline and always visible. */
.plot-overlay-head .zoom-ctrls { position: static; opacity: 1; margin-right: 8px; }

.view {
  flex: 1;
  overflow-y: auto;
  padding: 18px 20px 40px;
}

/* ============================ STAT GRID ============================ */

.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}

.spotify-link {
  display: inline-block;
  background: #1db954;
  color: #fff;
  text-decoration: none;
  font-weight: 600;
  font-size: 13px;
  padding: 8px 16px;
  border-radius: 20px;
  margin-bottom: 16px;
  transition: background 0.15s, transform 0.08s;
}
.spotify-link:hover {
  background: #1ed760;
  transform: translateY(-1px);
}

.stat-card {
  background: var(--bg-panel);
  border: 1px solid var(--border-soft);
  border-radius: 8px;
  padding: 12px 14px;
}
.stat-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-faint);
  margin-bottom: 6px;
}
.stat-value {
  font-family: var(--mono);
  font-size: 22px;
  font-weight: 600;
  color: var(--text);
  line-height: 1.15;
  word-break: break-word;
}
.stat-value-sm { font-size: 15px; line-height: 1.3; }
.stat-sub {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 4px;
  word-break: break-word;
}

/* ============================ PANELS / PLOTS ============================ */

.panel {
  background: var(--bg-panel);
  border: 1px solid var(--border-soft);
  border-radius: 8px;
  margin-bottom: 16px;
  overflow: hidden;
}
.panel-head {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border-soft);
}
.panel-title { font-size: 13px; font-weight: 600; }
.panel-sub { font-size: 11.5px; color: var(--text-faint); }

.plot-wrap {
  position: relative;
  padding: 10px 12px 12px;
}
/* The canvas is sized by JS (setupCanvas) to its real pixel size. Do NOT
   stretch it with width:100% + height:auto — that stretches the bitmap to the
   full width while keeping the attribute height, so the right side of the
   drawing is clipped off-screen and the plot looks empty. */
.plot-wrap canvas {
  display: block;
  /* Let the plot's own touch handlers (pinch-zoom / pan) work instead of the
     browser zooming the whole page. */
  touch-action: none;
}

.tooltip {
  position: absolute;
  pointer-events: none;
  background: var(--bg-active);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 6px 9px;
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--text);
  white-space: nowrap;
  z-index: 10;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.4);
}
/* Per-play tooltip lines (song/album/artist detail plots). */
.tooltip .tip-plays {
  white-space: nowrap; line-height: 1.5;
  max-width: 520px; overflow: hidden; text-overflow: ellipsis;
  margin-top: 4px; padding-top: 4px; border-top: 1px solid var(--border);
}
.tooltip .tip-hint { color: var(--accent); font-style: italic; }

.placeholder {
  padding: 40px 14px;
  color: var(--text-faint);
  font-size: 13px;
}

/* ============================ TYPE MIX ============================ */

.plot-help {
  border-style: dashed;
}
.plot-help .panel-head {
  margin-bottom: 0;
}
.plot-help-body {
  padding: 10px 14px 12px;
  font-size: 12px;
  color: var(--text-dim);
  line-height: 1.6;
}
.plot-help-body b {
  color: var(--text);
  font-weight: 600;
}
.plot-help-mobile { display: none; }
@media (max-width: 760px) {
  .plot-help-desktop { display: none; }
  .plot-help-mobile { display: block; }
}

.type-mix {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 14px;
}
.tm-row {
  display: grid;
  grid-template-columns: 110px 1fr 190px;
  align-items: center;
  gap: 12px;
}
.tm-name { font-size: 12.5px; color: var(--text-dim); }
.tm-bar-track {
  height: 14px;
  background: var(--bg-panel-2);
  border-radius: 3px;
  overflow: hidden;
}
.tm-bar {
  height: 100%;
  border-radius: 3px;
  min-width: 2px;
}
.tm-val {
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--text-dim);
  text-align: right;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ============================ ABOUT ============================ */

.about-body {
  padding: 14px;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-dim);
}
.about-row {
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: 12px;
  padding: 3px 0;
  line-height: 1.5;
}
.about-row .k { color: var(--text-faint); }
.about-row .v { color: var(--text-dim); word-break: break-word; white-space: nowrap; }

/* ============================ SCROLLBARS ============================ */

/* Wide, always-grabbable scrollbars. The thumb has a large minimum size so
   long virtualized lists (33k rows) don't shrink it to a dot. */
* { scrollbar-width: auto; scrollbar-color: var(--text-faint) var(--bg-panel); }
::-webkit-scrollbar { width: 18px; height: 18px; }
::-webkit-scrollbar-track { background: var(--bg-panel); }
::-webkit-scrollbar-thumb {
  background: var(--text-faint);
  border-radius: 9px;
  border: 3px solid var(--bg-panel);
  min-height: 80px;
  min-width: 80px;
}
::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }

/* ============================ FILTER BAR ============================ */

.filter-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  background: var(--bg-panel);
  border: 1px solid var(--border-soft);
  border-radius: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.filter-bar label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-faint);
}
.filter-bar input[type="date"],
.filter-bar input[type="search"],
.filter-bar select {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text);
  background: var(--bg-panel-2);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 5px 8px;
  outline: none;
}
.filter-bar input[type="date"]:focus,
.filter-bar input[type="search"]:focus,
.filter-bar select:focus {
  border-color: var(--accent);
}
.filter-bar input[type="search"] { min-width: 180px; }
.filter-bar .filter-sep {
  width: 1px;
  height: 20px;
  background: var(--border);
}
.filter-bar .filter-count {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-dim);
  margin-left: auto;
}

/* ============================ TOGGLE GROUPS (Phase 3d) ============================ */

.toggle-group {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
}
.toggle-btn {
  font-family: var(--mono);
  font-size: 11.5px;
  font-weight: 500;
  color: var(--text-dim);
  background: var(--bg-panel-2);
  border: none;
  border-right: 1px solid var(--border);
  padding: 5px 12px;
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
}
.toggle-group .toggle-btn:last-child { border-right: none; }
.toggle-btn:hover { background: var(--bg-hover); color: var(--text); }
.toggle-btn.active {
  background: var(--bg-active);
  color: var(--text);
  font-weight: 600;
}
.toggle-btn.disabled {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
}

/* ============================ PLOT PANELS ============================ */

.plot-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
.plot-grid .panel { margin-bottom: 0; }
/* Single-column variant (heatmaps): stack the two plots vertically. */
.plot-grid-1col { grid-template-columns: 1fr; }

.plot-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  padding: 8px 14px;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-dim);
}
.plot-legend .lg-item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.plot-legend .lg-swatch {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  display: inline-block;
}

/* ============================ VIRTUALIZED TABLES (Phase 3c) ============================ */

.vtable {
  position: relative;
  overflow: hidden;
}
.vtable-head,
.vtable-row {
  display: grid;
  align-items: center;
  font-size: 12.5px;
}
.vtable-head {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--bg-panel-2);
  border-bottom: 1px solid var(--border);
  height: 34px;
}
.vtable-head .th {
  padding: 0 10px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-faint);
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.vtable-head .th:hover { color: var(--text); }
.vtable-head .th.sorted { color: var(--accent); }
.vtable-head .th .arrow { font-size: 9px; margin-left: 3px; }
.vtable-head .th.num, .vtable-row .td.num { text-align: right; }

.vtable-body {
  position: relative;
  overflow-y: auto;
  /* Always tall enough to show ~16 rows regardless of window height. A tiny
     clientHeight made the virtualizer render only ~3 rows until a scroll. */
  height: 480px;
  max-height: calc(100vh - 240px);
  min-height: 320px;
}
/* Entity table views (artists/songs/albums) take the entire remainder of the screen. */
#view-artists .vtable-body,
#view-songs .vtable-body,
#view-albums .vtable-body {
  height: calc(100vh - 180px);
  max-height: calc(100vh - 180px);
}
.vtable-spacer { position: relative; width: 100%; }
.vtable-row {
  position: absolute;
  left: 0;
  right: 0;
  height: 30px;
  background: transparent;
  border-bottom: 1px solid var(--border-soft);
  cursor: pointer;
}
.vtable-row:hover { background: var(--bg-hover); }
.vtable-row .td {
  padding: 0 10px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.vtable-row .td.num {
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--text-dim);
}
.vtable-row .td.name { color: var(--text); }
.vtable-row .td.dim { color: var(--text-faint); }
/* Clickable entity names (artist/album links) get a hover color change. */
.clickable { cursor: pointer; }
.clickable:hover { color: var(--accent); }
/* Beat the .vtable-row .td.name / .td.dim color rules. */
.vtable-row .td.clickable:hover { color: var(--accent); text-decoration: underline; }
.vtable-empty {
  padding: 30px 14px;
  color: var(--text-faint);
  font-size: 12.5px;
}

/* ============================ ENTITY DETAIL (Phase 3c) ============================ */

.detail-head {
  display: flex;
  align-items: baseline;
  gap: 14px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.detail-title {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.3px;
  word-break: break-word;
}
.detail-sub {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text-dim);
  word-break: break-word;
}

.detail-sub-entities {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.detail-sub-entities .panel { margin-bottom: 0; }
.detail-sub-entities .vtable-body { max-height: 340px; }

/* ============================ RESPONSIVE ============================ */

@media (max-width: 1100px) {
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 760px) {
  .app { flex-direction: column; }
  .sidebar { width: 100%; flex: 0 0 auto; flex-direction: row; align-items: center; }
  .brand { border-bottom: none; border-right: 1px solid var(--border-soft); padding: 12px 14px; }
  .nav { flex-direction: row; overflow-x: auto; padding: 8px; }
  .nav-item { border-left: none; border-bottom: 2px solid transparent; border-radius: 5px 5px 0 0; white-space: nowrap; }
  .nav-item.active { border-left: none; border-bottom-color: var(--accent); }
  .sidebar-foot { display: none; }
  /* Show the mobile "New upload" button in the topbar (sidebar one is hidden). */
  .topbar-new-upload { display: inline-block; }
  /* Let the topbar wrap to two rows: title+meta on top, tz+button below. */
  .topbar { flex-wrap: wrap; padding: 6px 12px; }
  .topbar-title { flex: 1 1 auto; }
  .topbar-meta { flex: 0 1 auto; }
  .topbar-tz { flex: 1 1 100%; justify-content: flex-end; order: 3; }
  .topbar-new-upload { order: 2; }
  .stat-grid { grid-template-columns: 1fr 1fr; }
  .plot-grid { grid-template-columns: 1fr; }
  /* No hover on touch: keep the plot buttons (↺ X / ↺ Y / ⛶) always visible. */
  .plot-fs-btn, .zoom-ctrls { opacity: 1; }
  /* Narrow screens: let the about label column shrink so the value fits. */
  .about-row { grid-template-columns: 150px 1fr; }
}
