:root {
  --chat-bg: #faf9f7;
  --chat-surface: #ffffff;
  --chat-ink: #111111;
  --chat-muted: #f1f0ed;
  --chat-border: #e7e5e4;
  --chat-soft: rgba(17, 17, 17, 0.06);
}

html[data-theme='dark'] {
  --chat-bg: #0b0f14;
  --chat-surface: #131a24;
  --chat-ink: #e6edf3;
  --chat-muted: #1a2330;
  --chat-border: #2b3440;
  --chat-soft: rgba(230, 237, 243, 0.08);
}

body {
  background-color: var(--chat-bg);
  background-image: radial-gradient(circle at 20% 10%, rgba(17, 17, 17, 0.04), transparent 50%),
    radial-gradient(circle at 85% 0%, rgba(17, 17, 17, 0.03), transparent 50%);
}

.chat-main {
  padding-bottom: 16px;
}

.chat-shell {
  display: flex;
  flex-direction: column;
  gap: 20px;
  min-height: calc(100vh - 56px - 64px);
}

.chat-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.chat-title-text {
  font-size: 24px;
  font-weight: 600;
  color: var(--chat-ink);
}

.chat-subtitle {
  font-size: 12px;
  color: var(--accents-4);
  margin-top: 4px;
}

.status-text {
  font-size: 12px;
  color: var(--accents-4);
  padding: 6px 10px;
  border-radius: 999px;
  background: var(--chat-muted);
}

.status-text.connected {
  color: #0f766e;
  background: rgba(15, 118, 110, 0.12);
}

.status-text.connecting {
  color: #b45309;
  background: rgba(217, 119, 6, 0.14);
}

.status-text.error {
  color: #b91c1c;
  background: rgba(185, 28, 28, 0.12);
}

.chat-thread {
  display: flex;
  flex-direction: column;
  gap: 18px;
  min-height: 320px;
  padding-bottom: 12px;
  flex: 1;
}

.chat-empty {
  text-align: center;
  color: var(--accents-4);
  font-size: 13px;
  padding: 48px 0;
}

.message-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.message-row.user {
  align-items: flex-end;
}

.message-row.assistant {
  align-items: flex-start;
  width: 100%;
}

.message-actions {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--accents-4);
  font-size: 12px;
  margin-left: 2px;
}

.action-btn {
  border: none;
  background: transparent;
  color: var(--accents-4);
  font-size: 12px;
  padding: 4px 6px;
  border-radius: 999px;
  cursor: pointer;
  transition: color 0.2s ease, background 0.2s ease;
}

.action-btn:hover {
  color: var(--chat-ink);
  background: rgba(17, 17, 17, 0.06);
}

.message-bubble {
  max-width: 100%;
  font-size: 14px;
  line-height: 1.6;
  color: var(--chat-ink);
  width: 100%;
}

.message-row.user .message-bubble {
  max-width: min(720px, 100%);
  width: auto;
}

.message-row.assistant .message-content {
  width: 100%;
}

.message-row.user .message-bubble {
  background: transparent;
  padding: 0;
  border-radius: 0;
  border: none;
}

.message-row.user .message-content.user-rendered {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
}

.user-text-bubble {
  background: var(--chat-muted);
  border: 1px solid var(--chat-border);
  border-radius: 20px;
  padding: 8px 14px;
  max-width: 100%;
  line-height: 1.35;
}

.user-text-bubble p {
  margin: 0;
}

.user-media-row {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
  max-width: 100%;
}

.user-image-btn {
  width: 72px;
  height: 72px;
  border: 1px solid var(--chat-border);
  border-radius: 16px;
  padding: 0;
  overflow: hidden;
  background: var(--chat-surface);
  cursor: zoom-in;
}

.user-image-btn img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  max-width: none;
  max-height: none;
  margin: 0;
  border: none;
  border-radius: 0;
}

.user-file-row {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
  max-width: 100%;
}

.user-file-chip {
  display: inline-flex;
  align-items: center;
  max-width: 240px;
  height: 30px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid var(--chat-border);
  background: var(--chat-surface);
  color: var(--chat-ink);
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.message-row.assistant .message-bubble {
  background: transparent;
  padding: 0;
}

.message-content.rendered img {
  max-width: min(420px, 100%);
  max-height: 320px;
  border-radius: 12px;
  margin-top: 12px;
  border: 1px solid var(--chat-border);
  cursor: zoom-in;
}

.message-content.rendered a {
  color: inherit;
  text-decoration: underline;
}

.message-content.rendered .inline-code {
  background: var(--chat-muted);
  border: 1px solid var(--chat-border);
  border-radius: 6px;
  padding: 2px 6px;
  font-size: 12px;
  font-family: 'Geist Mono', monospace;
}

.message-content.rendered .code-block {
  background: var(--chat-muted);
  border: 1px solid var(--chat-border);
  border-radius: 12px;
  padding: 12px 14px;
  overflow-x: auto;
  margin-top: 12px;
  font-size: 12px;
  font-family: 'Geist Mono', monospace;
}

.message-content.rendered .code-block code {
  font-family: 'Geist Mono', monospace;
  white-space: pre-wrap;
}

.code-block-wrap {
  position: relative;
  margin-top: 12px;
}

.code-block-wrap .code-block {
  margin-top: 0;
}

.code-copy-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  border: 1px solid var(--chat-border);
  background: var(--chat-surface);
  color: var(--chat-ink);
  border-radius: 8px;
  padding: 2px 8px;
  font-size: 12px;
  line-height: 1.4;
  cursor: pointer;
}

.code-copy-btn:hover {
  border-color: var(--accents-5);
}

.message-content.rendered h1,
.message-content.rendered h2,
.message-content.rendered h3,
.message-content.rendered h4,
.message-content.rendered h5,
.message-content.rendered h6 {
  font-weight: 600;
  margin: 10px 0 6px;
  line-height: 1.3;
}

.message-content.rendered h1 { font-size: 20px; }
.message-content.rendered h2 { font-size: 18px; }
.message-content.rendered h3 { font-size: 16px; }
.message-content.rendered h4 { font-size: 15px; }
.message-content.rendered h5 { font-size: 14px; }
.message-content.rendered h6 { font-size: 13px; }

.message-content.rendered p {
  margin: 6px 0;
}

.message-content.rendered ul,
.message-content.rendered ol {
  margin: 6px 0 10px;
  padding-left: 20px;
}

.message-content.rendered li {
  margin: 4px 0;
}

.message-content.rendered .table-wrap {
  overflow-x: auto;
  margin: 10px 0;
}

.message-content.rendered table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.message-content.rendered th,
.message-content.rendered td {
  border: 1px solid var(--chat-border);
  padding: 6px 8px;
  text-align: left;
}

.message-content.rendered th {
  background: var(--chat-muted);
  font-weight: 600;
}

.think-block {
  margin-top: 10px;
  margin-bottom: 16px;
  border: none;
  padding: 0;
  background: transparent;
  width: 100%;
}

.think-summary {
  cursor: pointer;
  font-size: 12px;
  color: var(--accents-4);
  list-style: none;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.think-summary::before {
  content: "";
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: conic-gradient(from 180deg, #f59e0b, #f97316, #22c55e, #0ea5e9, #f59e0b);
  border: 1px solid #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(17, 17, 17, 0.15);
}

.think-summary::after {
  content: "";
  width: 6px;
  height: 6px;
  border-right: 2px solid var(--accents-4);
  border-bottom: 2px solid var(--accents-4);
  transform: rotate(45deg);
  margin-left: 2px;
}

.think-block[open] .think-summary::after {
  transform: rotate(225deg);
}

.think-summary::-webkit-details-marker {
  display: none;
}

.think-content {
  margin-top: 8px;
  margin-left: 0;
  padding-left: 0;
  border-left: none;
  font-size: 12px;
  color: var(--accents-5);
  line-height: 1.6;
  max-height: 0;
  opacity: 0;
  overflow: hidden;
  transition: max-height 0.25s ease, opacity 0.25s ease;
}

.think-block[open] .think-content {
  max-height: none;
  opacity: 1;
  overflow: visible;
  padding-right: 0;
}

.img-grid {
  display: grid;
  gap: 2px;
  margin: 12px 0;
  grid-template-columns: repeat(var(--cols, 4), minmax(0, 1fr));
  width: 100%;
  max-width: 100%;
  justify-items: stretch;
}

.img-grid > * {
  display: block;
  width: 100%;
}

.message-content.rendered .img-grid img {
  width: 100%;
  height: auto;
  display: block;
  max-width: 100%;
  max-height: none;
  margin: 0;
  border-radius: 12px;
  border: 1px solid var(--chat-border);
  background: transparent;
}

.img-retry {
  width: 100%;
  min-height: 120px;
  border: 1px dashed var(--chat-border);
  border-radius: 12px;
  background: var(--chat-surface);
  color: var(--accents-4);
  font-size: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: color 0.2s ease, border-color 0.2s ease;
}

.img-retry:hover {
  color: var(--chat-ink);
  border-color: #111;
}

.think-agents {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
}

.think-agent {
  border: 1px solid var(--chat-border);
  background: var(--chat-surface);
  border-radius: 12px;
  padding: 8px 10px 10px;
  width: 100%;
}

.think-agent summary {
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  color: var(--chat-ink);
  list-style: none;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 4px 8px;
  border-radius: 999px;
  background: transparent;
  width: auto;
  max-width: 100%;
}

.think-agent summary::before {
  content: "";
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: conic-gradient(from 180deg, #f59e0b, #f97316, #22c55e, #0ea5e9, #f59e0b);
  border: 1px solid #fff;
  box-shadow: 0 2px 8px rgba(17, 17, 17, 0.15);
}

.think-agent summary::after {
  content: "";
  width: 6px;
  height: 6px;
  border-right: 2px solid var(--accents-4);
  border-bottom: 2px solid var(--accents-4);
  transform: rotate(45deg);
  margin-left: 2px;
}

.think-agent[open] summary::after {
  transform: rotate(225deg);
}

.think-agent summary::-webkit-details-marker {
  display: none;
}

@keyframes thinkGlow {
  0% {
    box-shadow: 0 0 0 rgba(17, 17, 17, 0);
    background: transparent;
  }
  50% {
    box-shadow: 0 0 0 2px rgba(14, 165, 233, 0.14);
    background: rgba(14, 165, 233, 0.08);
  }
  100% {
    box-shadow: 0 0 0 rgba(17, 17, 17, 0);
    background: transparent;
  }
}

.think-block[data-thinking="true"] .think-agent summary {
  animation: thinkGlow 1.4s ease-in-out infinite;
}

.think-agent-items {
  margin-top: 10px;
  margin-left: 0;
  padding-left: 2px;
  padding-right: 2px;
  border-left: none;
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
}

.think-agent[open] .think-agent-items {
  max-height: 36vh;
  overflow: auto;
  overscroll-behavior: contain;
  padding-right: 4px;
}

.think-rollout-group {
  border: 1px solid var(--chat-border);
  border-radius: 14px;
  padding: 8px 12px;
  background: var(--chat-surface);
  width: 100%;
}

.think-rollout-group summary {
  cursor: pointer;
  font-size: 12px;
  color: var(--chat-ink);
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
}

.think-rollout-group summary::-webkit-details-marker {
  display: none;
}

.think-rollout-group summary::after {
  content: "";
  width: 6px;
  height: 6px;
  border-right: 2px solid var(--accents-4);
  border-bottom: 2px solid var(--accents-4);
  transform: rotate(45deg);
  transition: transform 0.2s ease;
}

.think-rollout-group[open] summary::after {
  transform: rotate(225deg);
}

.think-rollout-title {
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.think-rollout-title::before {
  content: "";
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: conic-gradient(from 180deg, #f59e0b, #f97316, #22c55e, #0ea5e9, #f59e0b);
  border: 1px solid #fff;
  box-shadow: 0 2px 8px rgba(17, 17, 17, 0.15);
}

.think-rollout-body {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.think-item-row {
  border-left: none;
  padding: 8px 10px;
  border: 1px solid var(--chat-border);
  border-radius: 10px;
  background: rgba(17, 17, 17, 0.02);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.think-item-type {
  font-size: 12px;
  color: var(--accents-4);
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.think-item-type::before {
  content: "";
  width: 14px;
  height: 14px;
  background-color: var(--accents-4);
  mask-image: url("data:image/svg+xml;base64,PHN2ZyB4bWxucz0naHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmcnIHZpZXdCb3g9JzAgMCAyNCAyNCcgZmlsbD0nYmxhY2snPjxwYXRoIGQ9J005IDIxaDZ2LTFIOXYxem0zLTIwYTcgNyAwIDAwLTQgMTIuNzRWMTdhMSAxIDAgMDAxIDFoNmExIDEgMCAwMDEtMXYtMy4yNkE3IDcgMCAwMDEyIDF6Jy8+PC9zdmc+");
  mask-size: contain;
  mask-repeat: no-repeat;
  mask-position: center;
  -webkit-mask-image: url("data:image/svg+xml;base64,PHN2ZyB4bWxucz0naHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmcnIHZpZXdCb3g9JzAgMCAyNCAyNCcgZmlsbD0nYmxhY2snPjxwYXRoIGQ9J005IDIxaDZ2LTFIOXYxem0zLTIwYTcgNyAwIDAwLTQgMTIuNzRWMTdhMSAxIDAgMDAxIDFoNmExIDEgMCAwMDEtMXYtMy4yNkE3IDcgMCAwMDEyIDF6Jy8+PC9zdmc+");
  -webkit-mask-size: contain;
  -webkit-mask-repeat: no-repeat;
  -webkit-mask-position: center;
}

.think-item-type[data-type="websearch"]::before {
  mask-image: url("data:image/svg+xml;base64,PHN2ZyB4bWxucz0naHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmcnIHZpZXdCb3g9JzAgMCAyMCAyMCcgZmlsbD0nYmxhY2snPjxwYXRoIGZpbGwtcnVsZT0nZXZlbm9kZCcgZD0nTTkgM2E2IDYgMCAxMDQuNDcyIDEwLjAxNmwzLjI1NiAzLjI1NmExIDEgMCAwMDEuNDE2LTEuNDE2bC0zLjI1Ni0zLjI1NkE2IDYgMCAwMDkgM3ptMCAyYTQgNCAwIDEwMCA4IDQgNCAwIDAwMC04eicgY2xpcC1ydWxlPSdldmVub2RkJy8+PC9zdmc+");
  -webkit-mask-image: url("data:image/svg+xml;base64,PHN2ZyB4bWxucz0naHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmcnIHZpZXdCb3g9JzAgMCAyMCAyMCcgZmlsbD0nYmxhY2snPjxwYXRoIGZpbGwtcnVsZT0nZXZlbm9kZCcgZD0nTTkgM2E2IDYgMCAxMDQuNDcyIDEwLjAxNmwzLjI1NiAzLjI1NmExIDEgMCAwMDEuNDE2LTEuNDE2bC0zLjI1Ni0zLjI1NkE2IDYgMCAwMDkgM3ptMCAyYTQgNCAwIDEwMCA4IDQgNCAwIDAwMC04eicgY2xpcC1ydWxlPSdldmVub2RkJy8+PC9zdmc+");
}

.think-item-type[data-type="agentthink"]::before {
  mask-image: url("data:image/svg+xml;base64,PHN2ZyB4bWxucz0naHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmcnIHZpZXdCb3g9JzAgMCAyNCAyNCcgZmlsbD0nYmxhY2snPjxwYXRoIGQ9J00xMSAyaDJ2MmgtMnonLz48cGF0aCBkPSdNNyA2aDEwYTMgMyAwIDAxMyAzdjhhMyAzIDAgMDEtMyAzSDdhMyAzIDAgMDEtMy0zVjlhMyAzIDAgMDEzLTN6bTIgNWExLjUgMS41IDAgMTAwIDMgMS41IDEuNSAwIDAwMC0zem02IDBhMS41IDEuNSAwIDEwMCAzIDEuNSAxLjUgMCAwMDAtM3onLz48cGF0aCBkPSdNNCAxMGgydjRINHonLz48cGF0aCBkPSdNMTggMTBoMnY0aC0yeicvPjwvc3ZnPg==");
  -webkit-mask-image: url("data:image/svg+xml;base64,PHN2ZyB4bWxucz0naHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmcnIHZpZXdCb3g9JzAgMCAyNCAyNCcgZmlsbD0nYmxhY2snPjxwYXRoIGQ9J00xMSAyaDJ2MmgtMnonLz48cGF0aCBkPSdNNyA2aDEwYTMgMyAwIDAxMyAzdjhhMyAzIDAgMDEtMyAzSDdhMyAzIDAgMDEtMy0zVjlhMyAzIDAgMDEzLTN6bTIgNWExLjUgMS41IDAgMTAwIDMgMS41IDEuNSAwIDAwMC0zem02IDBhMS41IDEuNSAwIDEwMCAzIDEuNSAxLjUgMCAwMDAtM3onLz48cGF0aCBkPSdNNCAxMGgydjRINHonLz48cGF0aCBkPSdNMTggMTBoMnY0aC0yeicvPjwvc3ZnPg==");
}

.think-item-body {
  font-size: 12px;
  color: var(--accents-5);
  line-height: 1.6;
}

html[data-theme='dark'] .think-agent {
  background: #101924;
  border-color: #273142;
}

html[data-theme='dark'] .think-agent summary {
  background: transparent;
}

html[data-theme='dark'] .think-item-row {
  background: #0f1824;
  border-color: #273142;
}

html[data-theme='dark'] .think-item-type {
  color: #9fb2c9;
}

html[data-theme='dark'] .think-item-body {
  color: #d5e0ee;
}

@keyframes thinkGlowDark {
  0% {
    box-shadow: 0 0 0 rgba(96, 165, 250, 0);
    background: transparent;
  }
  50% {
    box-shadow: 0 0 0 2px rgba(96, 165, 250, 0.2);
    background: rgba(96, 165, 250, 0.08);
  }
  100% {
    box-shadow: 0 0 0 rgba(96, 165, 250, 0);
    background: transparent;
  }
}

html[data-theme='dark'] .think-block[data-thinking="true"] .think-agent summary {
  animation: thinkGlowDark 1.6s ease-in-out infinite;
}

.composer-shell {
  position: sticky;
  bottom: 8px;
  background: transparent;
  backdrop-filter: none;
  padding: 0;
  border-radius: 0;
  border: none;
  box-shadow: none;
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: auto;
}

.composer-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 0;
}

.composer-bottom {
  display: flex;
  align-items: center;
  gap: 10px;
}

.composer-bottom .composer-input {
  flex: 1;
}

.composer-meta .model-chip {
  margin-left: auto;
  flex-shrink: 0;
}

.composer-input {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--chat-surface);
  border: 1px solid var(--chat-border);
  border-radius: 999px;
  padding: 10px 14px;
  box-shadow: 0 18px 32px rgba(17, 17, 17, 0.08);
}

.composer-input.drag-over {
  border-color: var(--accents-5);
  box-shadow: 0 0 0 2px var(--chat-soft);
}

.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--chat-border);
  background: var(--chat-surface);
  color: var(--chat-ink);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s ease, border 0.2s ease;
}

.icon-btn:hover {
  border-color: #111;
}

.file-input {
  display: none;
}

.composer-textarea {
  flex: 1;
  min-height: 40px;
  height: 40px;
  max-height: 160px;
  border: none;
  outline: none;
  resize: none;
  font-size: 14px;
  line-height: 1.4;
  padding: 10px 0;
  background: transparent;
  color: var(--chat-ink);
  overflow-y: auto;
}

.composer-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.model-chip {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 0;
  padding: 0;
  border-radius: 999px;
  border: 1px solid var(--chat-border);
  background: var(--chat-surface);
  height: 28px;
  min-width: 132px;
  max-width: 172px;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.model-chip:focus-within {
  border-color: var(--accents-5);
  box-shadow: 0 0 0 2px var(--chat-soft);
}

.model-picker-btn {
  width: 100%;
  height: 100%;
  border: none;
  background: transparent;
  color: var(--chat-ink);
  border-radius: 999px;
  padding: 0 10px;
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
}

.model-picker-label {
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.model-picker-arrow {
  flex-shrink: 0;
  transition: transform 0.2s ease;
}

.model-picker.open .model-picker-arrow {
  transform: rotate(180deg);
}

.model-picker-menu {
  position: absolute;
  bottom: calc(100% + 10px);
  left: 0;
  right: 0;
  max-height: 260px;
  overflow: auto;
  border-radius: 14px;
  border: 1px solid var(--chat-border);
  background: var(--chat-surface);
  box-shadow: 0 16px 34px rgba(17, 17, 17, 0.18);
  padding: 6px;
  z-index: 90;
  }

  .chat-sidebar .sidebar-header {
    padding-top: calc(12px + env(safe-area-inset-top, 0px));
  }

.model-option {
  width: 100%;
  border: none;
  background: transparent;
  color: var(--chat-ink);
  border-radius: 10px;
  text-align: left;
  padding: 8px 10px;
  font-size: 13px;
  line-height: 1.3;
  cursor: pointer;
}

.model-option:hover {
  background: var(--chat-muted);
}

.model-option.active {
  background: rgba(59, 130, 246, 0.2);
  color: var(--chat-ink);
}

.model-select-native {
  display: none;
}

html[data-theme='dark'] .model-chip {
  background: #101826;
  border-color: #2e3a4c;
}

html[data-theme='dark'] .model-picker-menu {
  background: #0f1724;
  border-color: #2e3a4c;
}

html[data-theme='dark'] .model-option:hover {
  background: #172233;
}

html[data-theme='dark'] .model-option.active {
  background: rgba(96, 165, 250, 0.28);
}

.send-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid #111;
  background: #111;
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.2s ease;
}

.send-btn:disabled {
  opacity: 0.5;
}

.send-btn.is-abort {
  background: #7f1d1d;
  border-color: #7f1d1d;
}

.send-btn.is-abort:hover {
  background: #991b1b;
  border-color: #991b1b;
}

.popover {
  position: relative;
}

.settings-panel {
  position: absolute;
  right: 0;
  bottom: calc(100% + 12px);
  min-width: 260px;
  max-width: 320px;
  background: var(--chat-surface);
  border: 1px solid var(--chat-border);
  border-radius: 14px;
  padding: 14px;
  box-shadow: 0 20px 40px rgba(17, 17, 17, 0.12);
  z-index: 20;
}

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

.settings-block {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.settings-block-full {
  grid-column: span 2;
}

.field-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accents-4);
}

.range-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.range-value {
  font-size: 12px;
  color: var(--accents-5);
  min-width: 40px;
  text-align: right;
}

.chat-input {
  min-height: 80px;
}

.file-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  max-width: 100%;
  min-height: 28px;
  flex-shrink: 0;
}

.file-badge-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 28px;
  max-width: 220px;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--chat-border);
  background: var(--chat-surface);
  color: var(--chat-ink);
  font-size: 12px;
}

.file-badge-item.is-image {
  cursor: zoom-in;
}

.file-preview {
  width: 20px;
  height: 20px;
  border-radius: 4px;
  object-fit: cover;
  border: 1px solid var(--chat-border);
  flex-shrink: 0;
  cursor: zoom-in;
}

.attachment-preview-overlay {
  position: fixed;
  inset: 0;
  z-index: 2000;
  background: rgba(0, 0, 0, 0.68);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.attachment-preview-image {
  max-width: min(92vw, 1200px);
  max-height: 88vh;
  width: auto;
  height: auto;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.45);
}

.chat-image-preview-overlay {
  position: fixed;
  inset: 0;
  z-index: 2100;
  background: rgba(0, 0, 0, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.chat-image-preview-image {
  max-width: min(92vw, 1200px);
  max-height: 88vh;
  width: auto;
  height: auto;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  box-shadow: 0 22px 56px rgba(0, 0, 0, 0.5);
}

.file-name {
  max-width: 140px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.file-remove {
  border: none;
  background: transparent;
  font-size: 14px;
  line-height: 1;
  color: var(--accents-4);
}

.file-remove:hover {
  color: var(--chat-ink);
}

.meta-btn {
  border: 1px solid var(--chat-border);
  background: var(--chat-surface);
  color: var(--chat-ink);
  font-size: 12px;
  padding: 6px 12px;
  border-radius: 999px;
  transition: border 0.2s ease;
}

.meta-btn:hover {
  border-color: #111;
}

@media (max-width: 720px) {
  .message-bubble {
    max-width: 100%;
  }

  .composer-meta {
    order: 1;
    align-items: center;
    justify-content: space-between;
  }

  .composer-bottom {
    order: 2;
    flex-direction: row;
    align-items: center;
    gap: 8px;
  }

  .composer-input {
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border-radius: 22px;
    order: 1;
  }

  .icon-btn,
  .send-btn {
    width: 34px;
    height: 34px;
    flex-shrink: 0;
  }

  .composer-textarea {
    min-width: 0;
    min-height: 36px;
    height: 36px;
    padding: 8px 0;
    font-size: 16px;
  }

  .composer-actions {
    gap: 6px;
    flex-shrink: 0;
  }

  .model-chip {
    height: 28px;
    width: auto;
    max-width: 52vw;
    min-width: 132px;
    order: 0;
  }

  .model-picker-btn {
    padding: 0 10px;
  }

  .model-picker-label {
    min-width: 0;
    width: auto;
    max-width: 42vw;
    font-size: 11px;
  }

  .settings-panel {
    right: auto;
    left: 0;
    width: 92vw;
  }
}

/* --- 会话侧栏扩展 --- */
.chat-layout {
  display: flex;
  gap: 6px;
  align-items: flex-start;
}

.chat-sidebar {
  width: 180px;
  flex-shrink: 0;
  border: none;
  border-radius: 16px;
  background: var(--chat-surface);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  height: calc(100vh - 56px - 64px);
  position: sticky;
  top: 56px;
}

html[data-theme='dark'] .chat-sidebar {
  background: #0d1520;
}

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

.sidebar-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--chat-ink);
}

.sidebar-actions {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.sidebar-action-btn {
  border: none;
  background: transparent;
  color: var(--chat-ink);
  font-size: 10px;
  padding: 0;
  cursor: pointer;
}

.sidebar-action-btn.icon-btn {
  width: 24px;
  height: 24px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.sidebar-action-btn.icon-btn:hover {
  background: var(--chat-muted);
}

.sidebar-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.session-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 4px 6px;
  border-radius: 10px;
  cursor: pointer;
}

.session-item:hover {
  background: var(--chat-muted);
}

.session-item.active {
  background: var(--chat-soft);
}

.session-title {
  flex: 1;
  min-width: 0;
  font-size: 11px;
  color: var(--chat-ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1;
}

.session-delete {
  width: 22px;
  height: 22px;
  border: none;
  background: transparent;
  color: var(--accents-4);
  border-radius: 6px;
  cursor: pointer;
  opacity: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  padding: 0;
}

.session-item:hover .session-delete {
  opacity: 1;
}

.session-delete:hover {
  color: #b91c1c;
  background: rgba(185, 28, 28, 0.08);
}

.session-rename-input {
  flex: 1;
  min-width: 0;
  font-size: 12px;
  color: var(--chat-ink);
  border: 1px solid var(--chat-border);
  border-radius: 6px;
  padding: 2px 6px;
  background: var(--chat-surface);
  outline: none;
}

.session-unread {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: #22c55e;
}

.sidebar-overlay {
  display: none;
}

.sidebar-toggle {
  display: none;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  border: 1px solid var(--chat-border);
  background: var(--chat-surface);
  color: var(--chat-ink);
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.sidebar-expand-btn {
  display: none;
  align-self: flex-start;
  border: 1px solid var(--chat-border);
  background: var(--chat-surface);
  color: var(--chat-ink);
  padding: 0;
  width: 32px;
  height: 32px;
  border-radius: 999px;
  cursor: pointer;
  margin-top: 6px;
  margin-left: 0;
  align-items: center;
  justify-content: center;
  position: sticky;
  top: 56px;
  z-index: 5;
}

.sidebar-expand-btn:hover {
  border-color: #b8b8b8;
  background: var(--chat-muted);
}

@media (min-width: 1025px) {
  .chat-layout.collapsed {
    gap: 8px;
  }

  .chat-layout.collapsed .chat-sidebar {
    width: 0;
    border: none;
    padding: 0;
    overflow: hidden;
  }

  .chat-layout.collapsed .chat-shell {
    padding-left: 0;
  }

  .chat-layout.collapsed .sidebar-expand-btn {
    display: inline-flex;
    margin-left: 0;
    margin-right: 8px;
  }
}

.chat-shell {
  flex: 1;
  min-width: 0;
  padding-left: 16px;
}

@media (max-width: 1024px) {
  .chat-layout {
    position: relative;
  }

  .chat-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100%;
    transform: translateX(-110%);
    transition: transform 0.2s ease;
    z-index: 100; /* 高于 navbar */
    border-radius: 0;
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.12);
  }

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

  html[data-theme='dark'] .chat-sidebar {
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.45);
  }

  .sidebar-overlay {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(17, 17, 17, 0.18);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
    z-index: 90;
  }

  .chat-sidebar .sidebar-header {
    padding-top: calc(12px + env(safe-area-inset-top, 0px));
  }

  .sidebar-overlay.open {
    opacity: 1;
    pointer-events: auto;
  }

  .sidebar-toggle {
    display: inline-flex;
  }
}
