:root {
  --bg: #f4f6fb; --panel: #ffffff; --panel2: #f8f9fc; --text: #1c2333; --muted: #6b7489; --line: #e5e8f0;
  --primary: #2f7cf6; --primary-2: #1f66d8; --primary-soft: #e8f0fe;
  --ok: #18a058; --ok-soft: #e6f6ed; --warn: #e58a00; --warn-soft: #fff4e0; --err: #e5484d; --err-soft: #fdecec;
  --side: #121826; --side-text: #c4cad8; --side-active: #1d2638;
  --radius: 12px; --shadow: 0 1px 2px rgba(16,24,40,.04), 0 2px 8px rgba(16,24,40,.05);
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #0f131b; --panel: #171c26; --panel2: #1c2230; --text: #e6e9f0; --muted: #8b93a7; --line: #262d3c;
  --primary-soft: #1a2a45; --ok-soft: #12291d; --warn-soft: #2e2410; --err-soft: #32171a;
  --side: #0b0e14; --side-active: #182030; --shadow: none;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 14px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif; background: var(--bg); color: var(--text); }
a { color: var(--primary); cursor: pointer; text-decoration: none; }
a:hover { text-decoration: underline; }
code { background: var(--panel2); border: 1px solid var(--line); padding: 0 4px; border-radius: 4px; font-size: 12px; }
h1 { font-size: 18px; margin: 0; font-weight: 600; }
h3 { font-size: 15px; margin: 0 0 12px; font-weight: 600; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.center { text-align: center; }
.r { text-align: right; }
.err { color: var(--err); min-height: 1em; }
.grow { flex: 1; }
.row { display: flex; align-items: center; }
.row.gap { gap: 8px; } .row.end { justify-content: flex-end; } .row.between { justify-content: space-between; } .row.wrap { flex-wrap: wrap; }
.pad { padding: 12px 16px; }
.ellipsis { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

input, select, textarea { font: inherit; color: inherit; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; outline: none; min-width: 0; }
input:focus, select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
input[type=checkbox], input[type=radio] { width: 16px; height: 16px; accent-color: var(--primary); margin: 0; }
label { display: flex; flex-direction: column; gap: 6px; color: var(--muted); font-size: 13px; }
label input, label select { color: var(--text); font-size: 14px; }
label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--text); cursor: pointer; }
.label-text { color: var(--muted); font-size: 13px; margin-bottom: 6px; }

.btn { font: inherit; border: 1px solid var(--line); background: var(--panel); color: var(--text); border-radius: 8px; padding: 8px 14px; cursor: pointer; white-space: nowrap; transition: .15s; }
.btn:hover { border-color: var(--primary); color: var(--primary); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-2); color: #fff; }
.btn.ghost { background: transparent; }
.btn.danger { background: var(--err); border-color: var(--err); color: #fff; }
.btn.danger-ghost { color: var(--err); }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn.block { width: 100%; }
.sep { width: 1px; height: 20px; background: var(--line); margin: 0 4px; }

/* login */
.login { min-height: 100%; display: grid; place-items: center; background: radial-gradient(1200px 600px at 20% -10%, var(--primary-soft), transparent), var(--bg); }
.login-card { width: min(380px, 92vw); background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 32px; display: flex; flex-direction: column; gap: 14px; box-shadow: 0 10px 40px rgba(16,24,40,.08); }
.login-card p { margin: 0; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; }
.brand.big { font-size: 24px; }
.logo { width: 28px; height: 28px; border-radius: 50%; background: linear-gradient(135deg, #3ea0ff, #2f6cf6); position: relative; flex: none; }
.logo::after { content: ""; position: absolute; inset: 8px 7px 7px 6px; background: #fff; clip-path: polygon(0 45%, 100% 0, 78% 100%, 50% 72%, 38% 92%, 36% 64%); }

/* layout */
.shell { display: flex; min-height: 100%; }
.side { width: 220px; background: var(--side); color: var(--side-text); display: flex; flex-direction: column; padding: 18px 12px; position: sticky; top: 0; height: 100vh; flex: none; }
.side .brand { color: #fff; padding: 0 8px 18px; }
.side nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.side nav a { color: var(--side-text); padding: 9px 12px; border-radius: 8px; display: flex; align-items: center; gap: 10px; text-decoration: none; }
.side nav a i { font-style: normal; width: 18px; text-align: center; opacity: .8; }
.side nav a:hover { background: var(--side-active); color: #fff; }
.side nav a.active { background: var(--primary); color: #fff; }
.badge { margin-left: auto; background: rgba(255,255,255,.15); border-radius: 10px; padding: 0 7px; font-size: 12px; font-weight: 500; }
.badge:empty { display: none; }
.side-foot { display: flex; flex-direction: column; gap: 10px; padding: 8px; border-top: 1px solid rgba(255,255,255,.08); }
.side-foot .btn { color: var(--side-text); border-color: rgba(255,255,255,.12); }
.speed-mini { display: flex; gap: 8px; align-items: center; color: #fff; font-size: 16px; }
main { flex: 1; min-width: 0; padding: 0 28px 40px; }
.top { display: flex; align-items: center; gap: 12px; height: 64px; position: sticky; top: 0; background: var(--bg); z-index: 5; }
.top-status { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.menu-btn { display: none; }
.page { display: none; flex-direction: column; gap: 16px; }
.page.active { display: flex; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow); }
.card.flush { padding: 0; overflow: clip; } /* clip keeps sticky table headers working */
.card.narrow { max-width: 560px; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 16px; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 16px; }
.stat .label { color: var(--muted); font-size: 13px; }
.stat .value { font-size: 24px; font-weight: 650; margin: 4px 0; }
.stat .sub { color: var(--muted); font-size: 12px; min-height: 18px; }
.steps { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 6px; }
#speedChart { width: 100%; display: block; }

.pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 20px; font-size: 12px; font-weight: 500; background: var(--panel2); color: var(--muted); border: 1px solid var(--line); white-space: nowrap; }
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill.ok { color: var(--ok); background: var(--ok-soft); border-color: transparent; }
.pill.warn { color: var(--warn); background: var(--warn-soft); border-color: transparent; }
.pill.err { color: var(--err); background: var(--err-soft); border-color: transparent; }
.pill.info { color: var(--primary); background: var(--primary-soft); border-color: transparent; }
.tag { display: inline-block; padding: 1px 8px; border-radius: 6px; font-size: 12px; background: var(--panel2); border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }

.banner { margin-bottom: 16px; padding: 12px 16px; border-radius: 10px; background: var(--warn-soft); color: var(--warn); display: flex; gap: 10px; align-items: center; }
.banner.err { background: var(--err-soft); color: var(--err); }
.banner.info { background: var(--primary-soft); color: var(--primary); }

.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.toolbar input:not([type]) , .toolbar input[type=text] { min-width: 200px; }
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-weight: 500; color: var(--muted); font-size: 12px; padding: 10px 16px; background: var(--panel2); border-bottom: 1px solid var(--line); position: sticky; top: 64px; }
.table td { padding: 10px 16px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: var(--panel2); }
.table .w1 { width: 1%; }
.table td.name { max-width: 460px; word-break: break-all; }
.table td.name .cap { color: var(--muted); font-size: 12px; display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical; overflow: hidden; }

.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px 16px; margin-bottom: 14px; }
.form-grid.inner { margin: 12px 0 0; }
.span2 { grid-column: 1 / -1; }
details summary { cursor: pointer; color: var(--primary); user-select: none; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips label { flex-direction: row; align-items: center; gap: 6px; border: 1px solid var(--line); border-radius: 20px; padding: 5px 12px; cursor: pointer; color: var(--text); font-size: 13px; }
.chips label:has(input:checked) { background: var(--primary-soft); border-color: var(--primary); color: var(--primary); }
.chips input { display: none; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; flex-wrap: wrap; }
.seg label { flex-direction: row; cursor: pointer; color: var(--text); }
.seg input { display: none; }
.seg span { padding: 8px 14px; }
.seg label:has(input:checked) span { background: var(--primary); color: #fff; }
.hint { color: var(--muted); font-size: 12px; margin: 8px 0 0; }
.hint.warn { color: var(--warn); }
.presets { display: flex; gap: 8px; align-items: center; }
.sticky-save { position: sticky; bottom: 12px; }
.settings { display: flex; flex-direction: column; gap: 16px; }
#pwForm, #page-settings .card { display: flex; flex-direction: column; gap: 12px; }
#pwForm h3, #page-settings .card h3 { margin: 0; }
#page-settings .form-grid { margin: 0; }

.tabs { display: inline-flex; background: var(--panel); border: 1px solid var(--line); border-radius: 9px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.tabs button { border: 0; background: transparent; color: var(--muted); font: inherit; padding: 5px 12px; border-radius: 6px; cursor: pointer; }
.tabs button.active { background: var(--primary); color: #fff; }
.tabs button b { font-weight: 500; opacity: .75; margin-left: 4px; }

.task-list .task { display: grid; grid-template-columns: 24px 1fr 130px 170px; gap: 14px; padding: 12px 16px; border-bottom: 1px solid var(--line); align-items: center; }
.task:hover { background: var(--panel2); }
.task .t-name { font-weight: 500; word-break: break-all; }
.task .t-meta { color: var(--muted); font-size: 12px; display: flex; gap: 10px; flex-wrap: wrap; margin-top: 2px; }
.task .t-err { color: var(--err); font-size: 12px; margin-top: 2px; word-break: break-all; }
.bar { height: 6px; background: var(--panel2); border-radius: 4px; overflow: hidden; margin-top: 8px; border: 1px solid var(--line); }
.bar i { display: block; height: 100%; background: var(--primary); border-radius: 4px; transition: width .6s; }
.bar.done i { background: var(--ok); } .bar.failed i { background: var(--err); } .bar.paused i { background: var(--muted); }
.t-speed { text-align: right; font-variant-numeric: tabular-nums; }
.t-speed b { display: block; }
.t-ops { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }
.mini-list .item { padding: 8px 0; border-bottom: 1px dashed var(--line); }
.mini-list .item:last-child { border: 0; }

.logs { font: 12px/1.6 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; height: calc(100vh - 170px); overflow: auto; margin: 0; white-space: pre-wrap; word-break: break-all; }
.logs .t { color: var(--muted); }

.qr-box { display: flex; gap: 24px; align-items: center; flex-wrap: wrap; }
.qr-box img { width: 220px; height: 220px; border-radius: 12px; border: 1px solid var(--line); background: #fff; padding: 6px; }
.qr-ph { width: 220px; height: 220px; border-radius: 12px; border: 1px dashed var(--line); display: grid; place-items: center; }
.acc-form { display: flex; flex-direction: column; gap: 12px; margin-top: 12px; }
.user-card { display: flex; gap: 16px; align-items: center; }
.avatar { width: 56px; height: 56px; border-radius: 50%; background: linear-gradient(135deg, #3ea0ff, #7b61ff); color: #fff; display: grid; place-items: center; font-size: 22px; font-weight: 600; flex: none; }

.spinner { width: 18px; height: 18px; border: 2px solid var(--line); border-top-color: var(--primary); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
#toasts { position: fixed; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 50; }
.toast { background: var(--side); color: #fff; padding: 10px 16px; border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.2); max-width: 420px; animation: pop .2s; }
.toast.err { background: var(--err); }
.toast.ok { background: var(--ok); }
@keyframes pop { from { transform: translateY(8px); opacity: 0; } }
.modal { position: fixed; inset: 0; background: rgba(5,8,14,.6); display: grid; place-items: center; z-index: 60; }
.modal-card { background: var(--panel); border-radius: 14px; padding: 22px; width: min(420px, 92vw); border: 1px solid var(--line); }

@media (max-width: 860px) {
  .side { position: fixed; left: 0; top: 0; z-index: 30; transform: translateX(-100%); transition: .2s; }
  .side.open { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.4); }
  .menu-btn { display: inline-block; }
  main { padding: 0 14px 30px; }
  .task-list .task { grid-template-columns: 24px 1fr; }
  .task .t-speed, .task .t-ops { grid-column: 2; text-align: left; justify-content: flex-start; }
  .table th:nth-child(5), .table td:nth-child(5), .table th:nth-child(6), .table td:nth-child(6) { display: none; }
  .top-status .pill:not(:first-child) { display: none; }
}

/* file manager */
.crumbs { display: flex; align-items: center; gap: 2px; flex-wrap: wrap; font-size: 14px; min-width: 200px; }
.crumbs a { padding: 3px 6px; border-radius: 6px; }
.crumbs a:hover { background: var(--primary-soft); text-decoration: none; }
.crumbs .sl { color: var(--muted); }
.fname { display: flex; align-items: center; gap: 10px; word-break: break-all; }
.fname .ico { width: 28px; height: 28px; border-radius: 7px; display: grid; place-items: center; font-size: 14px; flex: none; background: var(--panel2); border: 1px solid var(--line); }
.fname .ico.dir { background: #fff4d6; border-color: #f5dc9a; color: #c48a00; }
.fname .ico.arc { background: #efe7ff; border-color: #d9c8ff; color: #7b4dff; }
.fname .ico.vid { background: #e5f1ff; border-color: #c4ddff; color: var(--primary); }
:root[data-theme="dark"] .fname .ico.dir { background: #3a2f10; border-color: #5a4614; }
:root[data-theme="dark"] .fname .ico.arc { background: #2a2145; border-color: #3d2f66; }
:root[data-theme="dark"] .fname .ico.vid { background: #16294a; border-color: #20406e; }
.fname a { color: var(--text); font-weight: 500; }
.fname .sub { color: var(--muted); font-size: 12px; }
.row-ops { display: flex; gap: 4px; justify-content: flex-end; flex-wrap: wrap; }
.row-ops .btn { padding: 3px 8px; font-size: 12px; }
.job { padding: 10px 0; border-bottom: 1px dashed var(--line); }
.job:last-child { border: 0; }
.job .errs { color: var(--err); font-size: 12px; white-space: pre-wrap; }
.modal-card.wide { width: min(520px, 94vw); display: flex; flex-direction: column; gap: 14px; }
.modal-card h3 { margin: 0; }
.dialog-body { display: flex; flex-direction: column; gap: 12px; }
.dialog-body textarea { min-height: 80px; resize: vertical; }
