:root {
  --bg: #f5f7f6;
  --panel: #ffffff;
  --line: #cbd6d1;
  --text: #17211c;
  --muted: #5d6d65;
  --accent: #007a6c;
  --accent-soft: #dcefed;
  --danger: #ab3c3c;
  --good: #2f7a4f;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Inter", "SF Pro Text", "PingFang SC", "Noto Sans CJK SC", "Microsoft YaHei", sans-serif;
  color: var(--text);
  background: var(--bg);
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

.shell {
  width: min(1180px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 24px 0 48px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 24px;
  padding: 18px 20px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(8px);
}

.brand {
  font-family: "Avenir Next", "Inter", "SF Pro Display", "PingFang SC", "Noto Sans CJK SC", sans-serif;
  font-size: 1.24rem;
  font-weight: 800;
  letter-spacing: 0;
}

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

.nav form {
  margin: 0;
}

.hero,
.panel,
.table-panel,
.grid-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 10px 28px rgba(23, 33, 28, 0.05);
}

.hero {
  padding: 28px;
}

.hero h1,
.panel h1,
.panel h2,
.grid-panel h2 {
  margin-top: 0;
}

.hero p,
.panel p,
.muted {
  color: var(--muted);
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
}

.stack {
  display: grid;
  gap: 16px;
}

.panel,
.grid-panel,
.table-panel {
  padding: 20px;
}

.card {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.metric {
  font-size: 1.7rem;
  font-weight: 700;
  margin-top: 6px;
}

.metric-line {
  font-size: 0.92rem;
  color: var(--muted);
}

form {
  display: grid;
  gap: 14px;
}

.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
}

.field-note {
  margin: -4px 0 2px;
  font-size: 0.88rem;
  line-height: 1.6;
}

label {
  display: grid;
  gap: 6px;
  font-size: 0.92rem;
}

.api-key-control {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
}

.api-key-control input {
  min-width: 0;
}

.api-key-control button {
  white-space: nowrap;
}

.credit-status {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  color: var(--muted);
}

.credit-status[data-state="ok"] {
  color: var(--good);
}

.credit-status[data-state="error"] {
  color: var(--danger);
}

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

input,
textarea,
select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

textarea {
  min-height: 120px;
  resize: vertical;
}

button,
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 16px;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  background: var(--accent);
  color: white;
}

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

.button.alt,
button.alt {
  background: var(--accent-soft);
  color: var(--accent);
}

.button.warn,
button.warn {
  background: #f4dede;
  color: var(--danger);
}

.status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 0.88rem;
  background: var(--accent-soft);
  color: var(--accent);
}

.status.completed {
  background: #dceede;
  color: var(--good);
}

.status.awaiting_outline_confirmation {
  background: #fff0c7;
  color: #6f5300;
}

.status.awaiting_figure_selection {
  background: #e6f1ff;
  color: #1d5485;
}

.status.failed,
.status.budget_exceeded {
  background: #f5dfdf;
  color: var(--danger);
}

.progress-shell {
  display: grid;
  gap: 10px;
  margin: 18px 0 16px;
  padding: 16px 18px;
  border: 1px solid rgba(0, 122, 108, 0.18);
  border-radius: 8px;
  background: #f2fbf9;
}

.progress-head {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
  align-items: center;
}

.progress-meta {
  display: grid;
  gap: 4px;
  justify-items: end;
  font-size: 0.9rem;
  color: var(--muted);
}

.progress-value {
  font-size: 2rem;
  line-height: 1;
}

.progress-track,
.mini-progress {
  overflow: hidden;
  border-radius: 8px;
  background: rgba(0, 122, 108, 0.12);
}

.progress-track {
  width: 100%;
  height: 12px;
}

.progress-bar,
.mini-progress-bar {
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
  transition: width 0.3s ease;
}

.progress-foot {
  display: grid;
  gap: 4px;
}

.mini-progress {
  margin-top: 10px;
  width: min(180px, 100%);
  height: 8px;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

th {
  font-size: 0.88rem;
  color: var(--muted);
}

pre.log-box {
  margin: 0;
  padding: 16px;
  border-radius: 8px;
  background: #1d2522;
  color: #e3efe7;
  white-space: pre-wrap;
  line-height: 1.6;
  min-height: 220px;
}

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

.report-detail-grid {
  --report-scroll-window-height: 420px;
}

.report-scroll-panel {
  display: grid;
  gap: 12px;
  align-content: start;
}

.report-scroll-panel h2 {
  margin: 0;
}

.report-scroll-window {
  height: var(--report-scroll-window-height, 420px);
  overflow-y: auto;
}

.report-log-window {
  height: var(--report-scroll-window-height, 420px);
  overflow-y: scroll;
  scrollbar-gutter: stable;
  border-radius: 8px;
  background: #1d2522;
}

.report-log-content {
  min-height: 100%;
}

.report-scroll-window iframe.preview {
  height: 100%;
  min-height: 0;
}

.artifact-links {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.figure-candidate-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
}

.figure-candidate-card {
  align-content: start;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.figure-candidate-card input {
  width: auto;
}

.figure-candidate-card img {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: contain;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f7faf8;
}

.figure-candidate-title {
  font-weight: 700;
}

.figure-candidate-meta,
.figure-candidate-caption,
.figure-candidate-score {
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.5;
}

.chat-page {
  gap: 18px;
}

.chat-config-panel,
.chat-room {
  padding: 24px;
}

.chat-workspace {
  display: grid;
  grid-template-columns: minmax(230px, 300px) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.chat-history-panel {
  display: grid;
  gap: 14px;
  padding: 18px;
  max-height: 74vh;
  overflow-y: auto;
}

.chat-history-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}

.chat-history-head h2 {
  margin: 0;
}

.chat-history-list {
  display: grid;
  gap: 6px;
}

.chat-history-item {
  display: grid;
  gap: 4px;
  padding: 10px 12px;
  border-left: 3px solid transparent;
  border-radius: 8px;
  color: var(--text);
}

.chat-history-item:hover,
.chat-history-item.active {
  background: #eef4ef;
  text-decoration: none;
}

.chat-history-item.active {
  border-left-color: var(--accent);
}

.chat-history-title {
  font-weight: 700;
}

.chat-history-preview,
.chat-history-meta,
.chat-history-model {
  overflow: hidden;
  color: var(--muted);
  font-size: 0.82rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-config-head,
.chat-room-head,
.chat-compose-actions {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.chat-room-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.chat-config-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.chat-room {
  display: grid;
  gap: 16px;
}

.chat-status-line {
  display: inline-flex;
  align-items: center;
  min-height: 42px;
  padding: 0 14px;
  border-radius: 8px;
  background: #eef4ef;
  color: #315541;
  font-size: 0.92rem;
}

.chat-thread {
  min-height: 480px;
  max-height: 68vh;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f9fbfa;
  overflow-y: auto;
  display: grid;
  gap: 14px;
}

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

.chat-message {
  display: grid;
  gap: 6px;
  max-width: min(780px, 92%);
}

.chat-message.user {
  margin-left: auto;
}

.chat-message.assistant {
  margin-right: auto;
}

.chat-role {
  font-size: 0.82rem;
  color: var(--muted);
  letter-spacing: 0;
}

.chat-message.user .chat-role {
  justify-self: end;
  color: var(--accent);
  font-weight: 700;
  text-align: right;
}

.chat-bubble {
  padding: 16px 18px;
  border-radius: 8px;
  border: 1px solid rgba(23, 33, 28, 0.08);
  background: var(--panel);
  box-shadow: 0 8px 20px rgba(23, 33, 28, 0.05);
}

.chat-message.user .chat-bubble {
  background: var(--accent);
  color: white;
}

.chat-message.assistant .chat-bubble {
  border-top-left-radius: 8px;
}

.chat-message.pending .chat-bubble {
  background: #ecf3f0;
  color: #4c6258;
}

.chat-message.error .chat-bubble {
  background: #faecec;
  border-color: rgba(171, 60, 60, 0.18);
  color: var(--danger);
}

.chat-text {
  margin: 0;
  color: var(--text);
  white-space: pre-wrap;
  line-height: 1.8;
}

.chat-message.user .chat-bubble .chat-text {
  color: white !important;
}

p.user-chat-text {
  color: white !important;
}

.chat-compose {
  display: grid;
  gap: 12px;
}

.chat-compose textarea {
  min-height: 128px;
}

.inline-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 12px 0;
}

.inline-actions form {
  display: block;
}

.brief-topic-card {
  display: grid;
  gap: 12px;
}

.keyword-chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.keyword-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--accent-soft);
  color: var(--accent);
}

.chip-remove {
  padding: 0 4px;
  min-width: 24px;
  min-height: 24px;
  border-radius: 8px;
  background: transparent;
  color: var(--danger);
}

.outline-row {
  display: grid;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

#outline-rows {
  display: grid;
  gap: 12px;
}

iframe.preview {
  width: 100%;
  min-height: 720px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
}

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

.success {
  color: var(--good);
}

@media (max-width: 900px) {
  .two-col {
    grid-template-columns: 1fr;
  }

  .chat-config-grid {
    grid-template-columns: 1fr;
  }

  .chat-workspace {
    grid-template-columns: 1fr;
  }

  .chat-history-panel {
    max-height: none;
  }

  .progress-meta {
    justify-items: start;
  }

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

  .chat-thread {
    max-height: none;
    min-height: 420px;
  }
}

@media (max-width: 520px) {
  .api-key-control {
    grid-template-columns: 1fr;
  }

  .api-key-control button {
    width: 100%;
  }
}
