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

:root {
  --bg:          #0f0f0f;
  --surface:     #1a1a1a;
  --surface2:    #242424;
  --border:      #333;
  --text:        #f1f1f1;
  --text-muted:  #888;
  --red:         #ff0000;
  --red-hover:   #cc0000;
  --green:       #22c55e;
  --green-hover: #16a34a;
  --radius:      12px;
  --radius-sm:   8px;
  --font:        -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

body { font-family: var(--font); background: var(--bg); color: var(--text); min-height: 100vh; }

.hidden { display: none !important; }

/* ── Screens ─────────────────────────────────────────── */
.screen { min-height: 100vh; }

/* ── Auth screen ─────────────────────────────────────── */
#auth-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: linear-gradient(135deg, #0f0f0f 0%, #1a0000 100%);
}

.auth-card {
  width: 100%;
  max-width: 400px;
}

/* ── Cards ───────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
}

/* ── Logo ────────────────────────────────────────────── */
.logo {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 28px;
}
.logo h1 {
  font-size: 1.4rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.logo.small { margin-bottom: 0; }
.logo.small span { font-size: 1.1rem; font-weight: 600; }

/* ── Auth form ───────────────────────────────────────── */
.auth-card h2 { font-size: 1.3rem; font-weight: 600; margin-bottom: 20px; }

.field-group { margin-bottom: 16px; }
.field-group label {
  display: block;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 6px;
}
.field-group input {
  width: 100%;
  padding: 10px 14px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.15s;
}
.field-group input:focus { border-color: var(--red); }
.field-group input::placeholder { color: var(--text-muted); }

.hint { font-size: 0.85rem; color: var(--text-muted); margin-bottom: 16px; }

/* ── Buttons ─────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s, opacity 0.15s;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
  background: var(--red);
  color: #fff;
}
.btn-primary:hover:not(:disabled) { background: var(--red-hover); }

.btn-success {
  background: var(--green);
  color: #fff;
  white-space: nowrap;
}
.btn-success:hover { background: var(--green-hover); }

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

.btn-sm { padding: 6px 14px; font-size: 0.85rem; }
.btn-full { width: 100%; margin-top: 8px; }

/* ── Error messages ──────────────────────────────────── */
.error-msg {
  background: rgba(220, 38, 38, 0.12);
  border: 1px solid rgba(220, 38, 38, 0.35);
  color: #fca5a5;
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 0.88rem;
  margin-bottom: 14px;
}

/* ── App header ──────────────────────────────────────── */
.app-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 10;
}
.header-inner {
  max-width: 720px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 60px;
}
.user-info {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* ── Main content ────────────────────────────────────── */
.main-content {
  max-width: 720px;
  margin: 0 auto;
  padding: 32px 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.download-card h2 { font-size: 1.3rem; font-weight: 600; margin-bottom: 6px; }
.subtitle { font-size: 0.9rem; color: var(--text-muted); margin-bottom: 24px; }

/* ── Toggle buttons ──────────────────────────────────── */
.option-row {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 16px;
}
.option-label {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-muted);
  min-width: 52px;
}
.toggle-group { display: flex; gap: 8px; }
.toggle-btn {
  padding: 7px 16px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--text-muted);
  font-size: 0.88rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}
.toggle-btn.active {
  background: var(--red);
  border-color: var(--red);
  color: #fff;
}
.toggle-btn:hover:not(.active) { border-color: #555; color: var(--text); }

/* ── Result area ─────────────────────────────────────── */
.result-area {
  display: flex;
  align-items: center;
  gap: 14px;
  background: rgba(34, 197, 94, 0.08);
  border: 1px solid rgba(34, 197, 94, 0.25);
  border-radius: var(--radius-sm);
  padding: 16px;
  margin-bottom: 12px;
}
.result-icon { font-size: 1.5rem; }
.result-title { font-weight: 600; font-size: 0.95rem; }
.result-meta { font-size: 0.82rem; color: var(--text-muted); margin-top: 2px; }
.result-area .btn-success { margin-left: auto; }

/* ── Progress ────────────────────────────────────────── */
.progress-area {
  display: flex;
  align-items: center;
  gap: 14px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 16px;
  margin-bottom: 12px;
}
.progress-title { font-weight: 600; font-size: 0.95rem; }
.progress-hint { font-size: 0.82rem; color: var(--text-muted); margin-top: 2px; }

.spinner {
  width: 28px;
  height: 28px;
  border: 3px solid var(--border);
  border-top-color: var(--red);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Info card ───────────────────────────────────────── */
.info-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 24px;
}
.info-card h3 { font-size: 0.95rem; font-weight: 600; margin-bottom: 10px; }
.info-card ul { list-style: none; display: flex; flex-direction: column; gap: 6px; }
.info-card li {
  font-size: 0.88rem;
  color: var(--text-muted);
  padding-left: 14px;
  position: relative;
}
.info-card li::before {
  content: '·';
  position: absolute;
  left: 0;
  color: var(--red);
  font-weight: 700;
}

/* ── URL row (input + preview button side by side) ──── */
.url-row { display: flex; gap: 10px; align-items: flex-end; margin-bottom: 0; }
.url-field { flex: 1; margin-bottom: 0; }
.preview-btn { white-space: nowrap; height: 40px; }

/* ── Video preview card ──────────────────────────────── */
.preview-area {
  display: flex;
  gap: 14px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  margin: 14px 0 0;
  align-items: flex-start;
}
.preview-thumb {
  width: 120px;
  height: 68px;
  object-fit: cover;
  border-radius: 6px;
  flex-shrink: 0;
  background: #333;
}
.preview-meta { flex: 1; min-width: 0; }
.preview-title {
  font-weight: 600;
  font-size: 0.9rem;
  line-height: 1.3;
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.preview-channel { font-size: 0.8rem; color: var(--text-muted); margin-bottom: 6px; }
.preview-badges { display: flex; gap: 6px; flex-wrap: wrap; }

/* ── Badges ──────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 500;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-muted);
}
.badge-red  { background: rgba(255,0,0,0.12); border-color: rgba(255,0,0,0.3); color: #ff6b6b; }
.badge-blue { background: rgba(59,130,246,0.12); border-color: rgba(59,130,246,0.3); color: #7eb4fb; }

/* ── History card ────────────────────────────────────── */
.history-card { padding: 24px; }
.history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.history-header h3 { font-size: 1rem; font-weight: 600; }

.history-loading {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text-muted);
  font-size: 0.88rem;
  padding: 12px 0;
}
.spinner-sm {
  width: 18px;
  height: 18px;
  border: 2px solid var(--border);
  border-top-color: var(--red);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  flex-shrink: 0;
}

.history-empty {
  text-align: center;
  padding: 24px 0;
  color: var(--text-muted);
  font-size: 0.88rem;
}

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

.history-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}
.history-item:last-child { border-bottom: none; }

.history-item-info { flex: 1; min-width: 0; }
.history-url {
  font-size: 0.85rem;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 4px;
}
.history-badges { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.history-date { font-size: 0.75rem; color: var(--text-muted); }
.history-error { font-size: 0.85rem; color: #fca5a5; padding: 8px 0; }

/* ── Progress bar ────────────────────────────────────── */
.progress-header { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; }
.progress-message { font-size: 0.82rem; color: var(--text-muted); }
.progress-bar-track {
  width: 100%;
  height: 6px;
  background: var(--surface2);
  border-radius: 99px;
  overflow: hidden;
  margin-bottom: 8px;
}
.progress-bar-fill {
  height: 100%;
  background: var(--red);
  border-radius: 99px;
  transition: width 0.4s ease;
}

/* ── Admin modal ─────────────────────────────────────── */
.modal-overlay { position:fixed; inset:0; background:rgba(0,0,0,.7); z-index:100; display:flex; align-items:center; justify-content:center; padding:20px; }
.modal-card { background:var(--surface); border:1px solid var(--border); border-radius:var(--radius); padding:28px; width:100%; max-width:480px; max-height:80vh; overflow-y:auto; }
.modal-header { display:flex; justify-content:space-between; align-items:center; margin-bottom:20px; }
.modal-header h3 { font-size:1.1rem; }
.modal-close { background:none; border:none; color:var(--text-muted); font-size:1.2rem; cursor:pointer; padding:4px 8px; border-radius:4px; }
.modal-close:hover { color:var(--text); background:var(--surface2); }
.modal-users-header { display:flex; justify-content:space-between; align-items:center; margin:16px 0 8px; }

/* ── Admin panel ─────────────────────────────────────── */
.admin-card { margin-top: 0; }
.admin-invite { display: flex; gap: 10px; margin-bottom: 12px; }
.admin-invite input { flex: 1; background: var(--surface2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 8px 12px; color: var(--text); font-size: 0.9rem; }
.admin-invite input:focus { outline: none; border-color: #555; }
.success-msg { font-size: 0.85rem; color: #86efac; padding: 8px 0; }
.users-list { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.user-item { display: flex; justify-content: space-between; align-items: center; padding: 10px 12px; background: var(--surface2); border-radius: var(--radius-sm); }
.user-info { display: flex; align-items: center; gap: 10px; }
.user-email { font-size: 0.9rem; }
.badge-green { background: #14532d; color: #86efac; }
.badge-yellow { background: #422006; color: #fde68a; }
.btn-danger { background: #7f1d1d; color: #fca5a5; border: none; cursor: pointer; border-radius: var(--radius-sm); padding: 6px 12px; font-size: 0.8rem; }
.btn-danger:hover { background: #991b1b; }

/* ── Responsive ──────────────────────────────────────── */
@media (max-width: 480px) {
  .card { padding: 24px 20px; }
  .main-content { padding: 20px 16px; }
  .option-row { flex-wrap: wrap; }
  .result-area { flex-wrap: wrap; }
  .result-area .btn-success { width: 100%; }
}
