:root {
  --bg: #0f1419;
  --panel: #1a2332;
  --panel2: #243044;
  --border: #2d3a4f;
  --text: #e8edf5;
  --muted: #8b9cb3;
  --accent: #3b82f6;
  --accent2: #06b6d4;
  --success: #22c55e;
  --warn: #f59e0b;
  --danger: #ef4444;
  --radius: 10px;
  --sidebar-width: 220px;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: linear-gradient(135deg, #0f1419 0%, #1a1f2e 100%);
  color: var(--text);
  min-height: 100vh;
}

.app-layout {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  padding: 24px 16px;
  border-right: 1px solid var(--border);
  background: rgba(26, 35, 50, 0.98);
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.sidebar-footer {
  margin-top: auto;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sidebar-user {
  color: var(--muted);
  font-size: 0.85rem;
  padding: 0 4px;
}

.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
}

.login-card h2 {
  margin: 0 0 20px;
  font-size: 1.25rem;
}

.login-error {
  color: var(--danger);
  font-size: 0.9rem;
  margin-top: 8px;
}

.main-area {
  flex: 1;
  min-width: 0;
  overflow-x: auto;
}

.logo { font-size: 1.25rem; font-weight: 700; line-height: 1.4; }
.logo span { color: var(--accent2); }

.nav-tabs {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 28px;
}

.nav-group { display: flex; flex-direction: column; gap: 4px; }

.nav-group-title {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text);
  padding: 10px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.95rem;
  font-weight: 600;
  text-align: left;
  width: 100%;
  transition: all 0.2s;
  position: relative;
}

.nav-group-title::after {
  content: '▾';
  position: absolute;
  right: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  font-size: 0.75rem;
  transition: transform 0.2s;
}

.nav-group:not(.open) .nav-group-title::after {
  transform: translateY(-50%) rotate(-90deg);
}

.nav-group-title:hover {
  background: var(--panel2);
  border-color: var(--border);
}

.nav-sub {
  display: none;
  flex-direction: column;
  gap: 4px;
  padding-left: 10px;
  margin-bottom: 4px;
}

.nav-group.open .nav-sub { display: flex; }

.nav-sub-tab {
  font-size: 0.88rem;
  padding: 8px 12px 8px 16px;
}

.nav-tab {
  background: transparent;
  border: 1px solid transparent;
  color: var(--muted);
  padding: 10px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.95rem;
  text-align: left;
  width: 100%;
  transition: all 0.2s;
}

.nav-tab:hover {
  background: var(--panel2);
  border-color: var(--border);
  color: var(--text);
}

.nav-tab.active {
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  border-color: transparent;
  color: white;
}

.container { max-width: 1200px; margin: 0 auto; padding: 24px; }

@media (max-width: 768px) {
  .app-layout { flex-direction: column; }
  .sidebar {
    width: 100%;
    height: auto;
    position: static;
    padding: 16px;
  }
  .nav-tabs {
    flex-direction: row;
    flex-wrap: wrap;
    margin-top: 16px;
  }
  .nav-tab { width: auto; flex: 1 1 auto; text-align: center; }
}

.page { display: none; }
.page.active { display: block; }

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
}

.card h2, .card h3 { margin-top: 0; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 768px) { .grid-2 { grid-template-columns: 1fr; } }

.form-row { margin-bottom: 12px; }
.form-row label { display: block; margin-bottom: 6px; color: var(--muted); font-size: 0.85rem; }

input, select, textarea {
  width: 100%;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel2);
  color: var(--text);
  font-size: 0.95rem;
}

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

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 16px;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.9rem;
  transition: opacity 0.2s;
}
.btn:hover { opacity: 0.9; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: white; }
.btn-secondary { background: var(--panel2); color: var(--text); border: 1px solid var(--border); }
.btn-success { background: var(--success); color: white; }
.btn-danger { background: var(--danger); color: white; }
.btn-sm { padding: 5px 10px; font-size: 0.8rem; }

.btn-group { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th, td { padding: 10px 12px; border-bottom: 1px solid var(--border); text-align: left; }
th { color: var(--muted); font-weight: 600; }
tr:hover td { background: rgba(59, 130, 246, 0.05); }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.75rem;
  background: var(--panel2);
  color: var(--muted);
}
.badge.success { background: rgba(34,197,94,0.15); color: var(--success); }
.badge.warn { background: rgba(245,158,11,0.15); color: var(--warn); }

.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  padding: 12px 20px;
  border-radius: 8px;
  background: var(--panel);
  border: 1px solid var(--border);
  z-index: 9999;
  animation: slideIn 0.3s ease;
}
.toast.error { border-color: var(--danger); }
.toast.success { border-color: var(--success); }

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

.loading { opacity: 0.6; pointer-events: none; }

/* Article preview */
.article-preview {
  background: white;
  color: #1a1a1a;
  border-radius: var(--radius);
  padding: 32px;
  max-height: 600px;
  overflow-y: auto;
  line-height: 1.8;
}
.article-preview h1 { font-size: 1.8rem; margin-bottom: 16px; }
.article-preview h2 { font-size: 1.3rem; margin-top: 24px; color: #2563eb; }
.article-preview img { max-width: 100%; border-radius: 8px; margin: 16px 0; }

.article-images { display: flex; gap: 12px; flex-wrap: wrap; margin: 16px 0; }
.article-images img { width: 200px; height: 120px; object-fit: cover; border-radius: 8px; }

.validation-box {
  padding: 12px;
  border-radius: 8px;
  background: var(--panel2);
  margin-top: 12px;
  font-size: 0.85rem;
}
.validation-box.pass { border-left: 3px solid var(--success); }
.validation-box.fail { border-left: 3px solid var(--danger); }

/* Fullscreen preview */
.fullscreen-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.85);
  z-index: 1000;
  overflow-y: auto;
  padding: 40px;
}
.fullscreen-overlay.active { display: block; }
.fullscreen-content {
  max-width: 900px;
  margin: 0 auto;
  background: white;
  color: #1a1a1a;
  border-radius: 12px;
  padding: 48px;
  position: relative;
}
.fullscreen-close {
  position: fixed;
  top: 20px;
  right: 20px;
  background: var(--danger);
  color: white;
  border: none;
  padding: 10px 20px;
  border-radius: 8px;
  cursor: pointer;
  z-index: 1001;
}

.knowledge-item {
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 8px;
}
.knowledge-item .meta { font-size: 0.8rem; color: var(--muted); margin-bottom: 6px; }
.knowledge-item .content { font-size: 0.9rem; max-height: 80px; overflow: hidden; }

.empty { text-align: center; padding: 40px; color: var(--muted); }

.copy-toolbar {
  display: flex;
  gap: 8px;
  margin: 12px 0;
  flex-wrap: wrap;
  align-items: center;
}

.publish-site-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
  flex-wrap: wrap;
}

.publish-site-row label {
  color: var(--muted);
  font-size: 0.85rem;
  white-space: nowrap;
}

.publish-site-row select {
  width: auto;
  flex: 0 1 160px;
  max-width: 200px;
  min-width: 140px;
  min-height: 34px;
  padding: 6px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--panel2);
  color: var(--text);
  cursor: pointer;
  appearance: auto;
  -webkit-appearance: menulist;
}

.publish-target-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 12px;
  background: var(--panel2);
}

.publish-target-card h4 {
  margin: 0 0 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.publish-target-card .grid-2 {
  gap: 12px;
}

.knowledge-checklist {
  max-height: 200px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  background: var(--panel2);
}

.knowledge-check-item {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
  cursor: pointer;
}

.knowledge-check-item:last-child { border-bottom: none; }
.knowledge-check-item input { width: auto; margin-top: 3px; flex-shrink: 0; }
.knowledge-check-item .kb-title { color: var(--text); }
.knowledge-check-item .kb-snippet { color: var(--muted); font-size: 0.8rem; margin-top: 2px; }

.label-hint { color: var(--muted); font-size: 0.85rem; font-weight: normal; margin: 4px 0 0; }

.config-help {
  background: var(--panel2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 16px;
  font-size: 0.88rem;
  line-height: 1.6;
}

.config-help p { margin: 8px 0; }
.config-help ul { margin: 8px 0; padding-left: 20px; }
.config-help code {
  background: var(--panel);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 0.85em;
}

.code-block {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 12px;
  overflow-x: auto;
  font-size: 0.8rem;
  line-height: 1.5;
  color: var(--muted);
  margin: 8px 0;
}

.loading-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 10000;
  align-items: center;
  justify-content: center;
}
.loading-overlay.active { display: flex; }
.loading-box {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 28px 36px;
  text-align: center;
  min-width: 200px;
}
.loading-spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--accent2);
  border-radius: 50%;
  margin: 0 auto 14px;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.scenario-templates {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.scenario-chip {
  background: var(--panel2);
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.82rem;
  cursor: pointer;
  transition: all 0.2s;
}

.scenario-chip:hover {
  border-color: var(--accent2);
  color: var(--text);
}

.top5-list li {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 10px;
  border-bottom: 1px solid var(--border);
}
.top5-list .rank {
  width: 28px; height: 28px;
  background: var(--accent);
  color: white;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 0.85rem; flex-shrink: 0;
}
