:root {
  color-scheme: light;
  --bg: #ffffff;
  --sidebar: #f9f9f9;
  --surface: #ffffff;
  --surface-muted: #f4f4f4;
  --surface-hover: #ececec;
  --surface-active: #e8e8e8;
  --text: #0d0d0d;
  --muted: #5d5d5d;
  --subtle: #8f8f8f;
  --line: #e5e5e5;
  --line-strong: #d1d1d1;
  --accent: #111111;
  --accent-hover: #2f2f2f;
  --danger: #b42318;
  --danger-soft: #fff3f1;
  --code-bg: #171717;
  --code-text: #f5f5f5;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 12px 34px rgba(0, 0, 0, 0.08);
  --composer-shadow: 0 8px 26px rgba(0, 0, 0, 0.08);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "Microsoft YaHei", "PingFang SC", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  min-width: 320px;
  height: 100%;
}

body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
}

.app-shell {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  height: 100vh;
  min-height: 100vh;
  background: var(--bg);
  transition: grid-template-columns 0.18s ease;
}

.app-shell.sidebar-collapsed {
  grid-template-columns: 0 minmax(0, 1fr);
}

.history-panel {
  display: flex;
  min-height: 0;
  flex-direction: column;
  gap: 8px;
  overflow: visible;
  border-right: 1px solid var(--line);
  background: var(--sidebar);
  padding: 12px;
  transition:
    opacity 0.16s ease,
    padding 0.18s ease,
    border-color 0.18s ease;
}

.app-shell.sidebar-collapsed .history-panel {
  border-right: 0;
  padding-right: 0;
  padding-left: 0;
  pointer-events: none;
}

.app-shell.sidebar-collapsed .history-panel > :not(.sidebar-head) {
  opacity: 0;
  pointer-events: none;
  visibility: hidden;
}

.app-shell.sidebar-collapsed .sidebar-head {
  pointer-events: none;
}

.app-shell.sidebar-collapsed .brand-mark {
  opacity: 0;
  visibility: hidden;
}

.sidebar-head,
.settings-drawer-head,
.composer-actions,
.composer-left,
.composer-right {
  display: flex;
  align-items: center;
}

.sidebar-head {
  justify-content: space-between;
  min-height: 38px;
}

.brand-mark {
  display: grid;
  width: 48px;
  height: 48px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  overflow: hidden;
}

.brand-mark img {
  display: block;
  width: 38px;
  height: 38px;
  object-fit: contain;
}

.icon-button {
  display: inline-grid;
  width: 32px;
  height: 32px;
  place-items: center;
  flex: 0 0 auto;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  line-height: 1;
  transition:
    background 0.14s ease,
    box-shadow 0.14s ease,
    color 0.14s ease,
    transform 0.14s ease;
}

.ui-icon {
  display: block;
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.85;
}

.icon-button .ui-icon {
  width: 18px;
  height: 18px;
}

.icon-button:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.icon-button:active {
  transform: translateY(1px);
}

.sidebar-nav {
  display: grid;
  gap: 2px;
  margin-top: 4px;
}

.nav-button {
  display: flex;
  width: 100%;
  min-height: 40px;
  align-items: center;
  gap: 12px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  padding: 0 10px;
  text-align: left;
  font-size: 14px;
  font-weight: 500;
  transition: background 0.14s ease;
}

.nav-button span {
  width: 20px;
  color: var(--muted);
  text-align: center;
}

.button-icon {
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
}

.nav-button:hover,
.nav-button.active {
  background: var(--surface-hover);
}

.nav-button:hover .button-icon,
.nav-button.active .button-icon {
  color: var(--text);
}

.history-label {
  margin: 18px 8px 2px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

.conversation-list {
  display: grid;
  min-height: 0;
  align-content: start;
  gap: 2px;
  overflow-y: auto;
  padding-right: 2px;
}

.conversation-list::-webkit-scrollbar,
.chat-log::-webkit-scrollbar,
.settings-panel::-webkit-scrollbar {
  width: 10px;
}

.conversation-list::-webkit-scrollbar-thumb,
.chat-log::-webkit-scrollbar-thumb,
.settings-panel::-webkit-scrollbar-thumb {
  border: 3px solid transparent;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.18);
  background-clip: padding-box;
}

.empty-history {
  margin: 4px 8px;
  color: var(--subtle);
  font-size: 13px;
}

.conversation-item {
  position: relative;
  overflow: hidden;
  border-radius: 8px;
}

.conversation-item.active {
  background: var(--surface-active);
}

.conversation-main {
  display: grid;
  width: 100%;
  gap: 2px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  padding: 9px 10px;
  color: var(--text);
  text-align: left;
  transition: background 0.14s ease;
}

.conversation-main:hover {
  background: var(--surface-hover);
}

.conversation-main strong,
.conversation-main span,
.conversation-main small {
  overflow: hidden;
  max-width: 100%;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conversation-main strong {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 6px;
  padding-right: 66px;
  font-size: 14px;
  font-weight: 500;
  line-height: 1.4;
}

.conversation-title-text {
  overflow: hidden;
  min-width: 0;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pin-badge {
  display: inline-flex;
  height: 18px;
  align-items: center;
  flex: 0 0 auto;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.82);
  color: var(--muted);
  padding: 0 6px;
  font-size: 10px;
  font-weight: 650;
  line-height: 1;
}

.conversation-main span {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.conversation-main small {
  color: var(--subtle);
  font-size: 11px;
  line-height: 1.35;
}

.history-footer {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 4px;
  margin-top: auto;
  padding-top: 8px;
}

.settings-nav-button {
  display: flex;
  width: 100%;
  min-height: 42px;
  align-items: center;
  gap: 12px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  padding: 0 8px;
  text-align: left;
  font-size: 14px;
  line-height: 1;
  transition:
    background 0.14s ease,
    color 0.14s ease;
}

.settings-nav-button .button-icon {
  width: 20px;
  color: var(--text);
}

.settings-nav-button .ui-icon {
  width: 20px;
  height: 20px;
  stroke-width: 2;
}

.settings-nav-button:hover {
  background: var(--surface-hover);
}

.chat-panel {
  display: grid;
  grid-template-rows: 56px minmax(0, 1fr) auto;
  min-width: 0;
  min-height: 0;
  height: 100vh;
  background: var(--bg);
}

.chat-topbar {
  display: flex;
  min-width: 0;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
}

.topbar-brand {
  display: inline-flex;
  min-width: 0;
  align-items: center;
  gap: 0;
  transition: gap 0.18s ease;
}

.collapsed-sidebar-toggle {
  position: relative;
  display: grid;
  width: 0;
  height: 40px;
  place-items: center;
  flex: 0 0 auto;
  overflow: hidden;
  border: 0;
  border-radius: 14px;
  background: var(--surface);
  color: var(--muted);
  min-width: 0;
  opacity: 0;
  padding: 0;
  pointer-events: none;
  transform: translateX(-4px);
  transition:
    background 0.14s ease,
    box-shadow 0.14s ease,
    color 0.14s ease,
    opacity 0.16s ease,
    transform 0.18s ease,
    width 0.18s ease;
}

.collapsed-sidebar-toggle:hover {
  background: var(--surface-hover);
  color: var(--text);
  box-shadow: inset 0 0 0 1px var(--line);
}

.collapsed-sidebar-logo,
.collapsed-sidebar-icon {
  grid-area: 1 / 1;
  transition:
    opacity 0.14s ease,
    transform 0.14s ease;
}

.collapsed-sidebar-logo {
  width: 30px;
  height: 30px;
  object-fit: contain;
}

.collapsed-sidebar-icon {
  width: 20px;
  height: 20px;
  opacity: 0;
  transform: scale(0.88);
}

.collapsed-sidebar-toggle:hover .collapsed-sidebar-logo {
  opacity: 0;
  transform: scale(0.88);
}

.collapsed-sidebar-toggle:hover .collapsed-sidebar-icon {
  opacity: 1;
  transform: scale(1);
}

.sidebar-toggle {
  width: 40px;
  height: 40px;
  border-radius: 14px;
  background: var(--surface-muted);
  color: var(--muted);
  box-shadow: inset 0 0 0 1px var(--line);
}

.sidebar-toggle .ui-icon {
  width: 20px;
  height: 20px;
  stroke-width: 1.9;
}

.sidebar-toggle:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.sidebar-toggle[aria-pressed="true"] {
  background: var(--surface-active);
  color: var(--text);
}

.app-shell.sidebar-collapsed .sidebar-toggle {
  opacity: 0;
  pointer-events: none;
}

.app-shell.sidebar-collapsed .topbar-brand {
  gap: 9px;
}

.app-shell.sidebar-collapsed .collapsed-sidebar-toggle {
  width: 40px;
  opacity: 1;
  pointer-events: auto;
  transform: translateX(0);
}

.model-menu {
  display: inline-flex;
  min-width: 0;
  max-width: 52vw;
  min-height: 38px;
  align-items: center;
  color: var(--text);
  padding: 0 10px;
  font-size: 18px;
  font-weight: 650;
}

.model-menu span:first-child,
.conversation-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conversation-title {
  max-width: min(360px, 38vw);
  color: var(--muted);
  font-size: 13px;
}

.topbar-new-chat {
  display: inline-grid;
  width: 40px;
  height: 40px;
  place-items: center;
  border: 0;
  border-radius: 14px;
  background: transparent;
  color: var(--muted);
  padding: 0;
  transition:
    background 0.14s ease,
    box-shadow 0.14s ease,
    color 0.14s ease,
    transform 0.14s ease;
}

.topbar-new-chat .ui-icon {
  width: 24px;
  height: 24px;
  stroke-width: 2;
}

.topbar-new-chat:hover {
  background: var(--surface-hover);
  box-shadow: inset 0 0 0 1px var(--line);
  color: var(--text);
}

.topbar-new-chat:active {
  transform: translateY(1px);
}

.chat-log {
  display: flex;
  min-height: 0;
  flex-direction: column;
  align-items: center;
  gap: 26px;
  overflow-y: auto;
  padding: 24px 24px 34px;
}

.empty-state {
  display: grid;
  width: min(100%, 820px);
  min-height: 100%;
  align-content: center;
  justify-items: center;
  gap: 10px;
  padding-bottom: 10vh;
  color: var(--text);
  text-align: center;
}

.empty-state h2 {
  margin: 0;
  font-size: clamp(26px, 3.4vw, 32px);
  font-weight: 500;
  letter-spacing: 0;
  line-height: 1.25;
}

.empty-state p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.message {
  display: grid;
  width: min(100%, 760px);
  gap: 8px;
}

.message.user {
  justify-items: end;
}

.message.assistant {
  justify-items: start;
}

.message-meta {
  color: var(--subtle);
  font-size: 12px;
  font-weight: 500;
}

.message.user .message-meta {
  padding-right: 8px;
  text-align: right;
}

.message.assistant .message-meta {
  padding-left: 2px;
}

.bubble {
  max-width: 100%;
  line-height: 1.7;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.message.user .bubble {
  max-width: min(76%, 620px);
  border-radius: 18px;
  background: var(--surface-muted);
  padding: 10px 16px;
}

.message.assistant .bubble {
  width: 100%;
  background: transparent;
  padding: 2px 0;
}

.bubble.thinking {
  display: flex;
  align-items: center;
  min-height: 42px;
}

.thinking-state {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 550;
}

.thinking-dots {
  display: inline-flex;
  gap: 5px;
  align-items: center;
}

.thinking-dots i {
  display: block;
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: var(--muted);
  opacity: 0.35;
  animation: thinkingPulse 1.2s infinite ease-in-out;
}

.thinking-dots i:nth-child(2) {
  animation-delay: 0.15s;
}

.thinking-dots i:nth-child(3) {
  animation-delay: 0.3s;
}

.thinking-label {
  letter-spacing: 0;
}

.message.error .bubble {
  border-radius: 8px;
  background: var(--danger-soft);
  color: var(--danger);
  padding: 12px 14px;
}

.file-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 6px;
}

.file-chip {
  max-width: 220px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  padding: 4px 9px;
  color: var(--muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.composer {
  width: min(100%, 820px);
  margin: 0 auto;
  padding: 0 18px 24px;
}

.composer-attachments {
  margin-bottom: 8px;
}

.composer-box {
  border: 1px solid var(--line);
  border-radius: 28px;
  background: var(--surface);
  box-shadow: var(--composer-shadow);
  padding: 12px;
}

.composer textarea {
  width: 100%;
  min-height: 42px;
  max-height: 190px;
  resize: none;
  border: 0;
  background: transparent;
  color: var(--text);
  outline: none;
  padding: 3px 7px 0;
  line-height: 1.55;
}

.composer textarea:disabled {
  color: var(--muted);
}

.composer-actions {
  justify-content: space-between;
  gap: 12px;
  margin-top: 6px;
}

.composer-left,
.composer-right,
.model-control-group {
  min-width: 0;
  gap: 8px;
}

.model-control-group {
  position: relative;
  display: inline-flex;
  min-width: 0;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.78);
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.06);
  padding: 2px;
  backdrop-filter: blur(12px);
}

.native-select {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  pointer-events: none;
  white-space: nowrap;
}

.custom-select {
  position: relative;
  min-width: 0;
}

.custom-select-trigger {
  display: inline-flex;
  min-width: 86px;
  height: 30px;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  padding: 0 10px 0 12px;
  font-size: 13px;
  line-height: 1;
  transition:
    background 0.14s ease,
    color 0.14s ease;
}

.custom-select-trigger:hover,
.custom-select.open .custom-select-trigger {
  background: var(--surface-hover);
  color: var(--text);
}

.custom-select-trigger:disabled {
  opacity: 0.42;
}

.custom-select-trigger .ui-icon {
  width: 16px;
  height: 16px;
  stroke-width: 2.1;
  transition: transform 0.14s ease;
}

.custom-select-menu {
  position: absolute;
  right: 0;
  bottom: calc(100% + 8px);
  z-index: 25;
  display: grid;
  width: 100%;
  min-width: 100%;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(247, 247, 247, 0.96);
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.14);
  padding: 4px;
  transform-origin: bottom right;
  animation: customSelectIn 0.12s ease-out;
  backdrop-filter: blur(14px);
}

.custom-select-menu button {
  display: flex;
  min-height: 30px;
  align-items: center;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--text);
  padding: 0 12px;
  text-align: left;
  font-size: 13px;
  line-height: 1;
  white-space: nowrap;
}

.custom-select-menu button:hover,
.custom-select-menu button:focus,
.custom-select-menu button.active,
.custom-select-menu button.selected {
  background: #d8d8d8;
  color: var(--text);
}

.custom-select-menu button.selected {
  background: #7e7e7e;
  color: #fff;
  font-weight: 650;
}

.custom-select-menu button:disabled {
  opacity: 0.45;
}

.composer-quickbar {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.78);
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.06);
  padding: 2px;
  backdrop-filter: blur(12px);
}

.composer-select {
  width: auto;
  max-width: 150px;
  height: 30px;
  min-width: 84px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  padding: 0 8px;
  font-size: 13px;
  outline: none;
}

.composer-select:hover,
.composer-select:focus {
  background: var(--surface-hover);
  color: var(--text);
  box-shadow: none;
}

.attach-button {
  border-radius: 999px;
  color: var(--text);
}

.composer-quickbar .attach-button {
  width: 30px;
  height: 30px;
  border-radius: 999px;
}

.composer-quickbar .attach-button:hover {
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.08);
}

.status-line {
  min-width: 0;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.send-button {
  display: inline-grid;
  width: 30px;
  height: 30px;
  place-items: center;
  border: 0;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  line-height: 1;
  transition:
    background 0.14s ease,
    box-shadow 0.14s ease,
    opacity 0.14s ease,
    transform 0.14s ease;
}

.send-button .ui-icon {
  width: 18px;
  height: 18px;
  stroke-width: 2.1;
}

.send-button:hover {
  background: var(--accent-hover);
  box-shadow: 0 10px 22px rgba(0, 0, 0, 0.18);
}

.send-button:active {
  transform: translateY(1px);
}

.send-button:disabled {
  opacity: 0.35;
  transform: none;
}

.settings-backdrop {
  position: fixed;
  inset: 0;
  z-index: 18;
  background: rgba(0, 0, 0, 0.34);
}

.context-menu {
  position: fixed;
  z-index: 30;
  display: grid;
  min-width: 120px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(247, 247, 247, 0.96);
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.14);
  padding: 4px;
  backdrop-filter: blur(14px);
}

.context-menu button {
  min-height: 30px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--text);
  padding: 0 11px;
  text-align: left;
  font-size: 13px;
  line-height: 1;
  white-space: nowrap;
}

.context-menu button:hover {
  background: #d8d8d8;
}

.toast-region {
  position: fixed;
  top: 18px;
  right: 18px;
  z-index: 40;
  display: grid;
  width: min(360px, calc(100vw - 36px));
  gap: 10px;
  pointer-events: none;
}

.toast {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr);
  gap: 10px;
  align-items: start;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: var(--shadow-md);
  padding: 12px;
  color: var(--text);
  pointer-events: auto;
  animation: toastIn 0.18s ease-out;
}

.toast::before {
  display: grid;
  width: 28px;
  height: 28px;
  place-items: center;
  border-radius: 999px;
  background: #eff8f3;
  color: #167044;
  content: "✓";
  font-weight: 800;
}

.toast.error::before {
  background: var(--danger-soft);
  color: var(--danger);
  content: "!";
}

.toast strong {
  display: block;
  margin-bottom: 2px;
  font-size: 14px;
  font-weight: 650;
}

.toast span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

@keyframes toastIn {
  from {
    opacity: 0;
    transform: translateY(-6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes customSelectIn {
  from {
    opacity: 0;
    transform: translateY(4px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.settings-panel {
  position: fixed;
  inset: 0 0 0 auto;
  z-index: 19;
  display: flex;
  width: min(440px, calc(100vw - 32px));
  flex-direction: column;
  gap: 16px;
  overflow-y: auto;
  border-left: 1px solid var(--line);
  background: var(--surface);
  box-shadow: -18px 0 42px rgba(0, 0, 0, 0.14);
  padding: 18px;
}

.settings-drawer-head {
  gap: 12px;
  justify-content: space-between;
}

.brand {
  display: grid;
  min-width: 0;
  grid-template-columns: 48px minmax(0, 1fr);
  gap: 11px;
  align-items: center;
}

.brand h1 {
  margin: 0;
  color: var(--text);
  font-size: 18px;
  font-weight: 650;
  letter-spacing: 0;
  line-height: 1.25;
}

.brand p {
  min-width: 0;
  margin: 3px 0 0;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.field {
  display: grid;
  gap: 7px;
}

.field span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

select,
input,
.settings-panel textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  outline: none;
  transition:
    border-color 0.14s ease,
    box-shadow 0.14s ease,
    background 0.14s ease;
}

select,
input {
  height: 40px;
  padding: 0 11px;
}

select {
  appearance: auto;
}

.settings-panel textarea {
  resize: vertical;
  padding: 11px 12px;
  line-height: 1.55;
}

select:hover,
input:hover,
.settings-panel textarea:hover {
  border-color: var(--line-strong);
}

select:focus,
input:focus,
.settings-panel textarea:focus {
  border-color: #9b9b9b;
  box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.08);
}

input::placeholder,
textarea::placeholder {
  color: var(--subtle);
}

.api-key-box,
.file-box,
.request-box,
.settings-section,
.side-actions {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(247, 247, 247, 0.78);
}

.alert-dialog-backdrop {
  position: fixed;
  z-index: 50;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(13, 13, 13, 0.46);
  padding: 20px;
  backdrop-filter: blur(5px);
}

.alert-dialog-container {
  width: min(100%, 420px);
}

.alert-dialog {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.18);
  padding: 22px;
}

.alert-dialog-close {
  position: absolute;
  top: 12px;
  right: 12px;
}

.alert-dialog-head {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  gap: 13px;
  padding-right: 30px;
}

.alert-dialog-icon {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: 999px;
  background: var(--danger-soft);
  color: var(--danger);
}

.alert-dialog-icon .ui-icon {
  width: 22px;
  height: 22px;
}

.alert-dialog h2 {
  margin: 0 0 8px;
  color: var(--text);
  font-size: 18px;
  line-height: 1.25;
  letter-spacing: 0;
}

.alert-dialog p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.6;
}

.alert-dialog-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 22px;
}

.danger-action-button {
  min-height: 40px;
  border: 1px solid var(--danger);
  border-radius: 8px;
  background: var(--danger);
  color: #ffffff;
  padding: 0 14px;
  font-weight: 650;
}

.danger-action-button:hover {
  background: #9f1f16;
}

.danger-action-button:disabled {
  opacity: 0.55;
}

.api-key-box {
  display: grid;
  gap: 12px;
  padding: 13px;
}

.button-row,
.field-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 10px;
}

.settings-section,
.request-box {
  display: grid;
  gap: 12px;
  padding: 10px;
}

.settings-section > summary,
.request-box > summary {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  color: var(--text);
  border-radius: 12px;
  padding: 7px 9px;
  font-size: 13px;
  font-weight: 650;
  list-style: none;
}

.settings-section > summary::-webkit-details-marker,
.request-box > summary::-webkit-details-marker {
  display: none;
}

.settings-section > summary::before,
.request-box > summary::before {
  content: "";
  width: 6px;
  height: 6px;
  flex: 0 0 auto;
  border-right: 1.8px solid currentColor;
  border-bottom: 1.8px solid currentColor;
  opacity: 0.78;
  transform: rotate(-45deg);
  transition: transform 0.14s ease;
}

.settings-section[open] > summary::before,
.request-box[open] > summary::before {
  transform: rotate(45deg);
}

.settings-section > summary:hover,
.request-box > summary:hover {
  background: var(--surface-hover);
}

.settings-section[open] > summary,
.request-box[open] > summary {
  margin-bottom: 10px;
}

.request-box pre {
  overflow: auto;
  max-height: 240px;
  margin: 0;
  border-radius: 8px;
  background: var(--code-bg);
  padding: 12px;
  color: var(--code-text);
  font-size: 12px;
  line-height: 1.5;
  white-space: pre;
}

.system-field textarea {
  min-height: 130px;
}

.file-box {
  display: grid;
  min-height: 84px;
  place-items: center;
  border-style: dashed;
  padding: 14px;
  text-align: center;
}

.file-box.dragging {
  border-color: var(--text);
  background: #eeeeee;
}

.file-box p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.attachment-list {
  display: grid;
  gap: 8px;
}

.attachment-item {
  display: grid;
  min-width: 0;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  padding: 9px 10px;
  font-size: 13px;
}

.attachment-item strong {
  display: block;
  overflow: hidden;
  color: var(--text);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.attachment-item span {
  color: var(--muted);
}

.side-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  margin-top: auto;
  padding: 10px;
}

.primary-button,
.secondary-button,
.ghost-button,
.mini-button {
  display: inline-flex;
  min-height: 38px;
  align-items: center;
  justify-content: center;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 0 13px;
  transition:
    background 0.14s ease,
    border-color 0.14s ease,
    color 0.14s ease,
    transform 0.14s ease;
}

.primary-button {
  background: var(--accent);
  color: #fff;
  font-weight: 650;
}

.primary-button:hover {
  background: var(--accent-hover);
}

.primary-button:disabled,
.secondary-button:disabled,
.ghost-button:disabled,
.mini-button:disabled {
  opacity: 0.45;
  transform: none;
}

.primary-button:active,
.secondary-button:active,
.ghost-button:active,
.mini-button:active {
  transform: translateY(1px);
}

.secondary-button {
  border-color: var(--line);
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
}

.secondary-button:hover {
  border-color: var(--line-strong);
  background: var(--surface-hover);
}

.ghost-button,
.mini-button {
  border-color: var(--line);
  background: var(--surface);
  color: var(--text);
}

.ghost-button:hover,
.mini-button:hover {
  border-color: var(--line-strong);
  background: var(--surface-hover);
}

.mini-button {
  min-height: 28px;
  padding: 0 8px;
  font-size: 12px;
}

.danger-button {
  color: var(--danger);
}

.stop-button {
  min-height: 30px;
  border-radius: 999px;
  padding: 0 12px;
  font-size: 13px;
}

.toggle-field {
  display: flex;
  min-height: 40px;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 0 12px;
}

.toggle-field span {
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
}

.toggle-field input {
  width: auto;
  height: auto;
  margin: 0;
  flex: 0 0 auto;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  accent-color: var(--accent);
  appearance: auto;
}

.code-block {
  overflow: hidden;
  margin: 10px 0;
  border-radius: 8px;
  background: var(--code-bg);
  color: var(--code-text);
  box-shadow: var(--shadow-sm);
  white-space: normal;
}

.code-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
  padding: 8px 11px;
  color: #cfcfcf;
  font-size: 12px;
}

.code-block pre {
  overflow-x: auto;
  margin: 0;
  padding: 13px 14px;
  white-space: pre;
}

.code-copy {
  min-height: 28px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 6px;
  background: transparent;
  color: var(--code-text);
}

@keyframes thinkingPulse {
  0%,
  80%,
  100% {
    transform: translateY(0);
    opacity: 0.35;
  }
  40% {
    transform: translateY(-3px);
    opacity: 0.95;
  }
}

@media (max-width: 920px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: 184px minmax(0, 1fr);
    height: 100vh;
  }

  .app-shell.sidebar-collapsed {
    grid-template-columns: 1fr;
    grid-template-rows: 184px minmax(0, 1fr);
  }

  .app-shell.sidebar-collapsed .history-panel {
    border-bottom-color: var(--line);
    opacity: 1;
    padding: 12px;
    pointer-events: auto;
  }

  .app-shell.sidebar-collapsed .history-panel > :not(.sidebar-head),
  .app-shell.sidebar-collapsed .brand-mark {
    opacity: 1;
    pointer-events: auto;
    visibility: visible;
  }

  .app-shell.sidebar-collapsed .sidebar-head {
    pointer-events: auto;
  }

  .history-panel {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .sidebar-toggle {
    display: none;
  }

  .sidebar-nav {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .nav-button {
    justify-content: center;
    gap: 8px;
  }

  .history-label {
    margin-top: 8px;
  }

  .conversation-list {
    grid-auto-columns: minmax(210px, 1fr);
    grid-auto-flow: column;
    overflow-x: auto;
    overflow-y: hidden;
  }

  .conversation-main {
    padding: 8px 10px;
  }

  .conversation-main strong {
    padding-right: 0;
  }

  .conversation-main span,
  .conversation-main small {
    display: none;
  }

  .history-footer {
    display: none;
  }

  .chat-panel {
    height: calc(100vh - 184px);
  }
}

@media (max-width: 560px) {
  .app-shell {
    grid-template-rows: 156px minmax(0, 1fr);
  }

  .history-panel,
  .settings-panel {
    padding: 10px;
  }

  .chat-panel {
    height: calc(100vh - 156px);
  }

  .chat-topbar {
    padding: 0 12px;
  }

  .model-menu {
    max-width: 58vw;
    font-size: 16px;
  }

  .conversation-title {
    max-width: 32vw;
  }

  .nav-button {
    min-height: 36px;
    padding: 0 6px;
    font-size: 13px;
  }

  .nav-button span {
    width: 18px;
  }

  .history-label {
    display: none;
  }

  .conversation-list {
    grid-auto-columns: minmax(180px, 1fr);
  }

  .chat-log {
    gap: 22px;
    padding: 18px 14px 24px;
  }

  .empty-state {
    padding-bottom: 6vh;
  }

  .empty-state h2 {
    font-size: 25px;
  }

  .message.user .bubble {
    max-width: 86%;
  }

  .composer {
    padding: 0 10px 12px;
  }

  .composer-box {
    border-radius: 24px;
    padding: 10px;
  }

  .composer-actions {
    align-items: flex-end;
  }

  .composer-right {
    gap: 4px;
  }

  .model-control-group {
    gap: 4px;
  }

  .custom-select-trigger {
    min-width: 72px;
    gap: 6px;
    padding: 0 8px 0 10px;
    font-size: 12px;
  }

  [data-select-proxy="model"] .custom-select-trigger {
    min-width: 100px;
  }

  .composer-select {
    max-width: 96px;
    min-width: 68px;
    padding: 0 4px;
    font-size: 12px;
  }

  .status-line {
    max-width: 30vw;
  }

  .settings-panel {
    width: 100vw;
  }

  .button-row,
  .field-grid {
    grid-template-columns: 1fr;
  }
}
