/* 鸿蒙远程 DSH — 手机端样式
   设计取向：深色、信息密度高、单手可操作。
   不引外部字体与图标库：ArkWeb 里离线加载，任何外链都可能被网络策略拦掉。 */

:root {
  --bg: #0f1115;
  --bg-elev: #171a21;
  --bg-elev2: #1d2129;
  --line: #282e3a;
  --fg: #e6e9ef;
  --fg-dim: #8b93a7;
  --fg-faint: #5d6478;
  --accent: #5b8cff;
  --accent-dim: #2b3f6b;
  --warn: #f0b400;
  --danger: #ff5f57;
  --ok: #3ecf8e;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "HarmonyOS Sans SC", "PingFang SC",
        "Microsoft YaHei", sans-serif;
  overscroll-behavior-y: none;
}

body {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}

/* ── 顶栏 ─────────────────────────────────────── */
.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
  min-height: 52px;
}

.topbar h1 {
  font-size: 16px;
  font-weight: 600;
  margin: 0;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar .sub {
  font-size: 11px;
  color: var(--fg-faint);
  font-weight: 400;
  display: block;
  margin-top: 1px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

button {
  background: var(--bg-elev2);
  color: var(--fg);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 7px 12px;
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  flex: 0 0 auto;
  transition: background .12s;
}
button:active { background: var(--line); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.ghost { background: transparent; }
button.icon { padding: 7px 10px; }

/* ── 连接状态 ──────────────────────────────────── */
.statusbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 14px;
  font-size: 12px;
  color: var(--fg-dim);
  background: var(--bg-elev);
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}
.dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--fg-faint); flex: 0 0 auto;
  transition: background .2s;
}
.dot.online { background: var(--ok); box-shadow: 0 0 0 3px rgba(62,207,142,.15); }
.dot.connecting { background: var(--warn); animation: pulse 1.2s infinite; }
.dot.offline { background: var(--danger); }
@keyframes pulse { 50% { opacity: .35; } }

/* ── 内容区 ────────────────────────────────────── */
main { flex: 1 1 auto; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.view { display: none; }
.view.active { display: block; }

/* ── 会话列表 ──────────────────────────────────── */
.session {
  padding: 13px 14px;
  border-bottom: 1px solid var(--line);
  display: flex;
  gap: 11px;
  align-items: flex-start;
  cursor: pointer;
}
.session:active { background: var(--bg-elev); }

.session .proj {
  font: 10px/1.4 var(--mono);
  color: var(--fg-faint);
  margin-bottom: 3px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.session .title {
  font-size: 14.5px;
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  word-break: break-word;
}
.session .title.is-empty { color: var(--fg-faint); font-style: italic; }
.session .meta {
  font-size: 11px;
  color: var(--fg-faint);
  margin-top: 5px;
  display: flex;
  gap: 9px;
  align-items: center;
  flex-wrap: wrap;
}
.session .right {
  flex: 0 0 auto;
  text-align: right;
  font-size: 11px;
  color: var(--fg-faint);
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
  min-width: 58px;
}

.badge {
  font-size: 10px;
  padding: 1px 7px;
  border-radius: 20px;
  border: 1px solid currentColor;
  line-height: 1.6;
  white-space: nowrap;
}
.badge.running { color: var(--accent); }
.badge.waiting-approval { color: var(--warn); }
.badge.error { color: var(--danger); }
.badge.idle { color: var(--fg-faint); }

/* ── 消息流 ────────────────────────────────────── */
.messages { padding: 14px 14px 28px; display: flex; flex-direction: column; gap: 11px; }

.msg { display: flex; flex-direction: column; gap: 4px; max-width: 100%; }
.msg .who {
  font-size: 11px;
  color: var(--fg-faint);
  padding-left: 2px;
  display: flex;
  gap: 7px;
  align-items: center;
}
.msg .body {
  padding: 10px 13px;
  border-radius: 13px;
  white-space: normal;
  word-break: break-word;
  font-size: 14.5px;
  line-height: 1.62;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  overflow-wrap: anywhere;
}

/* markdown 元素（marked 生成） */
.msg .body > *:first-child { margin-top: 0; }
.msg .body > *:last-child { margin-bottom: 0; }
.msg .body p { margin: 7px 0; }
.msg .body h1, .msg .body h2, .msg .body h3, .msg .body h4 {
  font-size: 15px;
  font-weight: 650;
  margin: 14px 0 7px;
  color: #f2f5fa;
  line-height: 1.4;
}
.msg .body h1 { font-size: 17px; }
.msg .body ul, .msg .body ol { margin: 7px 0; padding-left: 21px; }
.msg .body li { margin: 3px 0; }
.msg .body blockquote {
  margin: 9px 0;
  padding: 2px 0 2px 11px;
  border-left: 3px solid var(--accent-dim);
  color: var(--fg-dim);
}
.msg .body hr { border: 0; border-top: 1px solid var(--line); margin: 14px 0; }
.msg .body a { color: var(--accent); text-decoration: none; word-break: break-all; }

/* 表格：屏幕上容易溢出，横滚而不是挤压 */
.msg .body table {
  border-collapse: collapse;
  font-size: 12.5px;
  margin: 9px 0;
  display: block;
  overflow-x: auto;
  max-width: 100%;
}
.msg .body th, .msg .body td {
  border: 1px solid var(--line);
  padding: 5px 9px;
  text-align: left;
  vertical-align: top;
}
.msg .body th { background: rgba(255,255,255,.045); font-weight: 600; white-space: nowrap; }
.msg.user .body { background: var(--accent-dim); border-color: #35507f; }
.msg.assistant .body { background: var(--bg-elev); }
.msg.system .body { background: transparent; border-style: dashed; color: var(--fg-dim); font-size: 13px; }

.msg .body code {
  font-family: var(--mono);
  font-size: 12.5px;
  background: rgba(255,255,255,.07);
  padding: 1px 5px;
  border-radius: 4px;
}
.msg .body pre {
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.5;
  background: #0b0d11;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  overflow-x: auto;
  margin: 7px 0;
  white-space: pre;
}
.msg .body pre code { background: none; padding: 0; }

/* ── 工具卡片 ──────────────────────────────────── */
.tool {
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--bg-elev);
  overflow: hidden;
  font-size: 13px;
}
.tool .head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 12px;
  cursor: pointer;
  user-select: none;
}
.tool .name {
  font-family: var(--mono);
  font-size: 12.5px;
  color: var(--accent);
  flex: 0 0 auto;
}
.tool .brief {
  flex: 1;
  color: var(--fg-faint);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: var(--mono);
}
.tool .chev { color: var(--fg-faint); font-size: 11px; transition: transform .15s; }
.tool.open .chev { transform: rotate(90deg); }
.tool .detail { display: none; border-top: 1px solid var(--line); }
.tool.open .detail { display: block; }
.tool .detail pre {
  margin: 0;
  padding: 10px 12px;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.5;
  color: var(--fg-dim);
  overflow-x: auto;
  white-space: pre;
  max-height: 340px;
  overflow-y: auto;
}
.tool .detail .label {
  font-size: 10px;
  color: var(--fg-faint);
  padding: 8px 12px 2px;
  text-transform: uppercase;
  letter-spacing: .06em;
}
.tool.error { border-color: rgba(255,95,87,.4); }
.tool.error .name { color: var(--danger); }

/* ── 分隔线 ────────────────────────────────────── */
.marker {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--fg-faint);
  font-size: 11px;
  margin: 4px 0;
}
.marker::before, .marker::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--line);
}
.marker.end .label { color: var(--fg-faint); }

/* ── 空态 / 配对 ───────────────────────────────── */
.empty {
  padding: 56px 26px;
  text-align: center;
  color: var(--fg-faint);
  font-size: 13.5px;
  line-height: 1.7;
}

.pair {
  padding: 26px 20px;
  max-width: 460px;
  margin: 0 auto;
}
.pair h2 { font-size: 19px; margin: 0 0 6px; }
.pair p { color: var(--fg-dim); font-size: 13px; line-height: 1.65; margin: 0 0 20px; }
.pair label { display: block; font-size: 12px; color: var(--fg-dim); margin: 14px 0 6px; }
.pair input {
  width: 100%;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 11px 13px;
  color: var(--fg);
  font-size: 14px;
  font-family: var(--mono);
}
.pair input:focus { outline: none; border-color: var(--accent); }
.pair button { width: 100%; margin-top: 20px; padding: 12px; font-size: 15px; }
.pair .hint { font-size: 11.5px; color: var(--fg-faint); margin-top: 14px; line-height: 1.6; }

/* ── 接管开关 ──────────────────────────────────── */
.lease-btn {
  margin-left: auto;
  padding: 3px 11px;
  height: 24px;
  border-radius: 12px;
  font-size: 11.5px;
  line-height: 1;
  background: transparent;
  border: 1px solid var(--line);
  color: var(--fg-dim);
  flex: 0 0 auto;
}
.lease-btn.on {
  background: var(--warn);
  border-color: var(--warn);
  color: #241d05;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* ── 审批横幅 ──────────────────────────────────── */
#approvals:empty { display: none; }

.approval {
  background: linear-gradient(180deg, #2a2313, #221d12);
  border-bottom: 1px solid #4a3c14;
  border-left: 3px solid var(--warn);
  padding: 11px 14px;
  animation: slidein .18s ease-out;
}
@keyframes slidein {
  from { transform: translateY(-100%); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.approval .ap-head {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--warn);
  margin-bottom: 6px;
}
.approval .ap-tool {
  font-family: var(--mono);
  font-weight: 600;
  font-size: 12.5px;
}
.approval .ap-left {
  margin-left: auto;
  color: #a08a4a;
  font-variant-numeric: tabular-nums;
}
.approval .ap-title {
  font-size: 14px;
  color: #f4e9c8;
  line-height: 1.45;
  word-break: break-word;
}
.approval .ap-cmd {
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.5;
  color: #cfc49c;
  background: rgba(0, 0, 0, .32);
  border: 1px solid #3d3319;
  border-radius: 8px;
  padding: 8px 10px;
  margin-top: 7px;
  max-height: 110px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-word;
}
.approval .ap-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}
.approval .ap-actions button {
  flex: 1;
  height: 38px;
  border-radius: 10px;
  font-size: 14px;
  border: 1px solid var(--line);
  background: var(--bg-elev2);
  color: var(--fg);
}
.approval .ap-allow {
  background: var(--warn) !important;
  border-color: var(--warn) !important;
  color: #241d05 !important;
  font-weight: 600;
}
.approval .ap-deny { color: #ff8a80 !important; border-color: #5a3330 !important; }
.approval .ap-note {
  font-size: 10.5px;
  color: #8d7c4d;
  margin-top: 7px;
  line-height: 1.5;
}

/* ── 底部输入（M2 启用，先占位禁用） ──────────────── */
/* 注意：display:flex 会覆盖 [hidden] 的 display:none，必须显式补一条 */
.composer[hidden] { display: none; }

.composer {
  flex: 0 0 auto;
  display: flex;
  gap: 8px;
  padding: 9px 12px;
  background: var(--bg-elev);
  border-top: 1px solid var(--line);
}
.composer input {
  flex: 1;
  background: var(--bg-elev2);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 9px 15px;
  color: var(--fg);
  font-size: 14px;
  font-family: inherit;
}
.composer input:disabled { opacity: .45; }
.composer input:focus { outline: none; border-color: var(--accent); }

.composer .stop {
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: 20px;
  background: var(--bg-elev2);
  border: 1px solid var(--line);
  color: var(--danger);
  font-size: 13px;
  line-height: 1;
  flex: 0 0 auto;
}
.composer .stop:active { background: rgba(255, 95, 87, .18); }

.toast {
  position: fixed;
  left: 50%;
  bottom: 84px;
  transform: translateX(-50%) translateY(12px);
  background: #2a2f3c;
  color: var(--fg);
  padding: 9px 16px;
  border-radius: 20px;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  z-index: 50;
  max-width: 82vw;
  text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }


/* ── 文件浏览 ─────────────────────────────────── */
.crumb {
  padding: 9px 14px;
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--fg-dim);
  background: var(--bg-elev);
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
  white-space: nowrap;
}
.crumb b { color: var(--accent); font-weight: 500; cursor: pointer; }

.fs-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 14px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  font-size: 14px;
}
.fs-item:active { background: var(--bg-elev); }
.fs-item .ico { font-size: 15px; flex: 0 0 auto; opacity: .8; }
.fs-item .nm {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.fs-item.dir .nm { color: var(--accent); }
.fs-item .sz {
  font-size: 11px;
  color: var(--fg-faint);
  font-variant-numeric: tabular-nums;
  flex: 0 0 auto;
}

/* 文件预览浮层 */
.fs-preview {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 60;
  display: flex;
  flex-direction: column;
}
.fs-preview[hidden] { display: none; }
.pv-head {
  display: flex;
  align-items: center;
  gap: 10px;
  /* fixed inset:0 的浮层不吃 body 的安全区 padding，得自己补：
     否则手机上头部钻到状态栏底下，"下载/关闭"按钮点不到 */
  padding: calc(10px + env(safe-area-inset-top)) 14px 10px;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--line);
  font-family: var(--mono);
  font-size: 12.5px;
  color: var(--fg-dim);
}
.pv-head span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pv-head button { flex: 0 0 auto; }
.fs-preview pre {
  flex: 1;
  margin: 0;
  padding: 14px;
  overflow: auto;
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.6;
  color: var(--fg);
  white-space: pre;
}

/* 文件视图底部上传条 */
.fs-foot {
  padding: 16px 14px 26px;
  display: flex;
  justify-content: center;
}
.fs-foot .ghost {
  padding: 9px 18px;
  border-radius: 10px;
  border: 1px dashed var(--line);
  background: transparent;
  color: var(--fg-dim);
  font-size: 13.5px;
}
.fs-foot .ghost:active { background: var(--bg-elev); }

/* 上传进度条：只有一个，因为手机上一次拖不了多个大文件 */
.up-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
  background: var(--bg-elev);
  border-top: 1px solid var(--line);
  font-size: 12px;
  color: var(--fg-dim);
  z-index: 70;
}
.up-bar .track {
  height: 3px;
  margin-top: 7px;
  border-radius: 2px;
  background: var(--line);
  overflow: hidden;
}
.up-bar .fill {
  height: 100%;
  width: 0;
  background: var(--accent);
  transition: width .15s linear;
}

/* ── 远控画面 ─────────────────────────────────── */
.rc {
  position: fixed;
  inset: 0;
  z-index: 90;
  background: #000;
  display: flex;
  flex-direction: column;
}

.rc-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  padding-top: calc(8px + env(safe-area-inset-top));
  background: rgba(18, 20, 26, .92);
  border-bottom: 1px solid var(--line);
  font-size: 12px;
  color: var(--fg-dim);
  flex: 0 0 auto;
  /* 缩放/画质/键盘按钮较多，手机上允许横向滑动，别把状态文字挤没 */
  overflow-x: auto;
  scrollbar-width: none;
}
.rc-bar::-webkit-scrollbar { display: none; }
.rc-live, .rc-status, .rc-fps { flex: 0 0 auto; white-space: nowrap; }

/* 常驻的"正在被控制"指示：桌面那头看不到这个，但手机上必须一直显示 */
.rc-live {
  color: #ff6b6b;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: .3px;
  animation: rc-blink 1.6s ease-in-out infinite;
}
@keyframes rc-blink { 0%, 100% { opacity: 1 } 50% { opacity: .45 } }

.rc-status { color: var(--fg-dim); }
.rc-status.bad { color: #ff8a8a; }
.rc-fps { color: var(--fg-faint); font-variant-numeric: tabular-nums; }
.rc-spacer { flex: 1; }

.rc-btn {
  padding: 5px 10px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--fg-dim);
  font-size: 12px;
  flex: 0 0 auto;
  white-space: nowrap;
}
.rc-zoom { min-width: 42px; text-align: center; }
.rc-btn.on { border-color: var(--accent); color: var(--accent); }
.rc-btn.danger { border-color: #6b2b2b; color: #ff8a8a; }
.rc-btn:active { background: rgba(255, 255, 255, .06); }

.rc-stage {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  touch-action: none;   /* 关键：否则拖拽会变成页面滚动 */
  background: #000;
}

.rc-canvas {
  display: block;
  image-rendering: auto;
}

/* 键盘承接输入法：不能 display:none，否则无法聚焦 */
.rc-kbd {
  position: absolute;
  left: -9999px;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.rc-hint {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(18px + env(safe-area-inset-bottom));
  padding: 0 14px;
  text-align: center;
  font-size: 12px;
  line-height: 1.65;
  white-space: pre-line;   /* 手势说明分两行 */
  color: rgba(255, 255, 255, .55);
  pointer-events: none;
  transition: opacity .6s;
}

/* ── 全局「屏幕接管」入口（会话列表上方，不属于任何会话） ── */
.screen-launcher {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 12px 12px 4px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: linear-gradient(135deg, rgba(91, 140, 255, .12), rgba(91, 140, 255, .03));
}
.screen-launcher.offline { opacity: .55; }
.sl-icon {
  font-size: 26px;
  line-height: 1;
  flex: 0 0 auto;
}
.sl-text {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.sl-text strong { font-size: 14.5px; color: var(--fg); }
.sl-text span {
  font-size: 11.5px;
  color: var(--fg-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.screen-launcher button { flex: 0 0 auto; }
button:disabled { opacity: .45; cursor: default; }

/* 多桌面选择层 */
.desktop-pick {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
  max-height: 46vh;
  overflow-y: auto;
}
.dp-item {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 3px;
  text-align: left;
  padding: 11px 12px;
}
.dp-item strong { font-size: 14px; color: var(--fg); }
.dp-item span { font-size: 11px; color: var(--fg-faint); word-break: break-all; }

/* 页面内确认层（替代 window.confirm，ArkWeb 里 confirm 会被静默吞掉） */
.sheet-mask {
  position: fixed;
  inset: 0;
  z-index: 120;
  background: rgba(0, 0, 0, .62);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 18px;
  padding-bottom: calc(18px + env(safe-area-inset-bottom));
}
.sheet {
  width: 100%;
  max-width: 420px;
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 18px;
}
.sheet h3 { margin: 0 0 10px; font-size: 16px; }
.sheet p { margin: 0 0 18px; font-size: 13.5px; line-height: 1.65; color: var(--fg-dim); }
.sheet-actions { display: flex; gap: 10px; }
.sheet-actions button { flex: 1; padding: 11px; border-radius: 11px; font-size: 14.5px; }
