:root {
  color-scheme: dark;
  --bg: #0d1117;
  --bg2: #151b24;
  --bg3: #1c2430;
  --line: #2b3441;
  --fg: #dbe3ee;
  --dim: #8b97a8;
  --accent: #3d8bfd;
  --ok: #2ecc71;
  --warn: #f1c40f;
  --err: #e05a4f;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 13.5px/1.55 "Microsoft YaHei", "Segoe UI", system-ui, sans-serif;
}
.hidden { display: none !important; }
.muted { color: var(--dim); font-size: 12px; }
.spacer { flex: 1; }
.err { color: #ff9d9d; font-size: 12px; min-height: 16px; }

button {
  background: var(--bg3);
  color: var(--fg);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 5px 11px;
  cursor: pointer;
  font-size: 12.5px;
}
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.danger { color: #ff9d9d; border-color: #5c2a26; }
button.small { padding: 3px 8px; font-size: 11.5px; }

input, select {
  background: var(--bg);
  color: var(--fg);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 9px;
  font-size: 12.5px;
  font-family: inherit;
}
input:focus, select:focus { outline: 1px solid var(--accent); }

/* 登录 */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-card {
  width: 340px;
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 26px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.login-card h1 { font-size: 17px; margin: 0; }
.login-card label { display: flex; flex-direction: column; gap: 5px; font-size: 12px; color: var(--dim); }
.login-card button { margin-top: 6px; padding: 9px; }

/* 顶栏 */
.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 16px;
  background: var(--bg2);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; font-size: 14.5px; }
.tabs { display: flex; gap: 4px; }
.tabs button.active { border-color: var(--accent); color: #fff; background: #1d2a3d; }

.banner {
  margin: 10px 16px 0;
  padding: 9px 12px;
  border-radius: 8px;
  background: rgba(241, 196, 15, 0.1);
  border: 1px solid rgba(241, 196, 15, 0.35);
  color: #f6e3a1;
  font-size: 12.5px;
}

main { padding: 14px 16px 40px; overflow-x: hidden; }

/* 表格 */
table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
th, td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { color: var(--dim); font-weight: 500; font-size: 12px; }
tr:hover td { background: rgba(255, 255, 255, 0.02); }
.pill { padding: 1px 7px; border-radius: 999px; font-size: 11px; background: #26303d; color: var(--dim); }
.pill.ok { background: rgba(46, 204, 113, 0.16); color: #7fe0a6; }
.pill.err { background: rgba(224, 90, 79, 0.16); color: #ff9d94; }
.pill.warn { background: rgba(241, 196, 15, 0.16); color: #f0dc7a; }

.card {
  overflow-x: auto;
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px;
  margin-bottom: 14px;
}
.card h2 { font-size: 13px; margin: 0 0 10px; color: #fff; font-weight: 700; }
.form-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 8px; }
.form-row label { color: var(--dim); font-size: 12px; }
.num { width: 92px; }
.pnum { width: 68px; padding: 3px 5px; font-size: 11.5px; }
input:disabled { opacity: .45; }

/* 设备卡片 */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; }
.device {
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.device h3 { margin: 0; font-size: 13.5px; }
.device .meta { color: var(--dim); font-size: 11.5px; display: flex; flex-direction: column; gap: 2px; }
.device .actions { display: flex; gap: 6px; margin-top: auto; }

/* 投屏浮层 */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.72);
  display: grid;
  place-items: center;
  z-index: 50;
  padding: 12px;
}
.modal-box {
  background: var(--bg2);
  border: 1px solid var(--line);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  /* 必须给确定高度:否则 flex:1 的中间区会塌成 0,画面就被压没了 */
  height: calc(100vh - 24px);
  max-height: calc(100vh - 24px);
  overflow: hidden;
  width: auto;
  max-width: 96vw;
}
.modal-head { display: flex; align-items: center; gap: 10px; padding: 9px 12px; background: var(--bg3); flex: 0 0 auto; }
.modal-head span:first-child { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* 画面区吃掉「顶栏 + 底栏」剩下的全部高度;具体尺寸由 JS 按比例算(见 fitModal) */
.modal-body { flex: 1 1 auto; min-height: 0; background: #000; display: grid; place-items: center; overflow: hidden; }
.screen { position: relative; background: #000; width: auto; height: auto; }
.screen canvas { width: 100% !important; height: 100% !important; display: block; }

/* 安卓三键导航 */
.navbar {
  display: flex;
  gap: 10px;
  padding: 8px 12px;
  background: var(--bg3);
  border-top: 1px solid var(--line);
  justify-content: center;
  align-items: center;
}
.navbtn {
  flex: 1 1 0;
  min-width: 0;
  height: 40px;
  font-size: 17px;
  line-height: 1;
  background: #232c3a;
}
.navbtn:hover { background: #2c394b; }
.navbtn.more { flex: 0 0 44px; margin-left: 4px; font-size: 19px; }

/* 更多操作面板 */
.moremenu {
  padding: 10px 12px 12px;
  border-top: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--bg2);
}
.moremenu .mr-row { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.moremenu .mr-row button { padding: 6px 10px; font-size: 12px; }
.moremenu .mr-row input { flex: 1; min-width: 140px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 30px;
  transform: translateX(-50%);
  background: #222c3a;
  border: 1px solid var(--line);
  color: #fff;
  padding: 9px 16px;
  border-radius: 8px;
  font-size: 12.5px;
  z-index: 100;
}
.toast.err { border-color: #6b2b26; background: #3a1f1c; }
pre.code {
  background: #0a0e14;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  font: 11.5px/1.5 Consolas, monospace;
  max-height: 320px;
  overflow: auto;
  white-space: pre;
}

/* ---------- 总览 ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 14px; }
.stat { background: var(--bg2); border: 1px solid var(--line); border-radius: 10px; padding: 14px; }
.stat-num { font-size: 26px; font-weight: 700; line-height: 1.2; }
.stat-label { color: var(--dim); font-size: 12px; margin-top: 2px; }
.stat-sub { color: var(--dim); font-size: 11px; margin-top: 6px; }
.stat.ok .stat-num { color: #7fe0a6; }
.stat.warn .stat-num { color: #f0dc7a; }

/* ---------- 上手步骤 ---------- */
.steps { margin: 0; padding-left: 20px; color: var(--dim); font-size: 12.5px; line-height: 2; }
.steps code { background: #0a0e14; padding: 1px 5px; border-radius: 4px; color: var(--fg); }

/* ---------- 设备卡片 ---------- */
.dev-top { display: flex; align-items: center; gap: 7px; }
.dev-top h3 { margin: 0; font-size: 13.5px; flex: 1; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #555; display: inline-block; flex: 0 0 auto; }
.dot.ok { background: var(--ok); }
.device .actions .wide { width: 100%; padding: 8px; font-size: 13px; }
.device button:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- 小屏适配 ---------- */
@media (max-width: 980px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
  main { padding: 10px; }
  .card { padding: 10px; overflow-x: auto; }
  table { font-size: 12px; }
  th, td { padding: 6px 6px; }
  .tabs { flex-wrap: wrap; }
  .brand { font-size: 13px; }
  .topbar { gap: 8px; padding: 8px 10px; }
  .modal { padding: 0; }
  .modal-box { width: 100%; height: 100vh; max-height: 100vh; border-radius: 0; }
  .grid { grid-template-columns: 1fr; }
  /* 尺寸统一由 JS 按可用空间计算,这里不再固定高度 */
}
@media (max-width: 560px) {
  .stats { grid-template-columns: 1fr 1fr; }
  .stat-num { font-size: 20px; }
  .modal-foot button { flex: 1 0 auto; }
}

/* 屏幕高度不够时(笔记本 768/600),把工具栏压紧,把高度还给画面 */
@media (max-height: 820px) {
  .modal-head { padding: 6px 10px; }
  .navbar { padding: 5px 8px; gap: 6px; }
  .navbtn { height: 34px; font-size: 15px; }
  .navbtn.more { flex: 0 0 38px; font-size: 17px; }
  .moremenu { padding: 6px 8px 8px; gap: 6px; }
  .moremenu .mr-row button { padding: 4px 8px; font-size: 11.5px; }
  .moremenu .mr-row input { padding: 4px 8px; }
}

/* 弹窗宽度由 JS 贴合画面,导航可换行 */
.navbar { flex-wrap: nowrap; }
.navbtn { min-width: 0; }
.moremenu .mr-row button { flex: 1 0 auto; }

/* 画面两侧不要黑块;工具区收窄到与画面同宽 */
.modal-body { background: transparent; padding: 0; }
.moremenu .mr-row:first-child { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
.moremenu .mr-row:first-child button { width: 100%; }
.moremenu .mr-row:last-child input { min-width: 0; }

/* 手机上让画面按宽度铺满,不要按高度缩成一条 */
@media (max-width: 980px) {
  .modal-box { width: 100% !important; max-width: 100vw; }
  .modal-body { background: #000; }
  /* 同上:交给 fitModal 处理 */
}

/* 用户端电源按钮 */
.power-row { display: flex; gap: 6px; width: 100%; }
.power-row button { flex: 1; padding: 6px; }
.hintline { color: var(--dim); font-size: 11px; text-align: center; }

.dot.warn { background: var(--warn); }

.warnline { margin-top: 8px; padding: 8px 10px; border-radius: 8px; font-size: 12px; line-height: 1.7;
  background: rgba(241,196,15,.10); border: 1px solid rgba(241,196,15,.32); color: #f3e2a4; }

/* ==================== 手机端适配(竖屏 / 刘海屏 / 地址栏收缩) ==================== */
/* 1) 用 dvh 而不是 vh:手机浏览器地址栏会把 100vh 撑出可视区,底部按钮被切掉 */
.modal-box {
  height: calc(100vh - 24px);
  height: calc(100dvh - 24px);
  max-height: calc(100vh - 24px);
  max-height: calc(100dvh - 24px);
}
.login-wrap { min-height: 100vh; min-height: 100dvh; }

/* 2) 工具栏不再被标题挤掉:标题可压缩,按钮不许换行 */
.modal-head { gap: 8px; min-width: 0; }
.modal-head span:first-child { flex: 0 1 auto; min-width: 0; }
.modal-head .spacer { flex: 1 1 auto; }
.modal-head button { flex: 0 0 auto; }

@media (max-width: 980px) {
  .modal { padding: 0; place-items: stretch; }
  .modal-box {
    width: 100% !important;
    max-width: 100vw;
    height: 100vh;
    height: 100dvh;
    max-height: 100vh;
    max-height: 100dvh;
    border-radius: 0;
    border-left: 0;
    border-right: 0;
  }
  /* 刘海 / 底部手势条留白 */
  .modal-head { padding-top: calc(9px + env(safe-area-inset-top)); }
  .navbar { padding-bottom: calc(8px + env(safe-area-inset-bottom)); }
  .moremenu { padding-bottom: calc(12px + env(safe-area-inset-bottom)); }
  /* 触控目标放大到 44px,手指点得中 */
  .navbtn { height: 46px; font-size: 19px; }
  .navbtn.more { flex: 0 0 52px; }
  /* 顶栏 tab 横向滚动,不要换行占掉画面高度 */
  .tabs { flex-wrap: nowrap; overflow-x: auto; overflow-y: hidden; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
  .tabs::-webkit-scrollbar { display: none; }
  .topbar { flex-wrap: nowrap; overflow-x: auto; }
  .topbar .brand { flex: 0 0 auto; }
  /* 卡片里的按钮至少 40px 高,避免误触 */
  .device .actions button, .device button { min-height: 40px; }
  .moremenu .mr-row button { min-height: 40px; }
}

@media (max-width: 560px) {
  .topbar { padding: 8px; gap: 6px; }
  .brand { font-size: 13px; }
  .tabs button { padding: 6px 9px; font-size: 13px; }
  .modal-head { padding: 8px 10px; padding-top: calc(8px + env(safe-area-inset-top)); }
  .modal-head button { padding: 7px 10px; }
  main { padding: 8px; }
  .card { padding: 9px; }
  /* 手机上表格改为可横向滑动,不挤成一行字 */
  .card table { min-width: 520px; }
}

/* 3) 弹窗打开时锁住背景滚动(手机上否则会"底下的页面跟着动") */
body.modal-open { overflow: hidden; touch-action: none; }
body.modal-open .modal { touch-action: auto; }

/* 4) 横屏手机:把上下工具栏压薄,把高度让给画面 */
@media (max-height: 480px) and (orientation: landscape) {
  .modal-head { padding: 4px 8px; }
  .navbar { padding: 3px 6px; gap: 5px; }
  .navbtn { height: 34px; font-size: 15px; }
  .moremenu .mr-row button { padding: 3px 7px; font-size: 11px; min-height: 30px; }
}

/* 5) 手机顶栏改成两行:第一行品牌+账号+按钮,第二行标签(可横向滑动) */
@media (max-width: 620px) {
  .topbar {
    flex-wrap: wrap;
    row-gap: 6px;
    padding: 8px;
    align-items: center;
  }
  .topbar .spacer { display: none; }
  .topbar .brand { order: 1; flex: 1 1 auto; white-space: nowrap; }
  #whoami { order: 2; flex: 0 0 auto; font-size: 12px; max-width: 96px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  #btnPass { order: 3; flex: 0 0 auto; white-space: nowrap; padding: 6px 8px; font-size: 12px; }
  #btnLogout { order: 4; flex: 0 0 auto; white-space: nowrap; padding: 6px 8px; font-size: 12px; }
  #tabs { order: 5; flex: 1 1 100%; overflow-x: auto; overflow-y: hidden; -webkit-overflow-scrolling: touch; padding-bottom: 2px; }
  #tabs button {
    flex: 0 0 auto;
    white-space: nowrap;
    padding: 7px 12px;
    font-size: 13px;
  }
  /* 顶部提示条:允许换行,别被裁掉 */
  #banner { font-size: 12px; line-height: 1.45; }
  #banner .muted, #banner span { white-space: normal; }
}

/* 6) 页面级横向溢出:表格在卡片内自己滚,别把整页撑宽 */
html, body { max-width: 100%; overflow-x: hidden; }
@media (max-width: 620px) {
  .card { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .card table { min-width: 560px; }
  th, td { white-space: nowrap; }
  /* 表格里的长文本不要竖排 */
  .device-cell, td { word-break: keep-all; }
}

/* 7) 手机顶栏用 grid 彻底定死两行,杜绝溢出(替换之前的 flex 方案) */
@media (max-width: 620px) {
  .topbar {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) auto auto;
    grid-template-areas:
      "brand pass out"
      "tabs  tabs tabs";
    gap: 6px 8px;
    padding: 8px;
    align-items: center;
    overflow: hidden;
  }
  .topbar .brand { grid-area: brand; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
  .topbar .spacer { display: none !important; }
  #whoami { display: none !important; }
  #btnPass { grid-area: pass; padding: 6px 10px; font-size: 12px; white-space: nowrap; }
  #btnLogout { grid-area: out; padding: 6px 10px; font-size: 12px; white-space: nowrap; }
  #tabs {
    grid-area: tabs;
    display: flex;
    flex-wrap: nowrap;
    gap: 4px;
    min-width: 0;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  #tabs::-webkit-scrollbar { display: none; }
  #tabs button { flex: 0 0 auto; white-space: nowrap; padding: 7px 11px; font-size: 13px; }
}

/* 8) 顶部横幅里的长链接/代码会把整页撑宽(手机上是万恶之源) */
#banner {
  max-width: 100%;
  overflow-wrap: anywhere;
  word-break: break-word;
}
#banner code, #banner a, #banner b, #banner span, #banner div {
  white-space: normal !important;
  overflow-wrap: anywhere;
  word-break: break-word;
}
@media (max-width: 620px) {
  #banner { font-size: 12px; line-height: 1.5; padding: 8px 10px; }
}

/* 9) 强制把宽度收进视口:手机端所有层都不许超出 100vw */
@media (max-width: 620px) {
  html, body { width: 100%; max-width: 100vw; overflow-x: hidden; }
  #app { width: 100%; max-width: 100vw; overflow-x: hidden; }
  main { width: 100%; max-width: 100vw; overflow-x: hidden; }
  .topbar { width: 100% !important; max-width: 100vw; box-sizing: border-box; }
  #tabs { width: 100% !important; max-width: 100%; }
  #banner { width: 100%; max-width: 100%; box-sizing: border-box; }
}

/* 10) 手机端输入框:字号≥16px 防止 iOS 聚焦时自动放大页面;
       另外把输入框的"自动纠正/自动大写"关掉,避免一碰就弹键盘 */
@media (max-width: 620px) {
  input, textarea, select { font-size: 16px !important; }
  #textInput { font-size: 16px; }
}
input, textarea { -webkit-text-size-adjust: 100%; }
