:root {
  --accent: #16a34a;
  --accent-2: #22c55e;
  --bg: #f5f7f5;
  --panel: #ffffff;
  --ink: #14181c;
  --ink-soft: #64705f;
  --line: #e5ebe4;
  --user-bubble: #16a34a;
  --mark-1: #14181c;
  --mark-2: #2b3038;
  --shadow: 0 10px 40px rgba(20, 40, 25, .12);
  font-synthesis: none;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: "PingFang TC", "Noto Sans TC", -apple-system, "Segoe UI", system-ui, sans-serif;
  color: var(--ink); background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
.brand-mark {
  width: 56px; height: 56px; border-radius: 18px; margin: 0 auto 14px;
  display: grid; place-items: center; font-size: 26px; color: var(--accent);
  background: linear-gradient(135deg, var(--mark-1), var(--mark-2));
  box-shadow: 0 8px 24px rgba(20, 30, 22, .35);
}
.brand-mark.small { width: 30px; height: 30px; border-radius: 9px; font-size: 15px; margin: 0; box-shadow: none; }

/* ---------- 登入 ---------- */
.login-body {
  display: grid; place-items: center; min-height: 100vh;
  background: radial-gradient(1200px 600px at 50% -10%, #e5f3ea, var(--bg));
  padding: 20px;
}
.login-card {
  width: 100%; max-width: 380px; background: var(--panel);
  border: 1px solid var(--line); border-radius: 22px; padding: 36px 30px;
  box-shadow: var(--shadow); text-align: center;
}
.brand h1 { font-size: 22px; margin: 0 0 4px; }
.brand-sub { color: var(--ink-soft); font-size: 14px; margin: 0 0 24px; }
#login-form { display: grid; gap: 14px; text-align: left; }
#login-form label { font-size: 13px; color: var(--ink-soft); display: grid; gap: 6px; }
#login-form input {
  font-size: 15px; padding: 12px 14px; border: 1px solid var(--line);
  border-radius: 12px; background: #fbfbfe; color: var(--ink); outline: none;
}
#login-form input:focus { border-color: var(--accent); background: #fff; }
#login-form button, .send-btn {
  margin-top: 6px; padding: 12px; border: none; border-radius: 12px; cursor: pointer;
  font-size: 15px; font-weight: 600; color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
}
#login-form button:disabled { opacity: .6; cursor: default; }
.error { color: #e0374b; font-size: 13px; min-height: 18px; margin: 4px 0 0; }

/* ---------- 版面：側邊欄 + 聊天 ---------- */
.chat-body { height: 100vh; overflow: hidden; }
.layout { display: flex; height: 100vh; }

.sidebar {
  width: 264px; flex: none; background: #0f1216; color: #e6e9e6;
  display: flex; flex-direction: column; border-right: 1px solid rgba(255, 255, 255, .06);
}
.sidebar-top { padding: 14px; display: flex; flex-direction: column; gap: 12px; }
.sidebar-top .topbar-left { display: flex; align-items: center; gap: 10px; color: #fff; font-size: 15px; }
.new-chat-btn {
  border: none; border-radius: 12px; padding: 11px; cursor: pointer;
  font-size: 14px; font-weight: 600; color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
}
.conv-list { flex: 1; overflow-y: auto; padding: 6px 8px; }
.conv-item {
  display: flex; align-items: center; gap: 6px; padding: 9px 10px; border-radius: 10px;
  cursor: pointer; color: #c7ccc7; font-size: 14px;
}
.conv-item:hover { background: rgba(255, 255, 255, .06); }
.conv-item.active { background: rgba(34, 197, 94, .16); color: #fff; }
.conv-title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-del { border: none; background: none; cursor: pointer; opacity: 0; font-size: 13px; padding: 0 2px; }
.conv-item:hover .conv-del { opacity: .65; }
.conv-del:hover { opacity: 1; }
.sidebar-footer {
  padding: 12px 14px; border-top: 1px solid rgba(255, 255, 255, .08);
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
}
.sidebar-footer .who { color: #9aa39a; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.chat-col { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  display: none; align-items: center; gap: 12px;
  padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--line);
}
.topbar-title { font-weight: 600; font-size: 15px; }
.backdrop { display: none; }
.menu-toggle { display: none; }
.ghost-btn {
  border: 1px solid var(--line); background: #fff; color: var(--ink-soft);
  padding: 7px 12px; border-radius: 10px; font-size: 13px; cursor: pointer;
}
.ghost-btn:hover { border-color: var(--accent); color: var(--accent); }

.messages { flex: 1; overflow-y: auto; padding: 24px 16px 8px; }
.welcome { max-width: 560px; margin: 8vh auto 0; text-align: center; color: var(--ink-soft); }
.welcome-mark {
  width: 64px; height: 64px; border-radius: 20px; margin: 0 auto 18px;
  display: grid; place-items: center; font-size: 30px; color: var(--accent);
  background: linear-gradient(135deg, var(--mark-1), var(--mark-2));
  box-shadow: 0 10px 30px rgba(20, 30, 22, .3);
}
.welcome h2 { color: var(--ink); margin: 0 0 8px; font-size: 22px; }

.msg { display: flex; margin: 0 auto 16px; max-width: 780px; }
.msg.user { justify-content: flex-end; }
.bubble {
  max-width: 78%; padding: 12px 15px; border-radius: 16px; line-height: 1.65;
  font-size: 15px; white-space: pre-wrap; word-break: break-word;
}
.msg.assistant .bubble { background: var(--panel); border: 1px solid var(--line); border-top-left-radius: 5px; }
.msg.user .bubble { background: var(--user-bubble); color: #fff; border-top-right-radius: 5px; }
.rich-img, .rich-video { display: block; max-width: 100%; border-radius: 12px; margin: 8px 0 4px; }

/* markdown 內容 */
.md > *:first-child { margin-top: 0; }
.md > *:last-child { margin-bottom: 0; }
.md p { margin: 0 0 8px; }
.md ul, .md ol { margin: 6px 0; padding-left: 22px; }
.md li { margin: 2px 0; }
.md h1, .md h2, .md h3 { margin: 10px 0 6px; font-size: 1.05em; }
.md code { background: #eef1ee; border-radius: 5px; padding: 1px 5px; font-size: .9em; }
.md pre { background: #14181c; color: #e6e9e6; padding: 12px; border-radius: 10px; overflow-x: auto; }
.md pre code { background: none; padding: 0; color: inherit; }
.md a { color: var(--accent); }
.md-table-wrap, .md .table-scroll { overflow-x: auto; }
.md table { border-collapse: collapse; width: 100%; margin: 8px 0; font-size: 14px; }
.md th, .md td { border: 1px solid var(--line); padding: 7px 10px; text-align: left; white-space: nowrap; }
.md th { background: #eef4ef; font-weight: 600; }
.md tr:nth-child(even) td { background: #fafcfa; }
.file-link {
  display: inline-block; margin: 6px 0; padding: 8px 14px; border-radius: 10px;
  background: rgba(22, 163, 74, .1); color: var(--accent); font-weight: 600; text-decoration: none;
}
.file-link:hover { background: rgba(22, 163, 74, .18); }
.file-chip {
  display: inline-block; background: rgba(255,255,255,.18); border-radius: 8px;
  padding: 4px 8px; font-size: 13px; margin-bottom: 6px;
}
.msg.assistant .file-chip { background: #f0f1f8; }
.dots { display: inline-flex; gap: 4px; }
.dots i { width: 7px; height: 7px; border-radius: 50%; background: var(--accent-2); animation: blink 1.2s infinite both; }
.dots i:nth-child(2) { animation-delay: .2s; } .dots i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }

/* ---------- 輸入區 ---------- */
.composer { border-top: 1px solid var(--line); background: var(--panel); padding: 10px 16px 16px; }
.attachments { display: flex; flex-wrap: wrap; gap: 6px; max-width: 780px; margin: 0 auto; }
.attachments:not(:empty) { padding-bottom: 8px; }
.pending-chip {
  display: inline-flex; align-items: center; gap: 6px; background: #eef0fa;
  color: var(--ink); border-radius: 10px; padding: 5px 8px; font-size: 13px;
}
.pending-chip button { border: none; background: none; cursor: pointer; font-size: 16px; color: var(--ink-soft); line-height: 1; }
.composer-row { display: flex; align-items: flex-end; gap: 10px; max-width: 780px; margin: 0 auto; }
.attach-btn {
  width: 42px; height: 42px; flex: none; border-radius: 12px; border: 1px solid var(--line);
  display: grid; place-items: center; cursor: pointer; font-size: 22px; color: var(--ink-soft); background: #fff;
}
.attach-btn:hover { border-color: var(--accent); color: var(--accent); }
#input {
  flex: 1; resize: none; border: 1px solid var(--line); border-radius: 14px;
  padding: 11px 14px; font-size: 15px; font-family: inherit; line-height: 1.5;
  max-height: 200px; outline: none; background: #fbfbfe;
}
#input:focus { border-color: var(--accent); background: #fff; }
.send-btn { width: 42px; height: 42px; flex: none; border-radius: 12px; font-size: 20px; padding: 0; margin: 0; }
.send-btn:disabled { opacity: .5; cursor: default; }

@media (max-width: 760px) {
  .bubble { max-width: 88%; }
  .topbar { display: flex; }
  .menu-toggle { display: inline-block; }
  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; z-index: 30;
    transform: translateX(-100%); transition: transform .22s ease;
  }
  .sidebar.open { transform: translateX(0); }
  .backdrop.show {
    display: block; position: fixed; inset: 0; z-index: 20;
    background: rgba(0, 0, 0, .4);
  }
}
