:root {
  --bg: #f5f7fb;
  --panel: #ffffff;
  --text: #172033;
  --muted: #667085;
  --line: #d9e0ea;
  --primary: #2454d6;
  --primary-dark: #173ea8;
  --danger: #d92d20;
  --ok: #16803c;
  --warn: #b54708;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background: var(--bg);
  font-family: Arial, "Microsoft YaHei", sans-serif;
}

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

button, .link-button {
  border: 0;
  border-radius: 6px;
  padding: 9px 14px;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

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

.primary { background: var(--primary); color: #fff; }
.primary:hover { background: var(--primary-dark); }
.secondary { background: #eef2f8; color: #25324a; }
.secondary:hover { background: #e1e7f0; }
.ghost { background: transparent; color: #d8e1f1; border: 1px solid rgba(255,255,255,0.18); }
.text-button {
  padding: 0;
  color: var(--primary);
  background: transparent;
}
.text-button:hover { text-decoration: underline; }
.wide { width: 100%; }
.hidden { display: none !important; }
.muted { color: var(--muted); line-height: 1.6; }
code {
  color: var(--primary-dark);
  background: #eef2f8;
  border-radius: 4px;
  padding: 2px 5px;
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: #172033;
}

.login-panel {
  width: min(420px, 100%);
  background: #fff;
  border-radius: 8px;
  padding: 32px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.24);
}

.brand-mark {
  width: 54px;
  height: 54px;
  border-radius: 8px;
  background: var(--primary);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 700;
  margin-bottom: 18px;
}

.login-panel h1 { margin: 0 0 8px; font-size: 24px; }
.login-panel p { margin: 0 0 22px; color: var(--muted); line-height: 1.6; }

.login-form {
  display: grid;
  gap: 14px;
}

.login-form button {
  margin-top: 4px;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr);
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  background: #172033;
  color: #fff;
  padding: 18px 14px;
  display: flex;
  flex-direction: column;
}

.sidebar-title {
  padding: 8px 8px 18px;
  border-bottom: 1px solid rgba(255,255,255,0.12);
}

.sidebar-title strong { display: block; }
.sidebar-title span { display: block; color: #aab6c7; font-size: 12px; margin-top: 4px; }

.sidebar nav {
  padding: 18px 0;
  display: grid;
  gap: 6px;
}

.nav-link {
  width: 100%;
  justify-content: flex-start;
  color: #d8e1f1;
  background: transparent;
}

.nav-link:hover, .nav-link.active {
  background: rgba(255,255,255,0.12);
  color: #fff;
}

.sidebar-footer {
  margin-top: auto;
  display: grid;
  gap: 12px;
}

.content {
  padding: 28px;
  max-width: 1280px;
  width: 100%;
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 20px;
  margin-bottom: 22px;
}

.page-header h1 { margin: 0; font-size: 26px; }
.page-header p { margin: 6px 0 0; color: var(--muted); }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  margin-bottom: 18px;
}

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

.panel-header h2 { margin: 0; font-size: 18px; }
.panel-header p { margin: 5px 0 0; }

.narrow-panel {
  max-width: 760px;
  margin-left: auto;
  margin-right: auto;
}

.narrow-panel h2,
.panel h2 {
  margin-top: 0;
  font-size: 18px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

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

.stat-card strong { display: block; font-size: 24px; }
.stat-card span { color: var(--muted); font-size: 13px; }

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

.list-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #fff;
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
}

.list-item.clickable { cursor: pointer; }
.list-item.clickable:hover { border-color: #9db2d7; background: #f8fbff; }
.list-item h3 { margin: 0 0 6px; font-size: 16px; }
.list-item p { margin: 0; color: var(--muted); font-size: 13px; }
.compact .list-item { align-items: flex-start; }

.list-actions {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-shrink: 0;
}

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

.danger-text:hover {
  background: #feeceb;
}

.badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 4px 9px;
  font-size: 12px;
  background: #eef2f8;
  color: #25324a;
  white-space: nowrap;
}

.badge.ok { background: #e8f5ee; color: var(--ok); }
.badge.warn { background: #fff3e5; color: var(--warn); }
.badge.bad { background: #feeceb; color: var(--danger); }

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

label, fieldset {
  display: grid;
  gap: 7px;
  margin: 0;
}

label span, legend {
  font-size: 13px;
  color: #344054;
  font-weight: 600;
}

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

textarea { resize: vertical; min-height: 160px; }
fieldset {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  grid-column: 1 / -1;
}

.full { grid-column: 1 / -1; }
.form-actions {
  grid-column: 1 / -1;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
  font-size: 14px;
}

.check-row input { width: auto; }

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

.button-row {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.grid-two {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(340px, 0.9fr);
  gap: 18px;
}

.progress-line {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 12px;
  align-items: center;
  margin-bottom: 12px;
}

.progress-track {
  height: 9px;
  background: #eef2f8;
  border-radius: 999px;
  overflow: hidden;
}

.progress-track > div {
  height: 100%;
  width: 0;
  background: var(--primary);
  transition: width .25s ease;
}

.stepper {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
  list-style: none;
  margin: 0 0 20px;
  padding: 0;
}

.stepper li {
  position: relative;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-size: 13px;
  font-weight: 600;
  padding: 8px;
}

.stepper li.active {
  color: var(--primary-dark);
  border-color: #9db2d7;
  background: #f4f7ff;
}

.stepper li.done {
  color: var(--ok);
  border-color: #b8dec8;
  background: #f0faf4;
}

.wizard-step { animation: fadeIn .18s ease; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

.wizard-actions {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-top: 18px;
}

.select-card-list {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}

.select-card {
  width: 100%;
  min-height: 78px;
  border: 2px solid var(--line);
  background: #fff;
  color: var(--text);
  display: grid;
  justify-items: start;
  align-content: center;
  gap: 5px;
  text-align: left;
  padding: 14px;
}

.select-card strong {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.select-card span {
  color: var(--muted);
  font-size: 13px;
}

.select-card:hover,
.select-card.active {
  border-color: #7c99d8;
  background: #f7faff;
}

.info-panel,
.empty-state {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
  color: var(--muted);
  padding: 14px;
  line-height: 1.6;
}

.info-panel { margin: 16px 0; }

.preview-box {
  max-height: 420px;
  overflow: auto;
  white-space: pre-wrap;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
  padding: 14px;
}

.field-block {
  display: grid;
  gap: 12px;
  margin: 18px 0;
}

.field-label {
  color: #344054;
  font-size: 13px;
  font-weight: 700;
}

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

.segmented button {
  border: 1px solid var(--line);
  background: #fff;
  min-width: 72px;
  font-weight: 600;
}

.segmented button.active {
  color: #fff;
  border-color: var(--primary);
  background: var(--primary);
}

.inline-field {
  max-width: 180px;
}

.template-card-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.template-card {
  min-height: 84px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  display: grid;
  justify-items: start;
  align-content: center;
  text-align: left;
  gap: 6px;
  padding: 14px;
}

.template-card span {
  color: var(--muted);
  font-size: 13px;
}

.template-card.active {
  border: 2px solid var(--primary);
  background: #f4f7ff;
  color: var(--primary-dark);
}

.stage-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.stage {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 56px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 10px;
  color: var(--muted);
}

.stage span {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  display: grid;
  place-items: center;
  background: #eef2f8;
  color: #25324a;
  font-weight: 700;
}

.stage.active {
  color: var(--primary-dark);
  border-color: #9db2d7;
  background: #f7faff;
}

.stage.active span {
  background: var(--primary);
  color: #fff;
}

.stage.done {
  color: var(--ok);
  border-color: #b8dec8;
  background: #f0faf4;
}

.stage.done span {
  background: var(--ok);
  color: #fff;
}

.stage.failed {
  color: var(--danger);
  border-color: #f5b5af;
  background: #fff7f6;
}

.stage.failed span {
  background: var(--danger);
  color: #fff;
}

.log-header {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  margin: 14px 0 8px;
}

.compact-log-header { margin: 0; }

.connection-dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  display: inline-block;
}

.connection-dot.ok { background: var(--ok); }
.connection-dot.bad { background: var(--danger); }

.log-box {
  height: 330px;
  overflow: auto;
  background: #101828;
  color: #d0d5dd;
  border-radius: 6px;
  padding: 12px;
  font-family: Consolas, monospace;
  font-size: 12px;
  line-height: 1.55;
}

.log-line { border-bottom: 1px solid rgba(255,255,255,0.06); padding: 4px 0; }
.article-content {
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 16px;
  max-height: 620px;
  overflow: auto;
}

.markdown-preview {
  color: var(--text);
  line-height: 1.78;
  word-break: break-word;
}

.markdown-preview h1,
.markdown-preview h2,
.markdown-preview h3,
.markdown-preview h4 {
  margin: 22px 0 10px;
  color: #111827;
  line-height: 1.35;
}

.markdown-preview h1 { font-size: 26px; }
.markdown-preview h2 { font-size: 22px; }
.markdown-preview h3 { font-size: 18px; }
.markdown-preview h4 { font-size: 16px; }
.markdown-preview p { margin: 0 0 14px; }
.markdown-preview ul { margin: 0 0 14px 22px; padding: 0; }
.markdown-preview ol { margin: 0 0 14px 22px; padding: 0; }
.markdown-preview li { margin: 5px 0; }
.markdown-preview blockquote {
  margin: 0 0 14px;
  padding: 8px 14px;
  border-left: 4px solid #b7c4dd;
  background: #f5f7fb;
  color: #344054;
}
.markdown-preview pre {
  margin: 0 0 14px;
  padding: 12px;
  border-radius: 6px;
  background: #101828;
  color: #e4e7ec;
  overflow: auto;
}
.markdown-preview pre code {
  padding: 0;
  color: inherit;
  background: transparent;
}
.markdown-preview table {
  width: 100%;
  border-collapse: collapse;
  margin: 0 0 14px;
  font-size: 14px;
}
.markdown-preview th,
.markdown-preview td {
  border: 1px solid var(--line);
  padding: 8px 10px;
  text-align: left;
  vertical-align: top;
}
.markdown-preview th {
  background: #eef2f8;
  font-weight: 700;
}

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

.review-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  overflow: hidden;
  cursor: pointer;
}

.review-card:hover { border-color: #9db2d7; }

.review-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px;
}

.review-card h3 {
  margin: 0 0 7px;
  font-size: 16px;
}

.review-card p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.review-card-body {
  border-top: 1px solid var(--line);
  padding: 18px;
  max-height: 520px;
  overflow: auto;
  background: #fbfcff;
}

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

.breadcrumb {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 13px;
}

.meta-list {
  display: grid;
  gap: 12px;
  margin: 0;
}

.meta-list div {
  display: grid;
  gap: 3px;
}

.meta-list dt {
  color: var(--muted);
  font-size: 12px;
}

.meta-list dd {
  margin: 0;
  font-weight: 600;
}

.tabs {
  display: inline-flex;
  gap: 4px;
  padding: 4px;
  border-radius: 8px;
  background: #e9eef6;
  margin-bottom: 16px;
}

.tabs button {
  background: transparent;
  color: var(--muted);
  font-weight: 600;
}

.tabs button.active {
  background: #fff;
  color: var(--primary-dark);
  box-shadow: 0 1px 3px rgba(16, 24, 40, 0.08);
}

.alert {
  color: var(--danger);
  background: #feeceb;
  border: 1px solid #f5b5af;
  padding: 10px 12px;
  border-radius: 6px;
  margin-bottom: 14px;
}

body.modal-open {
  overflow: hidden;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(23, 32, 51, 0.48);
}

.modal-panel {
  width: min(620px, 100%);
  max-height: calc(100vh - 48px);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 24px 70px rgba(16, 24, 40, 0.28);
}

.modal-wide {
  width: min(860px, 100%);
}

.modal-small {
  width: min(440px, 100%);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px;
  border-bottom: 1px solid var(--line);
}

.modal-header h2 {
  margin: 0;
  font-size: 18px;
}

.modal-close {
  width: 36px;
  height: 36px;
  flex: 0 0 auto;
  padding: 0;
  background: #eef2f8;
  color: #25324a;
  font-size: 22px;
  line-height: 1;
}

.modal-close:hover {
  background: #e1e7f0;
}

.modal-form {
  padding: 18px;
}

.modal-copy {
  margin: 0;
  padding: 18px;
  color: var(--muted);
  line-height: 1.6;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 0 18px 18px;
}

.primary.danger-action {
  background: var(--danger);
}

.primary.danger-action:hover {
  background: #b42318;
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  padding: 11px 14px;
  border-radius: 6px;
  background: #172033;
  color: #fff;
  box-shadow: 0 10px 30px rgba(0,0,0,0.2);
  z-index: 10;
}

@media (max-width: 900px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    position: static;
    height: auto;
  }
  .sidebar nav { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .content { padding: 18px; }
  .stats-grid, .form-grid, .grid-two, .check-grid,
  .stepper, .template-card-grid, .stage-row, .article-detail-grid {
    grid-template-columns: 1fr;
  }
  .page-header { flex-direction: column; }
  .review-card-head {
    flex-direction: column;
    align-items: stretch;
  }
  .wizard-actions {
    flex-direction: column-reverse;
  }
  .wizard-actions button,
  .form-actions button {
    width: 100%;
  }
  .modal-backdrop {
    padding: 12px;
  }
  .modal-panel {
    max-height: calc(100vh - 24px);
  }
  .modal-actions {
    flex-direction: column-reverse;
  }
  .modal-actions button {
    width: 100%;
  }
}
