:root {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-2: #334155;
  --text: #f8fafc;
  --muted: #94a3b8;
  --accent: #f97316;
  --accent-hover: #ea580c;
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --success: #22c55e;
  --sidebar-width: 280px;
  --radius: 8px;
  --font-sans: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body, #app {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
}

#app {
  display: flex;
}

.sidebar {
  width: var(--sidebar-width);
  background: var(--surface);
  border-right: 1px solid var(--surface-2);
  display: flex;
  flex-direction: column;
  padding: 1rem;
}

.brand h1 {
  margin: 0;
  font-size: 1.35rem;
  color: var(--accent);
}
.tagline { color: var(--muted); font-size: 0.8rem; }

.toolbar {
  margin-top: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

#search {
  padding: 0.5rem;
  border-radius: var(--radius);
  border: 1px solid var(--surface-2);
  background: var(--bg);
  color: var(--text);
  font-size: 0.9rem;
}

.note-list {
  list-style: none;
  padding: 0;
  margin: 1rem 0 0;
  overflow-y: auto;
  flex: 1;
}

.note-list li {
  padding: 0.55rem 0.75rem;
  border-radius: var(--radius);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

.note-list li:hover, .note-list li.active {
  background: var(--surface-2);
}

.note-list .title {
  font-size: 0.95rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.note-list .meta {
  font-size: 0.7rem;
  color: var(--muted);
}

.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
}

.note-pane {
  flex: 1;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.note-header {
  margin-bottom: 0.5rem;
}

#note-title {
  width: 100%;
  font-size: 1.5rem;
  font-weight: 700;
  background: transparent;
  border: none;
  border-bottom: 2px solid var(--surface-2);
  color: var(--text);
  padding: 0.25rem 0;
  outline: none;
}

#note-title:focus { border-color: var(--accent); }

.path {
  color: var(--muted);
  font-size: 0.8rem;
  font-family: var(--font-mono);
}

.editor-tabs {
  display: flex;
  gap: 0.5rem;
  margin: 0.75rem 0;
}

.tab {
  background: var(--surface);
  border: 1px solid var(--surface-2);
  color: var(--muted);
  padding: 0.35rem 0.75rem;
  border-radius: var(--radius);
  cursor: pointer;
}

.tab.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

#note-editor, #note-preview {
  flex: 1;
  width: 100%;
  min-height: 120px;
  background: var(--bg);
  border: 1px solid var(--surface-2);
  border-radius: var(--radius);
  padding: 0.75rem;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 0.9rem;
  resize: none;
  line-height: 1.5;
  overflow-y: auto;
  white-space: pre-wrap;
}

#note-preview { font-family: var(--font-sans); }
#note-preview h1, #note-preview h2, #note-preview h3 { margin-top: 0; }
#note-preview a { color: var(--accent); }
#note-preview ul, #note-preview ol { padding-left: 1.25rem; }
#note-preview code { background: var(--surface); padding: 0.1rem 0.3rem; border-radius: 4px; }
#note-preview pre { background: var(--surface); padding: 0.75rem; border-radius: var(--radius); overflow-x: auto; }

.hidden { display: none !important; }

.actions {
  margin-top: 0.75rem;
  display: flex;
  gap: 0.5rem;
}

.research-pane {
  height: 38vh;
  border-top: 1px solid var(--surface-2);
  background: var(--surface);
  padding: 0.75rem 1.25rem;
  display: flex;
  flex-direction: column;
  min-height: 220px;
}

.research-pane h2 {
  margin: 0 0 0.5rem;
  font-size: 1rem;
  color: var(--accent);
}

.chat {
  flex: 1;
  overflow-y: auto;
  background: var(--bg);
  border: 1px solid var(--surface-2);
  border-radius: var(--radius);
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.bubble {
  max-width: 90%;
  padding: 0.55rem 0.75rem;
  border-radius: var(--radius);
  line-height: 1.45;
  font-size: 0.9rem;
}

.bubble.user {
  align-self: flex-end;
  background: var(--surface-2);
}

.bubble.assistant {
  align-self: flex-start;
  background: var(--bg);
  border: 1px solid var(--surface-2);
}

.bubble.system {
  align-self: center;
  color: var(--muted);
  font-size: 0.8rem;
  background: transparent;
}

.chat-form {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

#chat-input {
  flex: 1;
  resize: none;
  background: var(--bg);
  border: 1px solid var(--surface-2);
  border-radius: var(--radius);
  color: var(--text);
  padding: 0.5rem;
  font-family: var(--font-sans);
}

.include-note {
  margin-top: 0.35rem;
  font-size: 0.8rem;
  color: var(--muted);
}

.btn {
  padding: 0.5rem 0.85rem;
  border-radius: var(--radius);
  border: none;
  cursor: pointer;
  font-weight: 600;
  background: var(--surface-2);
  color: var(--text);
}

.btn:hover { background: #475569; }

.btn.primary { background: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-hover); }

.btn.danger { background: transparent; color: var(--danger); border: 1px solid var(--danger); }
.btn.danger:hover { background: var(--danger); color: #fff; }

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}

.modal-content {
  background: var(--surface);
  padding: 1.5rem;
  border-radius: var(--radius);
  min-width: 300px;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

#auth-input {
  padding: 0.5rem;
  background: var(--bg);
  border: 1px solid var(--surface-2);
  color: var(--text);
  border-radius: var(--radius);
}

@media (max-width: 800px) {
  #app { flex-direction: column; }
  .sidebar { width: 100%; height: 35vh; border-right: none; border-bottom: 1px solid var(--surface-2); }
  .main { height: 65vh; }
}
