:root {
  color-scheme: light;
  --milk: #fbf4e6;
  --milk-deep: #f3ead8;
  --milk-soft: #fffaf0;
  --milk-warm: #efe3cd;
  --ink: #2d2820;
  --muted: #7b7165;
  --button: #342e26;
  --button-soft: #e7dcc9;
  --focus: rgba(52, 46, 38, 0.18);
  --shadow-panel: 0 26px 70px rgba(70, 53, 30, 0.13);
  --shadow-soft: 0 12px 34px rgba(70, 53, 30, 0.1);
  --shadow-tiny: 0 6px 18px rgba(70, 53, 30, 0.08);
  --fangsong: "Heiti SC", "STHeiti", "Microsoft YaHei", "PingFang SC", SimHei, sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  min-width: 320px;
  background: var(--milk);
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: var(--milk);
  font-family: var(--fangsong);
  letter-spacing: 0;
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.chat-shell {
  display: grid;
  grid-template-columns: 315px minmax(0, 1fr);
  gap: 24px;
  width: min(1480px, calc(100% - 48px));
  height: calc(100vh - 48px);
  min-height: 700px;
  margin: 24px auto;
  overflow: hidden;
  background: transparent;
}

.agent-sidebar,
.chat-panel {
  min-width: 0;
  overflow: hidden;
  border-radius: 8px;
  background: rgba(255, 250, 240, 0.38);
  box-shadow: var(--shadow-panel);
}

.agent-sidebar {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
}

.chat-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  background: rgba(255, 250, 240, 0.56);
}

.sidebar-head {
  padding: 26px 12px 16px;
}

.sidebar-head p,
.chat-kicker {
  margin: 0 0 7px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 400;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  color: var(--ink);
  font-size: 24px;
  font-weight: 400;
  line-height: 1.14;
}

.search-box {
  display: grid;
  gap: 8px;
  padding: 14px 12px 12px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 400;
}

.search-box input {
  width: 100%;
  height: 40px;
  border: 0;
  border-radius: 8px;
  padding: 0 13px;
  color: var(--ink);
  background: var(--milk-soft);
  box-shadow: var(--shadow-tiny);
  outline: none;
}

.search-box input::placeholder,
.message-box textarea::placeholder,
.api-grid input::placeholder {
  color: rgba(45, 40, 32, 0.42);
}

.search-box input:focus,
.message-box textarea:focus,
.api-grid input:focus,
.agent-row:focus-visible,
.send-button:focus-visible,
.secondary-button:focus-visible,
.ghost-button:focus-visible {
  outline: none;
  background: var(--milk-deep);
}

.agent-list {
  display: grid;
  align-content: start;
  gap: 4px;
  overflow: auto;
  padding: 4px 4px 14px;
}

.agent-row {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 9px;
  width: 100%;
  min-height: 40px;
  border: 0;
  border-radius: 8px;
  padding: 0 12px;
  color: var(--ink);
  background: transparent;
  text-align: left;
  font-size: 14px;
  font-weight: 400;
}

.agent-icon {
  display: inline-grid;
  flex: 0 0 28px;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 999px;
  color: var(--ink);
  background: rgba(255, 250, 240, 0.72);
  box-shadow: var(--shadow-tiny);
  font-size: 12px;
  line-height: 1;
}

svg.agent-icon {
  padding: 6px;
}

.agent-row:hover {
  background: rgba(255, 250, 240, 0.58);
  box-shadow: var(--shadow-tiny);
}

.agent-row.is-selected {
  background: var(--milk-soft);
  box-shadow: var(--shadow-soft);
}

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

.agent-row::after {
  flex: 0 0 auto;
  margin-left: auto;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: rgba(45, 40, 32, 0.18);
  content: "";
}

.agent-row.is-selected::after {
  background: var(--ink);
}

.chat-header {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  align-items: center;
  min-height: 84px;
  padding: 18px 26px 12px;
  background: transparent;
}

.chat-header h2 {
  margin: 0;
  color: var(--ink);
  font-size: 23px;
  font-weight: 400;
  line-height: 1.18;
}

.chat-tools {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  align-items: center;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  border: 0;
  border-radius: 999px;
  padding: 0 12px;
  color: var(--muted);
  background: var(--milk-soft);
  box-shadow: var(--shadow-tiny);
  font-size: 11px;
  font-weight: 400;
}

.conversation-list {
  display: grid;
  align-content: start;
  gap: 12px;
  overflow: auto;
  padding: 22px 26px;
  background: transparent;
}

.message {
  display: grid;
  gap: 7px;
  width: min(760px, 84%);
  padding: 13px 15px;
  border: 0;
  border-radius: 8px;
  color: var(--ink);
  background: var(--milk-soft);
  box-shadow: var(--shadow-soft);
}

.message.user {
  justify-self: end;
  color: var(--ink);
  background: var(--milk-warm);
  box-shadow: var(--shadow-soft);
}

.message.assistant {
  justify-self: start;
}

.message.empty {
  justify-self: center;
  max-width: 520px;
  color: var(--muted);
  text-align: center;
}

.message-role {
  color: var(--muted);
  font-size: 11px;
  font-weight: 400;
}

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

.message-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 108px;
  gap: 10px;
  padding: 14px 18px 18px;
  background: transparent;
}

.message-box {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 400;
}

.message-box textarea {
  width: 100%;
  min-height: 86px;
  max-height: 220px;
  resize: vertical;
  border: 0;
  border-radius: 8px;
  padding: 13px;
  color: var(--ink);
  background: var(--milk-soft);
  box-shadow: var(--shadow-soft);
  line-height: 1.66;
  outline: none;
}

.send-button,
.secondary-button,
.ghost-button {
  min-height: 36px;
  border: 0;
  border-radius: 8px;
  padding: 0 14px;
  font-size: 13px;
  font-weight: 400;
}

.send-button {
  align-self: end;
  height: 86px;
  color: #fffaf0;
  background: var(--button);
  box-shadow: var(--shadow-soft);
}

.send-button:hover,
.secondary-button:hover {
  background: #211d18;
}

.send-button:disabled {
  cursor: wait;
  opacity: 0.72;
}

.secondary-button {
  color: #fffaf0;
  background: var(--button);
  box-shadow: var(--shadow-tiny);
}

.ghost-button {
  color: var(--ink);
  background: var(--button-soft);
  box-shadow: var(--shadow-tiny);
}

.ghost-button:hover {
  background: var(--milk-warm);
}

.api-settings {
  background: transparent;
}

.api-settings summary {
  min-height: 38px;
  padding: 11px 18px;
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
  font-weight: 400;
}

.api-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(0, 0.8fr);
  gap: 10px;
  padding: 0 18px 12px;
}

.api-grid label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 400;
}

.api-grid input {
  width: 100%;
  height: 38px;
  border: 0;
  border-radius: 8px;
  padding: 0 11px;
  color: var(--ink);
  background: var(--milk-soft);
  box-shadow: var(--shadow-tiny);
  outline: none;
}

.api-key-field {
  grid-column: 1 / -1;
}

.api-key-field.is-hidden {
  display: none;
}

.api-actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 90px 90px;
  gap: 8px;
  padding: 0 18px 18px;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 20;
  max-width: min(360px, calc(100vw - 40px));
  padding: 12px 14px;
  border-radius: 8px;
  color: #fffaf0;
  background: var(--button);
  box-shadow: var(--shadow-soft);
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.no-results {
  padding: 18px;
  color: var(--muted);
  text-align: center;
}

@media (max-width: 820px) {
  .chat-shell {
    grid-template-columns: 1fr;
    width: min(100% - 24px, 1480px);
    height: auto;
    min-height: 100vh;
    margin: 12px auto;
    gap: 12px;
  }

  .sidebar-head {
    padding: 20px 10px 10px;
  }

  h1 {
    font-size: 22px;
  }

  .agent-list {
    max-height: 250px;
  }

  .chat-panel {
    min-height: 640px;
  }

  .chat-header,
  .message-form,
  .api-grid,
  .api-actions {
    grid-template-columns: 1fr;
  }

  .chat-header {
    display: grid;
    padding: 20px 18px 12px;
  }

  .chat-header h2 {
    font-size: 21px;
  }

  .chat-tools {
    justify-content: flex-start;
  }

  .conversation-list {
    padding: 20px;
  }

  .message {
    width: 100%;
  }

  .message-form {
    display: grid;
  }

  .send-button {
    width: 100%;
    height: 42px;
  }

  .api-key-field {
    grid-column: auto;
  }
}
