/* LQ.AI Repository Explorer — styles
   Dependency-free. Light/dark via [data-theme] on <html>. */

:root {
  --bg: #ffffff;
  --bg-soft: #f6f7f9;
  --bg-sidebar: #fbfbfc;
  --panel: #ffffff;
  --border: #e4e7eb;
  --border-strong: #d3d8de;
  --text: #1d2530;
  --text-soft: #5b6573;
  --text-faint: #8a93a0;
  --accent: #2f5bd9;
  --accent-soft: #e8eefc;
  --accent-text: #1f3fa0;
  --code-bg: #f4f5f7;
  --code-border: #e4e7eb;
  --mark: #fff3c4;
  --shadow: 0 6px 24px rgba(20, 30, 50, 0.10);
  --green: #1a7f4b;
  --amber: #b9770a;
  --red: #c0392b;
  --radius: 9px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

html[data-theme="dark"] {
  --bg: #11151b;
  --bg-soft: #161b22;
  --bg-sidebar: #0e1217;
  --panel: #161b22;
  --border: #262d36;
  --border-strong: #333c47;
  --text: #d7dee7;
  --text-soft: #9aa6b2;
  --text-faint: #6b7682;
  --accent: #5b86ee;
  --accent-soft: #1b2740;
  --accent-text: #9fb8f5;
  --code-bg: #0d1117;
  --code-border: #262d36;
  --mark: #5a4a00;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.45);
  --green: #4ec98a;
  --amber: #e0a948;
  --red: #ef7a6e;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--sans);
  color: var(--text);
  background: var(--bg);
  font-size: 15px;
  line-height: 1.6;
}

button { font-family: inherit; cursor: pointer; }

.layout {
  display: grid;
  grid-template-columns: 312px 1fr;
  height: 100vh;
  overflow: hidden;
}

/* ---------- Sidebar ---------- */
.sidebar {
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.sidebar-head { padding: 16px 16px 10px; }

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  text-decoration: none;
  color: var(--text);
}
.brand-mark {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-weight: 800;
  font-size: 13px;
  letter-spacing: 0.5px;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text strong { font-size: 15px; }
.brand-text small { color: var(--text-faint); font-size: 11.5px; }

.search-wrap {
  position: relative;
  padding: 0 14px 10px;
}
.search-wrap input {
  width: 100%;
  padding: 8px 30px 8px 11px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-size: 13.5px;
}
.search-wrap input:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.search-wrap kbd {
  position: absolute;
  right: 22px;
  top: 8px;
  font-size: 11px;
  color: var(--text-faint);
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  padding: 0 5px;
  background: var(--bg-soft);
}

.tree {
  flex: 1;
  overflow-y: auto;
  padding: 4px 8px 16px;
}

.tree-group > .tree-label { margin-top: 6px; }

.tree-label {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 8px;
  border-radius: 6px;
  color: var(--text-soft);
  font-weight: 600;
  font-size: 13px;
  user-select: none;
}
.tree-label:hover { background: var(--bg-soft); color: var(--text); }
.tree-label .twisty {
  display: inline-block;
  width: 12px;
  font-size: 10px;
  color: var(--text-faint);
  transition: transform 0.12s ease;
}
.tree-node.collapsed > .tree-label .twisty { transform: rotate(-90deg); }
.tree-node.collapsed > .tree-children { display: none; }
.tree-count { margin-left: auto; font-size: 11px; color: var(--text-faint); font-weight: 500; }

.tree-children { margin-left: 10px; border-left: 1px solid var(--border); padding-left: 4px; }

.tree-file {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 4px 8px;
  border-radius: 6px;
  color: var(--text-soft);
  font-size: 13px;
  cursor: pointer;
  text-decoration: none;
}
.tree-file:hover { background: var(--bg-soft); color: var(--text); }
.tree-file.active { background: var(--accent-soft); color: var(--accent-text); font-weight: 600; }
.tree-file .doticon { font-size: 11px; color: var(--text-faint); }
.tree-file .fname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tree-file .cbadge {
  margin-left: auto;
  font-size: 10.5px;
  background: var(--accent);
  color: #fff;
  border-radius: 9px;
  padding: 0 6px;
  font-weight: 600;
}

.sidebar-foot {
  display: flex;
  gap: 6px;
  padding: 8px 14px;
  border-top: 1px solid var(--border);
}
.ghost {
  background: transparent;
  border: 1px solid var(--border-strong);
  color: var(--text-soft);
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 12px;
}
.ghost:hover { background: var(--bg-soft); color: var(--text); }

/* ---------- Main ---------- */
.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }

.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 52px;
  padding: 0 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  flex-shrink: 0;
}
.crumbs {
  flex: 1;
  min-width: 0;
  font-size: 13px;
  color: var(--text-soft);
  font-family: var(--mono);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.crumbs .sep { color: var(--text-faint); margin: 0 5px; }
.crumbs .cur { color: var(--text); }
.topbar-actions { display: flex; align-items: center; gap: 6px; }
.review-count {
  font-size: 12px;
  color: var(--text-faint);
  padding-right: 4px;
  white-space: nowrap;
}
.icon-btn {
  background: transparent;
  border: 1px solid transparent;
  border-radius: 7px;
  width: 34px;
  height: 34px;
  font-size: 16px;
  color: var(--text-soft);
  display: grid;
  place-items: center;
}
.icon-btn:hover { background: var(--bg-soft); color: var(--text); }

.content-row { flex: 1; display: flex; min-height: 0; }

.doc {
  flex: 1;
  overflow-y: auto;
  padding: 38px 56px 120px;
  max-width: 100%;
  scroll-behavior: smooth;
}
.doc:focus { outline: none; }
.doc-inner { max-width: 860px; margin: 0 auto; }

/* ---------- Markdown content ---------- */
.doc h1, .doc h2, .doc h3, .doc h4 { line-height: 1.3; font-weight: 700; scroll-margin-top: 20px; }
.doc h1 { font-size: 30px; margin: 0 0 18px; }
.doc h2 { font-size: 22px; margin: 34px 0 14px; padding-bottom: 7px; border-bottom: 1px solid var(--border); }
.doc h3 { font-size: 18px; margin: 26px 0 10px; }
.doc h4 { font-size: 15.5px; margin: 20px 0 8px; }
.doc p { margin: 0 0 14px; }
.doc a { color: var(--accent); text-decoration: none; }
.doc a:hover { text-decoration: underline; }
.doc ul, .doc ol { margin: 0 0 14px; padding-left: 26px; }
.doc li { margin: 4px 0; }
.doc blockquote {
  margin: 0 0 16px;
  padding: 4px 16px;
  border-left: 3px solid var(--border-strong);
  color: var(--text-soft);
  background: var(--bg-soft);
  border-radius: 0 6px 6px 0;
}
.doc code {
  font-family: var(--mono);
  font-size: 0.875em;
  background: var(--code-bg);
  border: 1px solid var(--code-border);
  border-radius: 4px;
  padding: 1px 5px;
}
.doc pre {
  background: var(--code-bg);
  border: 1px solid var(--code-border);
  border-radius: var(--radius);
  padding: 14px 16px;
  overflow-x: auto;
  margin: 0 0 16px;
}
.doc pre code { background: none; border: none; padding: 0; font-size: 13px; line-height: 1.5; }
.doc table {
  border-collapse: collapse;
  width: 100%;
  margin: 0 0 16px;
  font-size: 13.5px;
  display: block;
  overflow-x: auto;
}
.doc th, .doc td { border: 1px solid var(--border); padding: 7px 11px; text-align: left; }
.doc th { background: var(--bg-soft); font-weight: 600; }
.doc img { max-width: 100%; }
.doc hr { border: none; border-top: 1px solid var(--border); margin: 28px 0; }
.doc .anchor {
  opacity: 0;
  margin-left: 8px;
  font-size: 0.7em;
  color: var(--text-faint);
  text-decoration: none;
}
.doc h1:hover .anchor, .doc h2:hover .anchor, .doc h3:hover .anchor, .doc h4:hover .anchor { opacity: 1; }

/* heading comment affordance */
.cmark {
  cursor: pointer;
  margin-left: 8px;
  font-size: 0.62em;
  vertical-align: middle;
  opacity: 0.35;
  user-select: none;
  white-space: nowrap;
}
.cmark:hover { opacity: 1; }
.cmark.has-comments { opacity: 1; color: var(--accent); font-weight: 600; }

.codeblock-wrap { position: relative; }
.copy-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  font-size: 11px;
  padding: 2px 8px;
  border: 1px solid var(--border-strong);
  border-radius: 5px;
  background: var(--bg);
  color: var(--text-soft);
  opacity: 0;
  transition: opacity 0.12s;
}
.codeblock-wrap:hover .copy-btn { opacity: 1; }

mark { background: var(--mark); color: inherit; padding: 0 2px; border-radius: 2px; }

/* ---------- Home / overview ---------- */
.home { max-width: 1000px; margin: 0 auto; }
.feature-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 24px; }
@media (max-width: 720px) { .feature-row { grid-template-columns: 1fr; } }
.feature-card {
  display: block;
  text-decoration: none;
  color: inherit;
  border: 1px solid var(--accent);
  background: linear-gradient(135deg, var(--accent-soft), var(--panel));
  border-radius: 12px;
  padding: 18px 20px;
  transition: box-shadow 0.12s, transform 0.08s;
}
.feature-card:hover { box-shadow: var(--shadow); transform: translateY(-1px); }
.feature-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  color: var(--green);
  margin-bottom: 6px;
}
.feature-title { font-size: 18px; font-weight: 700; color: var(--accent-text); margin-bottom: 5px; }
.feature-sub { font-size: 13px; color: var(--text-soft); line-height: 1.55; max-width: 760px; }
.home .hero { margin-bottom: 26px; }
.home .hero h1 { font-size: 30px; margin: 0 0 6px; }
.home .hero p { color: var(--text-soft); margin: 0 0 4px; max-width: 720px; }
.home .stat-row { display: flex; gap: 22px; margin: 16px 0 4px; flex-wrap: wrap; }
.home .stat { display: flex; flex-direction: column; }
.home .stat b { font-size: 22px; }
.home .stat span { font-size: 12px; color: var(--text-faint); }
.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-faint); margin: 30px 0 12px; font-weight: 700; }
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 12px; }
.card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  background: var(--panel);
  cursor: pointer;
  transition: border-color 0.12s, transform 0.08s, box-shadow 0.12s;
  text-decoration: none;
  color: inherit;
  display: block;
}
.card:hover { border-color: var(--accent); box-shadow: var(--shadow); transform: translateY(-1px); }
.card .card-title { font-weight: 600; margin-bottom: 4px; display: flex; align-items: center; gap: 8px; }
.card .card-cat { font-size: 11px; color: var(--accent-text); background: var(--accent-soft); border-radius: 5px; padding: 1px 7px; font-weight: 600; }
.card .card-sum { font-size: 12.5px; color: var(--text-soft); line-height: 1.5; }
.cat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; }
.cat-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  background: var(--panel);
  cursor: pointer;
}
.cat-card:hover { border-color: var(--accent); }
.cat-card .cc-name { font-weight: 600; display: flex; justify-content: space-between; }
.cat-card .cc-name span { color: var(--text-faint); font-weight: 500; font-size: 12px; }

/* ---------- Comments panel ---------- */
.comments {
  width: 340px;
  flex-shrink: 0;
  border-left: 1px solid var(--border);
  background: var(--bg-soft);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.comments-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}
.comments-meta { padding: 8px 14px; font-size: 12px; color: var(--text-faint); border-bottom: 1px solid var(--border); }
.comments-list { flex: 1; overflow-y: auto; padding: 10px 12px; display: flex; flex-direction: column; gap: 10px; }
.comment {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
  padding: 10px 12px;
}
.comment.resolved { opacity: 0.6; }
.comment-top { display: flex; align-items: baseline; gap: 8px; margin-bottom: 5px; }
.comment-author { font-weight: 600; font-size: 13px; }
.comment-time { font-size: 11px; color: var(--text-faint); margin-left: auto; }
.comment-anchor {
  font-size: 11px;
  color: var(--accent-text);
  background: var(--accent-soft);
  border-radius: 4px;
  padding: 1px 6px;
  cursor: pointer;
  display: inline-block;
  margin-bottom: 6px;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.comment-blockquote {
  font-size: 12px;
  color: var(--text-soft);
  border-left: 2px solid var(--border-strong);
  padding: 2px 8px;
  margin: 0 0 6px;
  font-style: italic;
}
.comment-body { font-size: 13.5px; white-space: pre-wrap; word-wrap: break-word; }
.comment-actions { display: flex; gap: 10px; margin-top: 8px; }
.comment-actions button {
  background: none;
  border: none;
  color: var(--text-faint);
  font-size: 12px;
  padding: 0;
}
.comment-actions button:hover { color: var(--accent); text-decoration: underline; }
.comment-actions button.danger:hover { color: var(--red); }

.comment-form { padding: 12px; border-top: 1px solid var(--border); }
.comment-quote {
  font-size: 12px;
  color: var(--text-soft);
  border-left: 2px solid var(--accent);
  padding: 3px 8px;
  margin-bottom: 8px;
  background: var(--accent-soft);
  border-radius: 0 5px 5px 0;
  max-height: 70px;
  overflow: auto;
}
.comment-form textarea {
  width: 100%;
  border: 1px solid var(--border-strong);
  border-radius: 7px;
  padding: 8px;
  font-family: inherit;
  font-size: 13.5px;
  resize: vertical;
  background: var(--bg);
  color: var(--text);
}
.comment-form-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }
.primary {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 7px;
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 600;
}
.primary:hover { filter: brightness(1.06); }
.primary.block { margin: 10px 12px 14px; }
.empty-note { color: var(--text-faint); font-size: 13px; text-align: center; padding: 24px 12px; }

/* ---------- Floating selection button ---------- */
.selection-comment {
  position: absolute;
  z-index: 50;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 7px;
  padding: 6px 11px;
  font-size: 12.5px;
  font-weight: 600;
  box-shadow: var(--shadow);
}

/* ---------- Menu / toast ---------- */
.menu {
  position: absolute;
  z-index: 60;
  background: var(--panel);
  border: 1px solid var(--border-strong);
  border-radius: 9px;
  box-shadow: var(--shadow);
  padding: 5px;
  min-width: 220px;
}
.menu button {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  color: var(--text);
  padding: 8px 11px;
  border-radius: 6px;
  font-size: 13px;
}
.menu button:hover { background: var(--bg-soft); }
.menu button.danger { color: var(--red); }

.toast {
  position: fixed;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%);
  background: #1d2530;
  color: #fff;
  padding: 9px 18px;
  border-radius: 8px;
  font-size: 13px;
  box-shadow: var(--shadow);
  z-index: 100;
}
html[data-theme="dark"] .toast { background: #2a3340; }

.banner {
  margin: 0 0 22px;
  padding: 12px 16px;
  border: 1px solid var(--amber);
  background: color-mix(in srgb, var(--amber) 12%, transparent);
  border-radius: 9px;
  font-size: 13.5px;
}
.banner code { background: var(--code-bg); padding: 1px 6px; border-radius: 4px; font-family: var(--mono); }

.loading { color: var(--text-faint); padding: 40px 0; text-align: center; }

.only-mobile { display: none; }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  .comments { width: 300px; }
  .doc { padding: 30px 32px 100px; }
}
@media (max-width: 820px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    z-index: 80;
    top: 0; bottom: 0; left: 0;
    width: 290px;
    transform: translateX(-100%);
    transition: transform 0.18s ease;
    box-shadow: var(--shadow);
  }
  .sidebar.open { transform: translateX(0); }
  .only-mobile { display: grid; }
  .comments { position: fixed; right: 0; top: 0; bottom: 0; z-index: 70; box-shadow: var(--shadow); }
  .doc { padding: 24px 20px 100px; }
}

/* ---------- Mermaid diagrams (rendered from ```mermaid fences) ---------- */
.mermaid-fig {
  margin: 0 0 18px;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--panel);
  text-align: center;
  overflow-x: auto;
}
.mermaid-fig svg { max-width: 100%; height: auto; }
.mermaid-loading { color: var(--text-faint); font-size: 13px; padding: 18px 0; }
.mermaid-error { text-align: left; }
.mermaid-error-msg {
  font-size: 12.5px;
  color: var(--amber);
  margin-bottom: 8px;
  font-weight: 600;
}
