/* ============================================================================
   Chat SDK Gateway 监控台 · 视觉系统
   「深空指挥台」：深色为默认的 NOC 控制台美学，荧光青主强调 + 琥珀告警，
   全部数字/ID/代码走等宽字体；浅色主题经 html[data-theme="light"] 切换。
   设计 token 统一在 :root 声明，状态语义色全站唯一来源。
   ============================================================================ */

:root {
  /* -- 基底 -- */
  --bg: #07090e;
  --bg-glow-1: rgba(45, 212, 191, 0.055);
  --bg-glow-2: rgba(138, 180, 255, 0.045);
  --panel: #0d1118;
  --panel-strong: #111722;
  --panel-raised: #151d2a;
  --line: rgba(148, 163, 184, 0.12);
  --line-strong: rgba(148, 163, 184, 0.24);
  --text: #e6edf6;
  --text-strong: #f4f8fd;
  --muted: #8b97a9;
  /* -- 品牌强调 -- */
  --accent: #3ddbc4;
  --accent-soft: rgba(61, 219, 196, 0.13);
  --accent-line: rgba(61, 219, 196, 0.34);
  --accent-2: #8ab4ff;
  --accent-2-soft: rgba(138, 180, 255, 0.12);
  /* -- 状态语义色（全站唯一来源）--
     成功 / 失败 / 处理中 / 异常中断 / 客户端取消 */
  --ok: #3fd68f;
  --ok-soft: rgba(63, 214, 143, 0.13);
  --ok-line: rgba(63, 214, 143, 0.32);
  --bad: #ff7070;
  --bad-soft: rgba(255, 112, 112, 0.12);
  --bad-soft-hover: rgba(255, 112, 112, 0.2);
  --bad-line: rgba(255, 112, 112, 0.32);
  --busy: #6ea8ff;
  --busy-soft: rgba(110, 168, 255, 0.13);
  --busy-line: rgba(110, 168, 255, 0.32);
  --warn: #ffb454;
  --warn-soft: rgba(255, 180, 84, 0.12);
  --warn-line: rgba(255, 180, 84, 0.32);
  --idle: #9aa4b8;
  --idle-soft: rgba(154, 164, 184, 0.12);
  --idle-line: rgba(154, 164, 184, 0.3);
  /* -- 字体 -- */
  --font-sans: -apple-system, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Segoe UI", sans-serif;
  --font-mono: ui-monospace, "SF Mono", "Cascadia Code", "JetBrains Mono", Menlo, Consolas, monospace;
  /* -- 结构 -- */
  --radius-lg: 14px;
  --radius-md: 10px;
  --radius-sm: 7px;
  --shadow: 0 14px 40px rgba(2, 4, 10, 0.5);
  --shadow-soft: 0 4px 18px rgba(2, 4, 10, 0.35);
  --code-bg: #070b12;
  --code-text: #c9d8ee;
  --scan-line: linear-gradient(90deg, #3ddbc4 0%, #8ab4ff 45%, #ffb454 100%);
}

html[data-theme="light"] {
  --bg: #eef1f6;
  --bg-glow-1: rgba(13, 148, 136, 0.07);
  --bg-glow-2: rgba(59, 92, 204, 0.05);
  --panel: #ffffff;
  --panel-strong: #fbfcfe;
  --panel-raised: #f2f5fa;
  --line: rgba(15, 23, 42, 0.11);
  --line-strong: rgba(15, 23, 42, 0.22);
  --text: #16202e;
  --text-strong: #0a1220;
  --muted: #5b6878;
  --accent: #0e9384;
  --accent-soft: rgba(14, 147, 132, 0.1);
  --accent-line: rgba(14, 147, 132, 0.32);
  --accent-2: #3b5ccc;
  --accent-2-soft: rgba(59, 92, 204, 0.1);
  --ok: #0c8f57;
  --ok-soft: rgba(12, 143, 87, 0.1);
  --ok-line: rgba(12, 143, 87, 0.3);
  --bad: #cc3340;
  --bad-soft: rgba(204, 51, 64, 0.09);
  --bad-soft-hover: rgba(204, 51, 64, 0.16);
  --bad-line: rgba(204, 51, 64, 0.3);
  --busy: #2563eb;
  --busy-soft: rgba(37, 99, 235, 0.09);
  --busy-line: rgba(37, 99, 235, 0.3);
  --warn: #b45309;
  --warn-soft: rgba(180, 83, 9, 0.1);
  --warn-line: rgba(180, 83, 9, 0.3);
  --idle: #64748b;
  --idle-soft: rgba(100, 116, 139, 0.1);
  --idle-line: rgba(100, 116, 139, 0.3);
  --shadow: 0 14px 36px rgba(15, 23, 42, 0.12);
  --shadow-soft: 0 4px 14px rgba(15, 23, 42, 0.08);
  --code-bg: #101623;
  --code-text: #d5e2f5;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 14px;
  background:
    radial-gradient(1100px 520px at 12% -8%, var(--bg-glow-1) 0%, transparent 60%),
    radial-gradient(900px 500px at 95% 8%, var(--bg-glow-2) 0%, transparent 55%),
    var(--bg);
  background-attachment: fixed;
}

::selection {
  background: var(--accent-soft);
  color: var(--text-strong);
}

/* ---------------------------------------------------------------------------
   应用布局：左侧导航 + 主区
   --------------------------------------------------------------------------- */

.app {
  display: grid;
  grid-template-columns: 212px minmax(0, 1fr);
  min-height: 100vh;
}

.sidenav {
  position: sticky;
  top: 0;
  align-self: start;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 18px 12px;
  border-right: 1px solid var(--line);
  background: linear-gradient(180deg, var(--panel) 0%, var(--bg) 130%);
}

.side-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 8px 16px;
}

.side-brand .logo {
  width: 34px;
  height: 34px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 9px;
  background: linear-gradient(135deg, rgba(61, 219, 196, 0.18), rgba(138, 180, 255, 0.14));
  border: 1px solid var(--accent-line);
  color: var(--accent);
}

.side-brand .name {
  font-size: 14.5px;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--text-strong);
  line-height: 1.25;
}

.side-brand .sub {
  font-size: 10.5px;
  color: var(--muted);
  font-family: var(--font-mono);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.tabs {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.tab {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  border: 1px solid transparent;
  background: transparent;
  border-radius: var(--radius-md);
  padding: 10px 11px;
  color: var(--muted);
  font-size: 13.5px;
  font-weight: 600;
  font-family: inherit;
  letter-spacing: 0.01em;
  white-space: nowrap;
  cursor: pointer;
  transition: color 0.15s ease, background 0.15s ease, border-color 0.15s ease;
  text-align: left;
}

.tab svg {
  width: 16px;
  height: 16px;
  flex: none;
  opacity: 0.75;
}

.tab:hover {
  color: var(--text);
  background: var(--panel-raised);
}

.tab.active {
  color: var(--accent);
  background: var(--accent-soft);
  border-color: var(--accent-line);
}

.tab.active svg {
  opacity: 1;
}

.tab.disabled {
  opacity: 0.42;
  cursor: not-allowed;
}

.tab.disabled:hover {
  color: var(--muted);
  background: transparent;
}

.tab .soon {
  margin-left: auto;
  font-size: 10px;
  font-family: var(--font-mono);
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 1px 6px;
}

.side-foot {
  margin-top: auto;
  padding: 10px 8px 2px;
  display: grid;
  gap: 8px;
}

.side-foot .ver {
  font-size: 10.5px;
  color: var(--muted);
  font-family: var(--font-mono);
  letter-spacing: 0.04em;
}

/* ---------------------------------------------------------------------------
   主区与顶栏
   --------------------------------------------------------------------------- */

.main-area {
  min-width: 0;
  padding: 0 22px 40px;
}

.main-area::before {
  content: "";
  display: block;
  height: 2px;
  margin: 0 -22px;
  background: var(--scan-line);
  opacity: 0.65;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 14px;
  padding: 18px 2px 14px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 18px;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}

.title {
  font-size: 21px;
  font-weight: 800;
  letter-spacing: 0.01em;
  color: var(--text-strong);
  line-height: 1.1;
}

.subtitle {
  color: var(--muted);
  font-size: 12.5px;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: 999px;
  background: var(--panel-strong);
  color: var(--muted);
  border: 1px solid var(--line);
  padding: 4px 10px;
  font-size: 11.5px;
  font-weight: 600;
  font-family: var(--font-mono);
  letter-spacing: 0.01em;
}

.chip.live {
  color: var(--ok);
  border-color: var(--ok-line);
  background: var(--ok-soft);
}

.chip.live::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--ok);
  animation: breathe 2.4s ease-in-out infinite;
}

.chip.stale {
  color: var(--warn);
  border-color: var(--warn-line);
  background: var(--warn-soft);
}

.chip.stale::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--warn);
}

.chip.danger {
  color: var(--bad);
  border-color: var(--bad-line);
  background: var(--bad-soft);
}

@keyframes breathe {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.45; transform: scale(0.82); }
}

.actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* ---------------------------------------------------------------------------
   按钮 / 输入
   --------------------------------------------------------------------------- */

.btn {
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--panel-strong);
  color: var(--text);
  padding: 8px 12px;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.14s ease, background 0.14s ease, transform 0.14s ease;
  font-family: inherit;
}

.btn:hover {
  border-color: var(--accent-line);
  background: var(--panel-raised);
}

.btn:active {
  transform: translateY(1px);
}

.btn.primary {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: var(--accent-line);
}

.btn.primary:hover {
  background: var(--accent-soft);
  filter: brightness(1.15);
}

.btn.warn {
  color: var(--bad);
  background: var(--bad-soft);
  border-color: var(--bad-line);
}

input,
select,
textarea {
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--panel-strong);
  color: var(--text);
  min-height: 34px;
  padding: 7px 10px;
  font-size: 12.5px;
  font-family: inherit;
}

input::placeholder,
textarea::placeholder {
  color: var(--muted);
  opacity: 0.75;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--accent-line);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

textarea {
  width: 100%;
  min-height: 120px;
  resize: vertical;
}

input[type="checkbox"] {
  min-height: 0;
  accent-color: var(--accent);
}

/* ---------------------------------------------------------------------------
   面板 / 区块
   --------------------------------------------------------------------------- */

.panel {
  display: none;
}

.panel.active {
  display: block;
  animation: panelIn 0.24s ease;
}

@keyframes panelIn {
  from {
    opacity: 0;
    transform: translateY(7px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.section-title {
  margin: 0 0 12px;
  font-size: 16px;
  font-weight: 700;
  color: var(--text-strong);
  letter-spacing: 0.01em;
}

.section-desc {
  margin: -8px 0 14px;
  font-size: 12.5px;
  color: var(--muted);
}

.block {
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--panel);
  padding: 14px;
  box-shadow: var(--shadow-soft);
}

.block h3 {
  margin: 0 0 10px;
  font-size: 13.5px;
  font-weight: 700;
  color: var(--text-strong);
  letter-spacing: 0.02em;
}

.block + .block {
  margin-top: 12px;
}

.split {
  margin-top: 12px;
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 12px;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

/* ---------------------------------------------------------------------------
   统计卡片
   --------------------------------------------------------------------------- */

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(168px, 1fr));
  gap: 10px;
}

.card {
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 12px 13px;
  background: var(--panel);
  transition: border-color 0.15s ease, transform 0.15s ease;
}

.card:hover {
  border-color: var(--line-strong);
}

.card .k {
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 0.05em;
  text-transform: uppercase;
  font-weight: 600;
}

.card .v {
  margin-top: 7px;
  font-size: 22px;
  font-weight: 700;
  font-family: var(--font-mono);
  letter-spacing: -0.01em;
  color: var(--text-strong);
  overflow-wrap: anywhere;
  word-break: break-word;
}

.card .v.text {
  font-size: 13px;
  font-weight: 600;
  line-height: 1.4;
}

.card .v.good { color: var(--ok); }
.card .v.bad { color: var(--bad); }
.card .v.warn { color: var(--warn); }
.card .v.neutral { color: var(--idle); }

.card .hint {
  margin-top: 5px;
}

/* 健康主卡（总览用）：更大的数值 + 内嵌趋势 */
.hero-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 12px;
}

.hero-card {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--panel);
  padding: 16px;
  box-shadow: var(--shadow-soft);
}

.hero-card .k {
  font-size: 11.5px;
  color: var(--muted);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  font-weight: 700;
}

.hero-card .v {
  margin-top: 8px;
  font-size: 30px;
  font-weight: 750;
  font-family: var(--font-mono);
  color: var(--text-strong);
  line-height: 1.05;
}

.hero-card .sub {
  margin-top: 6px;
  font-size: 11.5px;
  color: var(--muted);
  font-family: var(--font-mono);
}

.hero-card .v.good { color: var(--ok); }
.hero-card .v.bad { color: var(--bad); }
.hero-card .v.warn { color: var(--warn); }
.hero-card .v.busy { color: var(--busy); }

.hero-card .spark {
  margin-top: 10px;
}

.hero-card.accent-edge::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 3px;
  background: var(--accent);
  opacity: 0.7;
}

/* 迷你趋势图（原生 SVG 容器） */
.spark {
  display: block;
  width: 100%;
  height: 42px;
}

.spark svg {
  display: block;
  width: 100%;
  height: 100%;
}

/* Tooltip for spark chart data points */
.chart-tooltip {
  position: fixed;
  pointer-events: none;
  z-index: 9999;
  background: var(--panel-strong, var(--bg));
  color: var(--text);
  border: 1px solid var(--line-strong, var(--line));
  border-radius: 4px;
  padding: 4px 8px;
  font-size: 12px;
  font-family: var(--font-mono);
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
  white-space: nowrap;
  display: none;
}

/* Crosshair and cursor highlight for spark charts */
.spark-hover-band {
  visibility: hidden;
  fill: var(--accent-soft);
  opacity: 0.72;
  pointer-events: none;
}

.spark-crosshair {
  visibility: hidden;
  stroke: var(--accent);
  stroke-width: 1.4;
  stroke-dasharray: 3 2;
  pointer-events: none;
}

.spark-cursor {
  visibility: hidden;
  fill: var(--panel-strong, var(--bg));
  stroke: var(--accent);
  stroke-width: 1.7;
  pointer-events: none;
}

.trend-legend {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  font-size: 11.5px;
  color: var(--muted);
  font-family: var(--font-mono);
}

.trend-legend .dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 2px;
  margin-right: 5px;
  vertical-align: baseline;
}

/* ---------------------------------------------------------------------------
   列表 / 表格
   --------------------------------------------------------------------------- */

.mini-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 7px;
}

.mini-list li {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--panel-strong);
  padding: 8px 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
}

.mini-list li strong {
  color: var(--text-strong);
  font-family: var(--font-mono);
}

.mini-list .btn {
  padding: 4px 8px;
  font-size: 11.5px;
}

.stat-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  display: inline-block;
}

.stat-dot.ok { background: var(--ok); }
.stat-dot.err { background: var(--bad); }
.stat-dot.na { background: var(--idle); }

.table-wrap {
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  overflow: auto;
  background: var(--panel);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 9px 10px;
  vertical-align: top;
  text-align: left;
}

th {
  color: var(--muted);
  font-weight: 700;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: var(--panel-strong);
  position: sticky;
  top: 0;
  z-index: 1;
}

tr:last-child td {
  border-bottom: 0;
}

tbody tr {
  transition: background 0.12s ease;
}

tbody tr:hover {
  background: var(--panel-raised);
}

tbody tr.row-status-bad {
  background: var(--bad-soft);
}

tbody tr.row-status-bad:hover {
  background: var(--bad-soft-hover);
}

tbody tr.row-status-interrupted {
  background: var(--warn-soft);
}

tbody tr.row-status-interrupted:hover {
  background: var(--panel-raised);
}

.mono {
  font-family: var(--font-mono);
  font-size: 12px;
}

/* Two-line time cell in fixed tables */
.cell-date { display: block; }
.cell-time { display: block; font-size: 11px; }

/* Fixed-layout wide tables: identity columns stay readable */
table.table-fixed {
  table-layout: fixed;
  width: 100%;
}

/* Identity cells (request ID, endpoint): truncate with ellipsis */
table.table-fixed td.id-cell {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-family: var(--font-mono, ui-monospace, monospace);
  font-size: 0.85em;
}

/* Metric cells (attempts, added, elapsed): short values, no truncation */
table.table-fixed td.metric-cell {
  white-space: normal;
  word-break: break-word;
  font-family: var(--font-mono, ui-monospace, monospace);
  font-size: 0.85em;
}

/* 新增 column grid: 3 lines carrying 5 metrics (total; thinking/text; tool/drop) */
table.table-fixed td.metric-cell .added-grid {
  display: flex;
  flex-direction: column;
  gap: 1px;
  line-height: 1.35;
}

/* Attempts cell for server web search: 搜/决 on their own lines, extras below */
table.table-fixed td.metric-cell .attempts-grid {
  display: flex;
  flex-direction: column;
  gap: 1px;
  line-height: 1.35;
}
table.table-fixed td.metric-cell .attempts-grid .attempts-extra {
  font-size: 0.9em;
  color: var(--muted);
}

/* Two-line identity cell: request id on top, #seq · kind as muted subline */
table.table-fixed td.id-cell .id-main {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
table.table-fixed td.id-cell .cell-sub {
  font-size: 0.85em;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
table.table-fixed td.metric-cell .added-pair {
  display: flex;
  gap: 8px;
}
table.table-fixed td.metric-cell .added-pair span {
  min-width: 0;
}

/* Tool cell: allow multi-line wrapping */
table.table-fixed td.tool-cell {
  white-space: normal;
  word-break: break-word;
  font-family: var(--font-mono, ui-monospace, monospace);
  font-size: 0.85em;
}

/* Problem cell: allow wrapping with word break */
table.table-fixed td.problem-td {
  white-space: normal;
  word-break: break-word;
}

/* "问题" column in fixed tables: allow badge wrapping */
table.table-fixed td:nth-child(9):not(.mono),
table.table-fixed td:nth-child(10):not(.mono) {
  white-space: normal;
  word-break: break-word;
}

/* Parent-child request grouping: server_web_search children indented under parent */
tr.child-request td:first-child {
  padding-left: 24px;
}
tr.child-request td:first-child::before {
  content: '↳';
  position: absolute;
  left: 6px;
  color: var(--muted);
  font-size: 12px;
}
tr.child-request td {
  position: relative;
  background: var(--panel);
  border-top-color: transparent;
}
tr.child-request + tr:not(.child-request) td {
  border-top: 1.5px solid var(--line-strong);
}
.parent-badge {
  display: inline-block;
  font-size: 10px;
  color: var(--muted);
  background: var(--accent-soft);
  border-radius: 3px;
  padding: 1px 5px;
  margin-top: 2px;
}

/* Non-fixed tables: keep long-value wrapping for config/other panels */
.table-wrap table:not(.table-fixed) td.mono {
  overflow-wrap: anywhere;
  word-break: break-word;
}

/* Endpoint matrix: prevent path column compression; scroll horizontally on narrow screens */
[data-subpanel="endpoints"] .table-wrap table {
  min-width: 640px;
}
[data-subpanel="endpoints"] .table-wrap table td.mono {
  overflow-wrap: normal;
  word-break: normal;
  white-space: nowrap;
}

.muted {
  color: var(--muted);
}

.link-btn {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--accent);
  cursor: pointer;
  font: inherit;
  padding: 0;
  text-align: left;
}

.link-btn:hover {
  text-decoration: underline;
}

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

.hint {
  margin-top: 8px;
  font-size: 11.5px;
  color: var(--muted);
  line-height: 1.55;
}

/* ---------------------------------------------------------------------------
   徽章 / 状态
   --------------------------------------------------------------------------- */

.badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 10.5px;
  font-weight: 700;
  font-family: var(--font-mono);
  letter-spacing: 0.03em;
}

.badge.get {
  background: var(--busy-soft);
  color: var(--busy);
  border: 1px solid var(--busy-line);
}

.badge.post {
  background: var(--warn-soft);
  color: var(--warn);
  border: 1px solid var(--warn-line);
}

.status {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
}

.pill {
  display: inline-block;
  border-radius: 999px;
  padding: 2.5px 9px;
  border: 1px solid var(--line-strong);
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
}

.pill.good {
  background: var(--ok-soft);
  border-color: var(--ok-line);
  color: var(--ok);
  font-weight: 700;
}

.pill.warn {
  background: var(--warn-soft);
  border-color: var(--warn-line);
  color: var(--warn);
  font-weight: 700;
}

.pill.bad {
  background: var(--bad-soft);
  border-color: var(--bad-line);
  color: var(--bad);
  font-weight: 700;
}

.pill.busy {
  background: var(--busy-soft);
  border-color: var(--busy-line);
  color: var(--busy);
  font-weight: 700;
}

.pill.neutral {
  background: var(--idle-soft);
  border-color: var(--idle-line);
  color: var(--idle);
}

/* 处理中状态的呼吸动画（叠加在 pill 上） */
.pill.pulse {
  animation: pillPulse 2s ease-in-out infinite;
}

@keyframes pillPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.55; }
}

.problem-cell {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-width: 100%;
  min-width: 0;
  overflow: hidden;
}

.problem-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  max-width: 100%;
  min-width: 0;
  overflow: hidden;
}

.problem-pills .pill {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: middle;
}

.problem-summary-line {
  margin-top: 2px;
  font-size: 11px;
  font-family: var(--font-mono);
  color: var(--muted);
  max-width: 100%;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  word-break: break-word;
}

.problem-ok-text {
  font-size: 11px;
  color: var(--muted);
}

/* ---------------------------------------------------------------------------
   代码块
   --------------------------------------------------------------------------- */

.code {
  background: var(--code-bg);
  color: var(--code-text);
  border-radius: var(--radius-md);
  border: 1px solid var(--line);
  padding: 12px;
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.65;
  overflow: auto;
  max-height: 520px;
  white-space: pre;
}

/* ---------------------------------------------------------------------------
   错误提示条
   --------------------------------------------------------------------------- */

.error-box {
  display: none;
  margin: 0 0 12px;
  border: 1px solid var(--bad-line);
  background: var(--bad-soft);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  color: var(--bad);
  font-size: 12.5px;
}

.error-box.show {
  display: block;
}

/* ---------------------------------------------------------------------------
   系统调试区子导航
   --------------------------------------------------------------------------- */

.subnav {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  margin-bottom: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--panel);
  padding: 4px;
  width: fit-content;
  max-width: 100%;
}

.subtab {
  border: 0;
  background: transparent;
  border-radius: var(--radius-sm);
  padding: 7px 13px;
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
  transition: color 0.14s ease, background 0.14s ease;
}

.subtab:hover {
  color: var(--text);
}

.subtab.active {
  background: var(--accent-soft);
  color: var(--accent);
}

.subpanel {
  display: none;
}

.subpanel.active {
  display: block;
  animation: panelIn 0.2s ease;
}

/* ---------------------------------------------------------------------------
   弹窗（debug 详情 / 通用详情）
   --------------------------------------------------------------------------- */

body.modal-open {
  overflow: hidden;
}

.debug-modal {
  position: fixed;
  inset: 0;
  background: rgba(2, 5, 10, 0.68);
  backdrop-filter: blur(3px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 60;
  padding: 14px;
}

.debug-modal.show {
  display: flex;
}

.debug-modal-card {
  width: min(1200px, 100%);
  max-height: calc(100vh - 28px);
  background: var(--panel-strong);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: panelIn 0.18s ease;
}

.debug-modal-head {
  border-bottom: 1px solid var(--line);
  padding: 13px 15px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  background: var(--panel);
}

.debug-modal-head h3 {
  color: var(--text-strong);
}

.debug-modal-body {
  padding: 13px;
  overflow: auto;
  display: grid;
  gap: 8px;
  align-content: start;
  grid-auto-rows: max-content;
}

.debug-event-item {
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--panel);
  padding: 8px 10px;
}

.debug-event-item summary {
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text);
}

.debug-nested {
  margin-top: 8px;
}

.debug-payload-shell {
  margin-top: 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--panel-strong);
  padding: 8px;
}

.debug-payload-head {
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

.debug-payload-head .debug-nested {
  flex: 1;
  min-width: 0;
  margin-top: 0;
}

.debug-copy-btn {
  padding: 6px 8px;
  font-size: 11.5px;
  white-space: nowrap;
}

.debug-nested summary {
  font-size: 12px;
  color: var(--muted);
  cursor: pointer;
}

.debug-pre {
  margin-top: 6px;
  padding: 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--code-bg);
  color: var(--code-text);
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}

/* ---------------------------------------------------------------------------
   请求时间线（M3 使用；先行定义视觉）
   --------------------------------------------------------------------------- */

.timeline {
  position: relative;
  margin: 0;
  padding: 0 0 0 22px;
  list-style: none;
}

.timeline::before {
  content: "";
  position: absolute;
  left: 7px;
  top: 6px;
  bottom: 6px;
  width: 2px;
  background: var(--line-strong);
  border-radius: 2px;
}

.timeline-item {
  position: relative;
  padding: 0 0 14px;
}

.timeline-item::before {
  content: "";
  position: absolute;
  left: -20px;
  top: 5px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--idle);
  border: 2px solid var(--panel);
  box-shadow: 0 0 0 1.5px var(--idle-line);
}

.timeline-item.ok::before { background: var(--ok); box-shadow: 0 0 0 1.5px var(--ok-line); }
.timeline-item.bad::before { background: var(--bad); box-shadow: 0 0 0 1.5px var(--bad-line); }
.timeline-item.warn::before { background: var(--warn); box-shadow: 0 0 0 1.5px var(--warn-line); }
.timeline-item.busy::before { background: var(--busy); box-shadow: 0 0 0 1.5px var(--busy-line); }

.timeline-time {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--muted);
}

.timeline-title {
  margin-top: 2px;
  font-size: 13px;
  font-weight: 650;
  color: var(--text-strong);
}

.timeline-body {
  margin-top: 4px;
  font-size: 12.5px;
  color: var(--text);
  line-height: 1.55;
}

.timeline-meta {
  margin-top: 4px;
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--muted);
}

/* ---------------------------------------------------------------------------
   占位（兼容层审计）
   --------------------------------------------------------------------------- */

.placeholder-card {
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius-lg);
  background: var(--panel);
  padding: 40px 24px;
  text-align: center;
  color: var(--muted);
}

.placeholder-card .icon {
  opacity: 0.5;
  margin-bottom: 12px;
}

.placeholder-card h3 {
  margin: 0 0 8px;
  color: var(--text);
  font-size: 16px;
}

.placeholder-card p {
  margin: 0 auto;
  max-width: 520px;
  font-size: 12.5px;
  line-height: 1.7;
}

/* ---------------------------------------------------------------------------
   响应式
   --------------------------------------------------------------------------- */

@media (max-width: 1050px) {
  .split,
  .grid-2 {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (max-width: 900px) {
  .app {
    grid-template-columns: 1fr;
  }

  .sidenav {
    position: static;
    height: auto;
    flex-direction: row;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    overflow-x: hidden;
  }

  .side-brand {
    padding: 0 8px 0 0;
  }

  .side-brand .sub {
    display: none;
  }

  .tabs {
    flex-direction: row;
    flex: 1 1 auto;
    min-width: 0;
    overflow-x: auto;
    max-width: 100%;
  }

  .tab {
    width: auto;
  }

  .side-foot {
    flex: 0 0 auto;
    margin-top: 0;
    margin-left: auto;
    padding: 0;
  }

  .side-foot .btn {
    white-space: nowrap;
  }

  .side-foot .ver {
    display: none;
  }

  .main-area {
    padding: 0 14px 30px;
  }

  .main-area::before {
    margin: 0 -14px;
  }
}

@media (max-width: 420px) {
  .block,
  .mini-list,
  .mini-list li {
    min-width: 0;
  }

  .mini-list li {
    align-items: flex-start;
  }

  .mini-list li strong {
    min-width: 0;
    overflow-wrap: anywhere;
    text-align: right;
  }

  .toolbar {
    align-items: stretch;
  }

  .toolbar input[type="text"],
  .toolbar input[type="number"],
  .toolbar select {
    min-width: 0 !important;
    max-width: 100%;
  }

  .toolbar input[type="text"] {
    flex: 1 1 100%;
    width: 100%;
  }
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ---------------------------------------------------------------------------
   Modal overflow containment (desktop + 390px)
   --------------------------------------------------------------------------- */

.debug-modal-card {
  min-width: 0;
  max-width: 100%;
}

.debug-modal-head {
  flex-wrap: wrap;
  min-width: 0;
  max-width: 100%;
}

.debug-modal-head > div {
  min-width: 0;
  flex-shrink: 1;
}

.debug-modal-head > div:last-child {
  flex-wrap: wrap;
  justify-content: flex-end;
}

.debug-modal-body {
  min-width: 0;
  max-width: 100%;
}

.debug-modal-body > * {
  min-width: 0;
  max-width: 100%;
}

.debug-modal-body .debug-payload-shell {
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
}

.debug-modal-body .debug-event-item,
.debug-modal-body details,
.debug-modal-body .debug-nested {
  min-width: 0;
  max-width: 100%;
}

.debug-modal-body .debug-event-item summary,
.debug-modal-body .debug-nested summary {
  overflow-wrap: anywhere;
  word-break: break-word;
}

.debug-modal-body .debug-pre {
  min-width: 0;
  max-width: 100%;
  overflow-wrap: anywhere;
  word-break: break-word;
  overflow-x: auto;
}

.debug-modal-body pre,
.debug-modal-body code {
  min-width: 0;
  max-width: 100%;
  overflow-x: auto;
  overflow-wrap: anywhere;
  word-break: break-word;
}

@media (max-width: 420px) {
  .debug-modal-card {
    width: 100%;
    border-radius: var(--radius-md);
  }

  .debug-modal-head {
    padding: 10px 12px;
  }

  .debug-modal-body {
    padding: 10px;
  }
}

/* ---------------------------------------------------------------------------
   Sticky action column — only tables with .sticky-action-table
   --------------------------------------------------------------------------- */

.sticky-action-table tr > td:last-child,
.sticky-action-table tr > th:last-child {
  position: sticky;
  right: 0;
  z-index: 2;
  background: var(--panel);
  border-left: 1px solid var(--line);
}

.sticky-action-table thead tr > th:last-child {
  background: var(--panel-strong);
  z-index: 3;
}

.sticky-action-table tbody tr:hover > td:last-child {
  background: var(--panel-raised);
}

.sticky-action-table tbody tr.row-status-bad > td:last-child {
  background: var(--bad-soft);
}

.sticky-action-table tbody tr.row-status-interrupted > td:last-child {
  background: var(--warn-soft);
}

/* ---------------------------------------------------------------------------
   Mobile card layout — overview recent-request table only (.request-summary-table)
   Columns: 1=time 2=request 3=endpoint 4=status 5=duration 6=rounds 7=added 8=tools 9=problem 10=action
   Hidden on mobile: 5-8 (duration, rounds, added, tools)
   --------------------------------------------------------------------------- */

@media (max-width: 600px) {
  .request-summary-table colgroup {
    display: none;
  }

  .request-summary-table {
    table-layout: auto;
    width: 100%;
  }

  .request-summary-table thead {
    display: none;
  }

  .request-summary-table tbody {
    display: flex;
    flex-direction: column;
    gap: 8px;
  }

  .request-summary-table tbody tr {
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-rows: auto auto auto auto;
    gap: 4px 10px;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: var(--panel);
  }

  .request-summary-table tbody tr:hover {
    background: var(--panel-raised);
  }

  .request-summary-table tbody tr.row-status-bad {
    background: var(--bad-soft);
    border-color: var(--bad-line);
  }

  .request-summary-table tbody tr.row-status-bad:hover {
    background: var(--bad-soft-hover);
  }

  .request-summary-table tbody tr.row-status-interrupted {
    background: var(--warn-soft);
    border-color: var(--warn-line);
  }

  .request-summary-table tbody tr.row-status-interrupted:hover {
    background: var(--panel-raised);
  }

  /* Reset sticky positioning inside mobile cards */
  .request-summary-table tbody tr > td:last-child {
    position: static;
    border-left: none;
    background: transparent;
  }

  /* All td: reset table cell defaults */
  .request-summary-table tbody tr > td {
    display: block;
    border-bottom: none;
    padding: 0;
    white-space: normal;
    word-break: break-word;
    overflow: visible;
    text-overflow: unset;
  }

  /* Row 1: request ID+kind (col 2) | status (col 4) */
  .request-summary-table tbody tr > td:nth-child(2) {
    grid-column: 1;
    grid-row: 1;
    font-weight: 600;
    font-size: 12.5px;
  }

  .request-summary-table tbody tr > td:nth-child(4) {
    grid-column: 2;
    grid-row: 1;
    text-align: right;
    font-size: 12px;
  }

  /* Row 2: endpoint (col 3) */
  .request-summary-table tbody tr > td:nth-child(3) {
    grid-column: 1 / -1;
    grid-row: 2;
    font-size: 11.5px;
    color: var(--muted);
  }

  /* Row 3: problem cell (col 9) — full width */
  .request-summary-table tbody tr > td:nth-child(9) {
    grid-column: 1 / -1;
    grid-row: 3;
    font-size: 12px;
    padding-top: 4px;
  }

  /* Row 4: time (col 1) | action (col 10) */
  .request-summary-table tbody tr > td:nth-child(1) {
    grid-column: 1;
    grid-row: 4;
    font-size: 11px;
    color: var(--muted);
    align-self: center;
  }

  .request-summary-table tbody tr > td:nth-child(10) {
    grid-column: 2;
    grid-row: 4;
    text-align: right;
    align-self: center;
  }

  /* Hidden columns: 5=duration, 6=rounds, 7=added, 8=tools */
  .request-summary-table tbody tr > td:nth-child(5),
  .request-summary-table tbody tr > td:nth-child(6),
  .request-summary-table tbody tr > td:nth-child(7),
  .request-summary-table tbody tr > td:nth-child(8) {
    display: none;
  }

  /* Ensure action button is tap-friendly */
  .request-summary-table tbody tr > td:nth-child(10) .btn {
    min-height: 32px;
    min-width: 48px;
    padding: 6px 12px;
  }

  /* Pills/badges wrap naturally */
  .request-summary-table tbody tr > td:nth-child(9) .badge,
  .request-summary-table tbody tr > td:nth-child(9) .pill,
  .request-summary-table tbody tr > td:nth-child(9) .tag {
    display: inline-block;
    margin: 1px 3px 1px 0;
  }

  /* Empty-state row spans full width */
  .request-summary-table tbody tr > td[colspan] {
    grid-column: 1 / -1;
    grid-row: 1 / -1;
    text-align: center;
    padding: 18px 12px;
    color: var(--muted);
  }
}
