/* 租房助手前端样式：豆包风格，浅色为主并适配深色模式 */
:root {
  --bg: #f7f7f8;
  --panel: #ffffff;
  --panel-2: #f2f3f5;
  --border: #e8e8ea;
  --text: #1f2329;
  --text-2: #646a73;
  --text-3: #9aa0a8;
  --brand: #4d6bfe;
  --brand-2: #7b5bff;
  --brand-soft: rgba(77, 107, 254, 0.1);
  --green: #00b96b;
  --orange: #ff8f1f;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-md: 0 6px 20px rgba(15, 23, 42, 0.08);
  --shadow-lg: 0 18px 48px rgba(15, 23, 42, 0.12);
  --radius: 14px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17181c;
    --panel: #1f2025;
    --panel-2: #26272d;
    --border: #303138;
    --text: #e8e9ec;
    --text-2: #a6abb3;
    --text-3: #7c828b;
    --brand-soft: rgba(77, 107, 254, 0.16);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 6px 20px rgba(0, 0, 0, 0.35);
    --shadow-lg: 0 18px 48px rgba(0, 0, 0, 0.5);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

button { font-family: inherit; cursor: pointer; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.app { display: flex; height: 100vh; overflow: hidden; }

/* ---------- 顶栏 ---------- */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; position: relative; }

.topbar {
  height: 54px; flex: 0 0 54px;
  display: flex; align-items: center; gap: 10px;
  padding: 0 18px; border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: blur(10px);
  z-index: 5;
}
.topbar .title { flex: 1; font-size: 15px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.brand { display: flex; align-items: center; gap: 8px; }
.brand-logo {
  width: 26px; height: 26px; border-radius: 8px;
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  color: #fff; font-size: 13px; font-weight: 600;
  display: grid; place-items: center;
}
.brand-name { font-size: 14.5px; font-weight: 600; letter-spacing: .2px; }

.icon-btn {
  width: 32px; height: 32px; border: none; border-radius: 8px;
  background: transparent; color: var(--text-2);
  display: grid; place-items: center; transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--brand-soft); color: var(--brand); }
.icon-btn svg { width: 18px; height: 18px; }

.messages { flex: 1; overflow-y: auto; padding: 26px 20px 8px; scroll-behavior: smooth; }
.messages::-webkit-scrollbar { width: 8px; }
.messages::-webkit-scrollbar-thumb { background: transparent; border-radius: 4px; }
.messages:hover::-webkit-scrollbar-thumb { background: var(--border); }

.inner { max-width: 880px; margin: 0 auto; }

/* 欢迎区 */
.welcome { max-width: 880px; margin: 6vh auto 0; text-align: center; animation: fadeUp .5s ease both; }
.welcome-logo {
  width: 58px; height: 58px; border-radius: 18px; margin: 0 auto 18px;
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  color: #fff; font-size: 27px; font-weight: 600; display: grid; place-items: center;
  box-shadow: 0 10px 26px rgba(77, 107, 254, .32);
}
.welcome h1 { margin: 0 0 10px; font-size: 27px; font-weight: 650; letter-spacing: .3px; }
.welcome-sub { margin: 0 0 26px; color: var(--text-2); font-size: 14.5px; line-height: 1.75; }

.chips { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }
.chip {
  border: 1px solid var(--border); background: var(--panel); color: var(--text-2);
  padding: 10px 15px; border-radius: 999px; font-size: 13.5px;
  transition: border-color .15s, color .15s, transform .12s, box-shadow .15s;
}
.chip:hover { border-color: var(--brand); color: var(--brand); box-shadow: var(--shadow-sm); transform: translateY(-1px); }

/* 消息 */
.msg { display: flex; gap: 12px; margin-bottom: 26px; animation: fadeUp .28s ease both; }
.msg-user { justify-content: flex-end; }
.msg-user .bubble {
  max-width: 78%; padding: 11px 15px; border-radius: 16px 16px 4px 16px;
  background: linear-gradient(135deg, var(--brand), var(--brand-2)); color: #fff;
  font-size: 15px; line-height: 1.7; white-space: pre-wrap; word-break: break-word;
  box-shadow: 0 6px 16px rgba(77, 107, 254, .22);
}
.msg-bot .bot-avatar {
  width: 32px; height: 32px; flex: 0 0 32px; border-radius: 10px;
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  color: #fff; font-size: 15px; display: grid; place-items: center;
  box-shadow: 0 4px 12px rgba(77, 107, 254, .26);
}
.bot-body { min-width: 0; flex: 1; }
.bot-text { font-size: 15px; line-height: 1.85; white-space: pre-wrap; word-break: break-word; }

/* 思考状态 */
.thinking { display: flex; align-items: center; gap: 9px; color: var(--text-3); font-size: 14px; padding: 3px 0; }
.thinking .dots { display: inline-flex; gap: 4px; }
.thinking .dots i {
  width: 6px; height: 6px; border-radius: 50%; background: var(--brand);
  animation: bounce 1.15s infinite ease-in-out;
}
.thinking .dots i:nth-child(2) { animation-delay: .16s; }
.thinking .dots i:nth-child(3) { animation-delay: .32s; }
.thinking .stage-text { transition: opacity .2s; }

.caret { display: inline-block; width: 2px; height: 15px; background: var(--brand); vertical-align: -2px; margin-left: 2px; animation: blink .9s step-end infinite; }

/* ---------- Markdown 正文 ---------- */
.bot-text .md-p { margin: 0 0 9px; }
.bot-text .md-p:last-child { margin-bottom: 0; }
.bot-text .md-h { margin: 14px 0 8px; font-weight: 650; line-height: 1.5; }
.bot-text .md-h:first-child { margin-top: 0; }
.bot-text .md-h1 { font-size: 18px; }
.bot-text .md-h2 { font-size: 16.5px; }
.bot-text .md-h3 { font-size: 15px; color: var(--text-2); }
.bot-text .md-ul, .bot-text .md-ol { margin: 6px 0 10px; padding-left: 22px; }
.bot-text .md-ul { list-style: disc; }
.bot-text .md-ol { list-style: decimal; }
.bot-text .md-ul li, .bot-text .md-ol li { margin: 5px 0; }
.bot-text strong { font-weight: 650; color: var(--text); }
.bot-text .md-quote {
  margin: 8px 0; padding: 6px 12px; border-left: 3px solid var(--brand);
  background: var(--brand-soft); border-radius: 0 8px 8px 0; color: var(--text-2);
}
.bot-text .md-hr { margin: 12px 0; border: none; border-top: 1px solid var(--border); }
.bot-text .md-code {
  margin: 8px 0; padding: 11px 13px; border-radius: 9px; overflow-x: auto;
  background: var(--panel-2); border: 1px solid var(--border);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; line-height: 1.65;
}
.bot-text .md-code code { background: none; padding: 0; border: none; color: var(--text); }
.bot-text .md-code-inline {
  padding: 1.5px 5px; border-radius: 5px; background: var(--panel-2);
  border: 1px solid var(--border); font-size: 12.5px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.bot-text a { color: var(--brand); text-decoration: none; }
.bot-text a:hover { text-decoration: underline; }

/* Markdown 表格 */
.bot-text .md-table-wrap {
  margin: 8px 0 12px; overflow-x: auto; -webkit-overflow-scrolling: touch;
  border: 1px solid var(--border); border-radius: 10px; background: var(--panel);
}
.bot-text .md-table {
  width: 100%; border-collapse: collapse; font-size: 13.5px; line-height: 1.6;
}
.bot-text .md-table th, .bot-text .md-table td {
  padding: 8px 11px; border-bottom: 1px solid var(--border); border-right: 1px solid var(--border);
  white-space: normal; text-align: left; vertical-align: top; word-break: break-word;
}
.bot-text .md-table th {
  background: var(--panel-2); color: var(--text); font-weight: 650; white-space: nowrap;
  position: sticky; top: 0;
}
.bot-text .md-table td { color: var(--text-2); }
.bot-text .md-table th:last-child, .bot-text .md-table td:last-child { border-right: none; }
.bot-text .md-table tbody tr:last-child td { border-bottom: none; }
.bot-text .md-table tbody tr:hover td { background: var(--panel-2); }

/* ---------- 输入区 ---------- */
.composer-wrap { flex: 0 0 auto; padding: 8px 20px 16px; }
.composer {
  max-width: 880px; margin: 0 auto;
  background: var(--panel); border: 1px solid var(--border); border-radius: 18px;
  padding: 12px 12px 10px 16px; box-shadow: var(--shadow-md);
  transition: border-color .15s, box-shadow .15s;
}
.composer:focus-within { border-color: rgba(77, 107, 254, .5); box-shadow: 0 8px 26px rgba(77, 107, 254, .14); }
.composer textarea {
  width: 100%; border: none; outline: none; resize: none; background: transparent;
  color: var(--text); font-size: 15px; line-height: 1.7; max-height: 168px; padding: 2px 0 6px;
}
.composer textarea::placeholder { color: var(--text-3); }
.composer-bar { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.hint { font-size: 11.5px; color: var(--text-3); }
.send-btn {
  width: 36px; height: 36px; border: none; border-radius: 11px;
  background: linear-gradient(135deg, var(--brand), var(--brand-2)); color: #fff;
  display: grid; place-items: center; transition: opacity .15s, transform .12s, background .15s;
}
.send-btn svg { width: 19px; height: 19px; stroke-width: 2.2; }
.send-btn:disabled { background: var(--panel-2); color: var(--text-3); cursor: not-allowed; }
.send-btn:not(:disabled):hover { transform: translateY(-1px); }
.send-btn:not(:disabled):active { transform: scale(.94); }
.send-btn.stop { background: #f5222d; }
.disclaimer { max-width: 880px; margin: 9px auto 0; text-align: center; font-size: 11.5px; color: var(--text-3); }

/* ---------- 通用 ---------- */
.err-box {
  margin-top: 10px; padding: 10px 13px; border-radius: 10px; font-size: 13.5px;
  background: rgba(245, 34, 45, .09); color: #f5222d; border: 1px solid rgba(245, 34, 45, .2);
}
@keyframes fadeUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes bounce { 0%, 80%, 100% { transform: scale(.6); opacity: .45; } 40% { transform: scale(1); opacity: 1; } }
@keyframes blink { 50% { opacity: 0; } }

/* ---------- 响应式 ---------- */
@media (max-width: 860px) {
  .topbar { padding: 0 14px; }
  .brand-name { display: none; }
  .messages { padding: 18px 14px 6px; }
  .composer-wrap { padding: 6px 12px 12px; }
  .composer { border-radius: 16px; padding: 10px 10px 8px 13px; }
  .welcome { margin-top: 3vh; }
  .welcome h1 { font-size: 22px; }
  .welcome-sub { font-size: 13px; }
  .chips { flex-direction: column; align-items: stretch; }
  .chip { text-align: left; border-radius: 12px; }
  .msg-user .bubble { max-width: 86%; }
  .hint { display: none; }
}
/* ---------- 登录遮罩 ---------- */
.login-mask {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: var(--bg);
}
/* HTML 中遮罩默认可见，仅当 JS 确认已登录时才隐藏 */
.login-mask[hidden] { display: none; }

.login-card {
  width: min(340px, 100%);
  padding: 32px 26px 26px;
  text-align: center;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: var(--shadow-lg);
  animation: fadeUp .28s ease both;
}

.login-logo {
  width: 48px;
  height: 48px;
  margin: 0 auto 14px;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  font-weight: 600;
  color: #fff;
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
}

.login-title { margin: 0 0 6px; font-size: 19px; font-weight: 600; }
.login-sub { margin: 0 0 20px; font-size: 13px; color: var(--text-2); }

.login-input {
  width: 100%;
  height: 44px;
  padding: 0 14px;
  font-family: inherit;
  font-size: 15px;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.login-input::placeholder { color: var(--text-3); }
.login-input:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-soft);
}

.login-error {
  margin: 10px 0 0;
  font-size: 13px;
  color: #e5484d;
  text-align: left;
}
.login-error[hidden] { display: none; }

.login-btn {
  width: 100%;
  height: 44px;
  margin-top: 16px;
  font-family: inherit;
  font-size: 15px;
  font-weight: 600;
  color: #fff;
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  border: 0;
  border-radius: 12px;
  transition: opacity .15s, transform .1s;
}
.login-btn:hover { opacity: .92; }
.login-btn:active { transform: scale(.99); }
.login-btn:disabled { opacity: .6; cursor: default; }
