/* 大总管 控制台 — 深色为主，跟随系统浅色。无外部字体。 */
:root {
  --bg: #0d0e10;
  --panel: #131418;
  --panel-2: #1a1c21;
  --line: #262931;
  --text: #e7e8ea;
  --muted: #8b909a;
  --faint: #5c616b;
  --accent: #7c9cff;
  --accent-bg: rgba(124, 156, 255, 0.14);
  --ok: #4fc28a;
  --ok-bg: rgba(79, 194, 138, 0.14);
  --warn: #e3b341;
  --warn-bg: rgba(227, 179, 65, 0.14);
  --bad: #f0626b;
  --bad-bg: rgba(240, 98, 107, 0.14);
  --info: #6cb6ff;
  --radius: 8px;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "PingFang SC", "Hiragino Sans GB", "Noto Sans CJK SC", "Microsoft YaHei", sans-serif;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f6f7f9;
    --panel: #ffffff;
    --panel-2: #f0f2f5;
    --line: #e1e4ea;
    --text: #17191d;
    --muted: #5f6672;
    --faint: #9aa0aa;
    --accent: #3f63e0;
    --accent-bg: rgba(63, 99, 224, 0.1);
    --ok: #1f8f5c;
    --ok-bg: rgba(31, 143, 92, 0.1);
    --warn: #a16a00;
    --warn-bg: rgba(161, 106, 0, 0.1);
    --bad: #c8333d;
    --bad-bg: rgba(200, 51, 61, 0.1);
    --info: #1f6fd1;
    color-scheme: light;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }

.app {
  display: grid;
  grid-template-columns: 272px minmax(0, 1fr) 340px;
  grid-template-rows: auto auto auto 1fr;
  grid-template-areas:
    "top top top"
    "banner banner banner"
    "error error error"
    "left center right";
  height: 100vh;
}

/* 顶栏 */
.topbar {
  grid-area: top;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}
.brand { display: flex; align-items: baseline; gap: 8px; }
.brand-mark {
  width: 10px; height: 10px; border-radius: 3px;
  background: var(--accent);
  align-self: center;
}
.brand-name { font-weight: 650; letter-spacing: 0.02em; }
.brand-sub { color: var(--muted); font-size: 12px; }
.topbar-meta { display: flex; gap: 10px; align-items: center; flex: 1; min-width: 0; color: var(--muted); font-size: 12px; }
.source { padding: 2px 8px; border-radius: 999px; border: 1px solid var(--line); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 40ch; }
.source[data-kind="sample"] { color: var(--warn); background: var(--warn-bg); border-color: transparent; }
.source[data-kind="live"] { color: var(--ok); background: var(--ok-bg); border-color: transparent; }
.topbar-actions { display: flex; gap: 8px; }

.banner { margin: 0; padding: 8px 16px; font-size: 13px; color: var(--warn); background: var(--warn-bg); border-bottom: 1px solid var(--line); }
#stale-banner { grid-area: banner; }
.banner.bad { grid-area: error; color: var(--bad); background: var(--bad-bg); }

/* 按钮 */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-2);
  cursor: pointer;
  font-size: 13px;
  white-space: nowrap;
}
.btn:hover { border-color: var(--faint); }
.btn.ghost { background: transparent; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); }
button:focus-visible, select:focus-visible, textarea:focus-visible, .btn:focus-within {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* 栏位 */
.pane { overflow-y: auto; padding: 14px; min-width: 0; }
.left { grid-area: left; background: var(--panel); border-right: 1px solid var(--line); }
.center { grid-area: center; padding: 18px 22px; }
.right { grid-area: right; background: var(--panel); border-left: 1px solid var(--line); }
.pane-title {
  margin: 14px 4px 8px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}
.pane-title:first-child { margin-top: 2px; }
.count { color: var(--faint); font-variant-numeric: tabular-nums; font-weight: 500; }
.note { color: var(--faint); font-size: 12px; margin: 16px 4px 0; }
.empty { color: var(--faint); font-size: 13px; margin: 4px 6px 8px; }
.muted { color: var(--faint); }

/* 机器 */
.machine-list { display: flex; flex-direction: column; gap: 2px; }
.machine {
  display: flex; align-items: center; gap: 8px;
  width: 100%;
  padding: 6px 8px;
  border: 0; border-radius: 6px;
  background: transparent;
  text-align: left;
  cursor: pointer;
}
.machine:hover { background: var(--panel-2); }
.machine.active { background: var(--accent-bg); }
.machine-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* 状态点 */
.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; background: var(--faint); }
.dot-on, .st-working { background: var(--ok); }
.dot-off { background: transparent; border: 1.5px solid var(--faint); }
.st-idle { background: var(--info); }
.st-blocked { background: var(--bad); }
.st-stale { background: var(--warn); }
.st-ended, .st-unknown { background: var(--faint); }
.dot.st-working { box-shadow: 0 0 0 3px var(--ok-bg); }

/* 会话 */
.group { margin-bottom: 6px; }
.group-title {
  display: flex; justify-content: space-between;
  margin: 10px 6px 4px;
  font-size: 12px; font-weight: 600; color: var(--muted);
}
.session {
  display: block;
  width: 100%;
  padding: 8px 10px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  text-align: left;
  cursor: pointer;
}
.session:hover { background: var(--panel-2); }
.session.active { background: var(--panel-2); border-color: var(--line); }
.session-row { display: flex; align-items: center; gap: 8px; }
.session-title { flex: 1; min-width: 0; font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.session-ago { color: var(--faint); font-size: 11px; white-space: nowrap; }
.session-sub { display: block; margin: 2px 0 0 16px; color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* 中栏 */
.session-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.session-head h2 { margin: 0; font-size: 18px; font-family: var(--mono); font-weight: 600; word-break: break-all; }
.badge { padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; color: #fff; }
.badge.st-idle { color: #fff; }
.meta {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  gap: 6px 16px;
  margin: 0 0 8px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
}
.meta dt { color: var(--muted); font-size: 12px; padding-top: 1px; }
.meta dd { margin: 0; font-family: var(--mono); font-size: 13px; word-break: break-all; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 18px; }
.section-head .pane-title { margin: 0 4px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.seg button { border: 0; background: transparent; padding: 4px 10px; font-size: 12px; cursor: pointer; color: var(--muted); }
.seg button[aria-pressed="true"] { background: var(--panel-2); color: var(--text); }

.task-list { display: flex; flex-direction: column; gap: 10px; margin-top: 10px; }
.task {
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
}
.task.linked { border-color: var(--accent); box-shadow: inset 3px 0 0 var(--accent); }
.task-top { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.task-id { font-family: var(--mono); font-size: 12px; color: var(--muted); }
.task-title { flex: 1; min-width: 12ch; font-weight: 600; }
.pill {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  border: 1px solid var(--line);
  font-size: 11px;
  font-family: var(--mono);
  color: var(--muted);
  white-space: nowrap;
}
.pill.muted { font-family: var(--sans); color: var(--faint); border-style: dashed; }
.pill.warn { color: var(--warn); background: var(--warn-bg); border-color: transparent; }
.pill.bad { color: var(--bad); background: var(--bad-bg); border-color: transparent; }

.stages { display: flex; gap: 4px; margin-top: 10px; flex-wrap: wrap; }
.stage {
  flex: 1 1 0;
  min-width: 64px;
  padding: 3px 6px;
  border-radius: 4px;
  background: var(--panel-2);
  color: var(--faint);
  font-size: 11px;
  text-align: center;
  white-space: nowrap;
}
.stage.done { color: var(--ok); background: var(--ok-bg); }
.stage.current { color: #fff; background: var(--accent); font-weight: 600; }
.stage.off { opacity: 0.5; }

.gates { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; align-items: center; }
.gate {
  display: inline-flex; gap: 6px; align-items: center;
  padding: 2px 8px 2px 4px;
  border-radius: 999px;
  font-size: 11px;
  border: 1px solid var(--line);
  color: var(--muted);
}
.gate b { font-family: var(--mono); padding: 0 5px; border-radius: 999px; background: var(--panel-2); color: var(--text); font-weight: 600; }
.gate.ok { color: var(--ok); border-color: transparent; background: var(--ok-bg); }
.gate.bad { color: var(--bad); border-color: transparent; background: var(--bad-bg); }
.gate.none { border-style: dashed; color: var(--faint); }

.alerts { list-style: none; margin: 8px 0 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.alerts li { font-size: 12px; padding: 4px 8px; border-radius: 4px; }
.alerts li.bad { color: var(--bad); background: var(--bad-bg); }
.alerts li.warn { color: var(--warn); background: var(--warn-bg); }

.task-foot { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 2px 12px; margin: 10px 0 0; font-size: 12px; }
.task-foot dt { color: var(--faint); }
.task-foot dd { margin: 0; color: var(--muted); }

/* 右栏：派单 */
.form { display: flex; flex-direction: column; gap: 10px; }
.form label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.form select, .form input, .form textarea {
  width: 100%;
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
}
.form input[readonly] { color: var(--muted); font-family: var(--mono); font-size: 12px; }
.form textarea { resize: vertical; min-height: 96px; line-height: 1.5; }
.warn-list { list-style: none; margin: 0; padding: 8px 10px; border-radius: 6px; background: var(--warn-bg); color: var(--warn); font-size: 12px; display: flex; flex-direction: column; gap: 2px; }
.draft-msg { min-height: 1.5em; margin: 10px 0 6px; font-size: 12px; color: var(--muted); }
.draft-msg.bad { color: var(--bad); }
.draft {
  margin: 0;
  padding: 10px 12px;
  border-radius: 6px;
  background: var(--bg);
  border: 1px solid var(--line);
  font: 12px/1.55 var(--mono);
  white-space: pre-wrap;
  word-break: break-all;
  min-height: 3em;
}
.draft:empty { display: none; }
.draft-actions { display: flex; gap: 8px; margin-top: 8px; }

/* 窄屏：纵向堆叠 */
@media (max-width: 1080px) {
  .app { grid-template-columns: 240px minmax(0, 1fr); grid-template-areas: "top top" "banner banner" "error error" "left center" "right right"; height: auto; min-height: 100vh; }
  .right { border-left: 0; border-top: 1px solid var(--line); }
}
@media (max-width: 720px) {
  .app { grid-template-columns: minmax(0, 1fr); grid-template-areas: "top" "banner" "error" "left" "center" "right"; }
  .topbar { flex-wrap: wrap; padding: 10px 16px; }
  .topbar-meta { order: 3; flex-basis: 100%; }
  .pane, .center { padding: 14px 16px; overflow: visible; }
  .left { border-right: 0; border-bottom: 1px solid var(--line); }
}
