:root {
  color-scheme: light;
  --page: #f6f7f3;
  --panel: #ffffff;
  --panel-soft: #f0f5f3;
  --text: #202124;
  --muted: #65706c;
  --line: #dce2dd;
  --accent: #0f766e;
  --accent-strong: #115e59;
  --accent-soft: #d8f3ee;
  --warning: #a15c13;
  --danger: #b42318;
  --shadow: 0 20px 60px rgba(36, 42, 38, 0.08);
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  background: var(--page);
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "PingFang SC", "Microsoft YaHei", sans-serif;
  letter-spacing: 0;
}

button,
input,
textarea {
  font: inherit;
}

.app-shell {
  width: min(1040px, calc(100vw - 32px));
  height: calc(100vh - 32px);
  margin: 16px auto;
  display: grid;
  grid-template-rows: auto auto minmax(320px, 1fr) auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.topbar {
  min-height: 72px;
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  width: 40px;
  height: 40px;
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  border-radius: 8px;
  background: var(--accent);
  color: #ffffff;
  font-weight: 800;
}

.brand h1 {
  margin: 0;
  font-size: 20px;
  line-height: 1.2;
}

.brand p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.status-pill {
  min-width: 76px;
  padding: 7px 10px;
  border-radius: 999px;
  text-align: center;
  font-size: 13px;
  white-space: nowrap;
  border: 1px solid var(--line);
  color: var(--muted);
  background: #ffffff;
}

.status-pill.is-connecting {
  color: var(--warning);
  border-color: #f0cf9b;
  background: #fff7e8;
}

.status-pill.is-online {
  color: var(--accent-strong);
  border-color: #b8ddd7;
  background: var(--accent-soft);
}

.status-pill.is-offline {
  color: var(--danger);
  border-color: #f0b8b3;
  background: #fff0ef;
}

.settings-panel {
  padding: 12px 20px;
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  align-items: end;
  border-bottom: 1px solid var(--line);
  background: #fbfcfa;
}

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

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

.field input {
  width: 100%;
  height: 38px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--text);
  outline: none;
}

.field input:focus,
.composer textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.12);
}

.switch {
  height: 38px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  white-space: nowrap;
}

.switch input {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}

.button {
  height: 38px;
  padding: 0 14px;
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  white-space: nowrap;
  transition:
    background 0.15s ease,
    border-color 0.15s ease,
    transform 0.15s ease;
}

.button:hover {
  transform: translateY(-1px);
}

.button:disabled {
  cursor: not-allowed;
  opacity: 0.58;
  transform: none;
}

.button.primary {
  background: var(--accent);
  color: #ffffff;
}

.button.primary:hover {
  background: var(--accent-strong);
}

.button.danger {
  background: var(--danger);
  color: #ffffff;
}

.button.danger:hover {
  background: #962016;
}

.button.secondary,
.button.icon-button {
  background: #ffffff;
  border-color: var(--line);
  color: var(--text);
}

.button.icon-button {
  width: 44px;
  padding: 0;
  position: relative;
  display: inline-grid;
  place-items: center;
}

.voice-icon {
  width: 19px;
  height: 19px;
  fill: currentColor;
}

.voice-button.is-listening {
  color: #ffffff;
  background: var(--danger);
  border-color: var(--danger);
}

.voice-button.is-listening::after {
  content: "";
  width: 8px;
  height: 8px;
  position: absolute;
  margin: -26px 0 0 26px;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 0 0 4px rgba(255, 255, 255, 0.28);
}

.message-list {
  min-height: 320px;
  padding: 24px 20px;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
  background:
    linear-gradient(180deg, rgba(216, 243, 238, 0.32), rgba(255, 255, 255, 0) 220px),
    #ffffff;
}

.message {
  display: grid;
  gap: 6px;
  max-width: min(760px, 88%);
}

.message.user {
  align-self: flex-end;
}

.message.assistant,
.message.system {
  align-self: flex-start;
}

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

.message.user .message-label {
  text-align: right;
}

.bubble {
  padding: 12px 14px;
  border-radius: 8px;
  line-height: 1.7;
  font-size: 15px;
  word-break: break-word;
  white-space: pre-wrap;
}

.message.user .bubble {
  color: #ffffff;
  background: #17443f;
}

.message.assistant .bubble {
  color: var(--text);
  background: var(--panel-soft);
  border: 1px solid #d6e7e2;
}

.message.assistant .bubble.is-error {
  color: var(--danger);
  background: #fff0ef;
  border-color: #f0b8b3;
}

.message.system .bubble {
  color: #6b3b08;
  background: #fff7e8;
  border: 1px solid #f3d39e;
}

.bubble.is-loading::after {
  content: "";
  width: 8px;
  height: 8px;
  display: inline-block;
  margin-left: 8px;
  border-radius: 50%;
  background: var(--accent);
  animation: blink 0.9s ease-in-out infinite;
}

@keyframes blink {
  0%,
  100% {
    opacity: 0.25;
  }
  50% {
    opacity: 1;
  }
}

.meta-row {
  margin-top: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.meta-chip {
  padding: 3px 8px;
  border-radius: 999px;
  background: #ffffff;
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
}

.debug-block {
  margin-top: 10px;
  border-top: 1px solid rgba(0, 0, 0, 0.08);
  padding-top: 8px;
}

.debug-block summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 13px;
}

.debug-block pre {
  max-height: 260px;
  overflow: auto;
  margin: 8px 0 0;
  padding: 10px;
  border-radius: 8px;
  background: #17201d;
  color: #edf7f4;
  font-size: 12px;
  line-height: 1.5;
  white-space: pre-wrap;
}

.composer {
  padding: 14px 20px 18px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto auto;
  gap: 10px;
  align-items: end;
  border-top: 1px solid var(--line);
  background: #fbfcfa;
}

.composer textarea {
  width: 100%;
  min-height: 44px;
  max-height: 140px;
  resize: none;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: none;
  line-height: 1.55;
  color: var(--text);
  background: #ffffff;
}

.voice-status {
  min-height: 18px;
  grid-column: 1 / -1;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

@media (max-width: 760px) {
  .app-shell {
    width: 100%;
    height: 100vh;
    margin: 0;
    border: 0;
    border-radius: 0;
  }

  .topbar {
    align-items: flex-start;
  }

  .settings-panel {
    grid-template-columns: 1fr;
  }

  .switch,
  .settings-panel .button {
    width: 100%;
    justify-content: center;
  }

  .message {
    max-width: 94%;
  }

  .composer {
    grid-template-columns: 1fr auto auto;
  }

  .composer textarea {
    grid-column: 1 / -1;
  }

  .voice-status {
    grid-column: 1 / -1;
  }
}

/* 图片画廊 */
.image-gallery {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid rgba(0, 0, 0, 0.08);
}

.image-gallery-header {
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 8px;
}

.image-gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 8px;
}

.image-item {
  margin: 0;
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid var(--line);
  background: #ffffff;
}

.image-item img {
  width: 100%;
  height: 120px;
  object-fit: cover;
  display: block;
  cursor: pointer;
  transition: transform 0.15s ease;
}

.image-item img:hover {
  transform: scale(1.03);
}

.image-item figcaption {
  padding: 4px 6px;
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
