:root {
  --bg: #f4f5f2;
  --panel: #ffffff;
  --panel-2: #f9faf8;
  --line: #e2e5df;
  --text: #1d2420;
  --muted: #66706a;
  --accent: #1f6f5c;
  --accent-ink: #ffffff;
  --ok: #1e8a4c;
  --ok-bg: #e5f4ea;
  --warn: #a86a00;
  --warn-bg: #fbf0d9;
  --bad: #c0392b;
  --bad-bg: #fbe7e4;
  --idle: #7b847f;
  --idle-bg: #eceeeb;
  --shadow: 0 1px 2px rgba(20, 30, 25, .06), 0 2px 8px rgba(20, 30, 25, .04);
  --radius: 12px;
  --mono: ui-monospace, "Cascadia Mono", Consolas, "SF Mono", Menlo, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121614;
    --panel: #1a1f1c;
    --panel-2: #161a18;
    --line: #2b322e;
    --text: #e4e9e5;
    --muted: #94a099;
    --accent: #4fb596;
    --accent-ink: #0e1512;
    --ok: #5fcf8a;
    --ok-bg: #18301f;
    --warn: #e0a83a;
    --warn-bg: #342a12;
    --bad: #f07a6a;
    --bad-bg: #3a1c18;
    --idle: #8d9792;
    --idle-bg: #232926;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.55 system-ui, -apple-system, "PingFang SC", "Microsoft YaHei", "Noto Sans SC", sans-serif;
}
a { color: var(--accent); }
button, select, input {
  font: inherit; color: inherit;
}
button {
  border: 1px solid var(--accent); background: var(--accent); color: var(--accent-ink);
  border-radius: 8px; padding: 6px 14px; cursor: pointer; white-space: nowrap; min-height: 34px;
}
button:hover { filter: brightness(1.06); }
button:disabled { opacity: .5; cursor: default; filter: none; }
button.ghost { background: transparent; color: var(--text); border-color: var(--line); }
button.ghost:hover { background: var(--panel-2); }
button.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
button.small { padding: 3px 10px; min-height: 30px; font-size: 13.5px; }
input, select {
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; min-height: 36px;
}
input:focus, select:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
label { display: grid; gap: 4px; font-size: 14px; color: var(--muted); margin: 10px 0; }
label input { color: var(--text); }
h1, h2, h3 { margin: 0; line-height: 1.3; }
.muted { color: var(--muted); }
.err { color: var(--bad); min-height: 1.2em; margin: 6px 0; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
[hidden] { display: none !important; }

/* 顶栏 */
.top {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 18px;
  padding: 10px max(16px, calc((100vw - 1100px) / 2)); background: var(--panel); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 650; font-size: 16.5px; }
.tabs { display: flex; gap: 4px; }
.tabs a { text-decoration: none; color: var(--muted); padding: 6px 12px; border-radius: 8px; }
.tabs a.on { color: var(--text); background: var(--panel-2); font-weight: 600; }
.me { margin-left: auto; display: flex; align-items: center; gap: 6px; font-size: 14px; }
.me #me-name { color: var(--muted); margin-right: 4px; }

main { max-width: 1100px; margin: 0 auto; padding: 18px 16px 60px; }

/* 登录 */
.login {
  max-width: 360px; margin: 12vh auto 0; background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 26px 24px; box-shadow: var(--shadow);
}
.login h1 { font-size: 21px; display: flex; gap: 8px; align-items: center; }
.login p { margin: 6px 0 14px; }
.login button { width: 100%; margin-top: 6px; }

/* 概要 */
.summary { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 14px; }
.chip { display: inline-flex; gap: 6px; align-items: center; padding: 4px 12px; border-radius: 99px; font-size: 14px; background: var(--panel); border: 1px solid var(--line); }
.chip b { font-variant-numeric: tabular-nums; }
.summary .updated { margin-left: auto; font-size: 13px; }

.alert {
  background: var(--bad-bg); border: 1px solid color-mix(in srgb, var(--bad) 35%, transparent); color: var(--text);
  border-radius: var(--radius); padding: 12px 16px; margin-bottom: 16px;
}
.alert h3 { font-size: 15px; color: var(--bad); margin-bottom: 4px; }
.alert ul { margin: 0; padding-left: 20px; }

/* 机器 */
.machine { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 18px; box-shadow: var(--shadow); overflow: hidden; }
.machine.offline { opacity: .8; }
.m-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 14px; padding: 14px 18px 10px; border-bottom: 1px solid var(--line); }
.m-head h2 { font-size: 17.5px; }
.m-stats { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 13.5px; color: var(--muted); }
.m-section { padding: 4px 18px 10px; }
.m-section > h3 { font-size: 13px; font-weight: 600; color: var(--muted); letter-spacing: .02em; margin: 12px 0 2px; }

.svc { display: grid; grid-template-columns: auto 1fr auto; gap: 4px 14px; align-items: center; padding: 11px 0; border-top: 1px solid var(--line); }
.m-section > h3 + .svc, details > .svc:first-of-type { border-top: 0; }
.svc .name { font-weight: 600; }
.svc .desc { color: var(--muted); font-size: 14px; }
.svc .meta { display: flex; flex-wrap: wrap; gap: 2px 14px; font-size: 13px; color: var(--muted); margin-top: 2px; }
.svc .meta a { word-break: break-all; }
.svc .acts { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }

.pill { display: inline-block; min-width: 58px; text-align: center; font-size: 13px; font-weight: 600; padding: 2px 10px; border-radius: 99px; align-self: start; margin-top: 2px; }
.pill.running { background: var(--ok-bg); color: var(--ok); }
.pill.stopped { background: var(--idle-bg); color: var(--idle); }
.pill.failed { background: var(--bad-bg); color: var(--bad); }
.pill.starting, .pill.busy { background: var(--warn-bg); color: var(--warn); }
.pill.unknown { background: var(--idle-bg); color: var(--idle); }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--idle); }
.dot.on { background: var(--ok); }
.dot.bad { background: var(--bad); }
.hl-bad { color: var(--bad); }
.hl-ok { color: var(--ok); }

details.more { margin-top: 6px; }
details.more summary { cursor: pointer; color: var(--muted); font-size: 13.5px; padding: 6px 0; }

/* AI 会话 */
.sess { display: grid; grid-template-columns: auto 1fr auto; gap: 2px 12px; align-items: center; padding: 9px 0; border-top: 1px solid var(--line); }
.m-section > h3 + .sess { border-top: 0; }
.sess-main { min-width: 0; }
.sess .tool { font-size: 12px; font-weight: 600; padding: 1px 8px; border-radius: 6px; border: 1px solid var(--line); color: var(--muted); }
.sess .t { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sess .p { font-size: 13px; color: var(--muted); }
.sess .when { font-size: 13px; color: var(--muted); text-align: right; white-space: nowrap; }
.sess .live { color: var(--ok); font-weight: 600; }

.empty { color: var(--muted); padding: 30px 0; text-align: center; }

/* 管理 */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; margin-bottom: 16px; box-shadow: var(--shadow); }
.card h2 { font-size: 16.5px; margin-bottom: 4px; }
.card > p { margin: 4px 0 12px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 8px 6px; border-top: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 500; font-size: 13px; border-top: 0; }
.table-wrap { overflow-x: auto; }
pre.code, pre.secret {
  font-family: var(--mono); font-size: 13px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px;
  padding: 10px 12px; white-space: pre-wrap; word-break: break-all; margin: 6px 0 12px;
}
pre.secret { font-size: 15px; }
.inline-form { display: flex; gap: 8px; flex-wrap: wrap; align-items: end; }
.inline-form label { margin: 0; }

/* 弹窗 */
.dlg { border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); color: var(--text); padding: 18px 20px; width: min(460px, calc(100vw - 32px)); }
.dlg.wide { width: min(980px, calc(100vw - 32px)); }
.dlg::backdrop { background: rgba(10, 15, 12, .45); }
.dlg h2 { font-size: 17px; margin-bottom: 8px; }
.dlg-head { display: flex; flex-wrap: wrap; gap: 8px; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.logs {
  font-family: var(--mono); font-size: 12.5px; line-height: 1.5; background: #0f1311; color: #d6e2db; border-radius: 8px;
  padding: 12px; margin: 0; height: min(65vh, 640px); overflow: auto; white-space: pre-wrap; word-break: break-all;
}

.toast {
  position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%) translateY(20px); opacity: 0; pointer-events: none;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; max-width: calc(100vw - 32px);
  transition: opacity .2s, transform .2s; z-index: 50; font-size: 14px; white-space: pre-wrap;
}
.toast.show { opacity: 1; transform: translateX(-50%); }
.toast.bad { background: var(--bad); color: #fff; }

@media (max-width: 640px) {
  .top { flex-wrap: wrap; gap: 8px 12px; padding: 10px 16px; }
  .me { width: 100%; margin-left: 0; }
  .me #me-name { margin-right: auto; }
  .svc { grid-template-columns: auto 1fr; }
  .svc .acts { grid-column: 1 / -1; justify-content: flex-start; }
  .sess { grid-template-columns: auto 1fr; }
  .sess .when { grid-column: 2; text-align: left; }
  .summary .updated { margin-left: 0; width: 100%; }
}
