:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --panel-2: #fafbfc;
  --line: #e3e7ee;
  --line-2: #eef1f5;
  --text: #1b2230;
  --text-2: #5b6577;
  --text-3: #8b95a7;
  --brand: #1f5eff;
  --brand-soft: #eaf0ff;
  --ok: #0a7d4a;
  --ok-soft: #e6f6ee;
  --warn: #a86a00;
  --warn-soft: #fdf5e3;
  --danger: #c0392b;
  --danger-soft: #fdecea;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(20, 30, 60, .04), 0 8px 24px rgba(20, 30, 60, .05);
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

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

body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.6 -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--brand); text-decoration: none; }

/* ============ 布局 ============ */
.app {
  height: 100vh;
  display: grid;
  grid-template-rows: 52px 1fr;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  z-index: 10;
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  font-weight: 650;
  letter-spacing: .2px;
  white-space: nowrap;
}
.brand-mark {
  width: 24px; height: 24px;
  border-radius: 7px;
  background: linear-gradient(135deg, #1f5eff, #5b8cff);
  display: grid; place-items: center;
  color: #fff; font-size: 13px; font-weight: 800;
}
.brand small {
  font-weight: 400;
  color: var(--text-3);
  font-size: 11px;
  margin-left: 2px;
}

.topbar-spacer { flex: 1; }

.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  font-size: 11.5px;
  color: var(--text-2);
  white-space: nowrap;
}
.chip b { color: var(--text); font-weight: 600; }
.chip .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--text-3); }
.chip.ok .dot { background: var(--ok); }
.chip.warn .dot { background: var(--warn); }
.chip.bad .dot { background: var(--danger); }

.main {
  display: grid;
  grid-template-columns: 232px 1fr 320px;
  min-height: 0;
  overflow: hidden;
}

/* ============ 通用面板 ============ */
.col {
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.col-left { background: var(--panel); border-right: 1px solid var(--line); }
.col-right { background: var(--panel); border-left: 1px solid var(--line); }
.col-mid { background: var(--bg); }

.col-head {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line-2);
  font-size: 12px;
  font-weight: 600;
  color: var(--text-2);
  letter-spacing: .3px;
  text-transform: uppercase;
  flex-shrink: 0;
}
.col-head .grow { flex: 1; }

.col-body { flex: 1; overflow-y: auto; min-height: 0; }
.col-body::-webkit-scrollbar { width: 8px; }
.col-body::-webkit-scrollbar-thumb { background: #d8dde6; border-radius: 4px; }
.col-body::-webkit-scrollbar-thumb:hover { background: #c4cbd7; }

/* ============ 按钮 ============ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 5px;
  padding: 6px 12px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  font-size: 13px;
  transition: background .12s, border-color .12s, opacity .12s;
  white-space: nowrap;
}
.btn:hover { background: var(--panel-2); border-color: #d3d9e4; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary {
  background: var(--brand); border-color: var(--brand); color: #fff;
}
.btn-primary:hover { background: #1a51e0; border-color: #1a51e0; }
.btn-ghost { border-color: transparent; background: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--panel-2); color: var(--text); }
.btn-sm { padding: 3px 8px; font-size: 12px; border-radius: 7px; }
.btn-danger { color: var(--danger); border-color: #f2d3cf; background: #fff; }
.btn-danger:hover { background: var(--danger-soft); }
.btn-icon { padding: 4px 7px; }

/* ============ 项目列表 ============ */
.prj {
  padding: 9px 12px;
  border-bottom: 1px solid var(--line-2);
  cursor: pointer;
  transition: background .12s;
  position: relative;
}
.prj:hover { background: var(--panel-2); }
.prj.active { background: var(--brand-soft); }
.prj.active::before {
  content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 3px;
  background: var(--brand);
}
.prj-name {
  font-weight: 550;
  font-size: 13.5px;
  display: flex; align-items: center; gap: 6px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.prj-meta {
  margin-top: 2px;
  font-size: 11.5px;
  color: var(--text-3);
  display: flex; gap: 8px; align-items: center;
  overflow: hidden;
}
.tag {
  font-size: 10.5px;
  padding: 1px 6px;
  border-radius: 5px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--text-2);
  font-weight: 500;
  flex-shrink: 0;
}
.tag.live { background: var(--ok-soft); color: var(--ok); border-color: #cfeadd; }
.tag.idle { background: var(--warn-soft); color: var(--warn); border-color: #f0e2c2; }

.empty {
  padding: 28px 16px;
  text-align: center;
  color: var(--text-3);
  font-size: 12.5px;
  line-height: 1.9;
}

/* ============ 对话区 ============ */
.chat-head {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
  min-height: 50px;
}
.chat-title { font-weight: 600; font-size: 14.5px; }
.chat-sub { font-size: 11.5px; color: var(--text-3); display: flex; gap: 8px; align-items: center; }
.chat-head .grow { flex: 1; }

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 22px 0 10px;
  min-height: 0;
}
.messages::-webkit-scrollbar { width: 9px; }
.messages::-webkit-scrollbar-thumb { background: #d8dde6; border-radius: 5px; }

.msg-wrap { max-width: 860px; margin: 0 auto 18px; padding: 0 24px; display: flex; gap: 10px; }
.msg-wrap.user { flex-direction: row-reverse; }
.msg-wrap > .msg-col { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: flex-start; }
.msg-wrap.user > .msg-col { align-items: flex-end; }

.avatar {
  width: 26px; height: 26px; border-radius: 8px;
  flex-shrink: 0;
  display: grid; place-items: center;
  font-size: 11px; font-weight: 700;
  margin-top: 2px;
}
.msg-wrap.user .avatar { background: #1b2230; color: #fff; }
.msg-wrap.assistant .avatar { background: linear-gradient(135deg, #1f5eff, #5b8cff); color: #fff; }

.bubble {
  max-width: 100%;
  padding: 11px 15px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.72;
  word-break: break-word;
  white-space: pre-wrap;
}
.msg-wrap.user .bubble {
  background: #1b2230;
  color: #f2f5fa;
  border-bottom-right-radius: 4px;
}
.msg-wrap.assistant .bubble {
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  border-bottom-left-radius: 4px;
}
.bubble code {
  font-family: var(--mono);
  font-size: 12.5px;
  background: #f1f4f9;
  padding: 1px 5px;
  border-radius: 4px;
}
.msg-wrap.user .bubble code { background: rgba(255,255,255,.14); }
.bubble pre {
  background: #f6f8fb;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px 13px;
  overflow-x: auto;
  margin: 9px 0;
}
.bubble pre code { background: none; padding: 0; }
.bubble table { border-collapse: collapse; margin: 9px 0; font-size: 13px; }
.bubble th, .bubble td { border: 1px solid var(--line); padding: 5px 9px; text-align: left; }
.bubble th { background: var(--panel-2); }

.msg-meta {
  font-size: 10.5px;
  color: var(--text-3);
  margin-top: 5px;
  display: flex; gap: 7px; align-items: center;
}
.msg-wrap.user .msg-meta { justify-content: flex-end; }

.sys-note {
  max-width: 860px; margin: 0 auto 14px; padding: 0 24px;
  font-size: 11.5px; color: var(--text-3);
  text-align: center;
}
.sys-note span {
  display: inline-block;
  background: var(--panel-2);
  border: 1px solid var(--line-2);
  border-radius: 999px;
  padding: 3px 12px;
}
.sys-note.err span { background: var(--danger-soft); border-color: #f2d3cf; color: var(--danger); }

.typing { display: inline-flex; gap: 3px; padding: 3px 0; }
.typing i {
  width: 5px; height: 5px; border-radius: 50%; background: var(--text-3);
  animation: blink 1.2s infinite;
}
.typing i:nth-child(2) { animation-delay: .18s; }
.typing i:nth-child(3) { animation-delay: .36s; }
@keyframes blink { 0%, 60%, 100% { opacity: .25; } 30% { opacity: 1; } }

/* 输入区 */
.composer {
  border-top: 1px solid var(--line);
  background: var(--panel);
  padding: 12px 18px 14px;
  flex-shrink: 0;
}
.composer-inner {
  max-width: 860px; margin: 0 auto;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel-2);
  transition: border-color .15s, box-shadow .15s;
}
.composer-inner:focus-within {
  border-color: #b8caff;
  box-shadow: 0 0 0 3px rgba(31,94,255,.08);
  background: #fff;
}
.composer textarea {
  width: 100%;
  border: 0;
  background: transparent;
  resize: none;
  padding: 11px 14px 4px;
  max-height: 220px;
  min-height: 46px;
  outline: none;
  font-size: 14px;
  line-height: 1.6;
}
.composer-bar {
  display: flex; align-items: center; gap: 8px;
  padding: 5px 10px 9px 14px;
}
.composer-bar .grow { flex: 1; }
.hint { font-size: 11px; color: var(--text-3); }

/* ============ 右侧面板 ============ */
.tabs {
  display: flex;
  gap: 2px;
  padding: 8px 8px 0;
  border-bottom: 1px solid var(--line-2);
  background: var(--panel);
  flex-shrink: 0;
}
.tab {
  padding: 6px 11px;
  border: 0; background: transparent;
  border-radius: 8px 8px 0 0;
  font-size: 12.5px; color: var(--text-2);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.tab:hover { color: var(--text); background: var(--panel-2); }
.tab.on { color: var(--brand); border-bottom-color: var(--brand); font-weight: 600; background: transparent; }

.acc {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line-2);
}
.acc-top { display: flex; align-items: center; gap: 6px; }
.acc-name { font-weight: 550; font-size: 13px; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.acc-rows { margin-top: 5px; font-size: 11.5px; color: var(--text-3); display: flex; flex-wrap: wrap; gap: 4px 10px; }
.acc-acts { margin-top: 7px; display: flex; gap: 5px; flex-wrap: wrap; }

.status-dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; }
.s-active { background: var(--ok); }
.s-expired, .s-disabled { background: var(--danger); }
.s-pending { background: var(--text-3); }

.evt {
  padding: 7px 12px;
  border-bottom: 1px solid var(--line-2);
  font-size: 11.5px;
  display: flex; gap: 7px;
}
.evt-time { color: var(--text-3); font-family: var(--mono); font-size: 10.5px; flex-shrink: 0; padding-top: 1px; }
.evt-msg { color: var(--text-2); line-height: 1.55; }
.evt.error .evt-msg { color: var(--danger); }
.evt.warn .evt-msg { color: var(--warn); }

.job {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line-2);
}
.job-top { display: flex; align-items: center; gap: 6px; font-size: 12.5px; font-weight: 550; }
.job-bar {
  height: 4px; border-radius: 3px; background: var(--line-2);
  margin: 7px 0 5px; overflow: hidden;
}
.job-bar i {
  display: block; height: 100%;
  background: var(--brand);
  transition: width .3s;
  border-radius: 3px;
}
.job-meta { font-size: 11px; color: var(--text-3); display: flex; gap: 8px; }

/* ============ 弹窗 ============ */
.modal-mask {
  position: fixed; inset: 0;
  background: rgba(18, 24, 38, .38);
  backdrop-filter: blur(2px);
  display: grid; place-items: center;
  z-index: 100;
  padding: 24px;
  animation: fade .14s ease;
}
@keyframes fade { from { opacity: 0 } to { opacity: 1 } }
.modal {
  background: var(--panel);
  border-radius: 16px;
  width: 100%;
  max-width: 620px;
  max-height: 86vh;
  display: flex; flex-direction: column;
  box-shadow: 0 20px 70px rgba(15, 25, 50, .22);
  overflow: hidden;
  animation: pop .16s cubic-bezier(.2,.9,.3,1.2);
}
@keyframes pop { from { transform: translateY(8px) scale(.99); opacity: 0 } to { transform: none; opacity: 1 } }
.modal.wide { max-width: 880px; }
.modal-head {
  display: flex; align-items: center; gap: 10px;
  padding: 15px 20px;
  border-bottom: 1px solid var(--line-2);
  font-weight: 600;
  font-size: 15px;
  flex-shrink: 0;
}
.modal-head .grow { flex: 1; }
.modal-body { padding: 18px 20px; overflow-y: auto; flex: 1; }
.modal-foot {
  padding: 13px 20px;
  border-top: 1px solid var(--line-2);
  display: flex; gap: 8px; justify-content: flex-end;
  background: var(--panel-2);
  flex-shrink: 0;
}

.field { margin-bottom: 15px; }
.field:last-child { margin-bottom: 0; }
.field label {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--text-2);
}
.field .desc { font-size: 11.5px; color: var(--text-3); margin-top: 5px; line-height: 1.6; }
.input, .textarea, .select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 8px 11px;
  background: #fff;
  outline: none;
  transition: border-color .13s, box-shadow .13s;
  font-size: 13.5px;
}
.input:focus, .textarea:focus, .select:focus {
  border-color: #b8caff;
  box-shadow: 0 0 0 3px rgba(31,94,255,.08);
}
.textarea { resize: vertical; min-height: 84px; line-height: 1.65; font-family: inherit; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.alert {
  padding: 10px 13px;
  border-radius: 9px;
  font-size: 12.5px;
  line-height: 1.7;
  margin-bottom: 14px;
}
.alert.info { background: var(--brand-soft); color: #1a3fa8; }
.alert.warn { background: var(--warn-soft); color: var(--warn); }
.alert.err { background: var(--danger-soft); color: var(--danger); }
.alert.ok { background: var(--ok-soft); color: var(--ok); }
.alert code { font-family: var(--mono); font-size: 12px; background: rgba(0,0,0,.05); padding: 1px 5px; border-radius: 4px; word-break: break-all; }

.steps { counter-reset: s; margin: 0; padding: 0; list-style: none; }
.steps li {
  counter-increment: s;
  position: relative;
  padding-left: 26px;
  margin-bottom: 10px;
  font-size: 13px;
  line-height: 1.7;
  color: var(--text-2);
}
.steps li::before {
  content: counter(s);
  position: absolute; left: 0; top: 1px;
  width: 18px; height: 18px; border-radius: 50%;
  background: var(--brand); color: #fff;
  font-size: 11px; font-weight: 700;
  display: grid; place-items: center;
}

.kv { display: grid; grid-template-columns: 92px 1fr; gap: 7px 12px; font-size: 12.5px; }
.kv dt { color: var(--text-3); }
.kv dd { margin: 0; word-break: break-all; }

.toast-wrap {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; gap: 8px; z-index: 200;
  pointer-events: none;
}
.toast {
  padding: 9px 16px;
  border-radius: 10px;
  background: #1b2230; color: #fff;
  font-size: 13px;
  box-shadow: 0 8px 28px rgba(15,25,50,.24);
  animation: toastIn .18s ease;
  max-width: 520px;
}
.toast.err { background: var(--danger); }
.toast.ok { background: var(--ok); }
@keyframes toastIn { from { transform: translateY(10px); opacity: 0 } to { transform: none; opacity: 1 } }

.login-mask {
  position: fixed; inset: 0; background: var(--bg);
  display: grid; place-items: center; z-index: 300;
}
.login-box {
  background: var(--panel); padding: 32px; border-radius: 16px;
  width: 340px; box-shadow: var(--shadow); border: 1px solid var(--line);
}

.hidden { display: none !important; }

@media (max-width: 1100px) {
  .main { grid-template-columns: 200px 1fr 280px; }
}
@media (max-width: 900px) {
  .main { grid-template-columns: 1fr; }
  .col-left, .col-right { display: none; }
}
