:root {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --bg: #ededf0;
  --surface: #ffffff;
  --surface-elevated: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --line: #e5e7eb;
  --line-strong: #d1d5db;
  --primary: #2f7ebd;
  --primary-hover: #286ea6;
  --primary-soft: #edf6ff;
  --secondary-bg: #f2f3f5;
  --secondary-text: #374151;
  --danger: #c78e2b;
  --danger-hover: #a97821;
  --danger-soft: #fef2f2;
  --danger-line: #fecaca;
  --success-soft: #ecf8f1;
  --success-line: #9cd8b7;
  --warning-soft: #fff5e9;
  --warning-line: #ecc48f;
  --warning-text: #8d5a16;
  --info-soft: #eff6ff;
  --info-line: #9ec5e8;
  --info-text: #2f7ebd;
  --shadow-sm: 0 1px 0 rgba(17, 24, 39, 0.04), 0 10px 26px rgba(17, 24, 39, 0.06);
  --shadow-md: 0 2px 0 rgba(17, 24, 39, 0.05), 0 20px 46px rgba(17, 24, 39, 0.11);
  --radius: 14px;
  --radius-sm: 10px;
  --header-bg: #f3f4f6;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  font-size: 14px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 20px;
  background: var(--header-bg);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

.brand-mark {
  width: 32px;
  height: 32px;
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #4d8ec4;
  color: #fff;
  border: 1px solid #3f7ead;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.05em;
}

.brand-text {
  display: grid;
  line-height: 1.12;
}

.brand-text strong {
  color: var(--text);
  font-size: 16px;
  letter-spacing: 0.01em;
}

.brand-text small {
  color: var(--muted);
  font-size: 11px;
}

.topnav {
  display: inline-flex;
  gap: 10px;
  align-items: center;
}

.topnav a {
  text-decoration: none;
  color: var(--primary);
  font-weight: 600;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
}

.topnav a:hover {
  background: var(--primary-soft);
  border-color: #cfe3f5;
}

.topnav .nav-ghost {
  color: #475569;
}

.container {
  max-width: 920px;
  margin: 16px auto;
  padding: 0 16px 48px;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.section-header h1 {
  margin: 0;
  font-size: 32px;
  line-height: 1.18;
  letter-spacing: -0.02em;
}

.section-header h2 {
  margin: 0;
}

.meta-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 10px 0 14px;
}

.card {
  background: var(--surface-elevated);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 14px;
  box-shadow: var(--shadow-sm);
}

.card > h1,
.card > h2 {
  margin: -16px -18px 14px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--line);
  font-size: 18px;
  line-height: 1.25;
  letter-spacing: -0.01em;
}

.card > h2 {
  font-size: 16px;
}

.card h2 {
  margin: 0;
}

.card-title-link {
  color: inherit;
  text-decoration: none;
}

.card-title-link:hover {
  text-decoration: underline;
  text-decoration-thickness: 2px;
  text-underline-offset: 3px;
}

.card.narrow {
  width: min(640px, 100%);
  max-width: 640px;
}

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

.card-head-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 10px;
}

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

.form.inline {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: end;
}

.inline-fields-stacked {
  display: grid;
  gap: 12px;
  margin: 12px;
}

.inline-fields-stacked label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 0;
}

.inline-fields-stacked .field-label {
  white-space: nowrap;
}

.inline-fields-stacked input,
.inline-fields-stacked select,
.inline-fields-stacked textarea {
  width: min(420px, 60vw);
}

.align-end {
  justify-self: end;
}

label {
  display: grid;
  gap: 6px;
  font-size: 14px;
  color: #374151;
}

input,
select,
textarea,
button {
  font-size: 14px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: #fff;
  color: var(--text);
}

input,
select,
textarea {
  padding: 8px 10px;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: #7ea5f0;
  box-shadow: 0 0 0 3px rgba(43, 95, 217, 0.16);
}

button {
  cursor: pointer;
  background: var(--primary);
  color: #fff;
  border-color: #2b72aa;
  font-weight: 600;
  transition: all 0.2s ease;
  border-radius: 11px;
  padding: 6px 10px;
}

button:hover {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
}

button.secondary {
  background: var(--secondary-bg);
  color: var(--secondary-text);
  border-color: var(--line);
}

button.secondary:hover {
  background: #e7edf6;
}

button.success {
  background: #3f8a65;
  border-color: #3f8a65;
  color: #fff;
}

button.success:hover {
  background: #347457;
  border-color: #347457;
}

button.danger {
  background: #fff;
  color: var(--danger);
  border-color: #e5c07b;
}

button.danger:hover {
  background: #fff8ec;
  border-color: #d8a55d;
  color: var(--danger-hover);
}

.button-link {
  display: inline-block;
  padding: 6px 10px;
  background: var(--primary);
  color: #fff;
  text-decoration: none;
  border-radius: var(--radius-sm);
  font-weight: 600;
  transition: background-color 0.2s ease;
}

.button-link:hover {
  background: var(--primary-hover);
}

.ghost-link {
  background: var(--secondary-bg);
  color: var(--secondary-text);
  border: 1px solid var(--line);
}

.table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 8px;
}

.table th,
.table td {
  border: 1px solid var(--line);
  padding: 9px 10px;
  text-align: left;
  font-size: 13px;
}

.table th {
  background: #e7e7ea;
  color: #334155;
  font-weight: 700;
}

.table tbody tr:nth-child(even) {
  background: #f7f7f8;
}

.tone-row-success {
  background: #eef8f2;
}

.tone-row-info {
  background: #edf5fd;
}

.tone-row-warning {
  background: #fbf4e8;
}

.tone-row-neutral {
  background: #f4f4f6;
}

.unit-text {
  white-space: pre-wrap;
  word-break: break-word;
  background: #f7f7f8;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 10px;
}

.unit-text-rich {
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
}

.cite-ref {
  color: #3a6ea5;
  text-decoration: none;
  border-bottom: 1px dashed #c9dcf6;
}

.cite-ref:hover {
  background: #f3f8ff;
  border-bottom-color: #a9c7f0;
}

.bib-popover {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.18);
  display: none;
  align-items: flex-start;
  justify-content: center;
  padding: 80px 16px 24px;
  z-index: 1000;
}

.bib-popover[aria-hidden="false"] {
  display: flex;
}

.bib-popover-card {
  width: min(920px, 100%);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow-md);
  overflow: hidden;
}

.bib-popover-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 14px;
  background: #f3f4f6;
  border-bottom: 1px solid var(--line);
}

.bib-popover-close {
  background: transparent;
  border: 1px solid transparent;
  color: #475569;
  font-size: 18px;
  line-height: 1;
  padding: 4px 8px;
  border-radius: 10px;
  cursor: pointer;
}

.bib-popover-close:hover {
  background: #e5e7eb;
}

.bib-popover-body {
  margin: 0;
  padding: 12px 14px;
  white-space: pre-wrap;
  word-break: break-word;
  background: #fbfbfc;
  max-height: min(70vh, 560px);
  overflow: auto;
}

.status-failed {
  background: var(--danger-soft);
  border-color: var(--danger-line);
  color: #991b1b;
}

.toast-stack {
  position: fixed;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  width: min(920px, calc(100% - 32px));
  z-index: 2000;
  display: grid;
  gap: 10px;
}

.toast {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: #ffffff;
  box-shadow: var(--shadow-sm);
}

.toast-body {
  font-weight: 600;
  color: #1f2937;
}

.toast-close {
  background: transparent;
  border: 1px solid transparent;
  color: #475569;
  font-size: 18px;
  line-height: 1;
  padding: 4px 8px;
  border-radius: 10px;
  cursor: pointer;
}

.toast-close:hover {
  background: #e5e7eb;
}

.toast-success {
  background: #f3f8ff;
  border-color: #d7e7ff;
  color: #3a6ea5;
}

.toast-error {
  background: var(--danger-soft);
  border-color: var(--danger-line);
}

.toast-hide {
  opacity: 0;
  transform: translateY(-6px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.auth-center {
  min-height: calc(100vh - 140px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px 0;
}

.auth-card h1 {
  margin-top: 0;
  margin-bottom: 8px;
  font-size: 38px;
  letter-spacing: -0.02em;
  font-weight: 700;
}

.auth-subtitle {
  margin: 0 0 22px;
  color: var(--muted);
  font-size: 15px;
}

.auth-card {
  position: relative;
  overflow: hidden;
}

.auth-card::before {
  content: none;
}

.auth-card p {
  color: var(--muted);
}

.auth-card a {
  color: var(--primary);
  font-weight: 600;
}

.list {
  display: grid;
  gap: 12px;
}

.muted {
  color: var(--muted);
}

.inline-link {
  color: var(--primary);
  font-weight: 600;
  text-decoration: none;
}

.inline-link:hover {
  text-decoration: underline;
}

.details-panel {
  margin: 10px 0 12px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #fff;
  overflow: hidden;
}

.details-panel summary {
  cursor: pointer;
  font-weight: 600;
  color: #334155;
  list-style: none;
  padding: 10px 12px;
  background: #f3f4f6;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  gap: 8px;
}

.details-panel summary::-webkit-details-marker {
  display: none;
}

.details-panel summary::before {
  content: "▶";
  font-size: 12px;
  color: #6b7280;
}

.details-panel[open] summary::before {
  content: "▼";
}

.details-panel > *:not(summary) {
  padding: 12px;
}

.cite-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  margin: 6px 0 10px;
}

.tone-pill-link {
  text-decoration: none;
}

.tone-pill-link:hover {
  filter: brightness(0.98);
  text-decoration: none;
}

.unit-card .card-head strong {
  font-size: 20px;
  line-height: 1.1;
  letter-spacing: -0.02em;
}

.unit-lead {
  margin: 10px 0 12px;
  font-size: 14px;
  line-height: 1.6;
  font-weight: 400;
  color: #202938;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
}

.section-divider {
  border: 0;
  border-top: 1px solid #e2e2e7;
  margin: 14px 0;
}

.final-result {
  margin: 8px 0 0;
}

.action-group {
  margin: 0;
  padding: 0;
  border: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-top: 15px;
}

.action-group legend {
  width: 100%;
  margin-bottom: 2px;
  font-size: 14px;
  color: #374151;
}

.action-pill {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line-strong);
  background: #f8fafc;
  border-radius: 999px;
  color: #4b5563;
  cursor: pointer;
}

.action-pill input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.action-pill span {
  display: inline-block;
  padding: 5px 10px;
  font-weight: 600;
}

.action-pill-info {
  border-color: #9ec5e8;
  color: #2f7ebd;
}

.action-pill-success {
  border-color: #9cd8b7;
  color: #2f855a;
}

.action-pill-warning {
  border-color: #e7c38b;
  color: #b07a20;
}

.action-pill input:checked + span {
  background: #e8f2fb;
  border-radius: 999px;
}

.action-pill-info input:checked + span {
  background: #e4f3ff;
}

.action-pill-success input:checked + span {
  background: #e9f7ef;
}

.action-pill-warning input:checked + span {
  background: #fff4e4;
}

.tone-pill {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.tone-pill-success {
  background: #eaf7f0;
  border-color: #a7ddc0;
  color: #2f855a;
}

.tone-pill-info {
  background: #f3f8ff;
  border-color: #d7e7ff;
  color: #3a6ea5;
}

.tone-pill-warning {
  background: #fff4e6;
  border-color: #f1c28a;
  color: #9a3412;
}

.tone-pill-neutral {
  background: #f3f4f6;
  border-color: #e5e7eb;
  color: #6b7280;
}

.tone-pill-accent {
  background: #f2eeff;
  border-color: #d7ccff;
  color: #6d28d9;
}

.status {
  background: #f3f4f6;
  border: 1px solid #e5e7eb;
  color: #6b7280;
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 12px;
  font-weight: 600;
}

.status.status-draft,
.status.status-unreviewed {
  background: #f3f4f6;
  border-color: #e5e7eb;
  color: #6b7280;
}

.status.status-reviewing,
.status.status-in_review {
  background: #f3f8ff;
  border-color: #d7e7ff;
  color: #3a6ea5;
}

.status.status-processing {
  background: #fff4e6;
  border-color: #f1c28a;
  color: #9a3412;
}

.status.status-ready,
.status.status-reviewed,
.status.status-completed {
  background: #eaf7f0;
  border-color: #a7ddc0;
  color: #2f855a;
}

.status.status-failed {
  background: var(--danger-soft);
  border-color: var(--danger-line);
  color: #991b1b;
}

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

.row > * {
  flex: 1 1 220px;
}

.stats-grid {
  margin-top: 18px;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.stat-item {
  text-align: center;
  padding: 8px 4px;
}

.stat-item strong {
  display: block;
  font-size: 44px;
  line-height: 1;
  color: #111827;
}

.stat-item span {
  display: block;
  margin-top: 6px;
  font-size: 15px;
  color: #374151;
}

.stat-item.success strong {
  color: #48a889;
}

.stat-item.warning strong {
  color: #d3a043;
}

@media (max-width: 860px) {
  .unit-card .card-head strong {
    font-size: 24px;
  }

  .unit-lead {
    font-size: 13px;
  }

  .stats-grid {
    grid-template-columns: 1fr;
  }

  .stat-item strong {
    font-size: 38px;
  }

  .stat-item span {
    font-size: 14px;
  }
}

@media (max-width: 720px) {
  .topbar {
    padding: 10px 12px;
  }

  .brand-text small {
    display: none;
  }

  .topnav a {
    padding: 6px 8px;
  }

  .auth-card h1 {
    font-size: 34px;
  }
}

.checkbox-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin: 10px 0;
}

.checkbox-row input[type="checkbox"] {
  margin-top: 3px;
}

/* AI 评审：底部状态条，不遮挡正文；同步请求阶段无法展示真实百分比进度 */
body.ai-run-status-active {
  padding-bottom: 140px;
}

.ai-run-status-bar {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 900;
  padding: 12px 16px 14px;
  box-sizing: border-box;
  background: var(--surface);
  border-top: 1px solid var(--line-strong);
  box-shadow: 0 -10px 28px rgba(15, 23, 42, 0.08);
}

.ai-run-status-bar.is-open {
  display: block;
}

.ai-run-status-inner {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  max-width: 920px;
  margin: 0 auto;
}

.ai-run-status-copy {
  flex: 1;
  min-width: 0;
}

.ai-run-status-title {
  display: block;
  font-size: 14px;
  font-weight: 650;
  margin: 0 0 4px;
}

.ai-run-status-sub {
  margin: 0 0 6px;
  font-size: 13px;
  line-height: 1.5;
}

.ai-run-status-hint {
  margin: 0;
  font-size: 12px;
  line-height: 1.45;
}

.ai-run-spinner {
  border: 3px solid var(--line);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: ai-spin 0.85s linear infinite;
}

.ai-run-spinner-inline {
  width: 22px;
  height: 22px;
  margin-top: 2px;
  flex-shrink: 0;
  border-width: 2px;
}

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