:root {
  color-scheme: dark;
  --bg: #0f1115;
  --panel: #1b1f27;
  --surface: #252b36;
  --text: #f4f6f9;
  --muted: #9aa3b2;
  --accent: #57c7ff;
  --accent-hover: #3db8f5;
  --border: #2f3644;
  --danger: #ff5f56;
  --success: #5af78e;
  --font-mono: "Cascadia Code", "Fira Code", "Source Code Pro", "Consolas", monospace;
  --font-ui: "Segoe UI", system-ui, -apple-system, sans-serif;
  --radius: 6px;
  --radius-lg: 8px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  font-family: var(--font-ui);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* ── App shell ──────────────────────────────────────────────── */

.app-shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* ── Top bar ────────────────────────────────────────────────── */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1rem;
  height: 48px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  z-index: 100;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.logo {
  font-weight: 700;
  font-size: 1rem;
  color: var(--accent);
  letter-spacing: -0.02em;
  cursor: default;
  user-select: none;
}

.user-pill {
  padding: 0.3rem 0.7rem;
  background: var(--surface);
  border-radius: 999px;
  font-size: 0.8rem;
  color: var(--muted);
  border: 1px solid var(--border);
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Buttons ────────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.4rem 0.8rem;
  background: var(--accent);
  color: #0b0f14;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  font-weight: 600;
  font-size: 0.85rem;
  font-family: var(--font-ui);
  text-decoration: none;
  transition: background 0.15s, opacity 0.15s, color 0.15s, border-color 0.15s;
  white-space: nowrap;
}

.btn:hover {
  background: var(--accent-hover);
}

.btn.primary {
  background: var(--accent);
  color: #0b0f14;
}

.btn.small {
  padding: 0.2rem 0.5rem;
  font-size: 0.8rem;
}

.btn.ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
}

.btn.ghost:hover {
  color: var(--text);
  border-color: var(--muted);
  background: var(--surface);
}

/* ── Workspace (3-pane layout) ──────────────────────────────── */

.workspace {
  flex: 1;
  display: grid;
  grid-template-columns: 240px 1fr 260px;
  min-height: 0;
  overflow: hidden;
}

/* ── Sidebar ────────────────────────────────────────────────── */

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 0.75rem;
  background: var(--panel);
  border-right: 1px solid var(--border);
  overflow-y: auto;
}

.sidebar-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.sidebar-header h2 {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.search {
  width: 100%;
  padding: 0.45rem 0.7rem;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius);
  font-size: 0.85rem;
  font-family: var(--font-ui);
  outline: none;
  transition: border-color 0.15s;
}

.search:focus {
  border-color: var(--accent);
}

.search::placeholder {
  color: var(--muted);
  opacity: 0.6;
}

.note-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
  overflow-y: auto;
}

.note-list li {
  padding: 0.5rem 0.65rem;
  background: transparent;
  border-radius: var(--radius);
  border-left: 2px solid transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.88rem;
  transition: background 0.1s, color 0.1s;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.note-list li:hover {
  background: var(--surface);
  color: var(--text);
}

.note-list li.active {
  background: var(--surface);
  color: var(--text);
  border-left-color: var(--accent);
}

.sidebar-empty {
  text-align: center;
  padding: 1.5rem 0.5rem;
  color: var(--muted);
  font-size: 0.85rem;
}

.sidebar-empty p {
  margin-bottom: 0.75rem;
}

/* ── Editor pane ────────────────────────────────────────────── */

.editor-pane {
  display: flex;
  flex-direction: column;
  background: var(--panel);
  min-height: 0;
  overflow: hidden;
}

/* Tabs */
.tabs {
  display: flex;
  gap: 0;
  padding: 0.4rem 0.75rem 0;
  background: var(--panel);
  overflow-x: auto;
  flex-shrink: 0;
  border-bottom: 1px solid var(--border);
  min-height: 36px;
}

.tab {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.4rem 0.7rem;
  border-radius: var(--radius) var(--radius) 0 0;
  background: transparent;
  border: 1px solid transparent;
  border-bottom: none;
  color: var(--muted);
  font-size: 0.82rem;
  font-family: var(--font-ui);
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.1s, color 0.1s;
  position: relative;
  top: 1px;
}

.tab:hover {
  background: var(--surface);
  color: var(--text);
}

.tab.active {
  background: var(--surface);
  border-color: var(--border);
  color: var(--text);
}

.tab-title {
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tab-close {
  font-size: 1rem;
  line-height: 1;
  opacity: 0.4;
  cursor: pointer;
  padding: 0 2px;
  border-radius: 3px;
}

.tab-close:hover {
  opacity: 1;
  background: rgba(255, 95, 86, 0.2);
  color: var(--danger);
}

/* Editor area with line numbers */
.editor-wrap {
  flex: 1;
  display: flex;
  position: relative;
  overflow: hidden;
  background: var(--surface);
  margin: 0.5rem 0.75rem;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
}

.editor-wrap.disabled {
  opacity: 0.4;
}

.line-numbers {
  width: 48px;
  padding: 0.75rem 0.5rem;
  background: rgba(0, 0, 0, 0.15);
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 0.85rem;
  line-height: 1.5;
  text-align: right;
  user-select: none;
  white-space: pre;
  overflow: hidden;
  flex-shrink: 0;
  border-right: 1px solid var(--border);
}

.editor {
  flex: 1;
  width: 100%;
  border: none;
  background: transparent;
  color: var(--text);
  padding: 0.75rem;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  line-height: 1.5;
  resize: none;
  outline: none;
  overflow-y: auto;
  tab-size: 4;
}

.editor::placeholder {
  color: var(--muted);
  opacity: 0.4;
}

.editor:disabled {
  cursor: default;
}

/* Status bar */
.status-bar {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  padding: 0.3rem 0.75rem;
  font-size: 0.75rem;
  color: var(--muted);
  background: var(--bg);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

#status-saved {
  margin-left: auto;
  color: var(--success);
}

/* ── Context pane (right sidebar) ───────────────────────────── */

.context-pane {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 0.75rem;
  background: var(--panel);
  border-left: 1px solid var(--border);
  overflow-y: auto;
}

.context-pane h3 {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.context-item {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.context-item .label {
  color: var(--text);
  font-weight: 600;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.context-input {
  width: 100%;
  padding: 0.4rem 0.6rem;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius);
  font-size: 0.85rem;
  font-family: var(--font-ui);
  outline: none;
  transition: border-color 0.15s;
}

.context-input:focus {
  border-color: var(--accent);
}

/* ── Welcome screen ─────────────────────────────────────────── */

.welcome-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  padding: 3rem;
  text-align: center;
  color: var(--muted);
  height: 100%;
}

.welcome-screen h2 {
  color: var(--text);
  font-size: 1.4rem;
}

.welcome-screen p {
  max-width: 400px;
  line-height: 1.5;
}

/* ── Auth page (login) ──────────────────────────────────────── */

.auth-page {
  display: grid;
  place-items: center;
  min-height: 100vh;
  background: linear-gradient(135deg, #0f1115 0%, #1c212d 100%);
}

.auth-card {
  width: min(420px, 90%);
  background: var(--panel);
  padding: 2.5rem;
  border-radius: 12px;
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 1rem;
  text-align: center;
}

.auth-card h1 {
  font-size: 1.6rem;
  color: var(--accent);
  letter-spacing: -0.02em;
}

.auth-card p {
  color: var(--muted);
  line-height: 1.5;
}

.auth-meta {
  color: var(--muted);
  font-size: 0.8rem;
  opacity: 0.6;
}

/* ── Scrollbar styling ──────────────────────────────────────── */

::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--muted);
}

/* ── Responsive ─────────────────────────────────────────────── */

@media (max-width: 1024px) {
  .workspace {
    grid-template-columns: 220px 1fr;
  }

  .context-pane {
    display: none;
  }
}

@media (max-width: 768px) {
  .topbar {
    padding: 0 0.5rem;
    height: 44px;
  }

  .topbar-actions {
    gap: 0.3rem;
  }

  .logo {
    cursor: pointer;
  }

  .workspace {
    grid-template-columns: 1fr;
  }

  .sidebar {
    display: none;
    position: fixed;
    top: 44px;
    left: 0;
    bottom: 0;
    width: 280px;
    z-index: 50;
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.5);
  }

  .sidebar.mobile-visible {
    display: flex;
  }

  .context-pane {
    display: none;
  }
}
