/* ============================================
   cckdl — SINTETIZADOR Design System
   Estética modular synth / audio equipment
   ============================================ */

/* 1. CSS Reset
   ============================================ */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
}

/* 2. Design Tokens
   ============================================ */
:root {
  /* Backgrounds */
  --bg: #0D0D12;
  --surface: #1A1A24;
  --surface-hover: #22222E;

  /* Borders */
  --border: #2A2A3E;
  --border-accent: #F59E0B;

  /* Text */
  --text: #E8E8F0;
  --text-muted: #8888A0;

  /* Accents */
  --accent: #F59E0B;            /* Ámbar — acción primaria, LEDs */
  --accent-dim: rgba(245, 158, 11, 0.15);
  --cyan: #06B6D4;               /* Display digital, información */
  --cyan-dim: rgba(6, 182, 212, 0.15);

  /* Semantic */
  --success: #10B981;            /* Verde esmeralda */
  --error: #EF4444;              /* Rojo */

  /* Geometry */
  --radius: 4px;                 /* Esquinas mínimas, como hardware */
  --radius-btn: 4px;

  /* Typography */
  --font-display: 'DM Mono', monospace;
  --font-body: 'Inter', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
}

/* 3. Typography
   ============================================ */
h1, h2, h3, .title-display {
  font-family: var(--font-display);
  font-weight: 500;
  letter-spacing: -0.02em;
}

h1 { font-size: 1.75rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1rem; }

.body-text  { font-family: var(--font-body); font-weight: 400; font-size: 1rem; }
.text-small { font-family: var(--font-body); font-weight: 400; font-size: 0.875rem; }
.text-data  { font-family: var(--font-mono); font-weight: 400; font-size: 0.8125rem; }
.text-caption { font-family: var(--font-mono); font-weight: 400; font-size: 0.6875rem; }

/* 4. Layout
   ============================================ */
.container {
  width: 100%;
  max-width: 100%;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  min-height: 100vh;
  min-height: 100dvh;
}

@media (min-width: 480px) {
  .container {
    max-width: 480px;
  }
}

@media (min-width: 768px) {
  .container {
    max-width: 720px;
  }
}

@media (min-width: 1024px) {
  .container {
    max-width: 960px;
    padding: 24px 32px;
  }
}

/* Bottom Navigation */
.bottom-nav {
  display: flex;
  position: sticky;
  bottom: 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 0.5rem;
  gap: 0.25rem;
  z-index: 100;
  margin-top: 1.5rem;
}

.nav-tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
  padding: 0.5rem 0.25rem;
  border-radius: var(--radius-btn);
  text-decoration: none;
  color: var(--text-muted);
  font-size: 0.7rem;
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  transition: background 0.15s, color 0.15s;
}

.nav-tab.active {
  color: var(--accent);
  background: var(--accent-dim);
}

.nav-tab:hover {
  color: var(--accent);
}

.nav-icon {
  width: 20px;
  height: 20px;
  display: block;
}

.nav-label {
  font-size: 0.65rem;
}

/* 5. Inputs & Buttons
   ============================================ */
#url-input {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  font-size: 1rem;
  font-family: var(--font-mono);
  color: var(--text);
  outline: none;
  transition: border-color 0.2s;
}

#url-input:focus {
  border-color: var(--border-accent);
}

#url-input::placeholder {
  color: var(--text-muted);
  font-family: var(--font-body);
}

.format-row {
  display: flex;
  gap: 10px;
}

.btn-format {
  flex: 1;
  height: 52px;
  border: 2px solid var(--border);
  border-radius: var(--radius-btn);
  background: var(--surface);
  color: var(--text);
  font-size: 1rem;
  font-family: var(--font-display);
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.btn-format:hover {
  transform: translateY(-1px);
}

.btn-format:active {
  transform: translateY(0);
}

.btn-format.audio {
  border-color: var(--border);
}

.btn-format.audio:hover {
  border-color: var(--accent);
  background: var(--accent-dim);
  color: var(--accent);
}

.btn-format.video {
  border-color: var(--border);
}

.btn-format.video:hover {
  border-color: var(--cyan);
  background: var(--cyan-dim);
  color: var(--cyan);
}

.btn-format svg {
  width: 18px;
  height: 18px;
}

/* 6. Header
   ============================================ */
.app-header {
  text-align: center;
  padding: 16px 0 4px;
}

.app-header h1 {
  font-size: 1.75rem;
  font-weight: 500;
  color: var(--accent);
  letter-spacing: -0.03em;
  margin-bottom: 2px;
}

.app-header .subtitle {
  font-size: 0.8rem;
  font-family: var(--font-mono);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.app-header .stats {
  font-size: 0.75rem;
  font-family: var(--font-mono);
  color: var(--text-muted);
  margin-top: 4px;
}

/* 7. Navigation / Bottom tabs
   (moved to section 4 — Layout) */

/* 8. Table View — New Design (replaces cards)
   ============================================ */
/* Cards view is REMOVED — only table view remains */
}

/* 9. Management Panel
   ============================================ */
.lib-manage-panel {
  margin-top: 0.5rem;
  padding: 0.75rem;
  background: rgba(245, 158, 11, 0.04);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.78rem;
  font-family: var(--font-mono);
}

.lib-manage-row {
  display: flex;
  gap: 0.5rem;
  align-items: baseline;
  margin-bottom: 0.25rem;
  flex-wrap: wrap;
}

.lib-manage-label {
  color: var(--text-muted);
  font-weight: 500;
  min-width: 65px;
  flex-shrink: 0;
}

.lib-manage-value {
  color: var(--text);
  word-break: break-all;
}

.lib-manage-value a {
  color: var(--accent);
  text-decoration: none;
}

.lib-manage-value a:hover {
  text-decoration: underline;
}

.lib-manage-btn {
  padding: 0.4rem 0.75rem;
  border-radius: var(--radius-btn);
  border: none;
  font-size: 0.75rem;
  font-family: var(--font-mono);
  font-weight: 500;
  cursor: pointer;
  transition: opacity 0.15s;
  min-height: 36px;
}

.lib-manage-btn:hover {
  opacity: 0.8;
}

.lib-manage-redl {
  background: var(--accent-dim);
  color: var(--accent);
}

.lib-manage-meta {
  background: rgba(16, 185, 129, 0.15);
  color: var(--success);
}

.lib-manage-del {
  background: rgba(239, 68, 68, 0.15);
  color: var(--error);
}

/* 10. Progress & VU Meter
   ============================================ */
.prog-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 9999;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 8px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.4);
}

/* VU Meter */
.vu-meter {
  width: 100%;
}

.vu-track {
  display: flex;
  gap: 2px;
  height: 32px;
  align-items: flex-end;
}

.vu-segment {
  flex: 1;
  background: var(--border);
  border-radius: 1px;
  min-height: 2px;
  transition: background 0.2s, height 0.3s ease;
  height: 4%;
}

.vu-filled {
  background: var(--accent);
}

.vu-complete .vu-filled {
  background: var(--success);
}

.vu-info {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 4px;
}

.vu-title {
  font-size: 0.7rem;
  font-family: var(--font-mono);
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 70%;
}

.vu-pct {
  font-size: 0.7rem;
  font-family: var(--font-display);
  color: var(--accent);
  font-weight: 500;
  flex-shrink: 0;
}

.vu-complete .vu-pct {
  color: var(--success);
}

.vu-cancel {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1rem;
  padding: 0 4px;
  flex-shrink: 0;
}

.vu-cancel:hover {
  color: var(--error);
}

/* Progress Bar (legacy, for inline card progress) */
.lib-card-progress {
  height: 4px;
  background: rgba(245, 158, 11, 0.2);
  border-radius: 2px;
  overflow: hidden;
  margin-top: 0.25rem;
}

.lib-card-progress-bar {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.3s;
}

/* 11. Badges (quality indicators)
   ============================================ */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 2px;
  font-size: 0.65rem;
  font-family: var(--font-mono);
  font-weight: 600;
  white-space: nowrap;
  flex-shrink: 0;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.badge-original {
  background-color: rgba(16, 185, 129, 0.2);
  color: var(--success);
}

.badge-stream {
  background-color: var(--cyan-dim);
  color: var(--cyan);
}

/* 12. Chips (filters)
   ============================================ */
.lib-chip {
  padding: 0.4rem 0.85rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  font-size: 0.78rem;
  font-family: var(--font-mono);
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
  user-select: none;
}

.lib-chip:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.lib-chip.active {
  background: var(--accent);
  color: #0D0D12;
  border-color: var(--accent);
  font-weight: 600;
}

.lib-filter-row {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
  flex-wrap: wrap;
}

/* 13. Modal
   ============================================ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 16px;
}

.modal-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  width: 100%;
  max-width: 420px;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.25rem 0.75rem;
  border-bottom: 1px solid var(--border);
}

.modal-header h2 {
  font-size: 1rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.modal-header h2 svg {
  width: 18px;
  height: 18px;
  color: var(--accent);
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
}

.modal-close:hover {
  color: var(--text);
}

.modal-form {
  padding: 1rem 1.25rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.modal-form label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.78rem;
  font-family: var(--font-mono);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.modal-form input {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-btn);
  padding: 0.6rem 0.75rem;
  font-size: 0.9rem;
  font-family: var(--font-body);
  color: var(--text);
  outline: none;
  transition: border-color 0.2s;
}

.modal-form input:focus {
  border-color: var(--accent);
}

.modal-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
  margin-top: 0.5rem;
}

.modal-actions button {
  padding: 0.6rem 1.25rem;
  border-radius: var(--radius-btn);
  border: none;
  font-size: 0.85rem;
  font-family: var(--font-mono);
  cursor: pointer;
  transition: opacity 0.15s;
}

.modal-actions .btn-cancel {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
}

.modal-actions .btn-cancel:hover {
  border-color: var(--text-muted);
  color: var(--text);
}

.modal-actions .btn-save {
  background: var(--accent);
  color: #0D0D12;
  font-weight: 600;
}

.modal-actions .btn-save:hover {
  opacity: 0.85;
}

.modal-actions .btn-save:disabled {
  opacity: 0.5;
  cursor: default;
}

/* 14. Toast
   ============================================ */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 24px;
  font-size: 0.85rem;
  font-family: var(--font-mono);
  font-weight: 500;
  color: var(--text);
  box-shadow: 0 4px 24px rgba(0,0,0,0.5);
  opacity: 0;
  transition: transform 0.3s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.3s;
  z-index: 100;
  pointer-events: none;
  white-space: nowrap;
}

.toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

/* 15. Skeleton Loading
   ============================================ */
.skeleton {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.skeleton-line {
  height: 12px;
  background: linear-gradient(90deg, var(--border) 25%, var(--surface-hover) 50%, var(--border) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s ease-in-out infinite;
  border-radius: 2px;
}

.skeleton-line:first-child {
  width: 75%;
  height: 16px;
}

.skeleton-line:nth-child(2) {
  width: 50%;
}

.skeleton-line:nth-child(3) {
  width: 60%;
}

.skeleton-line:last-child {
  width: 40%;
}

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* 16. Spinner / Loader / Error
   ============================================ */
.loader {
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 24px 0;
}

.loader.active {
  display: flex;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.loader .pct {
  font-size: 1.5rem;
  font-weight: 500;
  font-family: var(--font-display);
  color: var(--accent);
  min-width: 48px;
  text-align: center;
}

.loader .status-text {
  font-size: 0.8125rem;
  font-family: var(--font-mono);
  color: var(--text-muted);
}

/* Error */
.error {
  display: none;
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.3);
  border-radius: var(--radius);
  padding: 12px 16px;
  color: var(--error);
  font-size: 0.85rem;
  font-family: var(--font-mono);
}

.error.active {
  display: block;
}

/* 17. Pagination
   ============================================ */
.lib-pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 0.4rem;
  margin-top: 1.5rem;
  flex-wrap: wrap;
}

.lib-pagination button {
  padding: 0.5rem 0.85rem;
  border-radius: var(--radius-btn);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font-size: 0.8rem;
  font-family: var(--font-mono);
  min-width: 44px;
  transition: border-color 0.15s, background 0.15s;
}

.lib-pagination button:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.lib-pagination button.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #0D0D12;
  font-weight: 600;
}

.lib-pagination button:disabled {
  opacity: 0.3;
  cursor: default;
  border-color: var(--border);
  color: var(--text-muted);
}

.lib-pagination button:disabled:hover {
  border-color: var(--border);
  color: var(--text-muted);
}

/* 17b. Table View (responsive, polished)
   ============================================ */
.lib-table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 0 -1rem;
  padding: 0 1rem;
  border-radius: var(--radius);
}

.lib-table {
  width: 100%;
  min-width: 620px;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 0.8rem;
  font-family: var(--font-mono);
}

.lib-table thead {
  position: sticky;
  top: 0;
  z-index: 2;
}

.lib-table th {
  text-align: left;
  padding: 0.65rem 0.5rem;
  color: var(--text-muted);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-size: 0.6rem;
  border-bottom: 2px solid var(--border);
  background: var(--bg);
  white-space: nowrap;
  user-select: none;
}

.lib-table td {
  padding: 0.55rem 0.5rem;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  vertical-align: middle;
  white-space: nowrap;
}

.lib-table tbody tr {
  transition: background 0.1s;
}

.lib-table tbody tr:hover {
  background: var(--surface-hover);
}

.lib-table tbody tr:last-child td {
  border-bottom: none;
}

.lib-table .col-title { width: 28%; }
.lib-table .col-platform { width: 12%; }
.lib-table .col-duration { width: 8%; }
.lib-table .col-size { width: 10%; }
.lib-table .col-quality { width: 12%; }
.lib-table .col-audio { width: 8%; text-align: center; }
.lib-table .col-video { width: 8%; text-align: center; }
.lib-table .col-actions { width: 14%; text-align: right; white-space: nowrap; }

.lib-table-title-cell {
  max-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: var(--font-body);
  font-weight: 500;
  color: var(--text);
}

.lib-table .badge {
  font-size: 0.6rem;
  padding: 1px 6px;
}

.lib-table .lib-manage-btn {
  font-size: 0.7rem;
  padding: 0.25rem 0.5rem;
  min-height: 28px;
  line-height: 1;
}

.lib-table td svg {
  vertical-align: middle;
  display: inline-block;
}

/* 18. Picker Overlay
   ============================================ */
.picker {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  z-index: 200;
  overflow-y: auto;
  padding: 16px;
}

.picker.active {
  display: flex;
  flex-direction: column;
}

.picker-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--surface);
  padding: 16px;
  border-radius: var(--radius) var(--radius) 0 0;
  border: 1px solid var(--border);
  border-bottom: none;
  font-weight: 500;
  font-family: var(--font-display);
}

#picker-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  cursor: pointer;
  padding: 0 4px;
}

.picker-groups {
  background: var(--surface);
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 var(--radius) var(--radius);
  padding: 0 16px 16px;
  max-height: 70vh;
  overflow-y: auto;
}

.picker-group {
  margin-top: 12px;
}

.picker-group-title {
  font-size: 0.7rem;
  text-transform: uppercase;
  font-family: var(--font-mono);
  color: var(--text-muted);
  margin-bottom: 8px;
  letter-spacing: 0.05em;
}

.picker-format {
  display: block;
  width: 100%;
  text-align: left;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-btn);
  padding: 10px 12px;
  margin-bottom: 6px;
  color: var(--text);
  font-size: 0.8125rem;
  font-family: var(--font-mono);
  cursor: pointer;
  transition: border-color 0.2s;
}

.picker-format:hover {
  border-color: var(--accent);
}

.picker-presets {
  margin-bottom: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

.picker-preset {
  background: var(--accent-dim) !important;
  border-color: var(--border-accent) !important;
  color: var(--accent) !important;
  font-weight: 600;
}

.picker-preset:hover {
  background: rgba(245, 158, 11, 0.25) !important;
}

/* Library picker overlay (in-card) */
.lib-picker-overlay {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem;
  margin-top: 0.5rem;
  max-height: 350px;
  overflow-y: auto;
}

.lib-picker-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.8rem;
  font-weight: 500;
  font-family: var(--font-mono);
  margin-bottom: 0.5rem;
  color: var(--text);
}

.lib-picker-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.2rem;
  cursor: pointer;
  padding: 0 0.25rem;
}

.lib-picker-overlay .picker-group {
  margin-top: 8px;
}

.lib-picker-overlay .picker-group-title {
  font-size: 0.7rem;
  text-transform: uppercase;
  font-family: var(--font-mono);
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.lib-picker-overlay .picker-format {
  width: 100%;
  text-align: left;
  padding: 0.4rem 0.65rem;
  font-size: 0.75rem;
  margin-bottom: 3px;
}

.lib-picker-overlay .picker-presets {
  margin-bottom: 8px;
  padding-bottom: 8px;
}

.lib-picker-overlay .picker-preset {
  width: 100%;
  text-align: left;
  margin-bottom: 3px;
}

/* 19. Install Banner
   ============================================ */
.install-banner {
  display: none;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
}

.install-banner.active {
  display: flex;
}

.install-banner span {
  flex: 1;
  font-size: 0.85rem;
  font-family: var(--font-body);
  color: var(--text);
}

.install-banner button {
  background: var(--accent);
  color: #0D0D12;
  border: none;
  border-radius: var(--radius-btn);
  padding: 8px 16px;
  font-size: 0.8125rem;
  font-family: var(--font-mono);
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: opacity 0.15s;
}

.install-banner button:hover {
  opacity: 0.85;
}

/* 20. Search (Library)
   ============================================ */
.lib-search {
  margin-bottom: 0.75rem;
}

.search-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.search-icon {
  position: absolute;
  left: 12px;
  width: 18px;
  height: 18px;
  color: var(--text-muted);
  pointer-events: none;
}

.lib-search input {
  width: 100%;
  padding: 0.75rem 1rem 0.75rem 2.5rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 0.9rem;
  font-family: var(--font-body);
  box-sizing: border-box;
  outline: none;
  transition: border-color 0.2s;
}

.lib-search input:focus {
  border-color: var(--accent);
}

.lib-search input::placeholder {
  color: var(--text-muted);
}

/* Library Filters Section */
.lib-filters {
  margin-bottom: 1rem;
}

.lib-filter-row {
  display: flex;
  gap: 0.4rem;
  margin-bottom: 0.5rem;
  flex-wrap: wrap;
}

/* 21. History section
   ============================================ */
.history-section h2 {
  font-size: 0.9rem;
  font-weight: 500;
  font-family: var(--font-display);
  color: var(--text-muted);
  margin-bottom: 10px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.history-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  transition: border-color 0.15s;
}

.history-item:hover {
  border-color: var(--accent);
}

.h-title {
  font-size: 0.875rem;
  font-family: var(--font-body);
  font-weight: 500;
  color: var(--text);
  margin-bottom: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.h-meta {
  font-size: 0.75rem;
  font-family: var(--font-mono);
  color: var(--text-muted);
}

.h-date {
  font-size: 0.6875rem;
  font-family: var(--font-mono);
  color: var(--text-muted);
  margin-top: 2px;
}

.empty {
  color: var(--text-muted);
  font-size: 0.8125rem;
  font-family: var(--font-mono);
  font-style: normal;
  text-align: center;
  padding: 16px 0;
}

/* 22. History and download section
   ============================================ */
.download-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 12px;
}

#custom-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.75rem;
  font-family: var(--font-mono);
  cursor: pointer;
  padding: 2px 0;
  text-align: left;
}

#custom-btn:hover {
  color: var(--accent);
}

/* Detect badge (original available) */
.badge-detect {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.75rem;
  font-family: var(--font-mono);
  color: var(--success);
  padding: 4px 0;
}

/* Download section header */
header {
  text-align: center;
  padding: 24px 0 8px;
}

header h1 {
  font-size: 2rem;
  font-weight: 500;
  color: var(--accent);
  letter-spacing: -0.03em;
  margin-bottom: 4px;
}

header p {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

/* 23. View Toggle (Cards / Table)
   ============================================ */
.view-toggle {
  display: flex;
  gap: 0.25rem;
  margin-bottom: 0.75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-btn);
  padding: 3px;
  width: fit-content;
}

.view-toggle-btn {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.4rem 1rem;
  border: none;
  border-radius: calc(var(--radius-btn) - 1px);
  background: transparent;
  color: var(--text-muted);
  font-size: 0.78rem;
  font-family: var(--font-mono);
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}

.view-toggle-btn:hover {
  color: var(--text);
}

.view-toggle-btn.active {
  background: var(--accent);
  color: #0D0D12;
  font-weight: 600;
}

.view-toggle-btn svg {
  width: 14px;
  height: 14px;
}

/* 23b. Utilities & Helpers
   ============================================ */
.text-center { text-align: center; }
.text-muted { color: var(--text-muted); }
.font-mono { font-family: var(--font-mono); }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mb-1 { margin-bottom: 0.5rem; }
.gap-1 { gap: 0.5rem; }

/* 24. Responsive
   ============================================ */
@media (max-width: 359px) {
  .container {
    padding: 12px;
    gap: 16px;
  }

  header h1 {
    font-size: 1.5rem;
  }

  .btn-format {
    height: 48px;
    font-size: 0.9rem;
  }
}

@media (min-width: 500px) {
  .lib-cards {
    grid-template-columns: 1fr 1fr;
  }
}

@media (min-width: 900px) {
  .lib-cards {
    grid-template-columns: repeat(3, 1fr);
  }
}

/* Legacy / Backward Compat selectors (for code migrated in Tasks 02-04)
   ============================================ */
/* Progress bar (old) → VU meter (new) */
#progress-bar { display: none; } /* Hidden by default */
.progress-bar { display: none; } /* Old class, hidden */
.progress-bar-track-fill,
.progress-bar-pct,
.progress-bar-title,
.progress-bar-cancel { display: none; }  /* Legacy, replaced by VU meter */

/* History section title */
.history-section h2 {
  font-size: 0.9rem;
  font-weight: 500;
  font-family: var(--font-display);
  color: var(--text-muted);
  margin-bottom: 10px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* Search wrapper for library */
.lib-search { margin-bottom: 0.75rem; }

/* 25. Reduced Motion
   ============================================ */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

  .vu-segment {
    height: 60% !important;  /* VU meter becomes flat bar */
    transition: background 0.2s !important;
  }

  .spinner {
    animation: none;
    border-top-color: var(--accent);
  }

  .skeleton-line {
    animation: none;
    background: var(--border);
  }
}

/* 26. Table Enhancements (new design)
   ============================================ */

/* Row height min 48px for mobile touch targets */
.lib-table tbody tr.lib-row { min-height: 48px; }
.lib-table tbody tr.lib-row:hover { background: var(--surface-hover); }

/* Sort indicators */
.sort-indicator { margin-left: 3px; font-size: 0.65rem; }

/* Thumbnail */
.lib-thumb { width: 40px; height: 40px; object-fit: cover; border-radius: 4px; display: block; }
.lib-thumb-placeholder {
  width: 40px; height: 40px; border-radius: 4px;
  background: var(--surface); display: flex; align-items: center;
  justify-content: center; font-size: 0.8rem; font-weight: 600;
  color: var(--text-muted); font-family: var(--font-mono);
}

/* Selection bar */
.selection-bar {
  display: none; align-items: center; gap: 0.75rem;
  padding: 0.5rem 1rem; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius);
  position: sticky; bottom: 60px; z-index: 50;
  margin-bottom: 0.5rem;
}
.sel-count { font-family: var(--font-mono); font-size: 0.8rem; color: var(--text); flex: 1; }
.sel-btn {
  padding: 0.5rem 1rem; border-radius: var(--radius-btn);
  border: none; font-family: var(--font-mono); font-size: 0.8rem;
  cursor: pointer; min-height: 44px;
}
.sel-btn-delete { background: rgba(239, 68, 68, 0.2); color: var(--error); }
.sel-btn-delete:hover { background: rgba(239, 68, 68, 0.3); }
.sel-btn-redl { background: var(--accent-dim); color: var(--accent); }
.sel-btn-redl:hover { background: rgba(245, 158, 11, 0.25); }

/* Editable cells */
.lib-table td.editable { cursor: text; position: relative; }
.lib-table td.editable:hover::after {
  content: '✏️'; position: absolute; right: 4px; top: 50%;
  transform: translateY(-50%); font-size: 0.65rem; opacity: 0.4;
}
.inline-edit-input {
  width: 100%; background: var(--bg); border: 1px solid var(--accent);
  border-radius: 2px; padding: 2px 4px; color: var(--text);
  font-family: var(--font-body); font-size: 0.8rem; outline: none;
}

/* Expandable panel */
.lib-expand-row td { padding: 1rem; background: rgba(245, 158, 11, 0.03); border-bottom: 2px solid var(--border-accent); }
.lib-expand-panel { display: flex; gap: 1rem; align-items: flex-start; }
.lib-expand-left { flex-shrink: 0; }
.lib-expand-thumb { width: 120px; height: 120px; object-fit: cover; border-radius: 4px; }
.lib-expand-thumb-placeholder {
  width: 120px; height: 120px; border-radius: 4px;
  background: var(--surface); display: flex; align-items: center;
  justify-content: center; font-size: 2rem; font-weight: 600;
  color: var(--text-muted); font-family: var(--font-mono);
}
.lib-expand-right { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 0.25rem; }
.lib-expand-title { font-size: 1rem; font-weight: 600; font-family: var(--font-body); color: var(--text); }
.lib-expand-meta { font-size: 0.78rem; font-family: var(--font-mono); color: var(--text); word-break: break-all; }
.lib-expand-divider { border-top: 1px solid var(--border); margin: 0.4rem 0; }
.lib-expand-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-top: 0.25rem; }

/* Expand button */
.expand-btn {
  background: none; border: none; color: var(--text-muted);
  cursor: pointer; font-size: 0.85rem; padding: 0.25rem 0.5rem;
  min-height: 44px; min-width: 44px;
}
.expand-btn:hover { color: var(--accent); }

/* Jellyfin badges */
.badge-jf { background: rgba(16, 185, 129, 0.2); color: var(--success); font-size: 0.6rem; }
.badge-jf-none { background: var(--surface); color: var(--text-muted); font-size: 0.6rem; }

/* Improved select-all checkbox */
.col-select input[type="checkbox"] { width: 18px; height: 18px; cursor: pointer; }

/* Embed card progress (reuse from old design under table) */
.lib-row .lib-card-progress { display: none; }

/* 27. Mobile Table Overrides
   ============================================ */
@media (max-width: 479px) {
  .lib-table .col-select,
  .lib-table .col-artist,
  .lib-table .col-album,
  .lib-table .col-bitrate,
  .lib-table .col-codec,
  .lib-table .col-size,
  .lib-table .col-platform,
  .lib-table .col-date,
  .lib-table .col-quality,
  .lib-table .col-jellyfin { display: none; }

  .lib-table-wrap { margin: 0 -1rem; padding: 0 0.5rem; }
  .lib-row .col-title { max-width: 40vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

  /* Expand panel stacks vertically on mobile */
  .lib-expand-panel { flex-direction: column; }
  .lib-expand-thumb { width: 80px; height: 80px; }
  .lib-expand-thumb-placeholder { width: 80px; height: 80px; font-size: 1.5rem; }

  /* Hide vertical indicators on mobile */
  .sort-indicator { display: none; }
}

@media (min-width: 480px) and (max-width: 899px) {
  .lib-table .col-codec,
  .lib-table .col-date,
  .lib-table .col-jellyfin { display: none; }
}
