.theme-anim,
.theme-anim *:not(.thinking-spinner):not(.thinking-spinner *) {
  transition: background-color 0.3s ease, border-color 0.3s ease,
    fill 0.3s ease, stroke 0.3s ease !important;
}

:root {
  color-scheme: light;
  --sidebar-width: 260px;
  --sidebar-width-collapsed: 76px;
  --content-width: 768px;
  --bg: #ffffff;
  --bg-soft: #f9f9f9;
  --bg-hover: #ececec;
  --line: #e5e5e5;
  --line-strong: #d9d9df;
  --text: #0d0d0d;
  --muted: #666666;
  --muted-soft: #999999;
  --surface: #ffffff;
  --surface-raised: #ffffff;
  --surface-subtle: #f6f7f8;
  --user-bubble: #f4f4f4;
  --accent: #000000;
  --accent-soft: rgba(0, 0, 0, 0.05);
  --brand-primary: #111111;
  --brand-primary-soft: rgba(0, 0, 0, 0.05);
  --selection-bg: rgba(17, 17, 17, 0.14);
  --focus-ring: rgba(37, 99, 235, 0.18);
  --danger: #ef4444;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow-soft: 0 4px 12px rgba(0, 0, 0, 0.05);
  --shadow-composer: 0 2px 6px rgba(15, 23, 42, 0.06), 0 8px 20px -6px rgba(15, 23, 42, 0.12);
  font-family: ui-sans-serif, -apple-system, system-ui, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

:root.dark {
  color-scheme: dark;
  --bg: #212121;
  --bg-soft: #171717;
  --bg-hover: #2f2f2f;
  --line: #424242;
  --line-strong: #525252;
  --text: #ececec;
  --muted: #b4b4b4;
  --muted-soft: #808080;
  --surface: #212121;
  --surface-raised: #262626;
  --surface-subtle: #2a2a2a;
  --user-bubble: #2f2f2f;
  --accent: #ffffff;
  --accent-soft: rgba(255, 255, 255, 0.1);
  --selection-bg: rgba(255, 255, 255, 0.22);
  --focus-ring: rgba(96, 165, 250, 0.24);
  --danger: #ef4444;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-soft: 0 4px 12px rgba(0, 0, 0, 0.3);
  --shadow-composer: 0 2px 6px rgba(0, 0, 0, 0.4), 0 8px 20px -6px rgba(0, 0, 0, 0.55);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
}

body {
  min-height: 100vh;
  overflow: hidden;
}

button,
input,
textarea {
  font: inherit;
}

.icon-svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
  flex: 0 0 auto;
  pointer-events: none;
}

button {
  -webkit-tap-highlight-color: transparent;
}

::selection {
  background: var(--selection-bg);
}

body {
  font-variant-numeric: tabular-nums;
}

button,
a,
input,
textarea,
[tabindex] {
  outline: none;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
textarea:focus-visible,
[tabindex]:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--brand-primary);
}

button:not(:disabled):active {
  transform: scale(0.97);
}

.session-card-main:not(:disabled):active,
.model-button:not(:disabled):active,
.mode-link:not(:disabled):active,
.account-card:not(:disabled):active {
  transform: none;
}

* {
  scrollbar-width: thin;
  scrollbar-color: transparent transparent;
}

*:hover {
  scrollbar-color: #d5d7dd transparent;
}

*::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

*::-webkit-scrollbar-track {
  background: transparent;
}

*::-webkit-scrollbar-thumb {
  border-radius: 999px;
  background-color: transparent;
}

*:hover::-webkit-scrollbar-thumb {
  background-color: #d5d7dd;
}

.app-shell {
  position: relative;
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  height: 100vh;
  background: var(--bg);
}

.app-shell.layout-ready {
  transition: grid-template-columns 0.18s ease;
}

.sidebar-resize-handle {
  position: absolute;
  top: 0;
  bottom: 0;
  left: calc(var(--sidebar-width) - 2px);
  width: 8px;
  z-index: 8;
  cursor: col-resize;
  transition: background 0.16s ease, opacity 0.16s ease, left 0.18s ease;
}

.sidebar-resize-handle:hover {
  background: rgba(17, 17, 17, 0.05);
}

.app-shell.sidebar-collapsed {
  grid-template-columns: var(--sidebar-width-collapsed) minmax(0, 1fr);
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 14px;
  border-right: 1px solid var(--line);
  background: var(--bg-soft);
  padding: calc(12px + env(safe-area-inset-top)) 12px calc(14px + env(safe-area-inset-bottom));
  overflow: hidden;
  min-width: 0;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding-bottom: 2px;
}

.brand-button,
.icon-button,
.text-button,
.model-button,
.message-action,
.composer-icon,
.send-button,
.session-menu-button {
  border: 0;
  background: transparent;
  cursor: pointer;
}

.brand-button,
.icon-button,
.composer-icon,
.send-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.brand-button,
.icon-button {
  width: 34px;
  height: 34px;
  border-radius: 12px;
  color: var(--text);
  transition: background 0.16s ease, transform 0.16s ease, border-color 0.16s ease;
}

.brand-button:hover,
.icon-button:hover,
.session-menu-button:hover,
.composer-icon:hover,
.message-action:hover,
.text-button:hover,
.model-button:hover {
  background: var(--bg-hover);
}

.brand-button:active,
.icon-button:active,
.sidebar-action:active,
.starter-card:active,
.send-button:active,
.message-action:active,
.text-button:active,
.model-button:active {
  transform: translateY(1px);
}

.brand-mark {
  width: 28px;
  height: 28px;
  border-radius: 999px;
  background: #fff;
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  overflow: hidden;
  box-shadow: inset 0 0 0 1px var(--line);
}

.brand-mark img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scale(1.14);
}

.sidebar-actions {
  display: grid;
  gap: 8px;
}

.sidebar-action,
.search-box {
  width: 100%;
  min-height: 38px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 12px;
  background: transparent;
  color: var(--text);
  transition: background 0.16s ease, border-color 0.16s ease, box-shadow 0.16s ease;
}

.sidebar-action {
  border: 1px solid var(--line);
  background: var(--bg);
  justify-content: flex-start;
}

.sidebar-action:hover,
.search-box:hover {
  background: var(--bg-hover);
}

.sidebar-action:focus-visible,
.search-box:focus-within,
.session-card-main:focus-visible,
.starter-card:focus-visible,
.message-action:focus-visible,
.text-button:focus-visible,
.model-button:focus-visible,
.icon-button:focus-visible,
.send-button:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.sidebar-action-icon,
.search-icon {
  width: 15px;
  text-align: center;
  flex: 0 0 15px;
  color: var(--text);
}

.search-box input {
  width: 100%;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
}

.search-box input::placeholder {
  color: var(--muted);
}

.history-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  flex: 1;
  overflow: hidden;
  gap: 8px;
}

.history-header {
  padding: 2px 8px 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.session-groups {
  display: grid;
  gap: 14px;
  overflow-y: auto;
  overflow-x: hidden;
  padding-right: 2px;
  padding-bottom: 12px;
  scrollbar-gutter: stable;
}

.session-group {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.session-group-label {
  padding: 0 8px;
  color: var(--muted);
  font-size: 12px;
}

.session-card {
  position: relative;
  min-width: 0;
  border-radius: 10px;
  background: transparent;
  transition: background 0.16s ease, box-shadow 0.16s ease;
}

.session-card.active::before {
  content: "";
  position: absolute;
  top: 50%;
  left: 0;
  width: 3px;
  height: 18px;
  border-radius: 999px;
  background: var(--text);
  transform: translateY(-50%);
}

.session-card:hover,
.session-card.active {
  background: var(--bg-hover);
}

.session-card.editing {
  background: var(--bg);
  box-shadow: 0 0 0 1px rgba(17, 17, 17, 0.08);
}

.session-card-main {
  width: 100%;
  border: 0;
  background: transparent;
  text-align: left;
  color: var(--text);
  cursor: pointer;
  padding: 9px 38px 9px 14px;
  border-radius: 10px;
  transition: background 0.16s ease, padding 0.16s ease;
}

.session-card-editing {
  display: grid;
  gap: 6px;
  padding: 10px 12px;
}

.session-title-input {
  width: 100%;
  height: 34px;
  border: 1px solid rgba(17, 17, 17, 0.12);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  padding: 0 10px;
  outline: none;
}

.session-title-input:focus {
  border-color: rgba(17, 17, 17, 0.18);
  box-shadow: 0 0 0 3px rgba(17, 17, 17, 0.06);
}

.session-card-edit-actions {
  position: absolute;
  top: 8px;
  right: 8px;
  display: flex;
  align-items: center;
  gap: 4px;
}

.session-card-title {
  display: block;
  font-size: 13px;
  line-height: 1.45;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.session-card-preview {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.session-menu-button {
  width: 26px;
  height: 26px;
  border-radius: 8px;
  color: var(--muted);
  background: var(--bg);
  box-shadow: 0 0 0 1px rgba(17, 17, 17, 0.04);
}

.session-menu-button .icon-svg {
  width: 15px;
  height: 15px;
}

.sidebar-footer {
  margin-top: auto;
  padding-top: 8px;
  border-top: 1px solid var(--line);
}

.account-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 8px;
  border-radius: 12px;
}

.account-card:hover {
  background: var(--bg-hover);
}

.account-avatar {
  position: relative;
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: #111;
  background-size: cover;
  background-position: center;
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  cursor: pointer;
}

.account-avatar-text {
  line-height: 1;
}

.account-avatar.has-image .account-avatar-text {
  display: none;
}

.account-avatar-edit {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.45);
  color: #fff;
  opacity: 0;
  transition: opacity 0.16s ease;
}

.account-avatar:hover .account-avatar-edit,
.account-avatar:focus-visible .account-avatar-edit {
  opacity: 1;
}

.account-avatar-edit svg {
  width: 15px;
  height: 15px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.avatar-dialog-card {
  width: min(360px, calc(100vw - 32px));
}

.avatar-stage {
  position: relative;
  width: 240px;
  height: 240px;
  margin: 2px auto 0;
  border-radius: 16px;
  overflow: hidden;
  background: var(--bg-soft);
  touch-action: none;
  user-select: none;
}

.avatar-stage-image {
  position: absolute;
  top: 50%;
  left: 50%;
  transform-origin: center;
  will-change: transform;
  pointer-events: none;
  -webkit-user-drag: none;
}

.avatar-stage[data-empty="true"] .avatar-stage-image,
.avatar-stage[data-empty="true"] .avatar-stage-mask {
  display: none;
}

.avatar-stage:not([data-empty="true"]) {
  cursor: grab;
}

.avatar-stage:not([data-empty="true"]) .avatar-stage-empty {
  display: none;
}

.avatar-stage.dragging {
  cursor: grabbing;
}

.avatar-stage-mask {
  position: absolute;
  inset: 0;
  pointer-events: none;
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.42);
  border-radius: 999px;
}

.avatar-stage-empty {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px dashed var(--line-strong);
  border-radius: 16px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  cursor: pointer;
}

.avatar-stage-empty svg {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.avatar-zoom {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 4px;
}

.avatar-zoom[hidden] {
  display: none;
}

.avatar-zoom-icon {
  color: var(--muted);
  font-size: 18px;
  line-height: 1;
  width: 14px;
  text-align: center;
}

.avatar-zoom input[type="range"] {
  flex: 1;
  accent-color: var(--text);
}

.avatar-dialog-actions {
  align-items: center;
}

.avatar-actions-spacer {
  flex: 1;
}

.confirm-dialog-btn.link-danger {
  min-width: 0;
  padding: 0 6px;
  background: transparent;
  border-color: transparent;
  color: #d23b3b;
  font-weight: 600;
}

.confirm-dialog-btn.link-danger:hover {
  text-decoration: underline;
}

.account-copy {
  display: grid;
  min-width: 0;
}

.account-copy strong,
.account-copy span {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.account-copy strong {
  font-size: 13px;
}

.account-copy span {
  color: var(--muted);
  font-size: 12px;
}

.account-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.account-link {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  padding: 7px 10px;
  font-size: 12px;
  cursor: pointer;
  transition: background 0.16s ease, border-color 0.16s ease;
}

.account-link:hover {
  background: var(--bg-hover);
  border-color: var(--line-strong);
}

.account-link.muted {
  color: var(--muted);
}

.chat-layout {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  height: 100vh;
  background: var(--bg);
  overflow: hidden;
}

.topbar {
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: calc(8px + env(safe-area-inset-top)) 14px 8px;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
}

.topbar-left,
.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.topbar-left {
  min-width: 0;
}

.topbar-right {
  flex: 0 0 auto;
}

.mode-switcher {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--bg-soft);
  flex: 0 0 auto;
}

.mode-link {
  min-width: 44px;
  height: 26px;
  padding: 0 10px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
}

.mode-link:hover {
  color: var(--text);
  background: var(--bg-hover);
}

.mode-link.active {
  color: #fff;
  background: #111;
}

.model-button {
  height: 34px;
  padding: 0 11px;
  border-radius: 12px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text);
  font-size: 14px;
}

.model-title {
  font-weight: 600;
  letter-spacing: 0;
}

.model-caret {
  color: var(--muted);
  font-size: 12px;
}

.text-button {
  height: 32px;
  padding: 0 10px;
  border-radius: 10px;
  color: var(--text);
  font-size: 13px;
}

.text-button.with-icon {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.conversation-stage {
  min-height: 0;
  overflow: hidden;
  padding: 18px 0 24px;
  display: flex;
  flex-direction: column;
  position: relative;
  background:
    linear-gradient(180deg, var(--bg) 0%, var(--surface-subtle) 100%);
}

.messages,
.empty-hero {
  width: min(var(--content-width), calc(100vw - 120px));
  margin: 0 auto;
}

.empty-hero {
  padding: 72px 0 28px;
  text-align: center;
  opacity: 1;
  transform: translateY(0);
  transition: opacity 0.24s ease, transform 0.24s ease;
}

.welcome-logo {
  display: block;
  width: 76px;
  height: 76px;
  margin: 0 auto 2px;
  object-fit: cover;
  transform: scale(1.1);
  border-radius: 999px;
}

.welcome-logo[hidden] {
  display: none;
}

.empty-hero.is-hidden {
  opacity: 0;
  transform: translateY(-10px);
}

.empty-hero.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.empty-hero h1 {
  margin: 16px 0 0;
  font-size: 32px;
  font-weight: 600;
  letter-spacing: 0;
  animation: hero-rise 0.5s cubic-bezier(0.22, 1, 0.36, 1) backwards;
}

.empty-hero p {
  margin: 12px auto 0;
  max-width: 640px;
  color: var(--muted);
  line-height: 1.75;
  animation: hero-rise 0.5s cubic-bezier(0.22, 1, 0.36, 1) 0.06s backwards;
}

.starter-grid {
  margin-top: 28px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.starter-card {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--bg);
  padding: 16px 18px;
  text-align: left;
  color: var(--text);
  line-height: 1.6;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform 0.16s ease, box-shadow 0.16s ease, background 0.16s ease, border-color 0.16s ease;
  animation: hero-rise 0.5s cubic-bezier(0.22, 1, 0.36, 1) backwards;
}

.starter-card:nth-child(1) { animation-delay: 0.12s; }
.starter-card:nth-child(2) { animation-delay: 0.18s; }
.starter-card:nth-child(3) { animation-delay: 0.24s; }
.starter-card:nth-child(4) { animation-delay: 0.3s; }

.starter-card:hover {
  background: var(--bg-soft);
  border-color: rgba(17, 17, 17, 0.1);
  box-shadow: var(--shadow-soft);
  transform: translateY(-1px);
}

.messages {
  display: grid;
  align-content: start;
  grid-auto-rows: max-content;
  gap: 24px;
  padding-top: 10px;
  padding-bottom: 52px;
  flex: 1;
  overflow-y: auto;
  min-height: 0;
  scrollbar-gutter: stable;
  scroll-padding-bottom: 56px;
  overflow-anchor: none;
}

.empty-state {
  color: var(--muted);
  text-align: center;
  padding: 70px 0 24px;
  line-height: 1.8;
}

.message {
  display: flex;
  gap: 12px;
  position: relative;
}

.message.is-entering {
  animation: message-enter 0.28s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.assistant-avatar {
  width: 30px;
  height: 30px;
  flex: 0 0 30px;
  margin-top: 1px;
  border-radius: 999px;
  background: #fff;
  object-fit: cover;
  transform: scale(1.12);
  box-shadow: inset 0 0 0 1px var(--line);
}

.assistant-avatar[hidden] {
  display: none;
}

.message.assistant {
  justify-content: flex-start;
}

.message.user {
  justify-content: flex-end;
}

.message-main {
  max-width: 100%;
  width: 100%;
}

.message.user .message-main {
  width: auto;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}

.message-content {
  line-height: 1.85;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text);
  font-size: 15px;
}

.message.user .message-content {
  max-width: min(620px, 72vw);
  background: var(--user-bubble);
  border: 1px solid var(--line);
  border-radius: 18px 18px 6px 18px;
  padding: 11px 16px;
  box-shadow: var(--shadow);
}

.message.assistant .message-content {
  max-width: min(100%, 720px);
  padding: 0;
  line-height: 1.76;
}

.message.assistant .message-content p,
.message.assistant .message-content ul,
.message.assistant .message-content ol,
.message.assistant .message-content blockquote,
.message.assistant .message-content .message-code,
.message.assistant .message-content .message-table-wrap,
.message.assistant .message-content hr {
  margin: 0 0 12px;
}

.message.assistant .message-content h1,
.message.assistant .message-content h2,
.message.assistant .message-content h3,
.message.assistant .message-content h4,
.message.assistant .message-content h5,
.message.assistant .message-content h6 {
  margin: 20px 0 10px;
  color: var(--text);
  font-weight: 700;
  line-height: 1.35;
  letter-spacing: 0;
}

.message.assistant .message-content h1:first-child,
.message.assistant .message-content h2:first-child,
.message.assistant .message-content h3:first-child,
.message.assistant .message-content h4:first-child,
.message.assistant .message-content h5:first-child,
.message.assistant .message-content h6:first-child {
  margin-top: 0;
}

.message.assistant .message-content h1 {
  font-size: 25px;
}

.message.assistant .message-content h2 {
  font-size: 21px;
}

.message.assistant .message-content h3 {
  font-size: 18px;
}

.message.assistant .message-content h4,
.message.assistant .message-content h5,
.message.assistant .message-content h6 {
  font-size: 16px;
}

.message.assistant .message-content p:last-child,
.message.assistant .message-content ul:last-child,
.message.assistant .message-content ol:last-child,
.message.assistant .message-content blockquote:last-child,
.message.assistant .message-content .message-code:last-child,
.message.assistant .message-content .message-table-wrap:last-child,
.message.assistant .message-content hr:last-child,
.message.assistant .message-content h1:last-child,
.message.assistant .message-content h2:last-child,
.message.assistant .message-content h3:last-child,
.message.assistant .message-content h4:last-child,
.message.assistant .message-content h5:last-child,
.message.assistant .message-content h6:last-child {
  margin-bottom: 0;
}

.message.assistant .message-content ul,
.message.assistant .message-content ol {
  padding-left: 22px;
}

.message.assistant .message-content li + li {
  margin-top: 6px;
}

.message.assistant .message-content strong {
  font-weight: 700;
}

.message.assistant .message-content code {
  font-family: Consolas, "SFMono-Regular", monospace;
  font-size: 0.92em;
  padding: 2px 6px;
  border-radius: 7px;
  background: var(--bg-hover);
}

.message.assistant .message-content blockquote {
  padding: 2px 0 2px 16px;
  border-left: 3px solid rgba(17, 24, 39, 0.14);
  color: var(--muted);
}

.message.assistant .message-content blockquote p {
  margin-bottom: 8px;
}

.message.assistant .message-content blockquote p:last-child {
  margin-bottom: 0;
}

.message.assistant .message-content hr {
  border: 0;
  border-top: 1px solid var(--line);
}

.message.assistant .message-content .message-code {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #0d0d0d;
}

.message.assistant .message-content .message-code-label {
  padding: 8px 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  color: #a1a1aa;
  font-size: 12px;
  font-weight: 600;
  text-transform: lowercase;
}

.message.assistant .message-content .message-code pre {
  margin: 0;
  padding: 14px 16px;
  overflow-x: auto;
  font-family: Consolas, "SFMono-Regular", monospace;
  font-size: 13px;
  line-height: 1.65;
  color: #fff;
}

.message.assistant .message-content .message-code code {
  display: block;
  padding: 0;
  background: transparent;
  border-radius: 0;
  font-size: inherit;
}

.message.assistant .message-content .message-table-wrap {
  display: block;
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.message.assistant .message-content .message-table {
  width: max-content;
  min-width: 100%;
  border-collapse: collapse;
  border-spacing: 0;
  font-size: 14px;
  table-layout: auto;
}

.message.assistant .message-content .message-table th,
.message.assistant .message-content .message-table td {
  padding: 10px 12px;
  text-align: left;
  vertical-align: top;
  border-bottom: 1px solid var(--line);
  white-space: normal;
  word-break: keep-all;
  overflow-wrap: break-word;
  min-width: 140px;
}

.message.assistant .message-content .message-table th {
  color: var(--text);
  font-weight: 700;
  background: var(--bg-soft);
  white-space: nowrap;
}

.message.assistant .message-content .store-map-card {
  margin: 10px 0 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  background: var(--bg);
  box-shadow: var(--shadow-soft);
}

.message.assistant .message-content .store-map-card img {
  display: block;
  width: 100%;
  max-height: min(560px, 70vh);
  object-fit: contain;
  background: var(--bg-soft);
}

.message.assistant .message-content .store-map-card figcaption {
  display: grid;
  gap: 3px;
  padding: 9px 10px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.message.assistant .message-content .store-map-title {
  color: var(--text);
  font-weight: 600;
}

.message.assistant .message-content .store-map-address {
  color: var(--muted);
}

.message.assistant .message-content .store-map-action {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 0 12px;
  border-top: 1px solid var(--line);
  background: var(--bg-soft);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  transition: background 0.16s ease;
}

.message.assistant .message-content .store-map-action:hover {
  background: var(--bg-hover);
}

.message.error .message-content {
  color: var(--danger);
}

.message.loading .message-content {
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-raised);
  box-shadow: var(--shadow);
}

.thinking-indicator {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.thinking-spinner {
  width: 14px;
  height: 14px;
  flex: 0 0 auto;
  border-radius: 999px;
  border: 2px solid var(--line-strong);
  border-top-color: var(--text);
  animation: thinking-spin 0.7s linear infinite;
}

.thinking-label {
  color: var(--muted);
  font-size: 14px;
}

@keyframes thinking-spin {
  to {
    transform: rotate(360deg);
  }
}

.message-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 28px;
  margin-top: 9px;
  opacity: 0;
  transform: translateY(2px);
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.message.assistant:hover .message-actions,
.message.user:hover .message-actions,
.message:focus-within .message-actions,
.message.loading .message-actions,
.message.streaming .message-actions {
  opacity: 1;
  transform: translateY(0);
}

.message-action {
  width: 30px;
  height: 30px;
  padding: 0;
  border-radius: 8px;
  color: var(--muted);
  font-size: 12px;
  border: 1px solid transparent;
  background: transparent;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.16s ease, border-color 0.16s ease, color 0.16s ease, transform 0.16s ease;
}

.message-action.feedback-action {
  width: auto;
  min-width: 44px;
  padding: 0 10px;
  font-size: 12px;
  font-weight: 600;
}

.message-action span {
  line-height: 1;
  pointer-events: none;
}

.message-action .icon-svg {
  width: 16px;
  height: 16px;
}

.message-action:hover {
  color: var(--text);
  border-color: var(--line);
  background: var(--surface-raised);
  box-shadow: var(--shadow);
}

.back-to-bottom {
  position: absolute;
  right: max(calc((100vw - var(--content-width)) / 2 - 64px), 20px);
  bottom: 132px;
  width: 38px;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--bg);
  color: var(--text);
  box-shadow: var(--shadow-soft);
  cursor: pointer;
  z-index: 4;
  transition: transform 0.16s ease, background 0.16s ease, border-color 0.16s ease;
}

.back-to-bottom:hover {
  background: var(--bg-hover);
}

.composer-wrap {
  z-index: 5;
  width: min(820px, calc(100vw - 120px));
  margin: 0 auto calc(14px + env(safe-area-inset-bottom));
  padding-top: 14px;
  padding-bottom: env(safe-area-inset-bottom);
  background: linear-gradient(180deg, transparent 0%, var(--surface-subtle) 22%, var(--surface-subtle) 100%);
  flex-shrink: 0;
}

.composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  min-height: 66px;
  padding: 11px 12px 11px 16px;
  border: 1px solid var(--line-strong);
  border-radius: 26px;
  background: var(--surface-raised);
  box-shadow: var(--shadow-composer);
  transition: border-color 0.18s ease, box-shadow 0.18s ease, transform 0.18s ease, background 0.18s ease;
}

.composer:focus-within {
  background: var(--surface-raised);
  border-color: var(--line-strong);
  box-shadow: var(--shadow-composer);
}

.composer textarea:focus-visible {
  box-shadow: none;
}

.composer textarea {
  flex: 1;
  min-height: 24px;
  max-height: 220px;
  border: 0;
  outline: 0;
  resize: none;
  background: transparent;
  color: var(--text);
  line-height: 1.68;
  padding: 8px 4px 7px;
}

.composer textarea::placeholder {
  color: var(--muted-soft);
}

.composer-right {
  display: flex;
  align-items: center;
  gap: 7px;
  flex-shrink: 0;
}

.composer-icon {
  width: 34px;
  height: 34px;
  border-radius: 999px;
  color: var(--text);
  flex: 0 0 auto;
  background: var(--bg-hover);
}

.composer-icon.muted {
  color: var(--muted);
  background: transparent;
}

.composer-cancel {
  height: 34px;
  padding: 0 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
  transition: background 0.16s ease, border-color 0.16s ease, color 0.16s ease;
}

.composer-cancel:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.send-button {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  background: #111;
  color: #fff;
  flex: 0 0 auto;
  transition: opacity 0.16s ease, transform 0.16s ease, background 0.16s ease;
}

.send-button .icon-svg {
  width: 16px;
  height: 16px;
}

.composer-wrap:not(.has-input) .send-button {
  background: var(--muted-soft);
  opacity: 0.52;
}

.composer-wrap.has-input .send-button:hover {
  background: #000;
  transform: translateY(-1px);
}

.send-button:disabled {
  opacity: 0.4;
  cursor: default;
}

.composer-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 4px 0;
  color: var(--muted);
  font-size: 12px;
}

/* 字数计数 */
.composer-counter {
  font-size: 11px;
  color: var(--muted-soft);
  font-variant-numeric: tabular-nums;
  align-self: center;
  user-select: none;
  padding: 0 4px;
  white-space: nowrap;
}

.composer-counter.warn { color: #f59e0b; }
.composer-counter.danger { color: var(--danger); }

.mobile-only {
  display: none;
}

.sidebar-scrim {
  position: fixed;
  inset: 0;
  border: 0;
  opacity: 0;
  pointer-events: none;
  background: rgba(17, 17, 17, 0.32);
  transition: opacity 0.18s ease;
}

.confirm-dialog {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 24px;
}

.confirm-dialog[hidden] {
  display: none;
}

.confirm-dialog-backdrop {
  position: absolute;
  inset: 0;
  border: 0;
  background: rgba(15, 23, 42, 0.42);
  backdrop-filter: blur(8px);
}

.confirm-dialog-card {
  position: relative;
  z-index: 1;
  width: min(420px, calc(100vw - 32px));
  display: grid;
  gap: 18px;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: var(--bg);
  box-shadow: 0 24px 60px rgba(15, 23, 42, 0.18);
}

.confirm-dialog-title {
  margin: 0;
  color: var(--text);
  font-size: 20px;
  font-weight: 700;
  line-height: 1.2;
}

.confirm-dialog-copy {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.7;
  word-break: break-word;
}

.confirm-dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.confirm-dialog-btn {
  min-width: 92px;
  min-height: 42px;
  padding: 0 16px;
  border: 1px solid transparent;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.16s ease, border-color 0.16s ease, color 0.16s ease, transform 0.16s ease;
}

.confirm-dialog-btn:hover {
  transform: translateY(-1px);
}

.confirm-dialog-btn.secondary {
  background: var(--bg-soft);
  color: var(--text);
  border-color: var(--line);
}

.confirm-dialog-btn.secondary:hover {
  background: var(--bg-hover);
}

.confirm-dialog-btn.danger {
  background: #111111;
  color: #ffffff;
}

.confirm-dialog-btn.danger:hover {
  background: #000000;
}

.form-dialog-card {
  width: min(520px, calc(100vw - 32px));
  max-height: min(760px, calc(100vh - 48px));
  overflow: auto;
}

.feedback-dialog-card {
  width: min(680px, calc(100vw - 32px));
}

.dialog-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-top: 2px;
}

.dialog-field {
  display: flex;
  flex-direction: column;
  gap: 7px;
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
}

.dialog-field input,
.dialog-field textarea {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  padding: 10px 12px;
  outline: none;
  resize: vertical;
  font-weight: 400;
  line-height: 1.55;
}

.message-sources {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-top: 10px;
  padding-top: 9px;
  border-top: 1px solid var(--line);
}

.message-sources-label {
  color: var(--muted-soft);
  font-size: 12px;
}

.message-source-chip {
  max-width: 100%;
  overflow: hidden;
  padding: 3px 7px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.attachment-link {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 4px 8px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
}

.attachment-link:hover {
  background: var(--bg-hover);
}

.password-control {
  position: relative;
  width: 100%;
}

.dialog-field .password-control input {
  padding-right: 46px;
}

.password-toggle {
  position: absolute;
  top: 50%;
  right: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transform: translateY(-50%);
  transition: background 160ms ease, color 160ms ease;
}

.password-toggle:hover,
.password-toggle:focus-visible {
  background: var(--bg-soft);
  color: var(--text);
}

.password-toggle:focus-visible {
  outline: 2px solid color-mix(in srgb, var(--text) 28%, transparent);
  outline-offset: 1px;
}

.password-icon {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.password-icon-eye-off,
.password-toggle.is-visible .password-icon-eye {
  display: none;
}

.password-toggle.is-visible .password-icon-eye-off {
  display: block;
}

.dialog-field textarea[readonly] {
  color: var(--muted);
  background: var(--bg-soft);
}

.dialog-field input:focus,
.dialog-field textarea:focus {
  border-color: var(--text);
}

.auth-mode-switch {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg-soft);
}

.oauth-login-button {
  width: 100%;
  min-height: 44px;
  border: 1px solid #1456d9;
  border-radius: 8px;
  background: #1456d9;
  color: #ffffff;
  font-size: 14px;
  font-weight: 650;
  cursor: pointer;
  transition: background 160ms ease, border-color 160ms ease, transform 160ms ease;
}

.oauth-login-button:hover {
  border-color: #0f47ba;
  background: #0f47ba;
  transform: translateY(-1px);
}

.oauth-login-button:focus-visible {
  outline: 2px solid color-mix(in srgb, #1456d9 35%, transparent);
  outline-offset: 2px;
}

.auth-divider {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 18px;
  color: var(--muted-soft);
  font-size: 12px;
}

.auth-divider::before {
  position: absolute;
  right: 0;
  left: 0;
  height: 1px;
  background: var(--line);
  content: '';
}

.auth-divider span {
  position: relative;
  padding: 0 10px;
  background: var(--bg);
}

.auth-mode-btn {
  border: none;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  padding: 8px 10px;
  cursor: pointer;
}

.auth-mode-btn.active {
  background: var(--bg);
  color: var(--text);
  box-shadow: var(--shadow);
}

.app-shell.sidebar-collapsed .sidebar {
  padding-left: 10px;
  padding-right: 10px;
  align-items: center;
}

.app-shell.sidebar-collapsed .sidebar-resize-handle {
  opacity: 0;
  pointer-events: none;
}

.app-shell.sidebar-collapsed .sidebar-header {
  width: 100%;
  flex-direction: column;
  justify-content: flex-start;
  align-items: center;
  gap: 10px;
}

.app-shell.sidebar-collapsed .sidebar-action-label,
.app-shell.sidebar-collapsed .search-box input,
.app-shell.sidebar-collapsed .account-copy,
.app-shell.sidebar-collapsed .account-actions {
  display: none;
}

.app-shell.sidebar-collapsed .history-panel {
  display: none;
}

.app-shell.sidebar-collapsed .search-box {
  justify-content: center;
  width: 40px;
  min-height: 40px;
  margin: 0 auto;
  padding: 0;
}

.app-shell.sidebar-collapsed .sidebar-actions {
  width: 100%;
  justify-items: center;
  gap: 10px;
}

.app-shell.sidebar-collapsed .sidebar-action {
  width: 40px;
  min-height: 40px;
  padding: 0;
  justify-content: center;
}

.app-shell.sidebar-collapsed .sidebar-footer {
  display: flex;
  justify-content: center;
  width: 100%;
}

@media (max-width: 960px) {
  .app-shell {
    grid-template-columns: 1fr;
    height: 100vh;
  }

  .sidebar-resize-handle {
    display: none;
  }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(82vw, 290px);
    z-index: 20;
    transform: translateX(-100%);
    transition: transform 0.22s ease;
    background: var(--bg-soft);
    border-right: 1px solid var(--line);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar.open + .sidebar-scrim {
    opacity: 1;
    pointer-events: auto;
    z-index: 15;
  }

  .confirm-dialog {
    align-items: end;
    padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
  }

  .confirm-dialog-card {
    width: min(100%, 460px);
    border-radius: 20px;
    padding: 20px;
    gap: 16px;
  }

  .confirm-dialog-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .confirm-dialog-btn {
    min-width: 0;
    min-height: 46px;
  }

  .mobile-only {
    display: inline-flex;
  }

  .topbar-right .text-button {
    display: none;
  }

  .messages,
  .empty-hero,
  .composer-wrap {
    width: min(720px, calc(100vw - 32px));
  }

  .composer-wrap {
    margin-bottom: calc(10px + env(safe-area-inset-bottom));
  }

  .back-to-bottom {
    right: 16px;
    bottom: 126px;
  }

  .starter-grid {
    grid-template-columns: 1fr;
  }

  .composer-meta {
    flex-direction: column;
    align-items: flex-start;
  }

  .session-groups {
    overflow-x: hidden;
    padding-right: 0;
  }
}

@media (max-width: 640px) {
  .composer-meta {
    display: none;
  }

  .conversation-stage {
    padding-bottom: 14px;
  }

  .messages {
    gap: 20px;
    padding-bottom: 34px;
  }

  .message-content {
    font-size: 14px;
  }

  .message.user .message-content {
    max-width: calc(100vw - 58px);
    border-radius: 16px;
    padding: 10px 14px;
  }

  .message.assistant .message-content {
    max-width: 100%;
  }

  .message-actions {
    margin-top: 7px;
  }

  .composer {
    min-height: 60px;
    border-radius: 18px;
    padding: 9px 10px 9px 14px;
  }
}

/* === 移动端 composer 浮起 + 发送按钮加大 === */
@media (max-width: 960px) {
  /* iOS Safari 输入框 < 16px 会触发自动放大,这里固定到 16px */
  .composer textarea {
    font-size: 16px;
  }

  /* 发送按钮加大到 44x44 (Apple HIG 推荐最小触控尺寸) */
  .send-button {
    width: 44px;
    height: 44px;
  }
  .send-button .icon-svg {
    width: 20px;
    height: 20px;
  }
  .composer-cancel {
    height: 40px;
    padding: 0 14px;
  }

  /* 让 composer 跟随键盘上浮（visualViewport API 写入 --keyboard-offset） */
  .composer-wrap {
    position: sticky;
    bottom: 0;
    transform: translateY(calc(-1 * var(--keyboard-offset, 0px)));
    transition: transform 0.18s ease;
  }
}

@media (max-width: 480px) {
  .topbar {
    gap: 8px;
    padding-right: 10px;
    padding-left: 10px;
  }

  .topbar-left,
  .topbar-right {
    gap: 4px;
  }

  .model-button {
    max-width: calc(100vw - 150px);
    padding: 0 8px;
  }

  .mode-switcher {
    display: none;
  }

  .messages,
  .empty-hero,
  .composer-wrap {
    width: calc(100vw - 24px);
    max-width: calc(100vw - 24px);
  }

  .empty-hero {
    padding-top: 28px;
  }

  .empty-hero h1 {
    font-size: 24px;
  }

  .confirm-dialog {
    padding-right: 12px;
    padding-left: 12px;
  }
}

@media (hover: none) {
  .message-actions {
    opacity: 1;
    transform: none;
  }
}

@keyframes message-enter {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes hero-rise {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes blink-caret {
  0%, 50% {
    opacity: 1;
  }
  50.01%, 100% {
    opacity: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .app-shell,
  .sidebar,
  .empty-hero,
  .empty-hero h1,
  .empty-hero p,
  .starter-card,
  .message,
  .message-actions,
  .message-action,
  .composer,
  .composer-wrap,
  .send-button,
  .back-to-bottom {
    animation: none;
    transition: none;
  }

  .typing-cursor,
  .thinking-spinner {
    animation: none;
  }
}

.session-card-actions {
  position: absolute;
  top: 50%;
  right: 6px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  transform: translateY(-50%);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease;
  z-index: 12;
}

.session-card:hover .session-card-actions,
.session-card.active .session-card-actions,
.session-card-actions.open {
  opacity: 1;
  pointer-events: auto;
}

.session-menu-trigger {
  position: relative;
  z-index: 2;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  padding: 0;
  border-radius: 999px;
  background: var(--bg);
  color: var(--muted);
  box-shadow: 0 0 0 1px rgba(17, 17, 17, 0.06);
}

.session-menu-trigger .icon-svg {
  display: block;
}

.session-menu-trigger:hover,
.session-card-actions.open .session-menu-trigger {
  background: var(--bg-hover);
  color: var(--text);
}

.session-actions-drawer {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  display: grid;
  gap: 2px;
  min-width: 140px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg);
  box-shadow: var(--shadow-soft);
  opacity: 0;
  pointer-events: none;
  transform: translateY(-4px) scale(0.98);
  transform-origin: top right;
  transition: opacity 0.16s ease, transform 0.16s ease;
}

.session-card-actions.drop-up .session-actions-drawer {
  top: auto;
  bottom: calc(100% + 6px);
  transform-origin: bottom right;
}

.session-card-actions.open .session-actions-drawer {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0) scale(1);
}

.session-action-btn {
  min-height: 32px;
  border-radius: 10px;
  color: var(--muted);
  background: transparent;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
  flex-shrink: 0;
}

.session-action-btn .icon-svg {
  width: 16px;
  height: 16px;
}

.session-action-btn.menu-item {
  justify-content: flex-start;
  gap: 8px;
  width: 100%;
  padding: 0 10px;
  font-size: 12px;
  font-weight: 500;
}

.session-action-btn.menu-item span {
  white-space: nowrap;
}

.session-action-btn:hover {
  background: var(--accent-soft);
  color: var(--text);
}

.session-action-btn.danger:hover {
  background: rgba(239, 68, 68, 0.1);
  color: var(--danger);
}

/* === 用户消息内联编辑 === */
.message.editing .message-actions {
  display: none;
}

.message-edit {
  background: var(--user-bubble);
  border: 1px solid var(--line-strong);
  border-radius: 14px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 280px;
}

.message-edit-input {
  width: 100%;
  resize: none;
  border: none;
  outline: none;
  background: transparent;
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  font-family: inherit;
  min-height: 48px;
  max-height: 220px;
}

.message-edit-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.message-edit-btn {
  font-size: 13px;
  padding: 6px 12px;
  border-radius: 8px;
  border: 1px solid var(--line-strong);
  background: transparent;
  color: var(--text);
  cursor: pointer;
  transition: background 0.16s ease;
}

.message-edit-btn:hover {
  background: var(--bg-hover);
}

.message-edit-btn.save {
  background: var(--text);
  color: var(--bg);
  border-color: var(--text);
}

.message-edit-btn.save:hover {
  opacity: 0.9;
}

/* === 流式打字光标 === */
.typing-cursor {
  display: inline-block;
  width: 6px;
  height: 1.05em;
  margin-left: 2px;
  vertical-align: -2px;
  background: var(--text);
  border-radius: 1px;
  animation: blink-caret 1s steps(1) infinite;
}

/* === 错误态：显眼的重试按钮 === */
.message-retry-row {
  margin-top: 10px;
  display: flex;
  justify-content: flex-start;
}

.message-retry-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--danger);
  background: rgba(239, 68, 68, 0.08);
  color: var(--danger);
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.16s ease, transform 0.12s ease;
}

.message-retry-btn:hover {
  background: rgba(239, 68, 68, 0.16);
}

.message-retry-btn:active {
  transform: scale(0.97);
}

.message-retry-btn .icon-svg {
  width: 14px;
  height: 14px;
}

/* === 「可发客户」话术卡片 === */
.script-card {
  margin: 12px 0;
  border: 1px solid rgba(16, 185, 129, 0.35);
  background: rgba(16, 185, 129, 0.08);
  border-radius: 12px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

:root.dark .script-card {
  border-color: rgba(16, 185, 129, 0.45);
  background: rgba(16, 185, 129, 0.12);
}

.script-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.script-card-label {
  font-size: 12px;
  font-weight: 600;
  color: #047857;
  letter-spacing: 0.02em;
}

:root.dark .script-card-label {
  color: #34d399;
}

.script-card-copy {
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 6px;
  border: 1px solid rgba(16, 185, 129, 0.5);
  background: transparent;
  color: #047857;
  cursor: pointer;
  transition: background 0.16s ease, color 0.16s ease;
}

.script-card-copy:hover {
  background: rgba(16, 185, 129, 0.15);
}

.script-card-copy.copied {
  background: #10b981;
  color: #fff;
  border-color: #10b981;
}

:root.dark .script-card-copy {
  color: #34d399;
}

.script-card-body {
  font-size: 15px;
  line-height: 1.6;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
}

.script-card-head-actions {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.script-card-star {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border-radius: 6px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: color 0.16s ease, background 0.16s ease, transform 0.16s ease;
}

.script-card-star:hover {
  color: #f59e0b;
  background: rgba(245, 158, 11, 0.12);
}

.script-card-star.is-saved {
  color: #f59e0b;
}

.script-card-star.is-saved svg {
  fill: currentColor;
}

.script-card-star .icon-svg {
  width: 16px;
  height: 16px;
}

/* === 话术库抽屉 === */
.library-backdrop {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(0, 0, 0, 0.32);
  border: none;
  cursor: pointer;
  padding: 0;
}

.library-drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 380px;
  max-width: 100vw;
  background: var(--bg);
  border-left: 1px solid var(--line);
  box-shadow: -8px 0 24px rgba(0, 0, 0, 0.08);
  z-index: 90;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.24s ease;
}

.library-drawer.open {
  transform: translateX(0);
}

.library-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.library-title {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
}

.library-title .icon-svg {
  width: 18px;
  height: 18px;
  fill: #f59e0b;
  stroke: none;
}

.library-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
}

.library-search {
  flex: 1;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 10px;
  background: var(--bg-soft);
  border: 1px solid var(--line);
}

.library-search .icon-svg {
  width: 16px;
  height: 16px;
  color: var(--muted);
}

.library-search input {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  color: var(--text);
  font-size: 14px;
}

.library-add-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--text);
  cursor: pointer;
  transition: background 0.16s ease;
}

.library-add-btn:hover {
  background: var(--bg-hover);
}

.library-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 16px 12px;
}

.library-filter-chip {
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  color: var(--muted);
  cursor: pointer;
  transition: background 0.16s ease, color 0.16s ease, border-color 0.16s ease;
}

.library-filter-chip:hover {
  background: var(--bg-hover);
}

.library-filter-chip.active {
  background: var(--text);
  color: var(--bg);
  border-color: var(--text);
}

.library-list {
  flex: 1;
  overflow-y: auto;
  padding: 0 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.library-empty {
  padding: 32px 24px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}

.library-item {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: border-color 0.16s ease, box-shadow 0.16s ease;
}

.library-item:hover {
  border-color: var(--line-strong);
  box-shadow: var(--shadow);
}

.library-item-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.library-item-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  min-width: 0;
}

.library-item-category {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(245, 158, 11, 0.12);
  color: #b45309;
  white-space: nowrap;
}

:root.dark .library-item-category {
  background: rgba(245, 158, 11, 0.18);
  color: #fbbf24;
}

.library-item-content {
  font-size: 13px;
  line-height: 1.5;
  color: var(--muted);
  margin: 0;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  white-space: pre-wrap;
  word-break: break-word;
}

.library-item-actions {
  position: relative;
  min-height: 30px;
}

.library-item-actions-default,
.library-item-actions-confirm {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  align-items: center;
  transition: transform 0.22s ease, opacity 0.18s ease;
}

.library-item-actions-confirm {
  position: absolute;
  inset: 0;
  transform: translateX(16px);
  opacity: 0;
  pointer-events: none;
  background: var(--bg);
}

.library-item.confirming .library-item-actions-default {
  transform: translateX(-16px);
  opacity: 0;
  pointer-events: none;
}

.library-item.confirming .library-item-actions-confirm {
  transform: translateX(0);
  opacity: 1;
  pointer-events: auto;
}

.library-item-confirm-label {
  font-size: 13px;
  color: var(--danger);
  font-weight: 500;
  margin-right: 2px;
}

.library-item-btn {
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--text);
  cursor: pointer;
  transition: background 0.16s ease;
}

.library-item-btn:hover {
  background: var(--bg-hover);
}

.library-item-btn.primary {
  background: var(--text);
  color: var(--bg);
  border-color: var(--text);
}

.library-item-btn.primary:hover {
  opacity: 0.9;
}

.library-item-btn.danger:hover {
  background: rgba(239, 68, 68, 0.1);
  color: var(--danger);
  border-color: rgba(239, 68, 68, 0.4);
}

/* 保存弹窗字段 */
.script-save-card {
  max-width: 460px;
  width: 92vw;
}

.script-save-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 12px;
  font-size: 13px;
  color: var(--muted);
}

.script-save-field span {
  color: var(--text);
  font-weight: 500;
}

.script-save-field input,
.script-save-field textarea {
  width: 100%;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--bg-soft);
  color: var(--text);
  padding: 8px 10px;
  font-family: inherit;
  font-size: 14px;
  outline: none;
  resize: vertical;
}

.script-save-field input:focus,
.script-save-field textarea:focus {
  border-color: var(--line-strong);
}

/* 分类选择器（点击展开） */
.category-picker {
  position: relative;
}

.category-picker-trigger {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--bg-soft);
  color: var(--text);
  cursor: pointer;
  font-family: inherit;
  font-size: 14px;
  text-align: left;
  transition: border-color 0.16s ease;
}

.category-picker-trigger:hover,
.category-picker-trigger.open {
  border-color: var(--line-strong);
}

.category-picker-trigger .icon-svg {
  width: 14px;
  height: 14px;
  color: var(--muted);
  transition: transform 0.18s ease;
}

.category-picker-trigger.open .icon-svg {
  transform: rotate(180deg);
}

.category-picker-menu {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow-soft);
  z-index: 10;
  padding: 4px;
}

.category-picker-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-height: 200px;
  overflow-y: auto;
}

.category-picker-option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  border-radius: 6px;
  border: none;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  font-size: 14px;
  font-family: inherit;
  text-align: left;
  width: 100%;
}

.category-picker-option:hover {
  background: var(--bg-hover);
}

.category-picker-option.active {
  background: var(--accent-soft);
  font-weight: 500;
}

.category-picker-option .icon-svg {
  width: 14px;
  height: 14px;
  color: #f59e0b;
}

.category-picker-create {
  display: flex;
  gap: 4px;
  padding: 6px 4px 2px;
  border-top: 1px solid var(--line);
  margin-top: 4px;
}

.category-picker-create input {
  flex: 1;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--bg-soft);
  color: var(--text);
  padding: 6px 8px;
  font-size: 13px;
  font-family: inherit;
  outline: none;
}

.category-picker-add {
  padding: 6px 12px;
  border-radius: 6px;
  border: 1px solid var(--text);
  background: var(--text);
  color: var(--bg);
  cursor: pointer;
  font-size: 13px;
  font-family: inherit;
}

.category-picker-add:hover {
  opacity: 0.9;
}

/* === 全局 toast === */
.app-toast {
  position: fixed;
  bottom: 32px;
  left: 50%;
  transform: translateX(-50%) translateY(10px);
  background: var(--text);
  color: var(--bg);
  font-size: 13px;
  padding: 8px 16px;
  border-radius: 999px;
  z-index: 200;
  box-shadow: var(--shadow-soft);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.app-toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

@media (max-width: 600px) {
  .library-drawer {
    width: 100vw;
  }
}
