/* Tentacle WebUI — 暖色深色主题（类 Claude 风格） */

:root {
  --bg: #201b16;
  --bg-sidebar: #1a1611;
  --bg-elevated: #2b241c;
  --bg-input: #292219;
  --bg-hover: #332b21;
  --border: #3d342a;
  --text: #e9e2d7;
  --text-dim: #a99e8e;
  --text-faint: #7d7466;
  --accent: #d97757;
  --accent-hover: #e58e6e;
  --accent-soft: rgba(217, 119, 87, 0.14);
  --user-bubble: #3e3327;
  --danger: #cf6a5f;
  --ok: #7fa66a;
  --radius: 14px;
  --radius-sm: 8px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --mono: "SF Mono", ui-monospace, "JetBrains Mono", Consolas, monospace;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

/* hidden 属性必须优先于任何 display 设置（修复登录框被 display:flex 钉死的问题） */
[hidden] { display: none !important; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.7;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}

input, textarea, select {
  font-family: inherit;
  font-size: inherit;
  color: var(--text);
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  outline: none;
  transition: border-color 0.15s;
}
input:focus, textarea:focus, select:focus { border-color: var(--accent); }

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-faint); }

/* ========== 布局 ========== */

#app { display: flex; height: 100vh; overflow: hidden; }

#sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 16px 10px;
}

#main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

#connBanner {
  background: rgba(207, 106, 95, 0.12);
  border-bottom: 1px solid var(--danger);
  color: var(--danger);
  font-size: 13px;
  padding: 10px 24px;
  text-align: center;
}
#connBanner code {
  background: rgba(207, 106, 95, 0.15);
  border-radius: 4px;
  padding: 0 6px;
  font-family: var(--mono);
}

.view { display: none; flex: 1; flex-direction: column; min-height: 0; }
.view.active { display: flex; }

/* ========== 侧边栏 ========== */

.logo {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 17px;
  font-weight: 600;
  padding: 6px 10px 18px;
  color: var(--accent);
}

#nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  color: var(--text-dim);
  text-align: left;
  transition: background 0.12s, color 0.12s;
}
.nav-item:hover { background: var(--bg-hover); color: var(--text); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); }

.sidebar-footer {
  border-top: 1px solid var(--border);
  padding: 12px 10px 4px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.agent-badge { font-size: 14px; font-weight: 600; }
.conn-status {
  font-size: 12px;
  color: var(--text-faint);
  display: flex;
  align-items: center;
  gap: 6px;
}
.conn-status .dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--text-faint);
  transition: background 0.3s;
}
.conn-status.online .dot { background: var(--ok); }

/* ========== 聊天视图 ========== */

.chat-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 16px 24px 12px;
  border-bottom: 1px solid var(--border);
}
.chat-title { font-size: 16px; font-weight: 600; }
.chat-usage { font-size: 12px; color: var(--text-faint); font-family: var(--mono); }

.chat-scroll { flex: 1; overflow-y: auto; }

.chat-messages {
  max-width: 780px;
  margin: 0 auto;
  padding: 24px 24px 12px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* 消息行通用 */
.msg-row { display: flex; flex-direction: column; }
.msg-row.user { align-items: flex-end; }
.msg-row.agent, .msg-row.system { align-items: stretch; }

.msg-meta {
  font-size: 11px;
  color: var(--text-faint);
  margin-top: 5px;
  font-family: var(--mono);
}
.msg-row.user .msg-meta { text-align: right; }

/* 用户气泡 */
.bubble-user {
  max-width: 75%;
  background: var(--user-bubble);
  border-radius: var(--radius);
  padding: 10px 16px;
  white-space: pre-wrap;
  word-break: break-word;
}

/* agent 消息：分段独立气泡（IM 风格，一段 = 一条消息） */
.agent-body {
  max-width: 100%;
  word-break: break-word;
}
.agent-body .platform-tag {
  display: inline-block;
  font-size: 11px;
  color: var(--text-faint);
  border: 1px solid var(--border);
  border-radius: 99px;
  padding: 0 8px;
  margin-right: 8px;
  vertical-align: 1px;
}
.agent-seg {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 16px;
}
.agent-seg + .agent-seg { margin-top: 8px; }
/* 气泡底色与 .md code 默认底色相同，内联代码改用暗色块保持对比 */
.agent-seg .md code { background: rgba(0, 0, 0, 0.28); }

/* 系统（心跳）消息 */
.msg-system {
  text-align: center;
  font-size: 12px;
  color: var(--text-faint);
}

/* 可折叠块：思考 / 草稿 / 工具 */
details.fold {
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.02);
  margin-bottom: 10px;
  overflow: hidden;
}
details.fold.tools { border-left-color: var(--ok); }

details.fold > summary {
  cursor: pointer;
  padding: 7px 12px;
  font-size: 12.5px;
  color: var(--text-dim);
  user-select: none;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 6px;
}
details.fold > summary::before {
  content: "▸";
  display: inline-block;
  transition: transform 0.15s;
  font-size: 11px;
}
details.fold[open] > summary::before { transform: rotate(90deg); }
details.fold > summary:hover { color: var(--text); }

.fold-body {
  padding: 4px 14px 12px;
  font-size: 13.5px;
  color: var(--text-dim);
  border-top: 1px dashed var(--border);
}
.fold-body p { margin: 6px 0; }

.tool-item { margin: 8px 0; }
.tool-item .tool-name {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--accent);
}
.tool-item pre {
  font-family: var(--mono);
  font-size: 12px;
  background: var(--bg);
  border-radius: 6px;
  padding: 8px 10px;
  margin-top: 4px;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 220px;
  overflow-y: auto;
}
.tool-item pre.tool-result { color: var(--text-faint); }
.tool-web-search .tool-name { color: var(--accent); }
.tool-web-search pre { color: var(--text-dim); font-size: 12px; }

/* markdown 渲染基础 */
.md p { margin: 6px 0; }
.md p:first-child { margin-top: 0; }
.md p:last-child { margin-bottom: 0; }
.md h1, .md h2, .md h3 { margin: 14px 0 6px; line-height: 1.4; }
.md h1 { font-size: 19px; } .md h2 { font-size: 17px; } .md h3 { font-size: 15.5px; }
.md ul, .md ol { margin: 6px 0; padding-left: 22px; }
.md code {
  font-family: var(--mono);
  font-size: 13px;
  background: var(--bg-elevated);
  border-radius: 5px;
  padding: 1px 6px;
}
.md pre.code {
  background: var(--bg-sidebar);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  overflow-x: auto;
  margin: 10px 0;
}
.md pre.code code { background: none; padding: 0; font-size: 13px; }
.md a { color: var(--accent); }
.md blockquote {
  border-left: 3px solid var(--border);
  padding-left: 12px;
  color: var(--text-dim);
  margin: 8px 0;
}

/* 错误提示 */
.msg-error {
  font-size: 13px;
  color: var(--danger);
  border: 1px solid var(--danger);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
}

/* 输入区 */
.chat-input-area {
  padding: 10px 24px 18px;
  max-width: 828px;
  margin: 0 auto;
  width: 100%;
  position: relative;
}
.chat-typing {
  font-size: 12.5px;
  color: var(--text-dim);
  padding: 0 8px 6px;
  animation: pulse 1.4s ease-in-out infinite;
}
@keyframes pulse { 50% { opacity: 0.35; } }

.thinking-status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--text-dim);
  font-size: 13px;
  padding: 8px 0;
}
.thinking-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
  animation: pulse 1.4s ease-in-out infinite;
}

.chat-input-box {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 10px 10px 16px;
  transition: border-color 0.15s;
}
.chat-input-box:focus-within { border-color: var(--accent); }

#chatInput {
  flex: 1;
  border: none;
  background: none;
  resize: none;
  max-height: 180px;
  padding: 4px 0;
  line-height: 1.6;
}

.command-palette {
  position: absolute;
  left: 24px;
  right: 24px;
  bottom: calc(100% - 2px);
  z-index: 30;
  max-height: min(320px, 45vh);
  overflow-y: auto;
  padding: 6px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 14px 36px rgba(0, 0, 0, 0.28);
}
.command-option {
  display: grid;
  grid-template-columns: minmax(150px, auto) 1fr;
  gap: 14px;
  align-items: baseline;
  width: 100%;
  padding: 9px 11px;
  border-radius: 8px;
  color: var(--text);
  text-align: left;
}
.command-option:hover,
.command-option.active {
  background: var(--bg-hover);
}
.command-option code {
  color: var(--accent);
  white-space: nowrap;
}
.command-option span {
  color: var(--text-dim);
  font-size: 12.5px;
}

@media (max-width: 640px) {
  .command-palette { left: 10px; right: 10px; }
  .command-option { grid-template-columns: 1fr; gap: 3px; }
}

#chatSend {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s, opacity 0.15s;
}
#chatSend:hover { background: var(--accent-hover); }
#chatSend:disabled { opacity: 0.4; cursor: default; }

#chatImage {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: none;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s, color 0.15s;
}
#chatImage:hover { background: var(--bg-elevated); color: var(--text); }

/* ---------- 图片消息 ---------- */

.chat-attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 0 8px 8px;
}
.att-item {
  position: relative;
  width: 72px;
  height: 72px;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
}
.att-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  cursor: pointer;
}
.att-loading {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  color: var(--text-dim);
  animation: pulse 1.4s ease-in-out infinite;
}
.att-remove {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: none;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-size: 10px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.att-remove:hover { background: rgba(0, 0, 0, 0.8); }

.msg-images {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
  justify-content: flex-end;
}
.msg-img {
  max-width: 220px;
  max-height: 220px;
  border-radius: 8px;
  border: 1px solid var(--border);
  cursor: zoom-in;
  object-fit: contain;
  display: block;
}
.img-broken {
  width: 120px;
  height: 72px;
  border-radius: 8px;
  border: 1px dashed var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  color: var(--text-dim);
}

/* 拖拽高亮 */
#view-chat.dragging::after {
  content: "松开以发送图片";
  position: absolute;
  inset: 8px;
  border: 2px dashed var(--accent);
  border-radius: var(--radius);
  background: rgba(217, 119, 87, 0.08);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  color: var(--accent);
  pointer-events: none;
  z-index: 5;
}
#view-chat { position: relative; }

/* 图片灯箱 */
#lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.82);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: zoom-out;
  z-index: 300;
}
#lightbox img {
  max-width: 92vw;
  max-height: 92vh;
  border-radius: 6px;
}

/* admin 图片缩略图 */
.admin-thumb {
  width: 44px;
  height: 44px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--border);
  display: block;
  margin-bottom: 4px;
  cursor: zoom-in;
}

/* ========== 通用视图头 / 卡片 / 按钮 ========== */

.view-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px 12px;
  border-bottom: 1px solid var(--border);
}
.view-header h2 { font-size: 16px; font-weight: 600; }

.card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  border-radius: var(--radius-sm);
  padding: 8px 18px;
  font-size: 14px;
  transition: background 0.15s;
}
.btn-primary:hover { background: var(--accent-hover); }

.btn-ghost {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 14px;
  font-size: 13px;
  color: var(--text-dim);
  transition: all 0.15s;
}
.btn-ghost:hover { color: var(--text); border-color: var(--text-faint); }

.btn-danger {
  color: var(--danger);
  border: 1px solid var(--danger);
  border-radius: 6px;
  padding: 3px 10px;
  font-size: 12px;
}
.btn-danger:hover { background: rgba(207, 106, 95, 0.12); }

.btn-mini {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 3px 10px;
  font-size: 12px;
  color: var(--text-dim);
  margin-right: 6px;
}
.btn-mini:hover { color: var(--text); border-color: var(--text-faint); }

.hint { font-size: 12.5px; color: var(--text-faint); }

/* ========== 记忆库管理 ========== */

#view-admin { overflow-y: auto; padding-bottom: 30px; }
#view-admin > * { max-width: 1080px; width: 100%; margin: 0 auto; padding-left: 24px; padding-right: 24px; }
#view-admin .view-header { max-width: none; padding-left: 24px; }

.admin-tabs { display: flex; gap: 6px; padding-top: 16px; flex-wrap: wrap; }
.admin-tabs button {
  font-family: var(--mono);
  font-size: 12.5px;
  padding: 6px 14px;
  border-radius: 99px;
  border: 1px solid var(--border);
  color: var(--text-dim);
  transition: all 0.12s;
}
.admin-tabs button:hover { color: var(--text); }
.admin-tabs button.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

.admin-toolbar {
  display: flex;
  gap: 8px;
  align-items: center;
  padding-top: 14px;
  flex-wrap: wrap;
}
.admin-toolbar input, .admin-toolbar select { padding: 6px 10px; font-size: 13px; }
.admin-toolbar .spacer { flex: 1; }

.admin-table-wrap {
  margin-top: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow-x: auto;
  background: var(--bg-elevated);
}

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td {
  text-align: left;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
th {
  font-size: 12px;
  color: var(--text-faint);
  font-weight: 500;
  white-space: nowrap;
  background: rgba(0, 0, 0, 0.15);
  position: sticky;
  top: 0;
}
tr:last-child td { border-bottom: none; }
tr:hover td { background: rgba(255, 255, 255, 0.02); }
td.mono { font-family: var(--mono); font-size: 12px; }
td.cell-text { max-width: 420px; }
td.cell-text .cell-clamp {
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
  white-space: pre-wrap;
  word-break: break-word;
}

.admin-pager {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-top: 12px;
  font-size: 13px;
  color: var(--text-dim);
}

.sql-console { margin-top: 26px; }
.sql-console h3 { font-size: 14px; font-weight: 600; display: flex; align-items: baseline; gap: 10px; }
#sqlInput {
  width: 100%;
  margin-top: 10px;
  font-family: var(--mono);
  font-size: 13px;
  resize: vertical;
}
.sql-actions { display: flex; align-items: center; gap: 12px; margin-top: 8px; }

/* ========== 状态视图 ========== */

#view-status { overflow-y: auto; }
#statusContent {
  max-width: 860px;
  width: 100%;
  margin: 0 auto;
  padding: 20px 24px 40px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

/* ========== 统计视图 ========== */

#view-stats { overflow-y: auto; }
.stats-actions { display: flex; align-items: center; gap: 12px; }
.stats-granularity { display: flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.stats-granularity button {
  background: none;
  border: none;
  color: var(--text-dim);
  padding: 5px 12px;
  font-size: 12.5px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.stats-granularity button.active { background: var(--accent); color: #fff; }
.stats-cards {
  max-width: 1060px;
  width: 100%;
  margin: 0 auto;
  padding: 20px 24px 0;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
}
.stats-card h3 {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dim);
  margin-bottom: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.stats-balance {
  font-size: 26px;
  font-weight: 700;
  padding: 2px 0 10px;
}
.stats-balance.warn { color: var(--danger); }
.stats-chart-card {
  max-width: 1060px;
  width: calc(100% - 48px);
  margin: 14px auto 0;
  padding: 18px 20px;
}
.stats-chart-card h3 {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dim);
  margin-bottom: 14px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.stats-canvas-wrap {
  position: relative;
  height: 260px;
}
#view-stats > .stats-chart-card:last-child { margin-bottom: 40px; }

.status-card { grid-column: span 1; }
.status-card.wide { grid-column: span 2; }
.status-card h3 {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dim);
  margin-bottom: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.stat-row {
  display: flex;
  justify-content: space-between;
  font-size: 13.5px;
  padding: 4px 0;
}
.stat-row .k { color: var(--text-dim); }
.stat-row .v { font-family: var(--mono); font-size: 12.5px; }

.meter-row { margin: 10px 0; }
.meter-row .meter-label {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  margin-bottom: 4px;
}
.meter-row .meter-label .v { font-family: var(--mono); color: var(--text-dim); }
.meter {
  height: 7px;
  background: var(--bg);
  border-radius: 99px;
  overflow: hidden;
}
.meter > div {
  height: 100%;
  border-radius: 99px;
  background: var(--accent);
  transition: width 0.4s;
}
.meter.emotion > div { background: #d9a057; }
.meter.miss > div { background: #c77d9e; }
.meter.drift > div { background: #7d9ec7; }

/* ========== 设置视图 ========== */

#view-settings { overflow-y: auto; }
#view-settings .settings-form {
  max-width: 560px;
  width: calc(100% - 48px);
  margin: 20px auto 0;
}
.settings-form h3 { font-size: 14px; margin-bottom: 6px; }
.form-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 14px 0;
  font-size: 13.5px;
  color: var(--text-dim);
}
.form-row input { width: 100%; }
.backup-filter-row {
  flex-direction: row;
  gap: 8px;
}
.backup-filter-row input { flex: 1; }
.settings-form .admin-table-wrap {
  max-height: 320px;
  margin-top: 10px;
}
.switch-row {
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
}
.switch-row input[type="checkbox"] {
  width: 40px;
  height: 22px;
  appearance: none;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 99px;
  position: relative;
  cursor: pointer;
  transition: background 0.15s;
  padding: 0;
  flex-shrink: 0;
}
.switch-row input[type="checkbox"]::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--text-dim);
  transition: all 0.15s;
}
.switch-row input[type="checkbox"]:checked { background: var(--accent); border-color: var(--accent); }
.switch-row input[type="checkbox"]:checked::after { left: 20px; background: #fff; }
.form-actions { display: flex; align-items: center; gap: 12px; margin-top: 16px; }

/* ========== 登录遮罩 ========== */

#loginOverlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.login-box {
  display: flex;
  flex-direction: column;
  gap: 14px;
  width: 300px;
  text-align: center;
}
.login-box .logo { justify-content: center; padding-bottom: 4px; }
.login-box p { color: var(--text-dim); font-size: 14px; }
#loginMsg { min-height: 18px; }

/* ========== 模态框 ========== */

dialog {
  background: var(--bg-elevated);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 22px;
  width: 440px;
  max-width: 92vw;
}
dialog::backdrop { background: rgba(0, 0, 0, 0.55); }
dialog h3 { font-size: 15px; margin-bottom: 12px; }
#modalBody .form-row { margin: 10px 0; }
#modalBody textarea { resize: vertical; min-height: 70px; width: 100%; }
#modalBody input, #modalBody select { width: 100%; }
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 18px;
}

/* 状态徽标 */
.badge {
  display: inline-block;
  font-size: 11px;
  border-radius: 99px;
  padding: 1px 9px;
  border: 1px solid var(--border);
  color: var(--text-dim);
}
.badge.active, .badge.in_progress { color: var(--ok); border-color: var(--ok); }
.badge.inactive, .badge.completed { color: var(--text-faint); }
.badge.high { color: var(--accent); border-color: var(--accent); }
.badge.system { color: var(--text-faint); }

/* ========== 终端视图 ========== */

#view-terminal {
  background: #141b24;
}

#view-terminal .view-header {
  background: #1a2230;
  border-bottom: 1px solid var(--border);
}

.terminal-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.terminal-body {
  flex: 1;
  min-height: 0;
  padding: 10px 6px 6px 12px;
  overflow: hidden;
}

.terminal-body .xterm {
  height: 100%;
}

.terminal-body .xterm-viewport {
  overflow-y: auto !important;
  scrollbar-width: thin;
  scrollbar-color: #3d342a transparent;
}

.terminal-body .xterm-viewport::-webkit-scrollbar {
  width: 10px;
}

.terminal-body .xterm-viewport::-webkit-scrollbar-thumb {
  background: #3d342a;
  border-radius: 4px;
}

.terminal-body .xterm-viewport::-webkit-scrollbar-thumb:hover {
  background: #51453a;
}

/* ========== 知识图谱 ========== */

#view-graph .view-header { padding-left: 24px; }
.graph-actions { display: flex; align-items: center; gap: 12px; }

.graph-toolbar {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  padding: 12px 24px;
  border-bottom: 1px solid var(--border);
}
.graph-filter {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-dim);
  cursor: pointer;
  user-select: none;
}
.graph-filter input[type="checkbox"] {
  accent-color: var(--accent);
  width: 14px;
  height: 14px;
  cursor: pointer;
}
.graph-search {
  flex: 1;
  min-width: 180px;
  max-width: 360px;
  padding: 6px 12px;
  font-size: 13px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
}
.graph-search:focus { border-color: var(--accent); }

.graph-canvas {
  position: relative;
  flex: 1;
  min-height: 0;
  background:
    radial-gradient(circle at 1px 1px, rgba(255, 255, 255, 0.04) 1px, transparent 0);
  background-size: 24px 24px;
}
.graph-empty {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-faint);
  font-size: 14px;
  pointer-events: none;
}

.graph-detail {
  position: absolute;
  right: 16px;
  bottom: 16px;
  width: 380px;
  max-width: 52vw;
  max-height: 85%;
  overflow-y: auto;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  font-size: 13.5px;
  color: var(--text-dim);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
}
.graph-detail .detail-label {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 8px;
}
.graph-detail .detail-label.event { color: #e8b667; }
.graph-detail .detail-label.person { color: #7fb2e5; }
.graph-detail .detail-label.concept { color: #9cc98b; }
.graph-detail .detail-label.location { color: #e5879a; }
.graph-detail .k {
  display: inline-block;
  min-width: 44px;
  color: var(--text-faint);
  margin-right: 6px;
}
.graph-detail .detail-content {
  margin-top: 6px;
}
.graph-detail .detail-text {
  margin-top: 6px;
  padding: 10px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 340px;
  overflow-y: auto;
}
.graph-detail .detail-related-title {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.03em;
  color: var(--text-faint);
}
.graph-detail .related-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 8px;
}
.graph-detail .related-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.12s;
}
.graph-detail .related-item:hover {
  background: var(--bg-hover);
  border-color: var(--accent);
}
.graph-detail .related-arrow {
  flex-shrink: 0;
  color: var(--accent);
  font-weight: 600;
}
.graph-detail .related-label {
  flex-shrink: 0;
  max-width: 40%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text);
}
.graph-detail .related-type {
  flex: 1;
  text-align: right;
  font-size: 12px;
  color: var(--text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.graph-detail .related-pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 8px;
}
.graph-detail .related-page-btn {
  font-size: 12px;
  color: var(--text-dim);
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition: all 0.12s;
}
.graph-detail .related-page-btn:hover:not(:disabled) {
  color: var(--text);
  border-color: var(--accent);
}
.graph-detail .related-page-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.graph-detail .related-page-info {
  font-size: 12px;
  color: var(--text-faint);
}
