:root {
  --bg: #0b0e14;
  --bg-elev: #111622;
  --bg-card: #151c2c;
  --bg-hover: #1b2438;
  --border: #24304a;
  --border-strong: #324365;
  --text: #e6edf7;
  --text-muted: #8b9bb7;
  --primary: #4f8cff;
  --primary-hover: #679dff;
  --accent: #22c55e;
  --warn: #f59e0b;
  --danger: #ef4444;
  --radius: 10px;
  --mono: "JetBrains Mono", "Cascadia Code", "Fira Code", Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }
.muted { color: var(--text-muted); }
.small-text { font-size: 12px; margin: 0 0 8px; }
code {
  font-family: var(--mono);
  background: rgba(79, 140, 255, 0.12);
  color: #a9c7ff;
  padding: 2px 6px;
  border-radius: 5px;
  font-size: 12px;
}

/* 按钮与表单 */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  padding: 8px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: all 0.15s ease;
  white-space: nowrap;
}
.btn:hover { background: var(--bg-hover); border-color: var(--border-strong); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-accent { background: rgba(34, 197, 94, 0.14); border-color: rgba(34, 197, 94, 0.35); color: #86efac; }
.btn-accent:hover { background: rgba(34, 197, 94, 0.24); }
.btn-danger { background: rgba(239, 68, 68, 0.14); border-color: rgba(239, 68, 68, 0.35); color: #fca5a5; }
.btn-danger:hover { background: rgba(239, 68, 68, 0.26); }
.btn-ghost { background: transparent; border-color: var(--border); }
.btn-sm { padding: 6px 11px; font-size: 12px; }
.btn-xs { padding: 4px 8px; font-size: 12px; border-radius: 6px; }
.btn-block { width: 100%; }
.icon-btn {
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 6px;
  font-size: 14px;
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text); }

input, select, textarea {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font-family: inherit;
  font-size: 13px;
  outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); }

.field { display: flex; flex-direction: column; gap: 6px; }
.field span { font-size: 12px; color: var(--text-muted); }

/* 登录页 */
.login-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: radial-gradient(circle at 20% 20%, rgba(79, 140, 255, 0.15), transparent 45%),
              radial-gradient(circle at 80% 80%, rgba(34, 197, 94, 0.10), transparent 45%),
              var(--bg);
}
.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
}
.login-brand { display: flex; align-items: center; gap: 14px; margin-bottom: 24px; }
.login-brand h1 { margin: 0; font-size: 22px; }
.login-brand p { margin: 4px 0 0; font-size: 12px; }
.brand-mark {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: linear-gradient(135deg, #4f8cff, #22c55e);
  color: #fff;
  font-weight: 800;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.brand-mark.small { width: 32px; height: 32px; border-radius: 8px; font-size: 13px; }
.login-form { display: flex; flex-direction: column; gap: 14px; }
.form-error {
  padding: 9px 12px;
  border-radius: 8px;
  background: rgba(239, 68, 68, 0.14);
  border: 1px solid rgba(239, 68, 68, 0.35);
  color: #fca5a5;
  font-size: 12px;
}
.login-footnote { margin-top: 18px; text-align: center; font-size: 12px; color: var(--text-muted); }

/* 主布局 */
.app-shell {
  display: grid;
  grid-template-columns: 240px 1fr;
  height: 100vh;
  overflow: hidden;
}
.sidebar {
  background: var(--bg-elev);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 14px 12px;
  min-height: 0;
}
.sidebar-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 6px 14px;
  border-bottom: 1px solid var(--border);
}
.brand-title { font-weight: 700; font-size: 15px; }
.brand-host { font-size: 11px; color: var(--text-muted); font-family: var(--mono); }

.nav-list { display: flex; flex-direction: column; gap: 4px; margin-top: 12px; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 10px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 13px;
  text-align: left;
  transition: all 0.12s;
}
.nav-item:hover { background: var(--bg-hover); color: var(--text); }
.nav-item.active {
  background: rgba(79, 140, 255, 0.14);
  border-color: rgba(79, 140, 255, 0.35);
  color: #fff;
  font-weight: 600;
}
.nav-icon { width: 16px; text-align: center; }
.nav-pill {
  margin-left: auto;
  background: rgba(79, 140, 255, 0.2);
  color: #a9c7ff;
  padding: 1px 7px;
  border-radius: 99px;
  font-size: 11px;
}

.sidebar-section {
  margin-top: 16px;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.sidebar-section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  padding: 0 6px 6px;
}
.session-mini-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.session-mini {
  padding: 7px 9px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid transparent;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.session-mini:hover { background: var(--bg-hover); }
.session-mini.active { border-color: var(--primary); background: rgba(79, 140, 255, 0.1); }
.session-mini-top { display: flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 500; }
.session-mini-cwd { font-size: 11px; color: var(--text-muted); font-family: var(--mono); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.sidebar-footer {
  border-top: 1px solid var(--border);
  padding-top: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.user-badge { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex-shrink: 0; }
.status-dot.online { background: var(--accent); box-shadow: 0 0 8px rgba(34, 197, 94, 0.6); }
.status-dot.offline { background: #64748b; }
.status-dot.warn { background: var(--warn); }

/* 主内容区 */
.main-area {
  min-width: 0;
  min-height: 0;
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.view {
  display: none;
  flex: 1;
  min-height: 0;
  flex-direction: column;
  padding: 16px 20px;
  gap: 14px;
  overflow-y: auto;
}
.view.active { display: flex; }

.view-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.view-header h2 { margin: 0; font-size: 18px; }
.view-header p { margin: 3px 0 0; font-size: 12px; }
.header-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.inline-select { display: inline-flex; align-items: center; gap: 8px; font-size: 12px; }

/* Agent 卡片 */
.agent-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}
.agent-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: border-color 0.15s, transform 0.15s;
}
.agent-card:hover { border-color: var(--border-strong); transform: translateY(-1px); }
.agent-card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.agent-name { font-size: 15px; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.badge {
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 99px;
  border: 1px solid var(--border);
  color: var(--text-muted);
}
.badge-green { color: #86efac; border-color: rgba(34, 197, 94, 0.4); background: rgba(34, 197, 94, 0.12); }
.badge-blue { color: #93c5fd; border-color: rgba(79, 140, 255, 0.4); background: rgba(79, 140, 255, 0.12); }
.badge-warn { color: #fcd34d; border-color: rgba(245, 158, 11, 0.4); background: rgba(245, 158, 11, 0.12); }
.agent-desc { font-size: 12px; color: var(--text-muted); line-height: 1.45; min-height: 34px; }
.agent-meta { font-size: 11px; color: var(--text-muted); font-family: var(--mono); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.agent-actions { display: flex; gap: 8px; margin-top: auto; padding-top: 4px; }

/* 活跃工作区（DSH iframe + xterm） */
.workspace-panel {
  flex: 1;
  min-height: 420px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.workspace-tabs-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #0d121d;
  border-bottom: 1px solid var(--border);
  padding: 6px 10px;
  gap: 8px;
}
.workspace-tabs { display: flex; align-items: center; gap: 6px; overflow-x: auto; flex: 1; }
.ws-tab {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 10px;
  border-radius: 7px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 12px;
  white-space: nowrap;
}
.ws-tab:hover { background: var(--bg-hover); color: var(--text); }
.ws-tab.active {
  background: var(--bg-card);
  border-color: var(--border-strong);
  color: #fff;
}
.workspace-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 36px;
}
.empty-icon { font-size: 38px; color: var(--primary); margin-bottom: 8px; }
.workspace-empty h3 { margin: 4px 0 8px; }
.workspace-empty p { max-width: 560px; line-height: 1.6; }

.frame-wrap { flex: 1; display: flex; min-height: 0; }
.frame-wrap iframe { width: 100%; height: 100%; border: none; background: #0f141e; }

.terminal-wrap { flex: 1; display: flex; flex-direction: column; min-height: 0; background: #090c12; }
.xterm-container { flex: 1; min-height: 0; padding: 8px 10px; overflow: hidden; }
.terminal-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
  padding: 6px 10px;
  border-top: 1px solid var(--border);
  background: #0d121d;
}
.term-keys { display: flex; gap: 5px; flex-wrap: wrap; }
.key-btn {
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  padding: 3px 8px;
  border-radius: 6px;
  font-family: var(--mono);
  font-size: 11px;
  cursor: pointer;
}
.key-btn:hover { background: var(--bg-hover); border-color: var(--primary); }
.term-meta { display: flex; align-items: center; gap: 8px; font-size: 12px; }

/* 文件管理 */
.file-head-left { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.segmented {
  display: inline-flex;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 2px;
}
.seg-btn {
  border: none;
  background: transparent;
  color: var(--text-muted);
  padding: 5px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 12px;
}
.seg-btn.active { background: var(--primary); color: #fff; font-weight: 600; }

.breadcrumbs { display: flex; align-items: center; gap: 4px; font-family: var(--mono); font-size: 12px; flex-wrap: wrap; }
.crumb {
  border: none;
  background: transparent;
  color: #a9c7ff;
  cursor: pointer;
  padding: 2px 5px;
  border-radius: 5px;
}
.crumb:hover { background: var(--bg-hover); }
.git-badge {
  font-family: var(--mono);
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 99px;
  background: rgba(79, 140, 255, 0.14);
  border: 1px solid rgba(79, 140, 255, 0.35);
  color: #93c5fd;
}

.file-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}
.file-toolbar-left { display: flex; gap: 6px; flex-wrap: wrap; }
.search-box { display: flex; gap: 6px; align-items: center; }
.search-box input { width: 220px; padding: 6px 10px; }
.search-box select { padding: 6px 8px; }

.file-workspace {
  flex: 1;
  min-height: 440px;
  display: grid;
  grid-template-columns: 1.05fr 1fr;
  gap: 12px;
  overflow: hidden;
}
.file-workspace.drag-over { outline: 2px dashed var(--primary); outline-offset: -4px; border-radius: 12px; }
.file-list-pane, .editor-pane {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}
.file-list-pane { overflow-y: auto; }
.file-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.file-table th {
  position: sticky;
  top: 0;
  background: #0d121d;
  text-align: left;
  padding: 9px 12px;
  font-size: 11px;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  z-index: 1;
}
.file-table td {
  padding: 8px 12px;
  border-bottom: 1px solid rgba(36, 48, 74, 0.5);
  vertical-align: middle;
}
.file-table tbody tr:hover { background: var(--bg-hover); }
.file-row-name {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  color: var(--text);
  word-break: break-all;
}
.file-row-name.is-dir { color: #93c5fd; font-weight: 500; }
.col-size { width: 90px; font-family: var(--mono); font-size: 12px; color: var(--text-muted); }
.col-time { width: 145px; font-family: var(--mono); font-size: 11px; color: var(--text-muted); }
.col-ops { width: 130px; text-align: right; white-space: nowrap; }

.editor-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
  background: #0d121d;
}
.editor-title-wrap { display: flex; align-items: center; gap: 6px; min-width: 0; }
.editor-filename { font-family: var(--mono); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dirty-dot { color: var(--warn); font-size: 12px; }
.editor-actions { display: flex; gap: 6px; }
.editor-empty { flex: 1; display: flex; align-items: center; justify-content: center; padding: 24px; text-align: center; }
.code-editor {
  flex: 1;
  width: 100%;
  border: none;
  border-radius: 0;
  background: #090c12;
  color: #e2e8f0;
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.55;
  padding: 12px 14px;
  resize: none;
  tab-size: 2;
}
.image-preview { flex: 1; display: flex; align-items: center; justify-content: center; padding: 16px; overflow: auto; background: #090c12; }
.image-preview img { max-width: 100%; max-height: 100%; border-radius: 8px; }

/* 监控与面板卡片 */
.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.metric-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
}
.metric-label { font-size: 12px; color: var(--text-muted); }
.metric-val { font-size: 22px; font-weight: 700; margin: 6px 0 4px; font-family: var(--mono); }
.metric-sub { font-size: 11px; color: var(--text-muted); font-family: var(--mono); }
.progress-track { height: 6px; background: var(--bg); border-radius: 99px; overflow: hidden; margin-top: 10px; }
.progress-fill { height: 100%; background: linear-gradient(90deg, var(--primary), var(--accent)); border-radius: 99px; }

.monitor-columns { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.panel-card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.panel-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  background: #0d121d;
}
.panel-card-header h3 { margin: 0; font-size: 14px; }
.panel-card-actions { display: flex; gap: 8px; align-items: center; }
.panel-card-body { padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.kv-row { display: flex; justify-content: space-between; gap: 12px; font-size: 13px; border-bottom: 1px dashed rgba(36, 48, 74, 0.6); padding-bottom: 6px; }
.log-pre {
  margin: 0;
  padding: 12px 14px;
  background: #090c12;
  color: #cbd5e1;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.5;
  max-height: 320px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
}
.stack-form { max-width: 380px; }
.security-checklist { font-size: 13px; line-height: 1.75; color: var(--text-muted); }
.audit-table-wrap { max-height: 360px; overflow-y: auto; }

/* 弹窗 & Toast */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(5, 8, 14, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 100;
}
.modal-card {
  width: 100%;
  max-width: 780px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 14px;
  display: flex;
  flex-direction: column;
  max-height: 86vh;
}
.modal-header, .modal-footer {
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
}
.modal-footer { border-bottom: none; border-top: 1px solid var(--border); justify-content: flex-end; gap: 8px; }
.modal-body { padding: 14px 16px; display: flex; flex-direction: column; flex: 1; min-height: 0; }
.modal-editor { min-height: 360px; border: 1px solid var(--border); border-radius: 8px; }

.toast-root {
  position: fixed;
  right: 18px;
  bottom: 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 200;
}
.toast {
  padding: 10px 14px;
  border-radius: 10px;
  background: var(--bg-card);
  border: 1px solid var(--border-strong);
  color: var(--text);
  font-size: 13px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
}
.toast.ok { border-color: rgba(34, 197, 94, 0.5); }
.toast.err { border-color: rgba(239, 68, 68, 0.6); color: #fca5a5; }

/* 响应式 */
@media (max-width: 1120px) {
  .agent-grid, .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .file-workspace, .monitor-columns { grid-template-columns: 1fr; }
}
@media (max-width: 780px) {
  .app-shell { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .sidebar { border-right: none; border-bottom: 1px solid var(--border); max-height: 220px; }
  .agent-grid, .metric-grid { grid-template-columns: 1fr; }
}
