/* ========================================================================
   Manuscript Workflow — Web UI Styles
   ======================================================================== */

:root {
  --color-bg:       #f8fafc;
  --color-surface:  #ffffff;
  --color-border:   #e2e8f0;
  --color-text:     #1e293b;
  --color-text-dim: #64748b;
  --color-primary:  #3b82f6;
  --color-primary-hover: #2563eb;
  --color-success:  #22c55e;
  --color-danger:   #ef4444;
  --color-warning:  #f59e0b;
  --radius:         8px;
  --shadow-sm:      0 1px 2px rgba(0,0,0,0.05);
  --shadow-md:      0 4px 6px -1px rgba(0,0,0,0.1);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.6;
}

/* ===== Navigation ===== */
.nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 1.5rem;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  box-shadow: var(--shadow-sm);
  position: sticky;
  top: 0;
  z-index: 100;
}
.nav-left {
  display: flex;
  gap: 0.5rem;
}
.nav-right {
  display: flex;
  align-items: center;
}
.nav-btn {
  padding: 0.5rem 1.2rem;
  font-size: 0.85rem;
  font-weight: 600;
  background: none;
  border: 2px solid transparent;
  border-radius: var(--radius);
  cursor: pointer;
  color: var(--color-text-dim);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}
.nav-btn:hover {
  color: var(--color-text);
  background: #f1f5f9;
}
.nav-btn.active {
  color: var(--color-primary);
  border-bottom-color: var(--color-primary);
  background: #eff6ff;
}
.nav-btn-icon {
  margin-right: 0.35rem;
}
.nav-logout {
  display: inline-flex;
  align-items: center;
  padding: 0.45rem 1rem;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--color-danger);
  background: none;
  border: 1px solid var(--color-danger);
  border-radius: var(--radius);
  text-decoration: none;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.nav-logout:hover {
  background: #fef2f2;
  color: #b91c1c;
}

/* ===== Container ===== */
.container {
  max-width: 960px;
  margin: 0 auto;
  padding: 1.5rem;
}

/* ===== Panel ===== */
.panel {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
  box-shadow: var(--shadow-sm);
}
.panel h2 {
  font-size: 1.15rem;
  font-weight: 600;
  margin-bottom: 1rem;
  color: var(--color-text);
  border-bottom: 2px solid var(--color-primary);
  padding-bottom: 0.5rem;
}

.hidden { display: none !important; }

/* ===== Forms ===== */
.form-row {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}
.form-group {
  margin-bottom: 1rem;
  flex: 1;
}
.flex-1 { flex: 1 1 0; }
.flex-2 { flex: 2 1 0; }

label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 0.3rem;
  color: var(--color-text-dim);
}
.req { color: var(--color-danger); }
.hint { font-weight: 400; color: var(--color-text-dim); font-size: 0.78rem; }

/* Liên kết nhỏ cạnh nhãn trường — dẫn sang nơi quản lý */
.label-link {
  margin-left: 0.35rem;
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--color-primary);
  text-decoration: none;
  border-bottom: 1px dashed currentColor;
}
.label-link:hover { border-bottom-style: solid; }

/* Khối thông tin nghiên cứu mở rộng (gấp/mở được) */
.form-details {
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 0.6rem 0.85rem;
  margin-bottom: 0.85rem;
  background: #fafafa;
}
.form-details > summary {
  cursor: pointer;
  font-weight: 600;
  font-size: 0.88rem;
  color: var(--color-text);
  list-style: none;
  display: flex;
  align-items: baseline;
  gap: 0.4rem;
}
.form-details > summary::-webkit-details-marker { display: none; }
.form-details > summary::before {
  content: "▸";
  color: var(--color-text-dim);
  transition: transform 0.15s;
}
.form-details[open] > summary::before { transform: rotate(90deg); }
.form-details > summary:hover { color: var(--color-primary, #2563eb); }
.form-details .form-row:first-of-type { margin-top: 0.7rem; }

input[type="text"],
input[type="number"],
select,
textarea {
  width: 100%;
  padding: 0.55rem 0.75rem;
  font-size: 0.9rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: #fff;
  color: var(--color-text);
  transition: border-color 0.15s;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(59,130,246,0.12);
}
textarea { resize: vertical; }

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.6rem 1.4rem;
  font-size: 0.9rem;
  font-weight: 600;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }

.btn-primary {
  background: var(--color-primary);
  color: #fff;
}
.btn-primary:hover:not(:disabled) {
  background: var(--color-primary-hover);
}

.btn-spinner {
  width: 16px; height: 16px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== Status Header ===== */
.status-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 1.25rem;
}
.status-meta { display: flex; gap: 0.5rem; flex-wrap: wrap; }

.badge {
  display: inline-block;
  padding: 0.25rem 0.6rem;
  font-size: 0.75rem;
  font-weight: 600;
  border-radius: 999px;
}
.badge-id { background: #e0e7ff; color: #3730a3; }
.badge-phase { background: #dbeafe; color: #1d4ed8; }

.progress-overall { display: flex; align-items: center; gap: 0.5rem; }
.progress-bar-bg {
  width: 160px;
  height: 8px;
  background: #e2e8f0;
  border-radius: 999px;
  overflow: hidden;
}
.progress-bar-fill {
  height: 100%;
  background: var(--color-primary);
  border-radius: 999px;
  transition: width 0.5s ease;
}
.progress-label { font-size: 0.8rem; color: var(--color-text-dim); white-space: nowrap; }

/* ===== Agent Grid ===== */
.agents-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 0.75rem;
}

.agent-card {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  transition: border-color 0.2s, box-shadow 0.2s;
  background: #fafbfc;
}
.agent-card.status-running {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 2px rgba(59,130,246,0.15);
}
.agent-card.status-completed {
  border-color: var(--color-success);
  background: #f0fdf4;
}
.agent-card.status-failed {
  border-color: var(--color-danger);
  background: #fef2f2;
}

.agent-icon {
  font-size: 1.4rem;
  width: 2rem;
  text-align: center;
  flex-shrink: 0;
}

.agent-info { flex: 1; min-width: 0; }
.agent-display {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--color-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.agent-name {
  font-size: 0.7rem;
  color: var(--color-text-dim);
  margin-top: 1px;
}
.agent-progress {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-top: 0.3rem;
}
.agent-progress-bg {
  flex: 1;
  height: 4px;
  background: #e2e8f0;
  border-radius: 999px;
  overflow: hidden;
}
.agent-progress-fill {
  height: 100%;
  border-radius: 999px;
  transition: width 0.4s ease, background 0.3s;
}
.agent-status-label {
  font-size: 0.65rem;
  font-weight: 600;
  white-space: nowrap;
  min-width: 56px;
  text-align: right;
}

.agent-badge {
  font-size: 0.7rem;
  font-weight: 700;
  width: 1.6rem;
  height: 1.6rem;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.badge-ok  { background: var(--color-success); color: #fff; }
.badge-fail { background: var(--color-danger);  color: #fff; }

/* Thời gian chạy của từng agent: bắt đầu / kết thúc / tổng */
.agent-timing {
  display: flex;
  flex-wrap: wrap;
  gap: 0.15rem 0.75rem;
  margin-top: 0.3rem;
  font-size: 0.68rem;
  line-height: 1.45;
  color: var(--color-text-dim, #64748b);
}

.agent-timing .timing-item {
  white-space: nowrap;
}

.agent-timing .timing-key {
  color: var(--color-text-dim, #94a3b8);
  opacity: 0.8;
}

.agent-timing .timing-start,
.agent-timing .timing-end,
.agent-timing .timing-total {
  color: var(--color-text, #334155);
  font-variant-numeric: tabular-nums;
  font-weight: 500;
}

/* Tổng thời gian khi đang chạy: nhấn mạnh */
.agent-timing .timing-total.timing-live {
  color: #d97706;
  font-weight: 700;
}

.agent-card.status-completed .agent-timing .timing-total {
  color: var(--color-success, #16a34a);
}

.agent-card.status-failed .agent-timing .timing-total {
  color: var(--color-danger, #dc2626);
}

/* ===== Status message ===== */
.status-message {
  margin-top: 1rem;
  padding: 0.75rem 1rem;
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: var(--radius);
  font-size: 0.9rem;
  color: #1e40af;
}

/* ===== Results summary ===== */
.results-summary { margin-bottom: 1.25rem; }
.summary-grid {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}
.summary-item {
  flex: 1;
  min-width: 100px;
  text-align: center;
  padding: 1rem;
  background: #f8fafc;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
}
.summary-number {
  font-size: 2rem;
  font-weight: 700;
  color: var(--color-primary);
}
.summary-label {
  font-size: 0.8rem;
  color: var(--color-text-dim);
  margin-top: 0.2rem;
}

/* ===== Tabs ===== */
.tabs {
  display: flex;
  gap: 0;
  border-bottom: 2px solid var(--color-border);
  margin-bottom: 1rem;
}
.tab {
  padding: 0.6rem 1rem;
  font-size: 0.85rem;
  font-weight: 600;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  cursor: pointer;
  color: var(--color-text-dim);
  transition: color 0.15s, border-color 0.15s;
}
.tab:hover { color: var(--color-text); }
.tab.active {
  color: var(--color-primary);
  border-bottom-color: var(--color-primary);
}

.tab-content { display: none; }
.tab-content.active { display: block; }

/* ===== Manuscript sections ===== */
.manuscript-section {
  margin-bottom: 1.25rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--color-border);
}
.manuscript-section:last-child { border-bottom: none; }
.manuscript-section h3 {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--color-text);
  margin-bottom: 0.5rem;
}
.manuscript-text {
  font-size: 0.88rem;
  line-height: 1.7;
  color: #334155;
  white-space: pre-wrap;
}
.manuscript-raw {
  font-size: 0.8rem;
  background: #f1f5f9;
  padding: 0.75rem;
  border-radius: var(--radius);
  overflow-x: auto;
}

/* ===== Pre / code blocks ===== */
pre {
  font-size: 0.82rem;
  background: #f8fafc;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 1rem;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.6;
}

/* ===== Review form ===== */
.radio-group {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-top: 0.25rem;
}
.radio-label {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.4rem 0.9rem;
  border: 2px solid var(--color-border);
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 500;
  transition: border-color 0.15s, background 0.15s;
}
.radio-label input { display: none; }
.radio-label.approve:hover,
.radio-label.approve:has(input:checked) {
  border-color: var(--color-success);
  background: #f0fdf4;
}
.radio-label.revise:hover,
.radio-label.revise:has(input:checked) {
  border-color: var(--color-warning);
  background: #fffbeb;
}
.radio-label.reject:hover,
.radio-label.reject:has(input:checked) {
  border-color: var(--color-danger);
  background: #fef2f2;
}

/* ===== Footer ===== */
.footer {
  text-align: center;
  padding: 1.5rem;
  font-size: 0.8rem;
  color: var(--color-text-dim);
}

/* ===== Settings panel ===== */
.settings-status {
  margin-top: 1rem;
  padding: 0.6rem 1rem;
  border-radius: var(--radius);
  font-size: 0.85rem;
  font-weight: 500;
}
.settings-status.ok {
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  color: #166534;
}
.settings-status.err {
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #991b1b;
}
.settings-hint {
  margin-top: 0.75rem;
  font-size: 0.8rem;
  color: var(--color-text-dim);
  line-height: 1.5;
}
.settings-divider {
  border: none;
  border-top: 1px solid var(--color-border);
  margin: 1.5rem 0;
}

/* ===== Khối trong panel Cài đặt ===== */
.settings-block {
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 1.1rem 1.25rem;
  margin-bottom: 1.25rem;
  background: #fff;
}
.settings-block-head h3 {
  margin: 0 0 0.25rem;
  font-size: 1rem;
}
.settings-block-head .settings-hint { margin-top: 0; margin-bottom: 0.9rem; }

/* Nút gấp/mở khối nâng cao — trông như tiêu đề, không như nút */
.settings-block-toggle {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  width: 100%;
  padding: 0;
  background: none;
  border: none;
  cursor: pointer;
  font-family: inherit;
  font-size: 1rem;
  font-weight: 600;
  color: var(--color-text);
  text-align: left;
}
.settings-block-toggle:hover { color: var(--color-primary); }
.settings-block-toggle .toggle-caret {
  display: inline-block;
  color: var(--color-text-dim);
  transition: transform 0.15s;
  font-size: 0.85rem;
}
.settings-block-toggle[aria-expanded="true"] .toggle-caret {
  transform: rotate(90deg);
}
.settings-block-toggle .hint {
  font-weight: 400;
  font-size: 0.78rem;
  color: var(--color-text-dim);
}
.settings-block-body {
  margin-top: 0.9rem;
  padding-top: 0.9rem;
  border-top: 1px solid var(--color-border);
}
.settings-block-body .settings-hint { margin-top: 0; margin-bottom: 1rem; }

/* ===== Hồ sơ hạ tầng LLM ===== */
.profile-table-wrap { overflow-x: auto; margin-bottom: 1rem; }
.profile-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.86rem;
}
.profile-table th {
  text-align: left;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--color-text-dim);
  padding: 0.5rem 0.7rem;
  border-bottom: 2px solid var(--color-border);
  white-space: nowrap;
}
.profile-action-icon {
  width: 2.15rem;
  height: 2.15rem;
  min-width: 2.15rem;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.95rem;
  line-height: 1;
}
.profile-table td {
  padding: 0.6rem 0.7rem;
  border-bottom: 1px solid var(--color-border);
  vertical-align: middle;
}
.profile-table tr:last-child td { border-bottom: none; }
.profile-row-error td { background: #fef2f2; }
.profile-empty {
  text-align: center;
  color: var(--color-text-dim);
  padding: 1rem !important;
}
.profile-empty.is-error { color: var(--color-danger); }
.profile-nokey { color: var(--color-warning); font-weight: 600; }
.profile-used { color: var(--color-primary); cursor: help; }
.profile-error-text {
  display: inline-block;
  max-width: 18ch;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--color-danger);
  font-size: 0.78rem;
  vertical-align: middle;
  margin-right: 0.4rem;
}
.profile-actions {
  display: flex;
  gap: 0.35rem;
  align-items: center;
  justify-content: flex-end;
  white-space: nowrap;
}
.profile-editor {
  margin-top: 1.25rem;
  padding: 1rem;
  background: #f8fafc;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
}
.profile-editor h4 {
  font-size: 0.95rem;
  font-weight: 600;
  margin-bottom: 0.75rem;
  color: var(--color-text);
}
.profile-editor .form-group { margin-bottom: 0.75rem; }
.field-hint {
  display: block;
  margin-top: 0.25rem;
  font-size: 0.75rem;
  color: var(--color-text-dim);
  line-height: 1.4;
}
#profile-name:disabled { background: #f1f5f9; color: var(--color-text-dim); }
input[type="password"] {
  width: 100%;
  padding: 0.55rem 0.75rem;
  font-size: 0.9rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: #fff;
  color: var(--color-text);
  transition: border-color 0.15s;
}
input[type="password"]:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(59,130,246,0.12);
}

/* ===== Login page ===== */
.login-body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  background: linear-gradient(135deg, #1e293b 0%, #334155 50%, #1e293b 100%);
  justify-content: center;
  align-items: center;
}
.login-wrapper {
  width: 100%;
  max-width: 400px;
  padding: 1.5rem;
}
.login-card {
  background: var(--color-surface);
  border-radius: 12px;
  padding: 2rem;
  box-shadow: 0 8px 32px rgba(0,0,0,0.25);
}
.login-header {
  text-align: center;
  margin-bottom: 1.75rem;
}
.login-header h1 {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--color-text);
  letter-spacing: -0.02em;
}
.login-header p {
  font-size: 0.85rem;
  color: var(--color-text-dim);
  margin-top: 0.3rem;
}
.login-form .form-group {
  margin-bottom: 1.1rem;
}
.login-form label {
  font-size: 0.82rem;
}
.login-btn {
  width: 100%;
  padding: 0.65rem;
  font-size: 0.95rem;
  margin-top: 0.25rem;
}
.login-error {
  padding: 0.6rem 0.9rem;
  margin-bottom: 1rem;
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: var(--radius);
  color: #991b1b;
  font-size: 0.85rem;
  text-align: center;
}
.login-hint {
  text-align: center;
  font-size: 0.78rem;
  color: rgba(255,255,255,0.5);
  margin-top: 1rem;
}

/* ===== Download bar ===== */
.download-bar {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 1.25rem;
  padding: 0.75rem;
  background: #f8fafc;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
}
.btn-download {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 1rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--color-primary);
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: var(--radius);
  text-decoration: none;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.btn-download:hover {
  background: #dbeafe;
  border-color: var(--color-primary);
}
.btn-secondary {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 1rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--color-text-dim);
  background: #fff;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.btn-secondary:hover {
  background: #f1f5f9;
  border-color: #94a3b8;
}
.btn-sm {
  padding: 0.3rem 0.7rem;
  font-size: 0.78rem;
}
.btn-danger {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 1rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: #fff;
  background: var(--color-danger);
  border: 1px solid var(--color-danger);
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.15s;
}
.btn-danger:hover:not(:disabled) { background: #dc2626; }

/* ===== Quản lý dự án ===== */
.project-current {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  padding: 0.65rem 0.9rem;
  background: #f1f5f9;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  /* Tách khỏi nút "Tạo dự án" phía trên — sát quá thì hai khối dính vào
     nhau, khó thấy đâu là nút hành động, đâu là thông tin dự án. */
  margin-top: 1rem;
  margin-bottom: 1rem;
  font-size: 0.9rem;
}
.project-current.has-current { background: #eff6ff; border-color: #bfdbfe; }
.project-current-label { color: var(--color-text-dim); font-weight: 600; }
.project-current-name { font-weight: 700; color: var(--color-text); }
.project-current-head { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }

/* Bảng thông tin nghiên cứu của dự án hiện tại */
.project-current-research {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.5rem 1rem;
  margin-top: 0.25rem;
  padding-top: 0.6rem;
  border-top: 1px solid rgba(59, 130, 246, 0.25);
}
.project-current-research > div { display: flex; flex-direction: column; gap: 0.1rem; }
.project-current-research dt {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--color-text-dim);
}
.project-current-research dd {
  font-size: 0.88rem;
  color: var(--color-text);
  word-break: break-word;
}
/* Đề tài và Mô tả là văn bản dài — cho trải rộng hết chiều ngang của lưới
   thay vì bó trong một ô 180px như các trường ngắn (lĩnh vực, từ khóa…) */
.project-current-research .pc-topic-row,
.project-current-research .pc-desc-row {
  grid-column: 1 / -1;
}
.project-current-research .pc-desc-row {
  white-space: pre-line;
}

.project-current-warn {
  width: 100%;
  padding: 0.5rem 0.75rem;
  background: #fffbeb;
  border: 1px solid #fde68a;
  border-radius: var(--radius);
  color: #92400e;
  font-size: 0.85rem;
}

/* Nhắc bổ sung trường khuyến nghị (không chặn chạy) */
.project-current-hint {
  width: 100%;
  padding: 0.5rem 0.75rem;
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: var(--radius);
  color: #1e40af;
  font-size: 0.85rem;
}
.form-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; }

/* ===== Lịch sử chạy ===== */
.run-history {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--color-border);
}
.run-history-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.35rem;
}
.run-history-head h3 { margin: 0; font-size: 0.95rem; font-weight: 600; color: var(--color-text); }
.run-history-hint { font-size: 0.78rem; color: var(--color-text-dim); margin-bottom: 0.75rem; }
.run-list { display: flex; flex-direction: column; gap: 0.4rem; }
.run-pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  margin-top: 0.75rem;
  padding-top: 0.65rem;
  border-top: 1px solid var(--color-border);
  color: var(--color-text-dim);
  font-size: 0.8rem;
}
.run-pagination button:disabled { opacity: 0.45; cursor: not-allowed; }
.run-empty {
  padding: 0.85rem;
  text-align: center;
  color: var(--color-text-dim);
  font-size: 0.86rem;
  background: #f8fafc;
  border: 1px dashed var(--color-border);
  border-radius: var(--radius);
}
.run-empty.is-error { color: var(--color-danger); border-color: var(--color-danger); background: #fef2f2; }

/* Mỗi lần chạy 2 hàng: hàng trên là thông tin, hàng dưới là nút thao tác
   — đồng bộ với cách hiển thị của Danh sách dự án. */
.run-item {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.5rem;
  padding: 0.55rem 0.8rem;
  background: #fff;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
}
.run-info { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; min-width: 0; }
.run-time { font-weight: 600; font-size: 0.88rem; color: var(--color-text); }

/* Số thứ tự đánh cho các mục trong danh sách (dự án / lần chạy) */
.item-index {
  flex: 0 0 auto;
  min-width: 1.55rem;
  height: 1.55rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 0.3rem;
  border-radius: 999px;
  background: var(--color-bg-soft, #f1f5f9);
  border: 1px solid var(--color-border);
  color: var(--color-text-dim);
  font-size: 0.75rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}
.project-item.current .item-index,
.run-item .item-index {
  background: #e0e7ff;
  border-color: #c7d2fe;
  color: #3730a3;
}
.run-meta { font-size: 0.78rem; color: var(--color-text-dim); }
.run-id {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.72rem;
  color: #94a3b8;
}
.run-actions {
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
  align-items: center;
  /* Ngăn cách nhẹ với hàng thông tin phía trên */
  padding-top: 0.5rem;
  border-top: 1px solid var(--color-border);
}

/* Nút mở PDF trên tab mới — kiểu <a> nhưng trông như nút */
.run-actions a.btn {
  text-decoration: none;
  white-space: nowrap;
}

.run-detail {
  margin-top: 0.85rem;
  border: 1px solid var(--color-primary);
  border-radius: var(--radius);
  background: #f8fafc;
  overflow: hidden;
}
.run-detail-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.6rem 0.85rem;
  background: #eff6ff;
  border-bottom: 1px solid #bfdbfe;
}
.run-detail-head strong { font-size: 0.88rem; color: var(--color-text); }
#run-detail-body { padding: 0.85rem; max-height: 28rem; overflow-y: auto; }
.run-section { margin-bottom: 0.85rem; }
.run-section:last-child { margin-bottom: 0; }
.run-section-title {
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--color-text-dim);
  margin-bottom: 0.3rem;
}
.run-section-body {
  background: #fff;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 0.7rem;
  font-size: 0.8rem;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 16rem;
  overflow-y: auto;
}

.project-create { margin-bottom: 0.5rem; }
.project-create .form-group { margin-bottom: 0.5rem; }

.project-list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin: 1rem 0 0.5rem;
}
.project-list-header h3 { margin: 0; font-size: 0.95rem; font-weight: 600; color: var(--color-text); }

.project-list { display: flex; flex-direction: column; gap: 0.5rem; }
.project-pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  margin-top: 0.75rem;
  padding-top: 0.65rem;
  border-top: 1px solid var(--color-border);
  color: var(--color-text-dim);
  font-size: 0.8rem;
}
.project-pagination button:disabled { opacity: 0.45; cursor: not-allowed; }
.project-empty {
  padding: 1rem;
  text-align: center;
  color: var(--color-text-dim);
  font-size: 0.88rem;
  background: #f8fafc;
  border: 1px dashed var(--color-border);
  border-radius: var(--radius);
}
.project-empty.is-error { color: var(--color-danger); border-color: var(--color-danger); background: #fef2f2; }

/* Mỗi dự án 2 hàng: hàng trên là thông tin, hàng dưới là các nút thao tác.
   Xếp dọc để tên dự án dài không bị nút bóp hẹp. */
.project-item {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.55rem;
  padding: 0.7rem 0.9rem;
  background: #fff;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  transition: border-color 0.15s, background 0.15s;
}
.project-item:hover { border-color: #94a3b8; }
.project-item.current { background: #eff6ff; border-color: var(--color-primary); }

.project-info { display: flex; align-items: center; align-content: center; gap: 0.5rem; flex-wrap: wrap; min-width: 0; }

/* Dòng phụ "Thư mục: <slug>" — nằm dưới dòng tên, chiếm trọn chiều ngang. */
.project-meta-row {
  flex-basis: 100%;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  min-width: 0;
}

/* Cụm badge ngôn ngữ / trạng thái đầu ra / hồ sơ LLM — nằm trên CÙNG dòng
   với tên dự án, dồn về LỀ PHẢI; giữ thứ tự cố định, tự xuống dòng khi
   cửa sổ hẹp thay vì tràn ra ngoài. */
.project-badges {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  min-width: 0;
  /* Đẩy cụm badge sang phải trong hàng flex của .project-info */
  margin-left: auto;
}

/* Dòng riêng cho đề tài nghiên cứu — tách khỏi dòng hồ sơ LLM. */
.project-topic-row {
  flex-basis: 100%;
  display: flex;
  align-items: baseline;
  gap: 0.35rem;
  min-width: 0;
}

/* Nhãn "Thư mục:" / "Đề tài:" — chữ thường, không đậm, để nhãn nổi rõ
   hơn phần giá trị mà không tranh sự chú ý với tên dự án. */
.project-label {
  flex: none;
  font-size: 0.78rem;
  color: var(--color-text-dim);
  font-style: normal;
  font-weight: 500;
}

/* Cặp "Thư mục: <slug>" — co giãn được để nhường chỗ cho cụm badge. */
.project-field {
  display: inline-flex;
  align-items: baseline;
  gap: 0.35rem;
  min-width: 0;
  flex: 1 1 100%;
  flex-wrap: wrap;
}
.project-name { font-weight: 600; font-size: 0.92rem; color: var(--color-text); }
/* Đường dẫn ĐẦY ĐỦ của thư mục dự án (dài) — cho phép xuống dòng tại dấu
   "/" và bẻ gãy từ dài, KHÔNG để tràn ra ngoài thẻ dự án. */
.project-slug {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.75rem;
  color: var(--color-text-dim);
  background: #f1f5f9;
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
  min-width: 0;
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
}
.project-badge {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
  background: var(--color-primary);
  color: #fff;
}
.project-badge.badge-output { background: var(--color-success); }
.project-badge.badge-warn { background: var(--color-warning); }
/* Ngôn ngữ bản thảo — nền trung tính, phân biệt với badge trạng thái */
.project-badge.badge-lang {
  background: var(--color-surface-alt, #eef2f7);
  color: var(--color-text, #1f2937);
  border: 1px solid rgba(0, 0, 0, 0.12);
}
/* Đủ thông tin nhưng chưa chạy lần nào — nhạt hơn "Có kết quả" để
   không tranh chấp thị giác với các trạng thái đã có đầu ra. */
.project-badge.badge-idle {
  background: transparent;
  color: var(--color-text-dim, #64748b);
  border: 1px dashed rgba(0, 0, 0, 0.25);
}

/* Nhãn hồ sơ LLM của dự án — viền nhạt để không tranh chấp với badge
   trạng thái, nhưng vẫn nhận ra ngay dự án chạy bằng hồ sơ nào. */
.profile-badge {
  font-size: 0.72rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  padding: 0.12rem 0.45rem;
  border-radius: 999px;
  border: 1px solid var(--color-border);
  background: #f8fafc;
  color: var(--color-text-dim);
  white-space: nowrap;
}
/* Hồ sơ đã bị xóa khỏi Cài đặt — dự án không chạy được, cần nổi bật. */
.profile-badge.profile-badge-missing {
  border-color: #fecaca;
  background: #fef2f2;
  color: #991b1b;
  font-weight: 600;
}
/* Đề tài: hiện TRỌN VẸN.
   Trước đây dùng nowrap + text-overflow:ellipsis nên đề tài dài bị cắt
   cụt ("Lượng hoá rủi ro lan truyền tron...") — người dùng khó phân biệt
   các dự án vì phần phân biệt nhất nằm ở cuối câu. Nay cho phép xuống
   dòng: danh sách có cao hơn chút nhưng đọc được đầy đủ. */
.project-topic {
  font-size: 0.8rem;
  color: var(--color-text-dim);
  font-style: italic;
  min-width: 0;
  overflow-wrap: anywhere;
}
.project-actions {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
  align-items: center;
  /* Ngăn cách nhẹ với hàng thông tin phía trên */
  padding-top: 0.55rem;
  border-top: 1px solid var(--color-border);
}
/* Cặp [Đang dùng][Bắt đầu workflow] của dự án đang chọn — đẩy cả NHÓM
   sang lề phải, tách khỏi nhóm nút phụ (Sửa / Xóa / Chọn) ở bên trái.
   Bọc trong một nhóm để hai phần tử không bao giờ bị tách rời nhau. */
.project-actions .project-run-group {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-left: auto;
  flex-wrap: wrap;
}

.status-message.is-error {
  background: #fef2f2;
  border-color: #fecaca;
  color: #b91c1c;
}

/* ===== Raw view ===== */
.raw-view {
  margin-bottom: 1.25rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  overflow: hidden;
}
.raw-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem 0.75rem;
  background: #f1f5f9;
  border-bottom: 1px solid var(--color-border);
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--color-text-dim);
}
.raw-view pre {
  margin: 0;
  border: none;
  border-radius: 0;
  max-height: 500px;
  overflow-y: auto;
  font-size: 0.78rem;
  background: #fafbfc;
}

/* ===== Nav link (for pages with <a> instead of <button>) ===== */
.nav-btn:not(button) {
  display: inline-flex;
  align-items: center;
  text-decoration: none;
}

/* ===== Tiêu đề trang (h1) — cỡ chữ đồng nhất với .panel h2 ===== */
.page-title {
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--color-text);
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 2px solid var(--color-primary);
}

/* ===== Mô tả ngắn dưới tiêu đề của từng trang/panel ===== */
.page-desc {
  color: var(--color-text-dim);
  font-size: 0.92rem;
  margin: 0.5rem 0 0;
  max-width: 720px;
  line-height: 1.6;
}
/* Vạch ngăn giữa tiêu đề trang và nội dung đầu tiên */
.section-sep {
  border: 0;
  border-top: 1px solid var(--color-border);
  margin: 1.25rem 0;
}

/* ===== Dashboard specific ===== */
.dash-container { max-width: 960px; margin: 0 auto; padding: 1.5rem; }

.wf-selector {
  display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;
  padding-top: 0.5rem;
}
.wf-selector label { font-weight: 600; font-size: 0.9rem; white-space: nowrap; }
.wf-selector select {
  flex: 1; min-width: 200px; padding: 0.5rem 0.75rem; font-size: 0.88rem;
  border: 1px solid var(--color-border); border-radius: var(--radius);
  background: #fff; color: var(--color-text);
}
.wf-selector .wf-info { font-size: 0.82rem; color: var(--color-text-dim); }

.summary-row {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.75rem; margin-bottom: 1.5rem;
}
.summary-card {
  background: var(--color-surface); border: 1px solid var(--color-border);
  border-radius: var(--radius); padding: 1rem 1.25rem; text-align: center;
  box-shadow: var(--shadow-sm); transition: transform 0.15s;
}
.summary-card:hover { transform: translateY(-2px); }
.summary-card .sc-value { font-size: 2rem; font-weight: 700; line-height: 1.2; }
.summary-card .sc-label { font-size: 0.78rem; color: var(--color-text-dim); margin-top: 0.25rem; text-transform: uppercase; letter-spacing: 0.04em; }
.sc-pending .sc-value { color: #94a3b8; }
.sc-running .sc-value { color: #3b82f6; }
.sc-completed .sc-value { color: #22c55e; }
.sc-failed .sc-value { color: #ef4444; }
.sc-retrying .sc-value { color: #f59e0b; }
.sc-total .sc-value { color: var(--color-text); }

.progress-section {
  background: var(--color-surface); border: 1px solid var(--color-border);
  border-radius: var(--radius); padding: 1.25rem 1.5rem; margin-bottom: 1.5rem;
  box-shadow: var(--shadow-sm);
}
.progress-section h3 { font-size: 0.95rem; font-weight: 600; margin-bottom: 0.75rem; }
.progress-outer { background: #e2e8f0; border-radius: 999px; height: 12px; overflow: hidden; }
.progress-inner {
  height: 100%; border-radius: 999px; transition: width 0.5s ease, background 0.3s;
  background: var(--color-primary);
}
.progress-text { display: flex; justify-content: space-between; margin-top: 0.5rem; font-size: 0.82rem; color: var(--color-text-dim); }

.pipeline-section {
  background: var(--color-surface); border: 1px solid var(--color-border);
  border-radius: var(--radius); padding: 1.5rem; margin-bottom: 1.5rem;
  box-shadow: var(--shadow-sm);
}
.pipeline-section h3 { font-size: 1rem; font-weight: 700; margin-bottom: 1rem; }
.pipeline-flow { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; }
.pipe-agent {
  display: flex; align-items: center; gap: 0.4rem;
  padding: 0.45rem 0.85rem; border-radius: 999px; font-size: 0.78rem;
  font-weight: 600; border: 2px solid transparent; transition: all 0.3s;
  white-space: nowrap;
}
.pipe-agent .pipe-icon { font-size: 0.95rem; }
.pipe-agent.pending   { background: #f1f5f9; color: #94a3b8; border-color: #e2e8f0; }
.pipe-agent.running   { background: #eff6ff; color: #3b82f6; border-color: #3b82f6; box-shadow: 0 0 0 3px rgba(59,130,246,0.15); animation: pulse-blue 1.5s infinite; }
.pipe-agent.completed { background: #f0fdf4; color: #16a34a; border-color: #22c55e; }
.pipe-agent.failed    { background: #fef2f2; color: #dc2626; border-color: #ef4444; }
.pipe-agent.retrying  { background: #fffbeb; color: #d97706; border-color: #f59e0b; animation: pulse-yellow 1.5s infinite; }
.pipe-arrow { color: #cbd5e1; font-size: 0.75rem; }
@keyframes pulse-blue { 0%,100%{box-shadow:0 0 0 3px rgba(59,130,246,0.15)} 50%{box-shadow:0 0 0 6px rgba(59,130,246,0.08)} }
@keyframes pulse-yellow { 0%,100%{box-shadow:0 0 0 3px rgba(245,158,11,0.15)} 50%{box-shadow:0 0 0 6px rgba(245,158,11,0.08)} }

.agents-detail {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 0.75rem; margin-bottom: 1.5rem;
}
.agents-detail .agent-card {
  background: var(--color-surface); border: 1px solid var(--color-border);
  border-radius: var(--radius); padding: 1rem 1.25rem;
  box-shadow: var(--shadow-sm); display: flex; gap: 0.75rem; align-items: flex-start;
  transition: border-color 0.3s, box-shadow 0.3s;
}
.agents-detail .agent-card.status-running { border-color: #3b82f6; box-shadow: 0 0 0 2px rgba(59,130,246,0.1); }
.agents-detail .agent-card.status-completed { border-color: #22c55e; }
.agents-detail .agent-card.status-failed { border-color: #ef4444; }
.agents-detail .agent-card.status-retrying { border-color: #f59e0b; }
.ac-icon { font-size: 1.5rem; flex-shrink: 0; width: 2.2rem; text-align: center; }
.ac-body { flex: 1; min-width: 0; }
.ac-name { font-weight: 700; font-size: 0.88rem; margin-bottom: 0.15rem; }
.ac-display { font-size: 0.78rem; color: var(--color-text-dim); margin-bottom: 0.4rem; }
.ac-status-row { display: flex; align-items: center; gap: 0.5rem; }
.ac-status-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.ac-status-dot.pending   { background: #94a3b8; }
.ac-status-dot.running   { background: #3b82f6; animation: dot-pulse 1s infinite; }
.ac-status-dot.completed { background: #22c55e; }
.ac-status-dot.failed    { background: #ef4444; }
.ac-status-dot.retrying  { background: #f59e0b; animation: dot-pulse 1s infinite; }
@keyframes dot-pulse { 0%,100%{opacity:1} 50%{opacity:0.4} }
.ac-status-text { font-size: 0.78rem; font-weight: 600; }
.ac-status-text.pending   { color: #94a3b8; }
.ac-status-text.running   { color: #3b82f6; }
.ac-status-text.completed { color: #16a34a; }
.ac-status-text.failed    { color: #dc2626; }
.ac-status-text.retrying  { color: #d97706; }
.ac-error { font-size: 0.75rem; color: #dc2626; margin-top: 0.3rem; word-break: break-word; }
.ac-retry { font-size: 0.72rem; color: #d97706; margin-top: 0.15rem; }
.ac-timing { font-size: 0.72rem; color: var(--color-text-dim); margin-top: 0.2rem; }

.error-section {
  background: var(--color-surface); border: 1px solid var(--color-border);
  border-radius: var(--radius); padding: 1.25rem 1.5rem; margin-bottom: 1.5rem;
  box-shadow: var(--shadow-sm);
}
.error-section h3 { font-size: 0.95rem; font-weight: 600; margin-bottom: 0.75rem; color: #dc2626; }
.error-section .empty { font-size: 0.88rem; color: #94a3b8; font-style: italic; }
.error-item {
  padding: 0.6rem 0.8rem; background: #fef2f2; border: 1px solid #fecaca;
  border-radius: var(--radius); margin-bottom: 0.5rem; font-size: 0.82rem;
}
.error-item .ei-agent { font-weight: 600; color: #dc2626; }
.error-item .ei-msg { color: #7f1d1d; margin-top: 0.2rem; word-break: break-word; }

.empty-state { text-align: center; padding: 3rem 1rem; color: var(--color-text-dim); }
.empty-state .es-icon { font-size: 3rem; margin-bottom: 0.75rem; }
.empty-state p { font-size: 0.95rem; }

.conn-badge {
  display: inline-flex; align-items: center; gap: 0.35rem;
  padding: 0.3rem 0.7rem; border-radius: 999px; font-size: 0.72rem;
  font-weight: 600; background: #f1f5f9; color: #94a3b8;
}
.conn-badge.connected { background: #f0fdf4; color: #16a34a; }
.conn-badge.disconnected { background: #fef2f2; color: #dc2626; }
.conn-dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

/* ===== Help specific ===== */
.help-container { max-width: 960px; margin: 0 auto; padding: 1.5rem; }
.settings-container { max-width: 960px; margin: 0 auto; padding: 1.5rem; }

/* --- Mục lục Hỗ trợ: lưới thẻ dẫn tới từng trang con --- */
.help-toc {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 0.85rem;
  margin-top: 1.25rem;
}
.help-toc-card {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 1rem 1.1rem;
  border: 1px solid var(--color-border);
  border-radius: 10px;
  background: #fff;
  text-decoration: none;
  color: inherit;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease;
}
.help-toc-card:hover {
  border-color: var(--color-primary);
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.12);
  transform: translateY(-2px);
}
.help-toc-icon { font-size: 1.6rem; line-height: 1.2; flex: none; }
.help-toc-body { display: flex; flex-direction: column; gap: 0.2rem; min-width: 0; }
.help-toc-title { font-size: 0.98rem; font-weight: 600; color: var(--color-text); }
.help-toc-summary { font-size: 0.82rem; color: var(--color-text-dim); line-height: 1.45; }
.help-toc-arrow {
  margin-left: auto;
  align-self: center;
  flex: none;
  color: var(--color-text-dim);
  font-size: 1.1rem;
  transition: color 0.15s ease, transform 0.15s ease;
}
.help-toc-card:hover .help-toc-arrow { color: var(--color-primary); transform: translateX(3px); }

/* --- Điều hướng trong từng trang con: Trang trước / Mục lục / Trang sau --- */
.help-pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-top: 1.25rem;
}
.help-pager-link {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  padding: 0.6rem 0.9rem;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  background: #fff;
  text-decoration: none;
  color: inherit;
  max-width: 42%;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.help-pager-link:hover { border-color: var(--color-primary); box-shadow: 0 2px 8px rgba(37,99,235,0.1); }
.help-pager-next { text-align: right; align-items: flex-end; }
.help-pager-dir { font-size: 0.72rem; color: var(--color-text-dim); }
.help-pager-title { font-size: 0.85rem; font-weight: 600; color: var(--color-text); }
.help-pager-home {
  flex: none;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--color-primary);
  text-decoration: none;
  padding: 0.4rem 0.8rem;
  border-radius: 999px;
  background: #eff6ff;
}
.help-pager-home:hover { background: #dbeafe; }
.help-pager-spacer { flex: none; min-width: 6rem; }

/* ===== Trang Báo cáo đánh giá ===== */
.report-picker { margin-bottom: 1rem; }

.report-context {
  font-size: 0.86rem;
  color: var(--color-text-dim);
  padding: 0.55rem 0.8rem;
  margin-bottom: 1.2rem;
  background: #f8fafc;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
}
.report-context code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.82rem;
}

/* Mỗi báo cáo một khối, có vạch phân cách để dễ đối chiếu khi in */
.report-block {
  margin-bottom: 1.6rem;
  padding-bottom: 1.2rem;
  border-bottom: 1px solid var(--color-border);
}
.report-block:last-of-type { border-bottom: none; }

.report-heading {
  margin: 0 0 0.6rem;
  font-size: 1rem;
  color: var(--color-text);
  /* Tiêu đề VR1/VR2 dài — cho phép xuống dòng thay vì tràn ra khỏi trang.
     overflow-wrap:anywhere xử lý cả từ dài không có khoảng trắng. */
  overflow-wrap: anywhere;
  word-break: break-word;
  min-width: 0;
}

.report-text {
  white-space: pre-wrap;
  word-wrap: break-word;
  font-family: inherit;
  font-size: 0.88rem;
  line-height: 1.65;
  margin: 0;
  padding: 0.9rem 1.1rem;
  background: #fff;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
}

.report-empty {
  font-size: 0.85rem;
  color: var(--color-text-dim);
  font-style: italic;
  margin: 0;
}

.report-actions {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
  margin-top: 1.4rem;
  padding-top: 1.1rem;
  border-top: 1px solid var(--color-border);
}
.report-actions .btn { text-decoration: none; }

/* Nhật ký lỗi trong panel Tiến trình (gộp từ trang Dashboard) */
.error-section { margin-top: 1.5rem; }
.error-section h3 { margin-top: 0; }
#error-list .err-item {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  padding: 0.55rem 0.8rem;
  margin-bottom: 0.45rem;
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: var(--radius);
  font-size: 0.85rem;
  color: #991b1b;
}
#error-list .err-item strong { font-size: 0.86rem; }
#error-list .err-item span { color: #b91c1c; word-break: break-word; }
#error-list .empty { color: var(--color-text-dim); font-size: 0.88rem; }

/* Sơ đồ pipeline 15 agent trong panel Tiến trình */
.pipeline-section { margin-top: 1.25rem; }
.pipeline-section h3 { margin-top: 0; }
.panel h3 { font-size: 1rem; font-weight: 600; color: var(--color-text); margin-top: 1.25rem; margin-bottom: 0.5rem; }
.panel p, .panel li { font-size: 0.92rem; color: #334155; line-height: 1.75; }
.panel ul, .panel ol { padding-left: 1.5rem; margin-top: 0.5rem; }
.panel li { margin-bottom: 0.4rem; }
.panel code { background: #f1f5f9; padding: 0.15rem 0.4rem; border-radius: 4px; font-size: 0.85rem; color: #be185d; }
.agent-table { width: 100%; border-collapse: collapse; margin-top: 0.75rem; font-size: 0.88rem; }
.agent-table th { background: #f1f5f9; padding: 0.6rem 0.75rem; text-align: left; font-weight: 600; color: var(--color-text); border-bottom: 2px solid var(--color-border); }
.agent-table td { padding: 0.55rem 0.75rem; border-bottom: 1px solid var(--color-border); color: #334155; }
.agent-table tr:hover td { background: #f8fafc; }
.step-list { counter-reset: step-counter; list-style: none; padding-left: 0; }
.step-list li { counter-increment: step-counter; padding: 0.75rem 1rem 0.75rem 3.5rem; position: relative; margin-bottom: 0.5rem; background: #f8fafc; border: 1px solid var(--color-border); border-radius: var(--radius); }
.step-list li::before { content: counter(step-counter); position: absolute; left: 0.75rem; top: 0.75rem; width: 1.75rem; height: 1.75rem; background: var(--color-primary); color: #fff; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 0.8rem; font-weight: 700; }
.tip-box { background: #eff6ff; border: 1px solid #bfdbfe; border-radius: var(--radius); padding: 1rem 1.25rem; margin-top: 1rem; font-size: 0.88rem; color: #1e40af; }
.tip-box strong { display: block; margin-bottom: 0.25rem; }
.warn-box { background: #fffbeb; border: 1px solid #fde68a; border-radius: var(--radius); padding: 1rem 1.25rem; margin-top: 1rem; font-size: 0.88rem; color: #92400e; }
.warn-box strong { display: block; margin-bottom: 0.25rem; }
.faq-item { border-bottom: 1px solid var(--color-border); padding: 0.75rem 0; }
.faq-item:last-child { border-bottom: none; }
.faq-q { font-weight: 600; color: var(--color-text); font-size: 0.92rem; }
.faq-a { margin-top: 0.35rem; font-size: 0.88rem; color: #334155; }

/* ===== Sơ đồ kiến trúc phân tầng (trang Hỗ trợ) ===== */
.arch-diagram { margin-top: 1rem; }
.arch-layer {
  background: #f8fafc;
  border: 1px solid var(--color-border);
  border-left: 4px solid var(--color-primary);
  border-radius: var(--radius);
  padding: 0.85rem 1rem;
}
.arch-layer-head {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 0.35rem;
}
.arch-layer-head strong { font-size: 0.95rem; color: var(--color-text); }
.arch-layer-head code {
  font-size: 0.78rem;
  background: #e2e8f0;
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
  color: #475569;
}
.arch-layer p { margin: 0; font-size: 0.86rem; line-height: 1.6; color: #334155; }
.arch-badge {
  display: inline-block;
  font-size: 0.66rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
  background: var(--color-primary);
  color: #fff;
  white-space: nowrap;
}
.arch-arrow {
  text-align: center;
  color: var(--color-text-dim);
  font-size: 1rem;
  line-height: 1.6;
}

/* Sơ đồ quan hệ nhiều — một */
.arch-map {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  flex-wrap: wrap;
  margin-top: 1rem;
  padding: 1rem;
  background: #f8fafc;
  border: 1px dashed var(--color-border);
  border-radius: var(--radius);
}
.arch-map-col { display: flex; flex-direction: column; gap: 0.5rem; }
.arch-map-arrow { color: var(--color-text-dim); font-size: 1.4rem; }
.arch-node {
  padding: 0.5rem 0.85rem;
  background: #fff;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 0.84rem;
  color: var(--color-text);
  text-align: center;
}
.arch-node-target {
  background: #eff6ff;
  border-color: var(--color-primary);
  line-height: 1.5;
}
.arch-node-target small { color: var(--color-text-dim); font-size: 0.75rem; }

/* ===== Responsive ===== */
@media (max-width: 640px) {
  .container, .dash-container, .help-container { padding: 0.75rem; }
  .panel { padding: 1rem; }
  .form-row { flex-direction: column; gap: 0; }
  .agents-grid { grid-template-columns: 1fr; }
  .status-header { flex-direction: column; align-items: flex-start; }
  .tabs { overflow-x: auto; }
  .login-wrapper { padding: 1rem; }
  .login-card { padding: 1.5rem; }
  .nav { flex-direction: column; gap: 0.5rem; }
  .nav-left { justify-content: center; }
  /* Trang con Hỗ trợ: pager xếp dọc cho khỏi chật trên điện thoại */
  .help-pager { flex-direction: column; align-items: stretch; }
  .help-pager-link { max-width: none; }
  .help-pager-next { text-align: left; align-items: flex-start; }
  .help-pager-spacer { display: none; }
}
