:root {
  color-scheme: light;
  --bg: #fafaf8;
  --surface: #ffffff;
  --surface-soft: #f3f2ee;
  --accent-soft: #e9f7fe;
  --ink: #1c1917;
  --muted: #6b6660;
  --subtle: #928d86;
  --line: #e8e6e1;
  --accent: #0ea5e9;
  --accent-strong: #0284c7;
  --error: #b42318;
  --radius: 8px;
  font-family: "PingFang SC", "Microsoft YaHei", "Helvetica Neue", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body, #app { min-height: 100%; height: 100%; margin: 0; }
body { background: var(--bg); color: var(--ink); font-size: 14px; line-height: 1.6; -webkit-font-smoothing: antialiased; }
button, input, textarea, select { font: inherit; }
button, select { cursor: pointer; }
a { color: inherit; }
.hidden { display: none !important; }
::selection { background: #bae6fd; color: var(--ink); }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { border: 3px solid transparent; border-radius: 99px; background: #d6d3ce; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background: #b8b3ac; background-clip: padding-box; }

/* Login */
.auth-shell { min-height: 100%; display: grid; place-items: center; padding: 32px 20px; background: var(--bg); }
.auth-panel { width: min(100%, 430px); padding: 36px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: 0 24px 70px -34px rgba(28, 25, 23, .28); }
.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--ink); font-size: 16px; font-weight: 700; text-decoration: none; }
.brand-mark { display: inline-grid; width: 30px; height: 30px; place-items: center; border-radius: 8px; background: var(--accent); color: #fff; font-size: 15px; font-weight: 800; }
.brand-light { color: var(--ink); }
.brand-mark-light { background: var(--accent); }
.auth-heading { margin: 56px 0 28px; }
.eyebrow { margin: 0 0 12px; color: var(--accent-strong); font-size: 11px; font-weight: 700; letter-spacing: 2px; text-transform: uppercase; }
.auth-heading h1 { margin: 0; font-size: 28px; line-height: 1.3; }
.auth-heading p:last-child { margin: 10px 0 0; color: var(--muted); }
.auth-form { display: grid; gap: 16px; }
.auth-form label { display: grid; gap: 7px; color: var(--ink); font-weight: 600; }
.auth-form input, .model-control select, .model-control input { width: 100%; min-height: 42px; padding: 0 12px; border: 1px solid var(--line); border-radius: 6px; outline: 0; background: #fcfcfb; color: var(--ink); transition: border-color .15s, box-shadow .15s, background .15s; }
.auth-form input:focus, .model-control select:focus, .model-control input:focus, #messageInput:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(14, 165, 233, .14); background: #fff; }
.button { min-height: 38px; padding: 0 15px; border: 1px solid transparent; border-radius: var(--radius); font-weight: 600; transition: background .15s, border-color .15s, color .15s, opacity .15s, transform .1s; }
.button:active:not(:disabled) { transform: translateY(1px); }
.button:disabled { cursor: not-allowed; opacity: .55; }
.button-primary { background: var(--accent); color: #fff; }
.button-primary:hover:not(:disabled) { background: var(--accent-strong); }
.form-message { min-height: 20px; margin: -2px 0 0; color: var(--error); line-height: 1.45; }
.auth-footer { display: flex; gap: 7px; margin-top: 26px; color: var(--muted); font-size: 13px; }
.auth-footer a { color: var(--accent-strong); font-weight: 600; text-decoration: none; }
.auth-footer a:hover { text-decoration: underline; }

/* Chat workspace */
.chat-shell { display: flex; height: 100%; min-height: 0; background: var(--bg); }
.sidebar { display: flex; width: 260px; flex: 0 0 260px; flex-direction: column; border-right: 1px solid var(--line); background: #f3f2ee; color: var(--ink); }
.sidebar-top { padding: 22px 18px 20px; border-bottom: 1px solid var(--line); }
.button-sidebar { display: flex; width: 100%; align-items: center; gap: 9px; margin-top: 24px; border-color: var(--line); background: var(--surface); color: var(--ink); text-align: left; }
.button-sidebar:hover { border-color: #cbd5e1; background: var(--accent-soft); color: var(--accent-strong); }
.button-leading { display: inline-grid; width: 18px; height: 18px; place-items: center; border-radius: 50%; background: var(--accent); color: #fff; font-size: 16px; line-height: 1; }
.conversation-heading { display: flex; align-items: center; justify-content: space-between; padding: 22px 18px 9px; color: var(--muted); font-size: 11px; font-weight: 700; letter-spacing: 1.5px; text-transform: uppercase; }
.text-button { padding: 3px 0; border: 0; background: transparent; color: var(--muted); font-size: 12px; }
.text-button:hover { color: var(--accent-strong); }
.conversation-list { min-height: 0; flex: 1; overflow-y: auto; padding: 0 10px 10px; }
.conversation-item { display: flex; width: 100%; align-items: center; gap: 9px; padding: 10px; overflow: hidden; border: 1px solid transparent; border-radius: 6px; background: transparent; color: var(--muted); text-align: left; text-overflow: ellipsis; white-space: nowrap; }
.conversation-item:hover { border-color: var(--line); background: var(--surface); color: var(--ink); }
.conversation-item.active { border-color: #bae6fd; background: var(--accent-soft); color: var(--accent-strong); font-weight: 600; }
.conversation-empty { padding: 20px 10px; color: var(--subtle); font-size: 13px; line-height: 1.5; }
.sidebar-bottom { padding: 16px 18px 18px; border-top: 1px solid var(--line); }
.account-row { display: flex; align-items: center; gap: 10px; min-width: 0; }
.account-avatar { display: grid; width: 34px; height: 34px; flex: 0 0 34px; place-items: center; border-radius: 50%; background: var(--accent); color: #fff; font-weight: 700; }
.account-copy { display: grid; min-width: 0; gap: 2px; }
.account-copy strong, .account-copy span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account-copy strong { font-size: 13px; }
.account-copy span { color: var(--muted); font-size: 12px; }
.button-logout { width: 100%; margin-top: 14px; border-color: #d9d5cf; background: transparent; color: var(--muted); }
.button-logout:hover { border-color: #b8b3ac; background: var(--surface); color: var(--ink); }

.chat-main { display: flex; min-width: 0; flex: 1; flex-direction: column; }
.chat-header { display: flex; min-height: 74px; align-items: center; justify-content: space-between; gap: 18px; padding: 14px 30px; border-bottom: 1px solid var(--line); background: rgba(255, 255, 255, .88); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); }
.header-title { display: grid; min-width: 0; gap: 2px; }
.header-title strong { overflow: hidden; font-size: 15px; text-overflow: ellipsis; white-space: nowrap; }
.header-title span { color: var(--muted); font-size: 12px; }
.header-actions { display: flex; align-items: center; gap: 12px; }
.key-control, .model-control { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; font-weight: 600; white-space: nowrap; }
.key-control select, .model-control select, .model-control input { min-height: 38px; padding: 0 11px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); color: var(--ink); font-size: 13px; outline: 0; }
.key-control select { width: 180px; }
.model-control select, .model-control input { width: 205px; }
.key-control select:focus, .model-control select:focus, .model-control input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(14, 165, 233, .12); }
.button-quiet { border-color: var(--line); background: transparent; color: var(--muted); }
.button-quiet:hover:not(:disabled) { border-color: #b8b3ac; background: var(--surface); color: var(--ink); }

.messages { min-height: 0; flex: 1; overflow-y: auto; padding: 38px max(28px, calc((100% - 900px) / 2)); }
.empty-state { display: grid; max-width: 430px; min-height: 340px; margin: 0 auto; align-content: center; justify-items: center; text-align: center; }
.empty-mark { display: grid; width: 54px; height: 54px; place-items: center; border: 1px solid #bae6fd; border-radius: 14px; background: var(--accent-soft); color: var(--accent-strong); font-size: 24px; font-weight: 800; }
.empty-state h2 { margin: 18px 0 7px; font-size: 20px; line-height: 1.35; }
.empty-state p { margin: 0; color: var(--muted); }
.message-row { display: flex; gap: 13px; max-width: 900px; margin: 0 auto 28px; }
.message-row.user { justify-content: flex-end; }
.message-avatar { display: grid; width: 30px; height: 30px; flex: 0 0 30px; place-items: center; border-radius: 50%; background: var(--accent-soft); color: var(--accent-strong); font-size: 12px; font-weight: 800; }
.message-row.user .message-avatar { order: 2; background: var(--accent); color: #fff; }
.message-body { max-width: min(730px, calc(100% - 45px)); }
.message-meta { margin-bottom: 6px; color: var(--subtle); font-size: 11px; font-weight: 600; }
.message-row.user .message-meta { text-align: right; }
.message-content { padding: 12px 15px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--ink); line-height: 1.7; white-space: pre-wrap; overflow-wrap: anywhere; box-shadow: 0 5px 18px -14px rgba(28, 25, 23, .35); }
.message-row.user .message-content { border-color: #bae6fd; background: var(--accent-soft); box-shadow: none; }
.message-content.pending::after { display: inline-block; width: 7px; height: 16px; margin-left: 4px; vertical-align: -3px; background: var(--accent); content: ""; animation: blink 1s steps(2, start) infinite; }
@keyframes blink { 50% { opacity: 0; } }

.composer-wrap { width: min(100%, 950px); margin: 0 auto; padding: 0 28px 20px; }
.composer { padding: 11px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: 0 16px 40px -28px rgba(28, 25, 23, .34); transition: border-color .15s, box-shadow .15s; }
.composer:focus-within { border-color: #7dd3fc; box-shadow: 0 16px 40px -25px rgba(14, 165, 233, .28); }
#messageInput { display: block; width: 100%; min-height: 52px; max-height: 180px; resize: none; padding: 5px 7px; border: 0; outline: 0; background: transparent; color: var(--ink); line-height: 1.6; }
.composer-actions { display: flex; align-items: center; justify-content: flex-end; gap: 10px; padding-top: 7px; }
.stream-status { margin-right: auto; color: var(--subtle); font-size: 12px; }
.button-stop { border-color: #fecaca; background: #fff7f7; color: var(--error); }
.button-stop:hover { background: #fee2e2; }
.composer-note { margin: 8px 2px 0; color: var(--subtle); font-size: 11px; text-align: center; }
.mobile-only { display: none; }

@media (max-width: 920px) {
  .sidebar { width: 240px; flex-basis: 240px; }
  .chat-header { padding: 14px 20px; }
  .header-actions { gap: 8px; }
  .key-control select { width: 150px; }
  .model-control select, .model-control input { width: 165px; }
}

@media (max-width: 760px) {
  .sidebar { position: fixed; z-index: 5; inset: 0 auto 0 0; transform: translateX(-100%); transition: transform .2s ease; box-shadow: 14px 0 34px rgba(28, 25, 23, .16); }
  .sidebar.open { transform: translateX(0); }
  .mobile-only { display: inline-flex; }
  .icon-button { position: relative; display: grid; width: 36px; height: 36px; place-items: center; padding: 0; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); color: var(--muted); font-size: 0; }
  .icon-button::before { width: 16px; height: 10px; border-top: 2px solid currentColor; border-bottom: 2px solid currentColor; content: ""; }
  .icon-button::after { position: absolute; width: 16px; height: 2px; background: currentColor; content: ""; }
  .chat-header { padding: 12px 16px; }
  .header-actions { min-width: 0; margin-left: auto; }
  .key-control span, .model-control span { display: none; }
  .messages { padding: 28px 16px; }
  .composer-wrap { padding: 0 14px 14px; }
}

@media (max-width: 560px) {
  .auth-panel { padding: 28px 22px; }
  .auth-heading { margin-top: 44px; }
  .chat-header { gap: 9px; }
  .header-title { max-width: 86px; }
  .header-title span { display: none; }
  .key-control select { width: 112px; }
  .model-control select, .model-control input { width: 122px; }
  .button-quiet { display: none; }
  .message-row { gap: 8px; margin-bottom: 20px; }
  .message-avatar { width: 27px; height: 27px; flex-basis: 27px; font-size: 11px; }
  .message-body { max-width: calc(100% - 36px); }
  .message-content { padding: 10px 12px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}
