:root {
  --bg: #0e1116;
  --panel: #161b23;
  --panel-2: #1d2430;
  --border: #262f3d;
  --text: #e6ebf2;
  --muted: #8b98ab;
  --accent: #4f9cff;
  --accent-2: #2f6fd0;
  --ok: #3fb96f;
  --warn: #e0b341;
  --err: #e0564f;
  --radius: 10px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.5;
}

header {
  padding: 28px 24px 8px;
  max-width: 860px;
  margin: 0 auto;
}
h1 { margin: 0; font-size: 26px; letter-spacing: -0.02em; }
.sub { margin: 4px 0 0; color: var(--muted); font-size: 14px; }

main { max-width: 860px; margin: 0 auto; padding: 16px 24px 60px; }

.add-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 20px;
}
#magnet {
  width: 100%;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 10px 12px;
  font-family: var(--mono);
  font-size: 13px;
}
#magnet:focus { outline: none; border-color: var(--accent); }
.add-row { display: flex; align-items: center; gap: 10px; margin-top: 12px; }

.btn {
  border: none;
  border-radius: 8px;
  padding: 8px 16px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.btn.primary { background: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-2); }
.btn.secondary {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  font-weight: 500;
}
.btn.secondary:hover { border-color: var(--accent); }
.file-btn { display: inline-flex; cursor: pointer; }

.form-msg { font-size: 13px; color: var(--muted); }
.form-msg.err { color: var(--err); }

.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}
.stat {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.stat-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}
.stat-value {
  font-family: var(--mono);
  font-size: 20px;
  font-weight: 600;
}
@media (max-width: 600px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
}

.health { margin-bottom: 20px; }
.health-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin-bottom: 8px;
}
.health-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}
.health .stat { min-width: 0; }
.health .stat-value { font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat-sub {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.meter {
  height: 4px;
  background: var(--panel-2);
  border-radius: 3px;
  overflow: hidden;
  margin: 4px 0 2px;
}
.meter-fill {
  height: 100%;
  width: 0;
  background: var(--ok);
  border-radius: 3px;
  transition: width 0.4s ease, background-color 0.4s ease;
}
.meter-fill.warn { background: var(--warn); }
.meter-fill.err { background: var(--err); }
@media (max-width: 600px) {
  .health-grid { grid-template-columns: repeat(2, 1fr); }
}

.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 14px;
}
.tab {
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
  padding: 8px 14px;
  cursor: pointer;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--text); border-bottom-color: var(--accent); }

.empty {
  text-align: center;
  color: var(--muted);
  padding: 40px 0;
  font-size: 14px;
}

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 12px;
}
.card-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.card-name { font-weight: 600; font-size: 14px; word-break: break-word; }

.badge {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 2px 8px;
  border-radius: 20px;
  white-space: nowrap;
}
.badge.loading   { background: #2a3342; color: var(--muted); }
.badge.downloading { background: #173049; color: var(--accent); }
.badge.complete  { background: #14351f; color: var(--ok); }
.badge.stopped   { background: #3a2f14; color: var(--warn); }
.badge.queued    { background: var(--panel-2); color: var(--muted); border: 1px dashed var(--border); }

.bar {
  height: 6px;
  background: var(--panel-2);
  border-radius: 4px;
  overflow: hidden;
  margin: 10px 0 8px;
}
.bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  border-radius: 4px;
  transition: width 0.4s ease;
}
.card.queued .bar-fill { background: var(--muted); opacity: 0.45; }

.group-label {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 18px 0 10px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}
.group-label::after { content: ""; flex: 1; height: 1px; background: var(--border); }

.card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
  font-size: 12px;
  color: var(--muted);
  font-family: var(--mono);
}

.file {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  padding: 5px 0;
  border-top: 1px solid var(--border);
  margin-top: 4px;
}
.file-name { color: var(--text); flex: 1; word-break: break-word; }
.file-size { color: var(--muted); font-family: var(--mono); }
.dl {
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
}
.dl:hover { text-decoration: underline; }

.remove {
  margin-top: 10px;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 12px;
  padding: 4px 12px;
  border-radius: 6px;
  cursor: pointer;
}
.remove:hover { color: var(--err); border-color: var(--err); }

.alert-bar { display: flex; align-items: center; gap: 10px; margin-top: 10px; }
.alert-toggle {
  background: var(--panel);
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 12px;
  font-size: 12px;
  cursor: pointer;
}
.alert-toggle:hover { color: var(--text, #e6e6e6); }
.alert-toggle.on { color: var(--ok); border-color: var(--ok); }
.alert-note { font-size: 12px; color: var(--muted); }

.toasts {
  position: fixed;
  top: 14px;
  right: 14px;
  z-index: 50;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(360px, calc(100vw - 28px));
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  background: var(--panel);
  border: 1px solid var(--ok);
  border-left-width: 4px;
  border-radius: var(--radius);
  padding: 10px 12px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.45);
  display: flex;
  gap: 10px;
  align-items: flex-start;
  animation: toast-in 0.2s ease-out;
}
.toast.out { opacity: 0; transform: translateX(12px); transition: opacity 0.25s, transform 0.25s; }
.toast-body { flex: 1; min-width: 0; }
.toast-title { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; color: var(--ok); }
.toast-name { font-size: 13px; word-break: break-word; margin-top: 2px; }
.toast-size { font-size: 12px; color: var(--muted); margin-top: 2px; }
.toast-x { background: none; border: 0; color: var(--muted); cursor: pointer; font-size: 16px; line-height: 1; padding: 0 2px; }
.toast-x:hover { color: var(--err); }
@keyframes toast-in { from { opacity: 0; transform: translateX(12px); } to { opacity: 1; transform: none; } }
