/* 玄言 Web 原型样式 —— 豆包式 UI（浅色 + 蓝紫主色） */

:root {
  --primary: #4e6ef2;
  --primary-dark: #3b5bdb;
  --primary-light: #eef1fe;
  --bg: #f5f6f8;
  --card: #ffffff;
  --text: #1f2329;
  --text-2: #646a73;
  --text-3: #8f959e;
  --border: #e5e6eb;
  --danger: #e5484d;
  --success: #30a46c;
  --radius: 14px;
  --shadow: 0 2px 10px rgba(31, 35, 41, 0.06);
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; }
body {
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  overflow: hidden;
}

/* ===== 左侧栏 ===== */
.sidebar {
  width: 240px;
  min-width: 240px;
  background: var(--card);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 16px 12px;
  gap: 12px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 6px; }
.brand-logo {
  width: 40px; height: 40px; border-radius: 12px;
  background: linear-gradient(135deg, #4e6ef2, #7b5cf0);
  color: #fff; font-size: 20px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 12px rgba(78, 110, 242, 0.35);
}
.brand-name { font-size: 17px; font-weight: 700; }
.brand-sub { font-size: 12px; color: var(--text-3); }

.btn-new {
  border: none; border-radius: var(--radius);
  background: linear-gradient(135deg, #4e6ef2, #7b5cf0);
  color: #fff; font-size: 14px; font-weight: 600;
  padding: 11px 0; cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
}
.btn-new:hover { opacity: 0.9; }
.btn-new:active { transform: scale(0.98); }

.sidebar-section-title { font-size: 12px; color: var(--text-3); padding: 0 6px; }
.conv-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.conv-empty { font-size: 12px; color: var(--text-3); padding: 8px 6px; }
.conv-item {
  padding: 9px 10px; border-radius: 10px; cursor: pointer;
  font-size: 13px; color: var(--text-2);
  display: flex; align-items: center; gap: 8px;
  overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
  transition: background 0.12s;
}
.conv-item:hover { background: var(--bg); }
.conv-item.active { background: var(--primary-light); color: var(--primary-dark); font-weight: 600; }
.conv-item .conv-time { margin-left: auto; font-size: 11px; color: var(--text-3); flex-shrink: 0; }

.sidebar-footer { display: flex; flex-wrap: wrap; gap: 6px; border-top: 1px solid var(--border); padding-top: 12px; }
.tool-chip {
  font-size: 12px; color: var(--primary-dark);
  background: var(--primary-light); border-radius: 999px;
  padding: 5px 11px; cursor: pointer; user-select: none;
  transition: background 0.12s;
}
.tool-chip:hover { background: #dfe6fd; }

/* ===== 主区 ===== */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  height: 56px; display: flex; align-items: center; gap: 10px;
  padding: 0 20px; background: var(--card); border-bottom: 1px solid var(--border);
}
.topbar-title { flex: 1; font-size: 15px; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.conn-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-3); }
.conn-dot.ok { background: var(--success); box-shadow: 0 0 6px rgba(48, 164, 108, 0.5); }
.conn-dot.bad { background: var(--danger); }
.conn-text { font-size: 12px; color: var(--text-3); font-weight: 400; }
.icon-btn {
  border: none; background: none; cursor: pointer; font-size: 17px;
  width: 36px; height: 36px; border-radius: 10px; color: var(--text-2);
}
.icon-btn:hover { background: var(--bg); }
.menu-btn { display: none; }

/* ===== 登录 ===== */
.login-btn {
  border: 1px solid var(--border); background: var(--card); cursor: pointer;
  border-radius: 999px; padding: 5px 14px; font-size: 12.5px; color: var(--text-2);
}
.login-btn:hover { border-color: var(--primary); color: var(--primary); }
.login-btn.logged { background: var(--primary-light); border-color: transparent; color: var(--primary-dark); }

.login-mask {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(0, 0, 0, 0.4);
  display: flex; align-items: center; justify-content: center;
}
.login-modal {
  width: min(360px, 90vw); background: var(--card); border-radius: 16px;
  padding: 24px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 10px;
}
.login-head { font-size: 17px; font-weight: 700; text-align: center; margin-bottom: 6px; }
.login-input {
  border: 1px solid var(--border); border-radius: 10px; padding: 11px 14px;
  font-size: 14px; outline: none; width: 100%;
}
.login-input:focus { border-color: var(--primary); }
.login-row { display: flex; gap: 8px; }
.login-row .login-input { flex: 1; }
.login-sms {
  border: 1px solid var(--border); background: var(--card); border-radius: 10px;
  padding: 0 12px; font-size: 12px; color: var(--primary-dark); cursor: pointer; white-space: nowrap;
}
.login-sms:disabled { color: var(--text-3); cursor: not-allowed; }
.login-err { font-size: 12px; color: var(--danger); min-height: 16px; }
.login-submit {
  border: none; border-radius: 10px; background: linear-gradient(135deg, #4e6ef2, #7b5cf0);
  color: #fff; font-size: 14px; font-weight: 600; padding: 12px 0; cursor: pointer;
}
.login-guest {
  border: 1px solid var(--border); background: var(--card); border-radius: 10px;
  color: var(--text-2); font-size: 13px; padding: 10px 0; cursor: pointer;
}
.login-hint { font-size: 11px; color: var(--text-3); text-align: center; line-height: 1.6; }

/* ===== 消息流 ===== */
.messages {
  flex: 1; overflow-y: auto; padding: 24px 20px 12px;
  display: flex; flex-direction: column; gap: 18px;
  scroll-behavior: smooth;
}
/* 微信式时间分隔行：居中、小字、弱化；负 margin 抵消消息间距，视觉贴近气泡 */
.time-divider {
  text-align: center; font-size: 11px; color: var(--text-3);
  margin: -10px 0 -4px; line-height: 1; user-select: none;
}
.msg { display: flex; gap: 10px; max-width: 780px; width: 100%; margin: 0 auto; }
.msg.user { flex-direction: row-reverse; }
.avatar {
  width: 34px; height: 34px; border-radius: 10px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 15px; font-weight: 700; color: #fff;
}
.avatar.ai { background: linear-gradient(135deg, #4e6ef2, #7b5cf0); }
.avatar.user { background: #9aa1ad; }
.bubble {
  background: var(--card); border-radius: 4px 14px 14px 14px;
  padding: 12px 16px; box-shadow: var(--shadow);
  font-size: 14.5px; line-height: 1.75;
  min-width: 60px; max-width: 100%;
  overflow-wrap: break-word; white-space: pre-wrap;
}
.msg.user .bubble {
  background: linear-gradient(135deg, #4e6ef2, #5f6df0);
  color: #fff; border-radius: 14px 4px 14px 14px;
}
.bubble .disclaimer { font-size: 12px; color: var(--text-3); }
.typing::after {
  content: "▍"; animation: blink 0.9s infinite;
}
@keyframes blink { 50% { opacity: 0; } }

/* ===== 工具卡片 ===== */
/* AI 消息包装块：工具卡片 + 气泡 绑定上下堆叠（卡片不会被气泡顶走）
   对齐：wrap 最大宽 = 560px 整体居中（消息流内）；
   卡片 margin-left 44px（头像 34 + 间距 10）→ 与气泡内容区左边缘对齐、宽度一致 */
.msg-wrap {
  display: flex; flex-direction: column; gap: 8px;
  width: 100%; max-width: 560px; margin: 0 auto;
}
.msg-wrap .msg { max-width: none; }
.msg-wrap .tool-card { margin-left: 44px; }

.tool-card {
  background: var(--card); border-radius: var(--radius);
  box-shadow: var(--shadow); border: 1px solid var(--border);
  overflow: hidden; /* 在 msg-wrap 内由 gap 控制间距 */
}
.tool-card .tc-head {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 14px; font-size: 12.5px; color: var(--text-2);
  background: var(--primary-light); border-bottom: 1px solid var(--border);
}
.tool-card .tc-head .tc-status { margin-left: auto; font-size: 11.5px; }
.tool-card .tc-body { padding: 12px 14px; font-size: 13.5px; line-height: 1.7; }
.tool-card .tc-body.err { color: var(--danger); }

.pillars { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.pillar { text-align: center; background: var(--bg); border-radius: 10px; padding: 8px 4px; }
.pillar .p-label { font-size: 11px; color: var(--text-3); }
.pillar .p-ganzhi { font-size: 19px; font-weight: 700; letter-spacing: 1px; }
.pillar .p-sub { font-size: 11px; color: var(--text-2); margin-top: 2px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.chip {
  font-size: 12px; padding: 3px 10px; border-radius: 999px;
  background: var(--primary-light); color: var(--primary-dark);
}
.chip.yi { background: #e8f7ef; color: #237a52; }
.chip.ji { background: #fdecec; color: #b83a3e; }
.chip.wx { background: #f6f0fe; color: #6b46c1; }

.kv { display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; font-size: 13px; }
.kv dt { color: var(--text-3); }
.kv dd { color: var(--text); }

.json-view {
  font-family: "SF Mono", Consolas, monospace; font-size: 12px;
  background: var(--bg); border-radius: 8px; padding: 10px;
  max-height: 220px; overflow: auto; white-space: pre-wrap;
  color: var(--text-2);
}

/* ===== 起卦台断语：问占高亮 ===== */
.dy-q {
  display: inline-block;
  background: linear-gradient(135deg, #fff7e0, #ffe9b8);
  border: 1px solid #f0c36d;
  border-radius: 10px;
  padding: 6px 12px;
  margin-bottom: 8px;
  font-size: 13.5px;
  box-shadow: 0 1px 4px rgba(240, 195, 109, .35);
  color: #7a5200;
}
.dy-q .dy-text {
  color: #8a5a00; font-weight: 800; font-size: 14px;
  background: rgba(255,255,255,.6); border-radius: 6px; padding: 1px 8px; margin-left: 4px;
}
.dy-t { white-space: pre-wrap; }

/* ===== 卦象卡片（与起卦台一致）===== */
.tool-card .gua-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.tool-card .gua-card {
  background: var(--bg); border-radius: 10px; padding: 10px 12px;
}
.tool-card .gua-card .g-name { font-size: 18px; font-weight: 700; }
.tool-card .gua-card .g-sub { font-size: 11.5px; color: var(--text-3); margin-bottom: 6px; }
.tool-card .gua-table { width: 100%; border-collapse: collapse; font-size: 11.5px; }
.tool-card .gua-table th, .tool-card .gua-table td { padding: 4px 2px; border-bottom: 1px solid var(--border); text-align: center; }
.tool-card .gua-table th { color: var(--text-3); font-weight: 500; }
.tool-card .gua-table .tc-moving { color: var(--danger); font-weight: 700; }
.tool-card .moving-note { margin-top: 10px; font-size: 12.5px; color: var(--text-2); }

/* ===== 输入区 ===== */
.composer { padding: 8px 20px 16px; background: var(--bg); }
.composer-box {
  max-width: 780px; margin: 0 auto;
  display: flex; align-items: flex-end; gap: 10px;
  background: var(--card); border: 1px solid var(--border);
  border-radius: 22px; padding: 8px 8px 8px 18px;
  box-shadow: var(--shadow); transition: border-color 0.15s;
}
.composer-box:focus-within { border-color: var(--primary); }
.composer-box textarea {
  flex: 1; border: none; outline: none; resize: none;
  font-family: inherit; font-size: 14.5px; line-height: 1.6;
  max-height: 140px; background: transparent; color: var(--text);
}
.btn-send {
  width: 38px; height: 38px; border: none; border-radius: 50%;
  background: linear-gradient(135deg, #4e6ef2, #7b5cf0);
  color: #fff; font-size: 15px; cursor: pointer; flex-shrink: 0;
  transition: opacity 0.15s, transform 0.1s;
}
.btn-send:hover { opacity: 0.9; }
.btn-send:active { transform: scale(0.94); }
.btn-send:disabled { opacity: 0.45; cursor: not-allowed; }
.composer-hint { text-align: center; font-size: 11.5px; color: var(--text-3); margin-top: 8px; }

/* ===== 移动端 ===== */
.mobile-tab { display: none; }
.drawer { display: none; }
.sidebar-mask { display: none; }

@media (max-width: 860px) {
  .sidebar {
    position: fixed; left: 0; top: 0; bottom: 0; z-index: 40;
    transform: translateX(-100%); transition: transform 0.22s ease;
    box-shadow: 4px 0 20px rgba(0, 0, 0, 0.12);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-mask {
    display: block; position: fixed; inset: 0; z-index: 30;
    background: rgba(0, 0, 0, 0.35); opacity: 0; pointer-events: none;
    transition: opacity 0.22s;
  }
  .sidebar-mask.show { opacity: 1; pointer-events: auto; }
  .menu-btn { display: block; }
  .mobile-tab {
    display: flex; height: 54px; background: var(--card);
    border-top: 1px solid var(--border);
  }
  .mobile-tab .tab {
    flex: 1; border: none; background: none; font-size: 12px;
    color: var(--text-3); cursor: pointer; display: flex;
    flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  }
  .mobile-tab .tab.active { color: var(--primary); font-weight: 600; }
  .drawer {
    position: fixed; left: 0; right: 0; bottom: 54px; top: 56px; z-index: 20;
    background: var(--bg); padding: 20px; flex-direction: column; gap: 10px;
    overflow-y: auto;
  }
  .drawer.open { display: flex; }
  .drawer-head { font-size: 16px; font-weight: 700; margin-bottom: 6px; }
  .drawer-item {
    text-align: left; border: none; background: var(--card);
    border-radius: 12px; padding: 14px 16px; font-size: 14.5px;
    box-shadow: var(--shadow); cursor: pointer;
  }
  .drawer-about { margin-top: 20px; font-size: 12.5px; color: var(--text-2); line-height: 2; }
  .about-title { font-size: 14px; font-weight: 700; color: var(--text); }
  .messages { padding: 16px 12px 8px; }
  .pillars { grid-template-columns: repeat(2, 1fr); }
}
