/* AnimeCDN Dark Theme */
:root {
  --bg-primary: #0a0a0f;
  --bg-secondary: #12121a;
  --bg-card: #1a1a2e;
  --bg-card-hover: #1f1f35;
  --bg-input: #16162a;
  --border: #2a2a4a;
  --text-primary: #e4e4f0;
  --text-secondary: #8888aa;
  --text-muted: #555577;
  --accent: #7c3aed;
  --accent-hover: #6d28d9;
  --accent-light: #a78bfa;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --info: #3b82f6;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
}

a { color: var(--accent-light); text-decoration: none; }
a:hover { color: var(--accent); }

/* Login */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-primary);
}

.login-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 40px;
  width: 100%;
  max-width: 380px;
}

.login-logo {
  text-align: center;
  margin-bottom: 32px;
}

.login-logo h1 {
  font-size: 1.8rem;
  background: linear-gradient(135deg, var(--accent-light), #c084fc);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  font-weight: 800;
}

.login-logo span {
  font-size: 0.8rem;
  color: var(--text-muted);
  display: block;
  margin-top: 4px;
}

.login-field {
  margin-bottom: 16px;
}

.login-field label {
  display: block;
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-bottom: 6px;
  font-weight: 500;
}

.login-field input {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-primary);
  font-size: 0.95rem;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s;
}

.login-field input:focus {
  border-color: var(--accent);
}

.login-error {
  color: var(--danger);
  font-size: 0.8rem;
  min-height: 20px;
  margin-bottom: 8px;
}

.login-btn {
  width: 100%;
  padding: 12px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 0.95rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.2s;
}

.login-btn:hover {
  background: var(--accent-hover);
}

.login-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

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

.sidebar {
  width: 240px;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  padding: 20px 0;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
}

.sidebar-logo {
  padding: 0 20px 20px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 10px;
}

.sidebar-logo h1 {
  font-size: 1.4rem;
  background: linear-gradient(135deg, var(--accent-light), #c084fc);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  font-weight: 800;
}

.sidebar-logo span {
  font-size: 0.7rem;
  color: var(--text-muted);
  display: block;
  margin-top: 2px;
}

.nav-items { flex: 1; padding: 10px 0; overflow-y: auto; }

.sidebar-bottom {
  border-top: 1px solid var(--border);
  padding: 10px 0;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 20px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s;
  border-left: 3px solid transparent;
  font-size: 0.9rem;
}

.nav-item:hover {
  background: var(--bg-card);
  color: var(--text-primary);
}

.nav-item.active {
  background: rgba(124, 58, 237, 0.1);
  color: var(--accent-light);
  border-left-color: var(--accent);
}

.nav-item svg { width: 20px; height: 20px; flex-shrink: 0; }

.main-content {
  flex: 1;
  margin-left: 240px;
  padding: 24px;
  min-height: 100vh;
}

/* Header */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
}

.page-header h2 {
  font-size: 1.5rem;
  font-weight: 700;
}

/* Cards */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  transition: transform 0.2s, box-shadow 0.2s;
}

.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.3);
}

.stat-card .label {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 8px;
}

.stat-card .value {
  font-size: 1.8rem;
  font-weight: 700;
}

.stat-card .value.accent { color: var(--accent-light); }
.stat-card .value.success { color: var(--success); }
.stat-card .value.warning { color: var(--warning); }
.stat-card .value.info { color: var(--info); }

/* Progress bar */
.progress-bar {
  width: 100%;
  height: 8px;
  background: var(--bg-primary);
  border-radius: 4px;
  overflow: hidden;
  margin-top: 12px;
}

.progress-bar .fill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.5s ease;
  background: linear-gradient(90deg, var(--accent), var(--accent-light));
}

.progress-bar .fill.warning { background: linear-gradient(90deg, var(--warning), #fbbf24); }
.progress-bar .fill.danger { background: linear-gradient(90deg, var(--danger), #f87171); }

/* Title cards grid */
.titles-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
}

.title-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  cursor: pointer;
  transition: all 0.2s;
}

.title-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.4);
  border-color: var(--accent);
}

.title-card .poster {
  width: 100%;
  aspect-ratio: 3/4;
  object-fit: cover;
  background: var(--bg-input);
}

.title-card .info {
  padding: 12px;
}

.title-card .info h3 {
  font-size: 0.9rem;
  font-weight: 600;
  margin-bottom: 6px;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.title-card .info .meta {
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 100px;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
}

.badge.ongoing { background: rgba(16, 185, 129, 0.15); color: var(--success); }
.badge.finished { background: rgba(59, 130, 246, 0.15); color: var(--info); }
.badge.ready { background: rgba(16, 185, 129, 0.15); color: var(--success); }
.badge.downloading { background: rgba(245, 158, 11, 0.15); color: var(--warning); }
.badge.converting { background: rgba(124, 58, 237, 0.15); color: var(--accent-light); }
.badge.pending { background: rgba(85, 85, 119, 0.15); color: var(--text-muted); }
.badge.error { background: rgba(239, 68, 68, 0.15); color: var(--danger); }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  border: none;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

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

.btn-primary:hover { background: var(--accent-hover); }

.btn-danger {
  background: rgba(239, 68, 68, 0.15);
  color: var(--danger);
}

.btn-danger:hover { background: rgba(239, 68, 68, 0.25); }

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
}

.btn-ghost:hover { background: var(--bg-card); color: var(--text-primary); }

.btn-sm { padding: 5px 10px; font-size: 0.78rem; }

/* Forms */
.input, select, textarea {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  color: var(--text-primary);
  font-size: 0.9rem;
  width: 100%;
  outline: none;
  transition: border-color 0.2s;
}

.input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
}

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

.search-box {
  position: relative;
  max-width: 400px;
}

.search-box .input { padding-left: 38px; }

.search-box svg {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 18px;
  height: 18px;
  color: var(--text-muted);
}

/* Table */
.table-container {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}

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

th {
  text-align: left;
  padding: 12px 16px;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
}

td {
  padding: 12px 16px;
  font-size: 0.85rem;
  border-bottom: 1px solid var(--border);
}

tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--bg-card-hover); }

/* Modal */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(4px);
}

.modal {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 24px;
  width: 90%;
  max-width: 600px;
  max-height: 80vh;
  overflow-y: auto;
}

.modal h3 {
  font-size: 1.2rem;
  margin-bottom: 16px;
}

.form-group {
  margin-bottom: 14px;
}

.form-group label {
  display: block;
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

/* Torrent search results */
.torrent-result {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.torrent-result:hover { border-color: var(--accent); }

.torrent-result .torrent-info { flex: 1; min-width: 0; }

.torrent-result .torrent-title {
  font-size: 0.85rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.torrent-result .torrent-meta {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 4px;
  display: flex;
  gap: 12px;
}

.torrent-result .torrent-meta .seeders { color: var(--success); }

/* Video player */
.player-container {
  background: #000;
  border-radius: 8px;
  overflow: hidden;
  margin: 16px 0;
  aspect-ratio: 16/9;
}

.player-container video {
  width: 100%;
  height: 100%;
}

/* Toast notifications */
.toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 16px;
  font-size: 0.85rem;
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.4);
  animation: slideIn 0.3s ease;
  max-width: 350px;
}

.toast.success { border-left: 3px solid var(--success); }
.toast.error { border-left: 3px solid var(--danger); }
.toast.info { border-left: 3px solid var(--info); }

@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* Loading spinner */
.spinner {
  width: 32px;
  height: 32px;
  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); } }

.loading-center {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 40px;
}

/* Episode list */
.episode-list { display: flex; flex-direction: column; gap: 8px; }

.episode-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.episode-item .ep-number {
  font-weight: 600;
  color: var(--accent-light);
  min-width: 50px;
}

.episode-item .ep-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

/* Episode card grid */
.ep-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 14px;
}

.ep-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  transition: transform 0.2s, box-shadow 0.2s, border-color 0.2s;
}

.ep-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  border-color: var(--accent);
}

.ep-card-thumb {
  position: relative;
  width: 100%;
  aspect-ratio: 16/9;
  background-size: cover;
  background-position: center;
  background-color: var(--bg-input);
  cursor: pointer;
}

.ep-play-icon {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.35);
  opacity: 0;
  transition: opacity 0.2s;
}

.ep-card-thumb:hover .ep-play-icon {
  opacity: 1;
}

.ep-card-badges {
  position: absolute;
  top: 6px;
  left: 6px;
  display: flex;
  gap: 4px;
}

/* Episode badge styles */
.ep-badge {
  font-size: 0.65rem;
  font-weight: 700;
  padding: 3px 7px;
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  backdrop-filter: blur(6px);
  text-shadow: 0 1px 2px rgba(0,0,0,0.5);
}

.ep-badge-ready { background: rgba(16, 185, 129, 0.85); color: #fff; }
.ep-badge-converting { background: rgba(124, 58, 237, 0.85); color: #fff; }
.ep-badge-downloading { background: rgba(245, 158, 11, 0.85); color: #fff; }
.ep-badge-pending { background: rgba(85, 85, 119, 0.7); color: #ddd; }
.ep-badge-error { background: rgba(239, 68, 68, 0.85); color: #fff; }
.ep-badge-res { background: rgba(255, 255, 255, 0.2); color: #fff; }
.ep-badge-hd { background: rgba(124, 58, 237, 0.9); color: #fff; }

.ep-card-progress {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 0 4px 4px;
}

.ep-card-progress .progress-bar {
  height: 4px;
  margin-top: 0;
  border-radius: 2px;
}

.ep-card-info {
  padding: 8px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.ep-card-title {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ep-card-size {
  font-size: 0.7rem;
  color: var(--text-muted);
  white-space: nowrap;
  flex-shrink: 0;
}

.ep-card-duration {
  position: absolute;
  bottom: 6px;
  right: 6px;
  background: rgba(0,0,0,0.8);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 3px;
  letter-spacing: 0.5px;
}

/* Auto-Grab Section */
.grab-section {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 20px;
}

.grab-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.grab-status-badge {
  font-size: 0.7rem;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 100px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.grab-status-idle { background: rgba(85, 85, 119, 0.2); color: var(--text-muted); }
.grab-status-scanning { background: rgba(245, 158, 11, 0.2); color: var(--warning); animation: grabPulse 1.5s ease-in-out infinite; }
.grab-status-queued { background: rgba(59, 130, 246, 0.2); color: var(--info); }
.grab-status-grabbing { background: rgba(124, 58, 237, 0.2); color: var(--accent-light); animation: grabPulse 1.5s ease-in-out infinite; }
.grab-status-converting { background: rgba(124, 58, 237, 0.2); color: var(--accent-light); animation: grabPulse 2s ease-in-out infinite; }
.grab-status-done { background: rgba(16, 185, 129, 0.2); color: var(--success); }
.grab-status-error { background: rgba(239, 68, 68, 0.2); color: var(--danger); }

@keyframes grabPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

@media (max-width: 768px) {
  .ep-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
}

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

/* Filters */
.filters {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
}

.filter-chip {
  padding: 6px 14px;
  border-radius: 100px;
  font-size: 0.8rem;
  cursor: pointer;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  transition: all 0.2s;
}

.filter-chip:hover, .filter-chip.active {
  background: rgba(124, 58, 237, 0.15);
  border-color: var(--accent);
  color: var(--accent-light);
}

/* Responsive */
@media (max-width: 768px) {
  .sidebar {
    width: 60px;
    overflow: hidden;
  }
  .sidebar-logo h1 { font-size: 0; }
  .sidebar-logo span { display: none; }
  .nav-item span { display: none; }
  .nav-item { justify-content: center; padding: 12px; }
  .main-content { margin-left: 60px; padding: 16px; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .titles-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 480px) {
  .titles-grid { grid-template-columns: 1fr; }
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}

.empty-state svg {
  width: 64px;
  height: 64px;
  margin-bottom: 16px;
  opacity: 0.3;
}

.empty-state h3 {
  font-size: 1.1rem;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--bg-primary); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* Title detail */
.title-detail {
  display: grid;
  grid-template-columns: 260px 1fr;
  gap: 24px;
}

.title-detail .poster-large {
  width: 100%;
  border-radius: 12px;
  object-fit: cover;
}

.title-detail .title-info h2 {
  font-size: 1.5rem;
  margin-bottom: 4px;
}

.title-detail .title-info .subtitle {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-bottom: 12px;
}

.title-detail .title-info .description {
  color: var(--text-secondary);
  font-size: 0.85rem;
  line-height: 1.6;
  margin-bottom: 16px;
}

@media (max-width: 768px) {
  .title-detail {
    grid-template-columns: 1fr;
  }
  .title-detail .poster-large {
    max-width: 200px;
  }
}

/* Download item */
.download-item {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
  margin-bottom: 10px;
}

.download-item .dl-name {
  font-size: 0.88rem;
  font-weight: 500;
  margin-bottom: 8px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.download-item .dl-stats {
  display: flex;
  gap: 16px;
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 8px;
}
