:root {
  --bg: #0b0e13;
  --panel: #141a22;
  --panel2: #1b2330;
  --line: #262f3d;
  --fg: #e6edf3;
  --muted: #8b98a5;
  --brand: #3b82f6;
  --brand2: #2563eb;
  --ok: #34d399;
  --warn: #fbbf24;
  --err: #f87171;
  --radius: 12px;
  --bar-h: 46px;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; font-family: -apple-system, "Microsoft YaHei", "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--fg); -webkit-font-smoothing: antialiased; }
.hidden { display: none !important; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; border-radius: 6px; }

/* ---------------- 登录 ---------------- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px;
  background: radial-gradient(1000px 600px at 50% -10%, #16283f 0%, var(--bg) 60%); }
.login-card { background: var(--panel); padding: 34px 30px; border-radius: 16px; width: 350px;
  border: 1px solid var(--line); box-shadow: 0 24px 70px rgba(0,0,0,.55); }
.brand { font-size: 36px; font-weight: 800; letter-spacing: 3px; color: var(--brand); }
.brand-name { font-size: 15px; font-weight: 600; color: var(--fg); margin-top: 4px; letter-spacing: 1px; }
.brand-slogan { color: var(--muted); font-size: 12px; margin: 4px 0 22px; letter-spacing: .3px; }
.login-card input { width: 100%; padding: 12px 13px; margin-bottom: 12px; background: var(--panel2);
  border: 1px solid var(--line); border-radius: 10px; color: var(--fg); font-size: 14px; transition: border-color .15s; }
.login-card input:focus { outline: none; border-color: var(--brand); }
.login-card button { width: 100%; padding: 12px; background: var(--brand); color: #fff; border: 0;
  border-radius: 10px; font-size: 15px; font-weight: 600; cursor: pointer; transition: background .15s; }
.login-card button:hover { background: var(--brand2); }
.login-card button:active { transform: translateY(1px); }
.err { color: var(--err); font-size: 13px; min-height: 18px; margin-top: 6px; }
.hint { color: var(--muted); font-size: 11px; margin-top: 14px; line-height: 1.6; }

/* ---------------- 主布局 ---------------- */
.app { display: flex; min-height: 100vh; }
.sidebar { width: 216px; background: var(--panel); border-right: 1px solid var(--line);
  padding: 20px 0; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.logo { font-size: 24px; font-weight: 800; letter-spacing: 2px; color: var(--brand); padding: 0 20px 16px; display: flex; align-items: baseline; gap: 8px; }
.logo-sub { font-size: 11px; font-weight: 500; letter-spacing: .5px; color: var(--muted); }
.sidebar nav a { display: block; padding: 11px 20px; color: var(--muted); cursor: pointer; font-size: 14px;
  border-left: 3px solid transparent; transition: all .15s; }
.sidebar nav a:hover { color: var(--fg); background: var(--panel2); }
.sidebar nav a.active { color: var(--fg); border-left-color: var(--brand); background: var(--panel2); }
.me { margin-top: auto; padding: 14px 20px; border-top: 1px solid var(--line); font-size: 13px;
  display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.me span { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ver { padding: 10px 20px 0; font-size: 11px; color: #5b6878; letter-spacing: .5px; border-top: 1px solid var(--line); margin-top: 4px; }
.link { background: none; border: 0; color: var(--brand); cursor: pointer; font-size: 13px; padding: 0; }
.content { flex: 1; padding: 26px 32px; overflow: auto; }
.content h2 { margin: 0 0 16px; font-size: 20px; font-weight: 700; }
.content h3 { margin: 28px 0 12px; font-size: 14px; color: var(--muted); font-weight: 600; }
.muted { color: var(--muted); }
.row-between { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; gap: 12px; }

/* ---------------- 工具栏 / 搜索 / 筛选 ---------------- */
.toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.search { flex: 1 1 240px; min-width: 180px; padding: 9px 13px; background: var(--panel2);
  border: 1px solid var(--line); border-radius: 9px; color: var(--fg); font-size: 13px; transition: border-color .15s; }
.search:focus { outline: none; border-color: var(--brand); }
.search::placeholder { color: #66748a; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { padding: 6px 12px; border-radius: 20px; font-size: 12px; cursor: pointer; user-select: none;
  background: var(--panel2); border: 1px solid var(--line); color: var(--muted); transition: all .15s; }
.chip:hover { color: var(--fg); border-color: #3a4759; }
.chip.on { background: rgba(59,130,246,.16); border-color: var(--brand); color: #93c5fd; }
.chip .n { opacity: .7; margin-left: 5px; font-size: 11px; }

/* ---------------- 卡片 ---------------- */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px;
  display: flex; flex-direction: column; gap: 6px; transition: border-color .15s, transform .15s; }
.card:hover { border-color: rgba(59,130,246,.35); }
.card .title { font-weight: 600; font-size: 14px; }
.card .meta { color: var(--muted); font-size: 12px; word-break: break-all; }
.card .actions { margin-top: auto; padding-top: 8px; display: flex; gap: 8px; align-items: center; }

/* 最近连接列表 */
.list { display: flex; flex-direction: column; gap: 8px; }
.list-item { display: flex; align-items: center; gap: 10px; padding: 10px 14px; background: var(--panel);
  border: 1px solid var(--line); border-radius: 10px; font-size: 13px; }
.list-item .t { color: var(--muted); font-size: 12px; min-width: 130px; }
.list-item .n { font-weight: 600; }
.list-item .d { color: var(--muted); margin-left: auto; font-size: 12px; }

button { background: var(--brand); color: #fff; border: 0; border-radius: 8px; padding: 8px 14px;
  cursor: pointer; font-size: 13px; font-weight: 500; transition: background .15s, opacity .15s; }
button:hover { background: var(--brand2); }
button:disabled { opacity: .55; cursor: not-allowed; }
button.ghost { background: transparent; border: 1px solid var(--line); color: var(--fg); }
button.ghost:hover { background: var(--panel2); }
button.danger { background: var(--err); color: #2a0b0b; font-weight: 600; }
button.danger:hover { background: #ef4444; }
button.tiny { padding: 4px 9px; font-size: 12px; border-radius: 6px; }
.stat { font-size: 28px; font-weight: 700; letter-spacing: -.5px; }
.badge { display: inline-block; padding: 3px 9px; border-radius: 20px; font-size: 11px; font-weight: 600;
  background: var(--panel2); border: 1px solid var(--line); color: var(--muted); }
.badge.ssh { color: #60a5fa; border-color: #60a5fa; }
.badge.vnc { color: #c084fc; border-color: #c084fc; }
.badge.rdp { color: #fbbf24; border-color: #fbbf24; }
.badge.http { color: #34d399; border-color: #34d399; }

/* ---------------- 表格 ---------------- */
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 10px; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .4px; }
tbody tr:hover { background: rgba(255,255,255,.02); }
td .act { margin-right: 10px; }
.row-actions { display: flex; gap: 6px; }
.copy-host { cursor: pointer; color: var(--muted); }
.copy-host:hover { color: var(--brand); }
select { background: var(--panel2); color: var(--fg); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; }
code { background: var(--panel2); padding: 3px 7px; border-radius: 6px; font-size: 12px; word-break: break-all; }
.ok { color: var(--ok); }

/* 说明卡片 / 状态药丸 */
.note-card { background: var(--panel); border: 1px solid var(--line); border-left: 3px solid var(--brand);
  border-radius: var(--radius); padding: 14px 16px; font-size: 13px; line-height: 1.85; color: #a9b6c4;
  margin-bottom: 14px; }
.note-card b { color: var(--fg); }
.note-card code { background: var(--panel2); padding: 2px 6px; border-radius: 5px; font-size: 12px; }
.pill { display: inline-block; padding: 3px 9px; border-radius: 20px; font-size: 11px; font-weight: 600;
  border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.pill.up { color: var(--ok); border-color: rgba(52,211,153,.55); background: rgba(52,211,153,.1); }
.pill.down { color: var(--err); border-color: rgba(248,113,113,.55); background: rgba(248,113,113,.1); }
.pill.wait { color: var(--warn); border-color: rgba(251,191,36,.5); }

/* ---------------- 空状态 / 分页 ---------------- */
.empty { padding: 44px 20px; text-align: center; color: var(--muted); font-size: 13px; line-height: 1.8;
  border: 1px dashed var(--line); border-radius: var(--radius); background: rgba(255,255,255,.015); }
.empty .big { font-size: 15px; color: var(--fg); margin-bottom: 6px; font-weight: 600; }
.pager { display: flex; align-items: center; justify-content: center; gap: 8px; margin-top: 16px; font-size: 12px; color: var(--muted); }
.pager button { padding: 5px 11px; font-size: 12px; }

/* ---------------- Toast ---------------- */
.toast-host { position: fixed; right: 18px; bottom: 18px; z-index: 200; display: flex; flex-direction: column; gap: 10px; align-items: flex-end; }
.toast { display: flex; align-items: center; gap: 10px; min-width: 200px; max-width: 340px;
  padding: 11px 14px; border-radius: 10px; background: var(--panel); border: 1px solid var(--line);
  box-shadow: 0 10px 30px rgba(0,0,0,.45); font-size: 13px; cursor: pointer;
  transform: translateY(10px); opacity: 0; transition: transform .2s ease, opacity .2s ease; }
.toast.in { transform: translateY(0); opacity: 1; }
.toast-ico { width: 20px; height: 20px; border-radius: 50%; display: grid; place-items: center;
  font-size: 12px; font-weight: 700; flex: 0 0 20px; color: #0b0e13; }
.toast-success { border-color: rgba(52,211,153,.5); } .toast-success .toast-ico { background: var(--ok); }
.toast-error { border-color: rgba(248,113,113,.5); } .toast-error .toast-ico { background: var(--err); }
.toast-warn { border-color: rgba(251,191,36,.5); } .toast-warn .toast-ico { background: var(--warn); }
.toast-info .toast-ico { background: var(--brand); color: #fff; }
.toast-msg { word-break: break-word; }

/* ---------------- 弹层 ---------------- */
/* z-index 需高于会话层(80)，否则在会话中弹出的确认框会被遮住 */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.68); backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center; z-index: 95; padding: 20px; }
.modal-card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  padding: 22px; width: min(460px, 100%); max-height: 88vh; overflow: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,.5); }
.modal-card h4 { margin: 0 0 4px; font-size: 16px; }
.modal-card label { display: block; font-size: 12px; color: var(--muted); margin-top: 12px; }
.modal-card input, .modal-card select { width: 100%; padding: 10px 12px; margin-top: 5px;
  background: var(--panel2); border: 1px solid var(--line); border-radius: 9px; color: var(--fg); font-size: 14px; }
.modal-card input:focus { outline: none; border-color: var(--brand); }
.modal-card input.bad { border-color: var(--err); }
.dlg-text { color: var(--muted); font-size: 13px; line-height: 1.7; margin: 10px 0 0; white-space: pre-wrap; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }
.modal-actions button { min-width: 84px; }
.field-err { color: var(--err); font-size: 12px; margin-top: 5px; min-height: 16px; }
.chk { display: flex !important; align-items: center; gap: 8px; cursor: pointer; user-select: none; }
.chk input { width: auto !important; margin: 0 !important; cursor: pointer; }

/* ---------------- 沉浸式会话 ---------------- */
.stage { position: fixed; inset: 0; z-index: 80; display: flex; flex-direction: column; background: #05070a; }
.stage-bar { height: auto; min-height: var(--bar-h); flex: 0 0 auto; display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 6px 14px; background: rgba(20,26,34,.92); border-bottom: 1px solid var(--line);
  backdrop-filter: blur(8px); user-select: none; }
.stage-title { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 30vw; }
.stage-msg { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stage-timer { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.stage-spacer { flex: 1; }
.bar-btn { background: rgba(255,255,255,.06); color: var(--fg); border: 1px solid var(--line);
  border-radius: 7px; padding: 6px 11px; font-size: 12px; font-weight: 500; }
.bar-btn:hover { background: rgba(255,255,255,.12); }
.bar-btn.on { background: rgba(59,130,246,.22); border-color: var(--brand); color: #bfdbfe; }
.bar-btn.danger { background: rgba(248,113,113,.14); border-color: rgba(248,113,113,.45); color: #fca5a5; }
.bar-btn.danger:hover { background: rgba(248,113,113,.24); }

.dot { width: 8px; height: 8px; border-radius: 50%; flex: 0 0 8px; background: var(--muted); }
.dot.connecting { background: var(--warn); animation: pulse 1.2s ease-in-out infinite; }
.dot.connected { background: var(--ok); box-shadow: 0 0 0 3px rgba(52,211,153,.16); }
.dot.disconnected { background: var(--muted); }
.dot.error { background: var(--err); box-shadow: 0 0 0 3px rgba(248,113,113,.16); }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .35; } }

.stage-body { flex: 1; position: relative; overflow: hidden; display: flex;
  align-items: center; justify-content: center; background: #000; }
.sess-mount { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; overflow: hidden; }
#termHost { width: 100%; height: 100%; padding: 8px; }
#vncHost, #rdpHost { width: 100%; height: 100%; touch-action: none; } /* 移动端触摸拖动直接操作远端，不滚动页面 */
#vncHost canvas, #rdpHost canvas { display: block; }
.stage-msg-box { color: var(--muted); font-size: 13px; padding: 20px; text-align: center; max-width: 460px; line-height: 1.7; }

/* 会话内虚拟按键（移动端/无键盘场景） */
.keypad { position: absolute; right: 12px; bottom: 12px; z-index: 5; display: flex; flex-direction: column; gap: 6px;
  background: rgba(20,26,34,.94); border: 1px solid var(--line); border-radius: 10px; padding: 8px; backdrop-filter: blur(6px); }
.keypad .row { display: flex; gap: 6px; }
.keypad button { padding: 7px 12px; font-size: 13px; background: rgba(255,255,255,.07); border: 1px solid var(--line); color: var(--fg); }
.keypad button:hover { background: rgba(255,255,255,.14); }
.keypad .cap { font-size: 11px; color: var(--muted); text-align: center; }

/* ---------------- 移动端 ---------------- */
@media (max-width: 768px) {
  .sidebar { position: static; width: 100%; height: auto; flex-direction: column; padding: 10px 0;
    border-right: 0; border-bottom: 1px solid var(--line); }
  .app { flex-direction: column; }
  .logo { padding: 0 14px 8px; font-size: 18px; }
  .sidebar nav { display: flex; gap: 4px; overflow-x: auto; padding: 0 10px 4px; scrollbar-width: none; }
  .sidebar nav::-webkit-scrollbar { display: none; }
  .sidebar nav a { padding: 9px 13px; border-left: 0; border-bottom: 2px solid transparent; white-space: nowrap; }
  .sidebar nav a.active { border-left: 0; border-bottom-color: var(--brand); }
  .me { margin-top: 0; padding: 8px 14px 2px; border-top: 0; }
  .content { padding: 16px; }
  .content h2 { font-size: 18px; }
  .row-between { flex-wrap: wrap; }
  .cards { grid-template-columns: 1fr; }
  table { display: block; width: 100%; overflow-x: auto; }
  th, td { white-space: nowrap; }
  .toolbar { gap: 8px; }
  .search { flex: 1 1 100%; }
  .list-item { flex-wrap: wrap; }
  .list-item .d { margin-left: 0; width: 100%; }
  .toast-host { right: 12px; left: 12px; bottom: 12px; align-items: stretch; }
  .toast { max-width: none; }
  .stage-msg, .stage-timer { display: none; }
  .stage-title { max-width: 38vw; }
  .bar-btn { padding: 6px 8px; font-size: 11px; }
}
@media (max-width: 420px) {
  .stage-title { max-width: 30vw; font-size: 12px; }
  #btnClip, #btnScale { display: none; }
}
