:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-muted: #f0f3f6;
  --surface-strong: #111827;
  --border: #d9dee7;
  --border-strong: #c2cad6;
  --text-main: #101828;
  --text-muted: #667085;
  --text-soft: #98a2b3;
  --accent: #0f766e;
  --accent-strong: #0d9488;
  --accent-soft: #e6f5f3;
  --warning: #b45309;
  --warning-soft: #fff7ed;
  --danger: #b42318;
  --danger-soft: #fff1f0;
  --shadow: 0 18px 45px rgba(15, 23, 42, 0.08);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  font-family: "Noto Sans SC", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text-main);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.88), rgba(246, 247, 249, 0.96)),
    repeating-linear-gradient(90deg, rgba(15, 23, 42, 0.025) 0 1px, transparent 1px 72px);
}

.login-overlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(246, 247, 249, 0.94);
}

.login-overlay[hidden] {
  display: none;
}

.login-panel {
  display: grid;
  gap: 14px;
  width: min(420px, 100%);
  padding: 24px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.login-panel h1 {
  margin: 0 0 4px;
  font-size: 24px;
  letter-spacing: 0;
}

.login-error {
  min-height: 20px;
  margin: 0;
  color: var(--danger);
  font-size: 13px;
}

button,
input,
textarea {
  font: inherit;
}

button {
  min-height: 42px;
}

.app-shell {
  display: grid;
  grid-template-columns: 344px minmax(0, 1fr);
  gap: 18px;
  width: min(1500px, 100%);
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0 auto;
  padding: 18px;
  transition: grid-template-columns 180ms ease;
}

.control-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
}

.brand-block,
.control-group,
.profile-card,
.workspace-header,
.message-list,
.composer {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 18px;
}

.brand-mark {
  display: grid;
  flex: 0 0 44px;
  width: 44px;
  height: 44px;
  place-items: center;
  border-radius: var(--radius);
  background: var(--surface-strong);
  color: #ffffff;
  font-size: 15px;
  font-weight: 800;
}

.eyebrow,
.section-kicker {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.brand-block h1,
.workspace-header h2,
.section-heading h2,
.profile-summary h2 {
  margin: 0;
  font-size: 20px;
  line-height: 1.25;
  letter-spacing: 0;
}

.control-group {
  padding: 16px;
}

.section-heading {
  margin-bottom: 14px;
}

.toggle-row,
.profile-summary,
.workspace-header,
.composer-footer,
.message-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.control-title {
  margin: 0;
  font-size: 14px;
  font-weight: 800;
}

.control-hint {
  margin: 6px 0 0;
  color: var(--text-muted);
  font-size: 13px;
  line-height: 1.55;
}

.account-row {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.account-row span {
  color: var(--text-muted);
  font-size: 13px;
}

.switch {
  position: relative;
  flex: 0 0 50px;
  width: 50px;
  height: 28px;
}

.switch input {
  position: absolute;
  opacity: 0;
}

.switch-slider {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: #d0d5dd;
  cursor: pointer;
  transition: background 160ms ease;
}

.switch-slider::after {
  content: "";
  position: absolute;
  top: 4px;
  left: 4px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 1px 4px rgba(15, 23, 42, 0.22);
  transition: transform 160ms ease;
}

.switch input:checked + .switch-slider {
  background: var(--accent-strong);
}

.switch input:checked + .switch-slider::after {
  transform: translateX(22px);
}

.danger-button,
.secondary-button,
.voice-button,
.send-button {
  border: 1px solid transparent;
  border-radius: var(--radius);
  cursor: pointer;
  font-weight: 800;
  transition: background 160ms ease, border-color 160ms ease, transform 160ms ease, opacity 160ms ease;
}

.danger-button {
  width: 100%;
  margin-top: 14px;
  color: var(--danger);
  background: var(--danger-soft);
  border-color: #ffd0cc;
}

.danger-button:hover,
.secondary-button:hover,
.send-button:hover {
  transform: translateY(-1px);
}

.profile-card {
  overflow: hidden;
}

.profile-summary {
  list-style: none;
  padding: 16px;
  cursor: pointer;
}

.profile-summary > div {
  min-width: 0;
}

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

.summary-indicator {
  flex: 0 0 auto;
  padding: 6px 10px;
  border-radius: 999px;
  background: var(--surface-muted);
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 800;
}

.profile-card[open] .summary-indicator {
  color: var(--warning);
  background: var(--warning-soft);
}

.profile-form {
  display: none;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  padding: 0 16px 16px;
}

.profile-card[open] .profile-form {
  display: grid;
}

.api-key-form {
  grid-template-columns: 1fr;
}

.key-provider {
  grid-column: 1 / -1;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fbfcfd;
}

.key-provider + .key-provider {
  margin-top: 2px;
}

.key-provider-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.key-provider-header h3 {
  margin: 0;
  font-size: 16px;
  line-height: 1.3;
}

.key-state {
  flex: 0 0 auto;
  max-width: 180px;
  padding: 5px 8px;
  border-radius: 999px;
  color: var(--text-muted);
  background: var(--surface-muted);
  font-size: 12px;
  font-weight: 800;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.key-state.configured {
  color: var(--accent);
  background: var(--accent-soft);
}

.agent-map {
  display: grid;
  gap: 6px;
  margin-bottom: 10px;
}

.agent-map p {
  margin: 0;
  color: var(--text-muted);
  font-size: 12px;
  line-height: 1.55;
  overflow-wrap: anywhere;
}

.key-field {
  margin-top: 8px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

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

.field input,
.field textarea,
.field select,
.composer-input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #ffffff;
  color: var(--text-main);
  line-height: 1.6;
}

.field input,
.field textarea,
.field select {
  padding: 10px 12px;
  font-size: 14px;
}

.field textarea {
  resize: vertical;
}

.field input:focus,
.field textarea:focus,
.field select:focus,
.composer-input:focus {
  outline: 3px solid rgba(13, 148, 136, 0.16);
  border-color: var(--accent-strong);
}

.field-wide {
  grid-column: 1 / -1;
}

.field-readonly {
  padding: 10px 12px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface-muted);
}

.field-readonly p {
  margin: 0;
  color: var(--text-muted);
  font-size: 13px;
  line-height: 1.55;
}

.hidden {
  display: none !important;
}

.profile-actions {
  grid-column: 1 / -1;
  display: flex;
  justify-content: flex-end;
}

.secondary-button {
  padding: 0 16px;
  color: var(--accent);
  background: var(--accent-soft);
  border-color: #b7e4df;
}

.subtle-button {
  color: var(--text-muted);
  background: var(--surface-muted);
  border-color: var(--border);
}

.control-group.muted {
  background: #fbfcfd;
}

.voice-button {
  width: 100%;
  margin-top: 14px;
  color: var(--text-muted);
  background: var(--surface-muted);
  border-color: var(--border);
  cursor: not-allowed;
}

.chat-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 12px;
  min-width: 0;
  min-height: 0;
}

.workspace-header {
  padding: 16px 18px;
}

.workspace-meta {
  display: flex;
  align-items: flex-end;
  flex-direction: column;
  gap: 8px;
}

.runtime-config-text {
  margin: 0;
  padding: 6px 10px;
  border-radius: 999px;
  color: #155e75;
  background: #e6f3f7;
  font-size: 12px;
  font-weight: 800;
  line-height: 1.35;
}

.composer-status-text {
  flex: 0 1 auto;
  max-width: 52%;
  margin: 0;
  padding: 8px 12px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 13px;
  font-weight: 800;
  line-height: 1.35;
  text-align: right;
}

.composer-status-text.thinking,
.composer-status-text.speaking,
.composer-status-text.listening,
.composer-status-text.transcribing {
  color: var(--warning);
  background: var(--warning-soft);
}

.composer-status-text.error,
.composer-status-text.interrupted {
  color: var(--danger);
  background: var(--danger-soft);
}

.message-list {
  min-height: 0;
  overflow: auto;
  padding: 18px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.84), rgba(250, 252, 253, 0.96)),
    repeating-linear-gradient(0deg, transparent 0 35px, rgba(15, 23, 42, 0.03) 35px 36px);
}

.message-list.empty {
  display: grid;
  place-items: center;
}

.message-list.empty::before {
  content: "输入一句话开始验证文字链路、流式回复和 TTS 情绪标签。";
  display: block;
  max-width: 420px;
  padding: 22px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  color: var(--text-muted);
  background: rgba(255, 255, 255, 0.76);
  text-align: center;
  line-height: 1.7;
}

.message-card {
  max-width: min(760px, 88%);
  margin: 0 0 12px;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #ffffff;
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.06);
}

.message-card.user {
  margin-left: auto;
  color: #ffffff;
  background: #155e75;
  border-color: #155e75;
}

.message-card.assistant.streaming {
  border-color: #f59e0b;
  box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.12);
}

.message-meta {
  justify-content: flex-start;
  margin-bottom: 8px;
  color: var(--text-soft);
  font-size: 12px;
  flex-wrap: wrap;
}

.message-card.user .message-meta {
  color: rgba(255, 255, 255, 0.72);
}

.message-role {
  color: var(--text-main);
  font-weight: 800;
}

.message-card.user .message-role {
  color: #ffffff;
}

.message-source {
  padding-left: 10px;
  border-left: 1px solid currentColor;
}

.message-emotion {
  margin-left: auto;
  padding: 4px 8px;
  border-radius: 999px;
  color: var(--accent);
  background: var(--accent-soft);
  font-weight: 800;
}

.message-emotion.hidden {
  display: none;
}

.message-body {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: 15px;
  line-height: 1.75;
}

.composer {
  padding: 16px;
}

.composer-label {
  display: block;
  margin-bottom: 8px;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 800;
}

.composer-input {
  min-height: 112px;
  max-height: 260px;
  padding: 12px 14px;
  resize: vertical;
}

.composer-footer {
  margin-top: 12px;
}

.composer-tip {
  margin: 0;
  color: var(--text-muted);
  font-size: 13px;
}

.send-button {
  min-width: 108px;
  padding: 0 18px;
  color: #ffffff;
  background: var(--surface-strong);
}

.send-button:disabled,
.danger-button:disabled,
.secondary-button:disabled {
  opacity: 0.58;
  cursor: not-allowed;
  transform: none;
}

@media (min-width: 1081px) {
  .app-shell {
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
  }

  .control-panel,
  .chat-panel {
    overflow: hidden;
  }

  .control-panel {
    min-height: 0;
  }

  .profile-card[open] {
    position: fixed;
    top: 50%;
    left: 50%;
    z-index: 20;
    width: min(920px, calc(100vw - 48px));
    max-height: min(92vh, 760px);
    min-height: 0;
    transform: translate(-50%, -50%);
    box-shadow: 0 28px 80px rgba(15, 23, 42, 0.28);
  }

  .profile-card[open] .profile-summary {
    padding: 16px 20px 10px;
  }

  .profile-card[open] .profile-summary h2 {
    font-size: 22px;
  }

  .profile-card[open] .profile-form {
    grid-template-columns: 1fr;
    gap: 10px;
    max-height: calc(min(92vh, 760px) - 82px);
    padding: 0 20px 20px;
    overflow: auto;
  }

  .profile-card[open] .field {
    display: grid;
    grid-template-columns: 168px minmax(0, 1fr);
    align-items: center;
    gap: 14px;
  }

  .profile-card[open] .field-wide {
    grid-column: auto;
  }

  .profile-card[open] .field span {
    color: var(--text-main);
    font-size: 13px;
  }

  .profile-card[open] .field textarea {
    min-height: 62px;
  }

  .profile-card[open] .field input,
  .profile-card[open] .field textarea {
    padding: 8px 10px;
  }

  .profile-card[open] .key-provider .field {
    grid-template-columns: 168px minmax(0, 1fr);
  }

  .profile-card[open] .key-provider {
    padding: 14px;
  }

  .profile-card[open] .field-readonly {
    display: grid;
    grid-template-columns: 168px minmax(0, 1fr);
    align-items: center;
    gap: 14px;
  }

  .profile-card[open] .profile-actions {
    justify-content: flex-end;
    grid-column: auto;
  }

  .profile-card[open] .secondary-button {
    min-height: 38px;
    width: min(240px, 100%);
  }
}

@media (min-width: 901px) and (max-width: 1120px) {
  .profile-card[open] .profile-actions {
    grid-column: auto;
  }
}

@media (max-width: 1180px) {
  .app-shell {
    grid-template-columns: 312px minmax(0, 1fr);
  }

  .message-card {
    max-width: 94%;
  }
}

@media (max-width: 900px) {
  .app-shell {
    grid-template-columns: 1fr;
    min-height: 100vh;
    min-height: 100dvh;
    padding: 12px;
  }

  .brand-block {
    align-items: flex-start;
  }

  .control-panel {
    gap: 10px;
  }

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

  .profile-card[open] .field,
  .profile-card[open] .field-readonly {
    display: grid;
    grid-template-columns: 112px minmax(0, 1fr);
    align-items: center;
    gap: 10px;
  }

  .profile-card[open] .field span,
  .profile-card[open] .field-readonly span {
    color: var(--text-main);
  }

  .chat-panel {
    min-height: 70vh;
    grid-template-rows: auto minmax(420px, 1fr) auto;
  }

  .workspace-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .workspace-meta {
    align-items: flex-start;
  }

  .composer-status-text {
    max-width: 100%;
    text-align: left;
  }
}

@media (max-width: 560px) {
  .app-shell {
    padding: 0;
    gap: 0;
  }

  .brand-block,
  .control-group,
  .profile-card,
  .workspace-header,
  .message-list,
  .composer {
    border-left: 0;
    border-right: 0;
    border-radius: 0;
    box-shadow: none;
  }

  .brand-block,
  .control-group,
  .profile-summary,
  .workspace-header,
  .message-list,
  .composer {
    padding-left: 14px;
    padding-right: 14px;
  }

  .brand-block h1,
  .workspace-header h2,
  .section-heading h2,
  .profile-summary h2 {
    font-size: 18px;
  }

  .control-group.muted {
    display: none;
  }

  .chat-panel {
    min-height: 72vh;
    gap: 0;
    grid-template-rows: auto minmax(360px, 1fr) auto;
  }

  .message-card,
  .message-card.user {
    max-width: 100%;
  }

  .composer-footer {
    align-items: stretch;
    flex-direction: column;
  }

  .send-button {
    width: 100%;
  }
}
