:root {
  color-scheme: light;
  --paper: #f7f5f0;
  --paper-deep: #efede7;
  --surface: rgba(255, 255, 255, .84);
  --surface-solid: #fffefa;
  --ink: #1f2523;
  --muted: #737a75;
  --faint: #a7ada7;
  --line: #e3e3dd;
  --accent: #176c60;
  --accent-soft: #dcebe5;
  --accent-deep: #0f554b;
  --warm: #bd6d49;
  --danger: #a8473f;
  --shadow: 0 18px 48px rgba(42, 51, 45, .08);
  --radius: 18px;
  font-family: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { min-height: 100%; }
body { margin: 0; color: var(--ink); background: var(--paper); }
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
button:disabled, input:disabled, textarea:disabled, select:disabled { cursor: not-allowed; opacity: .55; }
a { color: inherit; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.mobile-only { display: none; }

.chat-page { min-height: 100dvh; overflow: hidden; }
.app-shell { display: flex; min-height: 100dvh; }
.sidebar { width: 292px; flex: 0 0 292px; display: flex; flex-direction: column; padding: 26px 18px 18px; background: #f1f0eb; border-right: 1px solid var(--line); }
.sidebar-head { display: flex; align-items: center; justify-content: space-between; padding: 0 9px 22px; }
.brand { display: inline-flex; align-items: center; gap: 11px; text-decoration: none; color: var(--ink); }
.brand-mark { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 11px; background: var(--accent); color: #fff; font-size: 17px; font-weight: 700; box-shadow: 0 5px 12px rgba(23, 108, 96, .2); }
.brand strong, .brand small { display: block; }
.brand strong { font-size: 17px; line-height: 1.15; letter-spacing: .01em; }
.brand small { margin-top: 3px; color: var(--muted); font-size: 10px; letter-spacing: .07em; }
.icon-button { border: 0; background: transparent; color: var(--muted); font-size: 21px; padding: 7px; line-height: 1; border-radius: 10px; }
.icon-button:hover { background: var(--paper-deep); color: var(--ink); }
.new-chat-button { display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%; border: 1px solid #c9ddd6; border-radius: 12px; padding: 11px 14px; background: var(--accent-soft); color: var(--accent-deep); font-weight: 650; transition: .18s ease; }
.new-chat-button:hover { background: #cfe4dc; transform: translateY(-1px); }
.new-chat-button span { font-size: 20px; line-height: .75; font-weight: 400; }
.history-label { display: flex; justify-content: space-between; align-items: center; margin: 29px 10px 10px; color: var(--muted); font-size: 11px; letter-spacing: .06em; }
.history-count { min-width: 21px; border-radius: 9px; padding: 2px 6px; text-align: center; background: #e3e3dd; color: #888d87; font-size: 10px; }
.chat-list { flex: 1; min-height: 0; overflow-y: auto; padding-right: 2px; }
.chat-list::-webkit-scrollbar, .messages-region::-webkit-scrollbar { width: 7px; }
.chat-list::-webkit-scrollbar-thumb, .messages-region::-webkit-scrollbar-thumb { background: #d4d8d2; border-radius: 9px; }
.chat-item { display: flex; align-items: center; gap: 4px; min-height: 54px; margin: 3px 0; padding: 7px 8px 7px 12px; border: 1px solid transparent; border-radius: 12px; color: #525a54; transition: background .16s ease, border-color .16s ease; }
.chat-item:hover { background: rgba(255,255,255,.58); }
.chat-item.active { background: rgba(255,255,255,.9); border-color: var(--line); color: var(--ink); box-shadow: 0 4px 15px rgba(42, 51, 45, .04); }
.chat-item-main { display: block; flex: 1; min-width: 0; padding: 3px 0; border: 0; text-align: left; background: transparent; color: inherit; }
.chat-item-title { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; font-weight: 600; }
.chat-item-meta { display: block; margin-top: 4px; color: var(--faint); font-size: 10px; }
.chat-item-actions { display: flex; opacity: 0; transition: opacity .16s ease; }
.chat-item:hover .chat-item-actions, .chat-item.active .chat-item-actions { opacity: 1; }
.mini-action { width: 27px; height: 27px; border: 0; border-radius: 8px; background: transparent; color: var(--faint); font-size: 14px; }
.mini-action:hover { background: var(--paper-deep); color: var(--ink); }
.mini-action.delete:hover { color: var(--danger); }
.list-empty { margin: 14px 9px; color: var(--faint); font-size: 12px; line-height: 1.7; }
.sidebar-foot { display: flex; align-items: center; gap: 9px; margin-top: 16px; padding: 14px 7px 0; border-top: 1px solid var(--line); }
.user-chip { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; }
.avatar { display: grid; place-items: center; flex: 0 0 auto; width: 29px; height: 29px; border-radius: 50%; background: #d8e1dc; color: var(--accent-deep); font-size: 12px; font-weight: 700; }
.user-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: #545c56; font-size: 12px; }
.text-button { border: 0; background: transparent; color: var(--muted); font-size: 11px; }
.text-button:hover { color: var(--accent-deep); }

.main-panel { display: flex; flex: 1; min-width: 0; min-height: 100dvh; flex-direction: column; background: var(--paper); }
.topbar { display: flex; align-items: center; justify-content: space-between; min-height: 82px; padding: 17px clamp(20px, 4vw, 58px); border-bottom: 1px solid rgba(227, 227, 221, .8); }
.conversation-title-wrap { min-width: 0; }
.eyebrow { margin: 0; color: var(--accent); font-size: 10px; font-weight: 700; letter-spacing: .16em; text-transform: uppercase; }
.topbar h1 { overflow: hidden; max-width: min(50vw, 620px); margin: 5px 0 0; text-overflow: ellipsis; white-space: nowrap; font-size: 17px; font-weight: 650; letter-spacing: -.01em; }
.connection-dot { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 11px; }
.connection-dot::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: #7bad9d; }
.connection-dot.busy::before { background: var(--warm); box-shadow: 0 0 0 4px rgba(189,109,73,.12); }
.connection-dot.error { color: var(--danger); }
.connection-dot.error::before { background: var(--danger); }
.messages-region { display: flex; flex: 1; min-height: 0; flex-direction: column; overflow-y: auto; padding: 42px clamp(20px, 8vw, 150px) 25px; }
.welcome-state { max-width: 680px; margin: auto; padding: 22px 0 44px; text-align: center; }
.welcome-mark { display: grid; place-items: center; width: 48px; height: 48px; margin: 0 auto 20px; border: 1px solid #cbded7; border-radius: 16px; background: var(--accent-soft); color: var(--accent); font-size: 23px; }
.welcome-state h2 { margin: 13px 0 14px; font-size: clamp(29px, 4vw, 45px); line-height: 1.16; letter-spacing: -.04em; font-weight: 680; }
.welcome-copy { max-width: 455px; margin: 0 auto; color: var(--muted); font-size: 14px; line-height: 1.8; }
.suggestions { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 25px; }
.suggestion { border: 1px solid var(--line); border-radius: 99px; padding: 9px 13px; background: rgba(255,255,255,.45); color: var(--muted); font-size: 12px; }
.suggestion:hover { border-color: #b8d3ca; color: var(--accent-deep); background: #fff; }
.message-list { width: 100%; max-width: 820px; margin: 0 auto; }
.message { display: flex; gap: 12px; margin: 0 0 27px; animation: rise .2s ease both; }
.message.user { justify-content: flex-end; }
.message-avatar { display: grid; place-items: center; flex: 0 0 auto; width: 30px; height: 30px; margin-top: 2px; border-radius: 10px; background: var(--accent); color: white; font-size: 12px; font-weight: 700; }
.message.user .message-avatar { order: 2; background: #e3e5df; color: #69716b; }
.message-body { min-width: 0; max-width: min(75%, 680px); }
.message.user .message-body { display: flex; flex-direction: column; align-items: flex-end; }
.message-meta { margin: 0 0 6px; color: var(--faint); font-size: 10px; }
.message.user .message-meta { text-align: right; }
.message-content { margin: 0; padding: 13px 16px; border-radius: 5px 16px 16px 16px; background: var(--surface-solid); box-shadow: 0 6px 18px rgba(42, 51, 45, .045); font-size: 14px; line-height: 1.75; overflow-wrap: anywhere; white-space: pre-wrap; }
.message.user .message-content { border-radius: 16px 5px 16px 16px; background: var(--accent); color: #fff; }
.message-status { margin-top: 7px; color: var(--muted); font-size: 11px; }
.message-status.error { color: var(--danger); }
.message-actions { display: flex; gap: 7px; margin-top: 7px; }
.message-action { border: 0; padding: 3px 0; background: transparent; color: var(--muted); font-size: 11px; }
.message-action:hover { color: var(--accent-deep); }
.message-attachments { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.message-attachment { display: inline-flex; align-items: center; gap: 5px; max-width: 100%; border: 1px solid var(--line); border-radius: 8px; padding: 6px 9px; background: #fbfbf7; color: var(--muted); font-size: 11px; text-decoration: none; }
.message-attachment:hover { border-color: #b8d3ca; color: var(--accent-deep); }
.message-attachment img { width: 82px; height: 58px; border-radius: 5px; object-fit: cover; }
.typing-dots { display: inline-flex; gap: 4px; align-items: center; height: 18px; }
.typing-dots i { display: block; width: 5px; height: 5px; border-radius: 50%; background: #8bb1a6; animation: blink 1.1s infinite; }
.typing-dots i:nth-child(2) { animation-delay: .15s; }.typing-dots i:nth-child(3) { animation-delay: .3s; }
.inline-error { width: 100%; max-width: 820px; margin: 0 auto 16px; border: 1px solid #e8c8c4; border-radius: 10px; padding: 10px 13px; background: #fff5f3; color: var(--danger); font-size: 12px; line-height: 1.5; }

.composer-wrap { width: min(100%, 940px); margin: 0 auto; padding: 0 clamp(20px, 5vw, 72px) 20px; }
.attachment-strip { display: flex; flex-wrap: wrap; gap: 7px; margin: 0 0 8px; }
.attachment-pill { display: inline-flex; align-items: center; gap: 6px; max-width: 100%; border: 1px solid #cfe0da; border-radius: 10px; padding: 6px 8px 6px 10px; background: #eef6f2; color: var(--accent-deep); font-size: 11px; }
.attachment-pill span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attachment-remove { width: 20px; height: 20px; border: 0; border-radius: 6px; background: transparent; color: var(--muted); line-height: 1; }
.attachment-remove:hover { background: #dcebe5; color: var(--danger); }
.composer-card { border: 1px solid #d6d9d3; border-radius: 17px; background: rgba(255,255,255,.72); box-shadow: var(--shadow); transition: border-color .18s ease, box-shadow .18s ease; }
.composer-card:focus-within { border-color: #9ec2b6; box-shadow: 0 18px 50px rgba(42, 51, 45, .11); }
#message-input { display: block; width: 100%; min-height: 66px; max-height: 190px; resize: none; border: 0; outline: 0; padding: 17px 18px 9px; background: transparent; color: var(--ink); font-size: 14px; line-height: 1.6; }
#message-input::placeholder { color: #a0a69f; }
.composer-toolbar { display: flex; justify-content: space-between; gap: 12px; align-items: center; padding: 7px 10px 10px 14px; }
.toolbar-left, .toolbar-right { display: flex; align-items: center; gap: 8px; min-width: 0; }
.tool-button { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12px; cursor: pointer; }
.tool-button:hover { color: var(--accent-deep); }
.tool-button > span:first-child { font-size: 20px; transform: rotate(-35deg); }
.mode-switch { display: flex; padding: 2px; border-radius: 8px; background: #eceee9; }
.mode-button { border: 0; border-radius: 6px; padding: 5px 8px; background: transparent; color: var(--muted); font-size: 11px; }
.mode-button.active { background: #fff; color: var(--accent-deep); box-shadow: 0 1px 4px rgba(42, 51, 45, .12); font-weight: 650; }
.model-select-wrap { max-width: 155px; }
#model-select { max-width: 155px; overflow: hidden; border: 0; outline: 0; padding: 5px 20px 5px 5px; background: transparent; color: #68716b; font-size: 11px; text-overflow: ellipsis; }
.shortcut-hint { color: var(--faint); font-size: 10px; white-space: nowrap; }
.send-button, .stop-button { display: grid; place-items: center; min-width: 36px; height: 34px; border: 0; border-radius: 10px; font-weight: 650; }
.send-button { background: var(--accent); color: #fff; font-size: 20px; }
.send-button:hover { background: var(--accent-deep); }
.stop-button { padding: 0 11px; background: #f6e7df; color: #a2593e; font-size: 11px; }
.stop-button:hover { background: #f1d8cb; }
.composer-note { margin: 9px 0 0; color: #a4aaa4; text-align: center; font-size: 10px; }
.mode-help { margin: 8px 0 0; color: #8b938d; text-align: center; font-size: 10px; line-height: 1.5; }

.auth-page { display: grid; min-height: 100dvh; place-items: center; padding: 24px; background: radial-gradient(circle at 50% 8%, #fffefa 0, var(--paper) 50%); }
.auth-card { width: min(100%, 420px); padding: 42px 42px 35px; border: 1px solid var(--line); border-radius: 24px; background: rgba(255,255,255,.78); box-shadow: var(--shadow); }
.auth-brand { margin-bottom: 50px; }
.auth-card h1 { margin: 10px 0 10px; font-size: 31px; letter-spacing: -.04em; }
.auth-intro { margin: 0 0 28px; color: var(--muted); font-size: 13px; line-height: 1.7; }
.login-form label { display: block; margin: 17px 0 7px; color: #5f6761; font-size: 12px; font-weight: 650; }
.login-form input { display: block; width: 100%; border: 1px solid #d6d9d3; border-radius: 10px; padding: 12px 13px; outline: 0; background: #fffefa; color: var(--ink); font-size: 14px; }
.login-form input:focus { border-color: #86b5a8; box-shadow: 0 0 0 3px rgba(23,108,96,.1); }
.primary-button { width: 100%; margin-top: 26px; border: 0; border-radius: 11px; padding: 12px; background: var(--accent); color: #fff; font-weight: 650; }
.primary-button:hover { background: var(--accent-deep); }
.form-error { margin: -5px 0 15px; border: 1px solid #e8c8c4; border-radius: 9px; padding: 9px 11px; background: #fff5f3; color: var(--danger); font-size: 12px; line-height: 1.5; }
.auth-footnote { margin: 25px 0 0; color: var(--faint); text-align: center; font-size: 10px; line-height: 1.6; }

@keyframes rise { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: translateY(0); } }
@keyframes blink { 0%, 80%, 100% { opacity: .35; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-2px); } }

@media (max-width: 760px) {
  .mobile-only { display: inline-block; }
  .sidebar { position: fixed; z-index: 20; top: 0; bottom: 0; left: 0; transform: translateX(-102%); width: min(86vw, 310px); transition: transform .22s ease; box-shadow: 18px 0 38px rgba(23, 35, 30, .13); }
  .sidebar.open { transform: translateX(0); }
  .sidebar-backdrop { position: fixed; z-index: 19; inset: 0; display: none; background: rgba(25, 35, 30, .28); }
  .sidebar-backdrop.visible { display: block; }
  .topbar { min-height: 67px; padding: 12px 16px; gap: 9px; }
  .topbar h1 { max-width: 47vw; font-size: 15px; }
  .connection-dot { font-size: 0; gap: 0; }
  .connection-dot::before { width: 7px; height: 7px; }
  .messages-region { padding: 28px 15px 18px; }
  .welcome-state { padding: 12px 10px 30px; }
  .welcome-state h2 { font-size: 32px; }
  .welcome-copy { font-size: 13px; }
  .message { gap: 8px; margin-bottom: 23px; }
  .message-body { max-width: calc(100% - 38px); }
  .message-content { padding: 11px 13px; font-size: 13px; }
  .composer-wrap { padding: 0 11px 12px; }
  .composer-toolbar { align-items: flex-end; padding-left: 11px; }
  .tool-label, .shortcut-hint { display: none; }
  .model-select-wrap, #model-select { max-width: 125px; }
  .auth-card { padding: 32px 24px 28px; }
  .auth-brand { margin-bottom: 38px; }
}

@media (max-width: 420px) {
  .mode-button { padding-inline: 6px; }
  .model-select-wrap, #model-select { max-width: 112px; }
  .toolbar-left { gap: 5px; }
  .message-avatar { width: 28px; height: 28px; }
}
