:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --line: #dde3ea;
  --text: #17202a;
  --muted: #697586;
  --green: #07c160;
  --green-dark: #05964a;
  --blue: #2563eb;
  --danger: #c2410c;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
}

button,
input,
textarea {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.hidden {
  display: none !important;
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-panel {
  width: min(420px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 28px;
  box-shadow: 0 20px 50px rgba(15, 23, 42, 0.08);
}

.login-panel h1 {
  margin: 0 0 8px;
  font-size: 24px;
}

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

.login-form {
  display: grid;
  gap: 12px;
}

.login-form input,
.dev-panel input,
.settings-panel input,
.settings-panel textarea,
.composer textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 12px;
  outline: none;
  background: #fff;
}

.login-form input:focus,
.dev-panel input:focus,
.settings-panel input:focus,
.settings-panel textarea:focus,
.composer textarea:focus {
  border-color: var(--green);
}

.login-form button,
.composer button[type="submit"],
.dev-panel button,
.mini-button {
  background: var(--green);
  color: #fff;
  border-radius: 6px;
  padding: 10px 14px;
}

.login-form button:hover,
.composer button[type="submit"]:hover,
.dev-panel button:hover,
.mini-button:hover {
  background: var(--green-dark);
}

.error-text {
  min-height: 20px;
  margin-top: 12px;
  color: var(--danger);
}

.app-shell {
  height: 100vh;
  display: grid;
  grid-template-columns: 340px 1fr;
}

.sidebar {
  min-width: 0;
  background: #eef3f5;
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
}

.sidebar-header {
  height: 64px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--panel);
}

.sidebar-header span {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.ghost-button {
  background: transparent;
  color: var(--muted);
}

.settings-panel,
.dev-panel {
  margin: 12px 12px 0;
  padding: 12px;
  display: grid;
  gap: 8px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.dev-panel {
  margin-top: 10px;
}

.panel-title-row,
.avatar-row,
.check-row {
  display: flex;
  align-items: center;
}

.panel-title-row {
  justify-content: space-between;
  gap: 10px;
}

.dev-title {
  color: var(--muted);
  font-size: 13px;
}

.avatar-row {
  gap: 10px;
}

.avatar-preview {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #f8fafc;
  object-fit: cover;
}

.file-button,
.tool-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  padding: 7px 10px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: #f8fafc;
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
}

.file-button:hover,
.tool-button:hover {
  background: #eef2f7;
}

.check-row {
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.check-row input {
  width: auto;
}

.status-text {
  min-height: 18px;
  color: var(--muted);
  font-size: 12px;
}

.conversation-list {
  overflow: auto;
  padding: 6px 8px 16px;
}

.conversation-item {
  width: 100%;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px;
  padding: 12px;
  margin: 4px 0;
  text-align: left;
  background: transparent;
  border-radius: 8px;
  color: var(--text);
}

.conversation-item:hover,
.conversation-item.active {
  background: var(--panel);
}

.conversation-title {
  font-weight: 650;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conversation-preview {
  grid-column: 1 / -1;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
}

.badge {
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--green);
  color: #fff;
  font-size: 12px;
  display: inline-grid;
  place-items: center;
}

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

.chat-panel {
  min-width: 0;
  display: grid;
  grid-template-rows: 64px 1fr auto;
  background: var(--panel);
}

.chat-header {
  border-bottom: 1px solid var(--line);
  padding: 10px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.chat-header h2 {
  margin: 0;
  font-size: 18px;
  word-break: break-all;
}

.chat-header p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
  word-break: break-all;
}

.chat-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.secondary-button {
  background: #edf2f7;
  color: var(--text);
  border-radius: 6px;
  padding: 8px 12px;
}

.messages {
  overflow: auto;
  padding: 18px;
  background: #f8fafc;
}

.empty-state {
  color: var(--muted);
  text-align: center;
  margin-top: 20vh;
}

.message-row {
  display: flex;
  margin: 10px 0;
}

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

.message-row.bot,
.message-row.platform-agent {
  justify-content: center;
}

.bubble {
  max-width: min(680px, 72%);
  border-radius: 8px;
  padding: 9px 12px;
  background: #fff;
  border: 1px solid var(--line);
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.outbound .bubble {
  background: #d9fdd3;
  border-color: #b6e6b0;
}

.bot .bubble,
.platform-agent .bubble {
  max-width: 80%;
  background: #eef2ff;
  color: #334155;
}

.meta {
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 12px;
}

.media-preview {
  display: block;
  max-width: min(360px, 100%);
  max-height: 280px;
  border-radius: 6px;
  margin-top: 6px;
  background: #0f172a;
}

.link-card {
  display: grid;
  gap: 4px;
  min-width: min(340px, 100%);
  color: var(--text);
  text-decoration: none;
}

.link-card strong {
  color: var(--blue);
}

.link-card span {
  color: var(--muted);
  font-size: 12px;
  word-break: break-all;
}

.reply-panel {
  border-top: 1px solid var(--line);
  background: var(--panel);
}

.quick-replies {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 10px 12px 0;
}

.quick-reply {
  flex: 0 0 auto;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--text);
  padding: 7px 11px;
  font-size: 13px;
}

.quick-reply:hover {
  background: #eef2f7;
}

.composer {
  padding: 10px 12px 12px;
  display: grid;
  grid-template-columns: 1fr 96px;
  gap: 10px;
  background: var(--panel);
}

.composer-tools {
  grid-column: 1 / -1;
  display: flex;
  gap: 8px;
}

.composer textarea {
  resize: none;
}

@media (max-width: 800px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: 46vh 54vh;
  }

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
    min-height: 0;
  }

  .settings-panel,
  .dev-panel {
    margin-left: 8px;
    margin-right: 8px;
  }

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

  .chat-header {
    padding: 8px 10px;
  }

  .bubble {
    max-width: 88%;
  }

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