* { box-sizing: border-box; }
[hidden] { display: none !important; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

:root {
  color-scheme: dark;
  --bg: #090d13;
  --panel: #101722;
  --panel-2: #0c121c;
  --border: #1d2a3b;
  --border-strong: #2b3d55;
  --text: #e9eff7;
  --muted: #8fa1b8;
  --muted-2: #64748b;
  --accent: #5b9dff;
  --accent-strong: #2563eb;
  --green: #3ddc97;
  --green-strong: #10b981;
  --red: #ff7b7b;
  --red-strong: #ef4444;
  --yellow: #f5c451;
  --radius: 16px;
  --radius-sm: 11px;
  --shadow: 0 18px 40px rgba(0, 0, 0, .35);
}

html { min-height: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  background:
    radial-gradient(1000px 560px at 88% -12%, rgba(37, 99, 235, .20), transparent 62%),
    radial-gradient(720px 460px at -8% 104%, rgba(16, 185, 129, .10), transparent 60%),
    var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a { color: var(--accent); }
h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -.01em; }
p { margin: 0; }
.muted { color: var(--muted); }

/* ---------- Topbar ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 14px 24px;
  background: rgba(9, 13, 19, .72);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(14px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 17px;
  letter-spacing: -.01em;
}

.brand img {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  box-shadow: 0 4px 14px rgba(37, 99, 235, .35);
}

.globals {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 16px;
  font-size: 13px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.global { display: flex; align-items: center; gap: 7px; }

.stat-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}

.stat-dot.down { background: var(--accent); box-shadow: 0 0 8px rgba(91, 157, 255, .7); }
.stat-dot.up { background: var(--green); box-shadow: 0 0 8px rgba(61, 220, 151, .6); }

.global.disk {
  padding-left: 14px;
  border-left: 1px solid var(--border);
}

/* ---------- Layout ---------- */

.wrap {
  max-width: 960px;
  margin: 0 auto;
  padding: 30px 20px 90px;
}

.card {
  background: linear-gradient(180deg, var(--panel), var(--panel-2));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

/* ---------- Upload ---------- */

.upload { padding: 24px; }

.upload-head h2 { font-size: 18px; }

.upload-head p {
  margin-top: 6px;
  font-size: 13.5px;
  line-height: 1.5;
}

.upload-head strong { color: var(--text); font-weight: 600; }

.dropzone {
  position: relative;
  margin-top: 18px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 26px 18px;
  border: 1.5px dashed var(--border-strong);
  border-radius: 14px;
  background: rgba(12, 18, 28, .55);
  color: var(--muted);
  cursor: pointer;
  text-align: center;
  transition: border-color .18s, background .18s, transform .18s;
}

.dropzone:hover,
.dropzone.drag {
  border-color: var(--accent);
  background: rgba(37, 99, 235, .08);
}

.dropzone.drag { transform: scale(.995); }

.dz-icon { width: 40px; height: 40px; color: var(--accent); margin-bottom: 4px; }
.dz-title { font-size: 14.5px; color: var(--text); }
.dz-sub { font-size: 12px; color: var(--muted-2); }

.dz-file {
  margin-top: 4px;
  font-size: 12.5px;
  color: var(--green);
  font-weight: 600;
  word-break: break-all;
}

.or {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 16px 0;
  color: var(--muted-2);
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: .08em;
}

.or::before,
.or::after {
  content: "";
  height: 1px;
  flex: 1;
  background: var(--border);
}

.magnet-row { display: flex; gap: 10px; }
.magnet-row .input { flex: 1; min-width: 0; }

/* ---------- Inputs e botões ---------- */

.input {
  background: #0a111b;
  border: 1px solid var(--border-strong);
  color: var(--text);
  padding: 11px 13px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: inherit;
  outline: none;
  width: 100%;
  transition: border-color .15s, box-shadow .15s;
}

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

.input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(91, 157, 255, .16);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: #16202f;
  color: var(--text);
  font: inherit;
  font-size: 14px;
  font-weight: 550;
  line-height: 1;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: background .15s, border-color .15s, color .15s, transform .1s;
}

.btn:hover { background: #1b283b; border-color: #3a5170; }
.btn:active { transform: translateY(1px); }

.btn.primary {
  background: linear-gradient(180deg, #3579f0, #2563eb);
  border-color: #3b82f6;
  color: #fff;
  box-shadow: 0 6px 18px rgba(37, 99, 235, .35);
}

.btn.primary:hover { background: linear-gradient(180deg, #2f70e4, #1d4ed8); }
.btn.ghost { background: transparent; }
.btn.ghost:hover { background: rgba(255, 255, 255, .05); }

.btn.danger {
  color: var(--red);
  border-color: rgba(239, 68, 68, .35);
  background: rgba(239, 68, 68, .08);
}

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

.btn.danger-solid {
  background: var(--red-strong);
  border-color: var(--red-strong);
  color: #fff;
}

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

.btn.small { padding: 7px 12px; font-size: 12.5px; border-radius: 9px; }

.btn.icon {
  width: 34px;
  height: 34px;
  padding: 0;
  border-color: transparent;
  background: transparent;
  color: var(--muted);
}

.btn.icon:hover {
  color: var(--text);
  background: rgba(255, 255, 255, .06);
  border-color: var(--border);
}

.btn.icon.danger:hover {
  color: var(--red);
  background: rgba(239, 68, 68, .1);
}

.btn.icon svg { width: 17px; height: 17px; fill: currentColor; }

.btn.block { width: 100%; }

.btn:focus-visible,
.input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.btn[disabled] { opacity: .55; cursor: not-allowed; }

/* ---------- Progresso ---------- */

.progress {
  height: 9px;
  border-radius: 999px;
  background: #070c13;
  border: 1px solid rgba(255, 255, 255, .04);
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: linear-gradient(90deg, #2563eb, #60a5fa);
  transition: width .45s ease, background .3s;
}

.progress-bar.paused { background: #475569; }
.progress-bar.queued { background: #64748b; }
.progress-bar.checking { background: linear-gradient(90deg, #b45309, #fbbf24); }
.progress-bar.downloading { background: linear-gradient(90deg, #2563eb, #60a5fa); }
.progress-bar.seeding { background: linear-gradient(90deg, #059669, #34d399); }
.progress-bar.error { background: linear-gradient(90deg, #b91c1c, #f87171); }

.upload-progress { margin-top: 16px; }

.progress-bar.indeterminate {
  width: 100%;
  background-color: #2563eb;
  background-image: repeating-linear-gradient(
    45deg,
    rgba(255, 255, 255, .14) 0 10px,
    transparent 10px 20px
  );
  background-size: 40px 100%;
  animation: stripes .9s linear infinite;
}

@keyframes stripes {
  from { background-position: 0 0; }
  to { background-position: 40px 0; }
}

/* ---------- Lista de torrents ---------- */

.list-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin: 30px 4px 12px;
}

.list-head h2 { font-size: 16px; }
.list-head .muted { font-size: 12.5px; }

.torrents { display: flex; flex-direction: column; gap: 12px; }

.torrent {
  padding: 18px 20px;
  transition: border-color .2s;
}

.torrent:hover { border-color: var(--border-strong); }
.torrent.done { border-color: rgba(16, 185, 129, .25); }

.t-top {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 13px;
}

.t-title {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.t-name {
  font-size: 14.5px;
  font-weight: 600;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.badge {
  flex-shrink: 0;
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  padding: 3px 8px;
  border-radius: 999px;
  border: 1px solid transparent;
}

.badge.downloading { color: #93c5fd; background: rgba(59, 130, 246, .14); border-color: rgba(59, 130, 246, .35); }
.badge.seeding { color: #6ee7b7; background: rgba(16, 185, 129, .13); border-color: rgba(16, 185, 129, .35); }
.badge.paused { color: #cbd5e1; background: rgba(148, 163, 184, .12); border-color: rgba(148, 163, 184, .3); }
.badge.queued { color: #a5b4cb; background: rgba(100, 116, 139, .14); border-color: rgba(100, 116, 139, .35); }
.badge.checking { color: #fcd34d; background: rgba(245, 158, 11, .12); border-color: rgba(245, 158, 11, .35); }
.badge.error { color: #fca5a5; background: rgba(239, 68, 68, .14); border-color: rgba(239, 68, 68, .4); }

.t-actions { display: flex; gap: 3px; flex-shrink: 0; }

.t-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 5px 15px;
  margin-top: 11px;
  font-size: 12.5px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.t-meta .pct { color: var(--text); font-weight: 600; }
.t-meta .speed.down { color: var(--accent); }
.t-meta .speed.up { color: var(--green); }

.t-error {
  margin-top: 10px;
  padding: 8px 11px;
  border-radius: 9px;
  background: rgba(239, 68, 68, .1);
  border: 1px solid rgba(239, 68, 68, .25);
  color: #fca5a5;
  font-size: 12.5px;
}

.confirm {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
  padding: 10px 12px;
  background: rgba(239, 68, 68, .07);
  border: 1px solid rgba(239, 68, 68, .22);
  border-radius: 10px;
}

.confirm-text {
  margin-right: auto;
  font-size: 12.5px;
  color: #fca5a5;
}

.t-files { margin-top: 12px; }

.files-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.files-list {
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 320px;
  overflow: auto;
}

.file-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  background: rgba(7, 12, 19, .5);
  border: 1px solid var(--border);
  border-radius: 9px;
  font-size: 12.5px;
}

.file-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text);
}

.file-size { color: var(--muted-2); font-variant-numeric: tabular-nums; }

.files-loading {
  color: var(--muted);
  font-size: 12.5px;
  padding: 6px 2px;
}

/* ---------- Vazio, toast e login ---------- */

.empty {
  padding: 34px 20px;
  text-align: center;
  color: var(--muted);
  font-size: 13.5px;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translateX(-50%);
  z-index: 50;
  max-width: min(520px, calc(100vw - 32px));
  padding: 12px 18px;
  border-radius: 11px;
  background: #16202f;
  border: 1px solid var(--border-strong);
  box-shadow: var(--shadow);
  font-size: 13.5px;
  animation: toast-in .2s ease;
}

.toast.error {
  border-color: rgba(239, 68, 68, .5);
  color: #fecaca;
  background: #2a1215;
}

@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, 8px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

.login-body { display: grid; place-items: center; padding: 24px; }

.login-card {
  width: min(400px, 100%);
  padding: 34px 30px;
  background: linear-gradient(180deg, rgba(20, 29, 43, .9), rgba(12, 18, 28, .95));
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: var(--shadow);
}

.login-logo img {
  width: 46px;
  height: 46px;
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(37, 99, 235, .4);
}

.login-card h1 { margin-top: 16px; font-size: 22px; }
.login-card .muted { margin-top: 6px; font-size: 13px; }

.login-card form {
  margin-top: 22px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.label {
  display: block;
  margin-bottom: 7px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .06em;
}

.form-error {
  margin-top: 16px;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(239, 68, 68, .1);
  border: 1px solid rgba(239, 68, 68, .3);
  color: #fca5a5;
  font-size: 13px;
}

/* ---------- Responsivo ---------- */

@media (max-width: 640px) {
  .topbar { padding: 12px 16px; gap: 10px; flex-wrap: wrap; }

  .globals {
    order: 3;
    width: 100%;
    margin-left: 0;
    justify-content: space-between;
    gap: 10px;
  }

  .global.disk { border-left: 0; padding-left: 0; }

  .wrap { padding: 20px 14px 70px; }
  .upload { padding: 18px; }
  .magnet-row { flex-direction: column; }
  .t-meta { gap: 4px 12px; }
  .file-row { grid-template-columns: 1fr auto; }
  .file-size { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition-duration: .01ms !important;
    animation-duration: .01ms !important;
  }
}

/* ---------- Auth multiusuário ---------- */

.user-nav {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.user-chip {
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, .03);
  color: var(--muted);
  font-size: 11.5px;
  white-space: nowrap;
}

.badge.admin { color: #c4b5fd; background: rgba(139, 92, 246, .14); border-color: rgba(139, 92, 246, .35); }
.badge.operator { color: #93c5fd; background: rgba(59, 130, 246, .12); border-color: rgba(59, 130, 246, .3); }

.admin-card { padding: 20px; }
.admin-card h2 { font-size: 15px; margin-bottom: 12px; }

.admin-form {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.admin-form .input { flex: 1; min-width: 180px; }
.admin-form select.input { flex: 0 1 150px; min-width: 130px; }

.admin-hint { margin-top: 10px; font-size: 12px; }

.admin-actions {
  margin-top: 12px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.reset-inline { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.small-input { width: 190px; padding: 7px 10px; font-size: 12.5px; }
.warn-text { color: var(--yellow); }

.msg-ok {
  margin-bottom: 14px;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(16, 185, 129, .1);
  border: 1px solid rgba(16, 185, 129, .3);
  color: #6ee7b7;
  font-size: 13px;
}

.login-hint { margin-top: 16px; font-size: 11.5px; text-align: center; }
.login-hint a { color: var(--accent); }

@media (max-width: 640px) {
  .user-nav { order: 4; width: 100%; justify-content: flex-end; }
  .admin-form { flex-direction: column; align-items: stretch; }
  .admin-form .input, .admin-form select.input { width: 100%; flex: 1 1 auto; }
  .small-input { width: 100%; }
}

/* ---------- MFA ---------- */
.security-card { max-width: 460px; }
.form-ok { margin: 14px 0; padding: 10px 12px; border-radius: 10px; font-size: 13.5px; color: #a7f3d0; background: rgba(16, 185, 129, .1); border: 1px solid rgba(16, 185, 129, .3); }
.sec-title { font-size: 16px; margin: 18px 0 6px; }
.mfa-state { margin: 16px 0 14px; padding: 10px 12px; border-radius: 10px; font-size: 13.5px; font-weight: 600; }
.mfa-state.on { color: #a7f3d0; background: rgba(16, 185, 129, .1); border: 1px solid rgba(16, 185, 129, .3); }
.mfa-state.off { color: #cbd5e1; background: rgba(255, 255, 255, .04); border: 1px solid rgba(255, 255, 255, .1); }
.mfa-steps { margin: 14px 0; padding-left: 20px; font-size: 13.5px; line-height: 1.7; color: #cbd5e1; text-align: left; }
.mfa-qr { display: block; width: 200px; height: 200px; margin: 6px auto 14px; padding: 4px; background: #fff; border-radius: 12px; }
.mfa-secret { display: block; margin: 4px 0 6px; padding: 10px 12px; border-radius: 10px; background: rgba(0, 0, 0, .3); border: 1px solid rgba(255, 255, 255, .1); font-size: 13.5px; word-break: break-all; text-align: center; }
.code-input { text-align: center; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 18px; letter-spacing: .3em; }
.recovery-codes { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 12px 0 16px; padding: 14px; border-radius: 12px; background: rgba(0, 0, 0, .3); border: 1px solid rgba(255, 255, 255, .1); }
.recovery-codes code { font-size: 14px; text-align: center; }
.security-card .btn.block + .btn.block { margin-top: 10px; }
.muted.small { font-size: 12px; }
