/*
 * DJ-Digger Viewer — Minimal Flat High-Contrast Design
 *
 * Layout:
 *   Desktop (>=1180px): single row of [controls-left | player | stats] above a
 *     4-column data grid. Components naturally pull closer as the window narrows.
 *   Mobile  (<1180px) : data grid, filters and stats are hidden. Only the
 *     VU meters, the now-playing player and the two transport buttons remain.
 */

/* ============================================================================
   1. Tokens
   ========================================================================= */
:root {
  --bg: #ffffff;
  --bg-alt: #f5f5f5;
  --bg-hover: #e8e8e8;
  --accent: var(--accent-color);
  --accent-hover: #e8e8e8;
  --text: #000000;
  --text-dim: #666666;
  --border: #000000;
  --highlight: var(--accent-color);

  --shadow:      4px 4px 8px 0 rgba(0, 0, 0, 0.15);
  --shadow-sm:   2px 2px 4px 0 rgba(0, 0, 0, 0.15);
  --shadow-text: 4px 4px 8px      rgba(0, 0, 0, 0.15);

  --ec-controls-h:   99px;
  --ec-player-w:     300px;
  --ec-player-text:  250px;
  --ec-btn-size:     32px;
  --ec-row-h:        60px;
  --ec-thumb:        44px;
}

/* ============================================================================
   2. Page chrome (full-bleed viewer inside the chantier layout)
   ========================================================================= */
body:has(.ec-viewer) {
  height: 100vh;
  overflow: hidden;
}

body:has(.ec-viewer) metadata {
  height: 100vh;
  overflow-y: auto;
}

body:has(.ec-viewer) data {
  padding: 0;
  max-width: none;
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.ec-viewer {
  flex: 1;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  background: var(--bg);
  font-family: var(--font-family-ui);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ============================================================================
   3. Controls bar — three flex children pull together as width shrinks
   ========================================================================= */
/* Height is locked with both `height` and `min-height` so the row never
   shrinks below the design value, no matter what `min-height: auto` does
   to the inner flex/grid content. */
.ec-controls {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--ec-controls-h);
  min-height: var(--ec-controls-h);
  padding: 14px 16px;
  box-sizing: border-box;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

/* Two-row, four-column micro-grid:
   col1 = filter mode (rows 1–2), col2 = filter inputs (one per row),
   col3 = VU meters (rows 1–2), col4 = transport buttons (one per row) */
.ec-controls-left {
  flex: 0 1 auto;
  min-width: 0;
  display: grid;
  grid-template-columns: auto auto auto auto;
  grid-template-rows: 1fr 1fr;
  grid-auto-flow: column;
  gap: 6px 12px;
  align-items: center;
}

.ec-controls-left .ec-filter-mode             { grid-column: 1; grid-row: 1 / 3; }
.ec-controls-left .ec-filters-wrapper          { display: contents; }
.ec-controls-left .ec-filter-container:nth-child(1) { grid-column: 2; grid-row: 1; }
.ec-controls-left .ec-filter-container:nth-child(2) { grid-column: 2; grid-row: 2; }
.ec-controls-left .ec-vu-meters                { grid-column: 3; grid-row: 1 / 3; }
.ec-controls-left .ec-vu-controls              { display: contents; }
.ec-controls-left .ec-vu-controls .ec-player-btn:nth-child(1) { grid-column: 4; grid-row: 1; }
.ec-controls-left .ec-vu-controls .ec-player-btn:nth-child(2) { grid-column: 4; grid-row: 2; }

/* ============================================================================
   4. Filter mode (radios) and filter inputs
   ========================================================================= */
.ec-filter-mode {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 6px 12px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.ec-radio-label {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 8px;
  cursor: pointer;
  user-select: none;
  font-family: var(--font-family-ui);
  font-size: 11px;
  font-weight: 500;
  color: var(--text);
}

.ec-radio-label input[type="radio"] {
  width: 16px;
  height: 16px;
  margin: 0;
  appearance: none;
  -webkit-appearance: none;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 0;
  cursor: pointer;
  transition: all 0.15s ease;
}

.ec-radio-label input[type="radio"]:checked {
  background: var(--text);
}

.ec-radio-label span {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.3px;
  text-transform: uppercase;
}

#filter-playlists,
#filter-tracks {
  width: 100%;
  padding: 6px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  font-family: var(--font-family-ui);
  font-size: 13px;
  color: var(--text);
}

#filter-playlists::placeholder,
#filter-tracks::placeholder {
  color: var(--text-dim);
  font-size: 12px;
}

#filter-playlists:focus,
#filter-tracks:focus {
  outline: none;
}

/* ============================================================================
   5. VU meters and their stacked transport buttons
   ========================================================================= */
.ec-vu-meters {
  flex-shrink: 0;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 32px;
  padding: 10px 6px;
  background: var(--bg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.ec-vu-controls {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.ec-vu-meter {
  position: relative;
  width: 5px;
  height: 40px;
  margin-top: 3px;
  background: var(--bg-alt);
  border: 1px solid var(--border);
  overflow: hidden;
}

.ec-vu-meter-bar {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 0%;
  background: linear-gradient(to top,
    #00ff00 0%,
    #33ff33 10%,
    #88ff00 30%,
    #ddff00 50%,
    #ffcc00 65%,
    #ff8800 80%,
    #ff3300 90%,
    #ff0000 100%);
  transition: none;
  will-change: height;
  transform: translateZ(0);
}

/* ============================================================================
   6. Player (now-playing strip)
   ========================================================================= */
.ec-player {
  flex: 0 0 var(--ec-player-w);
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  height: 68px;
  padding: 10px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.ec-player-artwork {
  position: relative;
  flex-shrink: 0;
  width: 48px;
  min-width: 48px;
  height: 48px;
  background: var(--bg);
  background-size: cover;
  background-position: center;
  border: 1px solid var(--border);
  cursor: pointer;
  transition: transform 0.1s ease;
}

.ec-player-artwork::before {
  content: '♪';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  color: var(--text-dim);
  font-size: 24px;
}

.ec-player-artwork.has-artwork::before {
  display: none;
}

.ec-player-track-info {
  position: relative;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  width: var(--ec-player-text);
  overflow: hidden;
}

.ec-live-badge {
  width: fit-content;
  margin-bottom: 3px;
  padding: 2px 6px;
  background: #ff0000;
  border: 1px solid var(--border);
  font-family: var(--font-family-ui);
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  color: #ffffff;
}

.ec-player-title,
.ec-player-artist {
  position: relative;
  font-family: var(--font-family-ui);
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
}

.ec-player-title  { font-size: 11px; font-weight: 500; color: var(--text); }
.ec-player-artist { font-size:  9px; color: var(--text-dim); }

.ec-player-title:hover,
.ec-player-artist:hover {
  overflow: visible;
}

.ec-player-title  > span,
.ec-player-artist > span {
  display: inline-block;
  padding-right: 40px;
}

/* iPod-style marquee — only when JS adds the `scrolling` class */
@keyframes scroll-text {
  0%,  15% { transform: translateX(0); }
  85%, 100% { transform: translateX(calc(-100% + var(--ec-player-text))); }
}

.ec-player-title.scrolling  > span,
.ec-player-artist.scrolling > span {
  animation: scroll-text 12s ease-in-out infinite;
  animation-delay: 1s;
}

/* ============================================================================
   7. Circular buttons (player transport, go-to-track, A–Z letter filter)
   ========================================================================= */
.ec-player-btn,
.ec-player-goto-btn {
  position: relative;
  width: var(--ec-btn-size);
  height: var(--ec-btn-size);
  padding: 0;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 50%;
  box-shadow: var(--shadow);
  font-size: 11px;
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.08s ease;
}

.ec-player-btn i,
.ec-player-goto-btn i { pointer-events: none; }

.ec-player-btn:hover,
.ec-player-goto-btn:hover { background: var(--bg-hover); }

.ec-player-btn:active,
.ec-player-goto-btn:active {
  background: var(--bg-alt);
  box-shadow: var(--shadow-sm);
  transform: scale(0.92);
}

.ec-player-btn.muted { background: var(--accent); }

.ec-player-btn.loading {
  background: var(--bg);
  cursor: wait;
}

/* Subtle "boop" pulse hooks used by the muted state — kept invisible until
   JS animates them. */
.ec-player-btn.muted::before,
.ec-player-btn.muted::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 100%;
  height: 100%;
  border: 1px solid var(--accent);
  border-radius: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
  opacity: 0;
}

.ec-player-goto-btn:disabled {
  color: var(--text-dim);
  opacity: 0.4;
  cursor: not-allowed;
}

.ec-player-goto-btn:disabled:hover { background: var(--bg); }

/* Compact play button used inside the metadata column */
.ec-metadata-title-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.ec-metadata-play-btn {
  flex-shrink: 0;
  width: 24px;
  min-width: 24px;
  height: 24px;
  padding: 0;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 50%;
  font-size: 9px;
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.12s ease;
}

.ec-metadata-play-btn i {
  pointer-events: none;
  margin-left: 1px;
}

.ec-metadata-play-btn:hover  { background: var(--bg-hover); }
.ec-metadata-play-btn:active { background: var(--bg-alt); }

/* A / B / C / D letter buttons */
.ec-letter-buttons {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 6px;
}

.ec-letter-btn {
  width: var(--ec-btn-size);
  height: var(--ec-btn-size);
  padding: 0;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 50%;
  font-family: var(--font-family-ui);
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.1s ease;
}

.ec-letter-btn:hover  { background: var(--bg-hover); }
.ec-letter-btn:active { background: var(--bg-alt); }
.ec-letter-btn.active {
  background: var(--accent);
  color: var(--bg);
}

/* ============================================================================
   8. Stats display
   ========================================================================= */
.ec-stats {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  font-size: 11px;
  letter-spacing: 0.3px;
  text-align: right;
  color: var(--text-dim);
  white-space: nowrap;
}

#stats-display {
  font-weight: 500;
  color: var(--text-dim);
}

/* ============================================================================
   9. Data grid (4 columns)
   ========================================================================= */
.ec-columns {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  overflow: hidden;
}

.ec-column {
  display: flex;
  flex-direction: column;
  background: var(--bg);
  border-right: 1px solid var(--border);
  overflow: hidden;
}

.ec-column:last-child { border-right: none; }

.ec-column-header { display: none; }

.ec-column-content {
  flex: 1;
  position: relative;
  overflow-y: auto;
  overflow-x: hidden;
}

.ec-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

.ec-table tbody { display: block; width: 100%; }

.ec-table tr {
  display: table;
  width: 100%;
  table-layout: fixed;
}

/* ============================================================================
   10. Playlist + track rows (identical chrome, shared selectors)
   ========================================================================= */
.ec-playlist-row,
.ec-track-row {
  height: var(--ec-row-h);
  background: transparent;
  border-left: 3px solid transparent;
  cursor: pointer;
  transition: background-color 0.05s ease;
}

.ec-playlist-row.selected,
.ec-track-row.selected   { background: var(--bg-hover); }

.ec-playlist-row:hover,
.ec-track-row:hover      { background: var(--accent); }

.ec-playlist-row:focus,
.ec-track-row:focus {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

/* Force text back to default colour on hover/selected (accent backgrounds) */
.ec-playlist-row.selected .ec-playlist-name,
.ec-playlist-row.selected .ec-playlist-meta,
.ec-playlist-row:hover    .ec-playlist-name,
.ec-playlist-row:hover    .ec-playlist-meta,
.ec-track-row.selected    .ec-track-title,
.ec-track-row.selected    .ec-track-artist,
.ec-track-row.selected    .ec-track-num-cell,
.ec-track-row.selected    .ec-track-duration-cell,
.ec-track-row:hover       .ec-track-title,
.ec-track-row:hover       .ec-track-artist,
.ec-track-row:hover       .ec-track-num-cell,
.ec-track-row:hover       .ec-track-duration-cell {
  color: var(--text);
}

/* Cells — playlist column */
.ec-thumb-cell {
  width: 60px;
  padding: 8px 0 8px 9px;
  vertical-align: middle;
}

.ec-info-cell {
  padding: 8px 12px;
  vertical-align: middle;
  overflow: hidden;
}

/* Cells — track column */
.ec-track-num-cell {
  width: 40px;
  padding: 8px 0;
  font-family: var(--font-family-ui);
  font-size: 11px;
  text-align: center;
  vertical-align: middle;
  color: var(--text-dim);
}

.ec-track-thumb-cell {
  width: 52px;
  padding: 8px 0;
  vertical-align: middle;
}

.ec-track-info-cell {
  padding: 8px;
  vertical-align: middle;
  overflow: hidden;
}

.ec-track-duration-cell {
  width: 60px;
  padding: 8px;
  font-family: var(--font-family-ui);
  font-size: 11px;
  text-align: right;
  vertical-align: middle;
  white-space: nowrap;
  color: var(--text-dim);
}

/* Thumbnails — shared dimensions */
.ec-playlist-thumb,
.ec-track-thumb {
  display: block;
  width: var(--ec-thumb);
  height: var(--ec-thumb);
  object-fit: cover;
  border: 1px solid var(--border);
}

.ec-no-artwork {
  background: var(--bg-alt);
  border: 1px solid var(--border);
}

/* Text content — primary + secondary line */
.ec-playlist-name,
.ec-track-title {
  margin-bottom: 3px;
  font-family: var(--font-family-ui);
  font-size: 13px;
  font-weight: 400;
  line-height: 1.4;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ec-playlist-meta,
.ec-track-artist {
  font-family: var(--font-family-ui);
  font-size: 11px;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ec-playlist-row::selection,
.ec-track-row::selection,
.ec-playlist-name::selection,
.ec-track-title::selection {
  background: var(--highlight);
  color: var(--text);
}

.ec-empty-state {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-family-ui);
  font-size: 12px;
  color: var(--text);
}

/* ============================================================================
   11. Metadata column content
   ========================================================================= */
.ec-metadata-content {
  padding: 12px;
  color: var(--text);
}

.ec-metadata-artwork {
  width: 100%;
  aspect-ratio: 1;
  margin-bottom: 10px;
  object-fit: cover;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform 0.1s ease;
}

.ec-metadata-artwork.no-artwork {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-alt);
  font-size: 48px;
  color: var(--text-dim);
  cursor: default;
}

.ec-metadata-artwork.no-artwork:hover { transform: none; }

.ec-metadata-section {
  margin-bottom: 8px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.ec-metadata-section:last-child { border-bottom: none; }

.ec-metadata-label {
  margin-bottom: 4px;
  font-family: var(--font-family-ui);
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  color: var(--text-dim);
}

.ec-metadata-value {
  font-family: var(--font-family-ui);
  font-size: 11px;
  line-height: 1.4;
  color: var(--text);
  word-wrap: break-word;
}

.ec-metadata-value.large {
  font-size: 13px;
  font-weight: 500;
  line-height: 1.3;
}

.ec-metadata-badges {
  display: flex;
  gap: 6px;
  margin-top: 6px;
}

.ec-badge {
  display: inline-block;
  padding: 2px 6px;
  border: 1px solid var(--border);
  font-family: var(--font-family-ui);
  font-size: 8px;
  font-weight: 500;
  letter-spacing: 0.4px;
  text-transform: uppercase;
}

.ec-badge.explicit,
.ec-badge.lyrics {
  background: var(--text);
  color: var(--bg);
}

.ec-metadata-link {
  display: inline-block;
  margin-top: 8px;
  padding: 5px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  font-family: var(--font-family-ui);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.3px;
  text-decoration: none;
  color: var(--bg);
}

.ec-metadata-link:hover { background: var(--accent); }

/* ============================================================================
   12. Artwork lightbox
   ========================================================================= */
.artwork-lightbox {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 10000;
  align-items: center;
  justify-content: center;
}

.artwork-lightbox.active { display: flex; }

.artwork-lightbox-overlay {
  position: absolute;
  inset: 0;
  background: var(--bg);
  opacity: 0.95;
  cursor: pointer;
}

.artwork-lightbox-img {
  position: relative;
  max-width: 98vw;
  max-height: 98vh;
  object-fit: contain;
  border: 1px solid var(--border);
  cursor: pointer;
  animation: artwork-zoom-in 0.3s ease-out;
}

@keyframes artwork-zoom-in {
  from { opacity: 0; transform: scale(0.8); }
  to   { opacity: 1; transform: scale(1);   }
}

/* ============================================================================
   13. Scrollbars (column content)
   ========================================================================= */
.ec-column-content::-webkit-scrollbar {
  width: 12px;
  background: var(--bg);
}

.ec-column-content::-webkit-scrollbar-track {
  background: var(--bg);
  border-left: 1px solid var(--border);
}

.ec-column-content::-webkit-scrollbar-thumb {
  min-height: 40px;
  background: var(--text);
  border: 1px solid var(--border);
}

.ec-column-content::-webkit-scrollbar-thumb:hover  { background: var(--text-dim); }
.ec-column-content::-webkit-scrollbar-thumb:active { background: var(--accent); }

/* ============================================================================
   14. Loading spinner
   ========================================================================= */
@keyframes spin {
  to { transform: rotate(360deg); }
}

.ec-loading {
  animation: spin 1s linear infinite;
  color: var(--vsc-blue);
}

.ec-player-spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid var(--text-dim);
  border-top-color: var(--text);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

/* ============================================================================
   15. Mobile (<1180px) — only VU meters, player, transport buttons subsist
   The data grid, filters and stats are removed; metadata stacks above the
   controls bar in the surrounding chantier layout.
   ========================================================================= */
@media (max-width: 1179px) {
  body:has(.ec-viewer) {
    display: block;
    height: auto;
    min-height: 100vh;
    overflow-x: hidden;
    overflow-y: auto;
  }

  body:has(.ec-viewer) metadata {
    height: auto;
    max-height: none;
    border-right: none;
    border-bottom: 1px solid var(--border-color);
    overflow-y: visible;
  }

  body:has(.ec-viewer) data {
    flex: none;
    display: flex;
    flex-direction: column;
    height: auto;
    min-height: 0;
    overflow: visible;
  }

  .ec-viewer {
    flex: 1 1 auto;
    height: auto;
    min-height: 50vh;
  }

  /* Hide everything that does not belong in the mobile strip */
  .ec-columns,
  .ec-stats,
  #player-goto,
  .ec-controls-left .ec-filter-mode,
  .ec-controls-left .ec-filters-wrapper,
  .ec-controls-left .ec-filter-container {
    display: none !important;
  }

  .ec-controls {
    flex-wrap: nowrap;
    justify-content: center;
    align-items: center;
    gap: 8px;
    padding: 2em 6px 8px;
    border-bottom: none;
    height: auto;
    min-height: var(--ec-controls-h);
  }

  /* Switch the micro-grid to a simple flex row that only carries the VU
     meters and the two transport buttons. */
  .ec-controls-left {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 8px;
  }

  .ec-controls-left .ec-vu-controls {
    display: flex;
  }

  /* Let the player flex to fill remaining space, capped at its design width */
  .ec-player {
    flex: 1 1 auto;
    width: auto;
    max-width: var(--ec-player-w);
    min-width: 0;
    height: auto;
    min-height: 68px;
    padding: 6px 8px;
    gap: 8px;
  }

  .ec-player-track-info {
    flex-shrink: 1;
    width: auto;
    min-width: 0;
    max-width: 100%;
  }

  /* Marquee endpoint follows the new flexible width */
  @keyframes scroll-text {
    0%,  15% { transform: translateX(0); }
    85%, 100% { transform: translateX(calc(-100% + 12rem)); }
  }
}
