
/* ─── Design System ─────────────────────────────────────────── */
:root {
  --bg: #ffffff;
  --bg2: #f8f7f4;
  --bg3: #f0efe9;
  --text: #1a1a18;
  --text2: #5a5956;
  --text3: #8a8884;
  --accent: #2563eb;
  --accent2: #1d4ed8;
  --border: rgba(0,0,0,0.1);
  --shadow: 0 1px 4px rgba(0,0,0,0.08);
  --radius: 10px;
  --nav-h: 60px;
  font-size: 16px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1a1a18; --bg2: #222220; --bg3: #2a2a28;
    --text: #e8e6e0; --text2: #a0a09a; --text3: #6a6a64;
    --accent: #60a5fa; --accent2: #93c5fd;
    --border: rgba(255,255,255,0.1); --shadow: 0 1px 4px rgba(0,0,0,0.4);
  }
}
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body {
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg); color: var(--text);
  line-height: 1.7; min-height: 100vh;
}
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent2); text-decoration: underline; }

/* ─── Navigation ─────────────────────────────────────────────── */
.navbar {
  position: sticky; top: 0; z-index: 100;
  height: var(--nav-h); background: var(--bg);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(12px);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 clamp(16px, 4vw, 48px); gap: 16px;
}
.nav-brand { font-weight: 700; font-size: 1.1rem; color: var(--text); }
.nav-brand span { color: var(--accent); }
.nav-search {
  flex: 1; max-width: 440px;
  display: flex; align-items: center; gap: 8px;
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: 24px; padding: 6px 16px;
}
.nav-search input {
  flex: 1; border: none; background: transparent;
  color: var(--text); font-size: 0.9rem; outline: none;
}
.nav-search svg { flex-shrink: 0; color: var(--text3); }
.nav-actions { display: flex; align-items: center; gap: 8px; }
.btn-icon {
  width: 36px; height: 36px; border: none; cursor: pointer;
  background: transparent; color: var(--text2); border-radius: 8px;
  display: grid; place-items: center;
  transition: background 0.15s, color 0.15s;
}
.btn-icon:hover { background: var(--bg3); color: var(--text); }

/* ─── Layout ──────────────────────────────────────────────────── */
.site-layout {
  display: grid;
  grid-template-columns: 260px 1fr;
  grid-template-rows: auto 1fr auto;
  min-height: calc(100vh - var(--nav-h));
  max-width: 1280px; margin: 0 auto;
  padding: 0 clamp(8px, 2vw, 24px);
}
@media (max-width: 768px) {
  .site-layout { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .sidebar.open { display: block; position: fixed; inset: var(--nav-h) 0 0 0; z-index: 50; background: var(--bg); overflow-y: auto; padding: 16px; }
}
.sidebar {
  padding: 24px 16px 24px 0;
  border-right: 1px solid var(--border);
  position: sticky; top: var(--nav-h);
  height: calc(100vh - var(--nav-h));
  overflow-y: auto;
}
.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }
.main-content { padding: 32px 24px; min-width: 0; }
.footer {
  grid-column: 1 / -1; padding: 24px;
  border-top: 1px solid var(--border);
  text-align: center; color: var(--text3); font-size: 0.85rem;
}

/* ─── Sidebar Components ─────────────────────────────────────── */
.sidebar-section { margin-bottom: 24px; }
.sidebar-title {
  font-size: 0.75rem; font-weight: 700; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--text3); margin-bottom: 8px;
}
.sidebar-links { list-style: none; display: flex; flex-direction: column; gap: 2px; }
.sidebar-links a {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 10px; border-radius: 6px; font-size: 0.875rem;
  color: var(--text2); transition: background 0.12s, color 0.12s;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sidebar-links a:hover, .sidebar-links a.active {
  background: var(--bg3); color: var(--text); text-decoration: none;
}
.sidebar-links a .ext-badge {
  flex-shrink: 0; font-size: 0.65rem; padding: 1px 5px;
  border-radius: 3px; background: var(--bg3); color: var(--text3);
  font-weight: 600; margin-left: auto;
}

/* ─── Index Cards Grid ───────────────────────────────────────── */
.page-header { margin-bottom: 32px; }
.page-header h1 { font-size: clamp(1.4rem, 3vw, 2rem); font-weight: 800; }
.page-header p { color: var(--text2); margin-top: 6px; }
.stats-bar {
  display: flex; flex-wrap: wrap; gap: 16px; margin: 20px 0;
}
.stat-chip {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 14px; background: var(--bg2);
  border-radius: 20px; font-size: 0.85rem; color: var(--text2);
  border: 1px solid var(--border);
}
.stat-chip strong { color: var(--text); }
.filter-bar {
  display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 24px;
}
.filter-btn {
  padding: 5px 14px; border: 1px solid var(--border);
  border-radius: 20px; background: transparent; cursor: pointer;
  font-size: 0.85rem; color: var(--text2);
  transition: all 0.15s;
}
.filter-btn:hover, .filter-btn.active {
  background: var(--accent); color: #fff; border-color: var(--accent);
}
.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}
.card {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px;
  transition: box-shadow 0.2s, transform 0.2s;
  display: flex; flex-direction: column; gap: 10px;
}
.card:hover {
  box-shadow: var(--shadow), 0 4px 20px rgba(37,99,235,0.08);
  transform: translateY(-2px);
}
.card-type {
  font-size: 0.7rem; font-weight: 700; letter-spacing: 0.06em;
  text-transform: uppercase; padding: 2px 8px; border-radius: 4px;
  align-self: flex-start;
}
.type-pdf   { background: #fee2e2; color: #991b1b; }
.type-docx  { background: #dbeafe; color: #1e40af; }
.type-html  { background: #d1fae5; color: #065f46; }
.type-txt   { background: #fef3c7; color: #92400e; }
.type-md    { background: #ede9fe; color: #5b21b6; }
.type-other { background: var(--bg3); color: var(--text3); }
.card h3 { font-size: 1rem; font-weight: 600; line-height: 1.4; }
.card h3 a { color: var(--text); }
.card h3 a:hover { color: var(--accent); text-decoration: none; }
.card-desc { font-size: 0.875rem; color: var(--text2); flex: 1; }
.card-meta {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 0.78rem; color: var(--text3);
}
.card-path { font-size: 0.75rem; color: var(--text3); word-break: break-all; }

/* ─── Article / Page Content ─────────────────────────────────── */
.article-header { margin-bottom: 36px; padding-bottom: 24px; border-bottom: 1px solid var(--border); }
.article-header h1 { font-size: clamp(1.5rem, 3.5vw, 2.4rem); font-weight: 800; line-height: 1.25; }
.article-meta {
  display: flex; flex-wrap: wrap; gap: 12px; margin-top: 12px;
  font-size: 0.85rem; color: var(--text3);
}
.article-meta span { display: flex; align-items: center; gap: 4px; }
.article-body {
  max-width: 72ch;
}
.article-body h2 { font-size: 1.35rem; margin: 2em 0 0.75em; font-weight: 700; }
.article-body h3 { font-size: 1.1rem; margin: 1.75em 0 0.5em; font-weight: 600; }
.article-body p  { margin-bottom: 1.25em; }
.article-body ul, .article-body ol { padding-left: 1.5em; margin-bottom: 1.25em; }
.article-body li { margin-bottom: 0.4em; }
.article-body blockquote {
  border-left: 3px solid var(--accent); padding: 12px 20px;
  background: var(--bg2); margin: 1.5em 0; border-radius: 0 6px 6px 0;
  color: var(--text2);
}
.article-body code {
  background: var(--bg3); padding: 2px 6px; border-radius: 4px;
  font-size: 0.875em; font-family: "Consolas", monospace;
}
.article-body pre {
  background: var(--bg3); padding: 16px; border-radius: 8px;
  overflow-x: auto; margin: 1.5em 0;
}
.article-body pre code { background: none; padding: 0; }
.article-body table {
  width: 100%; border-collapse: collapse; margin: 1.5em 0; font-size: 0.9rem;
}
.article-body th, .article-body td {
  border: 1px solid var(--border); padding: 8px 12px; text-align: left;
}
.article-body th { background: var(--bg2); font-weight: 600; }

/* ─── Internal Links Box ─────────────────────────────────────── */
.related-links {
  margin: 40px 0; padding: 24px;
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius);
}
.related-links h3 {
  font-size: 0.9rem; font-weight: 700; letter-spacing: 0.06em;
  text-transform: uppercase; color: var(--text3); margin-bottom: 14px;
}
.related-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 8px;
}
.related-item {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px; background: var(--bg);
  border: 1px solid var(--border); border-radius: 6px;
  font-size: 0.85rem; color: var(--text2);
  transition: border-color 0.15s, color 0.15s;
  text-decoration: none;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.related-item:hover {
  border-color: var(--accent); color: var(--accent);
  text-decoration: none;
}

/* ─── Prev/Next Navigation ───────────────────────────────────── */
.page-nav {
  display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: 48px;
}
.page-nav-btn {
  display: flex; flex-direction: column; gap: 4px;
  padding: 16px; background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); text-decoration: none; transition: all 0.15s;
}
.page-nav-btn:hover {
  border-color: var(--accent); text-decoration: none;
  box-shadow: 0 2px 12px rgba(37,99,235,0.1);
}
.page-nav-btn .nav-dir {
  font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--text3); font-weight: 700;
}
.page-nav-btn .nav-title { font-size: 0.95rem; color: var(--text); font-weight: 600; }
.page-nav-btn.next { text-align: right; }

/* ─── Back to Top / Home Button ─────────────────────────────── */
.back-home {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px; background: var(--bg2); border: 1px solid var(--border);
  border-radius: 24px; font-size: 0.875rem; color: var(--text2);
  text-decoration: none; transition: all 0.15s; margin-bottom: 24px;
}
.back-home:hover {
  background: var(--accent); color: #fff; border-color: var(--accent);
  text-decoration: none;
}
.back-top {
  position: fixed; bottom: 24px; right: 24px;
  width: 40px; height: 40px; background: var(--accent); color: #fff;
  border: none; border-radius: 50%; cursor: pointer; font-size: 1.2rem;
  display: grid; place-items: center; box-shadow: 0 2px 8px rgba(0,0,0,0.2);
  opacity: 0; transition: opacity 0.3s; pointer-events: none;
}
.back-top.visible { opacity: 1; pointer-events: auto; }

/* ─── Search Results ─────────────────────────────────────────── */
#search-results {
  position: absolute; top: calc(var(--nav-h) - 2px); left: 50%;
  transform: translateX(-50%); width: min(640px, 90vw);
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 0 0 12px 12px; box-shadow: 0 8px 32px rgba(0,0,0,0.12);
  max-height: 480px; overflow-y: auto; display: none; z-index: 200;
}
#search-results.open { display: block; }
.search-result-item {
  display: block; padding: 12px 20px; border-bottom: 1px solid var(--border);
  color: var(--text); text-decoration: none; transition: background 0.1s;
}
.search-result-item:hover { background: var(--bg2); text-decoration: none; }
.search-result-item:last-child { border-bottom: none; }
.sr-title { font-weight: 600; font-size: 0.95rem; }
.sr-snippet { font-size: 0.82rem; color: var(--text2); margin-top: 3px; }
mark { background: #fef08a; color: #78350f; border-radius: 2px; padding: 0 2px; }

/* ─── Breadcrumb ─────────────────────────────────────────────── */
.breadcrumb {
  display: flex; flex-wrap: wrap; gap: 4px; align-items: center;
  font-size: 0.82rem; color: var(--text3); margin-bottom: 20px;
}
.breadcrumb a { color: var(--text3); }
.breadcrumb a:hover { color: var(--accent); }
.breadcrumb span { color: var(--border); }

/* ─── Progress Bar ───────────────────────────────────────────── */
.read-progress {
  position: fixed; top: var(--nav-h); left: 0;
  height: 3px; background: var(--accent);
  transition: width 0.1s; z-index: 99;
}
