/* === LOGSEQ-STYLE CUSTOM PROPERTIES === */
:root {
  --ls-primary: #106ba3;
  --ls-primary-bg: #1e3a5f;
  --ls-bg: #ffffff;
  --ls-bg-secondary: #f7f8fa;
  --ls-bg-tertiary: #edf0f2;
  --ls-sidebar-bg: #f7f8fa;
  --ls-border: #e2e5e9;
  --ls-text: #1a1a1a;
  --ls-text-secondary: #6b7280;
  --ls-text-muted: #9ca3af;
  --ls-bullet: #d1d5db;
  --ls-bullet-hover: #106ba3;
  --ls-block-highlight: #e8f4fd;
  --ls-block-selected: #d0e8f7;
  --ls-accent: #106ba3;
  --ls-error: #ef4444;
  --ls-success: #10b981;
  --sidebar-w: 260px;
  --header-h: 48px;
  --block-indent: 24px;

  font-family: -apple-system, BlinkMacSystemFont, 'Inter', 'Segoe UI', Roboto, sans-serif;
}

/* === DARK MODE === */
@media (prefers-color-scheme: dark) {
  :root {
    --ls-bg: #1e1e2e;
    --ls-bg-secondary: #27273a;
    --ls-bg-tertiary: #313147;
    --ls-sidebar-bg: #232336;
    --ls-border: #3a3a55;
    --ls-text: #e4e4eb;
    --ls-text-secondary: #a0a0b8;
    --ls-text-muted: #6b6b82;
    --ls-bullet: #4a4a6a;
    --ls-bullet-hover: #54a0ff;
    --ls-block-highlight: #1e3050;
    --ls-block-selected: #253b5e;
  }
}

/* === RESET === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body { background: var(--ls-bg); color: var(--ls-text); min-height: 100vh; font-size: 15px; line-height: 1.6; }

/* === SCREENS === */
.screen { display: none; }
.screen.active { display: flex; }

/* === AUTH SCREEN === */
#auth-screen.active {
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, var(--ls-primary-bg), #16213e);
}
.auth-container {
  background: var(--ls-bg);
  border-radius: 16px;
  padding: 48px 40px;
  width: 420px;
  max-width: 92vw;
  box-shadow: 0 20px 60px rgba(0,0,0,0.25);
}
.auth-logo {
  text-align: center;
  font-size: 28px;
  font-weight: 800;
  letter-spacing: 4px;
  color: var(--ls-primary);
  margin-bottom: 8px;
}
.subtitle { text-align: center; color: var(--ls-text-secondary); margin-bottom: 28px; font-size: 14px; }
#auth-tabs { display: flex; margin-bottom: 24px; border-bottom: 2px solid var(--ls-border); }
.tab {
  flex: 1;
  padding: 10px;
  background: none;
  border: none;
  color: var(--ls-text-secondary);
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: all 0.2s;
}
.tab.active { color: var(--ls-primary); border-bottom-color: var(--ls-primary); }
.tab:hover { color: var(--ls-text); }

/* === FORMS === */
.form-group { margin-bottom: 18px; }
.form-group label { display: block; margin-bottom: 6px; font-size: 13px; color: var(--ls-text-secondary); font-weight: 500; }
input[type="text"], input[type="email"], input[type="password"], input[type="search"] {
  width: 100%;
  padding: 10px 14px;
  border-radius: 8px;
  border: 1px solid var(--ls-border);
  background: var(--ls-bg);
  color: var(--ls-text);
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
  font-family: inherit;
}
input:focus { border-color: var(--ls-primary); box-shadow: 0 0 0 3px rgba(16,107,163,0.15); }

/* === BUTTONS === */
.btn {
  padding: 8px 16px;
  border-radius: 6px;
  border: 1px solid var(--ls-border);
  background: var(--ls-bg);
  color: var(--ls-text);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: all 0.15s;
  white-space: nowrap;
}
.btn:hover { background: var(--ls-bg-tertiary); }
.btn.primary { background: var(--ls-primary); border-color: var(--ls-primary); color: #fff; }
.btn.primary:hover { opacity: 0.9; }
.btn.danger { color: var(--ls-error); border-color: var(--ls-error); }
.btn.danger:hover { background: var(--ls-error); color: #fff; }
.btn.small { padding: 5px 10px; font-size: 12px; }
.icon-btn {
  background: none; border: none; cursor: pointer; font-size: 18px;
  padding: 4px 8px; border-radius: 4px; color: var(--ls-text-secondary);
  line-height: 1;
}
.icon-btn:hover { background: var(--ls-bg-tertiary); color: var(--ls-text); }

/* === ERROR === */
.error { background: rgba(239,68,68,0.1); border: 1px solid var(--ls-error); color: var(--ls-error); padding: 10px 14px; border-radius: 6px; font-size: 13px; margin-top: 12px; }
.hidden { display: none !important; }

/* === MAIN APP LAYOUT === */
#app-screen.active {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr auto;
  height: 100vh;
  overflow: hidden;
}

/* === LEFT SIDEBAR === */
#left-sidebar {
  background: var(--ls-sidebar-bg);
  border-right: 1px solid var(--ls-border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.sidebar-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 12px; border-bottom: 1px solid var(--ls-border);
  font-size: 14px; font-weight: 600; min-height: var(--header-h);
}
.graph-name { color: var(--ls-text); }
.sidebar-nav { display: flex; padding: 4px 8px; gap: 2px; border-bottom: 1px solid var(--ls-border); }
.nav-item {
  flex: 1; text-align: center; padding: 8px 4px; font-size: 12px; font-weight: 500;
  background: none; border: none; color: var(--ls-text-secondary); cursor: pointer;
  border-radius: 4px; transition: all 0.15s;
}
.nav-item.active { background: var(--ls-bg-tertiary); color: var(--ls-text); }
.nav-item:hover { background: var(--ls-bg-tertiary); }
.sidebar-search { padding: 8px 10px; }
.sidebar-search input { font-size: 13px; padding: 7px 10px; border-radius: 6px; }
.pages-list { flex: 1; overflow-y: auto; padding: 4px 0; }
.page-item {
  padding: 7px 16px; font-size: 13px; cursor: pointer; transition: background 0.1s;
  display: flex; align-items: center; gap: 6px; color: var(--ls-text-secondary);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.page-item:hover { background: var(--ls-bg-tertiary); color: var(--ls-text); }
.page-item.active { background: var(--ls-block-highlight); color: var(--ls-primary); font-weight: 500; }
.sidebar-footer { padding: 8px 10px; border-top: 1px solid var(--ls-border); }

/* === MAIN HEADER === */
#main-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px; height: var(--header-h); border-bottom: 1px solid var(--ls-border);
  background: var(--ls-bg);
}
.header-left { display: flex; align-items: center; gap: 10px; flex: 1; }
.header-right { display: flex; align-items: center; gap: 8px; }
.breadcrumb { display: flex; align-items: center; gap: 4px; font-size: 14px; font-weight: 600; }
.page-title-display { color: var(--ls-text); }
.user-badge {
  padding: 3px 8px; background: var(--ls-bg-tertiary); border-radius: 10px;
  font-size: 11px; color: var(--ls-text-secondary); max-width: 120px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* === VIEWS === */
#main-content { display: flex; flex-direction: column; overflow: hidden; }
.view { display: none; overflow: auto; flex: 1; }
.view.active { display: flex; flex-direction: column; }

/* === GRAPHS VIEW === */
.graphs-header { display: flex; justify-content: space-between; align-items: center; padding: 24px 24px 12px; }
.graphs-header h2 { font-size: 22px; font-weight: 700; }
.graphs-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; padding: 12px 24px 40px; }
.graph-card {
  background: var(--ls-bg-secondary); border-radius: 10px; padding: 18px;
  cursor: pointer; transition: all 0.15s; border: 1px solid var(--ls-border);
}
.graph-card:hover { border-color: var(--ls-primary); transform: translateY(-2px); box-shadow: 0 4px 12px rgba(0,0,0,0.08); }
.graph-card h3 { font-size: 16px; margin-bottom: 6px; color: var(--ls-text); }
.graph-card .meta { font-size: 11px; color: var(--ls-text-muted); }

/* === MODAL === */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,0.4); display: flex; align-items: center; justify-content: center; z-index: 100; }
.modal-content { background: var(--ls-bg); border-radius: 12px; padding: 28px; min-width: 360px; box-shadow: 0 12px 40px rgba(0,0,0,0.2); }
.modal-content h3 { font-size: 18px; margin-bottom: 16px; }
.modal-content input { margin-bottom: 16px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; }

/* === PAGE VIEW (OUTLINER) === */
.page-properties { padding: 8px 24px; border-bottom: 1px solid var(--ls-border); font-size: 13px; }
.property { display: flex; align-items: center; gap: 8px; padding: 2px 0; }
.prop-key { color: var(--ls-text-muted); font-size: 12px; min-width: 50px; }
.prop-value { border: none; background: transparent; font-size: 13px; padding: 2px 4px; flex: 1; }
.prop-value:focus { background: var(--ls-bg-secondary); border-radius: 4px; outline: none; }

/* === BLOCKS (OUTLINER) === */
.blocks-container { flex: 1; overflow-y: auto; padding: 12px 0 60px; }
.block-wrapper { position: relative; }

.block-row {
  display: flex; align-items: flex-start; gap: 4px; padding: 2px 16px;
  min-height: 28px; cursor: pointer; transition: background 0.1s;
  position: relative;
}
.block-row:hover { background: var(--ls-bg-secondary); }
.block-row.selected { background: var(--ls-block-selected); }
.block-row.highlighted { background: var(--ls-block-highlight); }

.bullet {
  width: 20px; height: 20px; display: flex; align-items: center; justify-content: center;
  cursor: pointer; flex-shrink: 0; font-size: 16px; color: var(--ls-bullet);
  user-select: none; line-height: 1; transition: color 0.15s;
  margin-top: 3px;
}
.bullet:hover { color: var(--ls-bullet-hover); }
.bullet.open::before { content: '▾'; font-size: 12px; }
.bullet.closed::before { content: '▸'; font-size: 12px; }
.bullet.leaf::before { content: '•'; }

.block-content {
  flex: 1; outline: none; padding: 3px 4px; min-height: 22px;
  border-radius: 3px; word-break: break-word;
  font-size: 15px; line-height: 1.55;
}
.block-content:empty::before {
  content: 'Leeg blok'; color: var(--ls-text-muted); font-style: italic;
}
.block-content:focus {
  background: var(--ls-bg); box-shadow: 0 0 0 2px var(--ls-primary);
}
.block-content strong { font-weight: 600; }
.block-content em { font-style: italic; }
.block-content del { text-decoration: line-through; opacity: 0.6; }
.block-content code { 
  background: var(--ls-bg-tertiary); padding: 1px 5px; border-radius: 3px;
  font-family: 'Fira Code', 'Consolas', monospace; font-size: 13px;
}
.block-content pre {
  background: var(--ls-bg-tertiary); padding: 12px; border-radius: 6px;
  overflow-x: auto; font-family: 'Fira Code', monospace; font-size: 13px;
  margin: 4px 0;
}
.block-content .tag { color: var(--ls-primary); }
.block-content .page-ref { color: var(--ls-primary); cursor: pointer; text-decoration: underline; text-decoration-style: dotted; }
.block-content .block-ref { color: var(--ls-text-secondary); cursor: pointer; border-bottom: 1px dashed var(--ls-text-muted); }

.block-children { padding-left: var(--block-indent); }

/* Add block input */
.add-block-row {
  display: flex; align-items: center; gap: 4px; padding: 6px 16px;
  border-top: 1px solid var(--ls-border); position: sticky; bottom: 0;
  background: var(--ls-bg);
}
.add-block-row .bullet-placeholder { width: 20px; text-align: center; color: var(--ls-bullet); font-size: 16px; flex-shrink: 0; }
.add-block-row input {
  flex: 1; border: none; background: transparent; padding: 8px 4px;
  font-size: 15px; font-family: inherit; color: var(--ls-text); outline: none;
}
.add-block-row input::placeholder { color: var(--ls-text-muted); }

/* Right sidebar */
#right-sidebar {
  width: 300px; background: var(--ls-sidebar-bg); border-left: 1px solid var(--ls-border);
  display: flex; flex-direction: column; overflow: hidden;
}
#right-sidebar .sidebar-header { justify-content: space-between; }
#right-sidebar-content { flex: 1; overflow-y: auto; padding: 12px; }

/* References */
.references-section { padding: 16px 24px 32px; border-top: 2px solid var(--ls-border); }
.references-section h3 { font-size: 14px; color: var(--ls-text-secondary); margin-bottom: 12px; }

/* Loading overlay */
.loading-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.3); display: flex; flex-direction: column; align-items: center; justify-content: center; z-index: 1000; gap: 12px; }
.loading-overlay.hidden { display: none; }
.spinner { width: 36px; height: 36px; border: 3px solid var(--ls-border); border-top-color: var(--ls-primary); border-radius: 50%; animation: spin 0.7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Toast */
#toast-container { position: fixed; bottom: 20px; right: 20px; z-index: 1100; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: var(--ls-bg); color: var(--ls-text); padding: 10px 18px;
  border-radius: 8px; font-size: 13px; box-shadow: 0 4px 16px rgba(0,0,0,0.15);
  animation: toastIn 0.3s ease;
  border-left: 4px solid var(--ls-primary);
}
.toast.error { border-left-color: var(--ls-error); }
.toast.success { border-left-color: var(--ls-success); }
@keyframes toastIn { from { transform: translateX(20px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* Responsive */
@media (max-width: 768px) {
  #app-screen.active { grid-template-columns: 1fr; }
  #left-sidebar { display: none; }
  #left-sidebar.open { display: flex; position: fixed; z-index: 50; left: 0; top: 0; bottom: 0; width: var(--sidebar-w); }
}