/* ─── CSS Custom Properties ───────────────────────────────────────────────── */
:root {
  --font-main: "Inter", system-ui, -apple-system, sans-serif;
  --node-bg: #ffffff;
  --node-border-radius: 12px;
  --sidebar-width: 320px;
  --header-h: 52px;

  --color-bg: #f5f5f4;
  --color-surface: #ffffff;
  --color-border: #e5e7eb;
  --color-text: #111827;
  --color-text-muted: #6b7280;
  --color-primary: #6366f1;
  --color-success: #22c55e;
  --color-failure: #ef4444;
  --color-pending: #d1d5db;
  --color-warning: #f59e0b;

  --shadow-sm: 0 1px 3px rgba(0,0,0,0.07), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
  --transition: 0.18s ease;
}

/* ─── Reset & Base ────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--font-main);
  background: var(--color-bg);
  color: var(--color-text);
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ─── Header bar ──────────────────────────────────────────────────────────── */
#header {
  height: var(--header-h);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  flex-shrink: 0;
  z-index: 20;
}

#header .logo {
  font-weight: 700;
  font-size: 1.1rem;
  letter-spacing: -0.03em;
  color: var(--color-primary);
}

#project-name {
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--color-text-muted);
}

#header .spacer { flex: 1; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: 8px;
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text);
  font-family: var(--font-main);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition);
  white-space: nowrap;
}
.btn:hover { background: #f3f4f6; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary {
  background: var(--color-primary);
  border-color: var(--color-primary);
  color: #fff;
}
.btn-primary:hover { background: #4f46e5; border-color: #4f46e5; }

/* ─── Layout ──────────────────────────────────────────────────────────────── */
#app {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ─── Sidebar ─────────────────────────────────────────────────────────────── */
#sidebar {
  width: var(--sidebar-width);
  min-width: 260px;
  max-width: 400px;
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  flex-shrink: 0;
}

.sidebar-section {
  padding: 12px 14px;
  border-bottom: 1px solid var(--color-border);
}

.sidebar-label {
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--color-text-muted);
  margin-bottom: 8px;
}

/* Project list */
#project-list {
  list-style: none;
  max-height: 120px;
  overflow-y: auto;
}

.project-item {
  padding: 6px 8px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.85rem;
  transition: background var(--transition);
}
.project-item:hover { background: #f3f4f6; }
.project-item.active { background: #ede9fe; color: var(--color-primary); font-weight: 600; }

/* Search */
#search-input {
  width: 100%;
  padding: 7px 10px;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  font-family: var(--font-main);
  font-size: 0.85rem;
  outline: none;
  transition: border-color var(--transition);
}
#search-input:focus { border-color: var(--color-primary); }

#search-results {
  list-style: none;
  margin-top: 6px;
  max-height: 140px;
  overflow-y: auto;
}

.search-result {
  padding: 6px 8px;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 0.82rem;
}
.search-result:hover { background: #f3f4f6; }
.search-result small { color: var(--color-text-muted); }
.search-empty, .search-error { padding: 6px 8px; color: var(--color-text-muted); font-size: 0.82rem; }

/* Node list */
#node-list { list-style: none; max-height: 160px; overflow-y: auto; }

.node-list-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 8px;
  border-radius: 6px;
  font-size: 0.82rem;
  cursor: default;
}

.node-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* Node form */
#node-form { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 10px; }
#sidebar-hint { flex: 1; display: flex; align-items: center; justify-content: center; padding: 24px; color: var(--color-text-muted); font-size: 0.85rem; text-align: center; }

.form-row { display: flex; flex-direction: column; gap: 4px; }
.form-label { font-size: 0.78rem; font-weight: 500; color: var(--color-text-muted); }

.form-input, .form-select, .form-textarea {
  width: 100%;
  padding: 7px 10px;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  font-family: var(--font-main);
  font-size: 0.85rem;
  color: var(--color-text);
  background: var(--color-surface);
  outline: none;
  transition: border-color var(--transition);
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
  border-color: var(--color-primary);
}

.form-textarea {
  resize: vertical;
  min-height: 120px;
  font-family: "JetBrains Mono", "Fira Code", ui-monospace, monospace;
  font-size: 0.8rem;
  line-height: 1.5;
}

.form-row-inline { display: flex; gap: 8px; align-items: center; }
.form-color { width: 36px; height: 32px; padding: 2px; border-radius: 6px; border: 1px solid var(--color-border); cursor: pointer; }

/* History list */
#node-history { list-style: none; display: flex; flex-direction: column; gap: 4px; max-height: 180px; overflow-y: auto; }

.history-entry {
  display: flex;
  align-items: baseline;
  gap: 6px;
  padding: 5px 8px;
  border-radius: 6px;
  font-size: 0.78rem;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background var(--transition);
}
.history-entry:hover { background: #f3f4f6; }
.history-entry.status-success { border-color: #bbf7d0; background: #f0fdf4; }
.history-entry.status-failure { border-color: #fecaca; background: #fef2f2; }
.history-version { font-weight: 700; color: var(--color-text-muted); }
.history-date { color: var(--color-text-muted); flex: 1; text-align: right; }
.history-error { color: var(--color-failure); font-size: 0.75rem; margin-top: 2px; }

/* Import / Export */
#import-area {
  width: 100%;
  min-height: 80px;
  resize: vertical;
  padding: 8px 10px;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  font-family: ui-monospace, monospace;
  font-size: 0.75rem;
  outline: none;
}
#import-area:focus { border-color: var(--color-primary); }

.import-actions { display: flex; gap: 8px; }

/* Write token */
#write-token {
  width: 100%;
  padding: 6px 10px;
  border: 1px solid var(--color-border);
  border-radius: 8px;
  font-family: ui-monospace, monospace;
  font-size: 0.8rem;
  outline: none;
}
#write-token:focus { border-color: var(--color-primary); }

/* Status bar */
#status-bar {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  padding: 8px 18px;
  border-radius: 20px;
  font-size: 0.85rem;
  font-weight: 500;
  background: #1f2937;
  color: #fff;
  box-shadow: var(--shadow-md);
  z-index: 1000;
  transition: opacity var(--transition);
}
#status-bar.status-error  { background: #dc2626; }
#status-bar.status-warn   { background: #d97706; }

/* ─── Canvas area ─────────────────────────────────────────────────────────── */
#canvas-wrap {
  flex: 1;
  position: relative;
  overflow: hidden;
}

#canvas {
  width: 100%;
  height: 100%;
}

/* Drawflow overrides */
.drawflow {
  background-color: var(--color-bg);
  background-image:
    radial-gradient(circle, #d1d5db 1px, transparent 1px);
  background-size: 28px 28px;
}

.drawflow .drawflow-node {
  background: var(--node-bg);
  border-radius: var(--node-border-radius);
  border: 1.5px solid var(--node-color, var(--color-border));
  box-shadow: var(--shadow-sm);
  padding: 0;
  min-width: 180px;
  max-width: 260px;
  font-family: var(--font-main);
  transition: box-shadow var(--transition), border-color var(--transition);
}

.drawflow .drawflow-node.selected {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 2px rgba(99,102,241,0.25), var(--shadow-md);
}

/* Node card inner */
.node-card {
  padding: 10px 12px;
  border-left: 4px solid var(--node-color, var(--color-primary));
  border-radius: calc(var(--node-border-radius) - 2px);
}

.node-header {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  font-weight: 600;
  line-height: 1.3;
}

.node-status-icon { font-size: 0.8rem; flex-shrink: 0; }
.node-title { flex: 1; word-break: break-word; }

.node-version {
  font-size: 0.65rem;
  font-weight: 700;
  background: #f3f4f6;
  border-radius: 4px;
  padding: 1px 5px;
  color: var(--color-text-muted);
  flex-shrink: 0;
}

.node-preview {
  margin-top: 5px;
  font-size: 0.75rem;
  color: var(--color-text-muted);
  line-height: 1.4;
  word-break: break-word;
}

/* Connector dots */
.drawflow .drawflow-node .input, .drawflow .drawflow-node .output {
  background: var(--node-color, var(--color-primary));
  border: 2px solid var(--color-surface);
  width: 12px; height: 12px;
  border-radius: 50%;
}

/* Connection lines */
.drawflow .connection .main-path {
  stroke: var(--color-primary);
  stroke-width: 2;
  opacity: 0.6;
}
.drawflow .connection .main-path:hover { opacity: 1; }

/* ─── Node type accent colours ────────────────────────────────────────────── */
.node-type-title  .node-card { border-left-color: #6366f1; }
.node-type-content .node-card { /* uses node's own color */ }
.node-type-idea   .node-card { border-left-color: #f59e0b; }
.node-type-group  .node-card { border-left-color: #06b6d4; }
.node-type-status .node-card { border-left-color: #84cc16; }

/* ─── Scrollbars (thin) ───────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: #9ca3af; }
