/* ================================================================
   学术研究技能平台 — Academic Theme
   配色：羊皮纸暖底 · 学术酒红 · 暗金 · 墨黑
   字体：Noto Serif SC / Cormorant Garamond / Georgia 衬线
   ================================================================ */

/* ===== Reset & Base ===== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  /* 背景层 */
  --bg: #f5f1ea;            /* 羊皮纸暖底 */
  --bg-deep: #ede7dc;       /* 略深暖底 */
  --surface: #fdfbf6;       /* 纸面白 */
  --surface-hover: #f3ede2; /* 纸面悬停 */
  --surface-sunken: #efe9dd;/* 凹陷区 */

  /* 边框 */
  --border: #d9cfc0;        /* 暖米色边框 */
  --border-strong: #b8a98f; /* 深米色 */
  --border-ink: #3a352d;    /* 墨线 */

  /* 文字 */
  --text: #1c1a17;          /* 浓墨黑 */
  --text-secondary: #5c5346;/* 暖灰棕 */
  --text-muted: #8a7f6f;    /* 浅暖灰 */

  /* 主色：学术酒红 */
  --primary: #7b1e3a;
  --primary-hover: #631530;
  --primary-light: #f5ebed;
  --primary-ghost: #faf3f4;

  /* 辅色：学术暗金 */
  --gold: #8b6914;
  --gold-light: #f4ecd6;

  /* 状态色 */
  --success: #2d6a4f;
  --success-light: #e8f0ea;
  --danger: #9b2226;
  --danger-hover: #7a1a1d;
  --warning: #b8860b;

  /* 圆角：收敛，更书卷气 */
  --radius: 4px;
  --radius-sm: 2px;

  /* 阴影 */
  --shadow-sm: 0 1px 3px rgba(60,50,30,0.06);
  --shadow: 0 2px 8px rgba(60,50,30,0.10);
  --shadow-lg: 0 6px 20px rgba(60,50,30,0.12);

  /* 字体族 */
  --font-serif: 'Noto Serif SC', 'Source Han Serif SC', 'Songti SC', Georgia, 'Times New Roman', serif;
  --font-display: 'Cormorant Garamond', 'Noto Serif SC', Georgia, serif;
  --font-mono: 'SF Mono', 'JetBrains Mono', Monaco, Consolas, monospace;
}

html, body {
  height: 100%;
  font-family: var(--font-serif);
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  /* 纸张纹理：极淡的暖色噪点 */
  background-image:
    radial-gradient(circle at 20% 30%, rgba(139,105,20,0.015) 0%, transparent 50%),
    radial-gradient(circle at 80% 70%, rgba(123,30,58,0.012) 0%, transparent 50%);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ===== Header ===== */
.app-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  height: 60px;
  display: flex;
  align-items: center;
  box-shadow: var(--shadow-sm);
  position: relative;
}

/* 双线底边，古典书籍感 */
.app-header::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  bottom: -1px;
  height: 3px;
  border-top: 1px solid var(--border-strong);
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
}

.app-title {
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 10px;
  letter-spacing: 0.02em;
}

.title-text {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}

.title-main {
  font-family: var(--font-serif);
  font-size: 17px;
  font-weight: 700;
  color: var(--primary);
  letter-spacing: 0.04em;
}

.brand-prefix {
  color: var(--gold);
  font-style: normal;
}

.title-sub {
  font-family: var(--font-display);
  font-size: 11px;
  font-weight: 400;
  font-style: italic;
  color: var(--text-muted);
  letter-spacing: 0.06em;
  margin-top: 1px;
}

.logo-icon {
  font-size: 26px;
  filter: sepia(0.3) saturate(0.8);
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 10px;
}

.control-label {
  font-family: var(--font-serif);
  font-size: 12px;
  color: var(--text-secondary);
  font-weight: 600;
  letter-spacing: 0.04em;
}

.model-select {
  padding: 6px 28px 6px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-family: var(--font-serif);
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
  min-width: 260px;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath fill='%237b1e3a' d='M0 0l5 6 5-6z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  transition: border-color 0.2s;
}

.model-select:hover {
  border-color: var(--primary);
  background-color: var(--surface-hover);
}

.model-select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(123,30,58,0.12);
}

/* ===== Language Toggle ===== */
.lang-toggle {
  padding: 6px 16px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-family: var(--font-serif);
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
  letter-spacing: 0.03em;
}

.lang-toggle:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--primary-ghost);
}

.lang-toggle.lang-en {
  background: var(--primary);
  border-color: var(--primary);
  color: #fdfbf6;
}

/* ===== Fallback Notice ===== */
.fallback-notice {
  background: var(--gold-light);
  border: 1px solid #d4b96a;
  border-left: 3px solid var(--gold);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  margin-bottom: 12px;
  font-family: var(--font-serif);
  font-size: 13px;
  color: #6b520e;
  line-height: 1.6;
}

/* ===== Tool Tabs ===== */
.tool-tabs {
  display: flex;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  gap: 2px;
  overflow-x: auto;
}

.tool-tab {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 11px 18px;
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  font-family: var(--font-serif);
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
  transition: all 0.15s;
  white-space: nowrap;
  letter-spacing: 0.03em;
  position: relative;
}

.tool-tab:hover {
  color: var(--text);
  background: var(--surface-hover);
}

.tool-tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
  font-weight: 700;
}

.tab-icon {
  font-size: 17px;
  filter: sepia(0.2);
}

/* ===== Main Content ===== */
.main-content {
  display: flex;
  height: calc(100vh - 60px - 48px - 28px);
  overflow: hidden;
}

/* ===== Config Panel (Left) ===== */
.config-panel {
  width: 290px;
  min-width: 290px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 18px;
}

.panel-section {
  margin-bottom: 22px;
}

.panel-title {
  font-family: var(--font-serif);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-muted);
  margin-bottom: 10px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 6px;
}

.panel-title::before {
  content: '§';
  font-family: var(--font-display);
  font-size: 14px;
  color: var(--primary);
  font-weight: 700;
}

/* Mode List */
.mode-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.mode-item {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  border: 1px solid transparent;
  border-left: 3px solid transparent;
  transition: all 0.15s;
}

.mode-item:hover {
  background: var(--surface-hover);
  border-left-color: var(--border-strong);
}

.mode-item.active {
  background: var(--primary-light);
  border-color: var(--border);
  border-left-color: var(--primary);
}

.mode-item.active .mode-name {
  color: var(--primary);
}

.mode-name {
  font-family: var(--font-serif);
  font-size: 13.5px;
  font-weight: 600;
  margin-bottom: 2px;
  letter-spacing: 0.02em;
}

.mode-desc {
  font-family: var(--font-serif);
  font-size: 11.5px;
  color: var(--text-secondary);
  line-height: 1.5;
}

.mode-meta {
  font-family: var(--font-display);
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
  font-style: italic;
}

/* Pipeline Progress */
.pipeline-progress {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.progress-empty {
  font-family: var(--font-serif);
  font-size: 12px;
  color: var(--text-muted);
  font-style: italic;
  line-height: 1.5;
}

.progress-agent {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 9px;
  border-radius: var(--radius-sm);
  font-family: var(--font-serif);
  font-size: 12px;
  transition: all 0.2s;
  border-left: 2px solid transparent;
}

.progress-agent.pending {
  color: var(--text-muted);
}

.progress-agent.running {
  background: var(--primary-light);
  color: var(--primary);
  font-weight: 600;
  border-left-color: var(--primary);
}

.progress-agent.done {
  color: var(--success);
  border-left-color: var(--success);
}

.progress-agent.error {
  color: var(--danger);
  border-left-color: var(--danger);
}

.agent-status-icon {
  width: 16px;
  height: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  flex-shrink: 0;
  font-family: var(--font-mono);
}

.agent-status-icon.pending::before {
  content: '○';
}

.agent-status-icon.running::before {
  content: '◐';
  animation: spin 1s linear infinite;
  display: inline-block;
}

.agent-status-icon.done::before {
  content: '✓';
}

.agent-status-icon.error::before {
  content: '✗';
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Phase Tracker */
.phase-tracker {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.phase-empty {
  font-family: var(--font-serif);
  font-size: 12px;
  color: var(--text-muted);
  font-style: italic;
}

.phase-badge {
  padding: 3px 10px;
  border-radius: var(--radius-sm);
  font-family: var(--font-serif);
  font-size: 11px;
  font-weight: 500;
  background: var(--surface-hover);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  letter-spacing: 0.02em;
}

.phase-badge.active {
  background: var(--primary);
  color: #fdfbf6;
  border-color: var(--primary-hover);
}

.phase-badge.done {
  background: var(--success-light);
  color: var(--success);
  border-color: #a8c9b3;
}

/* ===== Chat Area (Right) ===== */
.chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Input Section */
.input-section {
  padding: 14px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.user-input {
  width: 100%;
  padding: 11px 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  font-family: var(--font-serif);
  font-size: 14px;
  color: var(--text);
  background: var(--surface);
  resize: vertical;
  min-height: 64px;
  max-height: 200px;
  line-height: 1.6;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.user-input::placeholder {
  color: var(--text-muted);
  font-style: italic;
}

.user-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(123,30,58,0.10);
  background: #fffefb;
}

.input-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 9px;
}

.char-count {
  font-family: var(--font-display);
  font-size: 11.5px;
  color: var(--text-muted);
  font-style: italic;
}

.input-actions {
  display: flex;
  gap: 8px;
}

/* Buttons */
.btn {
  padding: 8px 18px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-family: var(--font-serif);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  display: flex;
  align-items: center;
  gap: 6px;
  letter-spacing: 0.04em;
}

.btn-primary {
  background: var(--primary);
  color: #fdfbf6;
  border-color: var(--primary-hover);
}

.btn-primary:hover {
  background: var(--primary-hover);
  box-shadow: var(--shadow);
}

.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border-strong);
}

.btn-ghost:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.btn-danger {
  background: var(--danger);
  color: #fdfbf6;
  border-color: var(--danger-hover);
}

.btn-danger:hover {
  background: var(--danger-hover);
}

.btn-spinner {
  width: 14px;
  height: 14px;
  border: 2px solid rgba(253,251,246,0.3);
  border-top-color: #fdfbf6;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

/* Output Section */
.output-section {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
}

.output-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.output-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.export-buttons {
  display: flex;
  gap: 4px;
  margin-left: 8px;
  padding-left: 12px;
  border-left: 1px solid var(--border);
}

.btn-export {
  padding: 4px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-family: var(--font-serif);
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s;
  letter-spacing: 0.04em;
}

.btn-export:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--primary-ghost);
}

.btn-export:active {
  transform: scale(0.96);
}

.output-title {
  font-family: var(--font-serif);
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: 0.02em;
}

.output-tabs {
  display: flex;
  gap: 4px;
}

.output-tab {
  padding: 4px 12px;
  border: 1px solid transparent;
  background: transparent;
  font-family: var(--font-serif);
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: all 0.15s;
  letter-spacing: 0.02em;
}

.output-tab:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.output-tab.active {
  background: var(--primary-light);
  color: var(--primary);
  border-color: #e0c8cd;
  font-weight: 600;
}

.output-content {
  flex: 1;
  overflow-y: auto;
  padding: 24px 28px;
}

.output-placeholder {
  text-align: center;
  color: var(--text-muted);
  padding: 56px 20px;
}

.output-placeholder p {
  margin-bottom: 10px;
  font-family: var(--font-serif);
  font-size: 14px;
  line-height: 1.7;
}

/* Agent Output Block — 论文章节式 */
.agent-block {
  margin-bottom: 26px;
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.agent-block-header {
  padding: 11px 16px;
  background: var(--surface-sunken);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 9px;
}

.agent-block-icon {
  font-size: 16px;
  filter: sepia(0.2);
}

.agent-block-name {
  font-family: var(--font-serif);
  font-size: 13.5px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.agent-block-phase {
  font-family: var(--font-display);
  font-size: 11.5px;
  color: var(--text-secondary);
  margin-left: auto;
  font-style: italic;
}

.agent-block-body {
  padding: 18px 20px;
  font-family: var(--font-serif);
  font-size: 14.5px;
  line-height: 1.85;
  color: var(--text);
}

.agent-block-body h1,
.agent-block-body h2,
.agent-block-body h3,
.agent-block-body h4 {
  font-family: var(--font-serif);
  font-weight: 700;
  color: var(--text);
  margin-top: 18px;
  margin-bottom: 10px;
  letter-spacing: 0.02em;
}

.agent-block-body h1 {
  font-size: 21px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 6px;
}

.agent-block-body h2 {
  font-size: 18px;
}

.agent-block-body h3 {
  font-size: 15.5px;
}

.agent-block-body h4 {
  font-size: 14px;
  color: var(--text-secondary);
}

.agent-block-body p {
  margin-bottom: 11px;
  text-align: justify;
  text-justify: inter-ideograph;
}

.agent-block-body ul,
.agent-block-body ol {
  margin-bottom: 11px;
  padding-left: 22px;
}

.agent-block-body li {
  margin-bottom: 5px;
  line-height: 1.75;
}

.agent-block-body table {
  border-collapse: collapse;
  width: 100%;
  margin-bottom: 12px;
  font-size: 13px;
}

.agent-block-body th,
.agent-block-body td {
  border: 1px solid var(--border-strong);
  padding: 7px 11px;
  text-align: left;
}

.agent-block-body th {
  background: var(--surface-sunken);
  font-weight: 700;
  font-family: var(--font-serif);
}

.agent-block-body code {
  background: var(--surface-sunken);
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  font-family: var(--font-mono);
  color: var(--primary);
  border: 1px solid var(--border);
}

.agent-block-body pre {
  background: #2b2620;
  color: #e8e0d0;
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  overflow-x: auto;
  margin-bottom: 12px;
  font-size: 13px;
  line-height: 1.6;
  border: 1px solid #3a352d;
}

.agent-block-body pre code {
  background: none;
  padding: 0;
  color: inherit;
  border: none;
  font-family: var(--font-mono);
}

.agent-block-body blockquote {
  border-left: 3px solid var(--primary);
  padding: 6px 14px;
  color: var(--text-secondary);
  margin-bottom: 12px;
  background: var(--primary-ghost);
  font-style: italic;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

.agent-block-body strong {
  font-weight: 700;
  color: var(--text);
}

.agent-block-body em {
  font-style: italic;
}

/* Streaming indicator */
.streaming-cursor {
  display: inline-block;
  width: 2px;
  height: 16px;
  background: var(--primary);
  animation: blink 1s infinite;
  vertical-align: text-bottom;
  margin-left: 2px;
}

@keyframes blink {
  0%, 50% { opacity: 1; }
  51%, 100% { opacity: 0; }
}

/* ===== Status Bar ===== */
.status-bar {
  height: 28px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  font-family: var(--font-serif);
  font-size: 11.5px;
  color: var(--text-secondary);
  letter-spacing: 0.02em;
}

.status-text {
  display: flex;
  align-items: center;
  gap: 6px;
}

.status-text::before {
  content: '●';
  color: var(--text-muted);
  font-size: 9px;
}

/* ===== Disclaimer Bar ===== */
.disclaimer-bar {
  background: var(--bg-deep);
  border-top: 1px solid var(--border);
  padding: 10px 24px;
}

.disclaimer-text {
  font-family: var(--font-serif);
  font-size: 10.5px;
  color: var(--text-muted);
  line-height: 1.7;
  text-align: center;
  letter-spacing: 0.01em;
}

.status-text.active::before {
  color: var(--primary);
  animation: pulse 1.5s infinite;
}

.status-text.done::before {
  color: var(--success);
}

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

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

.agent-counter {
  font-weight: 600;
  font-family: var(--font-display);
  font-style: italic;
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar {
  width: 7px;
  height: 7px;
}

::-webkit-scrollbar-track {
  background: var(--bg-deep);
}

::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 3px;
  border: 1px solid var(--bg-deep);
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* ===== Selection ===== */
::selection {
  background: var(--primary-light);
  color: var(--primary-hover);
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .config-panel {
    width: 230px;
    min-width: 230px;
  }

  .tool-tab .tab-label {
    display: none;
  }

  .model-select {
    min-width: 180px;
  }

  .title-sub {
    display: none;
  }

  .output-content {
    padding: 16px 18px;
  }

  .export-buttons {
    padding-left: 8px;
  }

  .btn-export {
    padding: 4px 8px;
    font-size: 10.5px;
  }
}
