:root {
  color-scheme: light;
  --bg: #f8faf8;
  --panel: #fffefd;
  --panel-soft: #f1f5f2;
  --ink: #1f2528;
  --muted: #687579;
  --line: #dce4de;
  --accent: #0f8b8d;
  --accent-strong: #096466;
  --danger: #b24c63;
  --warning: #a56b18;
  --shadow: 0 18px 48px rgba(31, 37, 40, 0.12);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
}

body {
  margin: 0;
  overflow: hidden;
  color: var(--ink);
  background: var(--bg);
  font-family: Inter, "Microsoft YaHei", "PingFang SC", system-ui, sans-serif;
}

button,
textarea,
input,
select {
  font: inherit;
}

button {
  min-height: 40px;
  border: 0;
  border-radius: 8px;
  color: #fff;
  background: var(--accent);
  cursor: pointer;
  font-weight: 800;
}

button:disabled {
  cursor: wait;
  opacity: 0.62;
}

h1,
h2,
h3,
p {
  margin: 0;
}

.app-shell {
  position: relative;
  width: 100vw;
  height: 100dvh;
  overflow: hidden;
}

.chat-panel {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100vw;
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
  overflow-x: clip;
  background: var(--panel);
}

.chat-panel::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 0;
  background-image: var(--chat-bg-image);
  background-position: center;
  background-size: contain;
  background-repeat: no-repeat;
  filter: blur(var(--chat-bg-blur, 0));
  opacity: 0;
  pointer-events: none;
}

.chat-panel.has-chat-background::before {
  opacity: var(--chat-bg-opacity, 0.18);
}

.chat-panel > * {
  position: relative;
  z-index: 1;
}

.topbar {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) auto 44px;
  gap: 8px;
  align-items: center;
  min-height: 64px;
  padding: max(10px, env(safe-area-inset-top)) 12px 10px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 254, 253, 0.94);
  backdrop-filter: blur(14px);
}

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

.avatar,
.mini-avatar {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  overflow: hidden;
  border-radius: 8px;
  color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--danger));
  font-weight: 900;
}

.avatar img,
.mini-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.avatar.has-avatar-image,
.mini-avatar.has-avatar-image {
  background: var(--panel-soft);
}

.avatar {
  width: 42px;
  height: 42px;
}

.mini-avatar {
  width: 38px;
  height: 38px;
}

.avatar-upload {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.topbar h1 {
  overflow: hidden;
  max-width: 100%;
  font-size: 18px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar p,
.drawer-header p,
.section-title span,
.agent-card small,
.message-meta,
.empty {
  color: var(--muted);
  font-size: 12px;
}

.icon-button,
.plain-icon {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  min-height: 40px;
  padding: 0;
  border: 1px solid var(--line);
  color: var(--accent-strong);
  background: var(--panel-soft);
}

.icon-button span {
  display: block;
  width: 18px;
  height: 2px;
  margin: 2px 0;
  border-radius: 99px;
  background: currentColor;
}

.settings-icon span {
  width: 18px;
  height: 18px;
  margin: 0;
  border: 2px solid currentColor;
  border-radius: 50%;
  background: radial-gradient(circle at center, currentColor 0 2px, transparent 3px);
}

.call-button {
  min-height: 36px;
  padding: 0 10px;
  border: 1px solid rgba(15, 139, 141, 0.28);
  color: var(--accent-strong);
  background: #e4f4f1;
  font-size: 13px;
  white-space: nowrap;
}

.call-button.active {
  color: #fff;
  background: var(--danger);
  border-color: transparent;
}

.plain-icon {
  font-size: 28px;
  line-height: 1;
}

.quick-actions {
  flex: 0 0 auto;
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 254, 253, 0.88);
  scrollbar-width: none;
}

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

.quick-actions::-webkit-scrollbar {
  display: none;
}

.quick-actions button {
  flex: 0 0 auto;
  max-width: 58vw;
  min-height: 34px;
  padding: 7px 10px;
  overflow: hidden;
  color: var(--accent-strong);
  background: #e4f4f1;
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.messages {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 14px 12px 18px;
  overscroll-behavior: contain;
}

.chat-panel.has-chat-background .messages {
  background: transparent;
}

.empty {
  display: grid;
  place-items: center;
  min-height: 160px;
  text-align: center;
}

.message {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  width: fit-content;
  max-width: min(92%, 720px);
  margin: 0 0 14px;
}

.message.user {
  align-items: flex-end;
  margin-left: auto;
}

.message-meta {
  max-width: 100%;
  margin: 0 0 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-panel.has-chat-background .message-meta {
  width: max-content;
  max-width: 100%;
  padding: 3px 8px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 999px;
  color: rgba(255, 255, 255, 0.92);
  background: rgba(31, 37, 40, 0.38);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.42);
  backdrop-filter: blur(8px) saturate(1.05);
}

.chat-panel.has-chat-background .message.user .message-meta {
  color: rgba(255, 255, 255, 0.94);
  background: rgba(15, 139, 141, 0.38);
}

.message-body {
  width: fit-content;
  max-width: 100%;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
  padding: 11px 13px;
  border: 1px solid rgba(220, 228, 222, 0.94);
  border-radius: 8px;
  background: rgba(255, 254, 253, 0.94);
  line-height: 1.6;
}

.chat-panel.has-chat-background .message-body {
  border-color: rgba(255, 255, 255, 0.52);
  background: rgba(255, 255, 255, 0.58);
  box-shadow: 0 8px 24px rgba(31, 37, 40, 0.08);
  backdrop-filter: blur(8px) saturate(1.08);
}

.message.user .message-body {
  color: #fff;
  border-color: transparent;
  background: var(--accent);
}

.chat-panel.has-chat-background .message.user .message-body {
  color: #fff;
  background: rgba(15, 139, 141, 0.72);
  box-shadow: 0 8px 24px rgba(15, 139, 141, 0.18);
}

.message.system .message-body {
  color: #61410f;
  background: #fff7df;
}

.chat-panel.has-chat-background .message.system .message-body {
  background: rgba(255, 247, 223, 0.72);
}

.message.failed .message-body {
  border-color: rgba(178, 76, 99, 0.4);
}

.image-message-body {
  display: grid;
  gap: 8px;
}

.media-caption {
  font-size: 13px;
}

.generated-image {
  display: block;
  width: min(100%, 320px);
  height: auto;
  border-radius: 8px;
  object-fit: contain;
}

.voice-message-body {
  display: grid;
  gap: 8px;
}

.voice-bubble {
  display: inline-grid;
  grid-template-columns: auto auto auto;
  gap: 8px;
  align-items: center;
  width: max-content;
  min-height: 38px;
  padding: 8px 12px;
  color: var(--accent-strong);
  background: #e4f4f1;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.voice-bubble.playing {
  color: #fff;
  background: var(--accent);
}

.voice-bubble.showing-transcript {
  border-color: rgba(15, 139, 141, 0.28);
  box-shadow: inset 0 0 0 1px rgba(15, 139, 141, 0.16);
}

.voice-wave {
  display: inline-flex;
  gap: 3px;
  align-items: center;
}

.voice-wave i {
  display: block;
  width: 3px;
  height: 12px;
  border-radius: 99px;
  background: currentColor;
}

.voice-wave i:nth-child(2) {
  height: 18px;
}

.voice-transcript {
  max-width: min(72vw, 320px);
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.voice-transcript:not([hidden]) {
  padding: 8px 10px;
  border: 1px solid rgba(15, 139, 141, 0.18);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.62);
  color: var(--ink);
}

.message-actions {
  display: flex;
  gap: 8px;
  align-self: flex-start;
  margin-top: 8px;
}

.regenerate-button {
  min-height: 30px;
  padding: 5px 10px;
  border: 1px solid rgba(15, 139, 141, 0.26);
  border-radius: 8px;
  color: var(--accent-strong);
  background: #e4f4f1;
  cursor: pointer;
  font-size: 12px;
  font-weight: 800;
}

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

.message-delete {
  position: absolute;
  top: 18px;
  right: 7px;
  min-height: 28px;
  padding: 4px 8px;
  opacity: 0;
  pointer-events: none;
  color: var(--danger);
  background: #fae8ec;
  font-size: 12px;
}

.message.user .message-delete {
  right: auto;
  left: 7px;
}

.message:hover .message-delete,
.message:focus-within .message-delete {
  opacity: 1;
  pointer-events: auto;
}

.composer {
  flex: 0 0 auto;
  position: sticky;
  bottom: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 72px;
  gap: 8px;
  padding: 10px 10px max(10px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: rgba(255, 254, 253, 0.95);
  backdrop-filter: blur(14px);
}

.chat-panel.has-chat-background .composer,
.chat-panel.has-chat-background .topbar,
.chat-panel.has-chat-background .quick-actions {
  background: rgba(255, 254, 253, 0.72);
  backdrop-filter: blur(12px) saturate(1.08);
}

.chat-panel.has-chat-background .composer textarea {
  background: rgba(255, 255, 255, 0.64);
}

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

.composer textarea:focus,
.config-form input:focus,
.config-form textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 139, 141, 0.12);
}

.drawer {
  position: fixed;
  top: 0;
  bottom: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  width: min(86vw, 380px);
  height: 100dvh;
  overflow: hidden;
  background: var(--panel);
  box-shadow: var(--shadow);
  transition: transform 0.2s ease;
}

.drawer-left {
  left: 0;
  transform: translateX(-102%);
}

.drawer-right {
  right: 0;
  display: block;
  overflow-y: auto;
  overflow-x: hidden;
  transform: translateX(102%);
}

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

.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: max(14px, env(safe-area-inset-top)) 14px 12px;
  border-bottom: 1px solid var(--line);
}

.drawer-header h2 {
  font-size: 20px;
}

.drawer-actions,
.button-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.drawer button:not(.plain-icon),
.drawer .import-button {
  min-height: 36px;
  padding: 0 10px;
  font-size: 14px;
  font-weight: 750;
  line-height: 1.15;
}

.drawer .button-row button,
.drawer .button-row .import-button {
  width: 100%;
}

.button-row > [hidden] {
  display: none;
}

.button-row > .full {
  grid-column: 1 / -1;
}

.drawer-actions {
  padding: 12px;
  border-bottom: 1px solid var(--line);
}

.secondary,
.import-button {
  color: var(--accent-strong);
  background: #e4f4f1;
}

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

.full {
  width: 100%;
}

.agent-list {
  display: grid;
  align-content: start;
  gap: 8px;
  overflow-y: auto;
  padding: 12px;
}

.agent-card {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  width: 100%;
  min-height: 60px;
  padding: 10px;
  border: 1px solid transparent;
  color: var(--ink);
  background: var(--panel-soft);
  text-align: left;
}

.agent-card.active {
  border-color: rgba(15, 139, 141, 0.35);
  background: #e4f4f1;
}

.agent-card strong,
.agent-card small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.panel-section {
  display: grid;
  gap: 10px;
  flex: 0 0 auto;
  padding: 14px;
  border-bottom: 1px solid var(--line);
}

.drawer-right .panel-section {
  display: block;
  min-height: max-content;
}

.drawer-right .panel-section > * + * {
  margin-top: 10px;
}

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

.section-title h3 {
  min-width: 0;
  font-size: 15px;
  line-height: 1.35;
}

.section-title span {
  flex: 0 0 auto;
  max-width: 46%;
  overflow: hidden;
  text-align: right;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.toggle-row,
.range-row,
.file-control {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
}

.toggle-row {
  grid-template-columns: 18px minmax(0, 1fr);
  align-items: start;
  color: var(--ink);
  line-height: 1.45;
}

.toggle-row input {
  width: 18px;
  height: 18px;
  margin: 2px 0 0;
  flex: 0 0 auto;
}

.toggle-row span {
  min-width: 0;
  overflow-wrap: anywhere;
}

.range-row {
  grid-template-columns: 68px minmax(0, 1fr);
  align-items: center;
}

.voice-tuning-grid {
  display: grid;
  gap: 9px;
}

.range-row.value-range {
  grid-template-columns: 56px minmax(150px, 1fr) 48px;
}

.range-row output {
  color: var(--ink);
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.range-row input {
  width: 100%;
  min-width: 0;
  height: 28px;
  padding: 0;
  accent-color: var(--accent-strong);
  touch-action: none;
}

.file-control input {
  width: 100%;
  min-width: 0;
  max-width: 100%;
  font-size: 13px;
}

.background-preview {
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  min-height: 64px;
  padding: 8px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: var(--panel-soft);
  font-size: 13px;
}

.background-preview img {
  width: 64px;
  height: 48px;
  border-radius: 8px;
  object-fit: cover;
}

.background-preview span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.config-form {
  display: grid;
  gap: 10px;
}

.config-form label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

.config-form .config-field {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

.config-form [hidden] {
  display: none;
}

.field-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-width: 0;
}

.field-title > span {
  min-width: 0;
  overflow-wrap: anywhere;
}

.backup-history-field {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

.backup-history-field select {
  width: 100%;
  min-width: 0;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: #fff;
  line-height: 1.45;
}

.config-form input,
.config-form textarea,
.config-form select {
  width: 100%;
  min-width: 0;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: none;
  color: var(--ink);
  background: #fff;
  line-height: 1.45;
}

.config-form textarea {
  min-height: 44px;
  resize: vertical;
}

.auth-tabs {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.68);
}

.auth-tabs button {
  min-height: 34px;
  padding: 0 8px;
  color: var(--muted);
  background: transparent;
  font-size: 13px;
  white-space: nowrap;
}

.auth-tabs button.active {
  color: var(--accent-strong);
  background: #e4f4f1;
}

.inline-input-action {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 76px;
  gap: 8px;
  align-items: center;
}

.inline-input-action input {
  min-width: 0;
}

.form-hint {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.license-ad {
  color: var(--accent-strong);
  font-weight: 800;
}

.text-action {
  width: auto;
  min-height: auto;
  justify-self: start;
  padding: 0;
  color: var(--accent-strong);
  background: transparent;
  font-size: 12px;
}

.mini-action {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 32px;
  min-height: 32px;
  padding: 0;
  border: 1px solid rgba(15, 139, 141, 0.2);
  border-radius: 7px;
  background: rgba(228, 244, 241, 0.72);
  font-weight: 800;
  font-size: 16px;
  line-height: 1;
}

.license-form {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px dashed var(--line);
}

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

.response-style-grid {
  display: grid;
  gap: 8px;
}

.compact-form {
  gap: 8px;
}

.agent-optimize-box {
  display: grid;
  gap: 7px;
  padding: 10px;
  border: 1px solid rgba(15, 139, 141, 0.18);
  border-radius: 8px;
  background: #eef7f4;
}

.reference-upload {
  display: grid;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
}

.reference-preview {
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  min-height: 64px;
  padding: 8px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: #fff;
  font-size: 13px;
}

.reference-preview img {
  width: 64px;
  height: 64px;
  border-radius: 8px;
  object-fit: cover;
}

.reference-preview span,
.memory-item span {
  overflow-wrap: anywhere;
}

.memory-list {
  display: grid;
  gap: 8px;
  max-height: 260px;
  overflow-y: auto;
}

.memory-item {
  display: grid;
  gap: 4px;
  padding: 9px 10px;
  border-radius: 8px;
  color: #3c4246;
  background: var(--panel-soft);
  font-size: 13px;
  line-height: 1.45;
}

.memory-item strong {
  color: var(--accent-strong);
  font-size: 12px;
}

.import-button {
  display: grid;
  place-items: center;
  min-height: 40px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 800;
}

.import-button input {
  display: none;
}

.external-import-box {
  display: grid;
  gap: 8px;
  padding: 10px;
  border: 1px solid rgba(46, 56, 51, 0.1);
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.58);
}

.compact-title {
  align-items: center;
}

.compact-title .small {
  min-height: 30px;
  padding: 0 10px;
  font-size: 12px;
}

.scrim {
  position: fixed;
  inset: 0;
  z-index: 10;
  background: rgba(31, 37, 40, 0.28);
}

@media (max-width: 720px) {
  .drawer {
    width: min(92vw, 390px);
  }

  .drawer-header {
    padding: max(12px, env(safe-area-inset-top)) 12px 10px;
  }

  .drawer-header h2 {
    font-size: 18px;
  }

  .drawer-actions {
    padding: 10px 12px;
  }

  .panel-section {
    gap: 8px;
    padding: 12px;
  }

  .drawer-right .panel-section > * + * {
    margin-top: 8px;
  }

  .config-form {
    gap: 8px;
  }

  .config-form label,
  .config-form .config-field {
    gap: 5px;
    font-size: 12px;
  }

  .config-form input,
  .config-form textarea,
  .config-form select {
    padding: 8px 9px;
  }

  .button-row {
    gap: 7px;
  }

  .drawer button:not(.plain-icon),
  .drawer .import-button {
    min-height: 34px;
    border-radius: 7px;
    font-size: 13px;
  }

  .call-button {
    min-height: 34px;
    padding: 0 8px;
    font-size: 12px;
  }

  .auth-tabs button {
    min-height: 30px;
    font-size: 12px;
  }
}

@media (min-width: 721px) {
  body {
    background: #edf2ef;
  }

  .app-shell {
    display: grid;
    place-items: center;
  }

  .chat-panel {
    width: min(430px, 100vw);
    height: min(860px, 100dvh);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
  }
}

/* Mobile-first product refresh */
:root {
  --bg: #f3f0ea;
  --panel: #fffdf8;
  --panel-soft: #f6f1e8;
  --ink: #202427;
  --muted: #68706d;
  --line: rgba(46, 56, 51, 0.13);
  --accent: #247c67;
  --accent-strong: #155946;
  --danger: #b65766;
  --warning: #a66b24;
  --shadow: 0 20px 58px rgba(28, 33, 31, 0.18);
}

body {
  background:
    linear-gradient(180deg, #f9f5ed 0%, #eef4ef 52%, #e7eee9 100%);
}

.chat-panel {
  background:
    linear-gradient(180deg, rgba(255, 253, 248, 0.94) 0%, rgba(246, 241, 232, 0.72) 38%, rgba(236, 242, 237, 0.9) 100%),
    var(--panel);
}

.chat-panel::before {
  background-position: center 42%;
  background-size: min(92vw, 430px) auto;
}

.chat-panel.has-chat-background::before {
  opacity: var(--chat-bg-opacity, 0.34);
}

.chat-panel::after {
  content: "";
  position: absolute;
  inset: auto 0 0;
  z-index: 0;
  height: 38%;
  pointer-events: none;
  background: linear-gradient(180deg, transparent 0%, rgba(246, 241, 232, 0.62) 52%, rgba(243, 240, 234, 0.95) 100%);
}

.topbar {
  grid-template-columns: 40px minmax(0, 1fr) 68px 40px;
  min-height: 64px;
  padding: max(10px, env(safe-area-inset-top)) 12px 8px;
  border-bottom: 0;
  background: rgba(255, 253, 248, 0.74);
  box-shadow: 0 1px 0 rgba(46, 56, 51, 0.08), 0 10px 30px rgba(36, 47, 43, 0.06);
  backdrop-filter: blur(18px) saturate(1.12);
}

.agent-identity {
  grid-template-columns: 38px minmax(0, 1fr);
  gap: 9px;
}

.avatar {
  width: 38px;
  height: 38px;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.46), 0 8px 20px rgba(36, 124, 103, 0.18);
}

.topbar h1 {
  font-size: 17px;
  line-height: 1.18;
}

.topbar p {
  margin-top: 2px;
  font-size: 11px;
}

.icon-button,
.plain-icon {
  width: 38px;
  height: 38px;
  min-height: 38px;
  border-color: rgba(46, 56, 51, 0.12);
  color: #26322e;
  background: rgba(255, 253, 248, 0.64);
  box-shadow: 0 8px 20px rgba(31, 37, 40, 0.06);
}

.call-button {
  min-height: 34px;
  padding: 0 9px;
  border-color: rgba(36, 124, 103, 0.2);
  color: var(--accent-strong);
  background: rgba(220, 241, 233, 0.78);
  font-size: 12px;
}

.quick-actions {
  padding: 9px 12px 7px;
  border-bottom: 0;
  background: transparent;
}

.quick-actions button {
  min-height: 32px;
  border: 1px solid rgba(36, 124, 103, 0.14);
  color: #28594b;
  background: rgba(255, 253, 248, 0.62);
  box-shadow: 0 8px 22px rgba(31, 37, 40, 0.06);
  backdrop-filter: blur(12px);
}

.messages {
  padding: 16px 12px 22px;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.messages::-webkit-scrollbar,
.drawer-right::-webkit-scrollbar,
.agent-list::-webkit-scrollbar {
  width: 0;
  height: 0;
  display: none;
}

.empty {
  min-height: 44vh;
  padding: 0 28px;
  color: rgba(32, 36, 39, 0.58);
  line-height: 1.65;
}

.message {
  max-width: min(84%, 620px);
  margin-bottom: 13px;
}

.message-meta {
  margin-bottom: 5px;
  padding: 0 3px;
  color: rgba(32, 36, 39, 0.47);
  font-size: 11px;
}

.message-body {
  padding: 10px 12px;
  border: 1px solid rgba(255, 255, 255, 0.58);
  color: #232827;
  background: rgba(255, 253, 248, 0.78);
  box-shadow: 0 10px 28px rgba(31, 37, 40, 0.08);
  backdrop-filter: blur(14px) saturate(1.1);
}

.message.user .message-body {
  background: linear-gradient(135deg, #247c67 0%, #1b6656 100%);
  box-shadow: 0 12px 28px rgba(36, 124, 103, 0.22);
}

.chat-panel.has-chat-background .message-body {
  background: rgba(255, 253, 248, 0.66);
  box-shadow: 0 12px 30px rgba(23, 28, 26, 0.13);
}

.chat-panel.has-chat-background .message.user .message-body {
  background: rgba(36, 124, 103, 0.78);
}

.composer {
  grid-template-columns: minmax(0, 1fr) 54px;
  gap: 8px;
  padding: 9px 10px max(10px, env(safe-area-inset-bottom));
  border-top: 0;
  background: rgba(255, 253, 248, 0.72);
  box-shadow: 0 -12px 34px rgba(31, 37, 40, 0.08);
  backdrop-filter: blur(18px) saturate(1.12);
}

.composer textarea {
  min-height: 42px;
  max-height: 124px;
  padding: 10px 12px;
  border-color: rgba(46, 56, 51, 0.12);
  background: rgba(255, 255, 255, 0.74);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.72);
}

.composer button {
  min-height: 42px;
  padding: 0 10px;
  background: #1e745f;
  box-shadow: 0 10px 22px rgba(36, 124, 103, 0.22);
}

.drawer-header {
  position: relative;
  background: rgba(255, 253, 248, 0.9);
  backdrop-filter: blur(16px) saturate(1.08);
}

.settings-tabs {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 9px 12px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 253, 248, 0.92);
  scrollbar-width: none;
  backdrop-filter: blur(16px) saturate(1.08);
}

.settings-tabs::-webkit-scrollbar {
  display: none;
}

.settings-tabs a {
  flex: 0 0 auto;
  padding: 7px 10px;
  border: 1px solid rgba(36, 124, 103, 0.14);
  border-radius: 8px;
  color: #28594b;
  background: rgba(220, 241, 233, 0.72);
  font-size: 12px;
  font-weight: 800;
  text-decoration: none;
  white-space: nowrap;
}

.panel-section {
  margin: 0;
  border-bottom: 1px solid rgba(46, 56, 51, 0.1);
  background: rgba(255, 253, 248, 0.62);
}

.section-title h3 {
  font-size: 15px;
}

.config-form input,
.config-form textarea,
.config-form select,
.backup-history-field select {
  border-color: rgba(46, 56, 51, 0.13);
  background: rgba(255, 255, 255, 0.82);
}

.secondary,
.import-button {
  color: #28594b;
  background: rgba(220, 241, 233, 0.82);
}

.agent-card,
.memory-item,
.reference-upload,
.background-preview {
  background: rgba(255, 253, 248, 0.7);
}

@media (max-width: 720px) {
  body {
    position: fixed;
    inset: 0;
  }

  .chat-panel {
    width: 100vw;
    height: 100dvh;
  }

  .drawer {
    top: auto;
    right: 0;
    bottom: 0;
    left: 0;
    width: 100vw;
    max-height: min(88dvh, 780px);
    height: auto;
    border: 1px solid rgba(46, 56, 51, 0.12);
    border-bottom: 0;
    border-radius: 8px 8px 0 0;
    background: rgba(255, 253, 248, 0.96);
    box-shadow: 0 -24px 68px rgba(20, 24, 22, 0.22);
    transform: translateY(105%);
  }

  .drawer-left,
  .drawer-right {
    transform: translateY(105%);
  }

  .drawer.open {
    transform: translateY(0);
  }

  .drawer-left {
    display: flex;
  }

  .drawer-right {
    display: flex;
    overflow: hidden;
  }

  .drawer-right {
    flex-direction: column;
  }

  .drawer-header {
    flex: 0 0 auto;
    padding: 10px 12px 9px;
    border-bottom: 1px solid rgba(46, 56, 51, 0.1);
  }

  .drawer-header::before {
    content: "";
    position: absolute;
    top: 6px;
    left: 50%;
    width: 42px;
    height: 4px;
    border-radius: 99px;
    background: rgba(32, 36, 39, 0.18);
    transform: translateX(-50%);
  }

  .drawer-header h2 {
    font-size: 17px;
  }

  .drawer-header p {
    font-size: 11px;
  }

  .settings-tabs {
    flex: 0 0 auto;
    top: 0;
  }

  .drawer-right .panel-section,
  .drawer-left .agent-list {
    flex: 0 0 auto;
  }

  .drawer-right {
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-width: none;
    -ms-overflow-style: none;
  }

  .panel-section {
    padding: 13px 12px;
  }

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

  .range-row,
  .range-row.value-range {
    grid-template-columns: 72px minmax(0, 1fr) 44px;
  }

  .range-row:not(.value-range) {
    grid-template-columns: 72px minmax(0, 1fr);
  }

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

  .scrim {
    background: rgba(18, 23, 21, 0.34);
    backdrop-filter: blur(2px);
  }
}

@media (min-width: 721px) {
  .chat-panel {
    border-color: rgba(46, 56, 51, 0.12);
    background:
      linear-gradient(180deg, rgba(255, 253, 248, 0.96) 0%, rgba(246, 241, 232, 0.76) 42%, rgba(236, 242, 237, 0.92) 100%),
      var(--panel);
  }

  .drawer-right {
    width: min(420px, 92vw);
  }
}

/* Mobile concept v2: character stage */
:root {
  --bg: #101713;
  --panel: #fbf7ee;
  --panel-soft: #efe8db;
  --ink: #202422;
  --muted: #747b75;
  --line: rgba(30, 38, 34, 0.13);
  --accent: #2f8f71;
  --accent-strong: #17624b;
  --stage: #111a15;
  --stage-2: #1f342b;
  --warm: #e4b66a;
  --coral: #c96f64;
}

body {
  background:
    radial-gradient(circle at 18% 0%, rgba(228, 182, 106, 0.24), transparent 34%),
    radial-gradient(circle at 86% 18%, rgba(47, 143, 113, 0.26), transparent 38%),
    #101713;
}

.chat-panel {
  color: #f6f2e9;
  background:
    linear-gradient(180deg, rgba(17, 26, 21, 0.98) 0%, rgba(20, 34, 28, 0.96) 33%, rgba(238, 232, 219, 0.96) 62%, rgba(246, 242, 233, 1) 100%),
    var(--stage);
}

.chat-panel::before {
  background-size: cover;
  background-position: center top;
  opacity: 0.08;
  mix-blend-mode: screen;
}

.chat-panel.has-chat-background::before {
  opacity: var(--chat-bg-opacity, 0.48);
  filter: blur(var(--chat-bg-blur, 0)) saturate(1.08);
}

.chat-panel::after {
  height: 62%;
  background:
    linear-gradient(180deg, transparent 0%, rgba(17, 26, 21, 0.18) 18%, rgba(238, 232, 219, 0.9) 48%, #f8f3e8 100%);
}

.topbar {
  grid-template-columns: 38px minmax(0, 1fr) 72px 38px;
  padding: max(9px, env(safe-area-inset-top)) 12px 7px;
  background: rgba(13, 20, 16, 0.48);
  box-shadow: none;
}

.topbar h1 {
  color: #fffaf1;
}

.topbar p {
  color: rgba(246, 242, 233, 0.68);
}

.icon-button,
.plain-icon {
  border-color: rgba(255, 255, 255, 0.13);
  color: #fff7e8;
  background: rgba(255, 255, 255, 0.08);
  box-shadow: none;
}

.call-button {
  border-color: rgba(228, 182, 106, 0.24);
  color: #ffe3a8;
  background: rgba(228, 182, 106, 0.12);
}

.avatar,
.mini-avatar {
  background:
    radial-gradient(circle at 28% 18%, rgba(255, 255, 255, 0.5), transparent 18%),
    linear-gradient(145deg, #2f8f71 0%, #305d58 48%, #c96f64 100%);
}

.quick-actions {
  margin-top: -4px;
  padding: 0 12px 12px;
}

.quick-actions button {
  color: #fff4dd;
  border-color: rgba(255, 255, 255, 0.14);
  background: rgba(255, 255, 255, 0.1);
}

.messages {
  margin: 0 8px 0;
  padding: 16px 4px 18px;
  border-radius: 8px 8px 0 0;
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(248, 243, 232, 0.7), rgba(248, 243, 232, 0.94) 18%, rgba(248, 243, 232, 0.98) 100%);
}

.message {
  max-width: min(80%, 620px);
}

.message-meta {
  color: rgba(32, 36, 34, 0.44);
}

.message-body {
  border: 0;
  color: #222723;
  background: rgba(255, 254, 248, 0.94);
  box-shadow: 0 10px 26px rgba(28, 32, 30, 0.09);
}

.message.user .message-body {
  color: #fff9ef;
  background: linear-gradient(135deg, #25785f, #145542);
}

.message.system .message-body {
  color: #714b14;
  background: #fff0c9;
}

.message-actions {
  gap: 6px;
}

.regenerate-button {
  color: #1d634d;
  border-color: rgba(47, 143, 113, 0.16);
  background: rgba(47, 143, 113, 0.1);
}

.composer {
  margin: 0 8px 8px;
  grid-template-columns: 40px minmax(0, 1fr) 54px;
  align-items: end;
  border: 1px solid rgba(23, 31, 27, 0.1);
  border-radius: 8px;
  background: rgba(255, 253, 247, 0.9);
}

.composer::before {
  content: "+";
  display: grid;
  place-items: center;
  width: 40px;
  height: 42px;
  border: 1px solid rgba(47, 143, 113, 0.14);
  border-radius: 8px;
  color: #1c604a;
  background: rgba(47, 143, 113, 0.08);
  font-size: 22px;
  font-weight: 700;
}

.composer textarea {
  border: 0;
  background: transparent;
  box-shadow: none;
}

.composer textarea:focus {
  box-shadow: none;
}

.composer button {
  color: #fff9ef;
  background: linear-gradient(135deg, #2f8f71, #17624b);
}

.drawer {
  color: var(--ink);
}

.drawer-header {
  color: #fff8ea;
  background:
    radial-gradient(circle at 12% 0%, rgba(228, 182, 106, 0.22), transparent 30%),
    linear-gradient(135deg, rgba(17, 26, 21, 0.98), rgba(31, 52, 43, 0.98));
}

.drawer-header p {
  color: rgba(255, 248, 234, 0.64);
}

.drawer .plain-icon {
  color: #fff8ea;
  background: rgba(255, 255, 255, 0.1);
}

.settings-tabs {
  padding: 10px 12px;
  background: #f6efe3;
}

.settings-tabs a {
  color: #1e5d49;
  background: #e4f0e9;
}

.panel-section {
  padding-top: 15px;
  background: #fbf7ee;
}

.section-title {
  position: relative;
  padding-left: 10px;
}

.section-title::before {
  content: "";
  position: absolute;
  left: 0;
  top: 3px;
  bottom: 3px;
  width: 3px;
  border-radius: 99px;
  background: linear-gradient(180deg, var(--warm), var(--accent));
}

.auth-tabs {
  background: #f2eadc;
}

.auth-tabs button.active,
.secondary,
.import-button {
  color: #1e5d49;
  background: #dff0e8;
}

.config-form input,
.config-form textarea,
.config-form select,
.backup-history-field select {
  border-color: rgba(30, 38, 34, 0.12);
  background: #fffdf8;
}

@media (min-width: 721px) {
  .chat-panel {
    background:
      linear-gradient(180deg, rgba(17, 26, 21, 0.98) 0%, rgba(20, 34, 28, 0.96) 33%, rgba(238, 232, 219, 0.96) 62%, rgba(246, 242, 233, 1) 100%),
      var(--stage);
  }
}

/* Real character background fix: the uploaded character image is the hero. */
.chat-panel.has-chat-background {
  color: #fff8ee;
  background: #101512;
}

.chat-panel.has-chat-background::before {
  background-size: cover;
  background-position: center top;
  opacity: var(--chat-bg-opacity, 0.92);
  filter: blur(var(--chat-bg-blur, 0)) brightness(0.86) saturate(1.04);
  mix-blend-mode: normal;
}

.chat-panel.has-chat-background::after {
  inset: 0;
  height: auto;
  background:
    linear-gradient(180deg, rgba(10, 14, 12, 0.74) 0%, rgba(10, 14, 12, 0.26) 26%, rgba(10, 14, 12, 0.18) 58%, rgba(10, 14, 12, 0.62) 100%);
}

.chat-panel.has-chat-background .topbar {
  border-bottom: 0;
  background: linear-gradient(180deg, rgba(10, 14, 12, 0.82), rgba(10, 14, 12, 0.44)) !important;
  box-shadow: none;
  backdrop-filter: blur(10px) saturate(1.08);
}

.chat-panel.has-chat-background .topbar h1 {
  color: #fff8ee;
}

.chat-panel.has-chat-background .topbar p {
  color: rgba(255, 248, 238, 0.68);
}

.chat-panel.has-chat-background .icon-button,
.chat-panel.has-chat-background .plain-icon {
  color: #fff8ee;
  border-color: rgba(255, 255, 255, 0.2);
  background: rgba(10, 14, 12, 0.34);
}

.chat-panel.has-chat-background .call-button {
  color: #ffe1a3;
  border-color: rgba(255, 225, 163, 0.34);
  background: rgba(10, 14, 12, 0.3);
}

.chat-panel.has-chat-background .quick-actions {
  padding: 8px 12px 6px;
  background: transparent !important;
}

.chat-panel.has-chat-background .quick-actions button {
  color: #fff8ee;
  border-color: rgba(255, 255, 255, 0.22);
  background: rgba(10, 14, 12, 0.34);
  backdrop-filter: blur(8px);
}

.chat-panel.has-chat-background .messages {
  margin: 0;
  padding: 16px 12px 20px;
  color: #fff8ee;
  background: transparent;
}

.chat-panel.has-chat-background .message {
  max-width: min(82%, 620px);
}

.chat-panel.has-chat-background .message-meta {
  width: max-content;
  max-width: 100%;
  padding: 3px 8px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  color: rgba(255, 248, 238, 0.88);
  background: rgba(10, 14, 12, 0.32);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.42);
  backdrop-filter: blur(8px);
}

.chat-panel.has-chat-background .message-body {
  color: #23201d;
  background: rgba(255, 252, 244, 0.82);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.18);
  backdrop-filter: blur(10px) saturate(1.08);
}

.chat-panel.has-chat-background .message.user .message-meta {
  margin-left: auto;
  color: rgba(255, 248, 238, 0.92);
  background: rgba(28, 91, 72, 0.45);
}

.chat-panel.has-chat-background .message.user .message-body {
  color: #fff8ee;
  background: rgba(31, 112, 88, 0.82);
}

.chat-panel.has-chat-background .regenerate-button {
  color: #0f5b45;
  background: rgba(230, 248, 239, 0.82);
}

.chat-panel.has-chat-background .composer {
  margin: 0 10px 10px;
  border-color: rgba(255, 255, 255, 0.22);
  background: rgba(255, 252, 244, 0.86) !important;
  box-shadow: 0 -12px 34px rgba(0, 0, 0, 0.18);
  backdrop-filter: blur(14px) saturate(1.08);
}

.chat-panel.has-chat-background .composer textarea {
  color: #1f2522;
  background: transparent;
}

.chat-panel.has-chat-background .composer textarea::placeholder {
  color: rgba(31, 37, 34, 0.48);
}

.chat-panel.has-chat-background.background-overlay-off::before {
  filter: blur(var(--chat-bg-blur, 0)) saturate(1.04);
}

.chat-panel.has-chat-background.background-overlay-off::after {
  background: transparent;
}

.chat-panel.has-chat-background.background-overlay-off .topbar {
  background: rgba(10, 14, 12, 0.34) !important;
}

/* Voice messages already have their own bubble; don't wrap them in a second card. */
.message .message-body.voice-message-body,
.chat-panel.has-chat-background .message .message-body.voice-message-body,
.chat-panel.has-chat-background .message.user .message-body.voice-message-body {
  padding: 0;
  border: 0;
  background: transparent;
  box-shadow: none;
  backdrop-filter: none;
}

.message .message-body.voice-message-body .voice-bubble {
  box-shadow: 0 10px 24px rgba(31, 37, 40, 0.08);
}

.chat-panel.has-chat-background .message .message-body.voice-message-body .voice-bubble {
  color: #fff8ee;
  background: rgba(31, 112, 88, 0.86);
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.18);
  backdrop-filter: blur(8px);
}

.chat-panel.has-chat-background .message .message-body.voice-message-body .voice-bubble.playing {
  background: rgba(21, 89, 70, 0.92);
}

/* Keep the send button stable while a message is in flight. */
.composer button#sendButton {
  width: 64px;
  min-width: 64px;
  white-space: nowrap;
  word-break: keep-all;
}

.composer button#sendButton:disabled {
  opacity: 0.72;
  cursor: wait;
}
