/* ============ 设计变量 ============ */
:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --line: #e6e8ec;
  --line-strong: #d5d8de;
  --text: #1c2230;
  --text-2: #4c5567;
  --muted: #8b93a5;
  --accent: #4f46e5;
  --accent-600: #4338ca;
  --accent-soft: #eef0ff;
  --green: #10b981;
  --red: #e5484d;
  --amber: #f59e0b;
  --term-bg: #0f1219;
  --radius: 12px;
  --shadow-sm: 0 1px 2px rgba(19, 24, 38, .05);
  --shadow-md: 0 8px 24px rgba(19, 24, 38, .09);
  --shadow-lg: 0 24px 60px rgba(19, 24, 38, .18);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", sans-serif;
  --mono: "JetBrains Mono", "Cascadia Mono", "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

.hidden { display: none !important; }

/* ============ 启动占位 ============ */
.boot {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: var(--bg);
  z-index: 90;
}
.boot-logo svg { animation: pulse 1.6s ease-in-out infinite; border-radius: 10px; }
.boot-text { color: var(--muted); font-size: 13px; }
@keyframes pulse {
  0%, 100% { opacity: .55; transform: scale(.97); }
  50% { opacity: 1; transform: scale(1); }
}

/* ============ 登录页 ============ */
.auth-view {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(900px 480px at 15% -10%, #e6e9ff 0%, rgba(230, 233, 255, 0) 60%),
    radial-gradient(700px 420px at 110% 110%, #e2f6f0 0%, rgba(226, 246, 240, 0) 55%),
    var(--bg);
  z-index: 80;
  overflow: auto;
}

.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 32px 30px 26px;
  box-shadow: var(--shadow-md);
  animation: rise .35s ease-out;
}
@keyframes rise {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}

.brand { display: flex; align-items: center; gap: 12px; margin-bottom: 26px; }
.brand svg { border-radius: 9px; }
.brand h1 { font-size: 17px; margin: 0; letter-spacing: .2px; }
.brand p { margin: 2px 0 0; font-size: 12px; color: var(--muted); }

.auth-card h2 { font-size: 19px; margin: 0 0 6px; }
.auth-sub { margin: 0 0 22px; font-size: 13px; color: var(--muted); line-height: 1.6; }

/* ============ 表单元素 ============ */
.field { display: block; margin-bottom: 14px; }
.field > span {
  display: flex;
  align-items: baseline;
  gap: 6px;
  font-size: 12.5px;
  color: var(--text-2);
  font-weight: 500;
  margin-bottom: 6px;
}
.field > span em {
  font-style: normal;
  font-weight: 400;
  font-size: 11.5px;
  color: var(--muted);
}
.field input,
.field select,
.field textarea {
  width: 100%;
  font-family: inherit;
  font-size: 13.5px;
  color: var(--text);
  background: #fff;
  border: 1px solid var(--line-strong);
  border-radius: 9px;
  padding: 9px 11px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.field textarea { resize: vertical; font-family: var(--mono); font-size: 12px; line-height: 1.5; }
.field input::placeholder,
.field textarea::placeholder { color: #b3b9c7; }
.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, .12);
}
.field-tip {
  display: block;
  font-style: normal;
  font-size: 11.5px;
  color: var(--muted);
  margin-top: 5px;
}

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-2);
  margin: 4px 0 6px;
  cursor: pointer;
  user-select: none;
}
.check input { width: 15px; height: 15px; accent-color: var(--accent); cursor: pointer; }

.form-error {
  color: var(--red);
  font-size: 12.5px;
  margin: 10px 0 0;
  min-height: 0;
  line-height: 1.5;
}
.form-error:empty { display: none; }

/* ============ 按钮 ============ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 36px;
  padding: 0 14px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  background: #fff;
  border: 1px solid var(--line-strong);
  border-radius: 9px;
  cursor: pointer;
  transition: background .15s, border-color .15s, color .15s, transform .06s, box-shadow .15s;
  white-space: nowrap;
}
.btn:hover { background: #fafbfc; border-color: #c6cad4; }
.btn:active { transform: translateY(.5px); }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }

.btn.primary {
  color: #fff;
  background: var(--accent);
  border-color: var(--accent);
  box-shadow: 0 1px 2px rgba(79, 70, 229, .25);
}
.btn.primary:hover { background: var(--accent-600); border-color: var(--accent-600); }

.btn.ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn.ghost:hover { background: #eef0f4; color: var(--text); }

.btn.danger-ghost { background: transparent; border-color: transparent; color: var(--red); }
.btn.danger-ghost:hover { background: #fdecec; }

.btn.sm { height: 30px; padding: 0 10px; font-size: 12.5px; border-radius: 8px; }
.btn.tiny { height: 28px; padding: 0 9px; font-size: 12px; border-radius: 7px; }
.btn.block { width: 100%; height: 40px; margin-top: 8px; font-size: 14px; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: background .15s, color .15s;
  flex: none;
}
.icon-btn:hover { background: #eef0f4; color: var(--text); }
.icon-btn.danger:hover { background: #fdecec; color: var(--red); }

/* ============ 主框架 ============ */
.app { display: flex; flex-direction: column; height: 100vh; }

.topbar {
  height: 54px;
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.brand-sm { display: flex; align-items: center; gap: 9px; font-weight: 600; font-size: 14px; letter-spacing: .2px; }
.brand-sm svg { border-radius: 6px; }
.topbar-right { display: flex; align-items: center; gap: 6px; }

.user-chip {
  font-size: 12.5px;
  color: var(--text-2);
  background: #f2f3f6;
  border-radius: 20px;
  padding: 5px 11px;
  margin-right: 4px;
}

.workspace { flex: 1; display: flex; min-height: 0; }

/* ============ 侧边栏 ============ */
.sidebar {
  width: 306px;
  flex: none;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-right: 1px solid var(--line);
  min-height: 0;
}

.side-tabs {
  display: flex;
  gap: 4px;
  padding: 10px 12px 0;
}
.side-tab {
  flex: 1;
  height: 32px;
  border: none;
  background: transparent;
  color: var(--muted);
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  border-radius: 8px;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.side-tab:hover { color: var(--text); background: #f5f6f8; }
.side-tab.active { color: var(--accent); background: var(--accent-soft); }

.side-body { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.tab-panel { display: flex; flex-direction: column; min-height: 0; flex: 1; }

.side-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 14px 8px;
}
.side-title { font-size: 12px; font-weight: 600; color: var(--muted); letter-spacing: .4px; text-transform: uppercase; }

.search-wrap { padding: 0 14px 8px; }
.search {
  width: 100%;
  font-family: inherit;
  font-size: 13px;
  padding: 7px 10px;
  border: 1px solid var(--line);
  background: #f7f8fa;
  border-radius: 8px;
  outline: none;
  transition: border-color .15s, background .15s;
}
.search:focus { border-color: var(--accent); background: #fff; box-shadow: 0 0 0 3px rgba(79, 70, 229, .1); }

.host-list,
.cmd-list {
  flex: 1;
  overflow-y: auto;
  padding: 0 10px 12px;
  min-height: 0;
}

.host-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 10px;
  border-radius: 10px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background .14s, border-color .14s;
}
.host-item:hover { background: #f7f8fb; border-color: var(--line); }
.host-item.active { background: var(--accent-soft); border-color: #dcdffb; }

.host-avatar {
  width: 30px;
  height: 30px;
  flex: none;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 600;
  color: #fff;
  background: linear-gradient(140deg, #6366f1, #4f46e5);
  letter-spacing: .3px;
}

.host-main { flex: 1; min-width: 0; }
.host-name {
  font-size: 13.5px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.host-meta {
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}
.host-acts { display: flex; gap: 1px; opacity: 0; transition: opacity .15s; }
.host-item:hover .host-acts { opacity: 1; }

.cmd-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 10px;
  border-radius: 10px;
  transition: background .14s;
}
.cmd-item:hover { background: #f7f8fb; }
.cmd-main { flex: 1; min-width: 0; }
.cmd-label { font-size: 13px; font-weight: 500; }
.cmd-code {
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}
.cmd-acts { display: flex; opacity: 0; transition: opacity .15s; }
.cmd-item:hover .cmd-acts { opacity: 1; }

.empty-hint {
  padding: 8px 18px 18px;
  font-size: 12.5px;
  color: var(--muted);
  line-height: 1.65;
}

.side-foot {
  flex: none;
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 10px 14px;
  border-top: 1px solid var(--line);
  font-size: 11.5px;
  color: var(--muted);
  line-height: 1.4;
}
.side-foot svg { flex: none; color: var(--green); }

/* ============ 终端区 ============ */
.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 12px 14px 12px 14px;
  gap: 0;
}

.term-bar {
  height: 38px;
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 4px 0 6px;
  gap: 12px;
}
.term-title { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-2); min-width: 0; }
.term-title #term-title {
  font-family: var(--mono);
  font-size: 12.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #c9cedb;
  flex: none;
  transition: background .2s, box-shadow .2s;
}
.dot.connecting { background: var(--amber); box-shadow: 0 0 0 3px rgba(245, 158, 11, .15); animation: blink 1s infinite; }
.dot.online { background: var(--green); box-shadow: 0 0 0 3px rgba(16, 185, 129, .16); }
.dot.offline { background: var(--red); box-shadow: 0 0 0 3px rgba(229, 72, 77, .14); }
@keyframes blink { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }

.term-badge {
  font-size: 11px;
  color: var(--green);
  background: rgba(16, 185, 129, .1);
  border-radius: 20px;
  padding: 2px 8px;
}
.term-actions { display: flex; gap: 4px; flex: none; }

.term-wrap {
  position: relative;
  flex: 1;
  min-height: 0;
  background: var(--term-bg);
  border-radius: 13px;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  border: 1px solid #1b2230;
}

#terminal {
  position: absolute;
  inset: 0;
  padding: 12px 6px 12px 14px;
  visibility: hidden;
}
#terminal.ready { visibility: visible; }

/* xterm 细节微调 */
#terminal .xterm-viewport { background: transparent !important; }
#terminal .xterm-viewport::-webkit-scrollbar { width: 9px; }
#terminal .xterm-viewport::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, .14);
  border-radius: 8px;
}
#terminal .xterm-viewport::-webkit-scrollbar-thumb:hover { background: rgba(255, 255, 255, .26); }

/* 欢迎页 */
.welcome {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(520px 300px at 50% 0%, rgba(79, 70, 229, .22), rgba(15, 18, 25, 0) 70%),
    var(--term-bg);
  z-index: 2;
}
.welcome-inner { max-width: 420px; text-align: center; color: #cbd2e0; }
.welcome-inner h2 { color: #f2f5fb; font-size: 20px; margin: 0 0 8px; font-weight: 600; }
.welcome-inner p { margin: 0 0 20px; font-size: 13px; line-height: 1.7; color: #98a2b8; }
.welcome-actions { display: flex; gap: 10px; justify-content: center; margin-bottom: 24px; }
.welcome-actions .btn:not(.primary) {
  background: rgba(255, 255, 255, .06);
  border-color: rgba(255, 255, 255, .14);
  color: #dbe1ee;
}
.welcome-actions .btn:not(.primary):hover { background: rgba(255, 255, 255, .11); }

.welcome-tips {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  text-align: left;
}
.welcome-tips li {
  font-size: 12px;
  color: #8d97ad;
  background: rgba(255, 255, 255, .04);
  border: 1px solid rgba(255, 255, 255, .07);
  border-radius: 9px;
  padding: 8px 12px;
  line-height: 1.6;
}
.welcome-tips b { color: #d6dceb; font-weight: 600; }

/* ============ 快捷命令栏 ============ */
.quickbar {
  flex: none;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 2px 0;
  min-height: 42px;
}
.qb-label {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  color: var(--muted);
  flex: none;
}
.qb-label svg { color: var(--amber); }

.chips {
  flex: 1;
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 2px;
  scrollbar-width: thin;
}
.chips::-webkit-scrollbar { height: 5px; }
.chips::-webkit-scrollbar-thumb { background: #d7dbe3; border-radius: 4px; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 28px;
  padding: 0 11px;
  font-family: inherit;
  font-size: 12.5px;
  color: var(--text-2);
  background: var(--panel);
  border: 1px solid var(--line-strong);
  border-radius: 20px;
  cursor: pointer;
  white-space: nowrap;
  transition: all .15s;
  flex: none;
}
.chip:hover {
  color: var(--accent);
  border-color: #c7caf7;
  background: var(--accent-soft);
  transform: translateY(-1px);
}
.chip:active { transform: none; }
.chip .chip-cmd {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--muted);
  max-width: 130px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chip:hover .chip-cmd { color: #7a74e8; }

/* ============ 弹窗 ============ */
.modal {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 100;
}
.modal-mask {
  position: absolute;
  inset: 0;
  background: rgba(17, 21, 31, .38);
  backdrop-filter: blur(2px);
  animation: fade .18s ease-out;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.modal-card {
  position: relative;
  width: 100%;
  max-width: 520px;
  max-height: calc(100vh - 48px);
  overflow-y: auto;
  background: var(--panel);
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
  padding: 22px 24px 20px;
  animation: pop .2s cubic-bezier(.2, .9, .3, 1);
}
.modal-card.narrow { max-width: 400px; }
@keyframes pop {
  from { opacity: 0; transform: translateY(8px) scale(.985); }
  to { opacity: 1; transform: none; }
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.modal-head h3 { margin: 0; font-size: 16px; font-weight: 600; }

.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.confirm-body {
  margin: 0;
  font-size: 13.5px;
  line-height: 1.75;
  color: var(--text-2);
  word-break: break-word;
}
.confirm-body code {
  display: inline-block;
  font-family: var(--mono);
  font-size: 11.5px;
  background: #f3f4f7;
  border-radius: 5px;
  padding: 1px 6px;
  word-break: break-all;
}

/* ============ Toast ============ */
.toasts {
  position: fixed;
  top: 16px;
  right: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 200;
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  min-width: 210px;
  max-width: 340px;
  padding: 10px 14px;
  background: #fff;
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: 10px;
  box-shadow: var(--shadow-md);
  font-size: 13px;
  color: var(--text);
  line-height: 1.55;
  animation: slideIn .22s ease-out;
}
.toast.success { border-left-color: var(--green); }
.toast.error { border-left-color: var(--red); }
.toast.warn { border-left-color: var(--amber); }
.toast.leaving { animation: slideOut .2s ease-in forwards; }
@keyframes slideIn { from { opacity: 0; transform: translateX(16px); } to { opacity: 1; transform: none; } }
@keyframes slideOut { to { opacity: 0; transform: translateX(16px); } }

/* ============ 响应式 ============ */
@media (max-width: 860px) {
  .sidebar { width: 252px; }
  .grid-2 { grid-template-columns: 1fr; gap: 0; }
  .side-foot { display: none; }
}

@media (max-width: 680px) {
  body { overflow: auto; }
  .app { height: auto; min-height: 100vh; }
  .workspace { flex-direction: column; }
  .sidebar { width: 100%; border-right: none; border-bottom: 1px solid var(--line); max-height: 42vh; }
  .main { padding: 10px; }
  .term-wrap { min-height: 58vh; }
  .welcome-tips { display: none; }
  .topbar-right .user-chip { display: none; }
}
