/* ============ Second Brain — modern dark UI ============ */
:root {
  --bg: #0b0e14;
  --bg-soft: #11151f;
  --panel: #151a26;
  --border: #232a3a;
  --text: #e6e9f0;
  --text-dim: #8b93a7;
  --accent: #7c6cff;
  --accent2: #4cc9f0;
  --danger: #ff6b81;
  --success: #52d273;
  --radius: 14px;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}
.hidden { display: none !important; }
a { color: var(--accent2); text-decoration: none; }

/* ---------- animated background orbs (auth) ---------- */
.auth-body {
  display: flex; align-items: center; justify-content: center;
  position: relative; overflow: hidden;
  background: radial-gradient(ellipse at top, #141a2b 0%, var(--bg) 70%);
}
.bg-orbs { position: absolute; inset: 0; overflow: hidden; }
.orb {
  position: absolute; border-radius: 50%; filter: blur(90px); opacity: .35;
  animation: float 14s ease-in-out infinite;
}
.o1 { width: 420px; height: 420px; background: #7c6cff; top: -120px; left: -100px; }
.o2 { width: 360px; height: 360px; background: #4cc9f0; bottom: -120px; right: -80px; animation-delay: -5s; }
.o3 { width: 260px; height: 260px; background: #ff6b81; top: 40%; left: 55%; animation-delay: -9s; }
@keyframes float {
  0%, 100% { transform: translate(0, 0) scale(1); }
  33% { transform: translate(60px, -40px) scale(1.08); }
  66% { transform: translate(-40px, 40px) scale(.94); }
}

/* ---------- auth card ---------- */
.auth-card {
  position: relative; z-index: 2;
  width: min(400px, 90vw);
  background: rgba(21, 26, 38, .75);
  backdrop-filter: blur(18px);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 44px 36px;
  text-align: center;
  box-shadow: 0 24px 60px rgba(0, 0, 0, .5);
  animation: cardIn .6s cubic-bezier(.22, 1, .36, 1);
}
@keyframes cardIn {
  from { opacity: 0; transform: translateY(28px) scale(.96); }
  to { opacity: 1; transform: none; }
}
.brain-logo { font-size: 52px; animation: pulse 3s ease-in-out infinite; }
@keyframes pulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.1); } }
.auth-card h1 { font-size: 24px; margin: 14px 0 6px; }
.auth-sub { color: var(--text-dim); font-size: 14px; margin-bottom: 24px; }
.auth-form { display: flex; flex-direction: column; gap: 14px; }
.input-wrap { position: relative; }
.input-wrap input {
  width: 100%; padding: 13px 42px 13px 16px;
  background: var(--bg-soft); color: var(--text);
  border: 1px solid var(--border); border-radius: 10px;
  font-size: 15px; outline: none; transition: border-color .2s, box-shadow .2s;
}
.input-wrap input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(124, 108, 255, .18);
}
.input-icon { position: absolute; right: 14px; top: 50%; transform: translateY(-50%); opacity: .6; }
.btn-primary {
  padding: 13px; border: none; border-radius: 10px; cursor: pointer;
  background: linear-gradient(135deg, var(--accent), #5a8bff);
  color: #fff; font-size: 15px; font-weight: 600;
  transition: transform .15s, box-shadow .2s;
}
.btn-primary:hover { transform: translateY(-2px); box-shadow: 0 8px 22px rgba(124, 108, 255, .35); }
.btn-primary:active { transform: translateY(0); }
.auth-error {
  background: rgba(255, 107, 129, .12); color: var(--danger);
  border: 1px solid rgba(255, 107, 129, .35);
  padding: 10px; border-radius: 10px; font-size: 13px; margin-bottom: 16px;
}
.auth-success {
  background: rgba(82, 210, 115, .12); color: var(--success);
  border: 1px solid rgba(82, 210, 115, .35);
  padding: 10px; border-radius: 10px; font-size: 13px; margin-bottom: 16px;
}
.shake { animation: shake .4s; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-7px); } 75% { transform: translateX(7px); }
}
.auth-link { display: inline-block; margin-top: 18px; font-size: 13px; color: var(--text-dim); }
.auth-link:hover { color: var(--accent2); }

/* ---------- app layout ---------- */
.app-body { display: flex; flex-direction: column; height: 100vh; }
.topbar {
  display: flex; align-items: center; gap: 18px;
  padding: 0 18px; height: 56px; flex-shrink: 0;
  background: var(--panel); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 9px; font-weight: 700; font-size: 16px; }
.brand-icon { font-size: 22px; }
.search-wrap { position: relative; flex: 1; max-width: 480px; margin: 0 auto; }
#searchInput {
  width: 100%; padding: 8px 14px;
  background: var(--bg-soft); border: 1px solid var(--border);
  border-radius: 9px; color: var(--text); font-size: 14px; outline: none;
  transition: border-color .2s;
}
#searchInput:focus { border-color: var(--accent); }
.search-results {
  position: absolute; top: 110%; left: 0; right: 0; z-index: 50;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 10px; max-height: 340px; overflow-y: auto;
  box-shadow: 0 16px 40px rgba(0, 0, 0, .5);
  animation: fadeSlide .18s ease;
}
@keyframes fadeSlide { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; } }
.search-item { padding: 10px 14px; cursor: pointer; border-bottom: 1px solid var(--border); }
.search-item:last-child { border-bottom: none; }
.search-item:hover { background: var(--bg-soft); }
.search-item .si-name { font-weight: 600; font-size: 14px; }
.search-item .si-snippet { font-size: 12px; color: var(--text-dim); margin-top: 3px; }
.topbar-actions { display: flex; gap: 8px; }
.icon-btn {
  background: var(--bg-soft); border: 1px solid var(--border);
  color: var(--text); border-radius: 9px; width: 36px; height: 36px;
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer; font-size: 16px; transition: background .2s, transform .15s;
}
.icon-btn:hover { background: var(--border); transform: translateY(-1px); }

.layout { display: flex; flex: 1; min-height: 0; }
.sidebar {
  width: 260px; flex-shrink: 0; overflow-y: auto;
  background: var(--panel); border-right: 1px solid var(--border);
  padding: 14px 10px;
}
.sidebar-head {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 13px; font-weight: 700; color: var(--text-dim);
  text-transform: uppercase; letter-spacing: .6px; padding: 4px 8px 12px;
}
.note-count { font-weight: 400; opacity: .7; }
.tree-folder { margin-bottom: 6px; }
.tree-folder-head {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 8px; border-radius: 8px; cursor: pointer;
  font-size: 13.5px; font-weight: 600; color: var(--text-dim);
  user-select: none; transition: background .15s;
}
.tree-folder-head:hover { background: var(--bg-soft); color: var(--text); }
.tree-folder-head .arrow { display: inline-block; transition: transform .25s; font-size: 10px; }
.tree-folder.open .tree-folder-head .arrow { transform: rotate(90deg); }
.tree-children {
  overflow: hidden; max-height: 0; transition: max-height .3s ease;
}
.tree-folder.open .tree-children { max-height: 600px; }
.tree-note {
  display: block; padding: 6px 8px 6px 28px; border-radius: 8px;
  font-size: 13.5px; color: var(--text); cursor: pointer;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  transition: background .15s, color .15s;
}
.tree-note:hover { background: var(--bg-soft); color: var(--accent2); }
.tree-note.active { background: rgba(124, 108, 255, .16); color: var(--accent2); font-weight: 600; }

/* ---------- content ---------- */
.content { flex: 1; display: flex; min-width: 0; }
.note-view {
  flex: 1; overflow-y: auto; padding: 40px 48px 80px;
  min-width: 0; animation: noteIn .35s ease;
}
@keyframes noteIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; } }
.welcome { text-align: center; margin-top: 14vh; color: var(--text-dim); }
.welcome-brain { font-size: 64px; animation: pulse 3s ease-in-out infinite; }
.welcome h2 { color: var(--text); margin: 18px 0 8px; }
.note-view h1, .note-view h2, .note-view h3 { margin: 1.3em 0 .5em; line-height: 1.3; }
.note-view h1 { font-size: 30px; border-bottom: 1px solid var(--border); padding-bottom: 12px; }
.note-view h2 { font-size: 22px; }
.note-view h3 { font-size: 18px; }
.note-view p { line-height: 1.75; margin: .7em 0; color: #cdd3e0; }
.note-view ul, .note-view ol { margin: .6em 0 .6em 1.6em; line-height: 1.7; color: #cdd3e0; }
.note-view blockquote {
  border-left: 3px solid var(--accent); padding: 8px 16px;
  background: var(--bg-soft); border-radius: 0 10px 10px 0;
  color: var(--text-dim); margin: 1em 0;
}
.note-view code {
  background: var(--bg-soft); border: 1px solid var(--border);
  padding: 2px 7px; border-radius: 6px; font-size: .9em;
  font-family: "JetBrains Mono", Consolas, monospace;
}
.note-view pre {
  background: #0d1220; border: 1px solid var(--border);
  border-radius: 12px; padding: 16px; overflow-x: auto; margin: 1em 0;
}
.note-view pre code { background: none; border: none; padding: 0; }
.note-view table { border-collapse: collapse; margin: 1em 0; width: 100%; }
.note-view th, .note-view td { border: 1px solid var(--border); padding: 8px 12px; font-size: 14px; }
.note-view th { background: var(--bg-soft); }
.note-view hr { border: none; border-top: 1px solid var(--border); margin: 2em 0; }
.wikilink {
  color: var(--accent2); cursor: pointer; font-weight: 500;
  border-bottom: 1px dashed rgba(76, 201, 240, .4);
  transition: color .15s, border-color .15s;
}
.wikilink:hover { color: var(--accent); border-color: var(--accent); }
.wikilink.missing { color: var(--text-dim); border-bottom-style: dotted; cursor: default; }
.tag {
  display: inline-block; background: rgba(124, 108, 255, .14);
  color: var(--accent2); padding: 1px 9px; border-radius: 20px;
  font-size: .85em; cursor: pointer; transition: background .15s;
}
.tag:hover { background: rgba(124, 108, 255, .3); }
.note-meta {
  display: flex; gap: 14px; flex-wrap: wrap;
  font-size: 12.5px; color: var(--text-dim); margin-bottom: 20px;
}
.note-meta span { background: var(--bg-soft); padding: 4px 10px; border-radius: 20px; border: 1px solid var(--border); }

/* ---------- side panel ---------- */
.side-panel {
  width: 240px; flex-shrink: 0; overflow-y: auto;
  border-left: 1px solid var(--border); background: var(--panel);
  padding: 18px 14px; animation: panelIn .3s ease;
}
@keyframes panelIn { from { opacity: 0; transform: translateX(14px); } to { opacity: 1; } }
.panel-section { margin-bottom: 22px; }
.panel-section h4 { font-size: 12px; text-transform: uppercase; letter-spacing: .6px; color: var(--text-dim); margin-bottom: 10px; }
.tag-list { display: flex; flex-wrap: wrap; gap: 6px; }
.backlink-list { display: flex; flex-direction: column; gap: 6px; }
.backlink-item {
  padding: 7px 10px; background: var(--bg-soft); border: 1px solid var(--border);
  border-radius: 8px; font-size: 13px; cursor: pointer; transition: border-color .15s;
}
.backlink-item:hover { border-color: var(--accent); }
.panel-empty { font-size: 12.5px; color: var(--text-dim); opacity: .7; }

/* ---------- graph overlay ---------- */
.graph-overlay {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(11, 14, 20, .96); backdrop-filter: blur(6px);
  display: flex; flex-direction: column;
  animation: fadeSlide .25s ease;
}
.graph-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 20px; font-weight: 700; border-bottom: 1px solid var(--border);
}
#graphCanvas { flex: 1; cursor: grab; }

/* ---------- scrollbar ---------- */
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: #333c52; }

/* ---------- responsive ---------- */
.welcome-hint-mobile { display: none; }
.menu-toggle { display: none; }
.sidebar-backdrop {
  position: fixed; inset: 0; z-index: 55;
  background: rgba(0, 0, 0, .5); backdrop-filter: blur(2px);
  opacity: 0; pointer-events: none; transition: opacity .25s;
}
.sidebar-backdrop.show { opacity: 1; pointer-events: auto; }

@media (max-width: 860px) {
  .welcome-hint-desktop { display: none; }
  .welcome-hint-mobile { display: block; }
  .menu-toggle { display: inline-flex; }
  .sidebar {
    position: fixed; left: 0; top: 56px; bottom: 0; z-index: 60;
    width: min(280px, 82vw);
    transform: translateX(-105%);
    transition: transform .28s cubic-bezier(.22, 1, .36, 1);
    box-shadow: 8px 0 30px rgba(0, 0, 0, .45);
  }
  .sidebar.open { transform: translateX(0); }
  .brand-name { display: none; }
  .note-view { padding: 22px 18px 60px; }
  .note-view h1 { font-size: 24px; }
  .side-panel {
    display: block; width: 100%; flex-shrink: 0;
    border-left: none; border-top: 1px solid var(--border);
  }
  .content { flex-direction: column; overflow-y: auto; }
  .note-view { flex: unset; overflow-y: visible; }
  .topbar { gap: 10px; padding: 0 12px; }
}
