/* ═══════════════════════════════════════════════
   Ranjan's Notebook — Base (reset, vars, typo)
   ═══════════════════════════════════════════════ */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  /* Layout */
  --sidebar-w: 260px;
  --toolbar-h: 44px;

  /* Colors — Light */
  --bg: #f5f6f8;
  --surface: #ffffff;
  --sidebar-bg: #1c1c2e;
  --sidebar-text: #c4c8d4;
  --sidebar-hover: #28283e;
  --sidebar-active: #343454;

  --text-primary: #1a1a2e;
  --text-secondary: #5f6577;
  --text-muted: #9ca3af;

  --accent: #4f6ef7;
  --accent-hover: #3b5ce4;
  --accent-light: #eef2ff;
  --green: #22c55e;
  --orange: #f59e0b;
  --red: #ef4444;
  --purple: #8b5cf6;

  --border: #e4e7ec;
  --border-light: #f0f1f4;
  --radius: 8px;
  --radius-sm: 5px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
  --shadow: 0 2px 8px rgba(0,0,0,0.06);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.1);
}

html, body {
  height: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, 'Inter', 'Segoe UI', sans-serif;
  font-size: 16px;
  line-height: 1.6;
  color: var(--text-primary);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

/* Text selection */
::selection { background: rgba(79, 110, 247, 0.35); color: inherit; }
:root.dark ::selection { background: rgba(99, 130, 255, 0.45); color: inherit; }

/* Scrollbars */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.12); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(0,0,0,0.2); }

/* Typography */
h1 { font-size: 1.5rem; font-weight: 700; }
h2 { font-size: 1.15rem; font-weight: 700; }
h3 { font-size: 0.95rem; font-weight: 600; }

/* Utilities */
.hidden { display: none !important; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; min-width: 0; }

/* Buttons */
button { font-family: inherit; cursor: pointer; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 11px;
  font-size: 0.78rem;
  font-weight: 500;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text-primary);
  transition: all 0.12s ease;
  white-space: nowrap;
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: white; }
.btn.primary:hover { background: var(--accent-hover); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--accent-light); }
.btn.active { background: var(--accent-light); border-color: var(--accent); color: var(--accent); }
.btn.sm { padding: 3px 7px; font-size: 0.72rem; }
.btn.danger { color: var(--red); }
.btn.danger:hover { background: #fef2f2; border-color: var(--red); }

/* Toast */
.toast {
  position: fixed;
  bottom: 16px;
  right: 16px;
  padding: 8px 16px;
  border-radius: var(--radius);
  font-size: 0.8rem;
  font-weight: 600;
  color: white;
  z-index: 9999;
  animation: slideUp 0.25s ease;
}
.toast.success { background: var(--green); }
.toast.info { background: var(--accent); }
.toast.error { background: var(--red); }

@keyframes slideUp {
  from { transform: translateY(10px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

/* ─── Share Modal ─── */
.share-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10000;
  animation: fadeIn 0.15s ease;
}
.share-modal {
  background: var(--surface);
  border-radius: 12px;
  padding: 24px 28px;
  width: min(480px, 90vw);
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
.share-modal h3 {
  font-size: 1.1rem;
  margin-bottom: 8px;
  color: var(--text-primary);
}
.share-url-box {
  display: flex;
  gap: 8px;
  align-items: center;
}
.share-url-box input {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.82rem;
  background: var(--bg);
  color: var(--text-primary);
  font-family: 'SF Mono', Menlo, monospace;
}
.share-url-box input:focus {
  outline: none;
  border-color: var(--accent);
}
.shared-badge {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--accent);
  background: rgba(99, 102, 241, 0.08);
  padding: 4px 10px;
  border-radius: 12px;
  white-space: nowrap;
}
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* ─── Modal ─── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  backdrop-filter: blur(2px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 10000;
}
.modal-overlay.visible {
  display: flex;
}
.modal {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 24px 28px;
  width: 380px;
  max-width: 90vw;
  box-shadow: var(--shadow-lg), 0 0 0 1px var(--border);
  animation: modalIn 0.15s ease;
}
@keyframes modalIn {
  from { transform: scale(0.95) translateY(-8px); opacity: 0; }
  to { transform: scale(1) translateY(0); opacity: 1; }
}
.modal-title {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 14px;
}
.modal-input {
  width: 100%;
  padding: 10px 12px;
  font-size: 0.88rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text-primary);
  outline: none;
  transition: border-color 0.15s;
}
.modal-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(79, 110, 247, 0.1);
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 18px;
}
.modal-cancel {
  background: transparent;
  border-color: var(--border);
}
.modal-ok {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}
.modal-ok:hover {
  background: var(--accent-hover);
}

/* ─── Login Screen ─── */
#login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  height: 100dvh;
  background: linear-gradient(135deg, #1c1c2e 0%, #2d2b55 100%);
}
.login-card {
  text-align: center;
  color: white;
  padding: 3rem;
}
.login-card h1 {
  font-size: 2.5rem;
  margin-bottom: 0.5rem;
  font-family: 'Caveat', cursive;
}
.login-card p {
  color: rgba(255,255,255,0.6);
  margin-bottom: 2rem;
  font-size: 1.1rem;
}
.login-btn {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 12px 28px;
  background: white;
  color: #333;
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
}
.login-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(0,0,0,0.3);
}
.skip-btn {
  display: block;
  margin: 12px auto 0;
  padding: 8px 20px;
  background: transparent;
  border: 1px solid rgba(255,255,255,0.25);
  border-radius: 8px;
  color: rgba(255,255,255,0.7);
  font-size: 0.88rem;
  cursor: pointer;
  transition: all 0.15s;
}
.skip-btn:hover {
  border-color: rgba(255,255,255,0.5);
  color: white;
  background: rgba(255,255,255,0.05);
}
.login-hint {
  margin-top: 16px;
  font-size: 0.75rem;
  color: rgba(255,255,255,0.35);
}

/* ═══════════════════════════════════════════════
   Dark Mode
   ═══════════════════════════════════════════════ */
:root.dark {
  --bg: #0f1117;
  --surface: #181a24;
  --text-primary: #f0f1f4;
  --text-secondary: #b0b8c8;
  --text-muted: #7a8294;
  --accent-light: rgba(79, 110, 247, 0.18);
  --border: #282a3a;
  --border-light: #20222e;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
  --shadow: 0 2px 8px rgba(0,0,0,0.4);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.5);
}
/* Blocks */
:root.dark .block { background: #1c1e2a; border-color: #282a3a; box-shadow: 0 1px 4px rgba(0,0,0,0.3); }
:root.dark .block-body { color: #e4e6f0; }
:root.dark .block-body p, :root.dark .block-body li, :root.dark .block-body span { color: #e4e6f0; }
:root.dark .block-body strong { color: #fff; }
:root.dark .block-body em { color: #b0b8c8; }
:root.dark .block-body code { background: #262838; color: #e2e8f0; }
:root.dark .block-title { color: #f0f1f4; }
:root.dark .page-title { color: #f0f1f4; }
/* Block types */
:root.dark .block[data-type="concept"] { border-left-color: #60a5fa; background: #151c2e; }
:root.dark .block[data-type="formula"] { border-left-color: #a78bfa; background: #1a1730; }
:root.dark .block[data-type="example"] { border-left-color: #4ade80; background: #141f1a; }
:root.dark .block[data-type="warning"] { border-left-color: #f87171; background: #1f1214; }
:root.dark .block[data-type="note"]    { border-left-color: #64748b; background: #171920; }
:root.dark .block[data-type="gate"]    { border-left-color: #fbbf24; background: #1c1a14; }
/* Badges */
:root.dark .block-badge.concept { background: #1e3a5a; color: #93c5fd; }
:root.dark .block-badge.formula { background: #312e81; color: #a5b4fc; }
:root.dark .block-badge.note    { background: #1e2a36; color: #94a3b8; }
:root.dark .block-badge.warning { background: #3b1818; color: #fca5a5; }
:root.dark .block-badge.example { background: #1a3020; color: #86efac; }
:root.dark .block-badge.gate    { background: #2e1f0a; color: #fcd34d; }
:root.dark .block-badge.image   { background: #2a1a3e; color: #c4b5fd; }
/* Math & formula */
:root.dark .formula-display { background: #14151e; border-color: #282a3a; }
:root.dark .katex { color: #f0f1f4; }
/* Tags */
:root.dark .page-tag { background: #22243a; color: #b0b8c8; border-color: #282a3a; }
/* Stickies */
:root.dark .sticky-yellow { background: #3b3520; color: #fde68a; }
:root.dark .sticky-pink   { background: #3b1a2e; color: #fbcfe8; }
:root.dark .sticky-blue   { background: #1a2a40; color: #bfdbfe; }
:root.dark .sticky-green  { background: #1a3020; color: #bbf7d0; }
:root.dark .sticky-purple { background: #2a1a3e; color: #ddd6fe; }
/* Misc */
:root.dark .btn { background: #1c1e2a; border-color: #282a3a; color: #e4e6f0; }
:root.dark .btn:hover { border-color: var(--accent); }
:root.dark .btn.ghost { background: transparent; }
:root.dark .btn.ghost:hover { background: rgba(79,110,247,0.12); }
:root.dark .btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
:root.dark .btn.active { background: rgba(79,110,247,0.18); }
:root.dark .btn.danger:hover { background: #2a1212; }
:root.dark .sidebar-toggle { background: #1c1e2a; border-color: #282a3a; color: #b0b8c8; }
:root.dark .toolbar-fab { background: rgba(20,22,30,0.9); }
:root.dark .modal { background: #1c1e2a; }
:root.dark .modal-input { background: #14151e; border-color: #282a3a; color: #f0f1f4; }
/* Sidebar in dark mode */
:root.dark .sidebar { background: #14151e; }
:root.dark .sidebar-brand { border-bottom-color: rgba(255,255,255,0.1); }
:root.dark .sidebar-brand h1 { color: #f0f1f4; }
:root.dark .sidebar-search input { background: rgba(255,255,255,0.08); border-color: rgba(255,255,255,0.12); color: #f0f1f4; }
:root.dark .sidebar-search input::placeholder { color: rgba(255,255,255,0.4); }
:root.dark .sidebar-section-label { color: rgba(255,255,255,0.5); }
:root.dark .tree-notebook-header { color: rgba(255,255,255,0.6); }
:root.dark .tree-notebook-header:hover { color: rgba(255,255,255,0.85); }
:root.dark .tree-section { color: rgba(255,255,255,0.95); }
:root.dark .tree-page { color: rgba(255,255,255,0.75); }
:root.dark .tree-page:hover { color: #fff; background: rgba(255,255,255,0.06); }
:root.dark .tree-page.active { color: #93b4f8; }
:root.dark .tree-add-page { color: rgba(255,255,255,0.4); }
:root.dark .tree-action { color: rgba(255,255,255,0.45); }
:root.dark .nb-chevron { color: rgba(255,255,255,0.4); }
:root.dark .tree-section .chevron { color: rgba(255,255,255,0.35); }
:root.dark .tree-page .dot.todo { background: rgba(255,255,255,0.25); }
:root.dark ::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.12); }
:root.dark ::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.22); }

/* ─── Content Modal (help, backup, etc.) ─── */
.content-modal-overlay {
  display: none;
  position: fixed; inset: 0;
  z-index: 20000;
  background: rgba(0,0,0,0.45);
  backdrop-filter: blur(4px);
  justify-content: center;
  align-items: center;
}
.content-modal-overlay.visible { display: flex; }
.content-modal {
  background: var(--surface);
  border-radius: 14px;
  width: min(680px, 92vw);
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 60px rgba(0,0,0,0.25);
  animation: rtFadeIn 0.15s ease;
}
.content-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.content-modal-title { font-size: 1.05rem; font-weight: 700; color: var(--text-primary); }
.content-modal-close {
  width: 28px; height: 28px;
  border: none; background: none;
  font-size: 1rem; cursor: pointer;
  color: var(--text-muted);
  border-radius: 6px;
  transition: background 0.1s;
}
.content-modal-close:hover { background: rgba(0,0,0,0.06); }
.content-modal-body {
  padding: 20px;
  overflow-y: auto;
  font-size: 0.85rem;
  line-height: 1.6;
  color: var(--text-secondary);
}
:root.dark .content-modal { background: #1c1e2a; }
:root.dark .content-modal-header { border-bottom-color: #282a3a; }
:root.dark .content-modal-close:hover { background: rgba(255,255,255,0.08); }

/* ─── Help content styling ─── */
.help-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 10px 0 16px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
}
.help-nav a {
  font-size: 0.72rem;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 4px;
  background: var(--accent-light);
  color: var(--accent);
  text-decoration: none;
  transition: background 0.1s;
}
.help-nav a:hover { background: var(--accent); color: white; }
:root.dark .help-nav a { background: rgba(79,110,247,0.15); }
:root.dark .help-nav a:hover { background: var(--accent); color: white; }

.help-content section {
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid rgba(0,0,0,0.06);
}
:root.dark .help-content section { border-bottom-color: rgba(255,255,255,0.06); }
.help-content h4 { font-size: 0.92rem; color: var(--text-primary); margin-bottom: 8px; }
.help-content p { margin-bottom: 6px; }
.help-content ul, .help-content ol { padding-left: 20px; margin-bottom: 6px; }
.help-content li { margin-bottom: 3px; }
.help-content table { width: 100%; border-collapse: collapse; margin: 8px 0; }
.help-content th, .help-content td {
  text-align: left;
  padding: 5px 8px;
  border-bottom: 1px solid rgba(0,0,0,0.06);
  font-size: 0.8rem;
}
:root.dark .help-content th, :root.dark .help-content td { border-bottom-color: rgba(255,255,255,0.06); }
.help-content th { font-weight: 700; color: var(--text-primary); }
.help-content kbd {
  display: inline-block;
  padding: 1px 5px;
  font-size: 0.72rem;
  font-family: monospace;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 3px;
  color: var(--text-primary);
}
:root.dark .help-content kbd { background: #14151e; border-color: #282a3a; }
