:root {
  --gov-blue: #2f6bdf;
  --gov-blue-deep: #1d4fc0;
  --gov-blue-soft: #eaf1fd;
  --ink: #22304a;
  --ink-soft: #5b6b87;
  --bg: #f4f6fb;
  --card: #ffffff;
  --bubble-agent: #ffffff;
  --bubble-user: #2f6bdf;
  --bubble-user-text: #ffffff;
  --warm: #fff8ef;
  --radius: 18px;
  --shadow: 0 10px 30px rgba(29, 63, 114, 0.08);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  background: linear-gradient(160deg, #eef3fb 0%, #f6f7fb 45%, #fdf9f3 100%);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

.page {
  display: grid;
  grid-template-columns: 340px 1fr;
  gap: 22px;
  max-width: 1180px;
  margin: 0 auto;
  padding: 22px;
  height: 100%;
}

/* ── 左侧形象面板 ─────────────────────────────── */
.portrait-panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 0;
}

.portrait-card {
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  flex: 1;
  min-height: 320px;
}

.portrait-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center top;
  display: block;
}

.portrait-overlay {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  padding: 46px 18px 16px;
  background: linear-gradient(to top, rgba(13, 30, 60, 0.72), rgba(13, 30, 60, 0));
  color: #fff;
}

.portrait-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  background: rgba(255, 255, 255, 0.18);
  backdrop-filter: blur(4px);
  border-radius: 999px;
  padding: 3px 10px;
  margin-bottom: 8px;
}

.portrait-status .dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: #5df0a5;
  animation: breath 2.6s ease-in-out infinite;
}

@keyframes breath {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.45; }
}

.portrait-name { font-size: 22px; font-weight: 700; letter-spacing: 1px; }
.portrait-title { font-size: 12.5px; opacity: 0.85; margin-top: 2px; }

.portrait-note {
  background: var(--warm);
  border: 1px solid #f2e3cd;
  border-radius: 14px;
  padding: 12px 14px;
  font-size: 13px;
  line-height: 1.7;
  color: #7a5b33;
}

/* ── 右侧对话面板 ─────────────────────────────── */
.chat-panel {
  display: flex;
  flex-direction: column;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  min-height: 0;
  overflow: hidden;
}

.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid #edf1f7;
}

.chat-avatar {
  width: 44px; height: 44px;
  border-radius: 50%;
  object-fit: cover;
  object-position: center 12%;
  border: 2px solid var(--gov-blue-soft);
}

.chat-header-name { font-weight: 700; font-size: 16px; }
.chat-header-sub { font-size: 12px; color: var(--ink-soft); margin-top: 1px; }

.ghost-btn {
  margin-left: auto;
  border: 1px solid #d8e2f2;
  background: #fff;
  color: var(--gov-blue-deep);
  border-radius: 999px;
  padding: 7px 16px;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s ease;
}
.ghost-btn:hover { background: var(--gov-blue-soft); }

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scroll-behavior: smooth;
}

.msg {
  display: flex;
  gap: 10px;
  max-width: 86%;
  animation: rise 0.22s ease both;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

.msg.user { align-self: flex-end; flex-direction: row-reverse; }

.msg .avatar {
  width: 34px; height: 34px;
  border-radius: 50%;
  flex: none;
  object-fit: cover;
  object-position: center 12%;
  border: 1.5px solid #e6ecf5;
}

.msg .bubble {
  padding: 11px 15px;
  border-radius: 16px;
  font-size: 15px;
  line-height: 1.75;
  white-space: pre-wrap;
  word-break: break-word;
}

.msg.agent .bubble {
  background: var(--bubble-agent);
  border: 1px solid #e8eef7;
  border-top-left-radius: 6px;
  color: var(--ink);
}

.msg.user .bubble {
  background: var(--bubble-user);
  color: var(--bubble-user-text);
  border-top-right-radius: 6px;
}

.typing-dots { display: inline-flex; gap: 4px; align-items: center; height: 18px; }
.typing-dots i {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: #b7c5dd;
  animation: bounce 1.2s infinite;
}
.typing-dots i:nth-child(2) { animation-delay: 0.15s; }
.typing-dots i:nth-child(3) { animation-delay: 0.3s; }
@keyframes bounce {
  0%, 60%, 100% { transform: none; opacity: 0.5; }
  30% { transform: translateY(-4px); opacity: 1; }
}

.tool-chip {
  align-self: flex-start;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 12.5px;
  color: var(--ink-soft);
  background: var(--gov-blue-soft);
  border-radius: 999px;
  padding: 6px 13px;
}
.tool-chip .spinner {
  width: 12px; height: 12px;
  border-radius: 50%;
  border: 2px solid #c3d5f4;
  border-top-color: var(--gov-blue);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.caret {
  display: inline-block;
  width: 2px; height: 16px;
  background: var(--gov-blue);
  margin-left: 2px;
  vertical-align: -2px;
  animation: breath 1s infinite;
}

/* ── 输入区 ───────────────────────────────────── */
.composer {
  border-top: 1px solid #edf1f7;
  padding: 12px 14px 14px;
  background: #fbfcfe;
}

.topics {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}

.topic {
  border: 1px solid #d9e4f5;
  background: #fff;
  color: var(--gov-blue-deep);
  font-size: 12.5px;
  border-radius: 999px;
  padding: 6px 13px;
  cursor: pointer;
  transition: all 0.15s ease;
}
.topic:hover { background: var(--gov-blue-soft); border-color: var(--gov-blue); }

.input-row {
  display: flex;
  gap: 10px;
  align-items: flex-end;
}

textarea {
  flex: 1;
  resize: none;
  border: 1.5px solid #dde6f3;
  border-radius: 14px;
  padding: 11px 14px;
  font: inherit;
  font-size: 15px;
  line-height: 1.6;
  max-height: 132px;
  outline: none;
  background: #fff;
  transition: border-color 0.15s ease;
}
textarea:focus { border-color: var(--gov-blue); }

#send {
  border: none;
  background: var(--gov-blue);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  border-radius: 14px;
  padding: 12px 22px;
  cursor: pointer;
  transition: background 0.15s ease;
}
#send:hover { background: var(--gov-blue-deep); }
#send:disabled { background: #b9cdf1; cursor: not-allowed; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 34px;
  transform: translateX(-50%);
  background: rgba(30, 42, 66, 0.92);
  color: #fff;
  font-size: 13.5px;
  border-radius: 12px;
  padding: 11px 20px;
  z-index: 50;
  animation: rise 0.2s ease both;
}

/* ── 窄屏 ─────────────────────────────────────── */
@media (max-width: 900px) {
  .page { grid-template-columns: 1fr; padding: 0; gap: 0; height: 100dvh; }
  .portrait-panel { display: none; }
  .chat-panel { border-radius: 0; }
  .chat-header { background: linear-gradient(120deg, var(--gov-blue), #4d86ec); color: #fff; }
  .chat-header-name, .chat-header-sub { color: #fff; }
  .ghost-btn { border-color: rgba(255,255,255,0.5); background: transparent; color: #fff; }
  .ghost-btn:hover { background: rgba(255,255,255,0.15); }
  .msg { max-width: 92%; }
}
