/* Andromate 群控台样式
 *
 * 深色是刻意选的：19 宫格 + 视频流是长时间盯着看的场景，
 * 深色底能显著降低眩光，且与设备画面的对比更清晰。
 */

:root {
  --bg: #0f1115;
  --panel: #171a21;
  --panel2: #1e232d;
  --line: #252a35;
  --fg: #e8eaed;
  --dim: #9aa3b2;
  --ok: #3ddc97;
  --warn: #ffb020;
  --err: #ff5c5c;
  --pri: #2563a8;
}

* { box-sizing: border-box; }

/* ★ 通用兜底：任何带 hidden 属性的元素都必须真正隐藏。
   .login/.focus/.tile-spinner 都自带 display 声明，
   会覆盖 [hidden] 的浏览器默认 display:none（实测导致
   「点关闭无反应」）。这一条把全站的坑一次性堵住，
   以后新增带 display 的元素不会再犯同样的错。 */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font: 14px/1.55 -apple-system, "Segoe UI", "PingFang SC",
        "Microsoft YaHei", sans-serif;
}

button {
  padding: 7px 12px;
  background: var(--panel2);
  color: var(--fg);
  border: 1px solid var(--line);
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
}
button:hover { background: #262c38; }
button.pri { background: var(--pri); border-color: var(--pri); }
button.pri:hover { background: #2f74bd; }
button.danger { border-color: #6b2b2b; color: #ffb3b3; }
button.danger:hover { background: #3a1f1f; }
button.rec { border-color: #6b4a2b; color: #ffd8a8; }
button.rec.recording { background: #7a2020; border-color: var(--err); color: #fff; }
button.on { background: var(--pri); border-color: var(--pri); }
button.block { width: 100%; margin: 6px 0; }
button.ghost { border-color: var(--line); color: var(--dim); }
button.ghost:hover { color: var(--fg); }
button:disabled { opacity: .55; cursor: default; }

input, select {
  padding: 6px 8px;
  background: #0b0d11;
  color: var(--fg);
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 13px;
  min-width: 0;
}
input:focus, select:focus { outline: none; border-color: #3a6ea5; }
input.range { padding: 0; width: 110px; }

.muted { color: var(--dim); }
.tiny { font-size: 12px; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.spacer { flex: 1; }

.pill {
  padding: 3px 10px;
  border-radius: 11px;
  font-size: 12px;
  border: 1px solid var(--line);
  color: var(--dim);
  white-space: nowrap;
}
.pill.ok { color: var(--ok); border-color: var(--ok); }
.pill.warn { color: var(--warn); border-color: var(--warn); }
.pill.err { color: var(--err); border-color: var(--err); }

/* ---------- 登录 ---------- */

.login {
  display: grid;
  place-items: center;
  height: 100%;
}
/* 同 .focus[hidden]：display:grid 会覆盖 hidden 属性的
   display:none，必须显式声明。 */
.login[hidden] { display: none; }
.login-card {
  width: 380px;
  padding: 28px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
}
.login-card h1 { margin: 0 0 4px; font-size: 20px; }
.login-card label { display: block; margin: 18px 0 6px; font-size: 12px; color: var(--dim); }
.login-card .errmsg { color: var(--err); min-height: 20px; font-size: 13px; }
/* 运维 Token 入口收进折叠区：日常用账号口令，
   Token 只是排障/脚本化的旁路，不该占据首屏。 */
.login-extra { margin-top: 16px; }
.login-extra summary { cursor: pointer; color: var(--dim); }
.login-extra label { margin-top: 12px; }
code { background: #0b0d11; padding: 1px 5px; border-radius: 3px; }

/* ---------- 布局 ---------- */

header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
header h1 { font-size: 16px; margin: 0; font-weight: 600; }

main {
  display: grid;
  grid-template-columns: 1fr 340px;
  height: calc(100vh - 47px);
}

.stage {
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding: 12px 16px;
  gap: 8px;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.hint { color: var(--dim); font-size: 12px; }

/* ---------- 宫格 ---------- */

.grid {
  flex: 1;
  overflow: auto;
  position: relative;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
  align-content: start;
  padding-bottom: 8px;
}

.tile {
  position: relative;
  background: #000;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  cursor: pointer;
  aspect-ratio: 9 / 16;
}
.tile canvas {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
}
.tile:hover { border-color: #3a6ea5; }
.tile.selected {
  border-color: var(--ok);
  box-shadow: 0 0 0 2px rgba(61, 220, 151, .35);
}
.tile[data-state="failed"], .tile[data-state="stalled"] {
  border-color: var(--err);
}
.tile[data-state="idle"] { opacity: .6; }
/* 有错误的格子加角标，一眼能看出哪台出问题 */
.tile[data-err] .tile-spinner {
  color: var(--err);
  font-size: 11px;
  padding: 8px;
  text-align: center;
  line-height: 1.4;
}

.tile-label {
  position: absolute;
  left: 0; top: 0;
  padding: 2px 7px;
  background: rgba(0, 0, 0, .62);
  font-size: 12px;
  border-bottom-right-radius: 6px;
}
.tile-meta {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  padding: 2px 6px;
  background: rgba(0, 0, 0, .62);
  font-size: 11px;
  color: var(--dim);
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.tile-spinner {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--dim);
  font-size: 12px;
  background: #0b0d11;
}
.tile[data-stream="live"] .tile-spinner { display: none; }

.tile-badge {
  position: absolute;
  right: 4px; top: 4px;
  padding: 1px 5px;
  font-size: 10px;
  border-radius: 4px;
  background: rgba(0, 0, 0, .6);
  color: var(--ok);
}
.tile-badge.warn { color: var(--warn); }
.tile-badge:empty { display: none; }

.marquee {
  position: absolute;
  border: 1px solid var(--ok);
  background: rgba(61, 220, 151, .12);
  pointer-events: none;
  z-index: 20;
}
.grid.select-mode .tile { cursor: crosshair; }

/* ---------- 右栏 ---------- */

.panel {
  border-left: 1px solid var(--line);
  background: var(--panel);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.tabs { display: flex; border-bottom: 1px solid var(--line); }
.tab { flex: 1; border: none; border-radius: 0; background: transparent; color: var(--dim); }
.tab.on { background: var(--panel2); color: var(--fg); box-shadow: inset 0 -2px 0 var(--pri); }

.tabpane { display: none; padding: 14px; overflow: auto; flex: 1; }
.tabpane.on { display: block; }

.tabpane h3 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--dim);
  margin: 18px 0 8px;
}
.tabpane h3:first-child { margin-top: 0; }

.row { display: flex; gap: 6px; align-items: center; margin: 6px 0; flex-wrap: wrap; }
.row label { font-size: 12px; color: var(--dim); white-space: nowrap; }
.row input[type="number"] { width: 74px; }
.row4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin: 6px 0; }

.keys { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }

.list { display: flex; flex-direction: column; gap: 5px; margin: 6px 0; }

.group, .script, .run {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 6px 8px;
  background: var(--panel2);
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 13px;
}
.group .gname, .script .sname, .run .rname {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.gcount, .scount, .smode { color: var(--dim); font-size: 12px; }
.gacts, .sacts { display: flex; gap: 4px; }
.gacts button, .sacts button, .run button { padding: 3px 7px; font-size: 11px; }
.dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }

.rbar {
  flex: 1;
  height: 5px;
  background: #0b0d11;
  border-radius: 3px;
  overflow: hidden;
}
.rbar i { display: block; height: 100%; background: var(--pri); }
.run.done .rbar i { background: var(--ok); }
.run.failed .rbar i, .run.stopped .rbar i { background: var(--err); }
.rstat { font-size: 11px; color: var(--dim); white-space: nowrap; }

.steps {
  max-height: 170px;
  overflow: auto;
  background: #0b0d11;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 7px;
  font: 12px/1.6 ui-monospace, Consolas, monospace;
}
.step { color: var(--dim); }

.alert {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 6px 8px;
  border-radius: 6px;
  border-left: 3px solid var(--dim);
  background: var(--panel2);
  font-size: 12px;
  cursor: pointer;
}
.alert.critical { border-left-color: var(--err); }
.alert.warn { border-left-color: var(--warn); }
.alert.info { border-left-color: #4a9eda; }
.alert.acked { opacity: .45; }
.alert .sev { font-weight: 600; }
.alert.critical .sev { color: var(--err); }
.alert.warn .sev { color: var(--warn); }
.alert.info .sev { color: #4a9eda; }
.alert .serial { color: var(--fg); }
.alert .msg { flex: 1; color: var(--dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.alert .dur { color: var(--dim); font-size: 11px; }

/* ---------- 单台放大 ---------- */

.focus {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .72);
  display: grid;
  place-items: center;
  z-index: 50;
}
/* ★ 必须显式盖掉 display:grid —— .focus 规则里的 display 会
   覆盖 [hidden] 的默认 display:none，导致点「关闭」后弹窗
   仍在（实测点按钮无反应，DOM 里节点一直存在）。
   这类「元素用 hidden 属性控制显隐 + 自身带 display 声明」
   的组合是隐藏属性失效的经典原因。 */
.focus[hidden] { display: none; }
.focus-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px;
  /* 放大窗现在还带按键条和提示，宽度按内容撑开即可，
     不写死像素宽度——写死会在小屏上溢出。 */
  max-width: 94vw;
  max-height: 94vh;
  overflow: auto;
}
.focus-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}
/* 画面 + 提示叠在一起。提示做成覆盖层，
   这样它不占额外高度，放大窗的纵向空间全留给画面。 */
.focus-stage {
  position: relative;
  width: 340px;
}
.focus-card canvas {
  display: block;
  width: 340px;
  height: 604px;
  background: #000;
  border-radius: 8px;
  border: 1px solid var(--line);
  cursor: crosshair;
  /* 关键：画面本身是控制面板，必须吃掉自身的文字选择与
     触摸滚动，否则双击会选中文本、长按会弹出右键菜单。 */
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}
.focus-hint {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 8px;
  text-align: center;
  font-size: 12px;
  color: #cfe3ff;
  background: rgba(0, 0, 0, .55);
  border-radius: 6px;
  padding: 3px 0;
  pointer-events: none;   /* 不能挡住画面上的点击 */
  opacity: .9;
}
.focus-keys {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  flex-wrap: wrap;
  justify-content: center;
}
.focus-keys button {
  padding: 8px 14px;
  font-size: 13px;
}
#focusMeta { margin-top: 8px; }

/* ---------- 日志 ---------- */

.log {
  position: fixed;
  right: 350px;
  bottom: 8px;
  width: 420px;
  max-height: 130px;
  overflow: auto;
  background: rgba(11, 13, 17, .93);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 7px 9px;
  font: 11px/1.6 ui-monospace, Consolas, monospace;
  color: var(--dim);
  z-index: 40;
  pointer-events: none;
}

@media (max-width: 1100px) {
  main { grid-template-columns: 1fr; }
  .panel { border-left: none; border-top: 1px solid var(--line); }
  .log { display: none; }
}