/* ============ 优创鲁班智能体 · Gemini 浅色风格 ============ */
:root {
  --primary: #0b5bd3;
  --primary-hover: #094fb0;
  --primary-soft: #e8f1ff;
  --text: #1c2333;
  --text-2: #5b6577;
  --text-3: #8a93a6;
  --line: #e4eaf3;
  --card: #ffffff;
  --danger: #d64545;
  --radius: 14px;
  --shadow: 0 6px 24px rgba(23, 43, 77, .08);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
          "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  --mono: "Cascadia Code", Consolas, "JetBrains Mono", "Courier New", monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }

body {
  font-family: var(--font);
  color: var(--text);
  font-size: 15px;
  line-height: 1.65;
  background:
    radial-gradient(1100px 520px at 78% -8%, #c9dcff 0%, rgba(201, 220, 255, 0) 62%),
    radial-gradient(880px 480px at 6% 108%, #d6efff 0%, rgba(214, 239, 255, 0) 58%),
    linear-gradient(180deg, #f4f8ff 0%, #fbfdff 55%, #ffffff 100%);
  background-attachment: fixed;
  overflow: hidden;
}

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

/* ---------- 按钮 ---------- */
.btn-primary {
  border: none; cursor: pointer; border-radius: 10px;
  background: var(--primary); color: #fff; font-size: 14px;
  padding: 8px 16px; font-family: var(--font);
  transition: background .15s ease, transform .1s ease;
}
.btn-primary:hover { background: var(--primary-hover); }
.btn-primary:active { transform: scale(.98); }

.btn-ghost {
  border: 1px solid var(--line); cursor: pointer; border-radius: 10px;
  background: #fff; color: var(--text-2); font-size: 14px;
  padding: 8px 14px; font-family: var(--font);
  display: inline-flex; align-items: center; gap: 6px;
  transition: all .15s ease;
}
.btn-ghost:hover { border-color: #b9cbe8; color: var(--primary); background: var(--primary-soft); }

.icon-btn {
  border: none; background: transparent; cursor: pointer; color: var(--text-2);
  width: 34px; height: 34px; border-radius: 8px;
  display: inline-flex; align-items: center; justify-content: center;
}
.icon-btn:hover { background: #eef3fb; color: var(--text); }

.icon-text-btn {
  border: none; background: transparent; cursor: pointer;
  color: var(--text-2); font-size: 13.5px; padding: 6px 10px; border-radius: 8px;
  font-family: var(--font);
}
.icon-text-btn:hover { background: #eef3fb; color: var(--primary); }

/* ---------- 侧边栏 ---------- */
#sidebar {
  width: 264px; flex-shrink: 0; height: 100vh;
  display: flex; flex-direction: column;
  background: rgba(255, 255, 255, .68);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-right: 1px solid var(--line);
  padding: 18px 14px 12px;
}

.brand { display: flex; align-items: center; gap: 10px; padding: 2px 6px 14px; }
.brand-logo { width: 34px; height: 34px; object-fit: contain; }
.brand-name { font-size: 16px; font-weight: 700; letter-spacing: .5px; }
.brand-sub { font-size: 11px; color: var(--text-3); margin-top: -2px; }

.btn-newchat { width: 100%; padding: 10px; font-size: 14.5px; display: flex; align-items: center; justify-content: center; gap: 4px; }
.btn-newchat .plus { font-weight: 700; font-size: 16px; }

.side-label {
  font-size: 12px; color: var(--text-3); padding: 16px 8px 8px;
  user-select: none;
}

.app-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }

.app-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px; border-radius: 10px; cursor: pointer;
  border: 1px solid transparent;
  transition: background .12s ease;
  min-width: 0;
}
.app-item:hover { background: rgba(232, 241, 255, .7); }
.app-item.active { background: var(--primary-soft); border-color: #cfe2ff; }
.app-item .app-avatar {
  width: 30px; height: 30px; border-radius: 8px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 14px; font-weight: 600;
}
.app-item .app-meta { min-width: 0; flex: 1; }
.app-item .app-name {
  font-size: 14px; font-weight: 500; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
}
.app-item.active .app-name { color: var(--primary); font-weight: 600; }
.app-item .app-desc {
  font-size: 11.5px; color: var(--text-3);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.history-list {
  max-height: 220px; overflow-y: auto;
  display: flex; flex-direction: column; gap: 2px;
  padding-bottom: 6px; border-bottom: 1px dashed var(--line);
}
.history-item {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 10px; border-radius: 8px; cursor: pointer;
  font-size: 13px; color: var(--text-2);
}
.history-item:hover { background: rgba(232, 241, 255, .7); }
.history-item.active { background: var(--primary-soft); color: var(--primary); }
.history-item .h-title { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.history-item .h-del {
  border: none; background: transparent; cursor: pointer; color: var(--text-3);
  display: none; padding: 2px; border-radius: 4px; line-height: 0;
}
.history-item:hover .h-del { display: inline-flex; }
.history-item .h-del:hover { color: var(--danger); background: #fdecec; }
.history-empty { font-size: 12px; color: var(--text-3); padding: 4px 10px; }

.side-foot { padding-top: 10px; }
.side-copy { text-align: center; font-size: 11px; color: var(--text-3); margin-top: 10px; }

.side-mask { display: none; }

/* ---------- 主区域 ---------- */
#main { flex: 1; display: flex; flex-direction: column; min-width: 0; height: 100vh; }

#topbar {
  height: 56px; flex-shrink: 0;
  display: flex; align-items: center; gap: 10px;
  padding: 0 18px;
  border-bottom: 1px solid rgba(228, 234, 243, .7);
  background: rgba(255, 255, 255, .55);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}
#menuToggle { display: none; }
.top-title { flex: 1; min-width: 0; display: flex; align-items: baseline; gap: 10px; }
#topAppName { font-size: 15.5px; font-weight: 600; }
.top-desc { font-size: 12.5px; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-actions { display: flex; gap: 2px; }

#chatScroll { flex: 1; overflow-y: auto; scroll-behavior: smooth; }
#messages { max-width: 820px; margin: 0 auto; padding: 26px 22px 12px; }

/* ---------- 欢迎页 ---------- */
#welcome {
  max-width: 720px; margin: 0 auto; padding: 9vh 24px 24px;
  text-align: center;
}
.welcome-logo { width: 62px; height: 62px; margin-bottom: 14px; object-fit: contain; }
.welcome-title {
  font-size: 27px; font-weight: 700; letter-spacing: .5px;
  background: linear-gradient(90deg, #1c2333 30%, #0b5bd3);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.welcome-sub { color: var(--text-2); margin: 8px 0 26px; font-size: 15px; }

.welcome-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; text-align: left; }
.wcard {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; cursor: pointer; box-shadow: var(--shadow);
  transition: transform .15s ease, border-color .15s ease;
}
.wcard:hover { transform: translateY(-2px); border-color: #b9cbe8; }
.wcard .wcard-avatar {
  width: 30px; height: 30px; border-radius: 8px; color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 600; margin-bottom: 8px;
}
.wcard .wcard-name { font-size: 14.5px; font-weight: 600; }
.wcard .wcard-desc { font-size: 12.5px; color: var(--text-3); margin-top: 2px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

/* ---------- 消息 ---------- */
.msg { display: flex; gap: 12px; margin-bottom: 26px; animation: fadeUp .25s ease; }
@keyframes fadeUp { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.msg.user { justify-content: flex-end; }
.msg.user .bubble {
  max-width: 78%; background: var(--primary); color: #fff;
  border-radius: 16px 16px 4px 16px; padding: 10px 15px;
  white-space: pre-wrap; word-break: break-word; font-size: 14.5px;
  box-shadow: 0 4px 14px rgba(11, 91, 211, .22);
}

.msg.ai { }
.msg-avatar {
  width: 30px; height: 30px; border-radius: 9px; flex-shrink: 0;
  background: #fff; border: 1px solid var(--line);
  display: flex; align-items: center; justify-content: center;
  box-shadow: var(--shadow); margin-top: 2px;
}
.msg-avatar img { width: 20px; height: 20px; }
.msg-body { flex: 1; min-width: 0; }
.msg-sender { font-size: 12px; color: var(--text-3); margin-bottom: 3px; }
.msg-content {
  background: var(--card); border: 1px solid var(--line);
  border-radius: 4px 16px 16px 16px; padding: 12px 16px;
  box-shadow: var(--shadow); font-size: 14.5px;
  min-width: 0; overflow-wrap: break-word;
}
.msg-content.error { border-color: #f3c6c6; background: #fff7f7; }
.md-img {
  display: inline-block; vertical-align: middle;
  max-width: min(100%, 420px); max-height: 320px;
  border-radius: 10px; border: 1px solid var(--line);
  margin: 4px 2px; cursor: zoom-in; background: #fff;
}
.msg-content p > .md-img:only-child { display: block; margin: 6px 0; }
.img-lightbox { position: fixed; inset: 0; z-index: 1000; display: flex; align-items: center; justify-content: center; }
.img-lightbox-mask { position: absolute; inset: 0; background: rgba(10, 15, 30, .74); }
.img-lightbox-box { position: relative; margin: 0; max-width: min(92vw, 1100px); }
.img-lightbox-box img {
  display: block; max-width: 100%; max-height: 84vh;
  border-radius: 12px; background: #fff; box-shadow: 0 24px 70px rgba(0, 0, 0, .45);
}
.img-lightbox-box figcaption { text-align: center; color: #dfe6f2; font-size: 13px; margin-top: 10px; }
.img-lightbox-close {
  position: absolute; top: 16px; right: 20px; z-index: 1;
  width: 38px; height: 38px; border: none; border-radius: 50%;
  background: rgba(255, 255, 255, .14); color: #fff; font-size: 22px; line-height: 1;
  cursor: pointer; transition: background .15s ease;
}
.img-lightbox-close:hover { background: rgba(255, 255, 255, .28); }

.msg-actions { display: flex; gap: 4px; margin-top: 5px; opacity: 0; transition: opacity .15s ease; align-items: center; }
.msg:hover .msg-actions { opacity: 1; }
.act-btn {
  border: none; background: transparent; cursor: pointer;
  font-size: 12px; color: var(--text-3); padding: 3px 8px; border-radius: 6px;
  display: inline-flex; align-items: center; gap: 4px; font-family: var(--font);
}
.act-btn:hover { background: #eef3fb; color: var(--primary); }
.act-btn:disabled { opacity: .35; cursor: default; }
.act-btn:disabled:hover { background: transparent; color: var(--text-3); }
.msg-meta { font-size: 11.5px; color: var(--text-3); margin-top: 3px; min-height: 15px; }
.msg-meta.direct { color: #0e9f6e; }

/* ---------- 评价（点赞 / 点踩 / 文字回复） ---------- */
.fb-sep { width: 1px; height: 12px; background: var(--line); margin: 0 4px; flex-shrink: 0; }
.act-btn.act-fb-up.on { color: var(--primary); background: var(--primary-soft); }
.act-btn.act-fb-down.on { color: var(--danger); background: #fdecec; }
.act-fb-comment.has { color: var(--primary); background: var(--primary-soft); }

.fb-comment {
  margin-top: 8px; background: #fcfdff; border: 1px solid var(--line);
  border-radius: 12px; padding: 10px 12px; animation: fadeUp .2s ease;
}
.fb-comment textarea {
  width: 100%; border: 1px solid var(--line); border-radius: 9px;
  padding: 8px 10px; font-family: var(--font); font-size: 13.5px; line-height: 1.55;
  resize: vertical; min-height: 56px; outline: none; color: var(--text); background: #fff;
}
.fb-comment textarea:focus { border-color: #a9c6f5; }
.fb-comment-actions { display: flex; gap: 8px; margin-top: 8px; }
.fb-comment-actions .btn-primary { padding: 5px 14px; font-size: 13px; border-radius: 8px; }
.fb-comment-actions .btn-ghost { padding: 5px 12px; font-size: 13px; border-radius: 8px; }
.fb-comment-view {
  margin-top: 6px; font-size: 13px; color: var(--text-2);
  background: #f4f8ff; border: 1px solid #e0e9f8; border-radius: 9px;
  padding: 7px 11px; white-space: pre-wrap; word-break: break-word;
}

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

.caret {
  display: inline-block; width: 8px; height: 1.05em; margin-left: 2px;
  background: var(--primary); vertical-align: text-bottom;
  animation: caretBlink .8s step-end infinite; border-radius: 1px;
}
@keyframes caretBlink { 50% { opacity: 0; } }

/* ---------- Markdown ---------- */
.md > *:first-child { margin-top: 0; }
.md > *:last-child { margin-bottom: 0; }
.md p { margin: 0 0 10px; }
.md h1, .md h2, .md h3, .md h4 { margin: 16px 0 8px; line-height: 1.4; }
.md h1 { font-size: 19px; } .md h2 { font-size: 17px; }
.md h3 { font-size: 15.5px; } .md h4 { font-size: 14.5px; }
.md ul, .md ol { margin: 0 0 10px; padding-left: 22px; }
.md li { margin: 2px 0; }
.md blockquote {
  border-left: 3px solid #b9cbe8; background: #f4f8ff;
  margin: 0 0 10px; padding: 8px 14px; border-radius: 0 8px 8px 0; color: var(--text-2);
}
.md hr { border: none; border-top: 1px solid var(--line); margin: 14px 0; }
.md a { color: var(--primary); text-decoration: none; }
.md a:hover { text-decoration: underline; }
.md code {
  font-family: var(--mono); font-size: .88em;
  background: #eef2f9; border: 1px solid #e2e8f3; border-radius: 5px;
  padding: 1px 5px; color: #b03a5b;
}
.md table { border-collapse: collapse; margin: 0 0 12px; width: 100%; font-size: 13.5px; }
.md th, .md td { border: 1px solid var(--line); padding: 6px 10px; text-align: left; }
.md th { background: #f4f8ff; font-weight: 600; }
.md tr:nth-child(even) td { background: #fafcfe; }

.codeblock { margin: 0 0 12px; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: #fbfcfe; }
.code-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 5px 12px; background: #f2f6fc; border-bottom: 1px solid var(--line);
  font-size: 12px; color: var(--text-3);
}
.code-copy {
  border: none; background: transparent; cursor: pointer; color: var(--text-3);
  font-size: 12px; padding: 2px 8px; border-radius: 5px; font-family: var(--font);
}
.code-copy:hover { background: #e3ecf9; color: var(--primary); }
.codeblock pre { margin: 0; padding: 12px 14px; overflow-x: auto; }
.codeblock code {
  background: none; border: none; padding: 0; color: #2b3a55;
  font-size: 13px; line-height: 1.6; white-space: pre;
}

/* ---------- 输入区 ---------- */
#composer {
  flex-shrink: 0; padding: 10px 22px 14px;
  background: linear-gradient(180deg, rgba(255,255,255,0), rgba(255,255,255,.75) 40%);
}
.input-row {
  max-width: 820px; margin: 0 auto;
  display: flex; align-items: flex-end; gap: 8px;
  background: #fff; border: 1px solid var(--line); border-radius: 16px;
  padding: 8px 8px 8px 16px; box-shadow: var(--shadow);
  transition: border-color .15s ease;
}
.input-row:focus-within { border-color: #a9c6f5; }
#input {
  flex: 1; border: none; outline: none; resize: none;
  font-family: var(--font); font-size: 14.5px; line-height: 1.55;
  max-height: 180px; padding: 6px 0; background: transparent; color: var(--text);
}
.send-btn, .stop-btn {
  border: none; cursor: pointer; border-radius: 11px;
  width: 38px; height: 38px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  transition: all .15s ease;
}
.send-btn { background: var(--primary); color: #fff; }
.send-btn:hover { background: var(--primary-hover); }
.send-btn:disabled { background: #c8d5ea; cursor: not-allowed; }
.stop-btn { background: #fdecec; color: var(--danger); }
.stop-btn:hover { background: #f9d5d5; }

.suggestions {
  max-width: 820px; margin: 0 auto 8px;
  display: flex; flex-wrap: wrap; gap: 8px;
}
.chip {
  border: 1px solid #cfe0f8; background: #fff; color: var(--primary);
  font-size: 13px; border-radius: 999px; padding: 5px 13px; cursor: pointer;
  font-family: var(--font); transition: all .13s ease;
}
.chip:hover { background: var(--primary-soft); border-color: #a9c6f5; }

/* ---------- 弹窗 ---------- */
.modal-mask {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(20, 32, 55, .38); backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center; padding: 20px;
  animation: fadeIn .15s ease;
}
@keyframes fadeIn { from { opacity: 0; } }
.modal {
  width: 720px; max-width: 100%; max-height: 88vh;
  background: #fff; border-radius: 18px; box-shadow: 0 24px 70px rgba(10, 25, 60, .25);
  display: flex; flex-direction: column; overflow: hidden;
  animation: popIn .18s ease;
}
@keyframes popIn { from { opacity: 0; transform: scale(.97) translateY(8px); } }
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 22px; border-bottom: 1px solid var(--line);
}
.modal-title { font-size: 16.5px; font-weight: 700; }
.modal-body { padding: 18px 22px 26px; overflow-y: auto; }

.panel {
  border: 1px solid var(--line); border-radius: 14px;
  padding: 16px; margin-bottom: 16px; background: #fcfdff;
}
.panel-title { font-size: 14.5px; font-weight: 600; margin-bottom: 12px; }
.panel-toggle {
  width: 100%; display: flex; align-items: center; justify-content: space-between;
  border: none; background: transparent; cursor: pointer; font-family: var(--font);
  color: var(--text); margin-bottom: 0;
}
.panel-toggle .chevron { transition: transform .15s ease; color: var(--text-3); }
.panel-toggle[aria-expanded="true"] .chevron { transform: rotate(180deg); }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 14px; }
.field-full { grid-column: 1 / -1; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field-label { font-size: 13px; color: var(--text-2); }
.field-label i { color: var(--danger); font-style: normal; }
.field input, .field select {
  border: 1px solid var(--line); border-radius: 9px; padding: 8px 11px;
  font-size: 14px; font-family: var(--font); outline: none; background: #fff;
  transition: border-color .13s ease; color: var(--text);
}
.field input:focus, .field select:focus { border-color: #a9c6f5; }

.form-actions { display: flex; align-items: center; gap: 10px; margin-top: 14px; }
.flex-spacer { flex: 1; }
.test-result { font-size: 12.5px; color: var(--text-2); }
.test-result.ok { color: #0e9f6e; }
.test-result.bad { color: var(--danger); }

.tip { font-size: 12.5px; color: var(--text-3); margin-bottom: 12px; }

.app-table { display: flex; flex-direction: column; gap: 6px; }
.app-row {
  display: flex; align-items: center; gap: 10px;
  border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; background: #fff;
}
.app-row .app-avatar { width: 28px; height: 28px; border-radius: 7px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; color: #fff; font-size: 13px; font-weight: 600; }
.app-row .ar-name { font-size: 14px; font-weight: 500; }
.app-row .ar-key { font-size: 11.5px; color: var(--text-3); font-family: var(--mono); }
.app-row .ar-mode { font-size: 11px; color: var(--text-3); background: #eef2f9; border-radius: 5px; padding: 1px 7px; }
.app-row .ar-actions { margin-left: auto; display: flex; gap: 4px; }
.app-row .ar-btn {
  border: none; background: transparent; cursor: pointer; font-size: 12.5px;
  color: var(--text-2); padding: 4px 9px; border-radius: 6px; font-family: var(--font);
}
.app-row .ar-btn:hover { background: #eef3fb; color: var(--primary); }
.app-row .ar-btn.danger:hover { background: #fdecec; color: var(--danger); }
.app-empty { font-size: 13px; color: var(--text-3); text-align: center; padding: 18px 0; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; top: 26px; transform: translateX(-50%);
  background: #1c2333; color: #fff; font-size: 13.5px;
  border-radius: 10px; padding: 9px 18px; z-index: 99;
  box-shadow: 0 10px 30px rgba(10, 25, 60, .3);
  animation: toastIn .2s ease; max-width: 80vw;
}
.toast.bad { background: #b23c3c; }
@keyframes toastIn { from { opacity: 0; transform: translateX(-50%) translateY(-8px); } }

/* ---------- 滚动条 ---------- */
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-thumb { background: #cfd9e8; border-radius: 5px; border: 2px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background: #b3c2d8; border: 2px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-track { background: transparent; }

/* ---------- 响应式 ---------- */
@media (max-width: 900px) {
  #sidebar {
    position: fixed; left: 0; top: 0; bottom: 0; z-index: 40;
    transform: translateX(-100%); transition: transform .22s ease;
    background: rgba(255, 255, 255, .92); box-shadow: 0 0 40px rgba(10, 25, 60, .18);
  }
  #sidebar.open { transform: none; }
  .side-mask.show {
    display: block; position: fixed; inset: 0; z-index: 39;
    background: rgba(20, 32, 55, .3);
  }
  #menuToggle { display: inline-flex; }
  #messages { padding: 18px 12px 8px; }
  .msg.user .bubble { max-width: 88%; }
  .welcome-cards { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
}
