:root {
  --bg: #eef1f6;
  --surface: #ffffff;
  --surface-2: #f6f8fb;
  --border: #dfe4ec;
  --text: #172033;
  --muted: #64708a;
  --accent: #4f46e5;
  --accent-soft: #eef0ff;
  --accent-text: #ffffff;
  --ok: #16a34a;
  --warn: #d97706;
  --danger: #dc2626;
  --row-hover: #f3f5fb;
  --row-sel: #e6e9ff;
  --shadow: 0 1px 2px rgb(16 24 40 / .06), 0 2px 8px rgb(16 24 40 / .05);
  --radius: 10px;
  /* file-type colours */
  --ft-folder: #f5a524; --ft-image: #a855f7; --ft-code: #3b82f6; --ft-archive: #ea7a1a;
  --ft-pdf: #e5484d; --ft-sheet: #16a34a; --ft-audio: #ec4899; --ft-video: #0ea5e9;
  --ft-text: #64748b; --ft-file: #94a3b8; --ft-link: #14b8a6;
}
:root[data-mode="dark"] {
  --bg: #0d1017;
  --surface: #151a23;
  --surface-2: #1b212c;
  --border: #283040;
  --text: #e6e9f0;
  --muted: #8b95a8;
  --accent: #818cf8;
  --accent-soft: #232845;
  --accent-text: #0d1017;
  --ok: #4ade80;
  --warn: #fbbf24;
  --danger: #f87171;
  --row-hover: #1c2230;
  --row-sel: #262d4a;
  --shadow: 0 1px 2px rgb(0 0 0 / .4);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) 230px;
  font: 13px/1.45 Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}
input, select, button { font: inherit; color: inherit; }
code { font: 12px ui-monospace, Consolas, monospace; background: var(--surface-2); padding: 1px 6px; border-radius: 4px; }

.icon { width: 16px; height: 16px; flex: none; vertical-align: middle; }
.spin { animation: spin .9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- buttons ---------- */
.btn, .icon-btn {
  display: inline-flex; align-items: center; gap: 6px;
  height: 32px; padding: 0 12px;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); cursor: pointer;
  transition: background .15s, border-color .15s, transform .1s, box-shadow .15s;
  white-space: nowrap;
}
.icon-btn { width: 32px; padding: 0; justify-content: center; }
.btn:hover:not(:disabled), .icon-btn:hover:not(:disabled) { background: var(--row-hover); border-color: var(--muted); }
.btn:active:not(:disabled), .icon-btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled, .icon-btn:disabled { opacity: .4; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.btn.primary:hover:not(:disabled) { background: var(--accent); filter: brightness(1.08); box-shadow: 0 0 0 3px var(--accent-soft); }
.btn.danger-ghost:not(:disabled) { color: var(--danger); }
.btn.danger-ghost:hover:not(:disabled) { border-color: var(--danger); background: color-mix(in srgb, var(--danger) 8%, transparent); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; font-weight: 600; }
.btn.ghost { border-style: dashed; color: var(--muted); }
.btn.ghost.has-key { border-style: solid; color: var(--ok); border-color: var(--ok); }
button.link { border: 0; background: none; color: var(--accent); cursor: pointer; font-size: 12px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- app bar ---------- */
.appbar {
  display: flex; align-items: center; gap: 16px;
  padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 8px; font-size: 16px; letter-spacing: -.01em; }
.brand b { color: var(--accent); }
.logo {
  display: grid; place-items: center; width: 30px; height: 30px; border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), #06b6d4); color: #fff;
}
.logo .icon { width: 17px; height: 17px; }
.dot { position: relative; width: 10px; height: 10px; border-radius: 50%; background: var(--muted); flex: none; }
.dot .ring { position: absolute; inset: 0; border-radius: 50%; }
@keyframes blink { 50% { opacity: .25; } }
@keyframes ripple { from { transform: scale(1); opacity: .8; } to { transform: scale(2.8); opacity: 0; } }

.latency, .uptime { display: flex; align-items: center; gap: 5px; font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.latency { padding-left: 12px; border-left: 1px solid var(--border); }
.uptime .icon { width: 13px; height: 13px; }
.bars { display: flex; align-items: flex-end; gap: 2px; height: 12px; }
.bars span { width: 3px; border-radius: 1px; background: var(--border); transition: background .3s; }
.bars span:nth-child(1) { height: 25%; } .bars span:nth-child(2) { height: 50%; }
.bars span:nth-child(3) { height: 75%; } .bars span:nth-child(4) { height: 100%; }
.latency[data-level="0"] .bars span { animation: blink 1.2s infinite; }
.latency[data-level="1"] .bars span:nth-child(-n+1) { background: var(--danger); }
.latency[data-level="2"] .bars span:nth-child(-n+3) { background: var(--warn); }
.latency[data-level="3"] .bars span { background: var(--ok); }

.activity { margin-left: auto; display: flex; align-items: center; gap: 6px; color: var(--accent); font-size: 12px; font-weight: 500; }

/* ---------- connect bar ---------- */
.connect-bar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
  padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.field {
  display: flex; align-items: center; gap: 6px; height: 32px; padding: 0 10px;
  border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2);
  color: var(--muted); transition: border-color .15s, box-shadow .15s;
}
.field:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); color: var(--accent); }
.field input, .field select { border: 0; outline: 0; background: transparent; color: var(--text); width: 130px; height: 100%; }
.field select { width: auto; cursor: pointer; }
.field option { background: var(--surface); }
.field.grow input { width: 190px; }
.field.port input { width: 56px; }
.field.filter { margin-left: auto; }
.field.filter input { width: 140px; }
.field:has(input:disabled) { opacity: .5; }
.connect-bar .check { display: flex; align-items: center; gap: 4px; font-size: 12px; color: var(--muted); }
.sep { width: 1px; height: 22px; background: var(--border); margin: 0 4px; }

/* ---------- workspace ---------- */
.workspace { display: grid; grid-template-columns: 250px minmax(0, 1fr); gap: 12px; padding: 12px 16px; min-height: 0; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.sidebar { display: flex; flex-direction: column; gap: 12px; min-height: 0; }

.dropzone {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 6px; padding: 20px; text-align: center; border: 2px dashed var(--border);
  transition: border-color .2s, background .2s, transform .2s;
}
.dropzone h3 { margin: 6px 0 0; font-size: 14px; }
.dropzone p { margin: 0 0 8px; color: var(--muted); font-size: 12px; }
.drop-icon { display: grid; place-items: center; width: 56px; height: 56px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); }
.drop-icon .icon { width: 28px; height: 28px; }
.dropzone.over { border-color: var(--accent); background: var(--accent-soft); transform: scale(1.02); }
.dropzone.over .drop-icon { animation: bob .8s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(-5px); } }
.dropzone.disabled { opacity: .55; }

.stat { display: flex; align-items: center; gap: 8px; padding: 5px 0; font-size: 12px; }
.stat span { flex: 1; color: var(--muted); }
.stat b { font-variant-numeric: tabular-nums; }
.stat.up .icon { color: var(--accent); } .stat.down .icon { color: var(--ok); }
.stat.fail .icon { color: var(--muted); }
.stat.fail.has-errors .icon, .stat.fail.has-errors b { color: var(--danger); }

/* ---------- remote browser ---------- */
.pane { display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
.browser-bar { display: flex; align-items: center; gap: 6px; padding: 10px 12px; border-bottom: 1px solid var(--border); }
.crumbs { display: flex; align-items: center; gap: 2px; min-width: 0; overflow-x: auto; scrollbar-width: none; flex: 1; }
.crumb {
  display: inline-flex; align-items: center; gap: 4px; padding: 4px 8px; border: 0; border-radius: 6px;
  background: none; cursor: pointer; white-space: nowrap; color: var(--muted);
}
.crumb:hover { background: var(--row-hover); color: var(--text); }
.crumb:last-child { color: var(--text); font-weight: 600; }
.crumbs > .icon { width: 13px; height: 13px; color: var(--border); }
.path-input { flex: 1; height: 32px; padding: 0 10px; border: 1px solid var(--accent); border-radius: 8px; background: var(--surface-2); font-family: ui-monospace, Consolas, monospace; outline: 0; }

.actions { display: flex; align-items: center; gap: 6px; padding: 8px 12px; flex-wrap: wrap; }
.chip { margin-left: auto; padding: 3px 10px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); font-size: 12px; font-weight: 600; animation: pop .2s ease-out; }
@keyframes pop { from { transform: scale(.85); opacity: 0; } }

.table-wrap { position: relative; flex: 1; overflow: auto; border-top: 1px solid var(--border); }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 6px 10px; white-space: nowrap; }
thead th {
  position: sticky; top: 0; z-index: 1; background: var(--surface-2);
  border-bottom: 1px solid var(--border); font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .04em; color: var(--muted);
}
th[data-sort] { cursor: pointer; user-select: none; }
th[data-sort]:hover { color: var(--text); }
th.sorted-asc::after { content: " ↑"; color: var(--accent); }
th.sorted-desc::after { content: " ↓"; color: var(--accent); }
th.sel, td.sel { width: 34px; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.pane tbody tr { cursor: default; user-select: none; transition: background .1s; border-bottom: 1px solid color-mix(in srgb, var(--border) 50%, transparent); }
.pane tbody tr:hover { background: var(--row-hover); }
.pane tbody tr.selected { background: var(--row-sel); }
.pane tbody tr.selected td.name { color: var(--accent); }
.pane tbody td.name { font-weight: 500; }
.pane tbody td.name .ft { margin-right: 8px; vertical-align: middle; }
.pane tbody td.muted { color: var(--muted); font-size: 12px; }
.pane tbody td.perm { font-family: ui-monospace, Consolas, monospace; font-size: 11px; color: var(--muted); }
.pane tbody tr.fresh { animation: fadein .25s ease-out both; }
@keyframes fadein { from { opacity: 0; transform: translateY(3px); } }
.pane tbody tr.dir td.name { cursor: pointer; }
input[type="checkbox"] { accent-color: var(--accent); width: 15px; height: 15px; cursor: pointer; }

.ft { width: 18px; height: 18px; }
.ft-folder { color: var(--ft-folder); fill: color-mix(in srgb, var(--ft-folder) 25%, transparent); }
.ft-image { color: var(--ft-image); } .ft-code { color: var(--ft-code); } .ft-archive { color: var(--ft-archive); }
.ft-pdf { color: var(--ft-pdf); } .ft-sheet { color: var(--ft-sheet); } .ft-audio { color: var(--ft-audio); }
.ft-video { color: var(--ft-video); } .ft-text { color: var(--ft-text); } .ft-file { color: var(--ft-file); }
.ft-link { color: var(--ft-link); }

.skeleton td { padding: 10px; }
.skeleton .bone { height: 10px; border-radius: 4px; background: linear-gradient(90deg, var(--surface-2) 25%, var(--row-hover) 50%, var(--surface-2) 75%); background-size: 200% 100%; animation: shimmer 1.2s infinite; }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

.empty-state { position: absolute; inset: 40px 0 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; color: var(--muted); pointer-events: none; }
.empty-state p { margin: 8px 0 0; font-weight: 600; color: var(--text); }
.empty-icon { display: grid; place-items: center; width: 64px; height: 64px; border-radius: 50%; background: var(--surface-2); }
.empty-icon .icon { width: 30px; height: 30px; }
.empty-state.small { position: static; flex-direction: row; padding: 24px; gap: 8px; font-size: 12px; }

.statusbar { display: flex; align-items: center; gap: 14px; padding: 6px 12px; border-top: 1px solid var(--border); background: var(--surface-2); color: var(--muted); font-size: 12px; min-height: 30px; }
.statusbar .icon { width: 13px; height: 13px; margin-right: 4px; }

/* ---------- dock (transfers + log) ---------- */
.dock { display: flex; flex-direction: column; margin: 0 16px 12px; min-height: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.tabs { display: flex; align-items: center; gap: 2px; padding: 0 8px; border-bottom: 1px solid var(--border); background: var(--surface-2); }
.tab { display: flex; align-items: center; gap: 6px; padding: 9px 12px; border: 0; border-bottom: 2px solid transparent; background: none; cursor: pointer; color: var(--muted); font-weight: 500; }
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab.pulsing .icon { animation: bob 1s ease-in-out infinite; }
.badge { min-width: 18px; padding: 0 6px; border-radius: 999px; background: var(--accent); color: var(--accent-text); font-size: 11px; font-weight: 700; text-align: center; line-height: 18px; }
.badge.err { background: var(--danger); color: #fff; animation: pop .2s ease-out; }
.spacer { flex: 1; }
.tab-panel { flex: 1; overflow: auto; }

.queue td { border-bottom: 1px solid var(--border); padding: 7px 12px; }
.q-name { max-width: 320px; }
.q-name span { display: inline-block; max-width: 280px; overflow: hidden; text-overflow: ellipsis; vertical-align: middle; }
.queue td > .icon { margin-right: 6px; vertical-align: middle; }
.q-dir { font-size: 12px; width: 110px; }
.q-dir.up { color: var(--accent); } .q-dir.down { color: var(--ok); }
.q-dir .icon { width: 14px; height: 14px; }
.q-progress { width: 40%; }
.q-progress .bar { display: inline-block; width: calc(100% - 50px); height: 8px; border-radius: 999px; background: var(--surface-2); overflow: hidden; vertical-align: middle; border: 1px solid var(--border); }
.q-progress .fill { height: 100%; width: 0; border-radius: 999px; background: var(--accent); transition: width .2s; }
.running .fill { background-image: linear-gradient(45deg, rgb(255 255 255 / .25) 25%, transparent 25%, transparent 50%, rgb(255 255 255 / .25) 50%, rgb(255 255 255 / .25) 75%, transparent 75%); background-size: 16px 16px; animation: stripes .6s linear infinite; }
.running.indeterminate .fill { width: 100% !important; opacity: .6; }
.done .fill { background: var(--ok); }
.failed .fill { background: var(--danger); }
@keyframes stripes { to { background-position: 16px 0; } }
.q-progress .pct { display: inline-block; width: 44px; text-align: right; font-size: 12px; font-variant-numeric: tabular-nums; color: var(--muted); }
.q-speed { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.q-status { font-size: 12px; max-width: 260px; overflow: hidden; text-overflow: ellipsis; }
.queued .q-status { color: var(--muted); }
.running .q-status { color: var(--accent); }
.done .q-status { color: var(--ok); }
.failed .q-status { color: var(--danger); }

.log { padding: 6px 12px; font: 12px/1.7 ui-monospace, Consolas, monospace; }
.log div { display: flex; align-items: flex-start; gap: 8px; }
.log .icon { width: 13px; height: 13px; margin-top: 3px; color: var(--muted); }
.log time { color: var(--muted); flex: none; }
.log .ok, .log .ok .icon { color: var(--ok); }
.log .err, .log .err .icon { color: var(--danger); }

/* ---------- toasts ---------- */
.toasts { position: fixed; bottom: 250px; right: 28px; z-index: 50; display: flex; flex-direction: column; gap: 8px; max-width: min(380px, calc(100vw - 32px)); }
.toast {
  display: flex; align-items: flex-start; gap: 10px; padding: 10px 14px;
  background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--accent);
  border-radius: 8px; box-shadow: 0 8px 24px rgb(0 0 0 / .14); animation: slidein .25s ease-out;
}
.toast .icon { width: 18px; height: 18px; margin-top: 1px; }
.toast-ok { border-left-color: var(--ok); } .toast-ok .icon { color: var(--ok); }
.toast-err { border-left-color: var(--danger); } .toast-err .icon { color: var(--danger); }
.toast-warn { border-left-color: var(--warn); } .toast-warn .icon { color: var(--warn); }
.toast-info .icon { color: var(--accent); }
.toast.leaving { opacity: 0; transform: translateX(20px); transition: all .3s; }
@keyframes slidein { from { opacity: 0; transform: translateY(12px); } }

/* ---------- dialog ---------- */
dialog { border: 1px solid var(--border); border-radius: 12px; background: var(--surface); color: var(--text); min-width: 360px; padding: 20px; box-shadow: 0 20px 50px rgb(0 0 0 / .25); }
dialog[open] { animation: pop .18s ease-out; }
dialog::backdrop { background: rgb(10 14 24 / .45); backdrop-filter: blur(2px); }
.dialog-head { display: flex; gap: 12px; align-items: flex-start; margin-bottom: 12px; }
#dialog-icon .icon { width: 22px; height: 22px; color: var(--accent); }
#dialog-icon.danger .icon { color: var(--danger); }
#dialog-msg { margin: 0; white-space: pre-line; }
dialog input { width: 100%; height: 34px; margin-bottom: 14px; padding: 0 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2); }
dialog menu { display: flex; justify-content: flex-end; gap: 8px; padding: 0; margin: 0; }

@media (max-width: 860px) {
  body { grid-template-rows: auto auto minmax(0, 1fr) 190px; }
  .workspace { grid-template-columns: 1fr; padding: 10px; }
  .sidebar { display: none; }
  .dock { margin: 0 10px 10px; }
  .pane .uptime { display: none; }
  .appbar, .connect-bar { padding: 8px 10px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition: none !important; }
}
