/**
 * YT Family Downloader - Styles
 * Minimalist, Dark Mode, Responsive
 */

/* ========================================
   CSS Variables
   ======================================== */
:root {
  /* Colors - Light mode */
  --bg-primary: #f8fafc;
  --bg-secondary: #ffffff;
  --bg-tertiary: #f1f5f9;
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  --border-color: #e2e8f0;

  /* Accent colors */
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --primary-light: #dbeafe;
  --success: #22c55e;
  --success-light: #dcfce7;
  --error: #ef4444;
  --error-light: #fee2e2;
  --warning: #f59e0b;
  --warning-light: #fef3c7;

  /* Spacing */
  --space-xs: 0.25rem;
  --space-sm: 0.5rem;
  --space-md: 1rem;
  --space-lg: 1.5rem;
  --space-xl: 2rem;

  /* Typography */
  --font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --font-size-sm: 0.875rem;
  --font-size-base: 1rem;
  --font-size-lg: 1.125rem;
  --font-size-xl: 1.25rem;
  --font-size-2xl: 1.5rem;

  /* Border radius */
  --radius-sm: 0.375rem;
  --radius-md: 0.5rem;
  --radius-lg: 0.75rem;
  --radius-full: 9999px;

  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.1);
}

/* Dark mode */
[data-theme="dark"],
.dark {
  --bg-primary: #0f172a;
  --bg-secondary: #1e293b;
  --bg-tertiary: #334155;
  --text-primary: #f1f5f9;
  --text-secondary: #cbd5e1;
  --text-muted: #64748b;
  --border-color: #334155;

  --primary-light: #1e3a5f;
  --success-light: #14532d;
  --error-light: #7f1d1d;
  --warning-light: #78350f;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --bg-tertiary: #334155;
    --text-primary: #f1f5f9;
    --text-secondary: #cbd5e1;
    --text-muted: #64748b;
    --border-color: #334155;

    --primary-light: #1e3a5f;
    --success-light: #14532d;
    --error-light: #7f1d1d;
    --warning-light: #78350f;
  }
}

/* ========================================
   Reset & Base
   ======================================== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

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

body {
  font-family: var(--font-family);
  font-size: var(--font-size-base);
  line-height: 1.6;
  color: var(--text-primary);
  background: var(--bg-primary);
  min-height: 100vh;
}

a {
  color: var(--primary);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

code {
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 0.875em;
  background: var(--bg-tertiary);
  padding: 0.125em 0.375em;
  border-radius: var(--radius-sm);
}

/* ========================================
   Layout
   ======================================== */
.app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.main {
  flex: 1;
  padding: var(--space-lg);
  max-width: 1200px;
  margin: 0 auto;
  width: 100%;
}

/* ========================================
   Header
   ======================================== */
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--space-md) var(--space-lg);
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  flex-wrap: wrap;
  gap: var(--space-md);
}

.header__logo h1,
.header__logo a {
  font-size: var(--font-size-xl);
  font-weight: 600;
  color: var(--text-primary);
  text-decoration: none;
}

.header__nav {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  flex-wrap: wrap;
}

.header__link {
  color: var(--text-secondary);
  font-size: var(--font-size-sm);
  padding: var(--space-xs) var(--space-sm);
  border-radius: var(--radius-sm);
  transition: background 0.2s, color 0.2s;
}

.header__link:hover,
.header__link--active {
  color: var(--primary);
  background: var(--primary-light);
  text-decoration: none;
}

.header__user {
  color: var(--text-muted);
  font-size: var(--font-size-sm);
}

/* ========================================
   Footer
   ======================================== */
.footer {
  padding: var(--space-md) var(--space-lg);
  text-align: center;
  color: var(--text-muted);
  font-size: var(--font-size-sm);
  border-top: 1px solid var(--border-color);
}

/* ========================================
   Buttons
   ======================================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  padding: var(--space-sm) var(--space-lg);
  font-size: var(--font-size-base);
  font-weight: 500;
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all 0.2s;
  text-decoration: none;
  white-space: nowrap;
}

.btn--primary {
  background: var(--primary);
  color: white;
}

.btn--primary:hover {
  background: var(--primary-hover);
  text-decoration: none;
}

.btn--secondary {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.btn--secondary:hover {
  background: var(--border-color);
  text-decoration: none;
}

.btn--danger {
  background: var(--error);
  color: white;
}

.btn--danger:hover {
  background: #dc2626;
}

.btn--small {
  padding: var(--space-xs) var(--space-sm);
  font-size: var(--font-size-sm);
}

.btn--block {
  width: 100%;
}

/* ========================================
   Forms
   ======================================== */
.form-group {
  margin-bottom: var(--space-md);
}

.form-group label {
  display: block;
  margin-bottom: var(--space-xs);
  font-weight: 500;
  color: var(--text-secondary);
  font-size: var(--font-size-sm);
}

input[type="text"],
input[type="password"],
input[type="email"],
select,
textarea {
  width: 100%;
  padding: var(--space-sm) var(--space-md);
  font-size: var(--font-size-base);
  font-family: inherit;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  background: var(--bg-secondary);
  color: var(--text-primary);
  transition: border-color 0.2s, box-shadow 0.2s;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}

.input-group {
  display: flex;
  gap: var(--space-sm);
}

.input-group input {
  flex: 1;
}

.form-inline {
  display: flex;
  gap: var(--space-md);
  flex-wrap: wrap;
  align-items: flex-end;
}

.form-inline .form-group {
  margin-bottom: 0;
  flex: 1;
  min-width: 150px;
}

.form-actions {
  display: flex;
  gap: var(--space-md);
  justify-content: flex-end;
  margin-top: var(--space-lg);
}

/* ========================================
   Cards
   ======================================== */
.card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  margin-bottom: var(--space-lg);
}

.card__title {
  font-size: var(--font-size-lg);
  font-weight: 600;
  margin-bottom: var(--space-md);
  padding-bottom: var(--space-sm);
  border-bottom: 1px solid var(--border-color);
}

/* ========================================
   Tables
   ======================================== */
.table-responsive {
  overflow-x: auto;
}

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

.table th,
.table td {
  text-align: left;
  padding: var(--space-sm) var(--space-md);
  border-bottom: 1px solid var(--border-color);
}

.table th {
  font-weight: 600;
  color: var(--text-muted);
  font-size: var(--font-size-sm);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.table tbody tr:hover {
  background: var(--bg-tertiary);
}

/* ========================================
   Stats Grid
   ======================================== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: var(--space-md);
  margin-bottom: var(--space-lg);
}

.stat-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  text-align: center;
}

.stat-card__value {
  font-size: var(--font-size-2xl);
  font-weight: 700;
  color: var(--primary);
}

.stat-card__label {
  color: var(--text-muted);
  font-size: var(--font-size-sm);
  margin-top: var(--space-xs);
}

/* ========================================
   Status & Badges
   ======================================== */
.status {
  display: inline-block;
  padding: var(--space-xs) var(--space-sm);
  border-radius: var(--radius-full);
  font-size: var(--font-size-sm);
  font-weight: 500;
}

.status--success { background: var(--success-light); color: var(--success); }
.status--error { background: var(--error-light); color: var(--error); }
.status--warning { background: var(--warning-light); color: var(--warning); }
.status--completed { background: var(--success-light); color: var(--success); }
.status--failed { background: var(--error-light); color: var(--error); }
.status--started { background: var(--warning-light); color: var(--warning); }

.badge {
  display: inline-block;
  padding: var(--space-xs) var(--space-sm);
  border-radius: var(--radius-full);
  font-size: var(--font-size-sm);
  font-weight: 500;
}

.badge--primary { background: var(--primary-light); color: var(--primary); }
.badge--secondary { background: var(--bg-tertiary); color: var(--text-secondary); }

/* ========================================
   Flash Messages
   ======================================== */
.flash {
  padding: var(--space-md);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-lg);
  font-weight: 500;
}

.flash--success { background: var(--success-light); color: var(--success); }
.flash--error { background: var(--error-light); color: var(--error); }
.flash--warning { background: var(--warning-light); color: var(--warning); }

/* ========================================
   Login Page
   ======================================== */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: var(--space-lg);
}

.login-container {
  width: 100%;
  max-width: 400px;
}

.login-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: var(--space-xl);
}

.login-header {
  text-align: center;
  margin-bottom: var(--space-xl);
}

.login-header h1 {
  font-size: var(--font-size-2xl);
  margin-bottom: var(--space-sm);
}

.login-header p {
  color: var(--text-muted);
}

.login-footer {
  text-align: center;
  margin-top: var(--space-lg);
}

/* ========================================
   Downloader
   ======================================== */
.downloader {
  max-width: 800px;
  margin: 0 auto;
}

.downloader__form {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: var(--space-xl);
  margin-bottom: var(--space-lg);
}

/* Video Card */
.video-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  margin-bottom: var(--space-lg);
}

.video-card__header {
  display: flex;
  gap: var(--space-lg);
  margin-bottom: var(--space-lg);
}

.video-card__thumbnail {
  width: 180px;
  height: 100px;
  object-fit: cover;
  border-radius: var(--radius-md);
  background: var(--bg-tertiary);
  flex-shrink: 0;
}

.video-card__info {
  flex: 1;
  min-width: 0;
}

.video-card__title {
  font-size: var(--font-size-lg);
  font-weight: 600;
  margin-bottom: var(--space-sm);
}

.video-card__meta {
  color: var(--text-muted);
  font-size: var(--font-size-sm);
}

.video-card__formats {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-sm);
  margin-bottom: var(--space-lg);
}

.format-option {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-sm) var(--space-md);
  background: var(--bg-tertiary);
  border: 2px solid transparent;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all 0.2s;
}

.format-option:hover {
  border-color: var(--primary);
}

.format-option input {
  display: none;
}

.format-option input:checked + .format-option__label {
  background: var(--primary-light);
  border-color: var(--primary);
}

.format-option.selected {
  background: var(--primary-light);
  border-color: var(--primary);
}

/* Playlist Card */
.playlist-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  margin-bottom: var(--space-lg);
}

.playlist-card__header {
  margin-bottom: var(--space-lg);
}

.playlist-card__title {
  font-size: var(--font-size-lg);
  font-weight: 600;
}

.playlist-card__count {
  color: var(--text-muted);
  font-size: var(--font-size-sm);
}

.playlist-item {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  padding: var(--space-sm) 0;
  border-bottom: 1px solid var(--border-color);
}

.playlist-item:last-child {
  border-bottom: none;
}

.playlist-item input[type="checkbox"] {
  width: 18px;
  height: 18px;
  cursor: pointer;
}

.playlist-item__title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.playlist-item__duration {
  color: var(--text-muted);
  font-size: var(--font-size-sm);
}

.playlist-item__download {
  padding: var(--space-xs) var(--space-sm);
}

.playlist-actions {
  display: flex;
  gap: var(--space-md);
  flex-wrap: wrap;
  margin-top: var(--space-lg);
}

/* Progress */
.progress-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
}

.progress-bar {
  height: 8px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-full);
  overflow: hidden;
  margin: var(--space-md) 0;
}

.progress-bar__fill {
  height: 100%;
  background: var(--primary);
  border-radius: var(--radius-full);
  transition: width 0.3s ease;
  width: 0%;
}

.progress-status {
  text-align: center;
  color: var(--text-muted);
  font-size: var(--font-size-sm);
}

/* Loading */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-md);
  padding: var(--space-xl);
  color: var(--text-muted);
}

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

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

/* Error */
.error {
  background: var(--error-light);
  color: var(--error);
  padding: var(--space-md);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-lg);
}

/* ========================================
   Theme Toggle
   ======================================== */
.theme-toggle {
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-full);
  width: 36px;
  height: 36px;
  font-size: 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

.theme-toggle:hover {
  background: var(--border-color);
}

/* ========================================
   Modal
   ======================================== */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-lg);
  z-index: 1000;
}

.modal__content {
  background: var(--bg-secondary);
  border-radius: var(--radius-lg);
  padding: var(--space-xl);
  width: 100%;
  max-width: 500px;
  max-height: 90vh;
  overflow-y: auto;
}

.modal__content h3 {
  margin-bottom: var(--space-lg);
}

/* ========================================
   Lists
   ======================================== */
.status-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}

.status-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: var(--space-sm) 0;
  border-bottom: 1px solid var(--border-color);
}

.status-item:last-child {
  border-bottom: none;
}

.status-item__label {
  color: var(--text-muted);
}

.top-list {
  list-style: none;
}

.top-list__item {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  padding: var(--space-sm) 0;
  border-bottom: 1px solid var(--border-color);
}

.top-list__item:last-child {
  border-bottom: none;
}

.top-list__count {
  background: var(--primary-light);
  color: var(--primary);
  padding: var(--space-xs) var(--space-sm);
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: var(--font-size-sm);
}

.top-list__title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.device-list {
  list-style: none;
}

.device-list__item {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  padding: var(--space-sm) 0;
  border-bottom: 1px solid var(--border-color);
}

.device-list__item:last-child {
  border-bottom: none;
}

.device-list__icon {
  font-size: 1.5rem;
}

.device-list__name {
  flex: 1;
  font-weight: 500;
}

.device-list__stats {
  color: var(--text-muted);
  font-size: var(--font-size-sm);
}

/* ========================================
   Pagination
   ======================================== */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-md);
  margin-top: var(--space-lg);
  flex-wrap: wrap;
}

.pagination__info {
  color: var(--text-muted);
  font-size: var(--font-size-sm);
}

/* ========================================
   Utilities
   ======================================== */
.hidden { display: none !important; }
.text-muted { color: var(--text-muted); }
.text-sm { font-size: var(--font-size-sm); }
.truncate {
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.page-title {
  font-size: var(--font-size-xl);
  font-weight: 600;
  margin-bottom: var(--space-lg);
}

.status-bar {
  display: flex;
  align-items: center;
  gap: var(--space-lg);
  padding: var(--space-md);
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-lg);
  flex-wrap: wrap;
  font-size: var(--font-size-sm);
}

.empty-state {
  text-align: center;
  padding: var(--space-xl);
  color: var(--text-muted);
}

.filters-form {
  display: flex;
  gap: var(--space-md);
  flex-wrap: wrap;
  align-items: flex-end;
}

.filters-form .form-group {
  margin-bottom: 0;
  min-width: 150px;
}

.device-icon {
  font-size: 1.25rem;
}

/* ========================================
   Cookies Section
   ======================================== */
.cookies-section {
  margin-top: var(--space-lg);
  padding: var(--space-lg);
  background: var(--warning-light);
  border: 2px solid var(--warning);
  border-radius: var(--radius-lg);
}

[data-theme="dark"] .cookies-section {
  background: rgba(245, 158, 11, 0.1);
}

.cookies-section h3 {
  margin: 0 0 var(--space-md) 0;
  color: var(--text-primary);
}

.cookies-section p {
  margin: 0 0 var(--space-md) 0;
  color: var(--text-secondary);
}

.cookies-status {
  padding: var(--space-md);
  border-radius: var(--radius-md);
  margin-bottom: var(--space-md);
  font-weight: 500;
}

.cookies-status--active {
  background: var(--success-light);
  color: var(--success);
  border: 1px solid var(--success);
}

.cookies-status--empty {
  background: var(--warning-light);
  color: #92400e;
  border: 1px solid var(--warning);
}

.cookies-instructions {
  margin-bottom: var(--space-lg);
  padding: var(--space-md);
  background: var(--bg-secondary);
  border-radius: var(--radius-md);
}

.cookies-instructions summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--primary);
}

.cookies-instructions ol {
  margin: var(--space-md) 0 0 var(--space-lg);
  padding: 0;
}

.cookies-instructions li {
  margin-bottom: var(--space-sm);
}

.cookies-instructions a {
  color: var(--primary);
}

.cookies-form textarea {
  width: 100%;
  padding: var(--space-md);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  font-family: monospace;
  font-size: var(--font-size-sm);
  background: var(--bg-secondary);
  color: var(--text-primary);
  resize: vertical;
  min-height: 120px;
}

.cookies-form__buttons {
  display: flex;
  gap: var(--space-md);
  margin-top: var(--space-md);
}

.cookies-note {
  margin-top: var(--space-md);
  font-size: var(--font-size-sm);
  color: var(--text-muted);
}

/* ========================================
   Responsive
   ======================================== */
@media (max-width: 768px) {
  .header {
    flex-direction: column;
    text-align: center;
  }

  .header__nav {
    justify-content: center;
  }

  .video-card__header {
    flex-direction: column;
  }

  .video-card__thumbnail {
    width: 100%;
    height: auto;
    aspect-ratio: 16/9;
  }

  .form-inline {
    flex-direction: column;
  }

  .form-inline .form-group {
    width: 100%;
  }

  .table th,
  .table td {
    padding: var(--space-xs) var(--space-sm);
    font-size: var(--font-size-sm);
  }

  .truncate {
    max-width: 120px;
  }

  .playlist-actions {
    flex-direction: column;
  }

  .playlist-actions .btn {
    width: 100%;
  }
}

@media (max-width: 480px) {
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .header__link {
    font-size: 0.75rem;
    padding: var(--space-xs);
  }

  .btn {
    padding: var(--space-sm) var(--space-md);
    font-size: var(--font-size-sm);
  }
}
