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

:root {
  /* 治愈柔和色调：暖米白背景 + 鼠尾草绿主色 + 棕褐文字 */
  --primary: #8ab17d;
  --primary-hover: #7a9c6d;
  --primary-light: #f4f7ec;
  --bg: #fdfbf5;
  --card: #ffffff;
  --text: #5d4a3b;
  --text-muted: #8c7a6b;
  --border: #e8dec4;
  --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.08), 0 2px 4px -1px rgba(0, 0, 0, 0.05);
  --radius: 12px;
}

html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  overflow: hidden;            /* 主页一屏，不滚动 */
}

/* ===== 一屏布局：header + 主体（左栏 / 画布） ===== */
.app { display: flex; flex-direction: column; height: 100vh; padding: 12px; gap: 10px; }

/* ===== 顶部：标题 + 导出下拉（参照站位置） ===== */
.top-bar { flex: none; display: flex; justify-content: space-between; align-items: center; height: 48px; padding: 0 4px; }
.top-title { font-size: 1.2rem; color: var(--primary); font-weight: 600; letter-spacing: -0.5px; }
.top-actions { display: flex; gap: 8px; align-items: center; }

.btn-header {
  display: inline-flex; align-items: center; gap: 7px;
  height: 38px; padding: 0 16px;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--card); color: var(--text);
  font-size: 0.9rem; font-weight: 600; cursor: pointer;
  transition: all 0.15s;
}
.btn-header:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-light); }

/* ===== 主体两列：左栏 380px 三页签 + 右侧画布 ===== */
.main { flex: 1; min-height: 0; display: grid; grid-template-columns: 380px 1fr; gap: 10px; }
.main.panel-hidden { grid-template-columns: 1fr; }

.left-panel {
  display: flex; flex-direction: column; min-height: 0;
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden;
}
.left-panel.hidden { display: none; }

/* ===== 页签栏 ===== */
.tabs { flex: none; display: flex; gap: 4px; padding: 8px; background: #f9f5ec; border-bottom: 1px solid var(--border); }
.tab {
  flex: 1; padding: 7px 0; border: none; border-radius: 9px;
  background: transparent; color: var(--text-muted);
  font-size: 0.9rem; font-weight: 600; cursor: pointer; transition: all 0.15s;
}
.tab:hover { background: #f1ead9; color: var(--text); }
.tab.active { background: var(--primary); color: #fff; box-shadow: 0 2px 6px rgba(138, 177, 125, 0.3); }

/* ===== 页签内容 ===== */
.tab-page { display: none; flex: 1; min-height: 0; flex-direction: column; }
.tab-page.active { display: flex; }

/* ---- AI 助手页签（参照站布局与风格） ---- */
.chat-head { flex: none; display: flex; justify-content: space-between; align-items: center; padding: 14px 16px 8px; }
.chat-title { font-size: 1.05rem; font-weight: 700; color: var(--text); line-height: 1.3; }
.chat-sub { font-size: 0.78rem; color: var(--text-muted); }
.chat-head-actions { display: flex; gap: 6px; }
.icon-btn {
  width: 34px; height: 34px; border-radius: 9px;
  border: 1px solid var(--border); background: var(--card);
  color: var(--text-muted); cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  transition: all 0.15s;
}
.icon-btn:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-light); }

.chat-body { flex: 1; min-height: 0; overflow-y: auto; padding: 4px 16px 8px; position: relative; }

.chat-empty { height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; }
.chat-empty-icon {
  width: 58px; height: 58px; border-radius: 15px;
  background: var(--card); border: 1px solid var(--border);
  box-shadow: var(--shadow);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.6rem;
}
.chat-empty-text { font-size: 0.9rem; color: var(--text-muted); }

/* 聊天气泡 */
.msg {
  max-width: 88%; padding: 9px 13px; border-radius: 12px;
  margin: 8px 0; font-size: 0.9rem; line-height: 1.55;
  white-space: pre-wrap; word-break: break-word;
  animation: msg-in 0.18s ease-out;
}
@keyframes msg-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.msg.user { background: var(--primary); color: #fff; margin-left: auto; border-bottom-right-radius: 4px; }
.msg.assistant { background: var(--card); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.msg.error { background: #f5e7dc; border: 1px solid #e8cdb8; color: #8c5a4a; border-bottom-left-radius: 4px; }

/* 底部输入盒（参照站样式） */
.chat-input-box {
  flex: none; margin: 0 12px 12px; padding: 10px 12px;
  background: #f7f6f1; border: 1px solid var(--border); border-radius: 16px;
  position: relative;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.chat-input-box:focus-within { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(138, 177, 125, 0.14); background: #fff; }
.chat-input-box textarea {
  width: 100%; min-height: 44px; max-height: 130px;
  border: none; background: transparent; resize: none; outline: none;
  font-family: inherit; font-size: 0.92rem; color: var(--text); line-height: 1.5;
}
.chat-input-box textarea::placeholder { color: #b0a798; }
.chat-input-row { display: flex; align-items: center; justify-content: space-between; margin-top: 6px; }

.model-select {
  padding: 5px 8px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--card); font-size: 0.78rem; color: var(--text-muted);
  outline: none; cursor: pointer; max-width: 160px;
}
.model-select:focus { border-color: var(--primary); }

/* 发送按钮：参照站样式（深色圆角方块 + 白色纸飞机） */
.send-btn {
  width: 40px; height: 40px; border: none; border-radius: 10px;
  background: #464f5e; color: #fff; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  transition: background 0.15s, transform 0.1s;
}
.send-btn:hover { background: #37404d; }
.send-btn:active { transform: scale(0.96); }

/* 生成中：禁用 + 转圈（防重复点击） */
.send-btn:disabled { cursor: not-allowed; opacity: 0.75; }
.send-btn:disabled:hover { background: #464f5e; }
.send-btn .send-spinner { display: none; }
.send-btn.loading .send-icon { display: none; }
.send-btn.loading .send-spinner {
  display: inline-block; width: 16px; height: 16px;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-top-color: #fff; border-radius: 50%;
  animation: send-spin 0.8s linear infinite;
}
@keyframes send-spin { to { transform: rotate(360deg); } }

/* ---- 源码 / JSON 页签 ---- */
#tab-source textarea, #tab-json textarea {
  flex: 1; min-height: 0; width: 100%;
  padding: 12px 14px; border: none; outline: none; resize: none;
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Consolas, monospace;
  font-size: 0.85rem; line-height: 1.6; color: var(--text);
  background: #fcfbf7;
}
#tab-source textarea:focus, #tab-json textarea:focus { box-shadow: inset 0 0 0 2px rgba(138, 177, 125, 0.35); background: #fff; }
#tab-source textarea::placeholder, #tab-json textarea::placeholder { color: #b5ac9c; }

.code-actions {
  flex: none; padding: 8px 12px; display: flex; gap: 6px; justify-content: flex-end;
  background: #f9f5ec; border-top: 1px solid var(--border);
}
.code-actions button {
  background: var(--card); color: var(--text);
  font-size: 0.84rem; padding: 6px 12px;
  border: 1px solid var(--border); border-radius: 8px; cursor: pointer;
  transition: all 0.15s; white-space: nowrap; flex: none;
}
.code-actions button:hover { background: var(--primary-light); border-color: var(--primary); color: var(--primary); }

/* ===== 右侧预览 ===== */
.preview-panel {
  position: relative; min-width: 0; min-height: 0;
  display: flex; flex-direction: column;
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden;
}

/* 画布工具栏：主题 chip + 方向 chip（参照站位置） */
.canvas-toolbar {
  flex: none; height: 50px; display: flex; align-items: center; gap: 8px;
  padding: 0 14px; background: #fdfcf9; border-bottom: 1px solid var(--border);
  position: relative; z-index: 30;
}
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  height: 32px; padding: 0 13px;
  border: 1px solid var(--border); border-radius: 16px;
  background: var(--card); color: var(--text);
  font-size: 0.85rem; cursor: pointer; white-space: nowrap;
  transition: all 0.15s;
}
.chip:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-light); }
.caret { font-size: 0.7em; color: var(--text-muted); }

/* ===== 下拉菜单 ===== */
.dropdown { position: relative; }
.dropdown-menu {
  position: absolute; top: calc(100% + 6px); left: 0;
  min-width: 175px; padding: 6px;
  background: var(--card); border: 1px solid var(--border);
  border-radius: 12px; box-shadow: 0 12px 28px rgba(0, 0, 0, 0.14);
  display: none; z-index: 100;
}
.dropdown.open .dropdown-menu { display: block; }
#exportDropdown .dropdown-menu { left: auto; right: 0; }
.dropdown-menu button {
  display: flex; align-items: center; gap: 9px;
  width: 100%; padding: 9px 12px;
  border: none; border-radius: 8px; background: none;
  color: var(--text); font-size: 0.88rem; text-align: left; cursor: pointer;
  transition: background 0.12s;
}
.dropdown-menu button:hover { background: var(--primary-light); }
.dropdown-menu button svg { color: var(--text-muted); flex: none; }
.dropdown-menu button:hover svg { color: var(--primary); }

/* 主题列表：当前项前缀圆点（参照站样式） */
.theme-btn::before, .dir-btn::before, .edge-btn::before {
  content: "●"; visibility: hidden; width: 10px; flex: none;
  font-size: 0.65em; color: var(--primary);
}
.theme-btn.active::before, .dir-btn.active::before, .edge-btn.active::before { visibility: visible; }
.theme-btn.active, .dir-btn.active, .edge-btn.active { color: var(--primary); font-weight: 600; }

/* ===== 画布区域 ===== */
.canvas-wrap { position: relative; flex: 1; min-height: 0; }
.canvas { position: absolute; inset: 0; overflow: auto; background: #f9f5ec; }
#mermaid-wrapper { width: 100%; max-width: 1200px; min-width: 400px; margin: 0 auto; padding: 12px 0; }
#mermaid-wrapper svg { height: auto; display: block; margin: 0 auto; transform-origin: 0 0; }

/* 空态（参照站样式） */
.canvas-empty {
  position: absolute; inset: 0; z-index: 5; pointer-events: none;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
}
.canvas-empty.hide { display: none; }
.canvas-empty-title { font-size: 0.95rem; font-weight: 600; color: #93a7bb; }
.canvas-empty-sub { font-size: 0.82rem; color: #a8b8c9; }

/* 加载遮罩 */
#loading {
  position: absolute; inset: 0; z-index: 15;
  display: none; align-items: center; justify-content: center;
  background: rgba(249, 245, 236, 0.78);
  color: var(--text-muted); font-size: 0.95rem;
}

/* 状态提示：header 导出按钮左侧，自动消失 */
#status {
  padding: 7px 14px; border-radius: 10px;
  background: #f4f7ec; color: var(--text);
  border: 1px solid var(--border); box-shadow: var(--shadow);
  font-size: 0.83rem; display: none;
  max-width: 560px; line-height: 1.5;
  transition: opacity 0.25s ease;
}
#status.show { display: block; }

/* 右下角操作提示（参照站位置） */
.canvas-hint {
  position: absolute; right: 14px; bottom: 12px; z-index: 10;
  font-size: 0.74rem; color: #a9a192; pointer-events: none; text-align: right;
}

/* ===== 附件（图片/文档）本地草稿 chips ===== */
.attach-list {
  display: flex; flex-wrap: wrap; gap: 6px;
  margin-bottom: 6px;
}
.attach-chip {
  display: inline-flex; align-items: center; gap: 6px;
  max-width: 100%; padding: 3px 6px;
  background: #fff; border: 1px solid var(--border); border-radius: 8px;
  font-size: 0.75rem; color: var(--text); animation: msg-in 0.18s ease-out;
}
.attach-thumb {
  width: 22px; height: 22px; border-radius: 5px;
  object-fit: cover; border: 1px solid var(--border);
}
.attach-ico { font-size: 0.85rem; line-height: 1; }
.attach-name {
  max-width: 150px; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap;
}
.attach-size { color: var(--text-muted); font-size: 0.7rem; }
.attach-del {
  width: 16px; height: 16px; padding: 0;
  border: none; border-radius: 50%;
  background: #efe9dc; color: var(--text-muted);
  font-size: 0.78rem; line-height: 1; cursor: pointer;
}
.attach-del:hover { background: #f5e7dc; color: #8c5a4a; }

/* ===== 通用弹窗（密码 / 自定义模型） ===== */
.modal-mask {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(60, 50, 40, 0.35);
  display: flex; align-items: center; justify-content: center;
  animation: msg-in 0.15s ease-out;
}
.modal {
  width: 320px; max-width: calc(100vw - 32px);
  padding: 18px 18px 14px;
  background: var(--card); border: 1px solid var(--border);
  border-radius: 14px; box-shadow: var(--shadow);
}
.modal-title { font-size: 0.98rem; font-weight: 700; color: var(--text); margin-bottom: 6px; }
.modal-msg { font-size: 0.84rem; color: var(--text-muted); line-height: 1.55; margin-bottom: 10px; }
.modal-input {
  width: 100%; padding: 8px 10px; margin-bottom: 8px;
  border: 1px solid var(--border); border-radius: 8px;
  background: #fff; outline: none;
  font-family: inherit; font-size: 0.9rem; color: var(--text);
  box-sizing: border-box;
}
.modal-input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(138, 177, 125, 0.14); }
.modal-err { font-size: 0.78rem; color: #8c5a4a; margin-bottom: 8px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }
.modal-btn {
  padding: 6px 16px; border: 1px solid var(--border); border-radius: 8px;
  background: #fff; color: var(--text-muted);
  font-size: 0.84rem; cursor: pointer; transition: all 0.15s;
}
.modal-btn:hover { border-color: var(--primary); color: var(--primary); }
.modal-btn.primary {
  background: var(--primary); border-color: var(--primary); color: #fff;
}
.modal-btn.primary:hover { background: var(--primary-hover); color: #fff; }

/* ===== 模型选择：紧凑下拉（每家仅默认项） + ☰ 展开全部模型 ===== */
.model-pick { display: inline-flex; align-items: center; gap: 4px; min-width: 0; }
.model-list-btn {
  height: 30px; padding: 0 9px; flex: none;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--card); color: var(--text-muted);
  font-size: 0.86rem; line-height: 1; cursor: pointer;
  transition: all 0.15s;
}
.model-list-btn:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-light); }

.model-panel {
  position: absolute; left: 12px; right: 12px; bottom: calc(100% + 8px);
  z-index: 40; padding: 8px;
  background: var(--card); border: 1px solid var(--border);
  border-radius: 12px; box-shadow: var(--shadow);
  animation: msg-in 0.15s ease-out;
}
.model-filter {
  width: 100%; box-sizing: border-box;
  padding: 6px 9px; margin-bottom: 4px;
  border: 1px solid var(--border); border-radius: 8px;
  background: #fff; outline: none;
  font-family: inherit; font-size: 0.82rem; color: var(--text);
}
.model-filter:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(138, 177, 125, 0.14); }
.model-panel-body { max-height: 250px; overflow-y: auto; }
.model-panel-head {
  position: sticky; top: 0; z-index: 1;
  padding: 7px 6px 3px;
  background: var(--card);
  font-size: 0.72rem; font-weight: 700; color: var(--text-muted);
}
.model-panel-item {
  display: block; width: 100%; text-align: left;
  padding: 5px 8px; border: none; border-radius: 7px;
  background: transparent; color: var(--text);
  font-size: 0.8rem; cursor: pointer;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.model-panel-item:hover { background: var(--primary-light); }
.model-panel-item.active { background: var(--primary); color: #fff; }
.model-panel-empty { padding: 10px 6px; font-size: 0.8rem; color: var(--text-muted); }
