:root {
  color-scheme: light;
  --app-height: 100lvh;
  --keyboard-offset: 0px;
  --bg: #ffffff;
  --surface: #ffffff;
  --surface-soft: #f7f7f8;
  --surface-muted: #fbfbfc;
  --line: rgba(15, 23, 42, 0.07);
  --line-strong: rgba(15, 23, 42, 0.1);
  --text: #1f2937;
  --muted: #6b7280;
  --subtle: #9aa1ad;
  --accent: #10a37f;
  --danger: #d14343;
  --shadow-sm: 0 6px 20px rgba(15, 23, 42, 0.04);
  --shadow-md: 0 18px 42px rgba(15, 23, 42, 0.07);
  --shadow-lg: 0 28px 76px rgba(15, 23, 42, 0.11);
  --sidebar-width: 268px;
  --thread-width: 820px;
  --composer-width: 824px;
  --ease-standard: cubic-bezier(0.22, 1, 0.36, 1);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: "Avenir Next", "SF Pro Display", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button,
input,
textarea,
select {
  font: inherit;
}

button {
  color: inherit;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

textarea,
input,
select {
  outline: none;
}

.hidden {
  display: none !important;
}

.app-shell {
  display: flex;
  height: var(--app-height);
  background: var(--bg);
  overflow: hidden;
}

.sidebar {
  width: var(--sidebar-width);
  flex: 0 0 var(--sidebar-width);
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px 12px 12px;
  background: linear-gradient(180deg, #fcfcfd 0%, #fafafb 100%);
  border-right: 1px solid var(--line);
  transition: width 240ms var(--ease-standard), flex-basis 240ms var(--ease-standard), padding 240ms var(--ease-standard), opacity 180ms ease, transform 240ms var(--ease-standard);
  overflow: hidden;
}

body.sidebar-collapsed .sidebar,
html.preload-sidebar-collapsed .sidebar {
  width: 0;
  flex-basis: 0;
  padding-left: 0;
  padding-right: 0;
  border-right-width: 0;
  opacity: 0;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 6px 4px;
}

.brand-mark {
  font-size: 17px;
  font-weight: 650;
  letter-spacing: -0.025em;
}

.sidebar-actions {
  display: grid;
  gap: 6px;
}

.conversation-list {
  min-height: 0;
  flex: 1 1 auto;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding-right: 4px;
  -webkit-overflow-scrolling: touch;
  transition: opacity 140ms ease;
}

html.app-preboot .conversation-list {
  opacity: 0;
}

.conversation-list::-webkit-scrollbar,
.toolbar-scroll::-webkit-scrollbar {
  display: none;
}

.conversation-item {
  width: 100%;
  display: flex;
  align-items: stretch;
  gap: 6px;
  padding: 6px 8px 6px 10px;
  border: 1px solid transparent;
  border-radius: 14px;
  background: transparent;
  transition: transform 180ms var(--ease-standard), background 180ms ease, border-color 180ms ease, box-shadow 180ms ease;
}

.conversation-item.long-pressing {
  background: #ffffff;
  border-color: rgba(16, 163, 127, 0.18);
  box-shadow: 0 8px 20px rgba(15, 23, 42, 0.06);
  transform: scale(0.988);
}

.conversation-item:hover {
  background: rgba(255, 255, 255, 0.82);
  border-color: rgba(15, 23, 42, 0.06);
  transform: translateY(-1px);
}

.conversation-item.active {
  background: #ffffff;
  border-color: rgba(15, 23, 42, 0.08);
  box-shadow: 0 4px 12px rgba(15, 23, 42, 0.04);
}

.conversation-open {
  min-width: 0;
  flex: 1 1 auto;
  padding: 4px 0;
  border: 0;
  background: transparent;
  text-align: left;
  cursor: pointer;
}

.conversation-open:hover {
  transform: none;
}

.conversation-star {
  flex: 0 0 auto;
  align-self: center;
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: rgba(15, 23, 42, 0.24);
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
  transition: transform 180ms var(--ease-standard), color 180ms ease, background 180ms ease, opacity 180ms ease;
}

.conversation-star:hover {
  transform: scale(1.04);
  color: #d39a12;
  background: rgba(15, 23, 42, 0.05);
}

.conversation-star.active {
  color: #f2b01e;
  background: rgba(242, 176, 30, 0.12);
}

.conversation-title,
.conversation-empty {
  font-size: 13px;
  line-height: 1.42;
}

.conversation-title {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.conversation-empty {
  color: var(--muted);
  padding: 8px 10px;
}

.workspace {
  position: relative;
  min-width: 0;
  flex: 1 1 auto;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  height: var(--app-height);
}

.workspace-header {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 56px;
  padding: 10px 18px;
  border-bottom: 1px solid rgba(15, 23, 42, 0.04);
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(18px);
}

.header-title {
  min-width: 0;
  font-size: 17px;
  font-weight: 650;
  letter-spacing: -0.025em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.thread-scroll {
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.thread-inner {
  position: relative;
  width: min(100%, calc(var(--thread-width) + 64px));
  min-width: 0;
  min-height: 100%;
  margin: 0 auto;
  padding: 28px 32px 30px;
}

.empty-state {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  text-align: center;
  pointer-events: none;
}

.empty-state-inner {
  width: min(100%, 580px);
  padding: 0 24px 96px;
  transition: opacity 180ms ease;
}

.empty-state h1 {
  margin: 0;
  font-size: clamp(36px, 4.6vw, 52px);
  line-height: 1.06;
  letter-spacing: -0.06em;
}

.empty-state p {
  margin: 16px 0 0;
  color: var(--muted);
  font-size: 16px;
  line-height: 1.7;
}

.message-list {
  position: relative;
  width: min(100%, var(--thread-width));
  min-width: 0;
  margin: 0 auto;
  padding: 22px 0 100px;
  display: grid;
  gap: 26px;
}

.jump-nav-dock {
  position: absolute;
  top: 72px;
  right: calc(16px + env(safe-area-inset-right));
  bottom: calc(116px + env(safe-area-inset-bottom) + var(--keyboard-offset));
  width: min(320px, calc(100vw - 32px));
  pointer-events: none;
  z-index: 14;
}

.jump-nav-btn,
.jump-nav-panel {
  position: absolute;
  right: 0;
  pointer-events: auto;
}

.jump-nav-btn {
  top: 50%;
  transform: translateY(-50%);
  min-height: 40px;
  padding: 0 10px 0 13px;
  border-radius: 999px;
  border: 1px solid rgba(15, 23, 42, 0.08);
  background: rgba(255, 255, 255, 0.95);
  box-shadow: 0 16px 38px rgba(15, 23, 42, 0.08);
  backdrop-filter: blur(18px);
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  transition: transform 180ms var(--ease-standard), box-shadow 180ms ease, border-color 180ms ease, background 180ms ease;
}

.jump-nav-btn:hover {
  transform: translateY(calc(-50% - 1px));
}

.jump-nav-btn-text {
  font-size: 13px;
  font-weight: 620;
  letter-spacing: -0.02em;
}

.jump-nav-btn-count {
  min-width: 22px;
  height: 22px;
  padding: 0 7px;
  display: inline-grid;
  place-items: center;
  border-radius: 999px;
  background: #f3f4f6;
  color: var(--muted);
  font-size: 11px;
  line-height: 1;
}

.jump-nav-panel {
  top: 50%;
  transform: translateY(-50%);
  width: 100%;
  max-height: 100%;
  padding: 12px;
  display: grid;
  gap: 10px;
  border-radius: 24px;
  border: 1px solid rgba(15, 23, 42, 0.08);
  background: rgba(255, 255, 255, 0.98);
  box-shadow: 0 24px 56px rgba(15, 23, 42, 0.12);
  backdrop-filter: blur(18px);
  overflow: hidden;
  animation: panel-in 180ms var(--ease-standard) both;
}

.jump-nav-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.jump-nav-title {
  font-size: 14px;
  font-weight: 650;
  letter-spacing: -0.025em;
}

.jump-nav-close-btn {
  width: 34px;
  height: 34px;
  font-size: 18px;
}

.jump-nav-search {
  width: 100%;
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid rgba(15, 23, 42, 0.06);
  border-radius: 16px;
  background: #f7f7f8;
  color: var(--text);
}

.jump-nav-search::placeholder {
  color: var(--subtle);
}

.jump-nav-list {
  min-height: 0;
  max-height: min(58vh, 560px);
  overflow-y: auto;
  display: grid;
  gap: 8px;
  padding-right: 4px;
  -webkit-overflow-scrolling: touch;
}

.jump-nav-list::-webkit-scrollbar {
  display: none;
}

.jump-nav-item {
  width: 100%;
  padding: 11px 12px 12px;
  display: grid;
  gap: 7px;
  text-align: left;
  border-radius: 18px;
  border: 1px solid rgba(15, 23, 42, 0.05);
  background: #fbfbfc;
  cursor: pointer;
  transition: transform 180ms var(--ease-standard), box-shadow 180ms ease, border-color 180ms ease, background 180ms ease;
}

.jump-nav-item:hover {
  transform: translateY(-1px);
  background: #ffffff;
  border-color: rgba(15, 23, 42, 0.08);
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.06);
}

.jump-nav-item-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  font-size: 11px;
  color: var(--muted);
}

.jump-nav-item-index {
  min-width: 34px;
  height: 22px;
  padding: 0 8px;
  display: inline-grid;
  place-items: center;
  border-radius: 999px;
  background: #ffffff;
  border: 1px solid rgba(15, 23, 42, 0.06);
  color: var(--text);
}

.jump-nav-item-time {
  white-space: nowrap;
}

.jump-nav-item-preview {
  font-size: 13px;
  line-height: 1.58;
  color: var(--text);
  word-break: break-word;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.jump-nav-empty {
  padding: 18px 8px 12px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}

.message-row {
  display: grid;
  min-width: 0;
  animation: message-in 260ms var(--ease-standard) both;
}

.message-row.user {
  justify-items: end;
}

.message-bubble {
  width: min(100%, var(--thread-width));
  min-width: 0;
  max-width: 100%;
  color: var(--text);
}

.message-bubble > * {
  min-width: 0;
  max-width: 100%;
}

.message-row.assistant .message-bubble {
  padding: 0;
  border: 0;
  background: transparent;
  box-shadow: none;
  line-height: 1.8;
  font-size: 15.5px;
}

.message-row.user .message-bubble {
  width: fit-content;
  min-width: 0;
  max-width: min(100%, 700px);
  padding: 13px 18px;
  border-radius: 24px;
  background: #f6f7f8;
  border: 1px solid rgba(15, 23, 42, 0.04);
  overflow: hidden;
  line-height: 1.68;
  word-break: break-word;
}

.message-row.user.jump-targeted .message-bubble {
  border-color: rgba(16, 163, 127, 0.24);
  background: #ffffff;
  box-shadow: 0 0 0 4px rgba(16, 163, 127, 0.12), 0 16px 34px rgba(15, 23, 42, 0.08);
  animation: jump-target-flash 1.45s var(--ease-standard) both;
}

.message-row.error .message-bubble,
.message-bubble.message-error {
  border-color: rgba(209, 67, 67, 0.24);
  background: rgba(209, 67, 67, 0.06);
}

.message-bubble p:first-child,
.message-bubble h1:first-child,
.message-bubble h2:first-child,
.message-bubble h3:first-child,
.message-bubble ul:first-child,
.message-bubble ol:first-child,
.message-bubble pre:first-child,
.message-bubble blockquote:first-child {
  margin-top: 0;
}

.message-bubble p:last-child,
.message-bubble h1:last-child,
.message-bubble h2:last-child,
.message-bubble h3:last-child,
.message-bubble ul:last-child,
.message-bubble ol:last-child,
.message-bubble pre:last-child,
.message-bubble blockquote:last-child {
  margin-bottom: 0;
}

.message-bubble h1,
.message-bubble h2,
.message-bubble h3 {
  line-height: 1.22;
  letter-spacing: -0.028em;
}

.message-bubble h1 {
  font-size: 29px;
}

.message-bubble h2 {
  font-size: 23px;
}

.message-bubble h3 {
  font-size: 18px;
}

.message-bubble p,
.message-bubble li {
  line-height: 1.8;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.message-bubble blockquote,
.message-bubble td,
.message-bubble th,
.message-bubble .math-target,
.message-bubble .streaming-text,
.message-bubble .attachment-grid,
.message-bubble .source-section,
.message-bubble .source-list {
  min-width: 0;
  max-width: 100%;
}

.message-bubble strong {
  font-weight: 700;
}

.message-bubble ul,
.message-bubble ol {
  padding-left: 1.4rem;
}

.message-bubble blockquote {
  margin: 1rem 0;
  padding: 0.1rem 0 0.1rem 1rem;
  border-left: 3px solid rgba(15, 23, 42, 0.14);
  color: var(--muted);
}

.message-bubble hr {
  border: 0;
  border-top: 1px solid var(--line-strong);
  margin: 1.4rem 0;
}

.message-bubble pre {
  margin: 1rem 0;
  padding: 14px 16px;
  border-radius: 18px;
  overflow: auto;
  background: #151922;
  color: #f8fafc;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.04);
}

.message-bubble code {
  font-family: "IBM Plex Mono", "SFMono-Regular", Consolas, monospace;
  font-size: 0.94em;
}

.message-bubble pre code {
  background: transparent;
}

.message-bubble :not(pre) > code {
  border-radius: 8px;
  padding: 0.14rem 0.36rem;
  background: rgba(15, 23, 42, 0.07);
}

.message-bubble table {
  width: 100%;
  border-collapse: collapse;
  margin: 1rem 0;
}

.message-bubble th,
.message-bubble td {
  padding: 10px 12px;
  border: 1px solid var(--line);
  text-align: left;
}

.message-bubble img {
  max-width: 100%;
  display: block;
  border-radius: 16px;
}

.message-bubble sub,
.message-bubble sup {
  line-height: 0;
}

.message-bubble .math-target {
  overflow-x: clip;
}

.math-fragment.math-display {
  display: block;
  overflow-x: auto;
  overflow-y: hidden;
}

.mjx-container {
  overflow-x: auto;
  overflow-y: hidden;
  max-width: 100%;
  padding-bottom: 2px;
}

.mjx-container[jax="CHTML"][display="true"] {
  margin: 1.05rem 0;
  padding: 0.15rem 0 0.35rem;
}

.mjx-container[jax="CHTML"][display="true"] mjx-math {
  white-space: nowrap;
}

.streaming-text {
  white-space: pre-wrap;
  word-break: break-word;
  min-height: 1.8em;
}

.streaming-text > :first-child {
  margin-top: 0;
}

.streaming-text > :last-child {
  margin-bottom: 0;
}

.streaming-cursor::after {
  content: "";
  display: inline-block;
  width: 0.56em;
  height: 1em;
  margin-left: 2px;
  vertical-align: -0.12em;
  border-radius: 999px;
  background: var(--accent);
  animation: blink 1.15s steps(2, start) infinite;
}

.attachment-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

.attachment-card {
  position: relative;
  border-radius: 16px;
  overflow: hidden;
  border: 1px solid var(--line);
  background: rgba(15, 23, 42, 0.04);
}

.attachment-card img {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
}

.attachment-caption {
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: 10px;
  padding: 6px 8px;
  border-radius: 10px;
  background: rgba(15, 23, 42, 0.74);
  color: #fff;
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.source-section {
  display: grid;
  gap: 8px;
  margin-top: 16px;
}

.source-header {
  display: flex;
  align-items: center;
  gap: 8px;
}

.source-heading {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
}

.source-summary {
  font-size: 12px;
  color: var(--muted);
}

.source-index {
  display: inline-grid;
  place-items: center;
  width: 18px;
  height: 18px;
  border-radius: 999px;
  border: 1px solid rgba(15, 23, 42, 0.08);
  background: rgba(255, 255, 255, 0.82);
  color: var(--subtle);
  font-size: 10px;
  line-height: 1;
}

.source-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(176px, 1fr));
  gap: 8px;
  overflow: visible;
  padding-bottom: 2px;
}

.source-list::-webkit-scrollbar {
  display: none;
}

.source-item {
  min-height: 98px;
  display: grid;
  align-content: start;
  gap: 6px;
  padding: 12px;
  border-radius: 16px;
  border: 1px solid rgba(15, 23, 42, 0.07);
  background: #fbfbfb;
  color: var(--text);
  text-decoration: none;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.03);
  transition: border-color 180ms ease, transform 180ms var(--ease-standard), background 180ms ease, box-shadow 180ms ease;
}

.source-item:visited {
  color: var(--text);
}

.source-item:hover {
  transform: translateY(-1px);
  border-color: rgba(15, 23, 42, 0.12);
  background: #fff;
  box-shadow: 0 8px 18px rgba(15, 23, 42, 0.06);
}

.source-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.source-domain {
  min-width: 0;
  flex: 1 1 auto;
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  letter-spacing: 0.01em;
}

.source-arrow {
  color: var(--subtle);
  font-size: 12px;
}

.source-title {
  font-size: 13px;
  font-weight: 600;
  line-height: 1.42;
  color: var(--text);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.source-snippet {
  font-size: 11px;
  color: var(--muted);
  line-height: 1.52;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.composer-shell {
  position: relative;
  z-index: 10;
  padding: 10px 18px calc(12px + env(safe-area-inset-bottom) + var(--keyboard-offset));
  background: linear-gradient(180deg, rgba(255, 255, 255, 0), rgba(255, 255, 255, 0.94) 24%, rgba(255, 255, 255, 0.985) 58%);
  transition: padding-bottom 180ms ease, transform 180ms ease;
}

.pending-attachments {
  width: min(100%, var(--composer-width));
  margin: 0 auto 10px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(92px, 1fr));
  gap: 8px;
}

.pending-chip {
  position: relative;
  border-radius: 16px;
  overflow: hidden;
  border: 1px solid var(--line);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

.pending-chip img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  display: block;
}

.pending-chip button {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 24px;
  height: 24px;
  border: none;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.76);
  color: #fff;
  cursor: pointer;
}

.pending-chip span {
  display: block;
  padding: 7px 10px;
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.composer-card {
  width: min(100%, var(--composer-width));
  margin: 0 auto;
  padding: 9px 10px 8px;
  border-radius: 26px;
  border: 1px solid rgba(15, 23, 42, 0.08);
  background: rgba(255, 255, 255, 0.98);
  box-shadow: 0 12px 34px rgba(15, 23, 42, 0.06), 0 1px 0 rgba(255, 255, 255, 0.7) inset;
  transition: border-color 180ms ease, box-shadow 180ms ease, transform 180ms var(--ease-standard);
}

.composer-card:focus-within {
  border-color: rgba(15, 23, 42, 0.12);
  box-shadow: 0 16px 40px rgba(15, 23, 42, 0.08), 0 1px 0 rgba(255, 255, 255, 0.78) inset;
}

.composer-form {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
}

.composer-input {
  min-height: 24px;
  max-height: 180px;
  padding: 9px 0;
  resize: none;
  border: none;
  background: transparent;
  color: var(--text);
  line-height: 1.58;
}

.composer-input::placeholder {
  color: var(--subtle);
}

.icon-btn,
.new-chat-btn,
.soft-btn,
.tool-chip,
.primary-btn,
.option-btn {
  border: 1px solid var(--line);
  background: var(--surface);
  cursor: pointer;
  transition: transform 180ms var(--ease-standard), border-color 180ms ease, background 180ms ease, opacity 160ms ease, box-shadow 180ms ease;
}

.icon-btn:hover,
.new-chat-btn:hover,
.soft-btn:hover,
.tool-chip:hover,
.primary-btn:hover,
.option-btn:hover {
  transform: translateY(-1px);
  border-color: rgba(16, 163, 127, 0.16);
}

.icon-btn {
  width: 42px;
  height: 42px;
  display: inline-grid;
  place-items: center;
  border-radius: 999px;
  font-size: 20px;
}

.attach-btn {
  background: var(--surface-soft);
}

.new-chat-btn {
  width: 100%;
  min-height: 46px;
  padding: 0 16px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.78);
  font-weight: 600;
}

.sidebar-filter-btn {
  width: calc(100% - 18px);
  margin: 0 auto;
  min-height: 36px;
  padding: 0 12px;
  border-radius: 14px;
  border: 1px solid rgba(15, 23, 42, 0.06);
  background: rgba(255, 255, 255, 0.52);
  color: var(--muted);
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 620;
  line-height: 1.2;
  cursor: pointer;
  transition: transform 180ms var(--ease-standard), border-color 180ms ease, background 180ms ease, color 180ms ease, box-shadow 180ms ease;
}

.sidebar-filter-btn > span:first-child {
  grid-column: 2;
  text-align: center;
  white-space: nowrap;
}

.sidebar-filter-btn:hover {
  transform: translateY(-1px);
  border-color: rgba(15, 23, 42, 0.08);
  background: rgba(255, 255, 255, 0.9);
}

.sidebar-filter-btn.active {
  border-color: rgba(15, 23, 42, 0.1);
  background: #ffffff;
  color: var(--text);
  box-shadow: 0 4px 14px rgba(15, 23, 42, 0.05);
}

.sidebar-filter-count {
  grid-column: 3;
  justify-self: end;
  min-width: 22px;
  height: 22px;
  padding: 0 7px;
  display: inline-grid;
  place-items: center;
  border-radius: 999px;
  background: #f3f4f6;
  color: var(--muted);
  font-size: 11.5px;
  line-height: 1;
}

.soft-btn {
  min-height: 38px;
  padding: 0 14px;
  border-radius: 999px;
  background: var(--surface);
}

.primary-btn {
  border-color: transparent;
  background: #202123;
  color: #fff;
  font-weight: 700;
}

.send-btn {
  width: 38px;
  height: 38px;
  min-width: 38px;
  padding: 0;
  border-radius: 999px;
  font-size: 20px;
  line-height: 1;
}

.composer-toolbar {
  position: relative;
  margin-top: 6px;
}

.toolbar-scroll {
  display: flex;
  align-items: center;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
  padding-bottom: 2px;
}

.tool-chip {
  min-height: 30px;
  padding: 0 10px;
  border-radius: 999px;
  background: #f7f7f8;
  color: #4b5563;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
  flex: 0 0 auto;
  font-size: 12.5px;
}

.tool-chip.active {
  border-color: rgba(15, 23, 42, 0.1);
  background: #ffffff;
  color: var(--text);
}

.chip-caret {
  display: none;
}

.inline-panel {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(100% + 10px);
  display: grid;
  gap: 10px;
  padding: 11px;
  border-radius: 20px;
  border: 1px solid rgba(15, 23, 42, 0.08);
  background: rgba(255, 255, 255, 0.98);
  box-shadow: 0 18px 44px rgba(15, 23, 42, 0.08);
  backdrop-filter: blur(18px);
  transform-origin: bottom center;
  animation: panel-in 180ms var(--ease-standard) both;
  z-index: 25;
}

.option-section {
  display: grid;
  gap: 6px;
}

.option-label,
.panel-field > span {
  font-size: 12px;
  color: var(--muted);
}

.option-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.option-grid-compact .option-btn {
  min-width: 86px;
}

.option-btn {
  min-height: 36px;
  padding: 0 13px;
  border-radius: 999px;
  background: #f7f7f8;
  color: var(--text);
}

.option-btn.active {
  border-color: rgba(15, 23, 42, 0.1);
  background: #ffffff;
}

.option-grid-muted .option-btn {
  color: var(--muted);
}

.balance-panel {
  gap: 12px;
}

.balance-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.balance-refresh-btn {
  min-height: 32px;
  padding: 0 12px;
  border-radius: 999px;
  background: #f7f7f8;
  font-size: 13px;
}

.balance-summary {
  display: grid;
  gap: 10px;
}

.balance-empty,
.balance-note {
  font-size: 13px;
  color: var(--muted);
  line-height: 1.65;
}

.balance-error {
  color: var(--danger);
}

.balance-hero {
  display: grid;
  gap: 4px;
  padding: 14px 16px;
  border-radius: 18px;
  border: 1px solid rgba(15, 23, 42, 0.06);
  background: linear-gradient(180deg, #fbfbfb 0%, #ffffff 100%);
}

.balance-hero-label {
  font-size: 12px;
  color: var(--muted);
}

.balance-hero-value {
  font-size: clamp(22px, 2.8vw, 28px);
  font-weight: 650;
  letter-spacing: -0.04em;
}

.balance-hero-value-muted {
  color: var(--muted);
}

.balance-hero-note {
  font-size: 12px;
  color: var(--muted);
}

.balance-stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.balance-stat {
  display: grid;
  gap: 3px;
  padding: 11px 12px;
  border-radius: 16px;
  background: #f7f7f8;
}

.balance-stat span {
  font-size: 12px;
  color: var(--muted);
}

.balance-stat strong {
  font-size: 14px;
  line-height: 1.35;
}

.panel-field {
  display: grid;
  gap: 6px;
}

.prompt-textarea,
.auth-input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
  color: var(--text);
}

.prompt-textarea {
  min-height: 104px;
  padding: 12px 14px;
  resize: vertical;
  line-height: 1.7;
}

.panel-actions {
  display: flex;
  justify-content: flex-end;
}

.primary-btn:disabled,
.icon-btn:disabled,
.soft-btn:disabled,
.tool-chip:disabled,
.option-btn:disabled {
  opacity: 0.54;
  cursor: not-allowed;
  transform: none;
}

.auth-gate,
.sidebar-scrim {
  position: fixed;
  inset: 0;
}

.auth-gate {
  display: grid;
  place-items: center;
  background: rgba(15, 23, 42, 0.34);
  backdrop-filter: blur(14px);
  z-index: 60;
}

.auth-card {
  width: min(92vw, 460px);
  border-radius: 30px;
  border: 1px solid rgba(255, 255, 255, 0.5);
  background: rgba(255, 255, 255, 0.96);
  box-shadow: var(--shadow-lg);
  padding: 28px;
}

.auth-kicker {
  color: var(--accent);
  font-size: 12px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.auth-card h1 {
  margin: 12px 0 10px;
  font-size: 30px;
  line-height: 1.05;
  letter-spacing: -0.04em;
}

.auth-card p {
  margin: 0 0 18px;
  color: var(--muted);
  line-height: 1.7;
}

.auth-input {
  padding: 14px 16px;
}

.auth-submit {
  width: 100%;
  min-height: 46px;
  margin-top: 12px;
  border-radius: 16px;
}

.auth-error {
  min-height: 1.5em;
  margin-top: 12px;
  color: var(--danger);
  font-size: 13px;
}

.toast-stack {
  position: fixed;
  right: 18px;
  bottom: calc(18px + env(safe-area-inset-bottom));
  display: grid;
  gap: 10px;
  z-index: 80;
}

.toast {
  min-width: min(86vw, 260px);
  max-width: min(86vw, 320px);
  padding: 12px 14px;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.96);
  box-shadow: var(--shadow-md);
  color: var(--text);
  animation: toast-in 180ms ease both;
}

.toast.error {
  border-color: rgba(209, 67, 67, 0.18);
}

.sidebar-scrim {
  background: rgba(15, 23, 42, 0.28);
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease;
  z-index: 45;
}

body.mobile-sidebar-open .sidebar-scrim {
  opacity: 1;
  pointer-events: auto;
}

body.mobile-empty-focus .thread-scroll {
  overflow: hidden;
  background: #fff;
}

body.mobile-empty-focus .thread-inner {
  min-height: 0;
}

body.mobile-empty-focus .empty-state,
body.mobile-empty-focus .empty-state-inner {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

body.mobile-empty-focus .workspace-header,
body.mobile-empty-focus .composer-shell {
  background: #fff;
}

body.mobile-empty-focus .workspace-header {
  backdrop-filter: none;
}

body.mobile-empty-focus .composer-card {
  box-shadow: none;
  border-color: rgba(15, 23, 42, 0.06);
}

.sidebar-close-btn {
  display: none;
}

@keyframes blink {
  50% {
    opacity: 0;
  }
}

@keyframes message-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes panel-in {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.985);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes jump-target-flash {
  0% {
    transform: translateY(4px);
    box-shadow: 0 0 0 0 rgba(16, 163, 127, 0), 0 10px 22px rgba(15, 23, 42, 0.02);
  }
  40% {
    transform: translateY(0);
  }
  100% {
    transform: translateY(0);
    box-shadow: 0 0 0 0 rgba(16, 163, 127, 0), 0 16px 34px rgba(15, 23, 42, 0.08);
  }
}

@media (max-width: 900px) {
  .workspace,
  .thread-scroll,
  .thread-inner,
  .message-list,
  .message-row,
  .message-bubble,
  .message-bubble > * {
    min-width: 0;
    max-width: 100%;
  }

  .sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 50;
    width: min(80vw, 320px);
    flex-basis: min(80vw, 320px);
    box-shadow: var(--shadow-lg);
    transform: translateX(-102%);
    opacity: 1;
  }

  body.mobile-sidebar-open .sidebar {
    transform: translateX(0);
  }

  body.sidebar-collapsed .sidebar,
  html.preload-sidebar-collapsed .sidebar {
    width: min(80vw, 320px);
    flex-basis: min(80vw, 320px);
    padding: 14px 12px 12px;
    border-right-width: 1px;
    opacity: 1;
  }

  .sidebar-close-btn {
    display: inline-grid;
  }

  .workspace-header {
    padding: 10px 14px;
  }

  .thread-inner {
    width: 100%;
    padding: 18px 14px 24px;
  }

  .empty-state-inner {
    padding-bottom: 112px;
  }

  .message-list {
    padding-bottom: 84px;
  }

  .message-row.user .message-bubble {
    width: fit-content;
    max-width: min(100%, 92%);
  }

  .message-bubble {
    overflow-x: clip;
  }

  .message-bubble pre {
    width: 100%;
    max-width: 100%;
    white-space: pre-wrap;
    word-break: break-word;
    overflow-wrap: anywhere;
    overflow-x: hidden;
  }

  .message-bubble table {
    width: 100%;
    table-layout: fixed;
  }

  .message-bubble th,
  .message-bubble td {
    white-space: normal;
    word-break: break-word;
    overflow-wrap: anywhere;
  }

  .attachment-grid {
    grid-template-columns: repeat(auto-fit, minmax(132px, 1fr));
  }

  .source-list {
    grid-template-columns: none;
    grid-auto-flow: column;
    grid-auto-columns: minmax(214px, min(78vw, 320px));
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scrollbar-width: none;
  }

  .jump-nav-dock {
    top: auto;
    right: calc(10px + env(safe-area-inset-right));
    bottom: calc(122px + env(safe-area-inset-bottom) + var(--keyboard-offset));
    width: min(360px, calc(100vw - 20px));
  }

  .jump-nav-btn,
  .jump-nav-panel {
    top: auto;
    bottom: 0;
    transform: none;
  }

  .jump-nav-btn:hover {
    transform: translateY(-1px);
  }

  .jump-nav-panel {
    max-height: min(44svh, 318px);
    border-radius: 22px;
  }

  .jump-nav-list {
    max-height: calc(60px * 3 + 16px);
  }

  .composer-shell {
    padding: 8px 10px calc(10px + env(safe-area-inset-bottom) + var(--keyboard-offset));
  }

  .composer-card {
    width: 100%;
    padding: 8px;
    border-radius: 22px;
  }

  .composer-card:focus-within {
    box-shadow: 0 10px 26px rgba(15, 23, 42, 0.05);
    transform: none;
  }

  .inline-panel {
    bottom: calc(100% + 8px);
    padding: 10px;
    border-radius: 18px;
    max-height: min(46svh, 320px);
    overflow-y: auto;
  }
}

@media (max-width: 640px) {
  .workspace-header {
    min-height: 56px;
  }

  .header-title {
    font-size: 17px;
  }

  .thread-inner {
    padding: 16px 12px 20px;
  }

  .jump-nav-dock {
    left: 10px;
    right: 10px;
    bottom: calc(128px + env(safe-area-inset-bottom) + var(--keyboard-offset));
    width: auto;
  }

  .jump-nav-btn {
    min-height: 38px;
    padding: 0 10px 0 12px;
  }

  .jump-nav-panel {
    width: 100%;
    max-height: min(42svh, 300px);
    padding: 11px;
  }

  .jump-nav-search {
    min-height: 36px;
  }

  .jump-nav-item {
    min-height: 60px;
    max-height: 60px;
    padding: 9px 10px 10px;
    border-radius: 16px;
    gap: 5px;
    overflow: hidden;
  }

  .jump-nav-item-preview {
    -webkit-line-clamp: 1;
    font-size: 12px;
    line-height: 1.5;
  }

  body.mobile-empty-focus .thread-inner {
    padding-top: 0;
    padding-bottom: 0;
  }

  .empty-state-inner {
    width: min(calc(100vw - 28px), 560px);
    padding: 0 14px 118px;
  }

  .empty-state h1 {
    font-size: 32px;
    line-height: 1.08;
  }

  .empty-state p {
    font-size: 15px;
  }

  .message-list {
    gap: 22px;
    padding-bottom: 76px;
  }

  .message-row.assistant .message-bubble {
    font-size: 15px;
  }

  .message-row.user .message-bubble {
    width: fit-content;
    max-width: min(100%, 94%);
    padding: 12px 14px;
    border-radius: 22px;
  }

  .message-bubble h1 {
    font-size: 24px;
  }

  .message-bubble h2 {
    font-size: 21px;
  }

  .message-bubble h3 {
    font-size: 18px;
  }

  .icon-btn {
    width: 38px;
    height: 38px;
  }

  .composer-form {
    gap: 8px;
  }

  .composer-input {
    padding: 7px 0;
  }

  .tool-chip {
    min-height: 28px;
    padding: 0 8px;
    gap: 4px;
    font-size: 12px;
    border-radius: 999px;
  }

  .option-btn {
    min-height: 34px;
    padding: 0 11px;
  }

  .balance-stats {
    grid-template-columns: 1fr;
  }

  .prompt-textarea {
    min-height: 92px;
  }

  .toast-stack {
    left: 12px;
    right: 12px;
    bottom: calc(12px + env(safe-area-inset-bottom));
  }

  .toast {
    min-width: 0;
    max-width: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
  }
}
