:root {
  --bg: #0a0a0f;
  --text: #e4e4e7;
  --text2: #a1a1aa;
  --text3: #71717a;
  --accent: #f97316;
  --accent2: #fb923c;
  --green: #22c55e;
  --red: #ef4444;
  --radius: 12px;
  --radius-sm: 8px;
  --sidebar-w: 260px;
  --card-bg: #1c1c1e;
  --card-border: #3a3a3c;
}
* { margin:0; padding:0; box-sizing:border-box; }
body {
  background: var(--bg); color: var(--text);
  font: 14px/1.6 -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  display: flex; min-height: 100vh; height: 100dvh; overflow: hidden;
}

/* ── Sidebar ── */
.sidebar {
  display: none;
  width: var(--sidebar-w); min-width: var(--sidebar-w);
  border-right: 1px solid rgba(255,255,255,0.08);
  background: #121215;
  flex-direction: column; overflow: hidden;
}
@media (min-width: 769px) { .sidebar { display: flex; } }
.sidebar-header {
  padding: 20px 18px 16px; border-bottom: 1px solid rgba(255,255,255,0.08);
}
.sidebar-header .logo-row { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.sidebar-header .logo { font-size: 26px; }
.sidebar-header h1 { font-size: 15px; font-weight: 600; }
.sidebar-header .desc { font-size: 11px; color: var(--text3); line-height: 1.5; }
.sidebar-nav { flex: 1; overflow-y: auto; padding: 8px 0; }
.sidebar-nav .section-label {
  font-size: 10px; text-transform: uppercase; letter-spacing: 0.8px;
  color: var(--text3); padding: 12px 18px 4px; font-weight: 500;
}
.cat-item {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 18px; cursor: pointer; border: none;
  background: none; color: var(--text2); font-size: 13px;
  width: 100%; text-align: left; font-family: inherit;
}
.cat-item:hover { background: rgba(255,255,255,0.04); color: var(--text); }
.cat-item.active { background: rgba(255,255,255,0.07); color: var(--accent2); border-right: 2px solid var(--accent); }
.cat-item .icon { font-size: 15px; width: 20px; text-align: center; }
.cat-item .count { margin-left: auto; font-size: 11px; color: var(--text3); }
.cat-item .count:empty { display: none; }
.sidebar-footer {
  padding: 12px 18px; border-top: 1px solid rgba(255,255,255,0.08);
  font-size: 11px; color: var(--text3);
  display: flex; align-items: center; gap: 6px;
}
.sidebar-footer .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--green); }

/* ── Main Area ── */
.main {
  flex: 1; display: flex; flex-direction: column; overflow: hidden;
}
.main.hero { justify-content: center; align-items: center; }

/* ── Search Section ── */
.search-section { width: 100%; position: relative; }
.search-section.hero {
  padding: 0 24px;
  max-width: 560px; margin: 0 auto; text-align: center;
}
.search-section.results {
  padding: 20px 24px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  background: linear-gradient(180deg, rgba(249,115,22,0.04) 0%, transparent 100%);
}

/* Hero elements */
.hero-logo { font-size: 56px; margin-bottom: 12px; display: block; }
.hero-title { font-size: 24px; font-weight: 600; margin-bottom: 16px; color: var(--text); }
.hero-sub { font-size: 13px; color: var(--text3); margin-bottom: 20px; }

/* Search bar */
.search-bar { display: flex; gap: 8px; align-items: stretch; }
.menu-trigger {
  display: none; width: 40px; min-width: 40px; height: 48px; flex-shrink: 0;
  background: var(--card-bg); border: 1.5px solid var(--card-border);
  border-radius: 14px; color: var(--text);
  font-size: 16px; cursor: pointer; -webkit-appearance: none;
  align-items: center; justify-content: center;
}
@media (min-width: 769px) { .menu-trigger { display: none; } }
.menu-trigger:active { background: #2c2c2e; }
.search-bar .input-wrap { flex: 1; position: relative; display: flex; align-items: center; }
.search-bar input { width: 100%; padding: 0 44px 0 16px; height: 48px;
  background: var(--card-bg); border: 1.5px solid var(--card-border);
  border-radius: 14px; color: var(--text);
  font-size: 16px; outline: none; -webkit-appearance: none;
  overflow-x: auto; white-space: nowrap;
}
.search-bar input:focus { border-color: var(--accent); }
.search-bar input::placeholder { color: #636366; }
.search-clear {
  position: absolute; right: 12px; top: 50%; transform: translateY(-50%);
  width: 28px; height: 28px; border-radius: 50%;
  background: rgba(255,255,255,0.08); border: none;
  color: var(--text3); font-size: 14px; cursor: pointer;
  display: none; align-items: center; justify-content: center;
  -webkit-appearance: none; font-family: inherit; line-height: 1;
}
.search-clear.show { display: flex; }
.search-clear:active { background: rgba(255,255,255,0.15); color: var(--text); }
.search-mode-btn {
  padding: 0 16px; height: 48px; flex-shrink: 0;
  background: var(--card-bg); border: 1.5px solid var(--card-border);
  border-radius: 14px; color: var(--text);
  font-size: 14px; font-weight: 500; cursor: pointer;
  font-family: inherit; -webkit-appearance: none;
  white-space: nowrap;
  display: flex; align-items: center; gap: 4px;
}
.search-mode-btn .mode-label { display: none; }
.search-mode-btn .mode-icon { font-size: 16px; }
.search-mode-btn .mode-text { display: inline; }
.search-mode-btn:active { background: #2c2c2e; }
.search-mode-btn.active { background: rgba(249,115,22,0.15); border-color: var(--accent); color: var(--accent2); }

/* Search stats */
.search-stats { margin-top: 10px; font-size: 12px; color: var(--text3); }

/* Quick tags */
.quick-tags {
  margin-top: 10px; display: flex; gap: 6px; flex-wrap: wrap; justify-content: center;
}
.quick-tags.results {
  margin-top: 6px; margin-bottom: 0;
  flex-wrap: nowrap; overflow-x: auto; justify-content: flex-start;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 2px;
}
.quick-tags.results::-webkit-scrollbar { display: none; }
.quick-tag {
  padding: 8px 18px; border-radius: 20px;
  border: 1.5px solid var(--card-border);
  background: var(--card-bg); color: var(--text);
  font-size: 13px; cursor: pointer; font-family: inherit;
  font-weight: 400; -webkit-appearance: none;
  white-space: nowrap; line-height: 1;
}
.quick-tag:active { background: #2c2c2e; border-color: var(--accent); color: var(--accent2); }

/* ── Toolbar ── */
.toolbar {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 16px; min-height: 32px;
}
.toolbar .breadcrumb { font-size: 12px; color: var(--text2); display: flex; align-items: center; gap: 4px; }
.toolbar .breadcrumb span { color: var(--text3); }
.toolbar .actions { margin-left: auto; display: flex; gap: 4px; }
.toolbar .back-btn {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 4px 10px; border-radius: 6px;
  background: var(--card-bg); border: 1px solid var(--card-border);
  color: var(--text2); font-size: 12px; cursor: pointer;
  font-family: inherit; -webkit-appearance: none;
}
.toolbar .back-btn:active { background: #2c2c2e; color: var(--text); }
.toolbar .sort-btn {
  background: var(--card-bg); border: 1px solid var(--card-border);
  color: var(--text2); cursor: pointer;
  font-size: 11px; padding: 3px 10px;
  border-radius: 6px; font-family: inherit;
}
.toolbar .sort-btn:hover { background: #2c2c2e; color: var(--text); }
.toolbar .sort-btn.active { background: rgba(249,115,22,0.12); border-color: var(--accent); color: var(--accent2); }

/* ── Content ── */
.content-area { flex: 1; overflow-y: auto; padding: 24px; }

/* ── Document List ── */
.doc-list { display: flex; flex-direction: column; gap: 10px; }
.doc-card {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 16px 18px; cursor: pointer;
  border-radius: var(--radius);
  background: var(--card-bg);
  border: 1px solid rgba(255,255,255,0.06);
}
.doc-card:active { background: #2c2c2e; border-color: rgba(249,115,22,0.2); }
.doc-card .doc-left { display: flex; flex-direction: column; align-items: center; gap: 6px; flex-shrink: 0; min-width: 44px; }
.doc-card .doc-icon { font-size: 20px; opacity: 0.7; }
.doc-card .doc-score {
  font-size: 12px; font-weight: 700; color: #22c55e; text-align: center;
}
.doc-card .doc-info { flex: 1; min-width: 0; }
.doc-card .doc-title { font-size: 14px; font-weight: 500; margin-bottom: 4px; line-height: 1.4; }
.doc-card .doc-meta { display: flex; gap: 8px; font-size: 11px; color: var(--text3); align-items: center; flex-wrap: wrap; }
.doc-card .doc-snippet { font-size: 13px; color: var(--text3); margin-top: 6px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc-card .card-score {
  position: absolute; top: 18px; right: 18px;
  font-size: 12px; font-weight: 600; color: #22c55e;
}
.tag {
  display: inline-block; font-size: 11px;
  padding: 2px 8px; border-radius: 10px;
  background: rgba(255,255,255,0.04); border: 1px solid rgba(255,255,255,0.08);
  color: var(--text3);
}
.score-badge {
  display: inline-block; font-size: 11px; font-weight: 500;
  padding: 2px 8px; border-radius: 8px;
  background: rgba(34,197,94,0.12); color: #22c55e;
  margin-left: 6px; vertical-align: middle;
}

/* ── Document View ── */
.doc-view { max-width: 800px; }
.doc-view h2 { font-size: 22px; font-weight: 600; margin-bottom: 10px; }
.doc-view .view-meta {
  display: flex; gap: 10px; font-size: 12px; color: var(--text3);
  margin-bottom: 24px; align-items: center; flex-wrap: wrap;
}
.markdown-body { line-height: 1.7; }
.markdown-body h1 { font-size: 1.6em; margin: 1em 0 0.5em; font-weight: 600; }
.markdown-body h2 { font-size: 1.3em; margin: 0.8em 0 0.4em; font-weight: 600; }
.markdown-body h3 { font-size: 1.1em; margin: 0.6em 0 0.3em; }
.markdown-body p { margin: 0.5em 0; }
.markdown-body code {
  background: rgba(255,255,255,0.06); border: 1px solid rgba(255,255,255,0.08);
  padding: 2px 6px; border-radius: 4px; font-size: 0.9em;
  font-family: ui-monospace, monospace;
}
.markdown-body pre {
  background: rgba(255,255,255,0.04); border: 1px solid rgba(255,255,255,0.08);
  padding: 14px; border-radius: var(--radius-sm); overflow-x: auto;
}
.markdown-body pre code { background: none; border: none; padding: 0; }
.markdown-body a { color: var(--accent2); }

/* ── Editor (unused but kept for safety) ── */
.editor-wrap { display: flex; flex-direction: column; gap: 16px; height: 100%; }
.editor-pane textarea {
  flex: 1; width: 100%; padding: 16px;
  background: transparent; border: none; color: var(--text);
  font-family: ui-monospace, monospace;
  font-size: 13px; line-height: 1.6; resize: none; outline: none;
}

/* ── Empty State ── */
.empty-state { text-align: center; padding: 80px 20px; color: var(--text3); }
.empty-state .icon { font-size: 48px; margin-bottom: 12px; }
.empty-state h3 { font-size: 16px; color: var(--text2); margin-bottom: 6px; }

/* ── Back to Top ── */
.back-to-top {
  position: fixed; bottom: 24px; right: 24px;
  width: 44px; height: 44px; border-radius: 50%;
  background: var(--card-bg); border: 1.5px solid var(--card-border);
  color: var(--text); font-size: 20px; cursor: pointer;
  display: none; align-items: center; justify-content: center;
  z-index: 50; -webkit-appearance: none;
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}
.back-to-top.show { display: flex; }
.back-to-top:active { background: #2c2c2e; }
/* ── Stats Button ── */
.stats-btn {
  position: fixed;
  top: 16px; right: 16px;
  z-index: 50;
  padding: 6px 14px;
  background: var(--card-bg);
  border: 1.5px solid var(--card-border);
  border-radius: 20px;
  color: var(--text2);
  font-size: 13px; cursor: pointer;
  font-family: inherit;
  -webkit-appearance: none;
  display: flex; align-items: center; gap: 4px;
}
.stats-btn:active { background: #2c2c2e; color: var(--text); }
.stats-btn.active { background: rgba(249,115,22,0.15); border-color: var(--accent); color: var(--accent2); }

/* ── Stats View ── */
.stats-view {
  flex: 1; display: flex; flex-direction: column;
  overflow-y: auto; padding: 24px;
}
.stats-header {
  display: flex; align-items: center; gap: 12px;
  margin-bottom: 24px; flex-wrap: wrap;
}
.stats-header h2 { font-size: 18px; font-weight: 600; }
.stats-back {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 6px 14px; border-radius: 8px;
  background: var(--card-bg); border: 1px solid var(--card-border);
  color: var(--text2); font-size: 13px; cursor: pointer;
  font-family: inherit; -webkit-appearance: none;
}
.stats-back:active { background: #2c2c2e; color: var(--text); }
.stats-total { margin-left: auto; font-size: 13px; color: var(--text3); }
.stats-body {
  flex: 1; display: flex; gap: 32px; align-items: flex-start;
}
.chart-wrapper { flex: 1; min-width: 280px; max-width: 420px; min-height: 300px; }
.chart-wrapper canvas { width: 100% !important; height: 100% !important; }
.stats-legend {
  flex: 1; min-width: 200px; max-width: 360px;
  display: flex; flex-direction: column; gap: 4px;
  max-height: 420px; overflow-y: auto;
}
.legend-item {
  display: flex; align-items: center; gap: 8px;
  padding: 5px 10px; border-radius: 6px; font-size: 13px;
}
.legend-item:hover { background: rgba(255,255,255,0.04); }
.legend-color {
  width: 10px; height: 10px; border-radius: 2px; flex-shrink: 0;
}
.legend-name {
  flex: 1; color: var(--text); min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.legend-count {
  color: var(--text2); font-weight: 500;
  min-width: 48px; text-align: right;
}
.legend-pct {
  color: var(--text3); font-size: 12px;
  min-width: 42px; text-align: right;
}

/* ── Stats Mobile ── */
@media (max-width: 768px) {
  .stats-view { padding: 16px; }
  .stats-body { flex-direction: column; gap: 20px; }
  .chart-wrapper { max-width: 100%; min-width: 0; min-height: 280px; }
  .stats-legend { max-height: none; max-width: 100%; }
  .stats-header h2 { font-size: 16px; }
  .stats-btn { top: 12px; right: 12px; padding: 5px 10px; font-size: 12px; border-radius: 16px; }
}

.toast {
  position: fixed; bottom: 20px; right: 20px;
  padding: 10px 20px; border-radius: var(--radius-sm);
  background: #2c2c2e; border: 1px solid rgba(255,255,255,0.08);
  color: var(--text); font-size: 13px;
  z-index: 1000; animation: fadeIn 0.2s;
}
.toast.success { border-color: var(--green); }
.toast.error { border-color: var(--red); }
@keyframes fadeIn { from { opacity:0; transform:translateY(8px); } to { opacity:1; transform:translateY(0); } }

/* ── Dialog ── */
.overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.6);
  display: flex; align-items: center; justify-content: center; z-index: 900;
}
.dialog {
  background: #18181b; border: 1px solid rgba(255,255,255,0.08);
  border-radius: var(--radius); padding: 24px;
  min-width: 320px; max-width: 420px;
}
.dialog h3 { font-size: 15px; margin-bottom: 8px; }
.dialog p { font-size: 13px; color: var(--text2); margin-bottom: 16px; }
.dialog .btns { display: flex; gap: 8px; justify-content: flex-end; }

/* ── Mobile ── */
@media (max-width: 768px) {
  .sidebar.open {
    display: flex !important; position: fixed; top:0; left:0; bottom:0; z-index: 100;
    width: 280px; box-shadow: 4px 0 20px rgba(0,0,0,0.5);
  }
  .menu-trigger { display: flex !important; }
  .search-mode-btn .mode-text { display: none; }
  .search-mode-btn .mode-icon { display: inline; font-size: 18px; }
  .search-mode-btn { height: 48px !important; padding: 0 12px !important; }
  .mobile-menu-btn {
    display: flex !important;
    background: none; border: none; color: var(--text);
    font-size: 20px; cursor: pointer; padding: 4px;
  }
  .search-section { padding: 16px !important; }
  .search-section.hero { padding: 0 16px !important; max-width: 100%; }
  .search-bar input { height: 48px !important; font-size: 16px; padding: 0 36px 0 12px; }
  .content-area { padding: 16px !important; }
  .hero-logo { font-size: 40px !important; margin-bottom: 8px !important; }
  .hero-title { font-size: 20px !important; margin-bottom: 12px !important; }
  .hero-sub { font-size: 12px !important; margin-bottom: 16px !important; }
  .main.hero { justify-content: flex-start; padding-top: 60px; min-height: 100dvh; }
  .doc-card { padding: 14px 16px; }
}
.mobile-menu-btn { display: none; }
.sidebar-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.85); z-index: 99; }
.sidebar-overlay.show { display: block; }
