/* dshgate 暗色后台主题 */
:root {
  --primary: #667eea;
  --primary-2: #764ba2;
  --primary-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  --success: #67c23a;
  --warning: #e6a23c;
  --danger: #f56c6c;

  --bg-primary: #0f1419;
  --bg-secondary: #192734;
  --bg-hover: rgba(255, 255, 255, 0.05);
  --bg-active: rgba(102, 126, 234, 0.15);

  --text-primary: #f5f7fa;
  --text-secondary: #8899a6;
  --text-tertiary: #657786;

  --border-color: rgba(255, 255, 255, 0.1);
  --border-highlight: rgba(102, 126, 234, 0.35);

  --glass-bg: rgba(255, 255, 255, 0.05);
  --glass-border: rgba(255, 255, 255, 0.08);

  --code-bg: rgba(255, 255, 255, 0.06);
  --log-bg: #0b0f14;
  --log-text: #d7dde6;
}

* { box-sizing: border-box; }

/* 覆盖 .btn / .pg-body-wrap 等组件设置的 display，让 hidden 属性真正生效 */
[hidden] { display: none !important; }

body {
  margin: 0;
  font: 14px/1.6 -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
}

/* ---------- 布局骨架 ---------- */
.admin-sidebar {
  position: fixed;
  left: 0;
  top: 0;
  bottom: 0;
  width: 200px;
  padding: 0 16px 16px;
  background: var(--bg-primary);
  border-right: 1px solid var(--border-color);
  overflow-y: auto;
  z-index: 100;
  display: flex;
  flex-direction: column;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  padding: 16px 0;
  border-bottom: 1px solid var(--border-color);
}

.sidebar-brand {
  font-size: 15px;
  font-weight: 800;
  color: var(--primary);
  display: flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  letter-spacing: 1px;
}

nav { padding-top: 16px; flex: 1; }

.sidebar-section { margin-bottom: 16px; }

.sidebar-title {
  font-size: 11px;
  color: var(--text-tertiary);
  padding: 8px 0 6px;
  font-weight: 500;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 12px;
  margin-bottom: 2px;
  border-radius: 6px;
  border: none;
  background: none;
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 14px;
  font-family: inherit;
  text-align: left;
  text-decoration: none;
  transition: all 0.15s;
}
.nav-item:hover { color: var(--text-primary); background: var(--bg-hover); }
.nav-item.active, .nav-item.on { color: var(--primary); background: var(--bg-active); }

.nav-icon { width: 18px; height: 18px; flex: none; }

.sidebar-footer {
  border-top: 1px solid var(--border-color);
  padding-top: 12px;
}

.admin-header {
  position: fixed;
  top: 0;
  left: 200px;
  right: 0;
  height: 60px;
  padding: 0 24px;
  background: var(--bg-primary);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  z-index: 99;
}

.page-title {
  font-size: 20px;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.header-right { display: flex; align-items: center; gap: 16px; }

.header-user {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: 10px;
}

.header-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--primary-gradient);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 14px;
  font-weight: 600;
}

.header-username { font-size: 14px; font-weight: 500; color: var(--text-primary); }

.admin-content {
  margin-left: 200px;
  margin-top: 60px;
  padding: 24px;
  min-height: calc(100vh - 60px);
  max-width: 1440px;
}

/* 独立页（登录） */
body.bare .admin-header { display: none; }
body.bare .admin-content {
  margin: 0;
  padding: 0;
  min-height: 100vh;
  max-width: none;
}

.login-wrap {
  min-height: 100vh;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 32px;
  background:
    radial-gradient(900px 480px at 18% 0%, rgba(102, 126, 234, 0.14), transparent 60%),
    radial-gradient(760px 460px at 85% 100%, rgba(118, 75, 162, 0.16), transparent 60%),
    radial-gradient(600px 300px at 70% 15%, rgba(103, 194, 58, 0.05), transparent 60%),
    var(--bg-primary);
  padding: 32px 20px;
}

.login-brand { text-align: center; }
.brand-mark.lg { width: 58px; height: 58px; border-radius: 16px; font-size: 26px; box-shadow: 0 8px 24px rgba(102, 126, 234, 0.35); }
.login-brand h1 {
  margin: 18px 0 6px;
  font-size: 32px;
  font-weight: 800;
  letter-spacing: 1px;
  background: var(--primary-gradient);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}
.login-brand p { font-size: 13px; letter-spacing: 0.5px; }

.login-card {
  width: 100%;
  max-width: 440px;
  padding: 38px 40px 34px;
  border: 1px solid var(--border-highlight);
  background: linear-gradient(180deg, rgba(25, 39, 52, 0.92), rgba(13, 19, 25, 0.96));
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.06);
}
.login-card .muted { font-size: 13px; margin-top: 0; }
.login-card label {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 16px;
}
.login-card input[type="text"], .login-card input[type="password"], .login-card input:not([type]) {
  margin-top: 6px;
  padding: 11px 14px;
  font-size: 15px;
  border-radius: 8px;
}
.login-card .btn {
  width: 100%;
  padding: 11px;
  font-size: 15px;
  border-radius: 8px;
  margin-top: 4px;
}

/* ---------- 通用组件 ---------- */
h1 { font-size: 20px; margin: 8px 0 16px; }
h2 { font-size: 15px; margin: 0 0 12px; }
h3 { font-size: 14px; margin: 20px 0 10px; }

.muted { color: var(--text-secondary); }
.link { color: var(--primary); text-decoration: none; }
.link:hover { text-decoration: underline; }
.nowrap { white-space: nowrap; }
.cell-clip { max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 20px;
  margin-bottom: 20px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.25);
}
.card.narrow { max-width: 400px; padding: 28px; }
.card.narrow-wide { max-width: 560px; }

.banner {
  padding: 10px 14px;
  border-radius: 8px;
  margin: 0 0 14px;
  font-size: 13px;
}
.banner.error { background: rgba(245, 108, 108, 0.12); color: #f5a3a3; border: 1px solid rgba(245, 108, 108, 0.35); }
.banner.ok { background: rgba(103, 194, 58, 0.12); color: #a5e18a; border: 1px solid rgba(103, 194, 58, 0.35); }

table { width: 100%; border-collapse: collapse; margin-bottom: 14px; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid rgba(255, 255, 255, 0.08); vertical-align: middle; }
th { font-size: 12px; color: var(--text-tertiary); font-weight: 600; white-space: nowrap; }
tbody tr:hover { background: var(--bg-hover); }
td.empty { color: var(--text-tertiary); text-align: center; padding: 24px; }

code {
  font-family: ui-monospace, Consolas, "Courier New", monospace;
  font-size: 12px;
  background: var(--code-bg);
  padding: 2px 5px;
  border-radius: 4px;
  word-break: break-all;
}
code.wrap { word-break: break-all; }
code.key { color: #b9c3d4; letter-spacing: 0.2px; }

.badge {
  display: inline-block;
  font-size: 11px;
  padding: 1px 9px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-secondary);
  white-space: nowrap;
}
.badge.b-busy, .badge.b-running, .badge.b-cancelling { background: rgba(230, 162, 60, 0.15); color: #e6a23c; }
.badge.b-completed, .badge.b-idle { background: rgba(103, 194, 58, 0.15); color: #67c23a; }
.badge.b-failed { background: rgba(245, 108, 108, 0.15); color: #f56c6c; }
.badge.b-cancelled, .badge.b-pending, .badge.b-off { background: rgba(255, 255, 255, 0.08); color: var(--text-tertiary); }
.badge.b-env { background: rgba(102, 126, 234, 0.15); color: #8fa3f5; }
.badge.b-managed { background: rgba(102, 126, 234, 0.22); color: #a5b4fc; }

.btn {
  display: inline-block;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: var(--bg-secondary);
  color: var(--text-primary);
  border-radius: 6px;
  padding: 6px 14px;
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  text-decoration: none;
  line-height: 1.5;
  transition: all 0.15s;
}
.btn:hover { border-color: var(--border-highlight); }
.btn.primary {
  background: var(--primary-gradient);
  border-color: transparent;
  color: #fff;
  font-weight: 500;
}
.btn.primary:hover { filter: brightness(1.1); }
.btn.danger { background: var(--danger); border-color: transparent; color: #fff; }
.btn.small { padding: 2px 10px; font-size: 12px; }
.btn.ghost { background: transparent; }
.btn.danger.ghost { color: var(--danger); border-color: rgba(245, 108, 108, 0.4); }
.btn.danger.ghost:hover { border-color: var(--danger); background: rgba(245, 108, 108, 0.08); }
.btn:disabled { opacity: 0.5; cursor: default; }

input[type="text"], input:not([type]), input[type="password"], input[type="number"], select, textarea {
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 6px;
  padding: 7px 10px;
  font-size: 13px;
  width: 100%;
  background: var(--bg-primary);
  color: var(--text-primary);
}
input::placeholder, textarea::placeholder { color: var(--text-tertiary); }
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.18);
}
select option { background: var(--bg-secondary); color: var(--text-primary); }

textarea {
  font: 13px/1.55 ui-monospace, Consolas, monospace;
  resize: vertical;
}
label { display: block; margin-bottom: 12px; }
label.check { display: inline-flex; gap: 6px; align-items: center; margin: 0; }

.hint { font-size: 12px; color: var(--text-tertiary); margin: 4px 0 12px; }
.hint code { font-size: 11px; }

form.inline-form {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
  margin-top: 8px;
}
form.inline-form input { flex: 1 1 200px; min-width: 160px; }

.settings-form { max-width: 640px; }
.settings-form label { display: block; margin-bottom: 12px; }
.settings-form input, .settings-form textarea, .settings-form select { margin-top: 4px; }

.login-form label { display: block; margin-bottom: 14px; }

.row-actions { display: flex; gap: 6px; align-items: center; white-space: nowrap; }
.row-actions form { display: inline; }

.note-form { display: flex; gap: 6px; align-items: center; }
.note-form input { width: 200px; border-color: transparent; background: transparent; padding: 4px 6px; }
.note-form input:hover, .note-form input:focus { border-color: var(--border-color); background: var(--bg-primary); }
.note-form input.saved-flash { border-color: rgba(103, 194, 58, 0.6); background: rgba(103, 194, 58, 0.08); }

.key-details { position: relative; }
.key-details summary { cursor: pointer; color: var(--text-secondary); font-size: 13px; list-style: none; }
.key-details summary::-webkit-details-marker { display: none; }
.key-pop {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  width: 340px;
  padding: 14px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
  display: flex;
  gap: 8px;
  align-items: center;
  z-index: 120;
}
.key-pop form { display: inline; }

.row-details { position: relative; display: inline-block; }
.row-details summary { cursor: pointer; }
.row-popform {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  width: 260px;
  padding: 12px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
  display: flex;
  gap: 8px;
  align-items: center;
  z-index: 120;
}

/* ---------- 数据看板 ---------- */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}
.stat-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 18px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.25);
}
.stat-value { font-size: 28px; font-weight: 700; color: var(--text-primary); }
.stat-sub { font-size: 13px; font-weight: 500; color: var(--text-tertiary); margin-left: 6px; }
.stat-label { font-size: 12px; color: var(--text-tertiary); margin-top: 2px; }

/* ---------- 项目空间 tab 切换 ---------- */
.tab { display: none; }
.tab.on { display: block; }

.console-top {
  display: flex;
  gap: 16px;
  align-items: center;
  margin-bottom: 10px;
  flex-wrap: wrap;
}
.console-top #user-name { max-width: 180px; }
#session-id:empty::before { content: "（新会话，运行后生成）"; color: var(--text-tertiary); }

.console-actions { display: flex; gap: 10px; align-items: center; margin: 10px 0 16px; }

.console-grid {
  display: grid;
  grid-template-columns: minmax(0, 5fr) minmax(0, 4fr);
  gap: 18px;
  align-items: start;
}

.console-side .side-title {
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 6px;
}
.console-side .log {
  min-height: 420px;
  max-height: calc(100vh - 170px);
  position: sticky;
  top: 12px;
}

#final-answer {
  background: rgba(102, 126, 234, 0.1);
  border: 1px solid var(--border-highlight);
  border-radius: 8px;
  padding: 12px 16px;
  margin-bottom: 14px;
  white-space: pre-wrap;
}

.log {
  background: var(--log-bg);
  color: var(--log-text);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 12px;
  min-height: 320px;
  max-height: 560px;
  overflow-y: auto;
  font-family: ui-monospace, Consolas, monospace;
  font-size: 12px;
}
.ev { margin-bottom: 8px; }
.ev .ev-type {
  display: inline-block;
  font-size: 11px;
  padding: 0 6px;
  border-radius: 4px;
  background: #1c2531;
  color: #8fa3bd;
  margin-bottom: 3px;
}
.ev pre {
  margin: 0;
  padding: 6px 8px;
  border-left: 2px solid #2c3646;
  white-space: pre-wrap;
  word-break: break-word;
}
.k-tool .ev-type { background: #3a2f18; color: #e0b45c; }
.k-error pre { border-left-color: #a33; color: #f0b6ad; }
.k-done .ev-type { background: #173425; color: #6fd39c; }
.k-info .ev-type { background: #1d2c47; color: #86aade; }

/* ---------- 接口文档 ---------- */
.doc-steps { padding-left: 20px; margin: 0 0 10px; }
.doc-steps li { margin: 4px 0; }
.doc-list { padding-left: 20px; margin: 0 0 12px; }
.doc-list li { margin: 4px 0; }

.endpoint { margin: 0 0 22px; }
.endpoint .ep-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}
.ep-path { font-size: 13px; font-weight: 600; background: var(--code-bg); }
.ep-desc { color: var(--text-secondary); font-size: 13px; }

.method {
  display: inline-block;
  min-width: 52px;
  text-align: center;
  font-size: 11px;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 5px;
  color: #fff;
}
.method.m-get { background: #2d7dd2; }
.method.m-post { background: #2f9e6e; }
.method.m-delete, .method.m-put, .method.m-patch { background: #c0474f; }

pre.codeblock {
  position: relative;
  background: var(--log-bg);
  color: var(--log-text);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  padding: 12px 14px;
  margin: 8px 0 14px;
  overflow-x: auto;
  font: 12px/1.6 ui-monospace, Consolas, monospace;
  white-space: pre;
}
.copy-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: var(--bg-secondary);
  color: var(--text-secondary);
  border-radius: 5px;
  padding: 2px 10px;
  font-size: 11px;
  cursor: pointer;
}
.copy-btn:hover { color: var(--text-primary); border-color: var(--border-highlight); }

/* ---------- API 调试台 ---------- */
.pg-row {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.pg-req select,
.pg-req input,
.pg-req .btn {
  height: 34px;
}
.pg-req .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding-top: 0;
  padding-bottom: 0;
}
.pg-method { width: 110px; }
.pg-path { flex: 1 1 360px; min-width: 220px; }
.pg-auth { flex: 1 1 360px; min-width: 220px; }
.pg-label { display: block; font-size: 12px; color: var(--text-tertiary); margin-bottom: 4px; }
.pg-body-wrap { display: block; margin-bottom: 12px; }
.pg-body-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 4px; }
.pg-body-modes { display: flex; gap: 14px; align-items: center; font-size: 13px; }
.pg-body-modes label.check { margin: 0; color: var(--text-secondary); }
.pg-body-modes input { width: auto; }
.pg-project-sel select { max-width: 360px; }

.pg-example-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
}
.pg-example-group {
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 12px;
}
.pg-example-group .pg-label {
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 8px;
}
.pg-example-group .btn {
  display: block;
  width: 100%;
  text-align: left;
  margin-bottom: 6px;
  white-space: normal;
}
.pg-example-group .btn:last-child { margin-bottom: 0; }

.pg-result-head { display: flex; gap: 12px; align-items: center; margin-bottom: 8px; }
.pg-out {
  background: var(--log-bg);
  color: var(--log-text);
  border-radius: 8px;
  padding: 14px;
  min-height: 120px;
  max-height: 480px;
  overflow: auto;
  font: 12px/1.6 ui-monospace, Consolas, monospace;
  white-space: pre-wrap;
  word-break: break-word;
  margin: 0;
}

/* ---------- MCP 服务面板 ---------- */
.mcp-card .mcp-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.mcp-name { font-size: 14px; }
.mcp-endpoint {
  font-size: 12px;
  font-family: ui-monospace, Consolas, monospace;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 55%;
}
.mcp-detail { margin-top: 8px; }
.mcp-info { font-size: 12px; color: var(--text-secondary); margin: 0 0 8px; }
.mcp-error {
  color: #f5a3a3;
  font-size: 12px;
  background: rgba(245, 108, 108, 0.08);
  border: 1px solid rgba(245, 108, 108, 0.22);
  border-radius: 6px;
  padding: 8px 10px;
  margin: 4px 0 0;
  word-break: break-all;
}
.mcp-tool-list {
  max-height: 320px;
  overflow-y: auto;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 4px 8px;
}
.mcp-tool {
  display: flex;
  gap: 10px;
  align-items: baseline;
  padding: 6px 4px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}
.mcp-tool:last-child { border-bottom: none; }
.mcp-tool-name { flex: none; font-weight: 600; }
.mcp-tool-desc { color: var(--text-secondary); font-size: 12px; }

/* MCP 管理：新增/编辑表单 */
.mcp-form .mcp-name-field { max-width: 320px; }
.mcp-form .mcp-kind { display: flex; gap: 18px; align-items: center; margin-bottom: 12px; }
.mcp-form .mcp-fields { margin-bottom: 12px; }
.mcp-form .mcp-fields label { margin-bottom: 10px; }
.mcp-form .mcp-fields textarea { font-size: 12px; }
.mcp-edit {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border-color);
}
.mcp-edit form { max-width: 460px; }
.mcp-actions { display: flex; gap: 8px; margin-top: 12px; }
.inline-submit { display: inline; margin: 0; }
.mcp-empty { margin-top: 14px; }

/* ---------- 响应式 ---------- */
@media (max-width: 960px) {
  .console-grid { grid-template-columns: 1fr; }
  .console-side .log { position: static; max-height: 560px; }
}

@media (max-width: 768px) {
  .admin-sidebar {
    position: relative;
    width: 100%;
    height: auto;
    border-right: none;
    border-bottom: 1px solid var(--border-color);
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
  }
  .sidebar-header { padding: 4px 0; border-bottom: none; }
  nav { display: flex; flex-wrap: wrap; gap: 4px; padding: 0; }
  .sidebar-section { margin: 0; }
  .sidebar-title { display: none; }
  .nav-item { width: auto; padding: 6px 10px; font-size: 13px; }
  .nav-icon { display: none; }
  .sidebar-footer { display: none; }
  .admin-header { position: relative; left: 0; }
  .admin-content { margin-left: 0; margin-top: 0; }
}
