:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --panel-2: #fbfcfd;
  --border: #e7e9ee;
  --border-strong: #d7dae1;
  --text: #1c1f23;
  --muted: #6b7280;
  --muted-2: #9aa1ab;
  --accent: #4f46e5;
  --accent-d: #4338ca;
  --accent-soft: #eef0fe;
  --add: #16a34a;
  --add-soft: #e9f7ee;
  --del: #dc2626;
  --del-soft: #fdecec;
  --shadow: 0 1px 2px rgba(16,24,40,.04), 0 4px 16px rgba(16,24,40,.06);
  --radius: 12px;
  --radius-sm: 8px;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--del); }
code { font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace; font-size: .92em; }

/* buttons */
button { font-family: inherit; font-size: 14px; cursor: pointer; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: #fff; color: var(--text);
  padding: 8px 14px; transition: background .12s, border-color .12s, box-shadow .12s; }
button:hover { background: var(--panel-2); }
button:active { transform: translateY(.5px); }
button:disabled { opacity: .5; cursor: not-allowed; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { background: var(--accent-d); border-color: var(--accent-d); }
button.ghost { border-color: transparent; background: transparent; color: var(--muted); padding: 6px 10px; }
button.ghost:hover { background: var(--accent-soft); color: var(--accent); }
button.icon { padding: 7px 9px; }
.btn-sm { padding: 5px 10px; font-size: 13px; }
button.danger { color: var(--del); border-color: #f3c4c4; }
button.danger:hover { background: var(--del-soft); border-color: var(--del); color: var(--del); }

/* inputs */
input[type=text], input[type=password], select {
  width: 100%; padding: 9px 11px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  font-size: 14px; font-family: inherit; background: #fff; color: var(--text); outline: none; }
input:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2.5'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center; padding-right: 30px; cursor: pointer; }
label.field { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin: 0 0 5px; }

/* ---------- login ---------- */
.login-view { display: flex; min-height: 100vh; align-items: center; justify-content: center; padding: 20px; }
.login-card { background: var(--panel); border: 1px solid var(--border); border-radius: 16px;
  padding: 36px 32px; width: 340px; box-shadow: var(--shadow); text-align: center; }
.login-card .logo { width: 44px; height: 44px; border-radius: 12px; background: var(--accent);
  display: inline-flex; align-items: center; justify-content: center; margin-bottom: 14px; }
.login-card h1 { margin: 0 0 2px; font-size: 20px; }
.login-card p { margin: 0 0 20px; color: var(--muted); font-size: 13px; }
.login-card input { margin-bottom: 12px; }
.login-card button { width: 100%; }
.login-card .error { min-height: 1.2em; margin-top: 10px; font-size: 13px; }

/* ---------- shell ---------- */
.topbar { display: flex; align-items: center; gap: 12px; height: 56px; padding: 0 22px;
  background: var(--panel); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; }
.brand .logo { width: 26px; height: 26px; border-radius: 7px; background: var(--accent);
  display: inline-flex; align-items: center; justify-content: center; }
.brand .sub { font-weight: 400; font-size: 12px; color: var(--muted-2); margin-left: 2px; }
.spacer { flex: 1; }

.layout { display: flex; align-items: flex-start; gap: 18px; padding: 18px 22px; max-width: 1500px; margin: 0 auto; }
.sidebar { width: 320px; flex-shrink: 0; position: sticky; top: 74px; display: flex; flex-direction: column; gap: 16px; }
.content { flex: 1; min-width: 0; }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); }
.card .card-h { padding: 14px 16px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 8px; }
.card .card-h h2 { margin: 0; font-size: 14px; font-weight: 650; }
.card .card-b { padding: 14px 16px; }
.count-badge { font-size: 11px; font-weight: 600; color: var(--accent); background: var(--accent-soft);
  border-radius: 20px; padding: 2px 9px; }

/* upload */
.dropzone { border: 1.5px dashed var(--border-strong); border-radius: var(--radius-sm); padding: 18px 12px;
  text-align: center; color: var(--muted); cursor: pointer; transition: .12s; background: var(--panel-2); }
.dropzone:hover, .dropzone.drag { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.dropzone .big { font-size: 13px; color: var(--text); font-weight: 600; }
.dropzone .file-name { color: var(--accent); font-weight: 600; }
.dropzone small { display: block; margin-top: 4px; font-size: 11.5px; }
.upload-b { display: flex; flex-direction: column; gap: 10px; }
.upload-result { font-size: 13px; }
.upload-result .ok { color: var(--add); }
.upload-result .skip { color: var(--muted); }
.upload-result .err { color: var(--del); }

/* skills list */
.search-wrap { margin-bottom: 8px; }
.skill-list { list-style: none; margin: 0; padding: 0; max-height: calc(100vh - 360px); overflow-y: auto; }
.skill-list li { padding: 9px 10px; border-radius: var(--radius-sm); cursor: pointer; transition: background .1s;
  display: flex; flex-direction: column; gap: 2px; }
.skill-list li:hover { background: var(--panel-2); }
.skill-list li.active { background: var(--accent-soft); }
.skill-list li.active .sname { color: var(--accent); }
.skill-list .sname { font-weight: 600; word-break: break-all; }
.skill-list .smeta { font-size: 11.5px; color: var(--muted-2); }
.skill-list .sdesc { font-size: 12px; color: var(--muted); margin-top: 3px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.empty-hint { color: var(--muted-2); font-size: 13px; padding: 6px 2px; }
.skill-desc { margin: -6px 0 16px; color: var(--muted); font-size: 13px; line-height: 1.6;
  max-width: 900px; }
#diff-toggle { display: inline-block; }

/* ---------- detail ---------- */
.empty-state { background: var(--panel); border: 1px dashed var(--border-strong); border-radius: var(--radius);
  padding: 60px 30px; text-align: center; color: var(--muted); }
.empty-state .big { font-size: 15px; color: var(--text); font-weight: 600; margin-bottom: 6px; }

.detail-head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.detail-head h2 { margin: 0; font-size: 20px; word-break: break-all; }

/* compare panel */
.compare-card { margin-bottom: 16px; }
.compare-row { display: flex; align-items: flex-end; gap: 10px; flex-wrap: wrap; }
.compare-row .sel { flex: 1; min-width: 200px; }
.compare-row .swap { margin-bottom: 1px; }
.fmt-toggle { display: inline-flex; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); overflow: hidden; }
.fmt-toggle button { border: none; border-radius: 0; padding: 7px 12px; background: #fff; color: var(--muted); font-size: 13px; }
.fmt-toggle button.on { background: var(--accent); color: #fff; }
#wrap-toggle.on { background: var(--accent); color: #fff; border-color: var(--accent); }

/* diff summary */
.diff-summary { display: flex; align-items: center; flex-wrap: wrap; gap: 8px 14px; margin: 14px 0 10px; }
.diff-summary .stat { font-size: 13px; color: var(--muted); }
.diff-summary .adds { color: var(--add); font-weight: 600; }
.diff-summary .dels { color: var(--del); font-weight: 600; }
.file-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.file-chip { font-size: 12px; border: 1px solid var(--border); border-radius: 20px; padding: 3px 10px; background: var(--panel-2);
  display: inline-flex; align-items: center; gap: 7px; }
.file-chip code { color: var(--text); }
.file-chip .c-add { color: var(--add); font-weight: 600; }
.file-chip .c-del { color: var(--del); font-weight: 600; }
.diff-status { color: var(--muted); font-size: 13px; padding: 8px 0; }

#diff { margin-top: 6px; }
/* diff2html tuning */
.d2h-wrapper { font-size: 12.5px; }
.d2h-file-header { background: var(--panel-2); border-top-left-radius: var(--radius-sm); border-top-right-radius: var(--radius-sm); }
.d2h-file-wrapper { border-color: var(--border); border-radius: var(--radius-sm); margin-bottom: 14px; box-shadow: var(--shadow); }
/* line wrapping — toggled via #diff.wrap (default OFF = horizontal scroll).
   table-layout:fixed constrains columns to the container so long lines wrap
   to the cell width instead of forcing the table wider. */
#diff.wrap .d2h-files-diff,
#diff.wrap .d2h-file-side-diff { overflow-x: hidden; }
#diff.wrap .d2h-diff-table { width: 100%; }
/* Wrap only the text container (not the line wrapper) so the +/- prefix and
   diff2html's inter-element whitespace aren't turned into line breaks.
   overflow-wrap:anywhere lets the auto-layout table shrink to the container
   and break long unbroken tokens (e.g. URLs). */
#diff.wrap .d2h-code-line-ctn {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  display: inline;
}
.d2h-ins { background: var(--add-soft); }
.d2h-del { background: var(--del-soft); }
.d2h-ins .d2h-code-line-prefix, .d2h-del .d2h-code-line-prefix { font-weight: 700; }
.d2h-file-list-wrapper { border-radius: var(--radius-sm); border-color: var(--border); margin-bottom: 14px; }

/* version timeline */
.versions-card .card-b { padding: 6px 8px; }
.vlist { list-style: none; margin: 0; padding: 0; }
.vrow { display: flex; align-items: center; gap: 12px; padding: 11px 10px; border-radius: var(--radius-sm); }
.vrow:hover { background: var(--panel-2); }
.vrow + .vrow { border-top: 1px solid var(--border); }
.vdot { width: 9px; height: 9px; border-radius: 50%; background: var(--border-strong); flex-shrink: 0; }
.vrow.is-newest .vdot { background: var(--accent); }
.vmain { flex: 1; min-width: 0; }
.vmain .vnote { font-weight: 550; word-break: break-word; }
.vmain .vmeta { font-size: 12px; color: var(--muted-2); margin-top: 1px; }
.vtag { font-size: 10px; font-weight: 700; color: #fff; background: var(--accent); border-radius: 5px; padding: 1px 6px; margin-left: 6px; }
.vtag.base { background: var(--muted); }
.vtag.target { background: var(--add); }
.vactions { display: flex; gap: 6px; flex-shrink: 0; }
