:root {
  --primary: #4f6ef7;
  --primary-dark: #3b57d6;
  --bg: #f5f7fb;
  --card: #ffffff;
  --text: #1f2430;
  --muted: #7a8199;
  --border: #e6e9f2;
  --radius: 12px;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; }
body {
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  /* 页面初始化完成前不渲染，避免闪烁 */
  visibility: hidden;
}
body.ready { visibility: visible; }
a { color: var(--primary); text-decoration: none; }
button { cursor: pointer; font-family: inherit; }

/* 顶栏 */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 32px; background: var(--card);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.topbar .logo { font-size: 1.15rem; font-weight: 700; color: var(--text); }
.topbar .logo span { color: var(--primary); }
.topbar nav a { margin-left: 20px; color: var(--muted); }
.topbar nav a:hover { color: var(--primary); }

.container { max-width: 1080px; margin: 0 auto; padding: 32px 20px; }

/* 首页 Hero */
.hero { text-align: center; padding: 80px 20px 60px; }
.hero h1 { font-size: 2.6rem; line-height: 1.3; }
.hero h1 span { color: var(--primary); }
.hero p { color: var(--muted); margin: 18px auto 32px; max-width: 560px; font-size: 1.05rem; }
.features { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 18px; max-width: 960px; margin: 0 auto; }
.feature-card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 24px; text-align: left; }
.feature-card .fi { font-size: 1.8rem; }
.feature-card h3 { margin: 10px 0 6px; font-size: 1.05rem; }
.feature-card p { color: var(--muted); font-size: .9rem; }

/* 按钮 & 表单 */
.btn {
  display: inline-block; border: none; border-radius: 8px;
  padding: 10px 22px; font-size: .95rem;
  background: var(--primary); color: #fff; transition: background .15s;
}
.btn:hover { background: var(--primary-dark); }
.btn.ghost { background: transparent; color: var(--primary); border: 1px solid var(--primary); }
.btn.ghost:hover { background: rgba(79,110,247,.08); }
.btn.small { padding: 6px 14px; font-size: .85rem; }
.btn.danger { background: #e05252; }
.btn:disabled { opacity: .6; cursor: not-allowed; }
input, textarea, select {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border);
  border-radius: 8px; font-size: .95rem; font-family: inherit; background: #fff;
}
input:focus, textarea:focus, select:focus { outline: 2px solid rgba(79,110,247,.35); border-color: var(--primary); }
.field { margin-bottom: 16px; }
.field label { display: block; margin-bottom: 6px; font-size: .88rem; color: var(--muted); }

/* 弹窗 */
.modal-mask {
  position: fixed; inset: 0; background: rgba(20,24,40,.45);
  display: none; align-items: center; justify-content: center; z-index: 100;
}
.modal-mask.show { display: flex; }
.modal { background: #fff; border-radius: var(--radius); padding: 28px; width: 380px; max-width: 92vw; }
.modal h2 { margin-bottom: 18px; font-size: 1.2rem; }
.modal .err { color: #e05252; font-size: .85rem; min-height: 1.2em; margin-bottom: 8px; }
.modal .switch { margin-top: 12px; text-align: center; font-size: .88rem; color: var(--muted); }

/* 卡片与公司列表 */
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 22px; }
.section-title { display: flex; justify-content: space-between; align-items: center; margin-bottom: 18px; }
.section-title h2 { font-size: 1.25rem; }
.company-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }
.company-card { display: block; color: inherit; }
.company-card:hover { border-color: var(--primary); }
.company-card h3 { margin-bottom: 6px; }
.company-card .meta { color: var(--muted); font-size: .85rem; }
.company-card .desc { margin-top: 10px; color: var(--muted); font-size: .88rem; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.empty { text-align: center; color: var(--muted); padding: 60px 0; }

/* 工作台布局 */
.workspace { display: grid; grid-template-columns: 200px 1fr; gap: 0; height: calc(100vh - 57px); }
.ws-side { background: var(--card); border-right: 1px solid var(--border); padding: 16px 10px; overflow-y: auto; }
.ws-side .co-name { font-weight: 700; padding: 4px 10px 14px; font-size: .95rem; word-break: break-all; }
.ws-nav-item {
  display: flex; align-items: center; gap: 8px; width: 100%;
  padding: 9px 10px; border: none; background: none; border-radius: 8px;
  font-size: .9rem; color: var(--text); text-align: left;
}
.ws-nav-item:hover { background: var(--bg); }
.ws-nav-item.active { background: rgba(79,110,247,.1); color: var(--primary); font-weight: 600; }
.ws-nav-group { margin: 14px 4px 6px; font-size: .75rem; color: var(--muted); }
.ws-main { display: flex; flex-direction: column; overflow: hidden; }

/* 聊天 */
.chat-head { padding: 14px 22px; border-bottom: 1px solid var(--border); background: var(--card); }
.chat-head h3 { font-size: 1rem; }
.chat-head p { font-size: .8rem; color: var(--muted); }
.chat-body { flex: 1; overflow-y: auto; padding: 22px; }
.msg { display: flex; margin-bottom: 18px; }
.msg .bubble { max-width: 78%; padding: 12px 16px; border-radius: 14px; line-height: 1.7; white-space: pre-wrap; word-break: break-word; font-size: .92rem; }
.msg.user { justify-content: flex-end; }
.msg.user .bubble { background: var(--primary); color: #fff; border-bottom-right-radius: 4px; }
.msg.assistant .bubble { background: var(--card); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.chat-input { display: flex; gap: 10px; padding: 14px 22px; background: var(--card); border-top: 1px solid var(--border); }
.chat-input textarea { resize: none; height: 46px; }
.chat-input .btn { flex-shrink: 0; }

/* 标签页内容 */
.tab-panel { flex: 1; overflow-y: auto; padding: 24px; }
.doc-item { border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; margin-bottom: 12px; background: var(--card); }
.doc-item .doc-head { display: flex; justify-content: space-between; align-items: center; }
.doc-item .doc-time { color: var(--muted); font-size: .8rem; }
.doc-item .doc-content { display: none; margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border); white-space: pre-wrap; line-height: 1.7; font-size: .9rem; }
.doc-item.open .doc-content { display: block; }
/* 组织架构图 */
.org-scroll { overflow-x: auto; padding: 6px 0 4px; }
.org-chart { display: flex; flex-direction: column; align-items: center; }
.org-root { display: flex; justify-content: center; }
.org-card {
  display: block; width: 104px; padding: 11px 8px; text-align: center;
  background: var(--card); border: 1px solid var(--border); border-radius: 10px;
  color: var(--text); font-family: inherit; font-size: 1rem;
  transition: border-color .15s, box-shadow .15s, transform .15s;
}
button.org-card { cursor: pointer; }
button.org-card:hover { border-color: var(--primary); box-shadow: 0 4px 14px rgba(79,110,247,.16); transform: translateY(-2px); }
.org-card.ceo { width: 168px; background: linear-gradient(135deg, #eef1ff, #fff); border-color: #cdd6ff; }
.org-card .org-icon { font-size: 1.25rem; line-height: 1.4; }
.org-card .org-name { font-weight: 600; font-size: .85rem; margin-top: 2px; white-space: nowrap; }
.org-card .org-desc { color: var(--muted); font-size: .72rem; line-height: 1.45; margin-top: 3px; }
.org-trunk { width: 2px; height: 24px; background: #d6dbe9; }
.org-row { --gap: 10px; display: flex; justify-content: center; gap: var(--gap); padding-top: 26px; }
.org-branch { position: relative; }
.org-branch::before {
  content: ''; position: absolute; top: -26px; left: 50%;
  width: 2px; height: 26px; background: #d6dbe9; transform: translateX(-1px);
}
.org-branch::after {
  content: ''; position: absolute; top: -26px; height: 2px; background: #d6dbe9;
  left: calc(-1 * var(--gap) / 2 - 1px); right: calc(-1 * var(--gap) / 2 - 1px);
}
.org-branch:first-child::after { left: 50%; }
.org-branch:last-child::after { right: 50%; }
.org-branch:only-child::after { display: none; }
.org-tools { margin-top: 28px; padding-top: 18px; border-top: 1px dashed var(--border); }
.org-tools-title { font-size: .8rem; color: var(--muted); margin-bottom: 12px; }
.org-tools-row { display: flex; gap: 14px; flex-wrap: wrap; }
.org-card.tool { width: 168px; background: #fafbff; }
/* 窄屏：模块换行排列，隐藏树形连线，避免横向滚动 */
@media (max-width: 720px) {
  .org-scroll { overflow-x: visible; }
  .org-chart { min-width: 0 !important; }
  .org-trunk { display: none; }
  .org-row { flex-wrap: wrap; padding-top: 16px; margin-top: 14px; }
  .org-branch::before, .org-branch::after { display: none; }
}

.toast {
  position: fixed; top: 70px; left: 50%; transform: translateX(-50%);
  background: #23283b; color: #fff; padding: 10px 20px; border-radius: 8px;
  font-size: .88rem; z-index: 200; display: none;
}
.toast.show { display: block; }
