:root {
  color-scheme: dark;
  font-family: "Segoe UI", "Microsoft YaHei UI", system-ui, sans-serif;
  --bg: #121922;
  --side: #18212c;
  --raised: #1e2a37;
  --hover: #283747;
  --border: #334455;
  --text: #f1f5f9;
  --muted: #a5b7c8;
  --accent: #79e2c3;
  --accent-dark: #122c26;
  --danger: #ffb4b5;
  --sidebar: 17rem;
  --content: 54rem;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--text); }
button, input, textarea { font: inherit; }
button { color: inherit; cursor: pointer; }
button:disabled { opacity: .48; cursor: default; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.boot, .signin {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
}
.boot { color: var(--muted); }
.signin {
  background: radial-gradient(ellipse at 50% 10%, #243944 0%, var(--bg) 62%);
}
.signin-card {
  width: min(100%, 25rem);
  padding: clamp(1.5rem, 5vw, 2.5rem);
  border: 1px solid var(--border);
  border-radius: 1.25rem;
  background: var(--side);
  box-shadow: 0 1.5rem 4rem #080d1675;
}
.signin-card h1 { margin: 1.65rem 0 1.35rem; font-size: 1.55rem; }
.signin-card label { display: block; margin-bottom: .5rem; color: var(--muted); }
.signin-card input {
  display: block;
  width: 100%;
  padding: .72rem .8rem;
  border: 1px solid var(--border);
  border-radius: .5rem;
  background: var(--bg);
  color: var(--text);
}
.signin-card .primary { width: 100%; margin-top: 1rem; }
.error { margin: 1rem 0 0; color: var(--danger); font-size: .875rem; }

.brand { display: flex; align-items: center; gap: .75rem; font-size: 1.13rem; font-weight: 700; letter-spacing: .01em; }
.brand-mark {
  --tile: .48rem;
  --gap: .14rem;
  display: grid;
  grid-template: repeat(2, var(--tile)) / repeat(2, var(--tile));
  gap: var(--gap);
  transform: rotate(-9deg);
}
.brand-mark i { background: var(--accent); border-radius: 25%; }
.brand-mark i:nth-child(2) { background: #4f87ad; transform: translate(.04rem, -.1rem); }
.brand-mark i:nth-child(3) { background: #416d84; }
.brand-mark i:nth-child(4) { background: #b1efda; transform: translate(.05rem, .04rem); }
.workspace { display: flex; height: 100vh; height: 100dvh; overflow: hidden; }
.sidebar {
  width: var(--sidebar);
  flex: 0 0 var(--sidebar);
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  background: var(--side);
  border-right: 1px solid var(--border);
}
.sidebar-top { display: grid; gap: 1.5rem; padding: 1.55rem 1.15rem 0; }
.new-session, .primary, .text-button, .icon-button { min-height: 2.5rem; border-radius: .55rem; font-weight: 600; }
.new-session {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .46rem .85rem;
  text-align: left;
  background: #203b3b;
  color: var(--accent);
  border: 1px solid #386057;
}
.new-session:not(:disabled):hover { background: #2a4b48; }
.plus { font-size: 1.25em; line-height: 1; }
.history { min-height: 0; display: flex; flex: 1; flex-direction: column; }
.history h2 {
  margin: 0 1.35rem .55rem;
  color: var(--muted);
  font-size: .76rem;
  font-weight: 650;
  letter-spacing: .05em;
}
.history-empty { margin: .45rem 1.35rem; color: var(--muted); font-size: .82rem; }
.session-list { margin: 0; padding: .2rem .9rem; list-style: none; overflow: auto; }
.session-list button {
  display: block;
  width: 100%;
  padding: .62rem .72rem;
  border: 1px solid transparent;
  border-radius: .45rem;
  color: var(--muted);
  background: transparent;
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.session-list button:hover { background: var(--raised); color: var(--text); }
.session-list button[aria-current="true"] { color: var(--text); background: var(--hover); border-color: var(--border); }
.sidebar-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: .5rem;
  margin-top: auto;
  padding: .65rem 1rem;
  border-top: 1px solid var(--border);
}
.connection { display: flex; align-items: center; gap: .5rem; color: var(--muted); font-size: .78rem; }
.connection i { width: .45rem; height: .45rem; border-radius: 50%; background: #ddbd83; flex: none; }
.connection i[data-ready="true"] { background: var(--accent); }

.main { min-width: 0; flex: 1; display: flex; flex-direction: column; }
.topbar {
  min-height: 3.75rem;
  flex: none;
  padding: .45rem clamp(.8rem, 3vw, 2rem);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: .8rem;
  border-bottom: 1px solid var(--border);
}
.topbar-left, .heading { display: flex; min-width: 0; align-items: center; gap: .6rem; }
.section-label { color: var(--muted); font-size: .82rem; white-space: nowrap; }
.section-label span { margin-left: .35rem; opacity: .55; }
.heading h1 { margin: 0; font-size: .94rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.text-button { padding: .35rem .65rem; font-size: .8rem; border: 1px solid transparent; background: transparent; color: var(--muted); }
.text-button:not(:disabled):hover { color: var(--text); background: var(--raised); }
.delete-session { flex: none; }
.delete-session:not(:disabled):hover { color: var(--danger); }
.icon-button { width: 2.5rem; flex: none; padding: .45rem; border: 1px solid var(--border); background: var(--side); }
.menu-icon, .menu-icon::before, .menu-icon::after { display: block; width: 1rem; height: 2px; background: var(--muted); border-radius: 2px; }
.menu-icon { position: relative; margin: auto; }
.menu-icon::before, .menu-icon::after { position: absolute; content: ""; left: 0; }
.menu-icon::before { top: -.3rem; }
.menu-icon::after { top: .3rem; }
.drawer-toggle, .drawer-backdrop { display: none; }

.chat-scroll { position: relative; flex: 1; min-height: 0; overflow: auto; overscroll-behavior: contain; }
.welcome {
  min-height: 100%;
  padding: 3rem 1rem 2rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  background: radial-gradient(ellipse at 50% 45%, #1a2a35 0%, transparent 47%);
}
.welcome-mark {
  display: grid;
  place-items: center;
  width: 4.2rem;
  height: 4.2rem;
  border-radius: 1.1rem;
  border: 1px solid #3a5a6d;
  background: #20313d;
}
.welcome-mark .brand-mark { --tile: .8rem; --gap: .22rem; }
.welcome h2 { margin: 1rem 0 .45rem; font-size: clamp(1.35rem, 3vw, 2.2rem); font-weight: 650; }
.welcome p { margin: 0; color: var(--muted); font-size: .92rem; }
.messages {
  display: grid;
  gap: 1.45rem;
  width: min(100%, var(--content));
  margin: 0 auto;
  padding: 1.6rem clamp(.85rem, 3vw, 2rem) .9rem;
}
.messages:empty { display: none; }
.message { min-width: 0; }
.message header { display: flex; align-items: center; gap: .5rem; margin-bottom: .35rem; font-size: .76rem; font-weight: 650; color: var(--muted); }
.message-body {
  max-width: 100%;
  padding: .7rem .9rem;
  border: 1px solid var(--border);
  border-radius: .65rem;
  background: var(--side);
  color: var(--text);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  line-height: 1.65;
}
.message[data-role="user"] { justify-self: end; max-width: 90%; }
.message[data-role="user"] header { justify-content: flex-end; }
.message[data-role="user"] .message-body { background: var(--raised); border-color: #435369; }
.message[data-role="assistant"] { max-width: 99%; }
.message[data-role="assistant"] header::before { content: ""; height: .45rem; width: .45rem; border-radius: 2px; background: var(--accent); }
.message[data-streaming="true"] .message-body:empty::after { content: "正在等待回复…"; color: var(--muted); }
.message .copy { min-height: 1.5rem; padding: .1rem .4rem; font-size: .73rem; }

.input-zone {
  flex: none;
  width: min(100%, var(--content));
  margin: 0 auto;
  padding: .65rem clamp(.8rem, 3vw, 2rem) max(.8rem, env(safe-area-inset-bottom));
}
.notice { padding: .6rem .75rem; margin-bottom: .55rem; border-radius: .45rem; color: var(--danger); border: 1px solid #856068; background: #332631; font-size: .83rem; }
.notice[data-kind="status"] { color: var(--text); border-color: var(--border); background: var(--raised); }
.composer { display: grid; padding: .55rem .65rem .45rem; border: 1px solid var(--border); border-radius: .8rem; background: var(--side); }
.composer:focus-within { border-color: #548d81; }
.composer textarea {
  width: 100%;
  min-height: 3.2rem;
  max-height: min(27vh, 14rem);
  resize: vertical;
  padding: .35rem .35rem .25rem;
  border: 0;
  outline: 0;
  color: var(--text);
  background: transparent;
  line-height: 1.45;
  font-size: 1rem;
}
.composer textarea::placeholder { color: var(--muted); }
.composer-actions { min-height: 2.5rem; display: flex; align-items: center; justify-content: flex-end; gap: .6rem; padding-top: .15rem; }
.shortcut { margin-right: auto; color: var(--muted); padding-left: .35rem; font-size: .72rem; }
.shortcut span { padding: 0 .15rem; }
.shortcut kbd { font-family: inherit; font-size: inherit; }
.primary { padding: .47rem .85rem; border: 1px solid transparent; background: var(--accent); color: var(--accent-dark); }
.primary:not(:disabled):hover { background: #a3efd8; }
.send, .stop { min-width: 4.45rem; }
.stop { border-color: #617183; }

@media (max-width: 48rem) {
  .sidebar {
    position: fixed;
    z-index: 5;
    inset: 0 auto 0 0;
    width: min(var(--sidebar), 84vw);
    visibility: hidden;
    transform: translateX(-100%);
    transition: transform .18s ease, visibility .18s;
  }
  .drawer-open .sidebar { transform: translateX(0); visibility: visible; }
  .drawer-open .drawer-backdrop { display: block; position: fixed; inset: 0; z-index: 4; border: 0; background: #080d16b8; }
  .drawer-toggle { display: inline-grid; place-items: center; }
  .topbar { min-height: 3.55rem; padding: .4rem .8rem; }
  .section-label, .shortcut { display: none; }
  .delete-session, .text-button, .send, .new-session { min-height: 2.75rem; }
  .message .copy { min-height: 1.8rem; }
  .composer textarea { resize: none; }
}

@media (prefers-reduced-motion: reduce) {
  .sidebar { transition: none; }
}
