/* File Transfer Machine operator UI.
   Dark by default: these units live in machine rooms and edit suites.
   No webfonts, no CDN -- the transfer network may have no internet at all. */
:root {
  --bg: #0e1116;
  --surface: #161b22;
  --surface-2: #1c232d;
  --border: #2a323d;
  --text: #e6edf3;
  --muted: #8b949e;
  --accent: #4493f8;
  --ok: #3fb950;
  --warn: #d29922;
  --err: #f85149;
  --purple: #a371f7;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --radius: 10px;
}
:root[data-theme="light"] {
  --bg: #f6f8fa; --surface: #fff; --surface-2: #f0f3f6; --border: #d0d7de;
  --text: #1f2328; --muted: #656d76;
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: var(--sans); font-size: 14px; line-height: 1.5;
}
.topbar {
  display: flex; justify-content: space-between; align-items: center;
  gap: 16px; padding: 12px 16px; background: var(--surface);
  border-bottom: 1px solid var(--border); flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 10px; font-size: 15px; }
.dot {
  width: 9px; height: 9px; border-radius: 50%; background: var(--err);
  box-shadow: 0 0 0 3px rgba(248,81,73,.15); transition: background .3s;
}
.dot.live { background: var(--ok); box-shadow: 0 0 0 3px rgba(63,185,80,.15); }
.role-badge {
  font-family: var(--mono); font-size: 11px; letter-spacing: .08em;
  padding: 2px 8px; border-radius: 999px; background: var(--surface-2);
  border: 1px solid var(--border); color: var(--muted); text-transform: uppercase;
}
.hostinfo { font-family: var(--mono); font-size: 12px; color: var(--muted); }
.sep { opacity: .4; margin: 0 6px; }

.tabs { display: flex; gap: 2px; padding: 0 16px; background: var(--surface);
  border-bottom: 1px solid var(--border); overflow-x: auto; }
.tab {
  background: none; border: none; border-bottom: 2px solid transparent;
  color: var(--muted); padding: 10px 14px; cursor: pointer; font-size: 13px;
  font-family: inherit; white-space: nowrap;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--text); border-bottom-color: var(--accent); }

main { padding: 16px; max-width: 1200px; margin: 0 auto; }
.panel { display: none; }
.panel.active { display: block; }

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); margin-bottom: 16px; overflow: hidden;
}
.card-head {
  display: flex; justify-content: space-between; align-items: center;
  gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.card-head h2 { margin: 0; font-size: 14px; font-weight: 600;
  display: flex; align-items: center; gap: 10px; }
.step {
  display: inline-flex; align-items: center; justify-content: center;
  width: 22px; height: 22px; border-radius: 50%; background: var(--surface-2);
  border: 1px solid var(--border); font-size: 12px; color: var(--muted);
}
.card-body { padding: 16px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.btn {
  font-family: inherit; font-size: 13px; padding: 7px 14px; cursor: pointer;
  border-radius: 6px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text); transition: .15s;
}
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { background: transparent; border-color: var(--err); color: var(--err); }
.btn.ghost { background: transparent; }
.sel {
  font-family: inherit; font-size: 13px; padding: 6px 10px; border-radius: 6px;
  background: var(--surface-2); color: var(--text); border: 1px solid var(--border);
}
.muted { color: var(--muted); }

/* ---- status hero: the thing an operator reads from across the room ---- */
.status-hero {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px; margin-bottom: 16px;
  border-left: 4px solid var(--muted);
}
.status-hero.idle        { border-left-color: var(--muted); }
.status-hero.testing,
.status-hero.preparing,
.status-hero.verifying   { border-left-color: var(--accent); }
.status-hero.transferring{ border-left-color: var(--accent); }
.status-hero.complete    { border-left-color: var(--ok); }
.status-hero.failed      { border-left-color: var(--err); }
.status-hero.cancelled   { border-left-color: var(--warn); }
.phase {
  font-size: 26px; font-weight: 650; letter-spacing: .04em; margin-bottom: 4px;
}
.phase-detail { color: var(--muted); font-size: 13px; }

.progress-wrap { margin-top: 16px; }
.progress {
  height: 10px; background: var(--surface-2); border-radius: 999px;
  overflow: hidden; border: 1px solid var(--border);
}
.bar {
  height: 100%; width: 0%; background: var(--accent);
  transition: width .6s ease; border-radius: 999px;
}
.progress-stats {
  display: flex; gap: 20px; margin-top: 10px; flex-wrap: wrap;
  font-family: var(--mono); font-size: 13px;
}
.progress-stats span:first-child { color: var(--text); font-weight: 600; }
.progress-stats span { color: var(--muted); }

/* ---- links ---- */
.links-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 12px;
}
.link-card {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 8px; padding: 12px; border-left: 3px solid var(--muted);
}
.link-card.up   { border-left-color: var(--ok); }
.link-card.down { border-left-color: var(--err); }
.link-card h3 { margin: 0 0 6px; font-size: 13px; display: flex;
  justify-content: space-between; align-items: center; }
.link-card .meta { font-family: var(--mono); font-size: 11px; color: var(--muted); }
.link-card .rate { font-family: var(--mono); font-size: 18px; margin-top: 8px; }
.pill {
  font-size: 10px; padding: 1px 7px; border-radius: 999px;
  text-transform: uppercase; letter-spacing: .05em;
}
.pill.ok   { background: rgba(63,185,80,.15);  color: var(--ok); }
.pill.err  { background: rgba(248,81,73,.15);  color: var(--err); }
.pill.warn { background: rgba(210,153,34,.15); color: var(--warn); }

/* ---- workers ---- */
.workers { display: grid; gap: 8px; margin-top: 12px; }
.worker {
  /* Fixed tracks so every row lines up: the bar is the same length on every
     link and volume row, and the free text at the end is cut short with an
     ellipsis instead of squeezing the bar. */
  display: grid; grid-template-columns: 110px minmax(140px, 1fr) 170px 110px minmax(0, 1.6fr);
  gap: 12px; align-items: center; padding: 8px 12px;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 6px; font-family: var(--mono); font-size: 12px;
}
.worker .wbar { height: 6px; background: var(--bg); border-radius: 999px; overflow: hidden; }
.worker .wbar > i { display: block; height: 100%; background: var(--accent); width: 0; }
.worker.done  .wbar > i { background: var(--ok); }
.worker.failed .wbar > i { background: var(--err); }

/* ---- tables ---- */
.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th, .tbl td {
  text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border);
}
.tbl th { color: var(--muted); font-weight: 500; font-size: 12px;
  text-transform: uppercase; letter-spacing: .04em; }
.tbl td.num, .tbl th.num { text-align: right; font-family: var(--mono); }
.tbl tbody tr:hover { background: var(--surface-2); }

/* ---- logs ---- */
.logs { max-height: 62vh; overflow-y: auto; font-family: var(--mono); font-size: 12px; }
.log-row {
  display: grid; grid-template-columns: 150px 92px 1fr; gap: 12px;
  padding: 5px 8px; border-bottom: 1px solid var(--border); align-items: start;
}
.log-row:hover { background: var(--surface-2); }
.log-row .lvl { text-transform: uppercase; font-size: 10px; letter-spacing: .05em; }
.log-row.info  .lvl { color: var(--muted); }
.log-row.warn  .lvl { color: var(--warn); }
.log-row.error .lvl { color: var(--err); }
.log-row .ts { color: var(--muted); }
.log-row .msg { white-space: pre-wrap; word-break: break-word; }

/* ---- misc ---- */
.big-num { font-family: var(--mono); font-size: 20px; }
canvas { width: 100%; display: block; }
.note {
  background: var(--surface-2); border-left: 3px solid var(--accent);
  padding: 10px 12px; border-radius: 0 6px 6px 0; margin: 10px 0; font-size: 13px;
}
.note.warn { border-left-color: var(--warn); }
.note.err  { border-left-color: var(--err); }
.note.ok   { border-left-color: var(--ok); }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 16px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-family: var(--mono); }
.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: var(--surface); border: 1px solid var(--border);
  border-left: 3px solid var(--accent); padding: 12px 18px; border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,.4); z-index: 50; max-width: 90vw;
}
.toast.err { border-left-color: var(--err); }
.toast.ok  { border-left-color: var(--ok); }
.dev-row {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 10px 12px; background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 6px; margin-bottom: 8px; flex-wrap: wrap;
}
@media (max-width: 680px) {
  .worker { grid-template-columns: 56px 1fr; }
  .log-row { grid-template-columns: 1fr; gap: 2px; }
  .hostinfo { display: none; }
}

/* ---- settings ---- */
.setting {
  display: grid; grid-template-columns: 220px 160px 1fr; gap: 14px;
  align-items: start; padding: 12px 0; border-bottom: 1px solid var(--border);
}
.setting:last-child { border-bottom: none; }
.setting .name { font-family: var(--mono); font-size: 13px; }
.setting .kind { display: inline-block; margin-top: 4px; }
.setting input {
  width: 100%; font-family: var(--mono); font-size: 13px; padding: 6px 8px;
  border-radius: 6px; background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border);
}
.setting input.changed { border-color: var(--accent); }
.setting .unit { color: var(--muted); font-size: 11px; margin-top: 4px; }
.setting .help { color: var(--muted); font-size: 12px; line-height: 1.45; }
.pill.live { background: rgba(68,147,248,.15); color: var(--accent); }
.pill.next { background: rgba(210,153,34,.15); color: var(--warn); }
.bench-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 12px; margin: 10px 0; }
.bench-leg {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px;
  padding: 12px; border-left: 3px solid var(--muted);
}
.bench-leg.slowest { border-left-color: var(--warn); }
.bench-leg h3 { margin: 0 0 6px; font-size: 12px; color: var(--muted);
  text-transform: uppercase; letter-spacing: .05em; }
.bench-leg .val { font-family: var(--mono); font-size: 22px; }
.bench-leg .sub { font-family: var(--mono); font-size: 11px; color: var(--muted); margin-top: 4px; }
.tbl tbody tr.clickable { cursor: pointer; }
.logbox {
  background: var(--bg); border: 1px solid var(--border); border-radius: 6px;
  padding: 8px 10px; font-family: var(--mono); font-size: 11px; max-height: 220px;
  overflow: auto; white-space: pre; margin: 6px 0 12px;
}
.logbox.err { border-left: 3px solid var(--err); }
@media (max-width: 760px) { .setting { grid-template-columns: 1fr; } }

/* ---- verification ---- */
.verify-panel { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--border); }
.verify-head { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; align-items: flex-start; }
.verify-head .meta { max-width: 520px; margin-top: 2px; }
.vol-table td.num, .vol-table th.num { text-align: right; }
.vol-table td.bad { color: var(--err); font-weight: 600; }

/* ---- hero: link strip and last-run summary ---- */
.hero-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; }
.link-strip { display: flex; gap: 10px; flex-wrap: wrap; font-family: var(--mono); font-size: 12px; }
.link-strip .ls { display: inline-flex; align-items: center; gap: 6px; color: var(--muted);
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; padding: 3px 10px; }
.link-strip .ls b { color: var(--text); }
.link-strip .ls i { width: 7px; height: 7px; border-radius: 50%; background: var(--err); display: inline-block; }
.link-strip .ls.up i { background: var(--ok); }
.last-run { margin-top: 16px; }
.last-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; }
.last-head code { font-family: var(--mono); font-size: 12px; }
.pill.big { font-size: 12px; padding: 3px 10px; font-weight: 600; }
.bar.ok { background: var(--ok); } .bar.err { background: var(--err); } .bar.warn { background: var(--warn); }
.err-text { color: var(--err); }

/* ---- live transfer tiles ---- */
.live-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px; margin-bottom: 14px; }
.tile { background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px;
  border-left: 3px solid var(--border); min-width: 0; }
.tile.warn { border-left-color: var(--warn); }
.tile .tl { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.tile .tv { font-family: var(--mono); font-size: 22px; margin-top: 2px; white-space: nowrap; }
.tile .tv small { font-size: 12px; color: var(--muted); }
.tile .ts { font-family: var(--mono); font-size: 11px; color: var(--muted); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.worker.stalled .wbar > i { background: var(--warn); }
.worker > span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.vol-outcome { margin-top: 4px; }
.vol-outcome code { font-size: 11px; }
.log-row.status .msg { color: var(--muted); }

/* ---- scrollable run charts ---- */
.scrollchart { overflow-x: auto; overflow-y: hidden; border: 1px solid var(--border); border-radius: 6px; background: var(--bg); padding: 4px 0; }
.scrollchart canvas { width: auto; }
.est-row { margin-top: 6px; display: flex; gap: 14px; flex-wrap: wrap; align-items: baseline; font-family: var(--mono); font-size: 12px; }
.est-row .est b { color: var(--muted); font-weight: 500; margin-right: 4px; }

/* ---- source priority ---- */
.pill.prio-high { background: rgba(68,147,248,.18); color: var(--accent); }
.pill.prio-low  { background: rgba(139,148,158,.18); color: var(--muted); }
.sel.prio { padding: 3px 6px; font-size: 12px; margin-left: 6px; }
.pill.policy { background: rgba(63,185,80,.15); color: var(--ok); }

/* hidden must win over any display rule (live tiles, picker forms) */
[hidden] { display: none !important; }

/* ---- folder picker ---- */
.btn.small { padding: 3px 9px; font-size: 12px; }
.sel-line { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 4px; }
.picker { margin-top: 8px; border: 1px solid var(--border); border-radius: 6px; background: var(--bg); padding: 8px; max-width: 760px; }
.picker-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 6px; font-size: 13px; }
.picker-tree { max-height: 320px; overflow: auto; font-size: 13px; }
.tree-row { display: flex; align-items: center; gap: 8px; padding: 3px 8px; border-bottom: 1px solid var(--border); }
.tree-row label { display: flex; align-items: center; gap: 6px; flex: 1; min-width: 0; cursor: pointer; }
.tree-name { font-family: var(--mono); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tree-exp { background: none; border: none; color: var(--muted); cursor: pointer; width: 18px; font-size: 12px; }
.tree-exp:disabled { cursor: default; opacity: .4; }

/* ---- benchmark progress ---- */
.bench-progress { background: var(--surface-2); border: 1px solid var(--border); border-left: 3px solid var(--accent);
  border-radius: 8px; padding: 10px 12px; margin: 10px 0; }
.bench-progress-head { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-bottom: 8px; font-size: 13px; }
.bench-progress .mono { font-family: var(--mono); font-size: 12px; margin-left: auto; }
.bench-steps { margin: 8px 0 0; padding-left: 20px; font-size: 12px; color: var(--muted); columns: 2; }
.bench-steps li { padding: 1px 0; }
.bench-steps li.done { color: var(--ok); }
.bench-steps li.now { color: var(--text); font-weight: 600; }
@media (max-width: 680px) { .bench-steps { columns: 1; } }

.dev-row.gone { border-left: 3px solid var(--err); opacity: .85; }

/* ---- drives card: mounted vs available ---- */
.sec-head { display: flex; justify-content: space-between; align-items: baseline; margin: 0 0 8px;
  font-size: 11px; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); }
.avail-panel { margin-top: 20px; padding: 12px; border: 1px dashed var(--border); border-radius: 8px;
  background: var(--bg); }
.avail-panel:empty { display: none; }
.avail-panel .dev-row { background: var(--surface); }

/* ---- active task pulse ---- */
@keyframes ftm-pulse { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }
.pulse { animation: ftm-pulse 1.4s ease-in-out infinite; }
@media (prefers-reduced-motion: reduce) { .pulse { animation: none; } }

.verify-line { margin-top: 10px; display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.kv dd .verify-line { margin-top: 0; font-family: var(--sans); }

/* default selection on a mounted drive: the whole drive */
.whole-drive { color: var(--purple); font-weight: 700; text-transform: uppercase; letter-spacing: .05em; font-size: 12px; }
:root[data-theme="light"] .whole-drive { color: #8250df; }

/* ---- mounted drive: what will be transferred ---- */
.dev-row.sel-whole   { border: 2px solid var(--purple); }
.dev-row.sel-folders { border: 2px solid var(--accent); }
.sel-line { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-top: 8px; }
.seg { display: inline-flex; border-radius: 6px; overflow: hidden; border: 1px solid var(--border); }
.seg-btn { font-family: inherit; font-size: 12px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .05em; padding: 6px 14px; cursor: pointer; border: none;
  background: var(--surface-2); color: var(--muted); transition: background .15s, color .15s; }
.seg-btn + .seg-btn { border-left: 1px solid var(--border); }
.seg-btn:hover:not(:disabled) { color: var(--text); }
.seg-btn:disabled { opacity: .45; cursor: not-allowed; }
.seg-btn.whole.on   { background: var(--purple); color: #fff; }
.seg-btn.folders.on { background: var(--accent); color: #fff; }
.seg-btn.whole:not(.on):hover:not(:disabled)   { box-shadow: inset 0 0 0 1px var(--purple); }
.seg-btn.folders:not(.on):hover:not(:disabled) { box-shadow: inset 0 0 0 1px var(--accent); }

/* ---- start dialog ---- */
.dlg { background: var(--surface); color: var(--text); border: 1px solid var(--border);
  border-radius: 10px; padding: 18px 20px; width: min(560px, calc(100vw - 32px)); }
.dlg::backdrop { background: rgba(0, 0, 0, .55); }
.dlg h3 { margin: 0 0 6px; font-size: 16px; }
.vopts { border: none; padding: 0; margin: 14px 0 0; display: grid; gap: 8px; }
.vopts legend { font-size: 11px; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); margin-bottom: 6px; }
.vopt { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border: 1px solid var(--border);
  border-radius: 8px; background: var(--surface-2); cursor: pointer; }
.vopt:has(input:checked) { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.vopt input { margin-top: 3px; }
.dlg-actions { justify-content: flex-end; margin-top: 16px; }

.worker > span { white-space: nowrap; }
.worker > span:last-child { overflow: hidden; text-overflow: ellipsis; min-width: 0; }
