:root {
  --bg: #f4f4f5;
  --card: #ffffff;
  --text: #09090b;
  --muted: #71717a;
  --border: #e4e4e7;
  --primary: #18181b;
  --primary-hover: #27272a;
  --success: #059669;
  --success-bg: #ecfdf5;
  --warning: #d97706;
  --warning-bg: #fffbeb;
  --danger: #dc2626;
  --danger-bg: #fef2f2;
  --info: #0284c7;
  --info-bg: #f0f9ff;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .05);
  --sidebar: 224px;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.55 Inter, -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--info); text-decoration: none; }
a:hover { text-decoration: underline; }
.hidden { display: none !important; }

/* 登录 */
.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(1200px 600px at 20% 0%, #fafafa 0%, var(--bg) 60%);
  padding: 24px;
}
.login-card {
  width: 380px; max-width: 100%; background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 32px;
}
.login-logo { width: 40px; height: 40px; border-radius: 10px; background: var(--primary); color: #fff; display: grid; place-items: center; font-weight: 700; margin-bottom: 18px; }
.login-card h1 { font-size: 22px; margin: 0 0 6px; }
.login-card p { color: var(--muted); margin: 0 0 24px; font-size: 13px; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.input, .select, .textarea {
  width: 100%; border: 1px solid var(--border); border-radius: 6px; background: #fff;
  padding: 8px 10px; outline: none; min-height: 36px; transition: border-color .15s, box-shadow .15s;
}
.input:focus, .select:focus, .textarea:focus { border-color: #a1a1aa; box-shadow: 0 0 0 3px rgba(161, 161, 170, .18); }
.textarea { resize: vertical; min-height: 88px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--border); background: #fff; color: var(--text);
  border-radius: 6px; padding: 7px 12px; min-height: 34px; font-size: 13px;
  transition: background .15s, border-color .15s, color .15s;
}
.btn:hover { background: #fafafa; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-hover); }
.btn.danger { color: var(--danger); border-color: #fecaca; background: var(--danger-bg); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn.ghost:hover { background: #f4f4f5; color: var(--text); }
.btn.sm { min-height: 28px; padding: 4px 8px; font-size: 12px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.err { color: var(--danger); font-size: 13px; min-height: 18px; margin-top: 8px; }

/* 主布局 */
.layout { display: grid; grid-template-columns: var(--sidebar) 1fr; height: 100vh; overflow: hidden; }
.sidebar { background: #fff; border-right: 1px solid var(--border); display: flex; flex-direction: column; min-width: 0; }
.brand { height: 60px; display: flex; align-items: center; gap: 10px; padding: 0 16px; border-bottom: 1px solid var(--border); }
.brand-mark { width: 30px; height: 30px; border-radius: 8px; background: var(--primary); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 13px; }
.brand-name { font-weight: 600; font-size: 14px; }
.brand-sub { font-size: 11px; color: var(--muted); }
.sidebar-scroll { flex: 1; overflow-y: auto; padding: 12px 10px; }
.sidebar-title { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; padding: 6px 8px; display: flex; align-items: center; justify-content: space-between; }
.project-item {
  width: 100%; text-align: left; border: 0; background: transparent; border-radius: 8px;
  padding: 8px 10px; margin-bottom: 2px; display: block;
}
.project-item:hover { background: #fafafa; }
.project-item.active { background: #f4f4f5; }
.project-item .name { font-size: 13px; font-weight: 500; display: flex; align-items: center; gap: 6px; }
.project-item .code { font-size: 11px; color: var(--muted); margin-top: 2px; }
.sidebar-footer { border-top: 1px solid var(--border); padding: 12px 14px; display: flex; align-items: center; gap: 10px; }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: #e4e4e7; color: #3f3f46; display: grid; place-items: center; font-size: 12px; font-weight: 600; flex: none; }
.avatar.sm { width: 22px; height: 22px; font-size: 10px; }
.user-meta { flex: 1; min-width: 0; }
.user-meta .u { font-size: 13px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-meta .r { font-size: 11px; color: var(--muted); }
.main { display: flex; flex-direction: column; min-width: 0; overflow: hidden; }
.topbar { height: 60px; background: rgba(255, 255, 255, .86); backdrop-filter: blur(8px); border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; padding: 0 24px; gap: 16px; }
.project-head { display: flex; align-items: center; gap: 10px; min-width: 0; }
.project-head h1 { font-size: 18px; margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chip { display: inline-flex; align-items: center; gap: 4px; border: 1px solid var(--border); border-radius: 999px; padding: 1px 8px; font-size: 11px; color: var(--muted); background: #fff; }
.chip.inbox { color: var(--warning); border-color: #fde68a; background: var(--warning-bg); }
.avatars { display: flex; align-items: center; }
.avatars .avatar { margin-left: -6px; border: 2px solid #fff; }
.avatars .avatar:first-child { margin-left: 0; }
.tabs { display: flex; gap: 4px; padding: 10px 24px 0; background: transparent; border-bottom: 1px solid var(--border); }
.tab { border: 0; background: transparent; padding: 8px 12px 10px; font-size: 13px; color: var(--muted); border-bottom: 2px solid transparent; }
.tab:hover { color: var(--text); }
.tab.active { color: var(--text); font-weight: 600; border-bottom-color: var(--primary); }
.content { flex: 1; overflow: hidden; padding: 20px 24px 24px; }
.content-inner { max-width: 1280px; margin: 0 auto; height: 100%; min-height: 0; }

/* 聊天 */
.chat-layout { height: 100%; display: flex; flex-direction: column; background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.messages { flex: 1; overflow-y: auto; padding: 20px 20px 8px; background: #fff; }
.msg { display: flex; gap: 10px; margin-bottom: 22px; max-width: 920px; }
.msg .body { min-width: 0; flex: 1; }
.msg .meta { font-size: 11px; color: var(--muted); margin-bottom: 5px; display: flex; gap: 8px; align-items: center; }
.msg .bubble { background: #f4f4f5; border-radius: 10px; padding: 12px 14px; white-space: normal; word-break: break-word; font-size: 13.5px; line-height: 1.75; }
.msg .bubble p { margin: 0 0 10px; }
.msg .bubble p:last-child { margin-bottom: 0; }
.msg .bubble h2, .msg .bubble h3, .msg .bubble h4, .msg .bubble h5 { margin: 18px 0 8px; line-height: 1.4; color: var(--text); }
.msg .bubble h2 { font-size: 17px; }
.msg .bubble h3 { font-size: 15.5px; }
.msg .bubble h4 { font-size: 14px; }
.msg .bubble ul, .msg .bubble ol { margin: 6px 0 12px; padding-left: 22px; }
.msg .bubble li { margin: 3px 0; }
.msg .bubble blockquote { margin: 8px 0 12px; padding: 7px 12px; border-left: 3px solid #bae6fd; background: #f0f9ff; color: #3f3f46; border-radius: 0 6px 6px 0; }
.msg .bubble hr { border: 0; border-top: 1px solid var(--border); margin: 16px 0; }
.msg .bubble code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; background: #e4e4e7; padding: 1px 4px; border-radius: 4px; }
.msg .bubble pre { background: #18181b; color: #fafafa; padding: 10px 12px; border-radius: 8px; overflow-x: auto; margin: 8px 0 12px; }
.msg .bubble pre code { background: transparent; color: inherit; padding: 0; font-size: 12px; line-height: 1.6; white-space: pre; }
.msg .bubble strong { font-weight: 650; }
.md-table-wrap { overflow-x: auto; margin: 8px 0 14px; border: 1px solid var(--border); border-radius: 8px; }
.md-table { border-collapse: collapse; width: 100%; font-size: 12.5px; }
.md-table th { text-align: left; background: #f4f4f5; color: #52525b; font-weight: 600; padding: 7px 9px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.md-table td { padding: 7px 9px; border-bottom: 1px solid var(--border); vertical-align: top; }
.md-table tr:last-child td { border-bottom: 0; }
.msg-actions { display: flex; gap: 8px; margin-top: 5px; opacity: .55; transition: opacity .15s; }
.msg:hover .msg-actions { opacity: 1; }
.msg-actions button { border: 0; background: transparent; color: var(--muted); font-size: 11px; padding: 2px 4px; cursor: pointer; }
.msg-actions button:hover { color: var(--text); }
.bundle-box { margin-top: 8px; margin-bottom: 10px; border: 1px solid #bae6fd; background: #f8fcff; border-radius: 8px; padding: 8px 10px; }
.msg-top-action { margin: 0 0 9px; }
.bundle-title { font-size: 11px; color: var(--info); margin-bottom: 4px; }
.bundle-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 3px 0; }
.bundle-name { font-size: 12.5px; color: #3f3f46; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.quote-bar { display: flex; align-items: flex-start; gap: 10px; background: #fafafa; border-left: 3px solid #a1a1aa; border-radius: 0 6px 6px 0; padding: 7px 10px; margin-bottom: 9px; }
.quote-main { min-width: 0; flex: 1; }
.quote-source { font-size: 11px; color: var(--muted); margin-bottom: 2px; }
.quote-text { font-size: 12px; color: #52525b; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.quote-bar button { padding: 0 5px; font-size: 16px; line-height: 1; }
.msg.ai .bubble { background: var(--info-bg); border: 1px solid #e0f2fe; }
.msg.system { justify-content: center; max-width: none; }
.msg.system .bubble { background: #fafafa; color: var(--muted); font-size: 12px; border: 1px dashed var(--border); white-space: pre-wrap; }
.msg.system .meta { display: none; }
.msg.system .avatar { display: none; }
.composer { border-top: 1px solid var(--border); padding: 12px 16px 14px; background: #fff; }
.composer-row { display: flex; gap: 10px; align-items: flex-end; }
.composer textarea { flex: 1; border: 1px solid var(--border); border-radius: 8px; padding: 9px 11px; min-height: 44px; max-height: 160px; resize: none; outline: none; }
.composer textarea:focus { border-color: #a1a1aa; box-shadow: 0 0 0 3px rgba(161, 161, 170, .18); }
.composer-tools { display: flex; align-items: center; justify-content: space-between; margin-top: 8px; gap: 12px; }
.switch { display: inline-flex; align-items: center; gap: 7px; font-size: 12px; color: var(--muted); user-select: none; cursor: pointer; }
.switch input { width: 14px; height: 14px; accent-color: var(--primary); }
.hint { font-size: 11px; color: var(--muted); }

/* 出图 */
.outputs-layout { height: 100%; overflow-y: auto; padding-right: 2px; }
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-head { padding: 14px 16px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.card-title { font-size: 14px; font-weight: 600; }
.card-body { padding: 16px; }
.card-foot { padding: 10px 16px; border-top: 1px solid var(--border); color: var(--muted); font-size: 11px; }
.gen-panel { margin-bottom: 18px; }
.gen-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px; }
.gen-grid .span2 { grid-column: span 2; }
.gen-grid label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 5px; }
.gen-grid .input, .gen-grid .select { min-height: 34px; padding: 6px 9px; }
.gen-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 14px; }
.gen-status { font-size: 12px; color: var(--muted); }
.gen-status.busy { color: var(--info); }
.toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin: 0 0 14px; }
.toolbar .spacer { flex: 1; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; }
.out-card { background: var(--card); border: 1px solid var(--border); border-radius: 10px; overflow: hidden; box-shadow: var(--shadow); display: flex; flex-direction: column; }
.out-img { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; background: #f4f4f5; display: block; cursor: zoom-in; }
.out-body { padding: 10px 11px 8px; flex: 1; }
.out-prompt { font-size: 12.5px; line-height: 1.45; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; min-height: 36px; }
.out-meta { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.out-foot { border-top: 1px solid var(--border); padding: 8px 10px; display: flex; align-items: center; gap: 6px; }
.out-foot .spacer { flex: 1; }
.badge { display: inline-flex; align-items: center; border-radius: 999px; padding: 1px 7px; font-size: 10.5px; line-height: 1.6; border: 1px solid transparent; white-space: nowrap; }
.badge.gray { background: #f4f4f5; color: #52525b; }
.badge.green { background: var(--success-bg); color: var(--success); border-color: #a7f3d0; }
.badge.red { background: var(--danger-bg); color: var(--danger); border-color: #fecaca; }
.badge.blue { background: var(--info-bg); color: var(--info); border-color: #bae6fd; }
.badge.amber { background: var(--warning-bg); color: var(--warning); border-color: #fde68a; }

/* 节点工作台 */
.node-layout { height: 100%; display: flex; flex-direction: column; gap: 12px; }
.node-bar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.node-frame-wrap { flex: 1; min-height: 0; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; background: #fff; position: relative; }
.node-frame { width: 100%; height: 100%; border: 0; display: block; background: #fff; }
.node-note { font-size: 12px; color: var(--muted); }

/* 设置 */
.settings-grid { display: grid; grid-template-columns: 1.2fr .8fr; gap: 16px; }
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: 11.5px; color: var(--muted); font-weight: 500; padding: 8px 10px; border-bottom: 1px solid var(--border); }
.table td { padding: 9px 10px; border-bottom: 1px solid var(--border); font-size: 13px; }
.table tr:last-child td { border-bottom: 0; }
.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat { background: #fafafa; border: 1px solid var(--border); border-radius: 8px; padding: 12px; }
.stat .n { font-size: 20px; font-weight: 600; }
.stat .l { font-size: 11px; color: var(--muted); }
.list-clean { list-style: none; padding: 0; margin: 0; }
.list-clean li { display: flex; justify-content: space-between; gap: 10px; padding: 6px 0; border-bottom: 1px dashed var(--border); font-size: 12.5px; }
.list-clean li:last-child { border-bottom: 0; }

/* 空态 */
.empty { display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 60px 20px; color: var(--muted); text-align: center; }
.empty .icon { width: 52px; height: 52px; border-radius: 14px; background: #f4f4f5; display: grid; place-items: center; font-size: 22px; margin-bottom: 12px; }
.empty h3 { margin: 0 0 6px; color: var(--text); font-size: 15px; }
.empty p { margin: 0 0 14px; font-size: 12.5px; max-width: 420px; }

/* 弹窗 */
.modal-mask { position: fixed; inset: 0; background: rgba(9, 9, 11, .45); display: flex; align-items: center; justify-content: center; padding: 20px; z-index: 50; }
.modal { background: #fff; border-radius: var(--radius); box-shadow: 0 20px 50px rgba(0, 0, 0, .18); width: 560px; max-width: 100%; max-height: 90vh; overflow: auto; }
.modal.wide { width: 860px; }
.modal-head { padding: 16px 18px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.modal-title { font-size: 15px; font-weight: 600; }
.modal-body { padding: 18px; }
.modal-foot { padding: 14px 18px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; }
.modal-close { border: 0; background: transparent; font-size: 20px; line-height: 1; color: var(--muted); padding: 4px; }
.preview-wrap { position: relative; min-height: 180px; display: flex; align-items: center; justify-content: center; background: #f4f4f5; border-radius: 8px; overflow: hidden; }
.preview-img { width: 100%; max-height: 60vh; object-fit: contain; background: #f4f4f5; border-radius: 8px; }
.preview-loading { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 12px; background: #f4f4f5; }
.preview-wrap.loaded .preview-loading { display: none; }
.kv { display: grid; grid-template-columns: 88px 1fr; gap: 6px 12px; font-size: 12.5px; margin-top: 14px; }
.kv .k { color: var(--muted); }
.kv .v { word-break: break-word; }
.params-pre { background: #fafafa; border: 1px solid var(--border); border-radius: 8px; padding: 10px; font-size: 11.5px; overflow: auto; max-height: 220px; white-space: pre-wrap; }

/* toast */
#toast { position: fixed; right: 20px; bottom: 20px; z-index: 100; display: flex; flex-direction: column; gap: 8px; }
.toast { background: #18181b; color: #fff; border-radius: 8px; padding: 9px 13px; font-size: 13px; box-shadow: 0 8px 20px rgba(0, 0, 0, .18); animation: in .18s ease-out; }
.toast.err { background: #dc2626; }
@keyframes in { from { transform: translateY(6px); opacity: 0; } to { transform: none; opacity: 1; } }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .settings-grid { grid-template-columns: 1fr; }
  .gen-grid { grid-template-columns: 1fr; }
  .gen-grid .span2 { grid-column: span 1; }
  .content { padding: 14px; }
  .topbar { padding: 0 14px; }
  .tabs { padding: 8px 14px 0; }
}
