:root {
  --bg: #f4f5f7; --surface: #ffffff; --surface-2: #f8f9fb; --text: #18202b; --muted: #677487; --line: #e2e6ec;
  --primary: #2563eb; --primary-hover: #1d4ed8; --primary-soft: #e8efff; --on-primary: #ffffff;
  --ok: #15803d; --ok-soft: #e7f6ec; --warn: #b45309; --warn-soft: #fdf3e2; --danger: #c2261d; --danger-soft: #fdecea;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1117; --surface: #161b22; --surface-2: #1c222b; --text: #e6edf3; --muted: #8b97a6; --line: #2a313c;
    --primary: #4f8cff; --primary-hover: #6b9eff; --primary-soft: #1a2a48; --on-primary: #ffffff;
    --ok: #4ade80; --ok-soft: #12301f; --warn: #fbbf24; --warn-soft: #36290f; --danger: #ff8a80; --danger-soft: #3a1c1b;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text);
  font: 14px/1.6 system-ui, -apple-system, "Segoe UI", "Microsoft YaHei", sans-serif; }
[hidden] { display: none !important; }
h1, h2, h3, p { margin: 0; }
.mono { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; }
.muted { color: var(--muted); }

input, textarea, button { font: inherit; color: inherit; }
input, textarea { width: 100%; background: var(--surface); border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 11px; transition: border-color .15s, box-shadow .15s; }
input::placeholder, textarea::placeholder { color: var(--muted); opacity: .8; }
input:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
textarea { resize: vertical; line-height: 1.6; }
button { cursor: pointer; }
button:disabled { opacity: .55; cursor: not-allowed; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

/* 顶栏 */
.topbar { background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10; }
.topbar-inner { max-width: 1120px; margin: 0 auto; padding: 12px 24px; display: flex; flex-wrap: wrap;
  align-items: center; justify-content: space-between; gap: 12px 24px; }
.brand { display: flex; align-items: center; gap: 12px; }
.logo { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--primary), #7c3aed); color: #fff; }
.logo svg { width: 20px; height: 20px; }
.brand h1 { font-size: 16px; line-height: 1.2; }
.brand p { font-size: 12px; color: var(--muted); }
.connection { display: flex; align-items: center; gap: 8px; }
.icon-button { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 8px;
  border: 1px solid var(--line); background: var(--surface); color: var(--muted); }
.icon-button:hover { color: var(--text); background: var(--surface-2); }
.icon-button svg { width: 16px; height: 16px; }
.icon-button.spinning svg { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.page { max-width: 1120px; margin: 0 auto; padding: 20px 24px 40px; display: flex; flex-direction: column; gap: 16px; }

/* 概览卡片 */
.tiles { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; }
.tile { text-align: left; display: flex; flex-direction: column; gap: 2px; padding: 14px 16px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow); transition: border-color .15s, transform .15s; }
.tile:hover { border-color: var(--primary); transform: translateY(-1px); }
.tile-label { font-size: 12px; color: var(--muted); }
.tile-value { font-size: 17px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile-value.ok { color: var(--ok); } .tile-value.warn { color: var(--warn); } .tile-value.danger { color: var(--danger); }
.tile-sub { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-height: 1.6em; }

/* 标签页 */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); }
.tab { border: 0; background: none; padding: 8px 14px; color: var(--muted); font-weight: 500;
  border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tab:hover { color: var(--text); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }

/* 卡片 */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 20px; display: flex; flex-direction: column; gap: 14px; }
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; }
.card-head h2 { font-size: 16px; }
.desc { color: var(--muted); font-size: 13px; margin-top: 4px; }
.card-foot { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding-top: 14px; border-top: 1px solid var(--line); }
.spacer { flex: 1; }
.sub-title { font-size: 13px; color: var(--muted); font-weight: 600; }

.badge { flex: none; font-size: 12px; font-weight: 500; padding: 2px 10px; border-radius: 999px;
  background: var(--surface-2); color: var(--muted); border: 1px solid var(--line); white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.badge.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.badge.danger { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.badge.info { background: var(--primary-soft); color: var(--primary); border-color: transparent; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field-label { font-size: 13px; font-weight: 500; display: flex; justify-content: space-between; }
.counter { font-weight: 400; color: var(--muted); font-size: 12px; }
.hint { color: var(--muted); font-size: 13px; }
.hint.center { text-align: center; margin-top: 12px; }
.row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-top: 12px; }

.button { border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: 7px 16px; font-weight: 500; }
.button:hover:not(:disabled) { background: var(--surface-2); }
.button.primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.button.primary:hover:not(:disabled) { background: var(--primary-hover); }
.button.link { border: 0; background: none; color: var(--muted); padding: 7px 4px; }
.button.link:hover:not(:disabled) { color: var(--danger); background: none; }

/* 开关 */
.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; font-weight: 500; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.track { width: 40px; height: 22px; border-radius: 999px; background: var(--line); position: relative; transition: background .15s; }
.thumb { position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .3); transition: transform .15s; }
.switch input:checked + .track { background: var(--ok); }
.switch input:checked + .track .thumb { transform: translateX(18px); }
.switch input:focus-visible + .track { outline: 2px solid var(--primary); outline-offset: 2px; }

/* 分段选择 */
.segmented { display: inline-flex; flex-wrap: wrap; padding: 3px; gap: 2px; border-radius: 9px; background: var(--surface-2); border: 1px solid var(--line); }
.segmented button { border: 0; background: none; padding: 4px 12px; border-radius: 6px; color: var(--muted); font-size: 13px; }
.segmented button:hover { color: var(--text); }
.segmented button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); font-weight: 500; }

/* 故障监测 */
.meter { padding: 16px; border-radius: 10px; background: var(--surface-2); display: flex; flex-direction: column; gap: 8px; }
.meter-numbers { display: flex; align-items: baseline; gap: 6px; }
.meter-numbers strong { font-size: 32px; line-height: 1; }
.meter-numbers span { color: var(--muted); }
.meter-bar { height: 8px; border-radius: 999px; background: var(--line); overflow: hidden; }
.meter-bar span { display: block; height: 100%; width: 0; background: var(--ok); border-radius: inherit; transition: width .3s, background .3s; }
.meter.warn .meter-bar span { background: var(--warn); }
.meter.danger .meter-bar span { background: var(--danger); }
.meter.danger strong { color: var(--danger); }
.conversation-list { list-style: none; margin: 0; padding: 0; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.conversation-list:empty { display: none; }
.conversation-list li { display: flex; align-items: center; gap: 12px; padding: 10px 14px; border-top: 1px solid var(--line); }
.conversation-list li:first-child { border-top: 0; }
.conversation-list .text { flex: 1; min-width: 0; word-break: break-word; }
.conversation-list time { color: var(--muted); font-size: 12px; white-space: nowrap; }
.conversation-list a { color: var(--primary); font-size: 13px; text-decoration: none; white-space: nowrap; }
.conversation-list a:hover { text-decoration: underline; }
.empty { color: var(--muted); text-align: center; padding: 16px; font-size: 13px; }

/* 上报 */
.card-head .segmented { flex: none; flex-wrap: nowrap; }
.report-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.report-list:empty { display: none; }
.report { border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; display: flex; flex-direction: column; gap: 8px; }
.report-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.report-reason { font-weight: 600; flex: 1; min-width: 200px; }
.report-time { color: var(--muted); font-size: 12px; white-space: nowrap; }
.report-question { color: var(--text); word-break: break-word; }
.report-question .label { color: var(--muted); }
.report-lines { margin: 0; padding-left: 18px; color: var(--muted); font-size: 13px; word-break: break-word; }
.report-foot { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.report-foot .mail { color: var(--muted); font-size: 12px; }
.report-foot .mail.fail { color: var(--danger); }
.report-foot a { color: var(--primary); text-decoration: none; font-size: 13px; }
.report-foot a:hover { text-decoration: underline; }
.button.small { padding: 4px 12px; font-size: 13px; }
.chat { display: flex; flex-direction: column; gap: 6px; padding: 10px; border-radius: 8px; background: var(--surface-2); max-height: 320px; overflow: auto; }
.bubble { max-width: 85%; padding: 6px 10px; border-radius: 10px; font-size: 13px; white-space: pre-wrap; word-break: break-word; background: var(--surface); border: 1px solid var(--line); }
.bubble.user { align-self: flex-start; }
.bubble.staff { align-self: flex-end; background: var(--primary-soft); border-color: transparent; }
#report-more { align-self: center; }

/* 模型设置 */
.model-cards { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; align-items: start; }
.advanced { border: 1px dashed var(--line); border-radius: 10px; padding: 10px 14px; }
.advanced summary { cursor: pointer; font-size: 13px; font-weight: 500; }
.advanced summary .muted { font-weight: 400; margin-left: 6px; }
.results { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.results:empty { display: none; }
.result { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 4px 10px; align-items: start;
  padding: 10px 12px; border-radius: 10px; font-size: 13px; }
.result.ok { background: var(--ok-soft); } .result.fail { background: var(--danger-soft); }
.result .dot { width: 18px; height: 18px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-size: 11px; margin-top: 1px; }
.result.ok .dot { background: var(--ok); } .result.fail .dot { background: var(--danger); }
.result .name { font-weight: 600; word-break: break-all; }
.result .roles { color: var(--muted); font-size: 12px; }
.result .latency { color: var(--muted); font-size: 12px; white-space: nowrap; }
.result .detail { grid-column: 2 / 4; word-break: break-word; }
.result.fail .detail { color: var(--danger); }

.alert { padding: 10px 12px; border-radius: 8px; font-size: 13px; white-space: pre-wrap; }
.alert.error { background: var(--danger-soft); color: var(--danger); }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 20;
  background: var(--text); color: var(--bg); padding: 9px 18px; border-radius: 999px; font-size: 13px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .2); }

@media (max-width: 1000px) {
  .tiles { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 900px) {
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .model-cards { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 560px) {
  .topbar-inner, .page { padding-left: 16px; padding-right: 16px; }
  .grid-2 { grid-template-columns: minmax(0, 1fr); }
  .card { padding: 16px; }
}

/* 批量处理与状态筛选 */
.report-actions { display: flex; align-items: center; justify-content: flex-end; gap: 10px; flex-wrap: wrap; flex: none; max-width: 100%; }
.report-actions .segmented { flex-wrap: wrap; }
