:root {
  color-scheme: light;
  --app-height: 100dvh;
  --bg: #f5f2ec;
  --panel: #fffdfa;
  --panel-strong: #ffffff;
  --ink: #161616;
  --muted: #6c6a64;
  --line: #ded8ce;
  --line-strong: #c9c1b4;
  --accent: #256e5d;
  --accent-dark: #164a40;
  --accent-soft: #d9ebe4;
  --warm: #c85c3f;
  --warm-soft: #f6ded6;
  --shadow: 0 18px 45px rgba(39, 34, 26, 0.13);
  --radius: 8px;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-width: 320px;
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--ink);
}

body.key-locked {
  overflow: hidden;
}

body.key-locked::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 40;
  background: var(--bg);
}

body.key-locked .app-shell {
  visibility: hidden;
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  position: relative;
  display: block;
  width: 100%;
  height: var(--app-height);
  overflow: hidden;
}

.sidebar {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  border-right: 1px solid var(--line);
  background: #eee8df;
  padding: 18px;
  gap: 12px;
}

.brand-row {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 44px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--accent-dark);
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0;
}

.brand-title {
  font-weight: 800;
  line-height: 1.1;
}

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

.account-panel {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.metric {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  padding: 12px;
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.metric strong {
  display: block;
  margin-top: 6px;
  overflow: hidden;
  color: var(--ink);
  font-size: 18px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.toolbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 42px 42px;
  gap: 8px;
  align-items: end;
}

.mode-chip {
  display: flex;
  align-items: center;
  min-width: 0;
  height: 38px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--accent-dark);
  font-size: 13px;
  font-weight: 800;
  padding: 0 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-strip {
  display: flex;
  align-items: center;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 253, 250, 0.82);
  color: var(--muted);
  font-size: 12px;
  padding: 0 10px;
  gap: 10px;
  white-space: nowrap;
}

.status-strip span {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.status-strip strong {
  color: var(--ink);
}

body.home-view .mode-chip,
body.home-view .message-search-toggle,
body.home-view .conversation-search,
body.home-view #historyButton,
body.home-view #refreshButton,
body.home-view .login-status,
body.home-view .composer {
  display: none;
}

body.home-view .conversation {
  grid-template-rows: auto minmax(0, 1fr);
}

body.home-view .conversation-header {
  border-bottom: 0;
  background: var(--panel-strong);
}

body.home-view .title-block {
  display: none;
}

body.home-view .header-actions {
  margin-left: auto;
}

.field {
  display: grid;
  gap: 6px;
  min-width: 0;
}

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

.field input,
.field textarea,
textarea {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-strong);
  color: var(--ink);
  outline: none;
}

.field input {
  height: 42px;
  padding: 0 12px;
}

.field input:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.icon-button,
.text-button,
.send-button {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  transition:
    background 0.16s ease,
    border-color 0.16s ease,
    transform 0.16s ease;
}

.icon-button {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  background: var(--panel);
  color: var(--ink);
  font-weight: 800;
}

.icon-button:hover,
.text-button:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.icon-button:active,
.text-button:active,
.send-button:active {
  transform: translateY(1px);
}

.search-field input {
  background: rgba(255, 253, 250, 0.74);
}

.history-search-meta {
  margin-top: -5px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.history-search-controls {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto 36px;
  align-items: end;
  gap: 8px;
}

.history-search-controls .field {
  min-width: 0;
}

.history-search-controls > button {
  min-height: 36px;
}

.history-search-controls .icon-button {
  width: 36px;
  height: 36px;
}

.chat-section-actions,
.history-selection-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 7px;
}

.history-selection-toolbar {
  border-block: 1px solid var(--line);
  padding-block: 8px;
}

.history-selection-toolbar[hidden] {
  display: none;
}

.history-selection-toolbar strong {
  margin-right: auto;
  font-size: 13px;
}

.history-export-format {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
}

.history-export-format select {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: var(--text);
  padding: 0 28px 0 9px;
}

.chat-selection-checkbox {
  width: 22px;
  height: 22px;
  margin: 0;
  accent-color: var(--accent);
}

.chat-item.selection-active {
  cursor: pointer;
}

.chat-item.selection-active.selected {
  border-color: var(--accent);
  background: var(--soft-green);
}

.section-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}

.mode-list {
  display: grid;
  grid-template-columns: 1fr;
  flex: 0 1 45%;
  min-height: 190px;
  overflow-y: auto;
  padding-right: 2px;
  gap: 9px;
}

.chat-section {
  display: flex;
  flex: 1 1 230px;
  flex-direction: column;
  min-height: 170px;
  gap: 10px;
}

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

.chat-section-header span,
.chat-section-header strong {
  display: block;
}

.chat-section-header span {
  color: var(--ink);
  font-size: 13px;
  font-weight: 800;
}

.chat-section-header strong {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.new-chat-button {
  min-height: 34px;
  white-space: nowrap;
}

.load-more-button {
  flex: 0 0 auto;
  min-height: 36px;
}

.load-more-button[hidden] {
  display: none;
}

.chat-list {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-height: 0;
  overflow-y: auto;
  padding-right: 2px;
  gap: 8px;
}

.mode-item {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr);
  align-items: center;
  width: 100%;
  min-height: 72px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--radius);
  background:
    linear-gradient(135deg, color-mix(in srgb, var(--mode-accent) 26%, transparent), transparent 70%),
    rgba(255, 253, 250, 0.7);
  color: var(--ink);
  padding: 11px;
  gap: 10px;
  text-align: left;
}

.mode-item:hover,
.mode-item.active {
  border-color: var(--mode-accent);
  background:
    linear-gradient(135deg, color-mix(in srgb, var(--mode-accent) 34%, transparent), transparent 70%),
    #fffdfa;
}

.mode-item.active {
  box-shadow: inset 3px 0 0 var(--mode-accent);
}

.mode-mark {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border: 1px solid var(--mode-accent);
  border-radius: 50%;
  color: var(--mode-accent);
  font-weight: 900;
}

.mode-name,
.mode-desc {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mode-name {
  font-size: 14px;
  font-weight: 850;
}

.mode-desc {
  margin-top: 5px;
  color: var(--muted);
  font-size: 12px;
}

.chat-item {
  display: grid;
  flex: 0 0 auto;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  width: 100%;
  min-height: 70px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: rgba(255, 253, 250, 0.72);
  padding: 12px;
  text-align: left;
}

.chat-actions {
  display: grid;
  justify-items: end;
  gap: 8px;
  min-width: 32px;
}

.chat-action-buttons {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
}

.chat-item:hover {
  border-color: var(--line-strong);
  background: var(--panel);
}

.chat-item.active {
  border-color: var(--accent);
  background: #f8fffb;
  box-shadow: inset 3px 0 0 var(--accent);
}

.chat-title,
.chat-preview {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-title {
  font-weight: 750;
}

.chat-preview {
  margin-top: 7px;
  color: var(--muted);
  font-size: 13px;
}

.chat-id {
  align-self: start;
  color: var(--muted);
  font-size: 12px;
}

.chat-quota {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 253, 250, 0.74);
  color: var(--accent-dark);
  font-size: 11px;
  font-weight: 750;
  line-height: 1;
  padding: 5px 7px;
  white-space: nowrap;
}

.chat-delete-button,
.chat-rename-button {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  color: var(--muted);
  font-size: 20px;
  line-height: 1;
}

.chat-rename-button:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-dark);
}

.chat-rename-button {
  font-size: 12px;
  font-weight: 750;
  white-space: nowrap;
}

.chat-delete-button:hover {
  border-color: var(--warm);
  background: var(--warm-soft);
  color: #7a2e1d;
}

.chat-delete-button:focus-visible,
.chat-rename-button:focus-visible {
  border-color: var(--warm);
  outline: 3px solid var(--warm-soft);
}

.history-drawer {
  position: fixed;
  inset: 0 0 0 auto;
  z-index: 20;
  display: flex;
  flex-direction: column;
  width: min(380px, calc(100vw - 28px));
  min-width: 0;
  min-height: 0;
  border-left: 1px solid var(--line);
  background: #eee8df;
  padding: 16px;
  gap: 12px;
  box-shadow: var(--shadow);
  transform: translateX(104%);
  transition: transform 0.2s ease;
}

body.history-open .history-drawer {
  transform: translateX(0);
}

.drawer-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 42px;
  align-items: center;
  gap: 10px;
}

.drawer-header strong {
  display: block;
  min-width: 0;
  overflow: hidden;
  color: var(--ink);
  font-size: 16px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.drawer-backdrop {
  position: fixed;
  inset: 0;
  z-index: 15;
  background: rgba(22, 22, 22, 0.22);
}

.conversation {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  min-width: 0;
  height: var(--app-height);
  background: var(--panel-strong);
}

.conversation-header {
  display: flex;
  align-items: center;
  min-width: 0;
  min-height: 54px;
  border-bottom: 1px solid var(--line);
  padding: 8px 16px;
  gap: 12px;
}

.title-block {
  flex: 1;
  min-width: 0;
}

.title-block h1 {
  margin: 0;
  overflow: hidden;
  font-size: 15px;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.title-block div {
  margin-top: 2px;
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.header-actions {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  min-width: 0;
  gap: 8px;
}

.message-search-toggle {
  min-height: 38px;
  white-space: nowrap;
}

.text-button {
  min-height: 38px;
  background: var(--panel);
  color: var(--ink);
  padding: 0 13px;
}

.messages {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow-y: auto;
  overflow-anchor: none;
  padding: 18px clamp(14px, 3vw, 42px);
  gap: 16px;
}

.home-panel {
  width: min(860px, 100%);
  margin: auto;
}

.home-balance {
  display: inline-flex;
  flex-wrap: wrap;
  min-width: min(360px, 100%);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  padding: 14px 16px;
  box-shadow: 0 8px 24px rgba(35, 31, 26, 0.06);
  gap: 14px 22px;
}

.home-balance div {
  display: grid;
  gap: 5px;
}

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

.home-balance strong {
  color: var(--accent-dark);
  font-size: 24px;
  line-height: 1.15;
}

.home-balance .home-expire-value {
  color: var(--ink);
  font-size: 18px;
}

.home-panel h2 {
  margin: 22px 0 16px;
  color: var(--ink);
  font-size: clamp(24px, 4vw, 38px);
}

.home-panel p {
  margin: 8px 0 20px;
  color: var(--muted);
}

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

.home-mode-card {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr);
  align-items: center;
  min-height: 78px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background:
    linear-gradient(135deg, color-mix(in srgb, var(--mode-accent) 20%, transparent), transparent 72%),
    var(--panel);
  color: var(--ink);
  padding: 12px;
  gap: 10px;
  text-align: left;
}

.home-mode-card:hover,
.home-mode-card.active {
  border-color: var(--mode-accent);
  background:
    linear-gradient(135deg, color-mix(in srgb, var(--mode-accent) 30%, transparent), transparent 72%),
    var(--panel-strong);
}

.home-mode-mark {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 1px solid var(--mode-accent);
  border-radius: 50%;
  color: var(--mode-accent);
  font-weight: 900;
}

.home-mode-card strong,
.home-mode-card small {
  display: block;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.home-mode-card strong {
  font-size: 14px;
}

.home-mode-card small {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.empty-state {
  display: grid;
  align-content: center;
  justify-items: center;
  min-height: 100px;
  height: 100%;
  color: var(--muted);
  text-align: center;
}

.chat-list .empty-state {
  min-height: 120px;
  padding: 12px;
}

.chat-list .empty-state p {
  margin: 0;
  font-size: 13px;
}

.empty-state h2 {
  margin: 0;
  color: var(--ink);
  font-size: clamp(24px, 4vw, 42px);
  letter-spacing: 0;
}

.empty-state p {
  margin: 12px 0 0;
}

.message-row {
  display: flex;
  width: 100%;
}

.message-row.user {
  justify-content: flex-end;
}

.bubble {
  max-width: min(760px, 78%);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 13px 15px;
  line-height: 1.65;
  overflow-wrap: anywhere;
  box-shadow: 0 8px 25px rgba(35, 31, 26, 0.06);
}

.bubble-header {
  margin-bottom: 8px;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  opacity: 0.82;
}

.copy-button,
.speak-button {
  flex: 0 0 auto;
  min-height: 28px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgba(255, 253, 250, 0.76);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
  padding: 0 8px;
}

.speak-button {
  width: 34px;
  padding: 0;
  font-size: 14px;
}

.copy-button:hover,
.speak-button:hover,
.speak-button[data-speech-state="playing"] {
  border-color: var(--line-strong);
  color: var(--ink);
}

.bubble-body {
  white-space: normal;
}

.bubble-body > :first-child {
  margin-top: 0;
}

.bubble-body > :last-child {
  margin-bottom: 0;
}

.bubble-body p {
  margin: 0 0 0.72em;
}

.bubble-body h3,
.bubble-body h4,
.bubble-body h5,
.bubble-body h6 {
  margin: 1em 0 0.45em;
  color: var(--ink);
  font-size: 15px;
  line-height: 1.45;
}

.bubble-body ul,
.bubble-body ol {
  margin: 0 0 0.78em;
  padding-left: 1.35em;
}

.bubble-body li {
  margin: 0.28em 0 0.72em;
}

.bubble-body li:last-child {
  margin-bottom: 0;
}

.bubble-body blockquote {
  margin: 0 0 0.8em;
  border-left: 3px solid var(--warm);
  padding-left: 0.85em;
  color: var(--muted);
}

.bubble-body code {
  border: 1px solid var(--line);
  border-radius: 5px;
  background: rgba(35, 31, 26, 0.06);
  padding: 1px 5px;
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  font-size: 0.92em;
}

.bubble-body pre {
  margin: 0 0 0.9em;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #211f1b;
  color: #fffdfa;
  padding: 10px 12px;
  white-space: pre;
}

.bubble-body pre code {
  border: 0;
  background: transparent;
  color: inherit;
  padding: 0;
}

.bubble-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 10px;
  color: var(--muted);
  font-size: 12px;
}

.bubble-footer span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.search-hit {
  border-radius: 3px;
  background: #ffe182;
  color: #261b00;
  padding: 0 2px;
}

.search-hit.active {
  background: #f28c28;
  color: #ffffff;
  box-shadow: 0 0 0 2px rgba(242, 140, 40, 0.28);
}

.message-row.user .bubble {
  border-color: #a9cfc3;
  background: var(--accent);
  color: white;
}

.message-row.user .bubble-footer,
.message-row.user .bubble-header {
  color: rgba(255, 255, 255, 0.84);
}

.message-row.user .copy-button {
  border-color: rgba(255, 255, 255, 0.32);
  background: rgba(255, 255, 255, 0.14);
  color: rgba(255, 255, 255, 0.92);
}

.message-row.user .speak-button {
  border-color: rgba(255, 255, 255, 0.32);
  background: rgba(255, 255, 255, 0.14);
  color: rgba(255, 255, 255, 0.92);
}

.message-row.user .copy-button:hover,
.message-row.user .speak-button:hover,
.message-row.user .speak-button[data-speech-state="playing"] {
  border-color: rgba(255, 255, 255, 0.55);
  color: #ffffff;
}

.message-row.assistant .bubble {
  background: #f8f5ef;
}

.message-row.system .bubble {
  margin: 0 auto;
  border-color: var(--warm-soft);
  background: var(--warm-soft);
  color: #7a2e1d;
  font-size: 13px;
}

.raw-panel {
  grid-row: 2;
  min-height: 0;
  overflow: auto;
  border-bottom: 1px solid var(--line);
  background: #191815;
  color: #f5f2ec;
  padding: 18px;
}

.raw-panel pre {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
}

.composer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 88px;
  align-items: end;
  gap: 8px;
  border-top: 1px solid var(--line);
  background: #fbfaf7;
  padding: 10px clamp(12px, 3vw, 22px);
}

.quick-prompts {
  grid-column: 1 / -1;
  display: flex;
  min-width: 0;
  min-height: 30px;
  gap: 7px;
  overflow-x: auto;
  scrollbar-width: thin;
}

.selection-toolbar {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 7px;
}

.selection-toolbar[hidden] {
  display: none;
}

.selection-toolbar > strong {
  margin-right: auto;
  font-size: 13px;
}

.quick-prompts[hidden] {
  display: none;
}

.quick-prompt {
  flex: 0 0 auto;
  height: 30px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-strong);
  color: var(--ink);
  padding: 0 11px;
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}

.quick-prompt:hover,
.quick-prompt:focus-visible {
  border-color: var(--accent);
  outline: none;
}

.message-row.selecting {
  align-items: flex-start;
  gap: 10px;
}

.message-select-control {
  flex: 0 0 auto;
  width: 20px;
  height: 20px;
  margin: 12px 0 0;
  accent-color: var(--accent);
}

.message-row.selected .bubble {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.conversation-search {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 30;
  display: grid;
  grid-template-columns: minmax(180px, 280px) auto;
  align-items: center;
  min-width: 0;
  width: min(520px, calc(100vw - 28px));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
  padding: 10px;
  gap: 8px;
}

.conversation-search[hidden] {
  display: none;
}

.conversation-search-field {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.conversation-search-field span {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.conversation-search-field input {
  width: 100%;
  min-width: 0;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-strong);
  color: var(--ink);
  outline: none;
  padding: 0 10px;
}

.search-nav {
  display: grid;
  grid-template-columns: 34px minmax(46px, auto) 34px;
  align-items: center;
  gap: 6px;
}

.search-nav-button {
  width: 34px;
  height: 34px;
  font-size: 20px;
  line-height: 1;
}

.search-count {
  min-width: 46px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
  text-align: center;
  white-space: nowrap;
}

.composer textarea {
  min-height: 44px;
  max-height: 160px;
  resize: none;
  overflow-y: auto;
  padding: 11px 12px;
  line-height: 1.45;
}

.send-button {
  min-height: 44px;
  border-color: var(--accent);
  background: var(--accent);
  color: white;
  font-weight: 800;
}

.send-button:hover {
  background: var(--accent-dark);
}

.send-button:disabled,
.icon-button:disabled,
.text-button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.key-dialog {
  width: min(480px, calc(100vw - 28px));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--ink);
  padding: 0;
  box-shadow: var(--shadow);
}

body.key-locked .key-dialog {
  position: fixed;
  top: 50%;
  left: 50%;
  z-index: 50;
  display: block;
  max-height: calc(100dvh - 28px);
  margin: 0;
  overflow: auto;
  transform: translate(-50%, -50%);
}

.key-dialog::backdrop {
  background: rgba(22, 22, 22, 0.44);
}

.key-form {
  display: grid;
  gap: 18px;
  padding: 20px;
}

.key-form h2 {
  margin: 0;
  font-size: 20px;
}

.key-form p {
  margin: 6px 0 0;
  color: var(--muted);
}

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

.auth-tabs .text-button.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-dark);
  font-weight: 800;
}

.auth-account-fields {
  display: grid;
  gap: 12px;
}

.email-check-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: 8px;
}

.email-check-row .text-button {
  min-height: 42px;
  white-space: nowrap;
}

.auth-hint {
  margin-top: -5px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.auth-hint.ok {
  color: #167a43;
}

.auth-hint.warn {
  color: #b35218;
}

.email-code-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: 8px;
}

.email-code-row[hidden] {
  display: none;
}

.email-code-row .text-button {
  min-height: 42px;
  white-space: nowrap;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.dialog-actions [hidden] {
  display: none;
}

.manual-copy-dialog {
  width: min(640px, calc(100vw - 28px));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--ink);
  padding: 0;
  box-shadow: var(--shadow);
}

.manual-copy-dialog::backdrop {
  background: rgba(22, 22, 22, 0.44);
}

.manual-copy-panel {
  display: grid;
  max-height: calc(100dvh - 28px);
  padding: 18px;
  gap: 14px;
}

.manual-copy-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 44px;
  align-items: start;
  gap: 12px;
}

.manual-copy-header h2 {
  margin: 0;
  font-size: 20px;
}

.manual-copy-header .icon-button,
.manual-copy-panel .dialog-actions .text-button {
  min-height: 44px;
}

.manual-copy-header .icon-button {
  width: 44px;
  height: 44px;
}

#manualCopyText {
  width: 100%;
  min-height: min(320px, 48dvh);
  overflow: auto;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #fffdfa;
  color: var(--ink);
  padding: 12px;
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  font-size: 13px;
  line-height: 1.55;
  white-space: pre;
  user-select: text;
}

.account-dialog {
  width: min(480px, calc(100vw - 28px));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--ink);
  padding: 0;
  box-shadow: var(--shadow);
}

.account-dialog::backdrop {
  background: rgba(22, 22, 22, 0.44);
}

.account-panel-form {
  display: grid;
  padding: 20px;
  gap: 16px;
}

.account-dialog-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 42px;
  align-items: start;
  gap: 12px;
}

.account-dialog-header h2 {
  margin: 0;
  font-size: 20px;
}

.account-dialog-header p {
  margin: 6px 0 0;
  color: var(--muted);
}

.account-summary {
  display: grid;
  grid-template-columns: 1fr 1fr;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-strong);
  overflow: hidden;
}

.account-summary div {
  display: grid;
  min-width: 0;
  padding: 13px;
  gap: 6px;
}

.account-summary div + div {
  border-left: 1px solid var(--line);
}

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

.account-summary strong {
  min-width: 0;
  overflow: hidden;
  color: var(--ink);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.account-dialog-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
}

.danger-button {
  border-color: var(--warm);
  background: var(--warm);
}

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

.admin-dialog {
  width: min(760px, calc(100vw - 28px));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--ink);
  padding: 0;
  box-shadow: var(--shadow);
}

.admin-dialog::backdrop {
  background: rgba(22, 22, 22, 0.44);
}

.admin-form {
  display: grid;
  max-height: min(720px, calc(100dvh - 28px));
  padding: 18px;
  gap: 14px;
}

.admin-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 42px;
  align-items: start;
  gap: 12px;
}

.admin-header h2 {
  margin: 0;
}

.admin-header p {
  margin: 6px 0 0;
  color: var(--muted);
}

.admin-section {
  display: grid;
  gap: 10px;
}

.admin-section[hidden] {
  display: none;
}

.admin-section-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}

.admin-section-title span {
  color: var(--muted);
  font-size: 12px;
}

.admin-upstream-list {
  display: grid;
  gap: 10px;
}

.admin-history-form {
  display: grid;
  grid-template-columns: minmax(150px, 0.72fr) minmax(180px, 1fr) auto;
  gap: 8px;
}

.admin-history-form select,
.admin-history-form input {
  width: 100%;
  min-width: 0;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #fffdfa;
  color: var(--ink);
  padding: 0 9px;
  font: inherit;
}

.admin-history-results {
  display: grid;
  max-height: 260px;
  overflow-y: auto;
  gap: 8px;
}

.admin-history-more {
  justify-self: center;
}

.admin-history-import {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.admin-history-import[hidden] {
  display: none;
}

.admin-history-import input {
  width: 100%;
  min-width: 0;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #fffdfa;
  color: var(--ink);
  padding: 0 9px;
  font: inherit;
}

.admin-history-select {
  width: 22px;
  height: 22px;
  margin: 0;
  accent-color: var(--accent);
}

.admin-history-row-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.admin-history-detail {
  grid-column: 1 / -1;
  max-height: 18rem;
  margin: 8px 0 0;
  padding: 10px;
  overflow: auto;
  white-space: pre-wrap;
  background: var(--surface-muted);
  border: 1px solid var(--line);
  font: inherit;
  font-size: 0.85rem;
}

.admin-history-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  border-block: 1px solid var(--line);
  padding: 10px 2px;
  gap: 10px;
}

.admin-history-row:first-child {
  border-top: 0;
}

.admin-history-row:last-child {
  border-bottom: 0;
}

.admin-history-row strong,
.admin-history-row span {
  display: block;
}

.admin-history-row span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.admin-users {
  display: grid;
  max-height: 560px;
  overflow: auto;
  gap: 10px;
}

.admin-user-row,
.admin-upstream-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-strong);
  padding: 12px;
  gap: 12px;
}

/* The dialog is narrower than the desktop viewport. Keep user actions in a
   full-width row so the history control cannot collide with quota controls. */
.admin-user-row {
  grid-template-columns: minmax(0, 1fr);
}

.admin-user-row[aria-busy="true"] {
  opacity: 0.72;
}

.admin-user-info {
  min-width: 0;
}

.admin-user-row strong,
.admin-user-row span {
  display: block;
}

.admin-user-row span {
  margin-top: 5px;
  color: var(--muted);
  font-size: 12px;
}

.admin-status-badge {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 9px;
  background: var(--soft-green);
  color: var(--ink);
  font-size: 12px;
  white-space: nowrap;
}

.admin-status-badge.error {
  background: var(--soft-warm);
}

.admin-mode-button[aria-pressed="true"] {
  border-color: #191815;
  background: #191815;
  color: #fffdfa;
}

.admin-locked-label {
  align-self: center;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.admin-user-actions {
  display: flex;
  width: 100%;
  flex-wrap: wrap;
  justify-content: flex-start;
  gap: 7px;
}

.admin-grant-form {
  display: grid;
  grid-template-columns: 76px auto auto;
  gap: 7px;
}

.admin-lookup-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  margin-top: 12px;
}

.admin-grant-form input,
.admin-lookup-form input {
  width: 100%;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #fffdfa;
  color: var(--ink);
  padding: 0 9px;
  font: inherit;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 60;
  max-width: min(420px, calc(100vw - 36px));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #191815;
  color: #fffdfa;
  padding: 12px 14px;
  box-shadow: var(--shadow);
}

.mobile-only {
  display: none;
}

@media (max-width: 820px) {
  .conversation-header {
    min-height: 50px;
    padding: 7px 8px;
    gap: 7px;
  }

  .title-block h1 {
    font-size: 14px;
  }

  .title-block div,
  .status-strip,
  .mode-chip {
    font-size: 11px;
  }

  .header-actions {
    gap: 6px;
  }

  .header-actions .mode-chip,
  .status-strip {
    display: none;
  }

  #historyButton {
    min-height: 36px;
    padding: 0 10px;
    font-size: 13px;
  }

  #keyButton {
    min-height: 36px;
    max-width: 104px;
    overflow: hidden;
    padding: 0 10px;
    font-size: 13px;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  #refreshButton {
    width: 36px;
    height: 36px;
  }

  #historyButton::before {
    content: "会话";
  }

  #historyButton {
    font-size: 0;
  }

  #historyButton::before {
    font-size: 13px;
  }

  .messages {
    padding: 14px 12px;
  }

  .bubble {
    max-width: 96%;
  }

  .home-mode-grid {
    grid-template-columns: 1fr;
    gap: 9px;
  }

  .home-mode-card {
    min-height: 64px;
    padding: 10px;
  }

  .history-drawer {
    width: min(92vw, 360px);
    padding: 12px;
  }

  .history-search-controls {
    grid-template-columns: minmax(0, 1fr) auto 44px;
  }

  .history-search-controls > button,
  .history-search-controls .icon-button,
  .chat-section-actions button,
  .history-selection-toolbar button {
    min-height: 44px;
  }

  .history-export-format select {
    min-height: 44px;
  }

  .history-search-controls .icon-button {
    width: 44px;
    height: 44px;
  }

  .chat-actions {
    min-width: 92px;
  }

  .chat-delete-button,
  .chat-rename-button {
    width: 44px;
    height: 44px;
  }

  .composer {
    grid-template-columns: minmax(0, 1fr) 74px;
    gap: 7px;
    padding: 7px 10px max(7px, env(safe-area-inset-bottom));
  }

  .composer textarea {
    min-height: 42px;
    max-height: 132px;
    font-size: 16px;
    line-height: 1.38;
    padding: 10px 11px;
  }

  .composer .send-button {
    min-height: 42px;
    font-size: 15px;
  }

  .conversation-search {
    right: 0;
    grid-template-columns: minmax(0, 1fr) auto;
    width: min(360px, calc(100vw - 16px));
    gap: 6px;
  }

  .conversation-search-field {
    grid-template-columns: minmax(0, 1fr);
    gap: 4px;
  }

  .conversation-search-field span {
    display: none;
  }

  .conversation-search-field input {
    height: 32px;
  }

  .email-code-row {
    grid-template-columns: 1fr;
  }

  .email-check-row {
    grid-template-columns: 1fr;
  }

  .account-summary,
  .account-dialog-actions {
    grid-template-columns: 1fr;
  }

  .account-summary div + div {
    border-top: 1px solid var(--line);
    border-left: 0;
  }

  .admin-user-row {
    grid-template-columns: 1fr;
  }

  .admin-user-actions {
    justify-content: stretch;
  }

  .admin-user-actions > button,
  .admin-grant-form {
    flex: 1 1 auto;
  }

  .admin-grant-form {
    grid-template-columns: minmax(72px, 1fr) auto auto;
  }

  .admin-user-actions button,
  .admin-grant-form input {
    min-height: 44px;
  }

  .admin-history-form {
    grid-template-columns: 1fr;
  }

  .admin-history-import {
    grid-template-columns: 1fr;
  }

  .admin-history-import input,
  .admin-history-import button {
    min-height: 44px;
  }

  .admin-history-form select,
  .admin-history-form input,
  .admin-history-form button {
    min-height: 44px;
  }

  .admin-history-row {
    grid-template-columns: 1fr;
  }

  .search-nav {
    grid-template-columns: 32px minmax(42px, auto) 32px;
    justify-content: end;
  }

  .search-nav-button {
    width: 32px;
    height: 32px;
  }

  .send-button {
    padding-inline: 0;
  }
}
