/* term：终端页（入口按钮条 / xterm 挂载 / 上传遮罩）。 */

.term-bar {
  display: flex; align-items: center; gap: 12px;
  padding: 3px 20px;
  border-bottom: 1px solid var(--line);
}

/* ---- 左侧提示轮播：单行视窗 + 纵向滚动轨道（term.js 逐条上移，末条无缝回卷） ---- */
.term-tip-wrap {
  display: flex; align-items: center; gap: 7px;
  margin-left: 6px;
  min-width: 0; flex: 0 1 auto;
}
.term-tip-icon { flex: none; color: var(--amber); }
.term-tips {
  --tip-h: 18px;
  height: var(--tip-h);
  min-width: 0;
  overflow: hidden;
}
.term-tips-track { display: flex; flex-direction: column; will-change: transform; }
.term-tip {
  height: var(--tip-h); line-height: var(--tip-h);
  font-family: var(--mono); font-size: 12px; color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  background: linear-gradient(90deg,
    var(--muted) 0%, var(--muted) 44%,
    var(--text-hi) 48%, var(--amber) 50%, var(--text-hi) 52%,
    var(--muted) 56%, var(--muted) 100%);
  background-size: 250% 100%;
  background-position: 100% 0;
  background-repeat: no-repeat;
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  animation: term-tip-scan 4s linear infinite;
}
@keyframes term-tip-scan {
  0%, 18% { background-position: 100% 0; }
  72%, 100% { background-position: 0 0; }
}

/* ---- 本会话已花：贴着连接状态左边，margin-left:auto 把这一组顶到右侧 ----
 * 金额用琥珀，token 压成次要——扫一眼要先看到钱。提示轮播可能很长，这一块
 * flex:none 保证它不被挤掉。 */
.term-spend {
  display: inline-flex; align-items: baseline; gap: 6px;
  margin-left: auto; flex: none;
  font-family: var(--mono); font-size: 12px;
  white-space: nowrap;
  cursor: default;
}
.term-spend .ts-label { color: var(--muted); }
.term-spend .ts-cost { color: var(--amber); }
.term-spend .ts-tok { color: var(--muted); }
/* 已花之后，连接状态那组就不该再抢 auto 边距了 */
.term-spend:not(.hidden) + .term-conn { margin-left: 0; }

/* ---- 右侧连接状态：状态点 + 文案 + 手动重连按钮 ---- */
.term-conn {
  display: inline-flex; align-items: center; gap: 8px;
  margin-left: auto; flex: none;
}
.term-state {
  color: var(--muted); font-size: 12px;
  white-space: nowrap;
}
.term-state[data-state="connected"] { color: var(--green); }
.term-state[data-state="closed"] { color: var(--red); }
.term-reconnect {
  display: inline-flex; align-items: center; justify-content: center;
  width: 26px; height: 26px; padding: 0;
  border: 0; background: none; color: var(--muted);
  cursor: pointer; flex: none;
  transition: color .15s, transform .12s;
}
.term-reconnect:hover { color: var(--text-hi); }
.term-reconnect:active { transform: scale(0.9); }
.term-reconnect:focus-visible { outline: 2px solid var(--amber); outline-offset: 1px; border-radius: 50%; }
.term-reconnect svg { width: 18px; height: 18px; }
/* 连接中 / 重连中：图标转圈（复用 base.css 的 rot 关键帧） */
.term-reconnect.busy svg { animation: rot 1s linear infinite; }
/* 终端显示区容器：挂载点 + 连接加载态覆盖层共用定位上下文 */
.term-body {
  flex: 1; min-height: 0;
  position: relative;
  display: flex; flex-direction: column;
}
/* 内边距必须放在 .xterm 上而不是挂载容器上：FitAddon 用容器的 computed 尺寸
   （border-box，含 padding）算行列数，只会减去 .xterm 自身的 padding，
   放容器上会导致终端比容器大一圈、把整页撑出滚动条 */
.term-mount { flex: 1; min-height: 0; background: var(--term-bg); overflow: hidden; color-scheme: dark; }
.term-mount .xterm { height: 100%; padding: 8px 8px 8px 16px; }
/* 终端始终深色；复用全局滚动条形状，只覆盖颜色令牌。 */
.term-mount {
  --scroll-thumb: var(--term-sel);
  --scroll-thumb-hover: #566174;
  --scroll-thumb-active: var(--term-cursor);
}
/* 连接加载态：盖在终端显示区上（而非按钮条），底色与终端一致 */
.term-loading {
  position: absolute; inset: 0; z-index: 10;
  background: var(--term-bg);
}

/* 终端图片上传遮罩：盖住整个终端页，阻断误操作 */
.term-overlay {
  position: absolute; inset: 0; z-index: 20;
  background: color-mix(in srgb, var(--term-bg) 55%, transparent);
  display: flex; align-items: center; justify-content: center;
  cursor: progress;
}
.term-overlay-box {
  display: flex; flex-direction: column; align-items: center; gap: 12px;
  background: var(--panel);
  border: 1px solid var(--line); border-radius: 10px;
  padding: 20px 28px;
  font-family: var(--mono); font-size: 12px; color: var(--amber);
  box-shadow: var(--shadow-md);
}
.term-overlay-box .spin { width: 26px; height: 26px; border-width: 3px; }

/* 手机辅助键独立于终端滚动区；横滑查看更多，键盘开关始终留在右侧。 */
.term-keys { display: none; }
@media (max-width: 760px), (pointer: coarse) {
  .term-keys {
    display: flex; align-items: center; flex: none; gap: 4px;
    min-width: 0; margin: 0; border: 0; border-top: 1px solid var(--term-sel);
    padding: 4px 6px max(4px, env(safe-area-inset-bottom));
    background: var(--term-bg); color: var(--term-fg);
  }
  .term-keys-scroll {
    display: flex; flex: 1; min-width: 0; gap: 2px;
    overflow-x: auto; overscroll-behavior-x: contain; scrollbar-width: none;
  }
  .term-keys-scroll::-webkit-scrollbar { display: none; }
  .term-keys button {
    display: inline-flex; align-items: center; justify-content: center;
    flex: none; min-width: 44px; height: 44px; padding: 0 8px;
    border: 0; border-radius: 7px; background: transparent; color: var(--term-cursor);
    font: 13px var(--mono); white-space: nowrap;
    touch-action: manipulation; user-select: none; -webkit-user-select: none;
    -webkit-touch-callout: none;
  }
  .term-keys button:active, .term-keys button[aria-pressed="true"] {
    background: var(--term-sel); color: var(--term-fg);
  }
  .term-keys button[aria-pressed="true"] { box-shadow: inset 0 -2px var(--term-cursor); }
  .term-keys button:focus-visible { outline: 2px solid var(--term-cursor); outline-offset: -2px; }
  .term-keys button:disabled { opacity: .35; }
  #term-keyboard { border-left: 1px solid var(--term-sel); border-radius: 0; }
  /* dvh 不会在所有手机浏览器中随软键盘缩小，实际高度由 VisualViewport 提供。 */
  .app.term-viewport {
    position: fixed; left: 0; right: 0; top: var(--term-viewport-top);
    height: var(--term-viewport-height);
  }
}

/* ---- 窄屏：提示占据连接状态左侧的剩余空间（xterm 字号在 js/term.js 里降到 12） ---- */
@media (max-width: 760px) {
  .term-bar { padding: 2px 12px; }
  .term-tip-wrap { margin-left: 0; flex: 1 1 0; }
  .term-tips { flex: 1 1 0; }
  .term-mount .xterm { padding: 6px 6px 6px 10px; }
}

@media (prefers-reduced-motion: reduce) {
  .term-tip {
    animation: none;
    background: none;
    -webkit-text-fill-color: currentColor;
  }
}
