:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f1f3f6;
  --text: #15181d;
  --muted: #5f6773;
  --line: #e2e5ea;
  --accent: #f38020;
  --accent-ink: #ffffff;
  --ok: #1f9d55;
  --warn: #b7791f;
  --bad: #d64545;
  --info: #3b6fd8;
  --queued: #7aa2f7;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06);
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1115;
    --surface: #171a20;
    --surface-2: #1e222a;
    --text: #e8eaee;
    --muted: #9aa2ae;
    --line: #2a2f38;
    --shadow: none;
    --queued: #5b7fd6;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1115;
  --surface: #171a20;
  --surface-2: #1e222a;
  --text: #e8eaee;
  --muted: #9aa2ae;
  --line: #2a2f38;
  --shadow: none;
  --queued: #5b7fd6;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
h1, h2 { margin: 0; font-weight: 600; }
h1 { font-size: 16px; }
h2 { font-size: 14px; }
code { font-family: var(--mono); font-size: 12.5px; }
[hidden] { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.hint { color: var(--muted); font-size: 12px; margin: 0; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.between { justify-content: space-between; }
.stack { display: grid; gap: 12px; max-width: 420px; }

.top {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 14px 24px; border-bottom: 1px solid var(--line); background: var(--surface);
  position: sticky; top: 0; z-index: 5;
}
.brand { display: flex; gap: 10px; align-items: center; min-width: 0; }
.logo {
  width: 32px; height: 32px; border-radius: 8px; display: grid; place-items: center;
  background: var(--accent); color: var(--accent-ink); font-size: 18px;
}
.sub { margin: 0; color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-right { display: flex; gap: 10px; align-items: center; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.dot.on { background: var(--ok); }

main { max-width: 1280px; margin: 0 auto; padding: 20px 24px 48px; display: grid; gap: 16px; }
#dash { display: grid; gap: 16px; }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow); min-width: 0;
}
.card-head { margin-bottom: 12px; }
.card-head p { margin: 6px 0 0; }

label { display: grid; gap: 6px; font-size: 13px; font-weight: 500; }
label.check { display: flex; align-items: center; gap: 8px; font-weight: 400; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--line);
  border-radius: 8px; padding: 8px 10px; min-width: 0;
}
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}
textarea { font-family: var(--mono); font-size: 12px; resize: vertical; }
input.code { font: 600 28px/1 var(--mono); letter-spacing: 0.4em; text-align: center; padding: 12px; max-width: 260px; }
input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--accent); }

.btn {
  font: inherit; font-weight: 500; border: 1px solid var(--line); background: var(--surface);
  color: var(--text); padding: 7px 12px; border-radius: 8px; cursor: pointer;
  transition: background-color 120ms ease, border-color 120ms ease, transform 80ms ease;
}
.btn:hover:not(:disabled) { background: var(--surface-2); }
.btn:active:not(:disabled) { transform: scale(0.98); }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover:not(:disabled) { background: #e5731a; }
.btn.danger { color: var(--bad); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover:not(:disabled) { background: var(--surface-2); }
.btn.tiny { padding: 3px 8px; font-size: 12px; }
.danger-text { color: var(--bad) !important; }

.pill {
  font-size: 12px; font-weight: 600; padding: 3px 10px; border-radius: 999px;
  background: var(--surface-2); color: var(--muted); text-transform: capitalize;
}
.pill[data-s="scanning"], .pill[data-s="transferring"] { background: color-mix(in srgb, var(--info) 15%, transparent); color: var(--info); }
.pill[data-s="paused"] { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); }
.pill[data-s="needs_auth"] { background: color-mix(in srgb, var(--bad) 15%, transparent); color: var(--bad); }
.pill[data-s="idle"] { background: color-mix(in srgb, var(--ok) 14%, transparent); color: var(--ok); }

.err {
  margin: 12px 0 0; padding: 10px 12px; border-radius: 8px; font-size: 13px;
  background: color-mix(in srgb, var(--bad) 12%, transparent); color: var(--bad);
}

.controls { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; align-items: center; }
.ctl-left, .ctl-right { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.settings { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; align-items: end; }
.settings .row, .settings .hint { grid-column: 1 / -1; }

.progress-card { display: grid; gap: 12px; }
.prog-head { display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap; align-items: flex-end; }
.big { font-size: 32px; font-weight: 650; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.r2path { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; min-width: 0; }
.r2path code { background: var(--surface-2); padding: 4px 8px; border-radius: 6px; overflow-wrap: anywhere; }
.bar { height: 10px; border-radius: 999px; background: var(--surface-2); overflow: hidden; display: flex; }
.seg { height: 100%; width: 0; transition: width 400ms ease; }
.seg.done { background: var(--ok); }
.seg.queued { background: var(--queued); }
.seg.failed { background: var(--bad); }
.scan { font-size: 12.5px; color: var(--muted); }

.stats { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 12px; }
.stat {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 14px; display: grid; gap: 2px; box-shadow: var(--shadow); min-width: 0;
}
.stat .k { font-size: 12px; color: var(--muted); }
.stat .v { font-size: 20px; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat .s { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; min-height: 1.45em; }

.split { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); gap: 16px; align-items: start; }
.files .card-head input { width: min(260px, 100%); }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 10px; }
.tabs button {
  font: inherit; font-size: 12.5px; border: 1px solid transparent; background: transparent; color: var(--muted);
  padding: 4px 10px; border-radius: 999px; cursor: pointer;
}
.tabs button:hover { color: var(--text); background: var(--surface-2); }
.tabs button.on { color: var(--text); background: var(--surface-2); border-color: var(--line); font-weight: 500; }
.table-wrap { overflow: auto; max-height: 620px; border: 1px solid var(--line); border-radius: 8px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; font-weight: 500; color: var(--muted); font-size: 12px; padding: 8px 10px; background: var(--surface-2); position: sticky; top: 0; }
td { padding: 7px 10px; border-top: 1px solid var(--line); vertical-align: top; }
.c-st { width: 28px; }
.c-date { white-space: nowrap; color: var(--muted); font-variant-numeric: tabular-nums; }
.c-size { white-space: nowrap; text-align: right; font-variant-numeric: tabular-nums; }
th.c-size { text-align: right; }
.c-file { overflow-wrap: anywhere; }
.c-key a { font-family: var(--mono); font-size: 12px; color: var(--muted); text-decoration: none; white-space: nowrap; }
.c-key a:hover { color: var(--text); text-decoration: underline; }
.tag { margin-left: 6px; font-size: 11px; padding: 1px 6px; border-radius: 4px; background: var(--surface-2); color: var(--muted); }
.tag:empty { display: none; }
.errline { color: var(--bad); font-size: 12px; }
.errline:empty { display: none; }
.st {
  display: inline-grid; place-items: center; width: 18px; height: 18px; border-radius: 50%;
  font-size: 11px; font-weight: 700; background: var(--surface-2); color: var(--muted);
}
.st[data-s="done"] { background: var(--ok); color: #fff; }
.st[data-s="done"]::after { content: "✓"; }
.st[data-s="failed"] { background: var(--bad); color: #fff; }
.st[data-s="failed"]::after { content: "!"; }
.st[data-s="queued"] { background: color-mix(in srgb, var(--queued) 25%, transparent); }
.st[data-s="queued"]::after { content: ""; width: 8px; height: 8px; border-radius: 50%; border: 2px solid var(--queued); border-right-color: transparent; animation: spin 0.8s linear infinite; }
.st[data-s="skipped"]::after { content: "–"; }
.st[data-s="pending"]::after { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--muted); opacity: 0.5; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .st[data-s="queued"]::after { animation: none; }
  .seg { transition: none; }
}
.empty { text-align: center; color: var(--muted); padding: 24px; margin: 0; }
.pager { display: flex; justify-content: space-between; align-items: center; margin-top: 10px; gap: 8px; flex-wrap: wrap; }

.logs { display: flex; flex-direction: column; height: 760px; }
.log {
  list-style: none; margin: 0; padding: 8px 10px; overflow-y: auto; flex: 1; min-height: 320px;
  font: 12px/1.55 var(--mono); background: var(--surface-2); border-radius: 8px;
}
.log li { display: grid; grid-template-columns: auto 1fr; gap: 8px; }
.log time { color: var(--muted); }
.log .m { overflow-wrap: anywhere; }
.log li[data-l="ok"] .m { color: var(--ok); }
.log li[data-l="warn"] .m { color: var(--warn); }
.log li[data-l="error"] .m { color: var(--bad); }
.log li[data-l="file"] .m { color: var(--muted); }
.log.nofiles li[data-l="file"] { display: none; }

@media (max-width: 1080px) {
  .stats { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .split { grid-template-columns: minmax(0, 1fr); }
  .logs { max-height: 480px; }
}
@media (max-width: 640px) {
  .top { padding: 12px 16px; flex-wrap: wrap; }
  main { padding: 16px; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .c-date, .c-key { display: none; }
  .big { font-size: 26px; }
}
