/* ===========================================================
   棕熊控制台 — 界面样式（深色/浅色双主题，无外部字体依赖）
   =========================================================== */

:root {
  --font-ui: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI",
    "PingFang SC", "Microsoft YaHei", "Hiragino Sans GB", sans-serif;
  --font-mono: "JetBrains Mono", "Cascadia Mono", "SF Mono", Menlo, Consolas,
    "DejaVu Sans Mono", "Noto Sans Mono CJK SC", monospace;
  --r-sm: 6px;
  --r-md: 9px;
  --r-lg: 14px;
  --dur: 160ms;
  --ease: cubic-bezier(.22, .61, .36, 1);
}

:root[data-theme="dark"] {
  --bg: #080b10;
  --bg-2: #0d1117;
  --panel: #11161e;
  --panel-2: #151b25;
  --panel-3: #1a2230;
  --border: #222c3a;
  --border-soft: #1a222d;
  --text: #e3ebf7;
  --text-2: #9dabbd;
  --text-3: #6a7787;
  --accent: #4d9dff;
  --accent-2: #2f7df0;
  --accent-soft: rgba(77, 157, 255, .14);
  --ok: #37d39b;
  --warn: #f2b544;
  --danger: #f4655f;
  --shadow-2: 0 16px 48px rgba(0, 0, 0, .58), 0 2px 8px rgba(0, 0, 0, .4);
  --term-bg: #0d1117;
}

/* 蓝白（默认）：白底 + 蓝调，专业、清爽，长看不累 */
:root[data-theme="light"] {
  --bg: #eef4fc;
  --bg-2: #e7eefa;
  --panel: #ffffff;
  --panel-2: #f4f9ff;
  --panel-3: #e6f0fe;
  --border: #d9e5f4;
  --border-soft: #e9f1fb;
  --text: #10243d;
  --text-2: #47617e;
  --text-3: #8aa2bc;
  --accent: #1d6ff2;
  --accent-2: #0a56d4;
  --accent-soft: rgba(29, 111, 242, .12);
  --ok: #0e9f6e;
  --warn: #cf7a12;
  --danger: #e0393e;
  --shadow-2: 0 18px 46px rgba(16, 36, 61, .14), 0 2px 8px rgba(16, 36, 61, .05);
  --term-bg: #ffffff;
}

* { box-sizing: border-box; }

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

/* 禁缩放：viewport 的 user-scalable=no 在 iOS 上会被忽略，
   这里再用 touch-action + text-size-adjust 兜一层。
   manipulation 只禁双击缩放，不影响滑动与滚动，按钮手感也不受影响。 */
html {
  touch-action: manipulation;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 13.5px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

button, input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }

::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 8px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
::-webkit-scrollbar-thumb:hover { background: var(--text-3); background-clip: padding-box; }

/* ============================ 布局 ============================ */
.app {
  display: grid;
  grid-template-columns: clamp(220px, 22vw, 288px) minmax(0, 1fr);
  height: 100%;
  /* --app-h 由 app.js 按 visualViewport 实时写入：软键盘弹出时 100dvh 在
     多数移动浏览器里不会缩，底部的触屏快捷键条会被键盘盖住。 */
  height: var(--app-h, 100dvh);
}

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

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 15px 16px 13px;
  border-bottom: 1px solid var(--border-soft);
}
.brand-mark {
  width: 28px; height: 28px;
  border-radius: 8px;
  display: grid; place-items: center;
  background: linear-gradient(150deg, var(--accent), var(--accent-2));
  box-shadow: 0 4px 12px rgba(47, 125, 240, .32);
  color: #fff;
  flex: 0 0 auto;
}
.brand-mark svg { width: 15px; height: 15px; }
/* 改用图片 logo 后不再需要渐变底：logo 自带白底和圆角 */
.brand-mark.logo {
  background: none;
  box-shadow: none;
  padding: 0;
  overflow: hidden;
}
.brand-mark.logo img {
  width: 100%;
  height: 100%;
  display: block;
  border-radius: inherit;
}
.brand-text { min-width: 0; }
.brand-name { font-size: 13.5px; font-weight: 650; letter-spacing: .2px; }
.brand-sub {
  font-size: 10.5px;
  color: var(--text-3);
  letter-spacing: .3px;
  margin-top: 1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.search-wrap { position: relative; padding: 11px 12px 8px; }
.search-wrap svg {
  position: absolute;
  left: 21px; top: 50%;
  transform: translateY(-50%);
  color: var(--text-3);
  pointer-events: none;
}
#search {
  width: 100%;
  height: 31px;
  padding: 0 10px 0 31px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  outline: none;
  font-size: 12.5px;
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
#search::placeholder { color: var(--text-3); }
#search:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.server-list {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 4px 8px 12px;
}

.side-group {
  padding: 10px 8px 5px;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: .7px;
  text-transform: uppercase;
  color: var(--text-3);
}

.srv {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: var(--r-md);
  border: 1px solid transparent;
  cursor: pointer;
  outline: none;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.srv:hover { background: var(--panel-2); }
.srv:focus-visible { border-color: var(--accent); }
.srv-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--text-3);
  flex: 0 0 auto;
  transition: background var(--dur);
}
.srv:hover .srv-dot { background: var(--accent); }
.srv-body { min-width: 0; flex: 1 1 auto; }
.srv-name {
  font-size: 12.8px;
  font-weight: 550;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.srv-meta {
  font-family: var(--font-mono);
  font-size: 10.8px;
  color: var(--text-3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 1px;
}
.srv-acts { display: flex; gap: 2px; opacity: 0; transition: opacity var(--dur) var(--ease); }
.srv:hover .srv-acts, .srv:focus-within .srv-acts { opacity: 1; }

.side-empty { padding: 34px 18px; text-align: center; color: var(--text-3); }
.side-empty p { margin: 0 0 4px; font-size: 12.5px; color: var(--text-2); }
.side-empty span { font-size: 11.5px; }

.side-foot {
  display: flex;
  gap: 6px;
  padding: 12px 10px;
  border-top: 1px solid var(--border-soft);
}

/* ============================ 按钮 ============================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 31px;
  padding: 0 12px;
  border-radius: var(--r-md);
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  font-size: 12.5px;
  font-weight: 520;
  white-space: nowrap;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease),
    transform var(--dur) var(--ease), color var(--dur) var(--ease);
}
.btn:hover { background: var(--panel-3); border-color: var(--text-3); }
.btn:active { transform: scale(.975); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.btn svg { width: 14px; height: 14px; flex: 0 0 auto; }
.btn.primary {
  background: linear-gradient(180deg, var(--accent), var(--accent-2));
  border-color: transparent;
  color: #fff;
  box-shadow: 0 3px 10px rgba(47, 125, 240, .28);
}
.btn.primary:hover { filter: brightness(1.06); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn.ghost:hover { background: var(--panel-2); color: var(--text); }
.btn.danger { color: var(--danger); border-color: rgba(244, 101, 95, .38); }
.btn.danger:hover { background: rgba(244, 101, 95, .12); }
.btn.grow { flex: 1 1 auto; }

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 29px; height: 29px;
  border-radius: var(--r-sm);
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-2);
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.icon-btn:hover { background: var(--panel-3); color: var(--text); }
.icon-btn:active { transform: scale(.94); }
.icon-btn.sm { width: 23px; height: 23px; }
/* 处于非默认档位时给个底色，用户一眼能看出"我把画质调低了" */
.icon-btn.on { background: var(--accent-soft); color: var(--accent); }
.icon-btn.on:hover { background: var(--accent-soft); color: var(--accent); }

/* ============================ 主区 ============================ */
.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: var(--bg-2);
}

.tabbar {
  display: flex;
  align-items: stretch;
  gap: 6px;
  height: 44px;
  min-width: 0;
  padding: 7px 8px 0;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
}
/* 标签滚动区：只清空这里，工具条不受影响 */
.tab-scroll {
  display: flex;
  align-items: stretch;
  gap: 4px;
  flex: 1 1 0;
  min-width: 0;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
}
.tab-scroll::-webkit-scrollbar { height: 0; }

/* 移动端汉堡菜单按钮：默认隐藏，窄屏由媒体查询打开 */
.menu-btn {
  display: none;
  flex: 0 0 auto;
  align-self: center;
  margin-right: 2px;
}

.tab {
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 280px;
  padding: 0 8px 0 12px;
  border: 1px solid transparent;
  border-bottom: none;
  border-radius: 8px 8px 0 0;
  color: var(--text-2);
  font-size: 12.3px;
  cursor: pointer;
  user-select: none;
  position: relative;
  top: 1px;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.tab:hover { background: var(--panel-2); color: var(--text); }
.tab.active {
  background: var(--bg-2);
  border-color: var(--border);
  color: var(--text);
  font-weight: 550;
}
.tab-label {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 200px;
  font-family: var(--font-mono);
  font-size: 11.6px;
}
.tab .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--text-3); flex: 0 0 auto; }
.dot.online { background: var(--ok); box-shadow: 0 0 0 3px rgba(55, 211, 155, .16); }
.dot.connecting { background: var(--warn); animation: pulse 1.1s ease-in-out infinite; }
.dot.closed, .dot.error { background: var(--danger); }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .28; } }

.tab-x {
  display: grid; place-items: center;
  width: 17px; height: 17px;
  border: none;
  border-radius: 4px;
  background: transparent;
  color: var(--text-3);
}
.tab-x:hover { background: var(--panel-3); color: var(--danger); }

.stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
  background: var(--term-bg);
}

.pane {
  position: absolute;
  inset: 0;
  display: none;
  padding: 8px 0 0 10px;
  overflow: auto;
}
.pane.active { display: block; }

.term-wrap { display: inline-block; position: relative; }
.term-canvas { display: block; outline: none; touch-action: pan-y; }
.term-input {
  position: absolute;
  left: 0; top: 0;
  width: 1px; height: 1px;
  padding: 0;
  border: 0;
  opacity: 0;
  resize: none;
  overflow: hidden;
  background: transparent;
  color: transparent;
  /* 必须 >=16px：iOS 聚焦小于 16px 的输入框会自动放大整页，
     光这一条就够让手机端「一碰就放大」 */
  font-size: 16px;
  z-index: 1;
}
body.term-selecting { user-select: none; }

/* 欢迎页 */
.welcome {
  position: absolute;
  inset: 0;
  display: block;
  padding: 24px;
  overflow: auto;
  background:
    radial-gradient(900px 420px at 50% -8%, var(--accent-soft), transparent 70%),
    var(--bg-2);
}
.welcome-inner {
  max-width: 520px;
  width: 100%;
  min-width: 0;
  margin: 0 auto;
  text-align: center;
  position: relative;
  top: 50%;
  transform: translateY(-50%);
}
.welcome-icon {
  width: 54px; height: 54px;
  margin: 0 auto 18px;
  border-radius: 15px;
  display: grid; place-items: center;
  background: linear-gradient(150deg, var(--accent), var(--accent-2));
  color: #fff;
  box-shadow: 0 10px 30px rgba(47, 125, 240, .32);
}
.welcome-icon svg { width: 26px; height: 26px; }
.welcome h1 { margin: 0 0 8px; font-size: 19px; font-weight: 650; letter-spacing: -.2px; }
.welcome p {
  margin: 0 auto 22px;
  max-width: 430px;
  color: var(--text-2);
  font-size: 12.8px;
  line-height: 1.7;
  word-break: break-word;
  overflow-wrap: anywhere;
}
.welcome-acts { display: flex; gap: 9px; justify-content: center; flex-wrap: wrap; }
.kbd-hints {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px 18px;
  margin-top: 30px;
  padding-top: 20px;
  border-top: 1px dashed var(--border);
  text-align: left;
  font-size: 11.8px;
  color: var(--text-3);
}
.kbd-hints div { display: flex; align-items: center; gap: 8px; }
kbd {
  display: inline-block;
  padding: 2px 6px;
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 5px;
  background: var(--panel-2);
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--text-2);
  white-space: nowrap;
}

/* 状态栏 */
.statusbar {
  display: flex;
  align-items: center;
  gap: 20px;
  height: 30px;
  padding: 0 14px;
  background: var(--panel);
  border-top: 1px solid var(--border);
  font-size: 11.3px;
  color: var(--text-3);
  overflow-x: auto;
  white-space: nowrap;
  flex: 0 0 auto;
  scrollbar-width: none;
}
.statusbar::-webkit-scrollbar { height: 0; }
.st-item { display: inline-flex; align-items: center; gap: 6px; }
.st-k { color: var(--text-3); }
.st-v { color: var(--text-2); font-family: var(--font-mono); font-size: 11px; }
.st-item.mono .st-v { max-width: 320px; overflow: hidden; text-overflow: ellipsis; }
.st-online .st-v { color: var(--ok); }
.st-connecting .st-v { color: var(--warn); }
.st-closed .st-v, .st-error .st-v { color: var(--danger); }

/* ============================ 弹层 ============================ */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(4, 7, 12, .58);
  backdrop-filter: blur(3px);
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--dur) var(--ease), visibility var(--dur);
}
.overlay.open { opacity: 1; visibility: visible; }

.modal {
  position: fixed;
  z-index: 50;
  left: 50%; top: 50%;
  width: min(560px, calc(100vw - 32px));
  max-height: calc(100dvh - 48px);
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-2);
  transform: translate(-50%, -50%);
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--dur) var(--ease), visibility var(--dur);
  overflow: hidden;
}
.modal.open { opacity: 1; visibility: visible; }
.modal.sm { width: min(420px, calc(100vw - 32px)); }

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 15px 16px 13px;
  border-bottom: 1px solid var(--border-soft);
}
.modal-head h2 { margin: 0; font-size: 14px; font-weight: 650; letter-spacing: .1px; }
.modal-body {
  padding: 16px;
  overflow-y: auto;
  flex: 1 1 auto;
  min-height: 0;
  -webkit-overflow-scrolling: touch;
}
.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--border-soft);
  background: var(--panel-2);
}

/* 含 <form> 包裹的弹窗（如「新增服务器」）：让 form 也成为弹性列容器，
   否则 .modal-body 的 flex:1 / min-height:0 对 form 内的子元素失效，
   .modal 的 overflow:hidden 会把底部「取消 / 保存并连接」按钮裁掉。 */
.modal > form {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  margin: 0;
}

/* ============================ 表单 ============================ */
.form-grid { display: grid; gap: 13px; }
.form-row { display: grid; gap: 6px; }
.form-row.two { grid-template-columns: 1fr 118px; gap: 10px; }
.field-label {
  font-size: 11.8px;
  font-weight: 550;
  color: var(--text-2);
  letter-spacing: .1px;
}
.field-label .req { color: var(--danger); margin-left: 2px; }

.input, .select, .textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 0 10px;
  height: 34px;
  outline: none;
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.input::placeholder, .textarea::placeholder { color: var(--text-3); }
.input:focus, .select:focus, .textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.select { appearance: none; padding-right: 28px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6' fill='none'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%236a7787' stroke-width='1.4' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
}
.textarea {
  height: auto;
  min-height: 92px;
  padding: 8px 10px;
  font-family: var(--font-mono);
  font-size: 11.6px;
  line-height: 1.55;
  resize: vertical;
}
.input.mono { font-family: var(--font-mono); font-size: 12px; }

.check {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 12.2px;
  color: var(--text-2);
  cursor: pointer;
  user-select: none;
  line-height: 1.45;
}
.check input {
  appearance: none;
  width: 15px; height: 15px;
  margin: 1px 0 0;
  border: 1.5px solid var(--border);
  border-radius: 4px;
  background: var(--bg);
  flex: 0 0 auto;
  position: relative;
  cursor: pointer;
  transition: border-color var(--dur), background var(--dur);
}
.check input:checked { background: var(--accent); border-color: var(--accent); }
.check input:checked::after {
  content: "";
  position: absolute;
  left: 4px; top: 1px;
  width: 5px; height: 9px;
  border: solid #fff;
  border-width: 0 1.8px 1.8px 0;
  transform: rotate(42deg);
}
.check input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.hint { font-size: 11.3px; color: var(--text-3); line-height: 1.5; }
.hint.warn { color: var(--warn); }

/* ============================ 提示条 ============================ */
.toast {
  position: fixed;
  left: 50%;
  bottom: 34px;
  z-index: 80;
  transform: translate(-50%, 12px);
  padding: 9px 16px;
  max-width: min(560px, calc(100vw - 40px));
  background: var(--panel-3);
  border: 1px solid var(--border);
  border-radius: 999px;
  box-shadow: var(--shadow-2);
  font-size: 12.4px;
  color: var(--text);
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--dur) var(--ease), transform var(--dur) var(--ease), visibility var(--dur);
}
.toast.show { opacity: 1; visibility: visible; transform: translate(-50%, 0); }
.toast.ok { border-color: rgba(55, 211, 155, .45); }
.toast.error { border-color: rgba(244, 101, 95, .5); color: var(--danger); }

/* ============================ 登录页 ============================ */
.login-body {
  display: grid;
  place-items: center;
  min-height: 100%;
  padding: 24px;
  background:
    radial-gradient(1000px 520px at 50% -10%, var(--accent-soft), transparent 68%),
    radial-gradient(700px 420px at 90% 110%, rgba(47, 125, 240, .10), transparent 70%),
    var(--bg);
  overflow: auto;
}
.login-card {
  width: min(392px, 100%);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow-2);
  padding: 30px 28px 26px;
  animation: rise .34s var(--ease) both;
}
@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
.login-brand {
  display: flex;
  align-items: center;
  gap: 11px;
  margin-bottom: 22px;
}
.login-brand .brand-mark { width: 34px; height: 34px; border-radius: 10px; }
.login-brand .brand-mark svg { width: 18px; height: 18px; }
.login-brand .brand-name { font-size: 15px; }
.login-card h1 {
  margin: 0 0 6px;
  font-size: 17px;
  font-weight: 650;
  letter-spacing: -.2px;
}
.login-sub {
  margin: 0 0 20px;
  font-size: 12.3px;
  color: var(--text-2);
  line-height: 1.6;
}
.login-card form { display: grid; gap: 12px; }
.login-card .btn { height: 38px; width: 100%; font-size: 13px; }
.alert {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  padding: 9px 11px;
  margin-bottom: 14px;
  border-radius: var(--r-md);
  background: rgba(244, 101, 95, .1);
  border: 1px solid rgba(244, 101, 95, .32);
  color: var(--danger);
  font-size: 12.2px;
  line-height: 1.5;
  animation: shake .3s var(--ease);
}
.alert svg { flex: 0 0 auto; margin-top: 1px; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}
.login-foot {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--border-soft);
  font-size: 11.3px;
  color: var(--text-3);
  line-height: 1.7;
}

/* ============================ 触控优化 ============================ */
/* 去除移动端点击延迟与点击高亮，按钮/标签更跟手，避免「点不动」的观感 */
button, .btn, .icon-btn, .tab, .srv, a, .select, .check, label, .sso-card-acts .btn {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

/* ============================ 响应式 ============================ */
/* 窄屏（≤1100px）：隐藏侧栏副标题与主机地址，压缩占用 */
@media (max-width: 1100px) {
  .brand-sub { display: none; }
  .srv-meta { display: none; }
}

/* 中屏（≤900px）：侧栏收窄 */
@media (max-width: 900px) {
  .app { grid-template-columns: 200px minmax(0, 1fr); }
  .brand { padding: 13px 12px 11px; }
  .side-foot { flex-wrap: wrap; }
  .side-foot .btn.grow { flex: 1 1 100%; }
}

/* 平板/手机（≤768px）：侧栏折叠为抽屉，主区占满 */
@media (max-width: 768px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    z-index: 60;
    top: 0; bottom: 0; left: 0;
    width: min(84vw, 300px);
    transform: translateX(-105%);
    transition: transform .24s var(--ease);
    box-shadow: 8px 0 30px -8px rgba(16, 36, 61, .28);
  }
  .sidebar.open { transform: translateX(0); }
  .menu-btn { display: inline-grid; }
  .kbd-hints { grid-template-columns: 1fr; }
  .statusbar { gap: 14px; }
  /* 点侧栏外关闭抽屉的遮罩 */
  body.side-open::after {
    content: "";
    position: fixed;
    inset: 0;
    z-index: 55;
    background: rgba(16, 36, 61, .4);
  }
}

/* 手机（≤480px）：弹窗全屏化、表单单列、间距收紧 */
@media (max-width: 480px) {
  .modal,
  .modal.sm {
    width: calc(100vw - 16px);
    max-height: calc(100dvh - 16px);
    border-radius: 12px;
  }
  .form-row.two { grid-template-columns: 1fr; gap: 8px; }
  .modal-head { padding: 13px 14px 11px; flex: 0 0 auto; }
  .modal-body { padding: 13px; }
  .modal-foot { padding: 11px 13px; flex: 0 0 auto; }
  .welcome { padding: 16px; }
  .welcome-inner { max-width: 100%; }
  .welcome p { max-width: 100%; }
  .kbd-hints { gap: 6px 12px; }
  .statusbar { padding: 0 10px; }
  /* 工具条图标更紧凑，确保 5 个图标 + 汉堡在窄屏下不溢出 */
  .tabbar { gap: 4px; padding: 7px 6px 0; }
  .tabbar-actions { gap: 0; padding-left: 4px; flex-shrink: 0; }
  .tabbar-actions .icon-btn { width: 26px; }
}

/* 布局补充 */
.term-host { position: absolute; inset: 0; }
.tabbar-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 2px;
  padding-left: 10px;
  flex: 0 0 auto;
}

/* ============================ 免密连接页 ============================ */
.sso-body { margin: 0; height: 100dvh; overflow: hidden; background: var(--term-bg); }
/* --app-h 由 sso.js 按 visualViewport 实时写入：软键盘弹出时 100dvh 不会缩，
   用可见高度才能保证快捷键条不被键盘盖住 */
.sso-app { display: flex; flex-direction: column; height: var(--app-h, 100dvh); }

.sso-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  height: 40px;
  padding: 0 8px 0 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
}
.sso-left { display: flex; align-items: center; gap: 9px; min-width: 0; }
.sso-left .dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--text-3);
  flex: 0 0 auto;
}
.sso-title {
  font-size: 12.8px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sso-host {
  font-family: var(--font-mono);
  font-size: 11.2px;
  color: var(--text-3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sso-right { display: flex; align-items: center; gap: 2px; flex: 0 0 auto; }
.sso-right .icon-btn { font-size: 11.5px; font-weight: 600; }

.sso-stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  padding: 8px 0 0 10px;
  background: var(--term-bg);
}

.sso-foot {
  display: flex;
  align-items: center;
  gap: 20px;
  height: 28px;
  padding: 0 14px;
  background: var(--panel);
  border-top: 1px solid var(--border);
  font-size: 11.2px;
  color: var(--text-3);
  overflow-x: auto;
  white-space: nowrap;
  flex: 0 0 auto;
  scrollbar-width: none;
}
.sso-foot::-webkit-scrollbar { height: 0; }

/* 触屏快捷键条：默认隐藏，只有「没有悬停能力 + 粗指针」（手机/平板）才出现 */
.sso-keys {
  display: none;
  gap: 6px;
  padding: 7px 8px;
  background: var(--panel);
  border-top: 1px solid var(--border);
  overflow-x: auto;
  overflow-y: hidden;
  white-space: nowrap;
  flex: 0 0 auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.sso-keys::-webkit-scrollbar { height: 0; }
.sso-keys .key {
  flex: 0 0 auto;
  min-width: 44px;
  height: 30px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--panel-2);
  color: var(--text-2);
  font-size: 12px;
  font-weight: 600;
  line-height: 1;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.sso-keys .key:active {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: var(--accent);
}
.sso-keys .key.strong { color: var(--accent); border-color: var(--accent); }

@media (hover: none) and (pointer: coarse) {
  .sso-keys { display: flex; }
  /* 连接中占位要让开快捷键条，否则会压住它 */
  .sso-wait { inset: 40px 0 calc(28px + 45px) 0; }
}

/* 连接中占位：只盖住终端区。页面一加载就显示，
   让「SSH 握手慢」变成可感知的进度，而不是一片白屏干等。 */
.sso-wait {
  position: absolute;
  inset: 40px 0 28px 0;
  z-index: 15;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 13px;
  background: var(--term-bg);
}
.sso-spin {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  animation: sso-spin .75s linear infinite;
}
.sso-wait-text { font-size: 12.6px; color: var(--text-2); font-variant-numeric: tabular-nums; }
@keyframes sso-spin { to { transform: rotate(360deg); } }

.sso-overlay {
  position: absolute;
  /* 只盖住中间的终端舞台（上下让出顶栏 40px、状态栏 28px）。
     .sso-overlay 是 .sso-app（flex 列）的直接子节点、定位父级是视口，
     用 inset:0 会把顶栏和状态栏也一起蒙住，浅色主题下那里的文字
     就成了半透的「鬼影」，看着像界面坏了。 */
  inset: 40px 0 28px 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(6, 9, 14, .74);
  backdrop-filter: blur(3px);
}
/* 浅色主题下蒙层必须是浅色的：以前这里不分主题一律用 74% 近黑，
   一进免密页（尤其「链接无效」这种整屏卡片）就变成黑乎乎一片，
   跟蓝白主题完全冲突。浅色用冷白半透明 + 模糊，卡片靠边框阴影浮起。 */
:root[data-theme="light"] .sso-overlay {
  background: rgba(232, 241, 252, .78);
}
:root[data-theme="light"] .sso-card {
  box-shadow: 0 18px 48px -18px rgba(16, 36, 61, .28), 0 1px 1px rgba(255, 255, 255, .9) inset;
}
.sso-card {
  width: min(430px, 100%);
  padding: 26px 24px 22px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow-2);
  text-align: center;
  animation: rise .28s var(--ease) both;
}
.sso-card-icon {
  width: 44px; height: 44px;
  margin: 0 auto 15px;
  border-radius: 12px;
  display: grid; place-items: center;
  background: var(--panel-3);
  color: var(--text-2);
}
.sso-card-icon.err { background: rgba(244, 101, 95, .14); color: var(--danger); }
.sso-card-icon.ok { background: rgba(55, 211, 155, .14); color: var(--ok); }
.sso-card h2 { margin: 0 0 7px; font-size: 15.5px; font-weight: 650; letter-spacing: -.1px; }
.sso-card p {
  margin: 0 0 18px;
  color: var(--text-2);
  font-size: 12.4px;
  line-height: 1.68;
  word-break: break-word;
}
.sso-card-acts { display: flex; justify-content: center; gap: 8px; }

/* ===========================================================
   蓝白主题精修层
   目标：白底 + 蓝调、层次靠阴影与细边框而非重色块，长看不累
   =========================================================== */
:root[data-theme="light"] body {
  background:
    radial-gradient(1200px 520px at 12% -10%, #e2eeff 0%, rgba(226, 238, 255, 0) 62%),
    radial-gradient(900px 420px at 100% 0%, #eaf2ff 0%, rgba(234, 242, 255, 0) 58%),
    var(--bg);
}

:root[data-theme="light"] ::selection { background: rgba(29, 111, 242, .2); }

:root[data-theme="light"] ::-webkit-scrollbar-thumb {
  background: #c8d9ec;
  border: 2px solid transparent;
  background-clip: content-box;
  border-radius: 8px;
}
:root[data-theme="light"] ::-webkit-scrollbar-thumb:hover { background: #a9c2df; background-clip: content-box; }

/* 侧栏：纯白面板 + 极轻投影，与蓝底分离 */
:root[data-theme="light"] .sidebar {
  background: #ffffff;
  border-right: 1px solid var(--border);
  box-shadow: 1px 0 0 rgba(255, 255, 255, .9), 6px 0 18px -12px rgba(16, 36, 61, .18);
}
:root[data-theme="light"] .brand { border-bottom: 1px solid var(--border-soft); }
:root[data-theme="light"] .brand-mark {
  background: linear-gradient(150deg, #3d8bff, #0a56d4);
  box-shadow: 0 6px 16px -6px rgba(29, 111, 242, .75);
}
:root[data-theme="light"] .brand-name { color: #10243d; }

/* 搜索框 */
:root[data-theme="light"] #search {
  background: #f7fbff;
  border-color: var(--border);
}
:root[data-theme="light"] #search:hover { border-color: #c3d7ef; }
:root[data-theme="light"] #search:focus {
  background: #fff;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

/* 服务器条目 */
:root[data-theme="light"] .srv {
  border-radius: 9px;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
:root[data-theme="light"] .srv:hover { background: var(--panel-2); }
:root[data-theme="light"] .srv.active,
:root[data-theme="light"] .srv[aria-current="true"] {
  background: var(--accent-soft);
  box-shadow: inset 2px 0 0 var(--accent);
}
:root[data-theme="light"] .srv-dot { background: #c3d3e5; }

/* 按钮 */
:root[data-theme="light"] .btn {
  background: #fff;
  border-color: var(--border);
  color: var(--text-2);
}
:root[data-theme="light"] .btn:hover {
  background: var(--panel-2);
  border-color: #bfd4ee;
  color: var(--text);
}
:root[data-theme="light"] .btn.primary {
  background: linear-gradient(180deg, #2f83ff, #1a63e0);
  border-color: #1a5fd6;
  color: #fff;
  box-shadow: 0 6px 16px -8px rgba(26, 99, 224, .9);
}
:root[data-theme="light"] .btn.primary:hover {
  background: linear-gradient(180deg, #3d8bff, #1d6ff2);
  filter: none;
}
:root[data-theme="light"] .icon-btn { color: var(--text-2); }
:root[data-theme="light"] .icon-btn:hover { background: var(--panel-3); color: var(--accent); }

/* 标签栏：白底 + 当前页蓝色下划线，代替旧的整块灰底 */
:root[data-theme="light"] .tabbar {
  background: #fff;
  border-bottom: 1px solid var(--border);
}
:root[data-theme="light"] .tab { top: 0; border-radius: 8px; border-bottom: none; }
:root[data-theme="light"] .tab:hover { background: var(--panel-2); }
:root[data-theme="light"] .tab.active {
  background: var(--accent-soft);
  border-color: transparent;
  color: var(--accent-2);
  box-shadow: inset 0 -2px 0 var(--accent);
}
:root[data-theme="light"] .tab.active .tab-label { color: var(--accent-2); }
:root[data-theme="light"] .tab-x:hover { background: rgba(224, 57, 62, .1); color: var(--danger); }
:root[data-theme="light"] .dot.online { background: var(--ok); box-shadow: 0 0 0 3px rgba(14, 159, 110, .16); }

/* 终端区：极浅蓝白 + 内阴影，边界更利落 */
:root[data-theme="light"] .stage {
  background: var(--term-bg);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .8);
}

/* 状态栏 */
:root[data-theme="light"] .statusbar {
  background: #fff;
  border-top: 1px solid var(--border);
}
:root[data-theme="light"] .st-v { color: var(--text-2); }

/* 弹层与表单 */
:root[data-theme="light"] .overlay { background: rgba(16, 36, 61, .38); }
:root[data-theme="light"] .modal {
  border-color: var(--border);
  box-shadow: 0 24px 64px -20px rgba(16, 36, 61, .38), 0 2px 10px rgba(16, 36, 61, .06);
}
:root[data-theme="light"] .modal-head { border-bottom: 1px solid var(--border-soft); }
:root[data-theme="light"] .modal-foot {
  background: #fbfdff;
  border-top: 1px solid var(--border-soft);
}
:root[data-theme="light"] .input,
:root[data-theme="light"] .select,
:root[data-theme="light"] .textarea {
  background: #fff;
  border-color: var(--border);
}
:root[data-theme="light"] .input:hover,
:root[data-theme="light"] .select:hover,
:root[data-theme="light"] .textarea:hover { border-color: #c3d7ef; }
:root[data-theme="light"] .input:focus,
:root[data-theme="light"] .select:focus,
:root[data-theme="light"] .textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

/* 欢迎页 */
:root[data-theme="light"] .welcome {
  background:
    radial-gradient(760px 360px at 50% -12%, rgba(29, 111, 242, .10), transparent 68%),
    #ffffff;
}
:root[data-theme="light"] .welcome-icon {
  background: var(--accent-soft);
  color: var(--accent);
  box-shadow: inset 0 0 0 1px rgba(29, 111, 242, .18);
}
:root[data-theme="light"] .welcome h1 { color: var(--text); }
:root[data-theme="light"] .kbd-hints { background: #fff; border-color: var(--border); }

/* 提示条 */
:root[data-theme="light"] .toast {
  background: #fff;
  box-shadow: 0 14px 40px -16px rgba(16, 36, 61, .4);
}
