:root {
  --bg: #0b0f17;
  --surface: #121826;
  --surface-2: #182133;
  --border: #243047;
  --text: #e6edf7;
  --muted: #8fa1bc;
  --cyan: #38bdf8;
  --emerald: #34d399;
  --amber: #fbbf24;
  --rose: #fb7185;
  --violet: #a78bfa;
  --radius: 12px;
  --header-h: 56px;
}

*, *::before, *::after {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow-x: clip;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
}

.hidden {
  display: none !important;
}

/* Top Header */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  height: calc(var(--header-h) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) 16px 0;
  background: rgba(11, 15, 23, 0.92);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-icon {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: linear-gradient(135deg, #0ea5e9, #6366f1);
  display: grid;
  place-items: center;
  font-size: 18px;
  color: #fff;
  flex-shrink: 0;
}

.brand-text h1 {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.brand-sub {
  display: block;
  font-size: 11px;
  color: var(--muted);
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.btn-icon {
  min-height: 44px;
  padding: 0 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  touch-manipulation: manipulation;
}

.badge {
  background: var(--cyan);
  color: #06131f;
  border-radius: 999px;
  padding: 1px 7px;
  font-size: 12px;
  font-weight: 700;
}

.select-compact, select, input[type="search"] {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 16px;
  min-height: 44px;
  width: 100%;
  outline: none;
}

.select-compact {
  width: auto;
  min-width: 210px;
  font-size: 14px;
  min-height: 38px;
  padding: 6px 10px;
}

select:focus, input[type="search"]:focus {
  border-color: var(--cyan);
}

/* App Shell */
.app-shell {
  display: flex;
  min-height: calc(100dvh - var(--header-h));
  max-width: 1480px;
  margin: 0 auto;
}

/* Sidebar */
.sidebar {
  width: 280px;
  flex-shrink: 0;
  border-right: 1px solid var(--border);
  padding: 16px;
  background: var(--surface);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.sidebar-header h2 {
  margin: 0;
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.btn-close {
  min-width: 44px;
  min-height: 44px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 18px;
  cursor: pointer;
}

.filter-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.filter-group label {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
}

.btn-secondary {
  min-height: 44px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  margin-top: 4px;
}

.btn-secondary:hover {
  background: var(--surface-2);
}

.full-width { width: 100%; }

/* Main Content */
.main-content {
  flex: 1;
  min-width: 0;
  padding: 16px;
  padding-bottom: calc(28px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* KPI Grid */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.kpi-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.kpi-value {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.kpi-sub {
  font-size: 11px;
  color: var(--muted);
}

.accent-cyan { color: var(--cyan); }
.accent-amber { color: var(--amber); }
.accent-emerald { color: var(--emerald); }

/* Inspector Panel */
.inspector-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.inspector-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.now-playing-meta {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  flex: 1;
}

.btn-play-main {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(135deg, #0ea5e9, #38bdf8);
  color: #06131f;
  font-size: 18px;
  font-weight: 900;
  cursor: pointer;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  touch-manipulation: manipulation;
}

.btn-play-main:hover {
  filter: brightness(1.08);
}

.now-playing-titles {
  min-width: 0;
}

.title-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.title-row h2 {
  margin: 0;
  font-size: 17px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.meta-line {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}

.mode-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.segmented {
  display: inline-flex;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 3px;
}

.seg-btn {
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  padding: 7px 12px;
  min-height: 36px;
  border-radius: 7px;
  cursor: pointer;
  touch-manipulation: manipulation;
}

.seg-btn.active {
  background: var(--cyan);
  color: #06131f;
}

.toggle-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 7px 10px;
  min-height: 38px;
  border-radius: 10px;
  cursor: pointer;
  user-select: none;
}

.toggle-chip.small {
  font-size: 12px;
  padding: 4px 8px;
  min-height: 32px;
}

.btn-download {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 13px;
  font-weight: 600;
  color: var(--cyan);
  background: rgba(56, 189, 248, 0.12);
  border: 1px solid rgba(56, 189, 248, 0.4);
  padding: 7px 12px;
  min-height: 38px;
  border-radius: 10px;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
  touch-manipulation: manipulation;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
}

.btn-download:hover {
  background: rgba(56, 189, 248, 0.22);
  border-color: var(--cyan);
}

.btn-download:active {
  transform: translateY(1px);
}

/* Waveform */
.waveform-wrap {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px 8px;
}

#waveformCanvas {
  width: 100%;
  height: 120px;
  display: block;
  cursor: pointer;
}

.waveform-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 6px;
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  flex-wrap: wrap;
}

.wf-legend {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  font-size: 11px;
}

.dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 4px;
}
.dot-peak { background: #38bdf8; }
.dot-rms { background: #0284c7; }
.dot-vocal { background: #a78bfa; }
.dot-clip { background: #fb7185; }

/* Inspector Details Grid */
.inspector-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.diag-card, .eq-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
}

.diag-card h3, .eq-card h3 {
  margin: 0 0 6px;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.diag-note {
  margin: 0 0 10px;
  font-size: 13px;
  line-height: 1.45;
  color: var(--text);
}

.metrics-mini {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.metric-item {
  background: rgba(11, 15, 23, 0.55);
  border: 1px solid rgba(255,255,255,0.05);
  border-radius: 8px;
  padding: 7px 9px;
}

.metric-item span {
  display: block;
  font-size: 11px;
  color: var(--muted);
}

.metric-item strong {
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.clip-ts-wrap {
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

.clip-ts-label {
  display: block;
  font-size: 11px;
  color: var(--rose);
  margin-bottom: 6px;
}

.clip-ts-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.ts-btn {
  background: rgba(251, 113, 133, 0.14);
  color: var(--rose);
  border: 1px solid rgba(251, 113, 133, 0.35);
  border-radius: 6px;
  padding: 3px 8px;
  font-size: 12px;
  cursor: pointer;
}

/* EQ Card */
.eq-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 6px;
}

.eq-header h3 { margin: 0; }

.eq-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.btn-xs {
  min-height: 32px;
  padding: 4px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.btn-accent {
  background: rgba(52, 211, 153, 0.16);
  border-color: rgba(52, 211, 153, 0.45);
  color: var(--emerald);
}

.eq-sliders {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
  margin-top: 8px;
}

.eq-band {
  background: rgba(11, 15, 23, 0.55);
  border-radius: 8px;
  padding: 8px 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.eq-band-val {
  font-size: 11px;
  font-weight: 700;
  color: var(--cyan);
  font-variant-numeric: tabular-nums;
}

.eq-band input[type="range"] {
  width: 100%;
  accent-color: var(--cyan);
  cursor: pointer;
}

.eq-band-freq {
  font-size: 11px;
  color: var(--muted);
}

/* List Header */
.list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  font-size: 13px;
  color: var(--muted);
}

.list-header-left {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.btn-zip-dl {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  min-height: 30px;
  border-radius: 999px;
  border: 1px solid rgba(56, 189, 248, 0.35);
  background: rgba(56, 189, 248, 0.1);
  color: var(--cyan);
  font-size: 12px;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s;
}

.btn-zip-dl:hover {
  background: rgba(56, 189, 248, 0.2);
  border-color: var(--cyan);
}

.quick-pills {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.qpill {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
  cursor: pointer;
}

.qpill.active {
  background: rgba(56, 189, 248, 0.16);
  border-color: var(--cyan);
  color: var(--cyan);
}

/* Track Cards */
.track-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.track-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  display: grid;
  grid-template-columns: 44px minmax(0, 1.6fr) 120px minmax(0, 1.2fr) auto;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.track-card:hover {
  border-color: #3a4f75;
  background: #151d2e;
}

.track-card.active {
  border-color: var(--cyan);
  background: rgba(56, 189, 248, 0.07);
}

.btn-row-play {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
  display: grid;
  place-items: center;
}

.track-card.active .btn-row-play {
  background: var(--cyan);
  color: #06131f;
  border-color: var(--cyan);
}

.tc-main {
  min-width: 0;
}

.tc-title {
  font-weight: 700;
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tc-projects {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tc-spark {
  width: 120px;
  height: 34px;
  display: block;
}

.tc-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.pill {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  border: 1px solid transparent;
  white-space: nowrap;
}

.pill-genre { background: rgba(99, 102, 241, 0.15); color: #a5b4fc; border-color: rgba(99, 102, 241, 0.3); }
.pill-style { background: rgba(56, 189, 248, 0.12); color: #7dd3fc; border-color: rgba(56, 189, 248, 0.25); }
.pill-atmo { background: rgba(167, 139, 250, 0.12); color: #c4b5fd; border-color: rgba(167, 139, 250, 0.25); }
.pill-bpm { background: rgba(255,255,255,0.06); color: var(--text); border-color: var(--border); }
.pill-clean { background: rgba(52, 211, 153, 0.14); color: var(--emerald); border-color: rgba(52, 211, 153, 0.35); }
.pill-warning { background: rgba(251, 191, 36, 0.14); color: var(--amber); border-color: rgba(251, 191, 36, 0.35); }
.pill-clipping { background: rgba(251, 113, 133, 0.16); color: var(--rose); border-color: rgba(251, 113, 133, 0.4); }
.pill-eq { background: rgba(56, 189, 248, 0.16); color: var(--cyan); border-color: rgba(56, 189, 248, 0.4); }
.pill-declip { background: rgba(52, 211, 153, 0.16); color: var(--emerald); border-color: rgba(52, 211, 153, 0.45); }

.declip-box {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.declip-summary {
  font-size: 12px;
  color: var(--emerald);
  font-weight: 600;
}

.declip-btns {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.btn-danger {
  background: rgba(251, 113, 133, 0.18);
  border-color: rgba(251, 113, 133, 0.5);
  color: var(--rose);
}

.replace-confirm {
  background: rgba(11, 15, 23, 0.72);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.replace-confirm-title {
  font-size: 12px;
  color: var(--amber);
  font-weight: 600;
}

.replace-target-list {
  margin: 0;
  padding-left: 16px;
  font-size: 11px;
  color: var(--muted);
  max-height: 120px;
  overflow-y: auto;
  word-break: break-all;
}

.replace-status {
  font-size: 12px;
  color: var(--emerald);
  background: rgba(52, 211, 153, 0.1);
  border: 1px solid rgba(52, 211, 153, 0.3);
  border-radius: 8px;
  padding: 7px 9px;
}

.tc-right {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
}

.tc-meta-right {
  text-align: right;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  font-variant-numeric: tabular-nums;
}

.btn-row-dl {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--muted);
  display: grid;
  place-items: center;
  text-decoration: none;
  flex-shrink: 0;
  touch-manipulation: manipulation;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}

.btn-row-dl:hover {
  color: var(--cyan);
  border-color: var(--cyan);
  background: rgba(56, 189, 248, 0.14);
}

.tc-dur {
  font-size: 14px;
  font-weight: 700;
}

.tc-lufs {
  font-size: 11px;
  color: var(--muted);
}

/* Mobile & Tablet Responsive */
.mobile-only { display: none; }

@media (max-width: 980px) {
  .inspector-grid {
    grid-template-columns: 1fr;
  }
  .track-card {
    grid-template-columns: 44px minmax(0, 1fr) auto;
  }
  .tc-spark {
    display: none;
  }
  .tc-tags {
    grid-column: 1 / -1;
  }
}

@media (max-width: 767px) {
  .mobile-only { display: inline-flex; }
  .desktop-sort { display: none; }
  .brand-sub { display: none; }

  .kpi-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 86vw;
    max-width: 340px;
    z-index: 60;
    overflow-y: auto;
    max-height: 100dvh;
    padding-top: calc(16px + env(safe-area-inset-top));
    padding-bottom: calc(24px + env(safe-area-inset-bottom));
    transform: translateX(-105%);
    transition: transform 0.22s ease;
    border-right: 1px solid var(--border);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .backdrop {
    position: fixed;
    inset: 0;
    z-index: 50;
    background: rgba(0, 0, 0, 0.62);
    backdrop-filter: blur(3px);
  }

  .filter-group.mobile-only {
    display: flex;
  }

  .eq-sliders {
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 4px;
  }
}
