:root {
  color-scheme: light;
  --paper: #f7f3ea;
  --ink: #151515;
  --muted: #6f6a60;
  --line: #d9d1c2;
  --panel: #fffaf0;
  --accent: #1f6f5b;
  --accent-ink: #ffffff;
  --danger: #9c372e;
  --focus: #255f9e;
  --shadow: 0 18px 50px rgba(29, 24, 16, 0.12);
  --chat-user: #e9f0f0;
  --chat-ai: #f5efe0;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--paper);
  color: var(--ink);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

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

.app-shell {
  min-height: 100vh;
  padding: 24px;
}

.workspace {
  max-width: 1440px;
  margin: 0 auto;
}

/* ── 顶部 ──────────────────────────────────────────────────── */

.topbar,
.output-head,
.actions,
.control-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.topbar {
  justify-content: space-between;
  margin-bottom: 18px;
  flex-wrap: wrap;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(28px, 4vw, 46px);
  line-height: 1.08;
}

h2 {
  font-size: 22px;
}

/* ── 模式切换标签 ──────────────────────────────────────────── */

.mode-tabs {
  display: flex;
  gap: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #fffefd;
}

.mode-tab {
  min-height: 38px;
  padding: 0 18px;
  border: none;
  border-radius: 0;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease;
}

.mode-tab + .mode-tab {
  border-left: 1px solid var(--line);
}

.mode-tab.active {
  background: var(--accent);
  color: var(--accent-ink);
}

.mode-tab:not(.active):hover {
  background: rgba(31, 111, 91, 0.06);
  color: var(--ink);
}

/* ── 状态指示 ──────────────────────────────────────────────── */

.status-pill {
  min-width: 96px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  background: rgba(255, 250, 240, 0.72);
  text-align: center;
  white-space: nowrap;
}

.status-pill.busy {
  color: var(--focus);
  border-color: rgba(37, 95, 158, 0.35);
}

.status-pill.error {
  color: var(--danger);
  border-color: rgba(156, 55, 46, 0.35);
}

/* ── 布局 ──────────────────────────────────────────────────── */

.grid {
  display: grid;
  grid-template-columns: minmax(420px, 0.92fr) minmax(460px, 1.08fr);
  gap: 18px;
  align-items: stretch;
}

.guide-flow {
  display: flex;
  flex-direction: column;
  gap: 18px;
  max-width: 900px;
}

/* ── 面板通用 ──────────────────────────────────────────────── */

.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.panel-head {
  padding: 18px 18px 0;
}

.panel-desc {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.input-panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 18px;
}

.output-panel {
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - 125px);
  padding: 18px;
}

.output-head {
  justify-content: space-between;
  margin-bottom: 14px;
}

/* ── 表单 ──────────────────────────────────────────────────── */

.field {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.field label,
.toggle {
  color: #2f2b25;
  font-size: 14px;
  font-weight: 700;
}

textarea,
select,
input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fffefd;
  color: var(--ink);
  outline: none;
}

textarea {
  resize: vertical;
  padding: 12px;
  line-height: 1.6;
}

select {
  min-height: 42px;
  padding: 0 12px;
}

input {
  min-height: 42px;
  padding: 0 12px;
}

textarea:focus,
select:focus,
input:focus {
  border-color: var(--focus);
  box-shadow: 0 0 0 3px rgba(37, 95, 158, 0.13);
}

.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.control-row {
  flex-wrap: wrap;
  align-items: end;
}

.compact {
  flex: 1 1 180px;
}

.toggle {
  display: flex;
  align-items: center;
  min-height: 42px;
  gap: 8px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fffefd;
}

.toggle input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.actions {
  flex-wrap: wrap;
  padding-top: 4px;
}

/* ── 按钮 ──────────────────────────────────────────────────── */

button {
  min-height: 42px;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 0 15px;
  cursor: pointer;
  transition: transform 0.12s ease, border-color 0.12s ease, background 0.12s ease;
}

button:active {
  transform: translateY(1px);
}

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

.primary {
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 800;
}

.ghost {
  border-color: var(--line);
  background: #fffefd;
  color: #2f2b25;
}

.small {
  min-height: 34px;
  padding: 0 12px;
}

/* ── 输出区 ────────────────────────────────────────────────── */

.output {
  flex: 1;
  min-height: 520px;
  margin: 0;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fffefd;
  color: #191714;
  line-height: 1.72;
  white-space: pre-wrap;
  overflow: auto;
}

.meta {
  min-height: 24px;
  margin-top: 10px;
  color: var(--muted);
  font-size: 13px;
}

.gift-result {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 10px;
  padding: 10px 12px;
  border: 1px dashed var(--line);
  border-radius: 6px;
  background: #fffefd;
  font-size: 14px;
}

.gift-result a {
  color: var(--focus);
  word-break: break-all;
}

.gift-result button {
  min-height: 30px;
  padding: 0 10px;
  font-size: 13px;
}

/* ── 人物档案面板 ──────────────────────────────────────────── */

.profile-panel {
  padding: 0;
  overflow: hidden;
}

.profile-panel .panel-head {
  padding: 18px 18px 0;
}

.profile-form {
  padding: 18px;
}

.profile-fields {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 14px;
}

.profile-fields input,
.profile-fields select {
  flex: 1 1 180px;
  min-width: 160px;
}

.profile-result {
  padding: 0 18px 18px;
}

.profile-result-card {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fffefd;
}

.profile-result-card h3 {
  margin: 0 0 12px;
  font-size: 16px;
}

.profile-result-card pre {
  margin: 0;
  white-space: pre-wrap;
  line-height: 1.7;
  font-size: 14px;
}

.profile-hint,
.profile-error {
  font-size: 14px;
  color: var(--muted);
}

.profile-error {
  color: var(--danger);
}

/* ── 引导对话面板 ──────────────────────────────────────────── */

.guide-chat-panel {
  display: flex;
  flex-direction: column;
  max-height: 640px;
}

.guide-chat-panel .panel-head {
  padding: 18px 18px 0;
  flex-shrink: 0;
}

.chat-messages {
  flex: 1;
  min-height: 300px;
  max-height: 440px;
  overflow-y: auto;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.chat-placeholder {
  color: var(--muted);
  font-size: 14px;
  text-align: center;
  margin: auto;
}

.chat-bubble {
  max-width: 85%;
}

.chat-bubble.user {
  align-self: flex-end;
}

.chat-bubble.assistant {
  align-self: flex-start;
}

.chat-role {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  margin-bottom: 4px;
  padding: 0 4px;
}

.chat-bubble.user .chat-role {
  text-align: right;
}

.chat-content {
  padding: 12px 14px;
  border-radius: 10px;
  line-height: 1.65;
  font-size: 15px;
  white-space: pre-wrap;
}

.chat-bubble.assistant .chat-content {
  background: var(--chat-ai);
  border: 1px solid var(--line);
  border-bottom-left-radius: 2px;
}

.chat-bubble.user .chat-content {
  background: var(--chat-user);
  border: 1px solid #cdd9d9;
  border-bottom-right-radius: 2px;
}

.chat-input-row {
  display: flex;
  gap: 10px;
  padding: 0 18px 18px;
  align-items: flex-end;
  flex-shrink: 0;
}

.chat-input-row textarea {
  flex: 1;
  min-height: 48px;
  max-height: 120px;
}

.chat-input-row button {
  flex-shrink: 0;
}

.guide-status {
  padding: 0 18px 14px;
  flex-shrink: 0;
}

.guide-thinking {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
  font-style: italic;
}

.guide-ready {
  margin: 0;
  font-size: 14px;
  color: var(--accent);
  font-weight: 700;
}

.guide-error {
  margin: 0;
  font-size: 14px;
  color: var(--danger);
}

/* ── 素材面板 ──────────────────────────────────────────────── */

.material-panel {
  padding: 0;
}

.material-panel .panel-head {
  padding: 18px 18px 0;
}

.material-preview {
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.material-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fffefd;
}

.material-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.material-value {
  font-size: 15px;
  line-height: 1.6;
  color: var(--ink);
}

.material-actions {
  padding: 0 18px 18px;
}

/* ── 响应式 ────────────────────────────────────────────────── */

@media (max-width: 980px) {
  .app-shell {
    padding: 14px;
  }

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

  .topbar-right {
    width: 100%;
    justify-content: space-between;
  }

  .grid,
  .two-col {
    grid-template-columns: 1fr;
  }

  .output-panel {
    min-height: 620px;
  }

  .guide-flow {
    max-width: 100%;
  }

  .chat-bubble {
    max-width: 92%;
  }

  .profile-fields input,
  .profile-fields select {
    flex: 1 1 100%;
    min-width: 100%;
  }
}

@media (max-width: 560px) {
  h1 {
    font-size: 30px;
  }

  .control-row,
  .actions {
    align-items: stretch;
    flex-direction: column;
  }

  button,
  .compact {
    width: 100%;
  }

  .mode-tabs {
    width: 100%;
  }

  .mode-tab {
    flex: 1;
    text-align: center;
  }

  .chat-input-row {
    flex-direction: column;
  }

  .chat-input-row button {
    width: 100%;
  }
}
