/* The Brain UI — dark-first, responsive, no framework.
   Mobile-first layout collapses the tabs to a horizontal scroller; desktop gets a
   single-column comfortable width. The note drawer slides in from the right on
   desktop, full-screen on phones. */

:root {
  --bg: #0e1116;
  --bg-2: #161b22;
  --bg-3: #1f2630;
  --fg: #e6edf3;
  --fg-mute: #9aa4ad;
  --accent: #6cb6ff;
  --accent-2: #56d364;
  --warn: #f0b057;
  --bad: #ff7b72;
  --border: #2a313c;
  --radius: 8px;
  --shadow: 0 6px 28px rgba(0, 0, 0, 0.4);
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue',
    Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f6f8fa; --bg-2: #ffffff; --bg-3: #eef1f5;
    --fg: #0e1116; --fg-mute: #57606a; --border: #d0d7de;
    --accent: #0969da; --accent-2: #1a7f37; --shadow: 0 4px 14px rgba(0,0,0,.06);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--fg);
  font-family: var(--font); font-size: 15px; line-height: 1.45; }
body { min-height: 100vh; display: flex; flex-direction: column; }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code, pre { font-family: var(--mono); background: var(--bg-3); padding: 1px 5px;
  border-radius: 4px; font-size: 13px; }
pre { padding: 10px 12px; overflow-x: auto; }

.muted { color: var(--fg-mute); }
.small { font-size: 13px; }
.grow { flex: 1; }

button, input, select, textarea {
  font: inherit; color: inherit;
  background: var(--bg-2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 8px 12px;
}
button { cursor: pointer; background: var(--accent); color: #001020;
  border-color: var(--accent); font-weight: 600; }
button.ghost { background: transparent; color: var(--fg); border-color: var(--border); font-weight: 400; }
button:hover { filter: brightness(1.08); }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
textarea { width: 100%; min-height: 120px; resize: vertical; font-family: var(--mono); font-size: 13.5px; }
label { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; font-size: 13px; color: var(--fg-mute); }
label input { color: var(--fg); }
.hint { color: var(--fg-mute); margin-top: 2px; }

.topbar {
  display: flex; align-items: center; gap: 12px; padding: 10px 16px;
  background: var(--bg-2); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 5;
}
.brand { display: flex; align-items: center; gap: 8px; }
.brand strong { font-size: 16px; letter-spacing: -.01em; }
.brand .dot { width: 10px; height: 10px; background: var(--accent-2);
  border-radius: 50%; box-shadow: 0 0 12px var(--accent-2); }

main {
  flex: 1; width: 100%; max-width: 960px; margin: 0 auto;
  padding: 14px 16px 80px; position: relative;
}

.tabs {
  display: flex; gap: 4px; overflow-x: auto;
  border-bottom: 1px solid var(--border); margin-bottom: 16px;
  scrollbar-width: thin;
}
.tab {
  background: transparent; border: 0; border-radius: 0;
  padding: 10px 14px; color: var(--fg-mute); font-weight: 600;
  border-bottom: 2px solid transparent; white-space: nowrap;
}
.tab.active { color: var(--fg); border-bottom-color: var(--accent); }

.pane { display: none; }
.pane.active { display: block; }

.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.right { justify-content: flex-end; }
.stack { display: flex; flex-direction: column; gap: 10px; }
form .row input[type="search"], form .row input[type="text"] { flex: 1 1 220px; }

.results { margin-top: 16px; display: flex; flex-direction: column; gap: 10px; }
.hit {
  padding: 12px 14px; background: var(--bg-2); border: 1px solid var(--border);
  border-radius: var(--radius); cursor: pointer; transition: border-color .12s ease;
}
.hit:hover { border-color: var(--accent); }
.hit-title { font-weight: 600; margin-bottom: 4px; }
.hit-meta { font-size: 12px; color: var(--fg-mute); margin-bottom: 6px; }
.hit-snippet { font-size: 13.5px; color: var(--fg); }
.hit-snippet :is(mark, .match) { background: rgba(108, 182, 255, .22); border-radius: 3px; padding: 0 2px; }
.badge { display: inline-block; padding: 1px 7px; border-radius: 999px;
  background: var(--bg-3); font-size: 11px; color: var(--fg-mute); margin-right: 4px; }
.badge.decision { background: rgba(240, 176, 87, .15); color: var(--warn); }
.badge.knowledge { background: rgba(86, 211, 100, .15); color: var(--accent-2); }
.badge.journal { background: rgba(154, 164, 173, .15); }
.badge.project { background: rgba(108, 182, 255, .15); color: var(--accent); }

.note-view { background: var(--bg-2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px; white-space: pre-wrap;
  font-family: var(--mono); font-size: 13.5px; }
.note-view h1, .note-view h2, .note-view h3 { font-family: var(--font); margin: 0 0 8px; }

.summary { background: var(--bg-3); border-left: 3px solid var(--accent);
  padding: 10px 12px; border-radius: 4px; }
.summary .row-line { margin: 2px 0; }
.summary .added { color: var(--accent-2); }
.summary .updated { color: var(--accent); }
.summary .superseded { color: var(--warn); }
.summary .linked { color: var(--fg-mute); }

.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(520px, 100vw);
  background: var(--bg-2); border-left: 1px solid var(--border);
  box-shadow: var(--shadow); transform: translateX(100%);
  transition: transform .2s ease; display: flex; flex-direction: column;
  z-index: 6;
}
.drawer.open { transform: translateX(0); }
.drawer-head { display: flex; align-items: center; gap: 8px;
  padding: 12px 14px; border-bottom: 1px solid var(--border); }
.drawer-head h3 { margin: 0; flex: 1; font-size: 15px; }
.drawer > .note-view { flex: 1; overflow: auto; border: 0; border-radius: 0; }

.status {
  position: fixed; bottom: 0; left: 0; right: 0; display: flex; gap: 10px;
  padding: 6px 14px; background: var(--bg-2); border-top: 1px solid var(--border);
  font-size: 12px; align-items: center;
}
#connState::before { content: '●'; margin-right: 4px; color: var(--bad); }
#connState.connected::before { color: var(--accent-2); }

dialog { background: var(--bg-2); color: var(--fg); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 22px;
  max-width: 440px; width: 92vw; }
dialog::backdrop { background: rgba(0, 0, 0, .5); backdrop-filter: blur(2px); }
dialog h2 { margin: 0 0 6px; }

@media (max-width: 640px) {
  main { padding: 10px 10px 80px; }
  .topbar { padding: 8px 10px; }
  form .row input { width: 100%; flex: 1 1 100%; }
  .row.right button { width: 100%; }
}
