:root {
  --bg: #0b0d12;
  --bg-elevated: #131722;
  --bg-card: #171c29;
  --bg-hover: #1e2436;
  --border: rgba(255, 255, 255, 0.08);
  --text: #f3f5f9;
  --text-muted: #9aa4b8;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --success: #22c55e;
  --warning: #f59e0b;
  --radius: 14px;
  --shadow: 0 18px 45px rgba(0, 0, 0, 0.45);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
  background: radial-gradient(circle at top right, #161f35 0%, var(--bg) 55%);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

.hidden {
  display: none !important;
}

/* Login */
.login-container {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 32px 28px;
  box-shadow: var(--shadow);
}

.brand-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
  background: rgba(59, 130, 246, 0.12);
  padding: 5px 12px;
  border-radius: 999px;
  margin-bottom: 16px;
}

.brand-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
}

.login-card h1 {
  font-size: 24px;
  font-weight: 700;
  margin-bottom: 6px;
}

.subtitle {
  color: var(--text-muted);
  font-size: 14px;
  margin-bottom: 24px;
}

.field {
  margin-bottom: 16px;
}

.field label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.field input {
  width: 100%;
  padding: 11px 14px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-size: 15px;
  outline: none;
  transition: border-color 0.2s;
}

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

/* Buttons */
button, .btn-secondary {
  font-family: inherit;
  cursor: pointer;
  border: none;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  transition: background 0.18s, transform 0.1s, opacity 0.18s;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  padding: 11px 18px;
}

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

.btn-secondary {
  background: var(--bg-hover);
  color: var(--text);
  padding: 8px 14px;
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: #283047;
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  padding: 8px 12px;
  border: 1px solid var(--border);
}

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

.btn-danger {
  background: var(--danger);
  color: #fff;
  padding: 10px 16px;
}

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

.btn-icon {
  background: var(--bg-hover);
  color: var(--text);
  width: 36px;
  height: 36px;
  border-radius: 50%;
}

.full-width {
  width: 100%;
}

/* Topbar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(11, 13, 18, 0.86);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
}

.topbar-inner {
  max-width: 1320px;
  margin: 0 auto;
  padding: 14px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

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

.brand-icon {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: linear-gradient(135deg, #3b82f6, #6366f1);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  color: #fff;
}

.brand-title {
  font-size: 17px;
  font-weight: 700;
}

.brand-sub {
  font-size: 12px;
  color: var(--text-muted);
}

.brand-sub.online {
  color: var(--success);
}

.brand-sub.offline {
  color: var(--warning);
}

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

.stats-pill {
  font-size: 13px;
  color: var(--text-muted);
  background: var(--bg-card);
  border: 1px solid var(--border);
  padding: 6px 12px;
  border-radius: 999px;
}

/* Main Container */
.container {
  max-width: 1320px;
  margin: 0 auto;
  padding: 24px 20px 60px;
}

.controls-bar {
  display: flex;
  gap: 12px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}

.search-wrap {
  flex: 1;
  min-width: 240px;
  position: relative;
}

.search-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 14px;
  opacity: 0.65;
  pointer-events: none;
}

.search-wrap input {
  width: 100%;
  padding: 11px 14px 11px 40px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text);
  font-size: 14px;
  outline: none;
}

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

.sort-wrap select {
  padding: 11px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text);
  font-size: 14px;
  outline: none;
  cursor: pointer;
}

/* Alerts & States */
.alert-error {
  background: rgba(239, 68, 68, 0.14);
  border: 1px solid rgba(239, 68, 68, 0.35);
  color: #fca5a5;
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 13px;
  margin-bottom: 16px;
}

.loading-state,
.empty-state {
  text-align: center;
  padding: 64px 20px;
  color: var(--text-muted);
}

.loading-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

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

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

.empty-icon {
  font-size: 42px;
  margin-bottom: 12px;
}

.empty-state h2 {
  color: var(--text);
  font-size: 20px;
  margin-bottom: 8px;
}

.empty-state code {
  background: var(--bg-card);
  padding: 2px 7px;
  border-radius: 6px;
  color: var(--accent);
}

/* Video Grid */
.video-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
  gap: 20px;
}

.video-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: transform 0.18s ease, border-color 0.18s ease;
}

.video-card:hover {
  transform: translateY(-3px);
  border-color: rgba(59, 130, 246, 0.45);
}

.thumb-wrap {
  position: relative;
  aspect-ratio: 16 / 9;
  background: #0d1018;
  overflow: hidden;
  cursor: pointer;
}

.thumb-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.thumb-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 36px;
  background: linear-gradient(135deg, #131826, #0d111a);
}

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

.thumb-wrap:hover .play-overlay {
  opacity: 1;
}

.play-circle {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: rgba(59, 130, 246, 0.92);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.4);
}

.duration-badge {
  position: absolute;
  right: 8px;
  bottom: 8px;
  background: rgba(0, 0, 0, 0.78);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 6px;
}

.status-badge {
  position: absolute;
  left: 8px;
  top: 8px;
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 6px;
  text-transform: uppercase;
}

.status-downloading {
  background: rgba(59, 130, 246, 0.9);
  color: #fff;
}

.status-failed {
  background: rgba(239, 68, 68, 0.9);
  color: #fff;
}

.card-body {
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex: 1;
}

.card-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  word-break: break-word;
}

.card-meta {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-muted);
  gap: 8px;
}

.progress-bar {
  width: 100%;
  height: 6px;
  background: var(--bg-elevated);
  border-radius: 999px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--accent);
  transition: width 0.3s ease;
}

.card-actions {
  display: flex;
  gap: 8px;
  margin-top: auto;
  padding-top: 4px;
}

.card-actions .btn-play {
  flex: 1;
  background: var(--bg-hover);
  color: var(--text);
  padding: 8px 10px;
  border: 1px solid var(--border);
}

.card-actions .btn-play:hover {
  background: var(--accent);
  border-color: var(--accent);
}

.card-actions .btn-dl {
  background: var(--bg-hover);
  color: var(--text-muted);
  padding: 8px 10px;
  border: 1px solid var(--border);
}

.card-actions .btn-dl:hover {
  color: var(--text);
}

.card-actions .btn-del {
  background: transparent;
  color: var(--text-muted);
  padding: 8px 10px;
  border: 1px solid var(--border);
}

.card-actions .btn-del:hover {
  color: #fca5a5;
  border-color: rgba(239, 68, 68, 0.45);
  background: rgba(239, 68, 68, 0.12);
}

/* Modals */
.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.78);
  backdrop-filter: blur(6px);
}

.modal-dialog {
  position: relative;
  z-index: 1;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  width: 100%;
}

.player-dialog {
  max-width: 960px;
  overflow: hidden;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}

.modal-title-wrap {
  min-width: 0;
}

.modal-title-wrap h2 {
  font-size: 16px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.modal-meta {
  font-size: 12px;
  color: var(--text-muted);
}

.modal-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.player-body {
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.player-body video {
  width: 100%;
  max-height: 75vh;
  outline: none;
}

.confirm-dialog {
  max-width: 420px;
  padding: 24px;
}

.confirm-dialog h2 {
  font-size: 18px;
  margin-bottom: 10px;
}

.confirm-dialog p {
  font-size: 14px;
  color: var(--text-muted);
  margin-bottom: 22px;
}

.confirm-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

@media (max-width: 600px) {
  .topbar-inner {
    padding: 12px 14px;
  }
  .container {
    padding: 16px 14px 48px;
  }
  .video-grid {
    grid-template-columns: 1fr;
  }
}
