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

:root {
  --bg:       #0f1117;
  --surface:  #1a1d27;
  --surface2: #22263a;
  --border:   #2e3248;
  --accent:   #6c63ff;
  --accent2:  #ff6584;
  --text:     #e2e4f0;
  --muted:    #7b7f9e;
  --success:  #4ade80;
  --warning:  #facc15;
  --error:    #f87171;
  --radius:   10px;
  --font: 'Inter', system-ui, sans-serif;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 14px;
  line-height: 1.5;
}

/* ── Auth ─────────────────────────────────────────────────── */
#auth-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}
.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  width: 360px;
}
.auth-card h1 { font-size: 1.4rem; margin-bottom: 1.5rem; text-align: center; }
.auth-tabs { display: flex; gap: .5rem; margin-bottom: 1.5rem; }
.auth-tab {
  flex: 1; padding: .5rem; border: none;
  background: var(--surface2); color: var(--muted);
  border-radius: var(--radius); cursor: pointer; font-size: .9rem;
  transition: .15s;
}
.auth-tab.active { background: var(--accent); color: #fff; }

/* ── App layout ───────────────────────────────────────────── */
#app { display: none; min-height: 100vh; }
.sidebar {
  position: fixed; top: 0; left: 0; bottom: 0;
  width: 220px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  padding: 1.5rem 1rem;
}
.sidebar-logo { font-size: 1.1rem; font-weight: 600; margin-bottom: 2rem; padding-left: .5rem; }
.sidebar-logo span { color: var(--accent); }
.nav-item {
  display: flex; align-items: center; gap: .7rem;
  padding: .6rem .8rem; border-radius: var(--radius);
  cursor: pointer; color: var(--muted);
  font-size: .9rem; transition: .15s; user-select: none;
}
.nav-item:hover { background: var(--surface2); color: var(--text); }
.nav-item.active { background: var(--accent); color: #fff; }
.nav-icon { font-size: 1rem; width: 20px; text-align: center; }
.sidebar-bottom { margin-top: auto; }
.user-info { padding: .6rem .8rem; font-size: .85rem; color: var(--muted); }
.user-info strong { display: block; color: var(--text); }

.main { margin-left: 220px; padding: 2rem; }
.page { display: none; }
.page.active { display: block; }
.page-title { font-size: 1.3rem; font-weight: 600; margin-bottom: 1.5rem; }

/* ── Forms & inputs ───────────────────────────────────────── */
.form-group { margin-bottom: 1rem; }
label { display: block; font-size: .85rem; color: var(--muted); margin-bottom: .3rem; }
input, select {
  width: 100%; padding: .55rem .8rem;
  background: var(--surface2); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius);
  font-size: .9rem; outline: none; transition: .15s;
}
input:focus, select:focus { border-color: var(--accent); }
select option { background: var(--surface2); }

.btn {
  padding: .55rem 1.2rem; border: none; border-radius: var(--radius);
  font-size: .9rem; cursor: pointer; transition: .15s; font-weight: 500;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: #5a52e0; }
.btn-danger { background: transparent; color: var(--error); border: 1px solid var(--error); }
.btn-danger:hover { background: var(--error); color: #fff; }
.btn-sm { padding: .3rem .7rem; font-size: .8rem; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ── Download card ────────────────────────────────────────── */
.download-form {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin-bottom: 2rem;
}
.download-form .form-row {
  display: grid;
  grid-template-columns: 1fr 140px 140px auto;
  gap: .75rem;
  align-items: flex-end;
}

.section-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 1rem;
}
.section-header h2 { font-size: 1rem; font-weight: 600; }
.badge {
  background: var(--surface2); color: var(--muted);
  padding: .2rem .6rem; border-radius: 99px; font-size: .75rem;
}

/* ── Job list ─────────────────────────────────────────────── */
.job-list { display: flex; flex-direction: column; gap: .75rem; }
.job-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1rem 1.2rem;
  display: grid; grid-template-columns: 1fr auto;
  gap: .5rem;
}
.job-url { font-size: .85rem; color: var(--muted); word-break: break-all; margin-bottom: .3rem; }
.job-meta { font-size: .78rem; color: var(--muted); display: flex; gap: 1rem; margin-top: .3rem; }
.job-meta .tag {
  background: var(--surface2); padding: .15rem .5rem;
  border-radius: 4px; color: var(--text);
}

.progress-bar-wrap {
  height: 4px; background: var(--surface2);
  border-radius: 2px; margin-top: .6rem; overflow: hidden;
}
.progress-bar {
  height: 100%; border-radius: 2px;
  background: var(--accent);
  transition: width .4s ease;
}
.progress-bar.done { background: var(--success); }
.progress-bar.error { background: var(--error); }

.status-badge {
  font-size: .75rem; padding: .2rem .6rem; border-radius: 99px;
  font-weight: 500; white-space: nowrap;
}
.status-pending  { background: #2e3248; color: var(--muted); }
.status-downloading { background: #1e2a4a; color: #60a5fa; }
.status-done     { background: #14291f; color: var(--success); }
.status-error    { background: #2a1414; color: var(--error); }

.job-actions { display: flex; gap: .4rem; align-items: flex-start; }
.speed-info { font-size: .78rem; color: var(--muted); margin-top: .3rem; }

/* ── File browser ─────────────────────────────────────────── */
.file-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1rem;
}
.file-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1rem;
  display: flex; flex-direction: column; gap: .5rem;
}
.file-icon { font-size: 2rem; }
.file-name { font-size: .82rem; word-break: break-all; }
.file-size { font-size: .75rem; color: var(--muted); }
.file-actions { display: flex; gap: .4rem; margin-top: auto; }

/* ── Admin ────────────────────────────────────────────────── */
.user-table { width: 100%; border-collapse: collapse; }
.user-table th, .user-table td {
  text-align: left; padding: .7rem 1rem;
  border-bottom: 1px solid var(--border); font-size: .88rem;
}
.user-table th { color: var(--muted); font-weight: 500; }
.role-admin { color: var(--accent); }
.role-user  { color: var(--muted); }

/* ── Toast ────────────────────────────────────────────────── */
#toast-container {
  position: fixed; bottom: 1.5rem; right: 1.5rem;
  display: flex; flex-direction: column; gap: .5rem; z-index: 999;
}
.toast {
  padding: .7rem 1.2rem; border-radius: var(--radius);
  font-size: .88rem; animation: slide-in .2s ease;
  max-width: 320px;
}
.toast-success { background: #14291f; border: 1px solid var(--success); color: var(--success); }
.toast-error   { background: #2a1414; border: 1px solid var(--error);   color: var(--error); }
.toast-info    { background: #1e2a4a; border: 1px solid #60a5fa;        color: #60a5fa; }

@keyframes slide-in {
  from { transform: translateX(30px); opacity: 0; }
  to   { transform: translateX(0);    opacity: 1; }
}

/* ── WS status dot ────────────────────────────────────────── */
.ws-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--error); display: inline-block; margin-right: .4rem;
  transition: .3s;
}
.ws-dot.connected { background: var(--success); }

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