:root {
  --bg: #f6f8fa;
  --surface: #ffffff;
  --surface-2: #f0f3f6;
  --border: #d8dee4;
  --text: #1f2328;
  --muted: #656d76;
  --accent: #0969da;
  --accent-soft: #ddf4ff;
  --ok: #1a7f37;
  --ok-soft: #dafbe1;
  --warn: #9a6700;
  --warn-soft: #fff8c5;
  --danger: #cf222e;
  --danger-soft: #ffebe9;
  --radius: 10px;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

[data-theme="dark"] {
  --bg: #0d1117;
  --surface: #161b22;
  --surface-2: #21262d;
  --border: #30363d;
  --text: #e6edf3;
  --muted: #8b949e;
  --accent: #58a6ff;
  --accent-soft: rgba(56, 139, 253, 0.16);
  --ok: #3fb950;
  --ok-soft: rgba(46, 160, 67, 0.16);
  --warn: #d29922;
  --warn-soft: rgba(187, 128, 9, 0.16);
  --danger: #f85149;
  --danger-soft: rgba(248, 81, 73, 0.16);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  font-size: 14px;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code {
  font-family: var(--font-mono);
  font-size: 0.9em;
  background: var(--surface-2);
  padding: 2px 5px;
  border-radius: 5px;
}
.mono { font-family: var(--font-mono); }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.center { text-align: center; }
.mt { margin-top: 18px; }
.mt-sm { margin-top: 10px; }
.ml { margin-left: 10px; }
.nowrap { white-space: nowrap; }
.inline-form { display: inline-flex; align-items: center; gap: 8px; }
.inline-form.wrap { flex-wrap: wrap; }
.text-ok { color: var(--ok); }
.text-warn { color: var(--warn); }

/* Topbar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: 1380px;
  margin: 0 auto;
  padding: 0 20px;
  height: 56px;
  display: flex;
  align-items: center;
  gap: 20px;
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  font-weight: 700;
  font-size: 15.5px;
  color: var(--text);
}
.brand:hover { text-decoration: none; }
.brand-dot {
  width: 11px; height: 11px; border-radius: 50%;
  background: linear-gradient(135deg, #2563eb, #06b6d4);
  display: inline-block;
}
.brand-dot.lg { width: 16px; height: 16px; }
.nav-links { display: flex; gap: 4px; }
.nav-links a {
  padding: 6px 12px;
  border-radius: 7px;
  color: var(--muted);
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.nav-links a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav-links a.active { background: var(--accent-soft); color: var(--accent); }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.rev-pill {
  font-family: var(--font-mono);
  font-size: 12px;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
}

.page-wrap { max-width: 1380px; margin: 0 auto; padding: 20px; }
.page-head h1 { margin: 0 0 6px; font-size: 22px; }
.page-head p { margin: 0; }

/* Buttons & inputs */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 7px 14px; border-radius: 8px; border: 1px solid transparent;
  font-size: 13.5px; font-weight: 500; cursor: pointer; text-decoration: none;
  background: var(--surface-2); color: var(--text);
}
.btn:hover { text-decoration: none; filter: brightness(0.96); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-secondary { background: var(--surface); border-color: var(--border); color: var(--text); }
.btn-ghost { background: transparent; color: var(--muted); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-warn { background: var(--warn-soft); color: var(--warn); border-color: var(--warn); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger-ghost { background: transparent; color: var(--danger); border: 1px solid transparent; }
.btn-danger-ghost:hover { background: var(--danger-soft); }
.btn-sm { padding: 4px 10px; font-size: 12.5px; }
.btn-block { width: 100%; }

input[type="text"], input[type="password"], input[type="search"], input[type="number"], select, textarea {
  font-family: inherit; font-size: 13.5px;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 7px 10px;
}
.input-sm { padding: 5px 9px; font-size: 12.5px; }
.input-xs { width: 64px; padding: 5px 8px; }
.select-sm { padding: 5px 8px; font-size: 12.5px; }
.select-md { min-width: 280px; }

/* Badges & pills */
.badge, .pill, .ver-badge, .chip, .mini-tag {
  display: inline-flex; align-items: center; border-radius: 999px; font-size: 11.5px; font-weight: 500;
}
.badge { padding: 1px 6px; }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.pill { padding: 2px 8px; background: var(--surface-2); color: var(--muted); }
.pill-ok { background: var(--ok-soft); color: var(--ok); }
.pill-warn { background: var(--warn-soft); color: var(--warn); }
.pill-danger { background: var(--danger-soft); color: var(--danger); }
.pill-accent, .pill-info { background: var(--accent-soft); color: var(--accent); }
.ver-badge {
  font-family: var(--font-mono);
  padding: 2px 8px;
  background: var(--accent-soft);
  color: var(--accent);
}
.ver-badge.lg { font-size: 13px; padding: 3px 10px; }
.mini-tag { font-size: 10.5px; padding: 1px 5px; background: var(--accent-soft); color: var(--accent); }
.chip { padding: 3px 9px; background: var(--surface-2); color: var(--text); border-radius: 6px; font-size: 12px; }

/* Alerts */
.alert { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; border: 1px solid; }
.alert-ok { background: var(--ok-soft); color: var(--ok); border-color: var(--ok); }
.alert-error { background: var(--danger-soft); color: var(--danger); border-color: var(--danger); }

/* Login */
.login-body { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-card {
  width: 100%; max-width: 390px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; padding: 28px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.06);
}
.login-head { text-align: center; margin-bottom: 20px; }
.login-head h1 { margin: 8px 0 4px; font-size: 20px; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field > span { font-size: 12.5px; font-weight: 500; color: var(--muted); }

/* Catalog layout */
.catalog-layout { display: grid; grid-template-columns: 240px minmax(0, 1fr); gap: 20px; align-items: start; }
.sidebar {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px; position: sticky; top: 72px; max-height: calc(100vh - 92px); overflow-y: auto;
}
.sidebar-section + .sidebar-section { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--border); }
.sidebar-title { font-size: 11.5px; font-weight: 600; text-transform: uppercase; color: var(--muted); padding: 4px 8px 6px; }
.cat-item {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 6px 9px; border-radius: 7px; color: var(--text); font-size: 13px;
}
.cat-item:hover { background: var(--surface-2); text-decoration: none; }
.cat-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.cat-item .count { font-family: var(--font-mono); font-size: 11.5px; color: var(--muted); }

.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.search-form { flex: 1; min-width: 260px; display: flex; gap: 8px; }
.search-form input { flex: 1; }
.toolbar-actions { display: flex; gap: 8px; }
.segmented {
  display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: var(--surface);
}
.segmented a { padding: 5px 10px; font-size: 12.5px; color: var(--muted); }
.segmented a:hover { text-decoration: none; color: var(--text); }
.segmented a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

.banner {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px 16px; margin-bottom: 14px; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px;
}
.result-meta { margin-bottom: 12px; }

.cards-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }
.skill-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 15px; display: flex; flex-direction: column; gap: 8px; color: var(--text);
  transition: border-color 0.15s, transform 0.15s;
}
.skill-card:hover { border-color: var(--accent); transform: translateY(-1px); text-decoration: none; }
.card-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.card-id { font-weight: 600; font-size: 15px; color: var(--text); font-family: var(--font-mono); }
.card-summary { margin: 0; font-size: 13.5px; color: var(--text); }
.card-desc {
  margin: 0; font-size: 12.5px; color: var(--muted);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.card-tags { display: flex; flex-wrap: wrap; gap: 5px; margin-top: auto; padding-top: 4px; }
.card-foot { display: flex; justify-content: space-between; border-top: 1px solid var(--border); padding-top: 8px; margin-top: 4px; }

/* Tables & panels */
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; }
.section-title { margin: 0 0 12px; font-size: 16px; }
.subsection-title { margin: 14px 0 8px; font-size: 14px; }
.table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; }
.data-table th, .data-table td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
.data-table th { font-size: 12px; color: var(--muted); font-weight: 600; background: var(--surface-2); }
.skill-link { font-family: var(--font-mono); font-weight: 600; }
.row-yanked { opacity: 0.6; text-decoration: line-through; }
.row-selected { background: var(--accent-soft); }
.empty-state { text-align: center; padding: 36px 20px; color: var(--muted); }

/* Detail */
.breadcrumb { font-size: 12.5px; color: var(--muted); margin-bottom: 12px; }
.detail-header {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px; display: flex; flex-wrap: wrap; gap: 16px; justify-content: space-between; align-items: flex-start;
}
.title-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.title-row h1 { margin: 0; font-size: 22px; font-family: var(--font-mono); }
.detail-summary { margin: 8px 0 10px; font-size: 14.5px; }
.meta-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.detail-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.callout-bar {
  margin-top: 12px; background: var(--warn-soft); border: 1px solid var(--warn);
  border-radius: var(--radius); padding: 10px 14px; font-size: 13px; display: flex; flex-direction: column; gap: 4px;
}

.tabs { display: flex; gap: 4px; margin: 16px 0 12px; border-bottom: 1px solid var(--border); }
.tab { padding: 8px 14px; color: var(--muted); border-bottom: 2px solid transparent; font-weight: 500; }
.tab:hover { color: var(--text); text-decoration: none; }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

.fm-box { background: var(--surface-2); border-radius: 8px; padding: 12px 14px; margin-bottom: 16px; }
.fm-title { font-size: 11.5px; font-weight: 600; color: var(--muted); text-transform: uppercase; margin-bottom: 6px; }
.fm-grid { display: grid; grid-template-columns: 140px minmax(0, 1fr); gap: 4px 12px; margin: 0; font-size: 13px; }
.fm-grid dt { font-family: var(--font-mono); color: var(--muted); }
.fm-grid dd { margin: 0; word-break: break-word; }

.markdown-body { line-height: 1.7; }
.markdown-body.pad { padding: 18px; }
.markdown-body pre { background: var(--surface-2); padding: 12px; border-radius: 8px; overflow-x: auto; }
.markdown-body pre code { background: none; padding: 0; }
.markdown-body table { border-collapse: collapse; width: 100%; margin: 12px 0; }
.markdown-body th, .markdown-body td { border: 1px solid var(--border); padding: 6px 10px; text-align: left; }
.markdown-body blockquote { margin: 10px 0; padding: 4px 12px; border-left: 3px solid var(--border); color: var(--muted); }

/* File viewer */
.files-layout { display: grid; grid-template-columns: 280px minmax(0, 1fr); gap: 14px; align-items: start; }
.file-tree-pane, .file-viewer-pane {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden;
}
.pane-head, .viewer-bar {
  padding: 10px 14px; background: var(--surface-2); border-bottom: 1px solid var(--border);
  font-weight: 600; font-size: 13px; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px;
}
.viewer-path { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; font-family: var(--font-mono); }
.viewer-actions { display: flex; gap: 6px; }
.tree-list { list-style: none; margin: 0; padding: 4px 0 4px 12px; }
.file-tree-pane > .tree-list { padding: 8px; }
.tree-dir summary { cursor: pointer; padding: 4px 6px; font-family: var(--font-mono); font-size: 12.5px; list-style: none; }
.tree-file a {
  display: flex; justify-content: space-between; gap: 8px;
  padding: 4px 8px; border-radius: 6px; color: var(--text); font-family: var(--font-mono); font-size: 12.5px;
}
.tree-file a:hover { background: var(--surface-2); text-decoration: none; }
.tree-file.active a { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.tree-size { color: var(--muted); font-size: 11px; flex-shrink: 0; }
.redacted-box { padding: 36px 20px; text-align: center; }

.code-wrap { overflow-x: auto; font-size: 12.5px; }
.codehilite table { width: 100%; border-collapse: collapse; }
.codehilite .linenos { width: 44px; text-align: right; padding: 10px 8px; color: var(--muted); border-right: 1px solid var(--border); user-select: none; vertical-align: top; }
.codehilite .code { padding: 10px 14px; vertical-align: top; }
.codehilite pre { margin: 0; font-family: var(--font-mono); line-height: 1.5; }
.codehilite .k, .codehilite .kd, .codehilite .kn { color: #cf222e; font-weight: 600; }
.codehilite .s, .codehilite .s1, .codehilite .s2 { color: #0a3069; }
.codehilite .c, .codehilite .c1 { color: #6e7781; font-style: italic; }
.codehilite .nf, .codehilite .nc { color: #8250df; }
[data-theme="dark"] .codehilite .k, [data-theme="dark"] .codehilite .kd, [data-theme="dark"] .codehilite .kn { color: #ff7b72; }
[data-theme="dark"] .codehilite .s, [data-theme="dark"] .codehilite .s1, [data-theme="dark"] .codehilite .s2 { color: #a5d6ff; }
[data-theme="dark"] .codehilite .c, [data-theme="dark"] .codehilite .c1 { color: #8b949e; }
[data-theme="dark"] .codehilite .nf, [data-theme="dark"] .codehilite .nc { color: #d2a8ff; }

/* Diff */
.diff-form { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 12px; }
.diff-summary { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.diff-file-card { border: 1px solid var(--border); border-radius: 8px; margin-bottom: 10px; overflow: hidden; }
.diff-file-head { padding: 6px 10px; font-family: var(--font-mono); font-size: 12.5px; font-weight: 600; background: var(--surface-2); }
.diff-file-head.add { color: var(--ok); }
.diff-file-head.del { color: var(--danger); }
.diff-file-head.mod { color: var(--warn); }
.diff-body { font-family: var(--font-mono); font-size: 12px; overflow-x: auto; max-height: 460px; overflow-y: auto; }
.diff-line { padding: 1px 10px; white-space: pre; }
.diff-add { background: var(--ok-soft); }
.diff-del { background: var(--danger-soft); }
.diff-hunk { background: var(--accent-soft); color: var(--accent); }
.diff-hdr { color: var(--muted); font-weight: 600; }

/* Form grid */
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.span-2 { grid-column: span 2; }
.sep { border: none; border-top: 1px solid var(--border); margin: 20px 0; }

/* Get started */
.hero-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; margin-top: 16px; }
.hero-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  padding: 20px; display: flex; flex-direction: column; gap: 10px;
}
.hero-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.hero-top h2 { margin: 0; font-family: var(--font-mono); font-size: 18px; }
.hero-foot { display: flex; gap: 8px; margin-top: auto; }
.generated-box { background: var(--surface-2); border: 1px solid var(--accent); border-radius: 10px; padding: 14px; }
.cmd-block { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 10px; background: var(--surface); padding: 8px 10px; border-radius: 8px; border: 1px solid var(--border); }
.cmd-label { font-size: 11.5px; font-weight: 600; color: var(--muted); width: 100%; }
.cmd-block code { flex: 1; background: none; padding: 0; word-break: break-all; }

/* Backups */
.status-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 14px; margin-top: 14px; }
.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.stat-label { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.stat-val { font-size: 16px; font-weight: 600; word-break: break-all; }
.action-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.monitor-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 10px; }
.progress-track { height: 8px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.progress-fill { height: 100%; background: var(--accent); transition: width 0.2s; }
.step-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; }
.step-item { display: flex; align-items: center; gap: 8px; padding: 6px 10px; border-radius: 7px; background: var(--surface-2); }
.step-running { border: 1px solid var(--accent); }
.step-failed { background: var(--danger-soft); }
.step-label { font-weight: 500; }
.log-box { border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.log-head { padding: 6px 10px; background: var(--surface-2); border-bottom: 1px solid var(--border); }
#job-log { margin: 0; padding: 10px 12px; max-height: 300px; overflow-y: auto; font-family: var(--font-mono); font-size: 12px; background: var(--bg); }
.compact-list { margin: 0; padding-left: 18px; }

/* Toast */
.toast {
  position: fixed; bottom: 20px; right: 20px; background: var(--text); color: var(--bg);
  padding: 9px 15px; border-radius: 8px; font-size: 13px; opacity: 0; pointer-events: none;
  transition: opacity 0.2s;
}
.toast.show { opacity: 1; }

@media (max-width: 860px) {
  .catalog-layout, .files-layout, .form-grid { grid-template-columns: 1fr; }
  .span-2 { grid-column: span 1; }
  .sidebar { position: static; max-height: none; }
}
