/* ========================================
   YouTube to MP3 — Dashboard
   ======================================== */

:root {
  --bg: #0a0a0f;
  --bg-card: #12121a;
  --bg-card-hover: #16161f;
  --bg-input: #1a1a25;
  --bg-input-focus: #1e1e2a;

  --border: #2a2a3a;
  --border-focus: #6366f1;

  --text: #e4e4eb;
  --text-secondary: #8b8b9e;
  --text-muted: #5a5a70;

  --accent: #6366f1;
  --accent-hover: #818cf8;
  --accent-glow: rgba(99, 102, 241, 0.15);

  --green: #22c55e;
  --green-bg: rgba(34, 197, 94, 0.1);
  --red: #ef4444;
  --red-bg: rgba(239, 68, 68, 0.08);
  --yellow: #eab308;
  --yellow-bg: rgba(234, 179, 8, 0.1);
  --blue: #3b82f6;

  --radius: 12px;
  --radius-sm: 8px;
  --radius-xs: 6px;
  --transition: 0.2s ease;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* ---- Layout ---- */

.app {
  max-width: 680px;
  margin: 0 auto;
  padding: 0 20px 60px;
}

/* ---- Header ---- */

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 24px 0 32px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 28px;
}

.header-left .logo {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
}

.logo svg {
  color: var(--accent);
}

.logo h1 {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.status-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-secondary);
}

.status-badge.online {
  border-color: rgba(34, 197, 94, 0.3);
  background: var(--green-bg);
  color: var(--green);
}

.status-badge.offline {
  border-color: rgba(239, 68, 68, 0.3);
  background: var(--red-bg);
  color: var(--red);
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-muted);
}

.status-badge.online .status-dot {
  background: var(--green);
  box-shadow: 0 0 6px rgba(34, 197, 94, 0.5);
}

.status-badge.offline .status-dot {
  background: var(--red);
}

/* ---- Cards ---- */

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 16px;
}

.card-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 20px;
}

/* ---- Form Elements ---- */

.input-group {
  margin-bottom: 16px;
  flex: 1;
}

.input-group label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.label-optional {
  color: var(--text-muted);
  font-weight: 400;
}

.url-input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.input-icon {
  position: absolute;
  left: 14px;
  color: var(--text-muted);
  pointer-events: none;
}

input[type="url"],
input[type="text"],
select {
  width: 100%;
  padding: 12px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  transition: border-color var(--transition), background var(--transition);
  outline: none;
}

input[type="url"] {
  padding-left: 42px;
  padding-right: 44px;
}

input:focus,
select:focus {
  border-color: var(--border-focus);
  background: var(--bg-input-focus);
}

input::placeholder {
  color: var(--text-muted);
}

select {
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg width='12' height='8' viewBox='0 0 12 8' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1.5L6 6.5L11 1.5' stroke='%235a5a70' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 36px;
}

.btn-paste {
  position: absolute;
  right: 8px;
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 6px;
  border-radius: var(--radius-xs);
  transition: color var(--transition), background var(--transition);
}

.btn-paste:hover {
  color: var(--accent);
  background: var(--accent-glow);
}

.options-row {
  display: flex;
  gap: 12px;
}

@media (max-width: 500px) {
  .options-row {
    flex-direction: column;
  }
}

/* ---- Video Preview ---- */

.video-preview {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
  animation: fadeIn 0.3s ease;
}

.preview-thumb {
  width: 96px;
  height: 54px;
  border-radius: var(--radius-xs);
  object-fit: cover;
  background: var(--bg);
  flex-shrink: 0;
}

.preview-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.preview-meta {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 2px;
}

.separator {
  margin: 0 4px;
  color: var(--text-muted);
}

/* ---- Buttons ---- */

.btn-convert {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px 20px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background var(--transition), transform 0.1s ease, opacity var(--transition);
}

.btn-convert:hover:not(:disabled) {
  background: var(--accent-hover);
}

.btn-convert:active:not(:disabled) {
  transform: scale(0.99);
}

.btn-convert:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn-convert.loading {
  opacity: 0.7;
  pointer-events: none;
}

.btn-download {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 14px 20px;
  background: var(--green);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  text-decoration: none;
  transition: background var(--transition), transform 0.1s ease;
  animation: fadeIn 0.4s ease;
}

.btn-download:hover {
  background: #16a34a;
}

.btn-download:active {
  transform: scale(0.99);
}

.download-size {
  font-weight: 400;
  opacity: 0.8;
  font-size: 13px;
}

.btn-new {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px;
  margin-top: 8px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: border-color var(--transition), color var(--transition);
}

.btn-new:hover {
  border-color: var(--text-muted);
  color: var(--text);
}

.btn-text {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius-xs);
  transition: color var(--transition);
}

.btn-text:hover {
  color: var(--text-secondary);
}

/* ---- Error Banner ---- */

.error-banner {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  background: var(--red-bg);
  border: 1px solid rgba(239, 68, 68, 0.2);
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
  color: var(--red);
  font-size: 13px;
  animation: fadeIn 0.3s ease;
}

.error-banner svg {
  flex-shrink: 0;
}

/* ---- Active Job ---- */

.job-card {
  border-color: var(--accent);
  box-shadow: 0 0 20px var(--accent-glow);
  animation: fadeIn 0.4s ease;
}

.job-card.done {
  border-color: var(--green);
  box-shadow: 0 0 20px rgba(34, 197, 94, 0.1);
}

.job-card.failed {
  border-color: var(--red);
  box-shadow: 0 0 20px rgba(239, 68, 68, 0.1);
}

.job-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.job-header .card-title {
  margin-bottom: 0;
}

.job-status-badge {
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: var(--accent-glow);
  color: var(--accent);
}

.job-status-badge.done {
  background: var(--green-bg);
  color: var(--green);
}

.job-status-badge.failed {
  background: var(--red-bg);
  color: var(--red);
}

.job-video-info {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
}

.job-thumb {
  width: 72px;
  height: 40px;
  border-radius: var(--radius-xs);
  object-fit: cover;
  background: var(--bg);
  flex-shrink: 0;
}

.job-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

.job-meta {
  font-size: 12px;
  color: var(--text-secondary);
}

/* ---- Progress Bar ---- */

.progress-section {
  margin-bottom: 16px;
}

.progress-bar-track {
  height: 6px;
  background: var(--bg-input);
  border-radius: 10px;
  overflow: hidden;
  margin-bottom: 8px;
}

.progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-hover));
  border-radius: 10px;
  transition: width 0.5s ease;
  min-width: 0;
}

.job-card.done .progress-bar-fill {
  background: linear-gradient(90deg, var(--green), #4ade80);
}

.job-card.failed .progress-bar-fill {
  background: var(--red);
}

.progress-labels {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
}

.progress-stage {
  color: var(--text-secondary);
}

.progress-percent {
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

/* ---- History ---- */

.history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.history-header .card-title {
  margin-bottom: 0;
}

.history-empty {
  text-align: center;
  padding: 24px 0;
  color: var(--text-muted);
  font-size: 13px;
}

.history-empty svg {
  margin-bottom: 8px;
}

.history-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  background: var(--bg-input);
  border-radius: var(--radius-sm);
  margin-bottom: 6px;
  transition: background var(--transition);
}

.history-item:hover {
  background: var(--bg-input-focus);
}

.history-item-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
  flex: 1;
}

.history-item-title {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-item-meta {
  font-size: 11px;
  color: var(--text-muted);
}

.history-item-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
  margin-left: 12px;
}

.history-item .btn-dl {
  padding: 6px 12px;
  background: var(--accent-glow);
  border: none;
  border-radius: var(--radius-xs);
  color: var(--accent);
  font-size: 12px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  text-decoration: none;
  transition: background var(--transition);
}

.history-item .btn-dl:hover {
  background: rgba(99, 102, 241, 0.25);
}

.history-item .status-indicator {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  margin-right: 10px;
}

.status-indicator.done { background: var(--green); }
.status-indicator.failed { background: var(--red); }
.status-indicator.processing { background: var(--yellow); }
.status-indicator.queued { background: var(--text-muted); }

/* ---- Stats ---- */

.stats-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.stats-header .card-title {
  margin-bottom: 0;
}

.btn-clear-queue {
  color: var(--red);
  font-size: 12px;
}

.btn-clear-queue:hover {
  color: #f87171;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

@media (max-width: 500px) {
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

.stat {
  text-align: center;
  padding: 12px 8px;
  background: var(--bg-input);
  border-radius: var(--radius-sm);
}

.stat-value {
  display: block;
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.stat-label {
  display: block;
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ---- Utilities ---- */

.hidden {
  display: none !important;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.loading-pulse {
  animation: pulse 1.5s ease-in-out infinite;
}

/* ---- Scrollbar ---- */

::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* ---- Playlist Selection ---- */

.playlist-select-card {
  border-color: var(--accent);
  box-shadow: 0 0 20px var(--accent-glow);
  animation: fadeIn 0.4s ease;
}

.pls-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}

.pls-header h3 {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}

.pls-meta {
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 16px;
}

.pls-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  padding: 8px 12px;
  background: var(--bg-input);
  border-radius: var(--radius-sm);
}

.pls-toolbar-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.pls-toolbar-right {
  font-size: 12px;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}

.pls-cb-all {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  user-select: none;
}

.pls-cb-all input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  border: 2px solid var(--border);
  border-radius: 4px;
  background: var(--bg-input);
  cursor: pointer;
  position: relative;
  transition: background var(--transition), border-color var(--transition);
  flex-shrink: 0;
}

.pls-cb-all input[type="checkbox"]:checked {
  background: var(--accent);
  border-color: var(--accent);
}

.pls-cb-all input[type="checkbox"]:checked::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 5px;
  width: 4px;
  height: 8px;
  border: solid white;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

.pls-cb-all input[type="checkbox"]:indeterminate {
  background: var(--accent);
  border-color: var(--accent);
}

.pls-cb-all input[type="checkbox"]:indeterminate::after {
  content: '';
  position: absolute;
  top: 6px;
  left: 3px;
  width: 8px;
  height: 2px;
  background: white;
  border-radius: 1px;
}

.pls-list {
  max-height: 420px;
  overflow-y: auto;
  margin-bottom: 16px;
}

.pls-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  background: var(--bg-input);
  border-radius: var(--radius-xs);
  margin-bottom: 4px;
  cursor: pointer;
  transition: background var(--transition);
  user-select: none;
}

.pls-item:hover {
  background: var(--bg-input-focus);
}

.pls-item.selected {
  background: rgba(99, 102, 241, 0.08);
  border: 1px solid rgba(99, 102, 241, 0.2);
  margin-bottom: 3px;
}

.pls-item input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border: 2px solid var(--border);
  border-radius: 4px;
  background: var(--bg-input);
  cursor: pointer;
  position: relative;
  transition: background var(--transition), border-color var(--transition);
  flex-shrink: 0;
}

.pls-item input[type="checkbox"]:checked {
  background: var(--accent);
  border-color: var(--accent);
}

.pls-item input[type="checkbox"]:checked::after {
  content: '';
  position: absolute;
  top: 1px;
  left: 4px;
  width: 4px;
  height: 7px;
  border: solid white;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

.pls-item-thumb {
  width: 64px;
  height: 36px;
  border-radius: 4px;
  object-fit: cover;
  background: var(--bg);
  flex-shrink: 0;
}

.pls-item-info {
  flex: 1;
  min-width: 0;
}

.pls-item-title {
  font-size: 12px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.pls-item-detail {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 1px;
}

.pls-item-idx {
  font-size: 11px;
  color: var(--text-muted);
  width: 20px;
  text-align: right;
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}

.btn-convert-selected {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px 20px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background var(--transition), transform 0.1s ease, opacity var(--transition);
}

.btn-convert-selected:hover:not(:disabled) {
  background: var(--accent-hover);
}

.btn-convert-selected:active:not(:disabled) {
  transform: scale(0.99);
}

.btn-convert-selected:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn-convert-selected.loading {
  opacity: 0.7;
  pointer-events: none;
}

.pls-cancel {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px;
  margin-top: 8px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: border-color var(--transition), color var(--transition);
}

.pls-cancel:hover {
  border-color: var(--text-muted);
  color: var(--text);
}

/* ---- Playlist Batch ---- */

.playlist-card {
  border-color: var(--accent);
  box-shadow: 0 0 20px var(--accent-glow);
  animation: fadeIn 0.4s ease;
}

.playlist-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.playlist-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}

.playlist-meta {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 2px;
}

.playlist-summary {
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
  white-space: nowrap;
}

.playlist-summary .pl-done {
  font-variant-numeric: tabular-nums;
}

.playlist-list {
  margin-top: 16px;
  max-height: 400px;
  overflow-y: auto;
}

.pl-job-row {
  display: flex;
  align-items: center;
  padding: 8px 10px;
  background: var(--bg-input);
  border-radius: var(--radius-xs);
  margin-bottom: 4px;
  transition: background var(--transition);
}

.pl-job-row:hover {
  background: var(--bg-input-focus);
}

.pl-job-info {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.pl-job-title {
  font-size: 12px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  min-width: 0;
}

.pl-job-status {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.pl-job-actions {
  flex-shrink: 0;
  margin-left: 8px;
}

.pl-job-actions .btn-dl {
  padding: 4px 10px;
  background: var(--accent-glow);
  border: none;
  border-radius: var(--radius-xs);
  color: var(--accent);
  font-size: 11px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  text-decoration: none;
  transition: background var(--transition);
}

.pl-job-actions .btn-dl:hover {
  background: rgba(99, 102, 241, 0.25);
}

.playlist-card .progress-bar-track {
  margin-bottom: 0;
}

.playlist-card .btn-new {
  margin-top: 16px;
}
