:root {
  --bg: #0d1117;
  --panel: #11161d;
  --panel-2: #161c25;
  --line: #232b37;
  --line-2: #2d3746;
  --text: #d6dde6;
  --muted: #7d8a9a;
  --accent: #5eead4;
  --accent-ink: #062a26;
  --danger: #f87171;
  --warn: #fbbf24;
  --select: rgba(94, 234, 212, .12);
  --hover: rgba(255, 255, 255, .04);
  --radius: 8px;
  --mono: "JetBrains Mono", "Cascadia Mono", "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 13px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  overflow: hidden;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--danger); min-height: 1.4em; margin: 0; }

button, .button {
  font: inherit;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line-2);
  border-radius: 6px;
  padding: 4px 10px;
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
button:hover, .button:hover { border-color: #3c4a5e; background: #1b2330; }
button:disabled { opacity: .5; cursor: default; }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
button.primary:hover { filter: brightness(1.08); }
button.danger { color: var(--danger); border-color: rgba(248, 113, 113, .4); }
button.ghost { background: transparent; border-color: transparent; }
button.ghost:hover { border-color: var(--line-2); }
button.icon { width: 28px; height: 28px; padding: 0; justify-content: center; font-size: 15px; }
button.small { padding: 1px 8px; font-size: 12px; }
input, select {
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line-2);
  border-radius: 6px;
  padding: 5px 8px;
  outline: none;
}
input:focus, select:focus { border-color: var(--accent); }
label.check { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); cursor: pointer; white-space: nowrap; }

/* Login */
.login { height: 100%; display: grid; place-items: center; background: radial-gradient(circle at 30% 20%, #132029, var(--bg) 60%); }
.login-card { width: min(360px, 92vw); display: grid; gap: 10px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 28px; box-shadow: 0 20px 60px rgba(0, 0, 0, .4); }
.login-card .brand { font-size: 20px; }
.login-card input { padding: 9px 10px; font-size: 14px; }
.login-card button { justify-content: center; padding: 8px; font-size: 14px; }
.login-card label { color: var(--muted); }

.brand { font-weight: 700; letter-spacing: .2px; display: flex; align-items: center; gap: 8px; }
.brand-mark { font-family: var(--mono); color: var(--accent); }
.host { font-weight: 400; color: var(--muted); font-family: var(--mono); font-size: 12px; }

/* App shell */
.app { height: 100%; display: flex; flex-direction: column; }
.topbar { height: 44px; flex: none; display: flex; align-items: center; gap: 16px; padding: 0 12px; border-bottom: 1px solid var(--line); background: var(--panel); }
.layout-switch { display: inline-flex; border: 1px solid var(--line-2); border-radius: 7px; overflow: hidden; margin-left: auto; }
.layout-switch button { border: 0; border-radius: 0; background: transparent; padding: 4px 12px; }
.layout-switch button + button { border-left: 1px solid var(--line-2); }
.layout-switch button.active { background: var(--select); color: var(--accent); }
.topbar-actions { display: flex; gap: 4px; }

.workspace { flex: 1; min-height: 0; display: flex; }
.pane { min-width: 0; min-height: 0; display: flex; flex-direction: column; background: var(--panel); }
.files-pane { flex: 0 0 var(--split, 46%); }
.terminal-pane { flex: 1; background: #0b0f14; }
.splitter { flex: none; width: 5px; cursor: col-resize; background: var(--line); }
.splitter:hover, .splitter.dragging { background: var(--accent); }
.workspace.layout-files .terminal-pane, .workspace.layout-files .splitter { display: none; }
.workspace.layout-files .files-pane { flex: 1; }
.workspace.layout-terminal .files-pane, .workspace.layout-terminal .splitter { display: none; }

/* Files */
.toolbar { display: flex; align-items: center; gap: 6px; padding: 8px 10px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.toolbar.actions { padding-top: 6px; padding-bottom: 6px; }
.path-form { flex: 1; min-width: 140px; display: flex; }
.path-form input { flex: 1; font-family: var(--mono); font-size: 12.5px; }
.filter { margin-left: auto; width: 140px; }
.breadcrumb { display: flex; flex-wrap: wrap; gap: 2px; padding: 4px 10px; border-bottom: 1px solid var(--line); font-family: var(--mono); font-size: 12px; color: var(--muted); }
.breadcrumb button { background: transparent; border: 0; padding: 1px 4px; color: var(--muted); font-family: var(--mono); font-size: 12px; }
.breadcrumb button:hover { color: var(--accent); background: transparent; }
.breadcrumb .sep { opacity: .5; }
.selection-bar { flex: none; display: flex; align-items: center; gap: 6px; padding: 6px 10px; background: var(--select); border-top: 1px solid var(--line); flex-wrap: wrap; }
.selection-bar span { margin-right: 6px; color: var(--accent); }

.file-list { flex: 1; overflow: auto; position: relative; outline: none; }
.file-list table { width: 100%; border-collapse: collapse; table-layout: fixed; }
.file-list thead th { position: sticky; top: 0; z-index: 1; background: var(--panel-2); text-align: left; font-weight: 500; color: var(--muted); padding: 6px 8px; border-bottom: 1px solid var(--line); cursor: pointer; user-select: none; white-space: nowrap; }
.file-list thead th.sorted { color: var(--text); }
.file-list thead th.sorted::after { content: " \25B4"; }
.file-list thead th.sorted.desc::after { content: " \25BE"; }
.file-list td { padding: 4px 8px; border-bottom: 1px solid rgba(35, 43, 55, .6); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file-list tbody tr { cursor: default; }
.file-list tbody tr:hover { background: var(--hover); }
.file-list tbody tr.selected { background: var(--select); }
.file-list tbody tr.cursor td:first-child { box-shadow: inset 2px 0 0 var(--accent); }
.col-check { width: 32px; }
.col-size { width: 84px; }
.col-mtime { width: 140px; }
.col-mode { width: 62px; }
.col-owner { width: 96px; }
td.size, td.mtime, td.mode, td.owner { color: var(--muted); font-variant-numeric: tabular-nums; font-family: var(--mono); font-size: 12px; }
td.size { text-align: right; }
.name-cell { display: flex; align-items: center; gap: 7px; min-width: 0; }
.name-cell .label { overflow: hidden; text-overflow: ellipsis; }
.name-cell .link-to { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; }
.file-icon { flex: none; width: 16px; height: 16px; }
.dir .label { color: #93c5fd; }
.link .label { font-style: italic; }
.exec .label { color: #86efac; }
.empty { padding: 40px; text-align: center; color: var(--muted); }
.drop-hint { position: absolute; inset: 8px; border: 2px dashed var(--accent); border-radius: 10px; display: grid; place-items: center; background: rgba(13, 17, 23, .85); color: var(--accent); font-size: 15px; pointer-events: none; }
.statusbar { flex: none; padding: 4px 10px; border-top: 1px solid var(--line); color: var(--muted); font-size: 12px; display: flex; gap: 14px; }

/* Terminals */
.tabs { display: flex; align-items: center; gap: 4px; padding: 6px 8px; border-bottom: 1px solid var(--line); background: var(--panel); }
.tab-list { display: flex; gap: 4px; overflow-x: auto; flex: 1; scrollbar-width: thin; }
.tab { display: inline-flex; align-items: center; gap: 6px; padding: 3px 6px 3px 10px; border: 1px solid var(--line-2); border-radius: 6px; background: transparent; color: var(--muted); cursor: pointer; max-width: 220px; flex: none; }
.tab.active { color: var(--text); background: var(--panel-2); border-color: #3c4a5e; }
.tab .tab-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: var(--mono); font-size: 12px; }
.tab .tab-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); flex: none; }
.tab.offline .tab-dot { background: var(--warn); }
.tab.ended .tab-dot { background: var(--muted); }
.tab .tab-close { border: 0; background: transparent; padding: 0 4px; color: var(--muted); font-size: 14px; line-height: 1; }
.tab .tab-close:hover { color: var(--danger); background: transparent; }
.terminals { flex: 1; min-height: 0; position: relative; }
.terminal-view { position: absolute; inset: 0; padding: 6px 0 0 8px; display: none; }
.terminal-view.active { display: block; }
.terminal-view .notice { position: absolute; right: 14px; top: 10px; z-index: 5; background: var(--panel-2); border: 1px solid var(--line-2); border-radius: 6px; padding: 6px 10px; display: flex; gap: 8px; align-items: center; }
.terminals .empty { position: absolute; inset: 0; display: grid; place-items: center; }

/* Overlays */
.overlay { position: fixed; inset: 0; z-index: 20; display: flex; flex-direction: column; background: var(--bg); }
.editor-bar { display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-bottom: 1px solid var(--line); background: var(--panel); flex-wrap: wrap; }
.editor-path { font-family: var(--mono); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; min-width: 120px; }
.editor-state { color: var(--warn); font-size: 12px; }
.editor-state.saved { color: var(--accent); }
.editor-body { flex: 1; min-height: 0; }
.preview-body { flex: 1; min-height: 0; display: grid; place-items: center; overflow: auto; padding: 16px; }
.preview-body img, .preview-body video { max-width: 100%; max-height: 100%; object-fit: contain; }

dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line-2); border-radius: 12px; padding: 20px; width: min(460px, 94vw); box-shadow: 0 20px 60px rgba(0, 0, 0, .5); }
dialog.wide { width: min(860px, 96vw); max-height: 90vh; }
dialog::backdrop { background: rgba(0, 0, 0, .55); }
dialog h3 { margin: 0 0 10px; font-size: 15px; }
dialog h4 { margin: 18px 0 8px; font-size: 13px; color: var(--muted); font-weight: 500; display: flex; align-items: center; gap: 8px; }
dialog input { width: 100%; font-family: var(--mono); margin: 6px 0 2px; }
.dialog-message { color: var(--muted); white-space: pre-wrap; word-break: break-all; max-height: 40vh; overflow: auto; }
.dialog-buttons { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; flex-wrap: wrap; }
.settings-head { display: flex; align-items: center; justify-content: space-between; }
.settings-head h3 { margin: 0; }
.password-form { display: grid; gap: 6px; max-width: 360px; }
.password-form input { margin: 0; }
.password-form button { justify-self: start; }
.password-form p { margin: 0; font-size: 12px; }
.audit { max-height: 42vh; overflow: auto; border: 1px solid var(--line); border-radius: 8px; }
.audit table { width: 100%; border-collapse: collapse; font-family: var(--mono); font-size: 12px; }
.audit td { padding: 4px 8px; border-bottom: 1px solid var(--line); vertical-align: top; word-break: break-all; }
.audit td:first-child { white-space: nowrap; color: var(--muted); }
.audit .bad { color: var(--danger); }

.menu { position: fixed; z-index: 30; min-width: 170px; background: var(--panel-2); border: 1px solid var(--line-2); border-radius: 8px; padding: 4px; box-shadow: 0 12px 40px rgba(0, 0, 0, .5); }
.menu button { width: 100%; justify-content: flex-start; border: 0; background: transparent; padding: 6px 10px; }
.menu button:hover { background: var(--select); }
.menu button.danger:hover { background: rgba(248, 113, 113, .12); }
.menu hr { border: 0; border-top: 1px solid var(--line-2); margin: 4px 2px; }

.uploads { position: fixed; right: 14px; bottom: 14px; z-index: 15; width: min(380px, 92vw); max-height: 50vh; overflow: auto; background: var(--panel-2); border: 1px solid var(--line-2); border-radius: 10px; box-shadow: 0 12px 40px rgba(0, 0, 0, .5); }
.uploads-head { display: flex; justify-content: space-between; align-items: center; padding: 8px 10px; border-bottom: 1px solid var(--line-2); }
.upload-item { padding: 6px 10px; border-bottom: 1px solid var(--line); font-size: 12px; }
.upload-item .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: var(--mono); }
.upload-item .bar { height: 4px; background: var(--line); border-radius: 2px; margin-top: 4px; overflow: hidden; }
.upload-item .bar div { height: 100%; background: var(--accent); width: 0; transition: width .15s; }
.upload-item.failed .bar div { background: var(--danger); }
.upload-item .meta { color: var(--muted); }

.toasts { position: fixed; left: 50%; bottom: 18px; transform: translateX(-50%); z-index: 40; display: grid; gap: 8px; justify-items: center; pointer-events: none; }
.toast { background: var(--panel-2); border: 1px solid var(--line-2); border-radius: 8px; padding: 8px 14px; box-shadow: 0 10px 30px rgba(0, 0, 0, .4); max-width: 80vw; word-break: break-all; }
.toast.error { border-color: rgba(248, 113, 113, .5); color: #fecaca; }
.toast.ok { border-color: rgba(94, 234, 212, .4); }

@media (max-width: 860px) {
  .workspace.layout-split { flex-direction: column; }
  .workspace.layout-split .files-pane { flex: 0 0 var(--split-v, 50%); }
  .workspace.layout-split .splitter { width: auto; height: 5px; cursor: row-resize; }
  .col-mtime, .col-mode, .col-owner, td.mtime, td.mode, td.owner { display: none; }
  .topbar { gap: 8px; }
  .host { display: none; }
}
