/* ── Variables ───────────────────────────────────────────────────────────────── */
:root, [data-theme="dark"] {
  --bg-app:        #0d0d0d;
  --bg-sidebar:    #111111;
  --bg-content:    #0d0d0d;
  --bg-hover:      #1e1e2e;
  --bg-active:     #1a1040;
  --bg-code:       #1a1a2e;
  --bg-table-alt:  #161625;
  --bg-input:      #1e1e2e;
  --text-primary:  #d4d4d8;
  --text-heading:  #f4f4f5;
  --text-muted:    #71717a;
  --text-faint:    #3f3f46;
  --accent:        #7c3aed;
  --accent-light:  #8b5cf6;
  --accent-hover:  #a78bfa;
  --accent-dim:    rgba(124, 58, 237, 0.15);
  --border:        #27272a;
  --border-light:  #3f3f46;
  --link:          #a78bfa;
  --link-hover:    #c4b5fd;
  --shadow:        rgba(0,0,0,0.5);
  --scrollbar:     #27272a;
  --scrollbar-thumb: #52525b;
  --tag-bg:        rgba(124,58,237,0.2);
  --blockquote-bg: rgba(124,58,237,0.07);
}

[data-theme="light"] {
  --bg-app:        #f8f8fc;
  --bg-sidebar:    #f0eff8;
  --bg-content:    #ffffff;
  --bg-hover:      #ede9f7;
  --bg-active:     #e2daf7;
  --bg-code:       #f3f2fb;
  --bg-table-alt:  #faf9fe;
  --bg-input:      #ffffff;
  --text-primary:  #27272a;
  --text-heading:  #18181b;
  --text-muted:    #71717a;
  --text-faint:    #a1a1aa;
  --accent:        #7c3aed;
  --accent-light:  #6d28d9;
  --accent-hover:  #5b21b6;
  --accent-dim:    rgba(124, 58, 237, 0.1);
  --border:        #e4e4e7;
  --border-light:  #d4d4d8;
  --link:          #7c3aed;
  --link-hover:    #5b21b6;
  --shadow:        rgba(0,0,0,0.08);
  --scrollbar:     #e4e4e7;
  --scrollbar-thumb: #a78bfa;
  --tag-bg:        rgba(124,58,237,0.12);
  --blockquote-bg: rgba(124,58,237,0.05);
}

/* ── Reset & Base ────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Inter", sans-serif;
  background: var(--bg-app);
  color: var(--text-primary);
  height: 100%;
  overflow: hidden;
  font-size: 15px;
  line-height: 1.6;
  transition: background 0.2s, color 0.2s;
}

a { color: var(--link); text-decoration: none; }
a:hover { color: var(--link-hover); text-decoration: underline; }

/* ── Layout ─────────────────────────────────────────────────────────────────── */
.app-layout {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ── Sidebar ─────────────────────────────────────────────────────────────────── */
.sidebar {
  width: 280px;
  min-width: 220px;
  max-width: 360px;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow: hidden;
  transition: transform 0.25s ease;
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 16px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.sidebar-header .site-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-heading);
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-header a { color: inherit; text-decoration: none; display: flex; align-items: center; gap: 10px; }

.obsidian-logo { flex-shrink: 0; width: 28px; height: 28px; }

.sidebar-search-wrap {
  padding: 10px 12px;
  flex-shrink: 0;
  border-bottom: 1px solid var(--border);
}

.sidebar-search-wrap input {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 10px 6px 30px;
  font-size: 13px;
  color: var(--text-primary);
  outline: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 16 16' fill='%2371717a'%3E%3Cpath d='M11.742 10.344a6.5 6.5 0 10-1.397 1.398h-.001c.03.04.062.078.098.115l3.85 3.85a1 1 0 001.415-1.414l-3.85-3.85a1.007 1.007 0 00-.115-.099zm-5.242 1.656a5.5 5.5 0 110-11 5.5 5.5 0 010 11z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: 8px center;
  transition: border-color 0.15s;
}

.sidebar-search-wrap input:focus { border-color: var(--accent); }
.sidebar-search-wrap input::placeholder { color: var(--text-muted); }

.sidebar-nav { flex: 1; overflow-y: auto; padding: 8px 0 16px; }

/* ── File Tree ───────────────────────────────────────────────────────────────── */
.tree-root, .tree-root ul { list-style: none; }

.tree-root { padding: 0 6px; }

.tree-folder > ul {
  display: none;
  padding-left: 14px;
  border-left: 1px solid var(--border);
  margin-left: 16px;
}

.tree-folder.open > ul { display: block; }

.folder-label {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  border-radius: 5px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  user-select: none;
  position: relative;
}

.folder-label:hover { background: var(--bg-hover); color: var(--text-heading); }

.folder-label::before {
  content: '';
  display: inline-block;
  width: 0; height: 0;
  border-style: solid;
  border-width: 4px 0 4px 6px;
  border-color: transparent transparent transparent var(--text-muted);
  flex-shrink: 0;
  transition: transform 0.15s;
  margin-right: 2px;
}

.tree-folder.open > .folder-label::before { transform: rotate(90deg); }

.icon-folder { width: 14px; height: 14px; fill: var(--accent-light); flex-shrink: 0; opacity: 0.85; }
.icon-file   { width: 13px; height: 13px; fill: var(--text-muted);    flex-shrink: 0; }

.tree-file > a {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  border-radius: 5px;
  font-size: 13px;
  color: var(--text-primary);
  text-decoration: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tree-file > a:hover { background: var(--bg-hover); color: var(--text-heading); text-decoration: none; }
.tree-file.active > a { background: var(--accent-dim); color: var(--accent-hover); font-weight: 500; }
.tree-file.active > a .icon-file { fill: var(--accent-light); }

/* ── Main Panel ──────────────────────────────────────────────────────────────── */
.main-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg-content);
}

/* ── Top Bar ─────────────────────────────────────────────────────────────────── */
.top-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 20px;
  height: 48px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--bg-sidebar);
}

.breadcrumb {
  flex: 1;
  font-size: 13px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 4px;
  overflow: hidden;
}

.breadcrumb .crumb { color: var(--text-muted); white-space: nowrap; }
.breadcrumb .crumb-sep { color: var(--text-faint); margin: 0 2px; }
.breadcrumb > span:last-child { color: var(--text-primary); font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.top-actions { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }

.icon-btn {
  display: flex; align-items: center; justify-content: center;
  width: 32px; height: 32px;
  background: none; border: none;
  border-radius: 6px;
  color: var(--text-muted);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text-primary); }
.icon-btn svg { width: 16px; height: 16px; }

.icon-sun, .icon-moon { display: none; }

.user-badge {
  font-size: 12px;
  color: var(--text-muted);
  padding: 4px 10px;
  background: var(--accent-dim);
  border-radius: 20px;
  display: flex; align-items: center; gap: 5px;
}

.btn-logout {
  font-size: 12px;
  padding: 4px 10px;
  background: none;
  border: 1px solid var(--border);
  border-radius: 5px;
  color: var(--text-muted);
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
  text-decoration: none;
}
.btn-logout:hover { border-color: var(--accent); color: var(--accent-hover); text-decoration: none; }

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

/* ── Welcome / Empty State ───────────────────────────────────────────────────── */
.welcome-state {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  height: 100%; gap: 16px; color: var(--text-muted);
}
.welcome-state .big-logo { opacity: 0.15; }
.welcome-state h2 { font-size: 22px; color: var(--text-heading); font-weight: 700; opacity: 0.4; }
.welcome-state p { font-size: 14px; opacity: 0.6; }

/* ── Markdown Body ───────────────────────────────────────────────────────────── */
.markdown-body {
  max-width: 780px;
  margin: 0 auto;
  color: var(--text-primary);
}

.markdown-body h1, .markdown-body h2, .markdown-body h3,
.markdown-body h4, .markdown-body h5, .markdown-body h6 {
  color: var(--text-heading);
  font-weight: 700;
  line-height: 1.3;
  margin-top: 1.8em;
  margin-bottom: 0.5em;
  position: relative;
}
.markdown-body h1 { font-size: 2em; margin-top: 0; border-bottom: 1px solid var(--border); padding-bottom: 0.3em; }
.markdown-body h2 { font-size: 1.5em; border-bottom: 1px solid var(--border); padding-bottom: 0.25em; }
.markdown-body h3 { font-size: 1.25em; }
.markdown-body h4 { font-size: 1.1em; }

.heading-anchor {
  opacity: 0;
  margin-left: 8px;
  color: var(--text-faint);
  vertical-align: middle;
  transition: opacity 0.15s;
}
.heading-anchor svg { fill: currentColor; }
.markdown-body h1:hover .heading-anchor,
.markdown-body h2:hover .heading-anchor,
.markdown-body h3:hover .heading-anchor,
.markdown-body h4:hover .heading-anchor { opacity: 1; }

.markdown-body p { margin-bottom: 1em; }

.markdown-body a { color: var(--link); }
.markdown-body a:hover { color: var(--link-hover); }

.markdown-body strong { font-weight: 700; color: var(--text-heading); }
.markdown-body em { font-style: italic; color: var(--text-primary); }

.markdown-body ul, .markdown-body ol { padding-left: 1.5em; margin-bottom: 1em; }
.markdown-body li { margin-bottom: 0.3em; }
.markdown-body li > ul, .markdown-body li > ol { margin-top: 0.3em; margin-bottom: 0; }

/* Task lists */
.markdown-body .task-list-item { list-style: none; margin-left: -1.5em; padding-left: 1.5em; }
.markdown-body .task-list-item input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  width: 14px; height: 14px;
  border: 1.5px solid var(--border-light);
  border-radius: 3px;
  margin-right: 7px;
  vertical-align: middle;
  cursor: pointer;
  background: var(--bg-code);
  position: relative;
  flex-shrink: 0;
}
.markdown-body .task-list-item input[type="checkbox"]:checked {
  background: var(--accent);
  border-color: var(--accent);
}
.markdown-body .task-list-item input[type="checkbox"]:checked::after {
  content: '';
  position: absolute;
  left: 2px; top: -1px;
  width: 6px; height: 9px;
  border: 2px solid #fff;
  border-top: none; border-left: none;
  transform: rotate(45deg);
}

/* Blockquotes */
.markdown-body blockquote {
  margin: 1em 0;
  padding: 12px 16px;
  background: var(--blockquote-bg);
  border-left: 3px solid var(--accent);
  border-radius: 0 6px 6px 0;
  color: var(--text-muted);
}
.markdown-body blockquote > :last-child { margin-bottom: 0; }

/* Code */
.markdown-body code {
  font-family: "JetBrains Mono", "Fira Code", "Cascadia Code", "Consolas", monospace;
  font-size: 0.875em;
  background: var(--bg-code);
  color: #c084fc;
  padding: 2px 5px;
  border-radius: 4px;
  border: 1px solid var(--border);
}

.markdown-body pre {
  background: var(--bg-code);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px 20px;
  overflow-x: auto;
  margin: 1em 0;
  font-size: 0.875em;
  line-height: 1.6;
}

.markdown-body pre code {
  background: none;
  border: none;
  padding: 0;
  color: var(--text-primary);
  font-size: inherit;
}

/* Tables */
.markdown-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 1em 0;
  font-size: 14px;
}
.markdown-body th {
  background: var(--accent-dim);
  color: var(--text-heading);
  font-weight: 600;
  padding: 8px 12px;
  border: 1px solid var(--border);
  text-align: left;
}
.markdown-body td {
  padding: 7px 12px;
  border: 1px solid var(--border);
}
.markdown-body tr:nth-child(even) td { background: var(--bg-table-alt); }
.markdown-body tr:hover td { background: var(--bg-hover); }

/* Horizontal rule */
.markdown-body hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 2em 0;
}

/* Images */
.markdown-body img {
  max-width: 100%;
  border-radius: 6px;
  border: 1px solid var(--border);
}

/* File metadata */
.file-meta {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-top: 40px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-faint);
}

/* ── Login Page ─────────────────────────────────────────────────────────────── */
.login-wrap {
  display: flex; align-items: center; justify-content: center;
  height: 100vh; background: var(--bg-app);
}
.login-card {
  width: 360px;
  background: var(--bg-sidebar);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 40px 36px;
  box-shadow: 0 8px 40px var(--shadow);
}
.login-logo {
  display: flex; align-items: center; justify-content: center;
  gap: 10px; margin-bottom: 28px;
}
.login-logo .site-title { font-size: 18px; font-weight: 800; color: var(--text-heading); }
.login-card h2 { font-size: 15px; font-weight: 600; color: var(--text-muted); text-align: center; margin-bottom: 24px; }

.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 12px; font-weight: 600; color: var(--text-muted); margin-bottom: 6px; text-transform: uppercase; letter-spacing: 0.05em; }
.form-group input {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 9px 12px;
  font-size: 14px;
  color: var(--text-primary);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.form-group input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-dim); }

.btn-primary {
  width: 100%;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 7px;
  padding: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  margin-top: 8px;
  transition: background 0.15s;
}
.btn-primary:hover { background: var(--accent-light); }

.login-error {
  background: rgba(239,68,68,0.12);
  border: 1px solid rgba(239,68,68,0.3);
  color: #f87171;
  border-radius: 6px;
  padding: 8px 12px;
  font-size: 13px;
  margin-bottom: 16px;
  text-align: center;
}

/* ── Scrollbars ─────────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--scrollbar-thumb); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--accent); }

/* ── Search results panel ───────────────────────────────────────────────────── */
.search-results {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.search-count {
  font-size: 11px;
  color: var(--text-faint);
  padding: 2px 4px 8px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.search-empty,
.search-loading {
  padding: 28px 16px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
  line-height: 1.6;
}
.search-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
}

.search-result-item {
  display: block;
  padding: 9px 10px;
  border-radius: 7px;
  border: 1px solid var(--border);
  margin-bottom: 5px;
  text-decoration: none;
  transition: border-color 0.15s, background 0.15s;
}
.search-result-item:hover {
  background: var(--bg-hover);
  border-color: var(--accent);
  text-decoration: none;
}

.sri-title {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-heading);
  margin-bottom: 4px;
}

.sri-snippet {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.5;
  word-break: break-word;
}

.sri-snippet mark {
  background: rgba(124, 58, 237, 0.3);
  color: var(--accent-hover);
  border-radius: 2px;
  padding: 0 2px;
  font-style: normal;
}
[data-theme="light"] .sri-snippet mark {
  background: rgba(124, 58, 237, 0.18);
  color: var(--accent-light);
}

.sri-path {
  font-size: 11px;
  color: var(--text-faint);
  margin-top: 5px;
}

/* ── Mobile ─────────────────────────────────────────────────────────────────── */
.sidebar-toggle-btn {
  display: none;
  align-items: center; justify-content: center;
  width: 32px; height: 32px;
  background: none; border: none;
  color: var(--text-muted); cursor: pointer; border-radius: 6px;
}
.sidebar-toggle-btn:hover { background: var(--bg-hover); color: var(--text-primary); }
.sidebar-toggle-btn svg { width: 18px; height: 18px; }

@media (max-width: 768px) {
  .sidebar-toggle-btn { display: flex; }
  .sidebar {
    position: fixed; left: 0; top: 0; bottom: 0; z-index: 100;
    transform: translateX(-100%);
    box-shadow: 4px 0 24px var(--shadow);
  }
  .sidebar.open { transform: translateX(0); }
  .content-area { padding: 24px 20px; }
}
