* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; background: #0f0f13; color: #e0e0e0; height: 100vh; display: flex; flex-direction: column; overflow: hidden; }

header { display: flex; align-items: center; gap: 12px; padding: 9px 16px; background: #1a1a22; border-bottom: 1px solid #2a2a38; flex-shrink: 0; }
header h1 { font-size: 14px; font-weight: 600; color: #8080b0; letter-spacing: 0.06em; }
.header-logo { width: 24px; height: 24px; flex-shrink: 0; }
.spacer { flex: 1; }
.stat { font-size: 11px; color: #888; }

.main { display: flex; flex: 1; overflow: hidden; }

/* ── Demo banner ── */
#demo-banner { display: none; align-items: center; gap: 8px; padding: 6px 16px; background: #2a2a1a; border-bottom: 1px solid #4a4a30; font-size: 12px; color: #cc9944; flex-shrink: 0; }
#demo-banner a { color: #88aaff; }

/* ── Left list ── */
.list-panel { flex: 0 0 44%; display: flex; flex-direction: column; border-right: 1px solid #2a2a38; }
.list-controls { padding: 10px 12px; background: #14141c; border-bottom: 1px solid #2a2a38; flex-shrink: 0; }
.search-wrap { position: relative; }
.search-wrap input { width: 100%; padding: 7px 10px 7px 30px; background: #1e1e2c; border: 1px solid #2e2e42; border-radius: 6px; color: #c0c0d8; font-size: 13px; outline: none; }
.search-wrap input:focus { border-color: #5050a0; }
.search-icon { position: absolute; left: 9px; top: 50%; transform: translateY(-50%); color: #555; font-size: 16px; pointer-events: none; }
.list-body { flex: 1; overflow-y: auto; }
table { width: 100%; border-collapse: collapse; font-size: 12px; }
th { position: sticky; top: 0; background: #14141c; text-align: left; padding: 5px 10px; color: #888; font-weight: 500; border-bottom: 1px solid #2a2a38; z-index: 1; font-size: 11px; }
td { padding: 4px 10px; border-bottom: 1px solid #18181f; vertical-align: top; }
tr:hover td { background: #18182a; cursor: pointer; }
tr.selected td { background: #24244a !important; border-left: 2px solid #5050a0; }
.td-dt { color: #666; white-space: nowrap; font-size: 11px; line-height: 1.4; }
.td-type { white-space: nowrap; text-align: center; padding-top: 8px; }
.td-title { color: #d0d0f0; font-size: 14px; font-weight: 500; line-height: 20px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.td-content { color: #999; font-size: 13px; line-height: 17px; max-height: 17px; display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical; overflow: hidden; }
.list-footer { display: flex; align-items: center; justify-content: center; padding: 5px 10px; background: #14141c; border-top: 1px solid #2a2a38; flex-shrink: 0; font-size: 11px; color: #888; }
#btn-sort { background: none; border: none; color: #555; cursor: pointer; font-size: 13px; margin-left: 4px; padding: 0 2px; vertical-align: middle; }
#btn-sort:hover { color: #a0a0c0; }
#btn-sort.disabled { color: #2a2a38; pointer-events: none; }

/* ── Right ── */
.right-panel { flex: 1; display: flex; flex-direction: column; overflow: hidden; min-width: 0; }
.graph-panel { flex: 1; display: flex; flex-direction: column; overflow: hidden; position: relative; }
.graph-header { padding: 4px 8px; font-size: 10px; color: #888; background: #0f0f13; border-bottom: 1px solid #1c1c24; flex-shrink: 0; display: flex; align-items: center; gap: 4px; }
.graph-header > span { flex: 1; }
.graph-tool { padding: 4px 6px; border-radius: 4px; border: 1px solid transparent; background: transparent; color: #888; cursor: pointer; display: flex; align-items: center; }
.graph-tool:hover { background: #1e1e2c; color: #c0c0d0; }
.graph-tool.active { background: #2a2a48; border-color: #4a4a80; color: #c0c0f0; }
.graph-tool.danger:hover { color: #ff6060; }
.threshold-control { position: relative; margin-left: auto; }
.threshold-btn { font-size: 11px !important; gap: 4px; white-space: nowrap; }
.threshold-popup { display: none; position: absolute; top: 100%; right: 0; background: #1a1a22; border: 1px solid #2a2a38; border-radius: 6px; padding: 16px 12px; z-index: 100; align-items: center; gap: 8px; box-shadow: 0 4px 12px rgba(0,0,0,0.5); }
.threshold-popup.open { display: flex; flex-direction: column; }
.threshold-popup .slider-wrap { width: 24px; height: 150px; position: relative; }
.threshold-popup input[type="range"] { -webkit-appearance: slider-vertical; appearance: slider-vertical; width: 24px; height: 150px; accent-color: #5050a0; cursor: pointer; margin: 0; padding: 0; }
.threshold-popup-labels { display: flex; flex-direction: column; justify-content: space-between; height: 150px; font-size: 9px; color: #666; position: absolute; left: 28px; top: 0; pointer-events: none; }
.demo-github { margin-left: auto; color: #88aaff; }
.selection-actions { display: none; align-items: center; gap: 4px; margin-left: 8px; padding-left: 8px; border-left: 1px solid #2a2a38; }
.selection-actions.visible { display: flex; }
.selection-count { font-size: 11px; color: #aaa; margin-right: 4px; }
#graph-canvas { display: block; width: 100%; height: 100%; flex: 1; min-height: 0; cursor: grab; }
.graph-loading { position: absolute; bottom: 10px; right: 12px; font-size: 10px; color: #4a4a70; pointer-events: none; }
.graph-loading.hidden { display: none; }

/* ── Resize handles ── */
.resize-handle-v { flex: 0 0 5px; cursor: col-resize; background: transparent; border-left: 1px solid #2a2a38; transition: background 0.15s; z-index: 10; }
.resize-handle-v:hover, .resize-handle-v.active { background: #4a4a80; }
.resize-handle-h { flex: 0 0 5px; cursor: row-resize; background: transparent; border-top: 1px solid #2a2a38; transition: background 0.15s; z-index: 10; }
.resize-handle-h:hover, .resize-handle-h.active { background: #4a4a80; }

/* ── Node card (docked panel below graph) ── */
#node-card { background: #181826; border-top: 1px solid #32324a; padding: 10px 12px; display: none; overflow-y: auto; flex-shrink: 0; }
#node-card.visible { display: flex; flex-direction: column; }
.nc-header { display: flex; align-items: center; gap: 7px; margin-bottom: 0; flex-shrink: 0; }
.nc-title { font-size: 13px; font-weight: 600; color: #c0c0e0; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nc-actions { display: none; margin-left: auto; gap: 6px; align-items: center; }
#node-card .nc-actions { display: flex; }
.nc-btn { background: none; border: none; color: #888; cursor: pointer; font-size: 13px; padding: 1px 3px; line-height: 1; transition: color 0.12s; }
.nc-btn:hover { color: #c0c0d0; }
.nc-btn.nc-delete:hover { color: #ff6060; }

/* ── Card tabs ── */
.nc-tabs { display: flex; gap: 0; margin: 6px 0 0; border-bottom: 1px solid #2a2a38; flex-shrink: 0; }
.nc-tab { padding: 4px 12px; border: none; background: transparent; color: #666; font-size: 11px; cursor: pointer; font-family: inherit; border-bottom: 2px solid transparent; transition: all 0.12s; }
.nc-tab:hover { color: #a0a0c0; }
.nc-tab.active { color: #8080b0; border-bottom-color: #5050a0; }
.nc-tab-content { display: none; overflow-y: auto; flex: 1; padding-top: 6px; }
.nc-tab-content.active { display: block; }

.nc-text { font-size: 13px; color: #ccc; line-height: 1.6; white-space: pre-wrap; word-break: break-word; }
.nc-neighbors { font-size: 10px; color: #8888cc; margin-top: 5px; }
.nc-date { font-size: 10px; color: #777; margin-top: 5px; }
.nc-edit-area { width: 100%; min-height: 140px; max-height: 320px; background: #0f0f18; border: 1px solid #3a3a5a; color: #c0c0d0; font-size: 12px; line-height: 1.6; padding: 5px; border-radius: 4px; resize: vertical; font-family: inherit; outline: none; box-sizing: border-box; }

/* ── History timeline ── */
.nc-history { padding: 4px 0; }
.nc-history-empty { font-size: 11px; color: #444; padding: 8px 0; }
.nc-history-entry { display: flex; gap: 10px; padding: 6px 0; border-bottom: 1px solid #1a1a24; font-size: 11px; }
.nc-history-entry:last-child { border-bottom: none; }
.nc-history-date { color: #666; white-space: nowrap; flex-shrink: 0; min-width: 70px; }
.nc-history-action { font-weight: 600; min-width: 60px; flex-shrink: 0; }
.nc-history-action.act-delete { color: #cc6666; }
.nc-history-action.act-merge { color: #6688cc; }
.nc-history-action.act-augment { color: #66aa88; }
.nc-history-action.act-keep, .nc-history-action.act-bump { color: #7788aa; }
.nc-history-action.act-create { color: #88cc66; }
.nc-history-action.act-insight { color: #cc9944; }
.nc-history-action.act-stale { color: #aa8866; }
.nc-history-action.act-promote { color: #8888cc; }
.nc-history-action.act-evict { color: #888866; }
.nc-history-reason { color: #999; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── Inline list spinner ── */
#list-spinner { display: flex; align-items: center; justify-content: center; padding: 18px 0; gap: 8px; }
#list-spinner.hidden { display: none; }
.spinner { width: 18px; height: 18px; border: 2px solid #252535; border-top-color: #5050a0; border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
#list-spinner span { font-size: 11px; color: #888; }

/* ── Settings view (full page tab) ── */
#settings-view { display: none; flex: 1; overflow-y: auto; padding: 30px 40px; }
#settings-view.active { display: flex; flex-direction: column; }
.settings-group { margin-bottom: 36px; max-width: 600px; padding-bottom: 36px; border-bottom: 1px solid #2a2a38; }
.settings-group:last-child { border-bottom: none; }
.settings-group h3 { font-size: 18px; color: #c0c0f0; font-weight: 600; margin-bottom: 16px; }
.settings-group label { display: block; font-size: 14px; color: #ccc; margin-bottom: 6px; margin-top: 16px; }
.settings-group input[type="text"], .settings-group input[type="password"] { width: 100%; padding: 10px 12px; background: #1e1e2c; border: 1px solid #2e2e42; border-radius: 6px; color: #e0e0f0; font-size: 14px; outline: none; font-family: inherit; }
.settings-group input[type="text"]:focus, .settings-group input[type="password"]:focus { border-color: #5050a0; }
.settings-group .hint { font-size: 12px; color: #888; margin-top: 4px; }
.slider-row { display: flex; align-items: center; gap: 16px; margin-top: 8px; }
.slider-row input[type="range"] { flex: 1; accent-color: #5050a0; height: 8px; }
.slider-val { font-size: 18px; color: #e0e0f0; font-weight: 600; min-width: 50px; text-align: right; }
.settings-save { margin-top: 24px; display: flex; gap: 12px; }
.settings-save button { padding: 8px 24px; border-radius: 6px; border: 1px solid #4a4a90; background: #2a2a5a; color: #c0c0f0; font-size: 14px; cursor: pointer; font-family: inherit; }
.settings-save button:hover { background: #3a3a70; }
.settings-save .btn-secondary { background: transparent; border-color: #4a4a4a; color: #999; }
.settings-save .btn-secondary:hover { background: #2a2a2a; color: #ccc; }

/* ── Tabs ── */
.tab-bar { display: flex; gap: 0; margin-left: 16px; }
.tab-btn { padding: 4px 14px; border: 1px solid transparent; border-bottom: none; border-radius: 5px 5px 0 0; background: transparent; color: #888; font-size: 11px; cursor: pointer; font-family: inherit; transition: all 0.12s; }
.tab-btn:hover { color: #a0a0c0; }
.tab-btn.active { background: #1a1a22; border-color: #2a2a38; color: #8080b0; }

/* ── Type filter ── */
#type-filter { background: #1e1e2c; border: 1px solid #2e2e42; border-radius: 5px; color: #c0c0d8; font-size: 12px; padding: 6px 8px; outline: none; font-family: inherit; flex-shrink: 0; }
#type-filter:focus { border-color: #5050a0; }

/* ── Dreaming panel ── */
#dreaming-view { display: none; flex: 1; overflow: hidden; }
#dreaming-view.active { display: flex; }
#thoughts-view.hidden { display: none; }

.dream-list { flex: 0 0 260px; border-right: 1px solid #2a2a38; overflow-y: auto; background: #111118; }
.dream-run { padding: 10px 14px; border-bottom: 1px solid #1a1a22; cursor: pointer; transition: background 0.1s; }
.dream-run:hover { background: #18182a; }
.dream-run.active { background: #1c1c38; }
.dream-run-date { font-size: 13px; font-weight: 600; color: #8080b0; }
.dream-run-stats { font-size: 10px; color: #444; margin-top: 3px; display: flex; gap: 8px; flex-wrap: wrap; }
.dream-run-stat { display: flex; align-items: center; gap: 3px; }

.dream-detail { flex: 1; overflow-y: auto; padding: 0; }
.dream-detail-empty { color: #2a2a40; font-size: 12px; padding: 20px; }

.dream-summary { display: flex; gap: 16px; flex-wrap: wrap; padding: 14px 20px; background: #14141c; border-bottom: 1px solid #2a2a38; }
.dream-stat-card { background: #1a1a28; border: 1px solid #2a2a38; border-radius: 8px; padding: 10px 16px; min-width: 90px; text-align: center; }
.dream-stat-val { font-size: 20px; font-weight: 700; color: #8080b0; }
.dream-stat-label { font-size: 9px; color: #444; margin-top: 2px; text-transform: uppercase; letter-spacing: 0.05em; }

.dream-sections { padding: 10px 20px 30px; }
.dream-section { margin-bottom: 18px; }
.dream-section-title { font-size: 13px; font-weight: 600; color: #6060a0; margin-bottom: 6px; padding-bottom: 4px; border-bottom: 1px solid #1e1e2e; }
.dream-subsection-title { font-size: 11px; font-weight: 600; color: #555; margin: 10px 0 4px; }
.dream-line { font-size: 11.5px; line-height: 1.6; color: #999; padding: 1px 0; }
.dream-line strong, .dream-line b { color: #b0b0d0; }
.dream-line-delete { color: #cc6666; }
.dream-line-augment { color: #66aa88; }
.dream-line-insight { color: #cc9944; }
.dream-line-keep { color: #7788aa; }

/* ── Dreaming cards ── */
.dream-card { background: #14141c; border: 1px solid #20202e; border-left: 3px solid #2a2a40; border-radius: 4px; padding: 8px 12px; margin-bottom: 6px; font-size: 12px; color: #b0b0c0; }
.dream-card .dc-head { display: flex; align-items: center; gap: 6px; margin-bottom: 4px; flex-wrap: wrap; }
.dream-card .dc-tag { font-size: 9px; text-transform: uppercase; letter-spacing: 0.05em; color: #666; font-weight: 600; background: #1a1a24; padding: 2px 6px; border-radius: 3px; }
.dream-card .dc-body { font-size: 12.5px; line-height: 1.5; color: #c8c8d8; }
.dream-card .dc-sub { font-size: 11px; line-height: 1.5; color: #888; margin-top: 3px; }
.dream-card .dc-label { color: #555; text-transform: uppercase; letter-spacing: 0.04em; font-size: 9px; margin-right: 4px; }
.dream-card .dc-muted { color: #666; font-style: italic; }
.dream-card .dc-reason { font-size: 11px; line-height: 1.5; color: #888; margin-top: 4px; font-style: italic; }
.dream-card .dc-strike { text-decoration: line-through; text-decoration-color: #cc6666; text-decoration-thickness: 1px; color: #8a8a96; }

.dream-card.dc-merged { border-left-color: #66aa88; }
.dream-card.dc-deleted { border-left-color: #cc6666; }
.dream-card.dc-created { border-left-color: #cc9944; }
.dream-card.dc-mem-add { border-left-color: #5588cc; }
.dream-card.dc-mem-remove { border-left-color: #cc6666; }
.dream-card.dc-other { border-left-color: #3a3a4e; }

.dream-card .dc-link { color: #8a8ad0; text-decoration: none; font-family: 'SF Mono', Menlo, monospace; font-size: 10.5px; background: #1a1a30; padding: 1px 5px; border-radius: 3px; cursor: pointer; }
.dream-card .dc-link:hover { color: #b0b0ff; background: #24243a; }
.dream-card .dc-link-gone { color: #555 !important; background: #18181f !important; text-decoration: line-through; cursor: default; }

.dream-card .dc-badge { font-size: 9px; text-transform: uppercase; letter-spacing: 0.04em; color: #888; background: #1e1e2c; padding: 2px 6px; border-radius: 3px; }
.dream-card .dc-badge-urgent, .dream-card .dc-badge-high { color: #d0a060; background: #2a1e14; }

.dream-other { margin-top: 20px; }
.dream-other > summary { cursor: pointer; list-style: none; }
.dream-other > summary::-webkit-details-marker { display: none; }
.dream-other > summary::before { content: "▸ "; color: #555; }
.dream-other[open] > summary::before { content: "▾ "; }
.dream-other .dc-badge { margin-left: 4px; }

/* ── Context menu ── */
#ctx-menu { position: fixed; background: #1a1a28; border: 1px solid #3a3a50; border-radius: 6px; padding: 4px 0; z-index: 300; display: none; box-shadow: 0 6px 20px rgba(0,0,0,0.7); min-width: 200px; }
#ctx-menu .ctx-item { padding: 8px 16px; font-size: 13px; color: #ccc; cursor: pointer; transition: background 0.1s; }
#ctx-menu .ctx-item:hover { background: #2a2a40; color: #e0e0f0; }

/* ── Mobile back button (hidden on desktop) ── */
#btn-mobile-back { display: none; }

::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #252535; border-radius: 2px; }

/* ── Mobile responsive ── */
@media (max-width: 768px) {
  header { padding: 6px 10px; gap: 8px; }
  header h1 { font-size: 13px; }
  .tab-bar { margin-left: 8px; }
  .tab-btn { padding: 4px 10px; font-size: 10px; }
  .stat { display: none; }

  #demo-banner { font-size: 11px; padding: 5px 10px; }

  /* Thoughts view: stack vertically, list takes full width */
  #thoughts-view { flex-direction: column; }
  #thoughts-view .list-panel { flex: 1; border-right: none; }
  #thoughts-view .right-panel { display: none; position: absolute; top: 0; left: 0; right: 0; bottom: 0; z-index: 100; background: #0f0f13; }

  /* When graph is active on mobile, show it full screen */
  #thoughts-view.mobile-graph .list-panel { display: none; }
  #thoughts-view.mobile-graph .right-panel { display: flex; position: relative; flex: 1; }

  /* Show back button on mobile */
  #thoughts-view.mobile-graph #btn-mobile-back { display: flex; }

  /* Node card adjustments for mobile */
  .nc-text { max-height: 140px; }

  /* Settings: less padding on mobile */
  #settings-view { padding: 16px 16px; }
  .settings-group { max-width: 100%; }

  /* Dreaming: stack on mobile */
  #dreaming-view { flex-direction: column; }
  .dream-list { flex: 0 0 auto; max-height: 200px; border-right: none; border-bottom: 1px solid #2a2a38; }
  .dream-detail { flex: 1; }

  /* Wider touch targets for list rows */
  td { padding: 8px 10px; }
  .td-title { font-size: 13px; }
}
