/* Brain map: a flat map of notes, tasks and memories. Follows the app theme (light by default); floating
   panels are plain Material surfaces (no glass, no glow). */
.brain-page {
  --b-glass: var(--surface); --b-glass-2: var(--surface); --b-line: var(--border);
  --b-text: var(--text); --b-text-2: var(--text-2); --b-faint: var(--muted); --b-accent: var(--accent);
  --b-hover: color-mix(in srgb, var(--text) 8%, transparent); --b-tint: color-mix(in srgb, var(--text) 4%, transparent);
  position: relative; height: 100%; overflow: hidden; color: var(--b-text); isolation: isolate;
  background: var(--bg);
}
.brain-page .faint { color: var(--b-faint); }
.brain-page .muted { color: var(--b-text-2); }
.brain-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
/* Flat like the calm-look neurons they stand for (a key shouldn't glow). */
.brain-page .dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }

/* Glass building blocks */
.brain-toolbar, .brain-legend, .brain-panel, .brain-ask, .brain-time, .brain-answer, .brain-tip, .brain-results {
  background: var(--b-glass); border: 1px solid var(--b-line); box-shadow: var(--shadow-2);
}
.brain-page button:not(.primary) { color: var(--b-text); }
.brain-page button.primary { color: var(--accent-fg); }
.brain-page .ghost:hover, .brain-page .icon-btn:hover { background: var(--b-hover); }
.brain-page input[type="search"], .brain-page input[type="text"] { background: var(--surface-2); border-color: transparent; color: var(--b-text); }
.brain-page input::placeholder { color: var(--b-faint); }

/* Toolbar */
.brain-toolbar { position: absolute; top: 12px; left: 12px; right: 12px; display: flex; align-items: center; gap: 10px; padding: 6px 8px 6px 16px; border-radius: var(--r-full); z-index: 3; }
.brain-brand { display: flex; align-items: center; gap: 8px; min-width: 0; }
.brain-brand .icon { color: var(--b-accent); }
.brain-brand strong { font-family: var(--font-display); white-space: nowrap; }
.brain-stats { font-size: 12px; color: var(--b-text-2); white-space: nowrap; }
.brain-search-wrap { position: relative; flex: 1; max-width: 360px; margin-left: auto; display: flex; align-items: center; }
.brain-search-wrap > .icon { position: absolute; left: 10px; color: var(--b-faint); pointer-events: none; }
.brain-search { padding-left: 36px; height: 36px; border-radius: var(--r-full); }
.brain-results { position: absolute; top: calc(100% + 6px); left: 0; right: 0; border-radius: var(--r-sm); padding: 6px 0; display: flex; flex-direction: column; z-index: 5; }
.brain-results button { display: flex; align-items: center; gap: 10px; height: 38px; padding: 0 14px; background: none; border: 0; border-radius: 0; text-align: left; justify-content: flex-start; }
.brain-results button:hover, .brain-results button.active { background: var(--b-hover); }
.brain-results p { margin: 8px; }
.brain-seg { display: flex; background: transparent; border: 1px solid var(--border-strong); border-radius: var(--r-full); padding: 0; overflow: hidden; }
.brain-seg button { height: 32px; padding: 0 14px; border: 0; background: none; border-radius: 0; font-size: 13px; color: var(--b-text) !important; }
.brain-seg button + button { border-left: 1px solid var(--border-strong); }
.brain-seg button[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent-text) !important; }
.brain-chip { display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 12px; border-radius: var(--r-sm); border: 1px solid transparent; background: var(--accent-soft); color: var(--accent-text) !important; font-size: 13px; white-space: nowrap; }
.brain-chip.off { border-color: var(--border-strong); background: transparent; color: var(--b-text-2) !important; }
.brain-hint { position: absolute; top: 64px; right: 16px; display: flex; flex-direction: column; align-items: flex-end; gap: 2px; font-size: 11px; color: var(--b-faint); pointer-events: none; z-index: 1; }

/* Legend */
.brain-legend { position: absolute; left: 12px; bottom: 76px; width: 230px; max-height: 40vh; overflow: auto; border-radius: var(--r); padding: 10px; z-index: 2; }
.brain-legend-head { justify-content: space-between; font-size: 12px; font-weight: 500; letter-spacing: .02em; color: var(--b-text-2); padding: 0 4px 6px; }
.brain-legend ul { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 2px 6px; }
.brain-legend button { display: flex; align-items: center; gap: 7px; width: 100%; height: 26px; padding: 0 6px; border: 0; background: none; border-radius: 7px; font-size: 12px; text-align: left; justify-content: flex-start; }
.brain-legend button:hover:not(:disabled) { background: var(--b-hover); }
.brain-legend button.off { opacity: 0.4; }
.brain-legend button .faint { margin-left: auto; font-size: 11px; }
.brain-legend button:disabled { opacity: 1; cursor: default; }

/* Hover tooltip */
.brain-tip { position: absolute; z-index: 6; display: flex; align-items: center; gap: 8px; padding: 6px 10px; border-radius: var(--r-sm); font-size: 12px; pointer-events: none; max-width: 320px; }
.brain-tip strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Detail panel */
.brain-panel { position: absolute; top: 72px; right: 12px; bottom: 76px; width: 360px; border-radius: var(--r-lg); padding: 14px 16px; overflow: auto; z-index: 3; display: flex; flex-direction: column; gap: 10px; animation: brain-in .22s var(--ease); }
@keyframes brain-in { from { opacity: 0; transform: translateX(12px); } }
.brain-panel-head { display: flex; align-items: center; gap: 8px; }
.brain-type { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 500; letter-spacing: .02em; color: var(--c); }
.brain-panel-title { font-size: 20px; font-weight: 400; line-height: 1.3; margin: 0; overflow-wrap: anywhere; }
.brain-topic-chip { align-self: flex-start; display: inline-flex; align-items: center; gap: 4px; height: 26px; padding: 0 10px; border-radius: var(--r-sm); font-size: 12px; background: color-mix(in srgb, var(--c) 14%, transparent); border: 0; }
.brain-actions { gap: 6px; }
.brain-actions button[aria-pressed="true"] { background: var(--accent-soft); border-color: transparent; color: var(--accent-text); }
.brain-md { font-size: 13px; color: var(--b-text-2); max-height: 220px; overflow: auto; padding: 10px 12px; border-radius: var(--r-sm); background: var(--surface-2); }
.brain-md img { max-width: 100%; border-radius: 6px; }
.brain-conns { display: flex; flex-direction: column; gap: 10px; }
.brain-conn h4 { font-size: 12px; font-weight: 500; letter-spacing: .02em; color: var(--b-faint); margin: 0 0 4px; }
.brain-conn ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.brain-conn-row { display: flex; align-items: center; gap: 4px; }
.brain-conn-row .mini-item { display: flex; align-items: center; gap: 8px; min-width: 0; height: 32px; padding: 0 10px; border: 0; background: none; border-radius: var(--r-full); text-align: left; justify-content: flex-start; font-size: 13px; }
.brain-conn-row .mini-item:hover { background: var(--b-hover); }
.brain-strength { width: 44px; height: 4px; border-radius: 4px; background: var(--surface-3); flex: none; overflow: hidden; }
.brain-strength i { display: block; height: 100%; background: var(--accent); border-radius: 4px; }
.brain-conn-row .icon-btn { width: 26px; height: 26px; }

/* Bottom: answer, ask, time travel */
.brain-bottom { position: absolute; left: 50%; bottom: 12px; transform: translateX(-50%); width: min(720px, calc(100% - 24px)); display: flex; flex-direction: column; gap: 8px; z-index: 4; }
.brain-ask { display: flex; align-items: center; gap: 8px; padding: 6px 6px 6px 16px; border-radius: var(--r-full); }
.brain-ask > .icon { color: var(--b-accent); }
.brain-ask input { border: 0; background: transparent !important; height: 34px; padding: 0; }
.brain-ask input:focus { box-shadow: none; }
.brain-answer { border-radius: var(--r-lg); padding: 12px 16px; max-height: 30vh; overflow: auto; animation: brain-up .25s var(--ease); }
@keyframes brain-up { from { opacity: 0; transform: translateY(8px); } }
.brain-answer-head { gap: 8px; margin-bottom: 6px; }
.brain-answer-head .icon { color: var(--b-accent); }
.brain-answer .md { font-size: 14px; }
.brain-answer sup { color: var(--b-accent); font-weight: 600; }
.brain-path { gap: 6px; margin-top: 10px; padding-top: 8px; border-top: 1px solid var(--b-line); }
.brain-path .chip-btn { background: var(--surface-2); border-color: transparent; max-width: 200px; }
.brain-time { display: flex; align-items: center; gap: 10px; padding: 4px 14px 4px 8px; border-radius: var(--r-full); font-size: 12px; color: var(--b-text-2); }
.brain-time input[type="range"] { flex: 1; accent-color: var(--b-accent); height: 20px; padding: 0; background: none; border: 0; }
.brain-time-label { min-width: 88px; text-align: right; font-variant-numeric: tabular-nums; }
.brain-toggle { display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; cursor: pointer; }
.brain-toggle input { width: auto; height: auto; accent-color: var(--b-accent); }

/* Options popover (rendered outside the page, in the popover layer) */
.brain-pop { background: var(--surface); color: var(--text); }
.brain-options { display: flex; flex-direction: column; gap: 4px; padding: 10px 12px; width: 260px; }
.brain-options h4 { font-size: 12px; font-weight: 500; letter-spacing: .02em; color: var(--muted); margin: 8px 0 2px; }
.brain-options h4:first-child { margin-top: 0; }
.brain-opt { display: flex; align-items: center; gap: 8px; font-size: 13px; cursor: pointer; padding: 3px 0; }
.brain-opt.col { flex-direction: column; align-items: stretch; gap: 4px; }
.brain-opt input[type="checkbox"] { width: auto; height: auto; accent-color: var(--accent); }
.brain-opt input[type="range"] { accent-color: var(--accent); padding: 0; height: 20px; background: none; border: 0; }
.brain-opt small { display: block; font-size: 11px; }
.brain-opt .dot { width: 9px; height: 9px; border-radius: 50%; }

/* Insights popover: hubs and surprising connections */
.brain-insights { display: flex; flex-direction: column; gap: 2px; padding: 10px 12px; width: 300px; max-height: 70vh; overflow: auto; }
.brain-insights h4 { display: flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 500; letter-spacing: .02em; color: var(--text-2); margin: 10px 0 0; }
.brain-insights h4:first-child { margin-top: 0; }
.brain-insights > p { margin: 0 0 4px; font-size: 12px; color: var(--muted); }
.brain-insights ol { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.brain-insights button { display: flex; align-items: center; gap: 8px; width: 100%; height: auto; min-height: 30px; padding: 4px 6px; border: 0; border-radius: 8px; background: none; color: inherit; font-size: 13px; font-weight: 500; text-align: left; cursor: pointer; }
.brain-insights button:hover, .brain-insights button:focus-visible { background: color-mix(in srgb, var(--text) 8%, transparent); }
.brain-insights .dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.brain-insights .faint { font-size: 12px; color: var(--muted); flex: none; }
.brain-insights .brain-ins-pair { flex-direction: column; align-items: stretch; gap: 1px; padding: 6px; }
.brain-insights .brain-ins-pair .row { gap: 8px; min-width: 0; }
.brain-insights .brain-ins-pair small { padding-left: 17px; font-size: 11.5px; color: var(--muted); }
.brain-ins-empty { margin: 2px 0 4px; font-size: 12px; color: var(--muted); }
.brain-types { display: grid; grid-template-columns: 1fr 1fr; }

/* Full screen: the brain takes the whole window */
.app.brain-immersive { --sidebar-w: 0px; }
.app.brain-immersive .sidebar { visibility: hidden; }
.app.brain-immersive .topbar { display: none; }

/* Overview card on Today */
.brain-card { height: auto; min-height: 190px; white-space: normal; padding: 0; overflow: hidden; position: relative; border: 1px solid var(--border); border-radius: var(--r);  color: var(--text); cursor: pointer; display: block; width: 100%; text-align: left; }
.brain-card, .brain-card:hover { background: var(--bg); }
.brain-card canvas { display: block; width: 100%; height: 190px; }
.brain-card-foot { position: absolute; left: 0; right: 0; bottom: 0; display: flex; align-items: center; gap: 8px; padding: 8px 12px; background: var(--surface); border-top: 1px solid var(--border); font-size: 12px; }
.brain-card-foot .icon { color: var(--accent); }
.brain-card-foot strong { font-size: 13px; font-weight: 500; }
.brain-card-foot .faint { color: var(--muted); }
.brain-card:hover { border-color: var(--border-strong); }
.brain-card:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

@media (max-width: 900px) {
  .brain-toolbar { flex-wrap: wrap; border-radius: var(--r-lg); padding: 8px 10px; }
  .brain-search-wrap { order: 5; max-width: none; flex-basis: 100%; }
  .brain-stats, .brain-hint { display: none; }
  .brain-legend { display: none; }
  .brain-panel { top: auto; left: 8px; right: 8px; bottom: 120px; width: auto; max-height: 50vh; }
  .brain-bottom { width: calc(100% - 16px); bottom: 8px; }
}
@media (prefers-reduced-motion: reduce) {
  .brain-panel, .brain-answer { animation: none; }
}

/* The app header already names the page; the toolbar brand only matters in full screen. */
.app:not(.brain-immersive) .brain-brand > strong, .app:not(.brain-immersive) .brain-brand > .icon { display: none; }
.brain-legend ul.one-col { grid-template-columns: 1fr; }
.brain-legend { overflow-x: hidden; }
