:root {
  --bg: #f7f7f8;
  --surface: #ffffff;
  --surface-2: #f7f9fa;      /* 次级底色：输入框前缀、内嵌小块 */
  --brand-teal: #0e6e79;     /* 品牌青：勾选、数字条。报告页用的也是这一支 */
  --border: #e5e5e5;
  --text: #1a1a1a;
  --text-secondary: #6b6b6b;
  --accent: #0d6efd;
  --accent-light: #e8f0fe;
  --user-bg: #0d6efd;
  --user-text: #ffffff;
  --tool-bg: #f0f4f9;
  --negative: #16a34a;
  --positive: #dc2626;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,.08);
  --sidebar-bg: #202123;
  --sidebar-text: #ececf1;
  --sidebar-hover: #2a2b32;
  --sidebar-active: #343541;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; overflow: hidden; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; background: var(--bg); color: var(--text); }

/* ═══════ Auth Overlay ═══════ */
#auth-overlay {
  position: fixed; inset: 0; z-index: 100;
  /* Hidden by default so guests never flash the login card before JS runs
     (initAuth() lands them straight in chat). JS sets display:flex when the
     login card is actually needed (header 登录 button / free-limit reached). */
  display: none; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}
.auth-card {
  width: 380px; padding: 40px 36px; background: var(--surface);
  border-radius: 16px; box-shadow: 0 20px 60px rgba(0,0,0,.2);
  text-align: center;
}
.auth-logo { font-size: 48px; margin-bottom: 8px; }
.auth-card h2 { font-size: 22px; margin-bottom: 4px; }
.auth-subtitle { font-size: 13px; color: var(--text-secondary); margin-bottom: 28px; }
.auth-card form { display: flex; flex-direction: column; gap: 12px; }
.auth-card input {
  padding: 11px 14px; border: 1px solid var(--border); border-radius: 10px;
  font-size: 14.5px; outline: none; font-family: inherit;
}
.auth-card input:focus { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-light); }
.auth-card button[type="submit"] {
  padding: 11px; background: var(--accent); color: #fff;
  border: none; border-radius: 10px; font-size: 15px; font-weight: 500;
  cursor: pointer; transition: background .15s;
}
.auth-card button[type="submit"]:hover { background: #0b5ed7; }
.auth-toggle { margin-top: 16px; font-size: 13px; color: var(--text-secondary); }
.auth-toggle a { color: var(--accent); text-decoration: none; font-weight: 500; }
.guest-btn {
  width: 100%; padding: 10px; margin-top: 8px;
  background: transparent; color: var(--accent);
  border: 1px solid var(--accent); border-radius: 10px;
  font-size: 14px; cursor: pointer; transition: all .15s;
}
.guest-btn:hover { background: var(--accent-light); }
.auth-error { color: var(--positive); font-size: 13px; min-height: 18px; margin-top: 8px; }

/* Banner shown when guest hits the 5-question limit and the auth overlay reopens. */
.limit-banner {
  background: linear-gradient(90deg, #fef2f2, #fef9c3);
  border: 1px solid #fca5a5;
  color: #b91c1c;
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 13px;
  line-height: 1.4;
  margin-bottom: 12px;
}
.auth-card .lang-btn { position: absolute; top: 16px; right: 16px; }
.auth-card { position: relative; }

/* ═══════ App Layout ═══════ */
#app {
  display: flex;
  height: 100vh;      /* fallback for old browsers */
  height: 100dvh;     /* dynamic viewport height — shrinks when the mobile keyboard opens,
                         keeping the input row visible instead of pushing it off-screen */
}

/* ═══════ Sidebar ═══════ */
#sidebar {
  width: 260px; flex-shrink: 0;
  display: flex; flex-direction: column;
  background: var(--sidebar-bg); color: var(--sidebar-text);
  transition: width .2s, padding .2s;
  overflow: hidden;
}
#sidebar.collapsed { width: 0; padding: 0; }

.sidebar-header { padding: 12px; }
#new-chat-btn {
  width: 100%; padding: 10px 14px;
  display: flex; align-items: center; gap: 8px;
  border: 1px solid #565869; border-radius: 8px;
  background: transparent; color: var(--sidebar-text);
  font-size: 14px; cursor: pointer; transition: background .15s;
}
#new-chat-btn:hover { background: var(--sidebar-hover); }

#conv-list { flex: 1; overflow-y: auto; padding: 4px 8px; }
.conv-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 12px; margin-bottom: 2px;
  border-radius: 8px; cursor: pointer; font-size: 13px;
  transition: background .1s;
}
.conv-item:hover { background: var(--sidebar-hover); }
.conv-item.active { background: var(--sidebar-active); }
.conv-title {
  flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.conv-delete {
  visibility: hidden; background: none; border: none;
  color: #999; cursor: pointer; font-size: 16px; padding: 0 4px;
}
.conv-item:hover .conv-delete { visibility: visible; }
.conv-delete:hover { color: #fff; }

.sidebar-footer {
  padding: 12px; border-top: 1px solid #444;
  font-size: 13px; display: flex; justify-content: space-between; align-items: center;
}
#logout-btn {
  background: none; border: 1px solid #565869; border-radius: 6px;
  color: var(--sidebar-text); padding: 4px 12px; font-size: 12px; cursor: pointer;
}
#logout-btn:hover { background: var(--sidebar-hover); }

#conv-list::-webkit-scrollbar { width: 4px; }
#conv-list::-webkit-scrollbar-thumb { background: #555; border-radius: 2px; }

/* ═══════ Chat Main ═══════ */
#chat-main {
  flex: 1; display: flex; flex-direction: column;
  min-width: 0;
}

header {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--surface); flex-shrink: 0;
}
#sidebar-toggle {
  background: none; border: none; font-size: 20px; cursor: pointer;
  color: var(--text-secondary); padding: 4px;
}
header .logo { font-size: 24px; }
header h1 { font-size: 17px; font-weight: 600; }
header p { font-size: 12px; color: var(--text-secondary); }

/* Language toggle button */
.lang-btn {
  padding: 5px 12px; font-size: 13px; font-weight: 500;
  background: var(--accent-light); color: var(--accent);
  border: 1px solid var(--accent); border-radius: 6px;
  cursor: pointer; transition: all .15s; white-space: nowrap;
}
.lang-btn:hover { background: var(--accent); color: #fff; }

/* Picks badge: prominent CTA in header pointing to /picks.html */
.picks-badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 6px 12px; font-size: 13px; font-weight: 600;
  background: linear-gradient(90deg, #ef4444, #f97316);
  color: #fff; border-radius: 999px; text-decoration: none;
  box-shadow: 0 1px 3px rgba(239, 68, 68, .3);
  transition: transform .15s, box-shadow .15s; white-space: nowrap;
}
.picks-badge:hover { transform: translateY(-1px); box-shadow: 0 3px 8px rgba(239, 68, 68, .4); }

/* ═══════ Messages ═══════ */
#messages {
  flex: 1; overflow-y: auto;
  padding: 20px 24px;
  display: flex; flex-direction: column; gap: 16px;
  max-width: 820px; width: 100%; margin: 0 auto;
}

.msg { max-width: 90%; line-height: 1.65; font-size: 14.5px; }
.msg.user {
  align-self: flex-end;
  background: var(--user-bg); color: var(--user-text);
  padding: 10px 16px; border-radius: var(--radius) var(--radius) 4px var(--radius);
}
.msg.assistant {
  align-self: flex-start;
  background: var(--bg);
  padding: 12px 16px; border-radius: var(--radius) var(--radius) var(--radius) 4px;
}
.msg.assistant p { margin-bottom: 8px; }
.msg.assistant p:last-child { margin-bottom: 0; }
.msg.assistant ul, .msg.assistant ol { padding-left: 20px; margin-bottom: 8px; }
.msg.assistant table { border-collapse: collapse; width: 100%; margin: 8px 0; font-size: 13px; }
.msg.assistant th, .msg.assistant td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; }
.msg.assistant th { background: var(--accent-light); font-weight: 600; }
.msg.assistant strong { font-weight: 600; }
.msg.assistant code { background: #f1f1f1; padding: 1px 5px; border-radius: 4px; font-size: 13px; }
.msg.assistant a { color: var(--accent); text-decoration: none; }
.msg.assistant a:hover { text-decoration: underline; }
.msg.assistant img { max-width: 100%; border-radius: 8px; margin: 8px 0; border: 1px solid var(--border); }

/* ═══════ Tool indicator ═══════ */
.tool-indicator {
  align-self: flex-start;
  display: flex; align-items: center; gap: 8px;
  padding: 8px 14px;
  background: var(--tool-bg); border-radius: 8px;
  font-size: 13px; color: var(--text-secondary);
}
.tool-indicator .spinner {
  width: 14px; height: 14px;
  border: 2px solid var(--border); border-top-color: var(--accent);
  border-radius: 50%; animation: spin .6s linear infinite;
}
.tool-indicator.done .spinner { display: none; }
.tool-indicator.done::before { content: '\2713'; color: var(--negative); font-weight: bold; margin-right: -4px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ═══════ Quick actions ═══════ */
#quick-actions {
  display: flex; flex-wrap: wrap; gap: 8px;
  padding: 0 24px 12px;
  max-width: 820px; width: 100%; margin: 0 auto;
}
.quick-btn {
  padding: 6px 14px; font-size: 13px;
  background: var(--accent-light); color: var(--accent);
  border: 1px solid transparent; border-radius: 20px;
  cursor: pointer; transition: all .15s;
}
.quick-btn:hover { background: var(--accent); color: #fff; }

/* ═══════ 例句卡片（买家入口）═══════
   例句原来是正文里的文字，用户得自己复制粘贴——那是把力气转嫁给他。
   做成可点的卡片，一下就发出去。 */
.sugg { margin: 6px 0 14px; }
.sugg-t { font-size: 14.5px; font-weight: 650; color: var(--text); margin-bottom: 10px; }
.sugg-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
@media (max-width: 640px) { .sugg-grid { grid-template-columns: 1fr } }
.sugg-card {
  text-align: left; padding: 11px 14px; font-size: 13.5px; line-height: 1.45;
  font-family: inherit; color: var(--text); background: #fff;
  border: 1px solid var(--border); border-radius: 11px; cursor: pointer;
  transition: border-color .15s, background .15s, transform .06s;
}
.sugg-card:hover:not(:disabled) { border-color: #0e6e79; background: var(--accent-light); }
.sugg-card:active:not(:disabled) { transform: translateY(1px); }
.sugg-card:disabled { cursor: default; opacity: .45; }
.sugg-card.picked { opacity: 1; border-color: #0e6e79; background: var(--accent-light); font-weight: 600; }
.sugg-h { font-size: 12.5px; color: var(--text-secondary); margin-top: 9px; }

/* ═══════ Input area ═══════ */
#input-area {
  display: flex; gap: 10px;
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  background: var(--surface); flex-shrink: 0;
  max-width: 820px; width: 100%; margin: 0 auto;
}
/* Storage notice — kept in the flex column (flex-shrink:0) like #input-area so it
   never overlaps the iOS keyboard fix that binds #app height to visualViewport. */
/* 对话内表单（卖家估价等需要结构化输入的工具） */
.chat-form {
  max-width: 480px; margin: 10px 0; padding: 16px 18px;
  background: var(--surface); border: 1px solid var(--border);
  border-left: 3px solid #0e6e79; border-radius: var(--radius); box-shadow: var(--shadow);
}
.chat-form.cf-done { opacity: .6; }
.chat-form .cf-title { font-weight: 700; font-size: 15px; color: var(--text); }
.chat-form .cf-sub { font-size: 12.5px; color: var(--text-secondary); margin: 4px 0 12px; line-height: 1.5; }
.chat-form .cf-row { display: flex; align-items: center; gap: 10px; margin: 8px 0; font-size: 13.5px; }
.chat-form .cf-row > span { flex: 0 0 116px; color: var(--text-secondary); }
.chat-form input, .chat-form select {
  flex: 1; padding: 7px 10px; font-size: 14px; font-family: inherit;
  border: 1px solid var(--border); border-radius: 8px; background: #fff; color: var(--text);
}
.chat-form input:focus, .chat-form select:focus { outline: none; border-color: #0e6e79; }
.chat-form .cf-submit {
  margin-top: 12px; width: 100%; padding: 9px; border: none; border-radius: 8px;
  background: #0e6e79; color: #fff; font-size: 14px; font-weight: 600; cursor: pointer;
}
/* 固定前缀（单元号的 #）：印在输入框里，用户只打 07-372 */
.cf-prefixed { display: flex; align-items: stretch; flex: 1; min-width: 0; }
.cf-prefixed i {
  display: flex; align-items: center; padding: 0 2px 0 11px;
  font-style: normal; font-weight: 600; color: var(--text-secondary);
  background: var(--surface-2, #f7f9fa);
  border: 1px solid var(--border, #d7dde2); border-right: none;
  border-radius: 8px 0 0 8px;
}
/* input 自带 flex:1，但它的 flex 容器现在是 .cf-prefixed 而不是 .cf-row，
   所以要显式给宽度，否则这一格会比上面几格窄一截（实测就是这样）。 */
.cf-prefixed input { flex: 1 1 auto; width: 100%; min-width: 0; border-radius: 0 8px 8px 0 !important; }
.cf-prefixed:focus-within i { border-color: #0e6e79; }
.cf-modal-card .cf-prefixed { width: 100%; }

.chat-form .cf-submit:hover { filter: brightness(1.08); }

/* 等待指示器：从发出问题到第一个字出现，之前这一段是完全空白的（实测 15-40 秒）。 */
.thinking { display: flex; gap: 5px; align-items: center; padding: 14px 4px; }
.thinking span {
  width: 7px; height: 7px; border-radius: 50%; background: var(--text-secondary);
  opacity: .35; animation: thinkPulse 1.25s ease-in-out infinite;
}
.thinking span:nth-child(2) { animation-delay: .18s; }
.thinking span:nth-child(3) { animation-delay: .36s; }
@keyframes thinkPulse {
  0%, 60%, 100% { opacity: .28; transform: translateY(0) }
  30%           { opacity: .85; transform: translateY(-3px) }
}
@media (prefers-reduced-motion: reduce) { .thinking span { animation: none; opacity: .5 } }

/* ── 留资浮窗（spec.modal）───────────────────────────────────────────
   夹在对话流里的卡片可以被滑过去，浮在页面上的不能。
   ⚠️ 必须留得住退路：×、点背景、Esc 三种关法都要能用。 */
.cf-backdrop {
  position: fixed; inset: 0; z-index: 200; display: grid; place-items: center;
  padding: 20px; background: rgba(10, 32, 38, .46);
  -webkit-backdrop-filter: blur(2px); backdrop-filter: blur(2px);
  animation: cfFade .16s ease-out;
}
@keyframes cfFade { from { opacity: 0 } to { opacity: 1 } }
.chat-form.cf-modal-card {
  position: relative; width: 100%; max-width: 380px; margin: 0;
  padding: 26px 24px 20px; border-radius: 16px;
  box-shadow: 0 24px 60px -18px rgba(10, 32, 38, .5);
  animation: cfRise .18s cubic-bezier(.2, .8, .3, 1);
}
@keyframes cfRise { from { transform: translateY(10px); opacity: 0 } to { transform: none; opacity: 1 } }
.cf-modal-card .cf-x {
  position: absolute; top: 8px; right: 10px; border: none; background: none;
  font-size: 22px; line-height: 1; color: var(--text-secondary);
  cursor: pointer; padding: 4px 8px; border-radius: 6px;
}
.cf-modal-card .cf-x:hover { background: rgba(0, 0, 0, .06); color: var(--text); }
.cf-modal-card .cf-title { font-size: 17px; }
.cf-modal-card .cf-sub { font-size: 13px; margin: 6px 0 16px; }
/* 只有一个字段，标签压在输入框上方比并排更好按（尤其手机） */
.cf-modal-card .cf-row { display: block; margin: 0 0 14px; }
.cf-modal-card .cf-row > span { display: block; flex: none; margin-bottom: 5px; font-size: 12.5px; }
.cf-modal-card input { width: 100%; box-sizing: border-box; font-size: 16px; padding: 11px 12px; }
.cf-modal-card .cf-submit { width: 100%; padding: 12px; font-size: 15px; }
.cf-modal-card .cf-sub strong { color: var(--text); font-weight: 700; }

/* 卖点三条：给的是「凭什么信你」，所以要看得见，但不能盖过手机号输入框 */
.cf-points { list-style: none; margin: 0 0 16px; padding: 0; display: grid; gap: 7px; }
.cf-points li {
  position: relative; padding-left: 21px; font-size: 12.8px; line-height: 1.5;
  color: var(--text-secondary);
}
.cf-points li::before {
  content: '\2713'; position: absolute; left: 0; top: -1px;
  color: var(--brand-teal); font-weight: 800; font-size: 12.5px;
}

/* 数字条 —— 取代成段卖点，不是叠在它上面。
   这是一个浮窗，用户来这里只为填一个手机号：每多一行字，就多一分放弃的理由。
   三个数字回答的正是此刻的三个犹豫：要多久、要花多少、要填多少东西。 */
.cf-stats {
  display: grid; grid-template-columns: repeat(3, 1fr);
  gap: 8px; margin: 2px 0 16px;
}
.cf-stat {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 9px; padding: 9px 5px; text-align: center;
  /* 三个说明文字长短不一（"免费，无义务" 一行 vs "Typical time to sell" 两行），
     grid 会把三格拉成等高。不居中的话，短的那两格内容贴顶、底下空一截。 */
  display: flex; flex-direction: column; justify-content: center;
}
.cf-stat b {
  display: block; color: var(--brand-teal); font-weight: 800; line-height: 1.2;
  /* 中英文长度差不少（"约 1 个月" vs "Typical time to sell"），用 clamp
     让窄屏自己缩，而不是靠断行——三个格子高度不齐会很难看。 */
  font-size: clamp(13px, 3.6vw, 15.5px); letter-spacing: -.01em;
}
.cf-stat span {
  display: block; margin-top: 3px; color: var(--text-secondary);
  font-size: 10.5px; line-height: 1.3;
}
.cf-modal-card .cf-sub { font-size: 13.5px; line-height: 1.62; color: var(--text-secondary); }
.cf-modal-card .cf-consent { margin-top: 10px; text-align: center; }
@media (max-width: 480px) { .chat-form.cf-modal-card { max-width: 100%; padding: 24px 18px 18px; } }
.chat-form .cf-submit:disabled { background: #9aa5b1; cursor: default; }
.chat-form .cf-err { color: #b42318; font-size: 12.5px; margin-top: 6px; min-height: 16px; }
@media (max-width: 640px) { .chat-form .cf-row { flex-direction: column; align-items: stretch; gap: 4px; }
  .chat-form .cf-row > span { flex: none; } }

/* 准确性告知：输入框正上方一行小字。刻意做得比正文更淡、更小——
   它必须常驻可见（合规），但不能跟对话内容抢注意力。 */
#ai-notice {
  text-align: center;
  font-size: 11.5px;
  line-height: 1.5;
  color: #6b7280;
  padding: 0 16px 6px;
}
@media (max-width: 640px) { #ai-notice { font-size: 11px; padding-bottom: 4px; } }

/* 这行本来就是 PDPA 告知，现在把隐私政策 / 服务条款也挂在这里 ——
   之前全站只有 pricing 和 sell 落地页链到它们，而绝大多数访客根本不去那两页。 */
#chat-disclaimer {
  flex-shrink: 0; display: flex; justify-content: center; align-items: center;
  gap: 14px; flex-wrap: wrap; text-align: center; font-size: 11px; line-height: 1.4;
  color: var(--text-secondary); opacity: .75; background: var(--surface);
  padding: 0 24px 8px; max-width: 820px; width: 100%; margin: 0 auto;
}
#chat-disclaimer a { color: inherit; text-decoration: none; border-bottom: 1px solid currentColor; opacity: .8; }
#chat-disclaimer a:hover { opacity: 1; }
#input-area textarea {
  flex: 1; resize: none;
  padding: 10px 14px; font-size: 14.5px;
  border: 1px solid var(--border); border-radius: 10px;
  outline: none; font-family: inherit;
  min-height: 44px; max-height: 120px;
}
#input-area textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-light); }
#input-area button {
  padding: 0 20px; height: 44px;
  background: var(--accent); color: #fff;
  border: none; border-radius: 10px;
  font-size: 14.5px; font-weight: 500; cursor: pointer;
  transition: background .15s;
}
#input-area button:hover { background: #0b5ed7; }
#input-area button:disabled { opacity: .5; cursor: not-allowed; }

/* ═══════ Welcome ═══════ */
.welcome {
  text-align: center; padding: 60px 20px;
  color: var(--text-secondary);
}

/* 空态垂直居中。
   #messages 是 flex:1 且内容顶对齐 —— 对话开始后这是对的（消息从上往下长），
   但新访客进来只有欢迎块时，它会贴死在顶栏底下，下面留一大片空白。
   手机上尤其明显：一屏就是一句标题加两张卡，剩下 2/3 全空，看着像没加载出来。

   用 :has 只在空态生效，用户一发消息 .welcome 就被移除，自动回到顶对齐。
   `safe center` 是关键：内容比容器高时退回顶对齐，否则 flex 居中会把顶部
   顶出可滚动区域，用户永远够不着。不认识 safe 的浏览器会整条丢弃，
   退回今天的行为 —— 坏不了。 */
#messages:has(> .welcome) { justify-content: safe center; }
.welcome h2 { font-size: 20px; color: var(--text); margin-bottom: 8px; }
.welcome p { font-size: 14px; }

/* 首屏买/卖两个入口。放在中间原本大片空白的位置——卖家是单次价值最高的用户，
   而在此之前整个首屏只有买家话术，业主进来找不到一句对他说的话。
   白底卡片：聊天区是深色的，白卡在上面最跳，也比深色卡干净。 */
.entry-cards { display: flex; gap: 16px; justify-content: center; margin-top: 28px; flex-wrap: wrap; }
.entry-card {
  display: flex; flex-direction: column; align-items: flex-start; gap: 6px;
  width: 244px; padding: 20px; text-align: left; cursor: pointer;
  background: #ffffff; border: 1px solid #e6e8ec; border-radius: 16px;
  box-shadow: 0 6px 18px -12px rgba(15, 33, 64, .45);
  transition: transform .15s, box-shadow .15s, border-color .15s;
}
.entry-card:hover { transform: translateY(-3px); }
.entry-card .ec-ico {
  display: inline-flex; align-items: center; justify-content: center;
  width: 40px; height: 40px; border-radius: 12px; margin-bottom: 4px;
}
.entry-card .ec-ico svg { width: 21px; height: 21px; display: block; }
.entry-card .ec-title { font-size: 15.5px; font-weight: 700; color: #0e1726; letter-spacing: -.01em; }
.entry-card .ec-sub { font-size: 12.5px; color: #667085; line-height: 1.55; }

/* 买家：清爽的薄荷绿 */
.entry-card.buy .ec-ico { background: #e6f7f1; color: #0d8b6c; }
.entry-card.buy:hover { border-color: #10a37f; box-shadow: 0 10px 24px -12px rgba(16, 163, 127, .55); }

/* 卖家：暖杏色。给足视觉权重，因为它是线索来源，但保持清新不压深 */
.entry-card.sell { border-color: #f0dfc2; }
.entry-card.sell .ec-ico { background: #fdf3e2; color: #c08a2e; }
.entry-card.sell .ec-title { color: #7a5a1c; }
.entry-card.sell:hover { border-color: #d9a441; box-shadow: 0 10px 24px -12px rgba(217, 164, 65, .6); }

@media (max-width: 560px) {
  .entry-cards { flex-direction: column; align-items: center; gap: 12px; margin-top: 20px; }
  .entry-card { width: 100%; max-width: 330px; }
}
}

/* ═══════ Scrollbar ═══════ */
#messages::-webkit-scrollbar { width: 6px; }
#messages::-webkit-scrollbar-thumb { background: #ccc; border-radius: 3px; }

/* ═══════ Table overflow fix (for long rows in chat) ═══════ */
.msg.assistant table { display: block; overflow-x: auto; white-space: nowrap; }
.msg.assistant table td, .msg.assistant table th { white-space: nowrap; }

/* ═══════ Backdrop for mobile sidebar ═══════ */
#sidebar-backdrop {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,.4);
  z-index: 49;
}
#sidebar-backdrop.show { display: block; }

/* ═══════ Mobile (≤768px) ═══════ */
@media (max-width: 768px) {
  /* Sidebar → drawer mode, closed by default on mobile */
  #sidebar {
    position: fixed; left: 0; top: 0;
    height: 100dvh; z-index: 50;
    width: 280px; max-width: 80vw;
    transition: transform .25s ease;
    transform: translateX(-100%);
  }
  #sidebar.open { transform: translateX(0); }
  #sidebar.collapsed { transform: translateX(-100%); width: 280px; }

  /* Header compact */
  header { padding: 10px 12px; gap: 8px; }
  header h1 { font-size: 16px; }
  header p { display: none; }    /* hide subtitle on mobile */
  header .logo { font-size: 20px; }

  /* Remove horizontal padding duplication */
  #messages {
    padding: 14px 12px;
    max-width: 100%;
  }
  .msg { max-width: 92%; font-size: 14px; }
  .msg.user { padding: 8px 12px; }
  .msg.assistant { padding: 10px 12px; }

  /* Quick actions: horizontal scroll instead of wrap */
  #quick-actions {
    padding: 0 12px 10px;
    flex-wrap: nowrap; overflow-x: auto;
    max-width: 100%;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  #quick-actions::-webkit-scrollbar { display: none; }
  .quick-btn { flex-shrink: 0; font-size: 12.5px; padding: 6px 12px; }

  /* Input area */
  #input-area {
    padding: 10px 12px;
    max-width: 100%;
    gap: 8px;
    padding-bottom: calc(10px + env(safe-area-inset-bottom));
  }
  #input-area textarea { font-size: 16px; /* prevent iOS zoom */ }
  #input-area button { padding: 0 16px; font-size: 14px; }

  /* Auth card fills screen better */
  .auth-card {
    width: calc(100vw - 32px); max-width: 400px;
    padding: 32px 24px;
  }

  /* Language button smaller */
  .lang-btn { padding: 4px 10px; font-size: 12px; }

  /* Welcome smaller */
  .welcome { padding: 40px 16px; }
  .welcome h2 { font-size: 18px; }

  /* Chart images full-width */
  .msg.assistant img { max-width: 100%; }

  /* Allow tables to wrap cell content on very small screens */
  .msg.assistant table { font-size: 12px; }
  .msg.assistant table td, .msg.assistant table th {
    padding: 5px 8px;
    white-space: normal;    /* override desktop nowrap */
  }
}

/* ═══════ Very small screens (≤380px) ═══════ */
@media (max-width: 380px) {
  header .logo { display: none; }
  header h1 { font-size: 15px; }
  .auth-card { padding: 28px 20px; }
}
