/* CSS Variables */
:root {
  --bg-dark: #000040;
  --bg-darker: #000030;
  --bg-card: #000050;
  --text-primary: #ffffff;
  --text-secondary: #a0a0b8;
  --text-muted: #6b6b7f;
  --accent-blue: #578cff;
  --accent-cyan: #00d4ff;
  --accent-purple: #a855f7;
  --border-subtle: rgba(255, 255, 255, 0.08);
  --gradient-primary: linear-gradient(135deg, #578cff 0%, #a855f7 100%);
}

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

html {
  scroll-behavior: smooth;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Inter', 'Roboto', sans-serif;
  background: var(--bg-dark);
  color: var(--text-primary);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
  margin: 0;
  width: 80%;
  padding: 2rem 3rem;
}

/* Layout */
.iframe-container {
  position: fixed;
  top: 0;
  right: 0;
  width: 20%;
  height: 100vh;
  box-sizing: border-box;
  border-left: 1px solid var(--border-subtle);
  background: rgba(0, 0, 0, 0.3);
  backdrop-filter: blur(10px);
}

iframe {
  width: 100%;
  height: 100%;
  border: none;
}

.content {
  margin-right: 20%;
  padding: 20px;
  box-sizing: border-box;
}

/* Typography */
h1 {
  font-size: clamp(2rem, 4vw, 3rem);
  font-weight: 800;
  margin-bottom: 1.5rem;
  letter-spacing: -0.02em;
  color: var(--text-primary);
  line-height: 1.2;
  background: linear-gradient(135deg, var(--accent-cyan) 0%, var(--accent-purple) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

h1 a {
  color: var(--accent-purple);
  -webkit-text-fill-color: var(--accent-purple);
}

h2 {
  font-size: clamp(1.5rem, 3vw, 2rem);
  font-weight: 700;
  margin: 2rem 0 1rem 0;
  color: var(--text-primary);
  letter-spacing: -0.01em;
  border-bottom: 1px solid var(--border-subtle);
  padding-bottom: 0.5rem;
}

h3 {
  font-size: 1.25rem;
  font-weight: 700;
  margin: 1.5rem 0 0.75rem 0;
  color: var(--text-primary);
}

p {
  color: var(--text-secondary);
  line-height: 1.8;
  margin-bottom: 1rem;
  font-size: 1rem;
}

/* Links */
a {
  color: var(--accent-cyan);
  text-decoration: none;
  transition: all 0.3s ease;
  position: relative;
  border-bottom: 1px solid transparent;
}

a:hover {
  color: var(--accent-purple);
  border-bottom-color: var(--accent-purple);
}

a:visited {
  color: var(--accent-blue);
}

/* Lists */
ul, ol {
  color: var(--text-secondary);
  margin: 1rem 0 1rem 2rem;
  line-height: 1.8;
}

li {
  color: var(--text-secondary);
  margin-bottom: 0.5rem;
}

li::marker {
  color: var(--accent-cyan);
}

/* Code blocks */
code {
  font-family: 'Courier New', monospace;
  background: rgba(87, 140, 255, 0.1);
  border: 1px solid rgba(87, 140, 255, 0.2);
  border-radius: 4px;
  padding: 0.2rem 0.4rem;
  font-size: 0.9em;
  color: var(--accent-cyan);
}

pre {
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.05) 0%, rgba(255, 255, 255, 0.02) 100%);
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  padding: 1.5rem;
  overflow-x: auto;
  margin: 1.5rem 0;
  line-height: 1.5;
}

pre code {
  background: none;
  border: none;
  padding: 0;
  color: var(--text-primary);
}

/* Blockquotes */
blockquote {
  border-left: 3px solid var(--accent-purple);
  padding-left: 1.5rem;
  margin: 1.5rem 0;
  color: var(--text-secondary);
  font-style: italic;
  background: rgba(168, 85, 247, 0.05);
  padding: 1rem 1.5rem;
  border-radius: 0 8px 8px 0;
}

/* Tables */
table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.5rem 0;
  background: rgba(255, 255, 255, 0.02);
  border-radius: 12px;
  overflow: hidden;
}

th, td {
  padding: 1rem;
  text-align: left;
  border-bottom: 1px solid var(--border-subtle);
}

th {
  background: rgba(87, 140, 255, 0.1);
  color: var(--text-primary);
  font-weight: 600;
}

td {
  color: var(--text-secondary);
}

tr:last-child td {
  border-bottom: none;
}

tr:hover {
  background: rgba(87, 140, 255, 0.05);
}

/* Images */
img {
  max-width: 100%;
  height: auto;
  border-radius: 12px;
  margin: 1.5rem 0;
  border: 1px solid var(--border-subtle);
}

/* Horizontal rule */
hr {
  border: none;
  border-top: 1px solid var(--border-subtle);
  margin: 2rem 0;
}

/* Form */
form {
  margin-top: 2rem;
  padding: 1.5rem;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.05) 0%, rgba(255, 255, 255, 0.02) 100%);
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
}

input[type="text"] {
  background-color: rgba(0, 0, 0, 0.5);
  color: var(--text-primary);
  border: 1px solid var(--border-subtle);
  padding: 0.875rem 1.25rem;
  width: 100%;
  max-width: 400px;
  border-radius: 8px;
  font-size: 1rem;
  transition: all 0.3s ease;
  font-family: inherit;
}

input[type="text"]:focus {
  outline: none;
  border-color: var(--accent-blue);
  box-shadow: 0 0 0 3px rgba(87, 140, 255, 0.1);
}

input[type="submit"] {
  background: var(--gradient-primary);
  color: white;
  border: none;
  padding: 0.875rem 2rem;
  cursor: pointer;
  border-radius: 8px;
  font-weight: 600;
  font-size: 1rem;
  transition: all 0.3s ease;
  margin-left: 0.5rem;
}

input[type="submit"]:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(87, 140, 255, 0.4);
}

/* Scrollbar */
::-webkit-scrollbar {
  width: 10px;
  background-color: var(--bg-dark);
}

::-webkit-scrollbar-thumb {
  background: var(--gradient-primary);
  border-radius: 5px;
  border: 2px solid var(--bg-dark);
}

::-webkit-scrollbar-thumb:hover {
  background: linear-gradient(135deg, #6a9cff 0%, #b965ff 100%);
}

/* Navigation */
.navbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1000;
  background: rgba(0, 0, 48, 0.95);
  backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border-subtle);
  padding: 1rem 0;
  transition: all 0.3s ease;
}

.nav-container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 2rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.nav-logo {
  font-size: 1.5rem;
  font-weight: 700;
  background: var(--gradient-primary);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  text-decoration: none;
  transition: opacity 0.3s ease;
  border-bottom: none !important;
}

.nav-logo:hover {
  opacity: 0.8;
}

.nav-subdomain {
  font-weight: 400;
  color: var(--accent-purple);
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 2rem;
}

.nav-link {
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.95rem;
  font-weight: 500;
  transition: color 0.3s ease;
  position: relative;
  border-bottom: none !important;
}

.nav-link:hover {
  color: var(--text-primary);
  border-bottom: none !important;
}

.nav-link::after {
  content: '';
  position: absolute;
  bottom: -4px;
  left: 0;
  width: 0;
  height: 2px;
  background: var(--gradient-primary);
  transition: width 0.3s ease;
}

.nav-link:hover::after {
  width: 100%;
}

/* Main Content */
.main-content {
  margin-top: 80px;
  min-height: calc(100vh - 80px);
}

/* Search Container — sits in the header bar between the logo and the nav links */
.search-container {
  position: relative;
  flex: 1 1 auto;
  max-width: 560px;
  margin: 0 1.5rem;
}

/* Neutralize the global form card styling (meant for the old bottom search box) */
.search-container form {
  margin: 0;
  padding: 0;
  background: none;
  border: none;
  border-radius: 0;
}

/* The omnibox input fills its header slot (overrides the global 400px-capped input) */
.search-container input[type="text"] {
  max-width: none;
  width: 100%;
  padding: 0.5rem 1rem;
  border-radius: 999px;
  font-size: 0.95rem;
  background-color: rgba(0, 0, 0, 0.35);
}

/* Terminal — the ask/search box that lives at the very end of the document. Press Esc to
   focus it; plain text asks Cohere about the page and answers stream into .terminal-log. */
.terminal {
  margin-top: 4rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border-subtle);
}

.terminal-log {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}
.terminal-log:not(:empty) {
  margin-bottom: 1.5rem;
}

.term-q {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color: var(--accent-cyan);
  font-size: 0.95rem;
  margin-bottom: 0.5rem;
  white-space: pre-wrap;
  word-break: break-word;
}
.term-q::before {
  content: "\276F  ";
  color: var(--accent-purple);
}

.term-a {
  color: var(--text-primary);
  line-height: 1.6;
}
.term-a.is-streaming {
  white-space: pre-wrap;
  word-break: break-word;
}
.term-a > :first-child { margin-top: 0; }
.term-a > :last-child { margin-bottom: 0; }
.term-a .term-cursor {
  display: inline-block;
  width: 0.55rem;
  height: 1.05rem;
  margin-left: 1px;
  vertical-align: text-bottom;
  background: var(--accent-cyan);
  animation: term-blink 1s steps(1) infinite;
}
@keyframes term-blink { 50% { opacity: 0; } }
.term-a.term-error { color: #ff8a8a; }

/* The terminal input spans the full content width (overrides the header-bar sizing) */
.terminal .search-container.terminal-input {
  max-width: 100%;
  margin: 0;
  flex: none;
}
.terminal-input input[type="text"] {
  padding: 0.8rem 1.2rem;
  font-size: 1rem;
}
/* At the bottom of the page the suggestions must open UPWARD, not off-screen */
.terminal .omnibox-dropdown {
  top: auto;
  bottom: calc(100% + 8px);
}

/* Responsive */
@media (max-width: 1024px) {
  body {
    width: 100%;
    padding: 1.5rem;
  }

  .iframe-container {
    display: none;
  }

  .content {
    margin-right: 0;
  }

  .nav-links {
    gap: 1.5rem;
  }

  .search-container {
    margin: 0 1rem;
  }

  .terminal .search-container.terminal-input {
    margin: 0;
  }
}

@media (max-width: 768px) {
  /* Drop the nav links on phones so the search box gets the full bar */
  .nav-links {
    display: none;
  }

  .nav-logo {
    font-size: 1.25rem;
  }

  .search-container {
    margin: 0 0 0 1rem;
  }

  .main-content {
    margin-top: 70px;
  }
}

/* Omnibox search dropdown — opens downward from the header bar */
.omnibox-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  right: 0;
  max-height: 60vh;
  overflow-y: auto;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
  padding: 6px;
  z-index: 1000;
}
.omnibox-dropdown[hidden] { display: none; }
.omnibox-item {
  display: block;
  padding: 8px 12px;
  border-radius: 8px;
  text-decoration: none;
  color: var(--text-primary);
  cursor: pointer;
}
.omnibox-item[aria-selected="true"] { background: rgba(87, 140, 255, 0.18); }
.omnibox-type, .omnibox-cmd {
  display: inline-block;
  min-width: 64px;
  margin-right: 8px;
  font-size: 0.7rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--accent-cyan);
}
.omnibox-cmd { color: var(--accent-purple); text-transform: none; font-weight: 600; }
.omnibox-name { font-weight: 600; }
.omnibox-label { color: var(--text-secondary); }
.omnibox-source { float: right; color: var(--text-muted); font-size: 0.7rem; }
.omnibox-snippet {
  display: block;
  margin-top: 2px;
  font-size: 0.8rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.omnibox-snippet mark {
  background: rgba(0, 212, 255, 0.25);
  color: var(--text-primary);
  padding: 0 2px;
  border-radius: 3px;
}

/* Query suggestions ("what others searched") */
.omnibox-suggest {
  display: flex;
  align-items: center;
  gap: 10px;
}
.omnibox-ic {
  width: 15px;
  height: 15px;
  flex: 0 0 auto;
  fill: none;
  stroke: var(--text-muted);
  stroke-width: 2;
  stroke-linecap: round;
}
.omnibox-sg { color: var(--text-primary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.omnibox-suggest[aria-selected="true"] .omnibox-ic { stroke: var(--accent-cyan); }
/* Section divider between suggestions and inline results */
.omnibox-group {
  padding: 6px 12px 2px;
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  border-top: 1px solid var(--border-subtle);
  margin-top: 4px;
}


/* ── Topic pages (docs/topic-pages.md): virtual + curated cross-vault views ────────── */
.topic { max-width: 760px; margin: 0 auto; }
.topic-header { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; border-bottom: 1px solid var(--border-subtle); padding-bottom: .5rem; margin-bottom: 1.25rem; }
.topic-title { margin: 0; font-size: 1.9rem; }
.topic-meta { display: flex; align-items: baseline; gap: .75rem; white-space: nowrap; }
.topic-kind { font-size: .75rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; }
.topic-edit { font-size: .8rem; color: var(--accent-cyan); text-decoration: none; }
.topic-edit:hover { text-decoration: underline; }
.topic-empty { color: var(--text-secondary); padding: 1.5rem 0; }
.topic-create { color: var(--accent-blue); text-decoration: none; }
.topic-prose { color: var(--text-primary); margin-bottom: 1.75rem; line-height: 1.6; }
.topic-section { margin: 1.5rem 0; }
.topic-section-title { font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--text-secondary); margin: 0 0 .6rem; }
.topic-live { color: var(--accent-purple); font-weight: 400; }
.topic-list { list-style: none; padding: 0; margin: 0; }
.topic-item { padding: .5rem 0; border-bottom: 1px solid var(--border-subtle); }
.topic-name { color: var(--accent-blue); text-decoration: none; font-weight: 600; }
.topic-name:hover { text-decoration: underline; }
.topic-name-dead { color: var(--text-muted); font-weight: 600; }
.topic-badge { margin-left: .5rem; font-size: .72rem; color: var(--text-muted); }
.topic-note { font-size: .85rem; color: var(--accent-cyan); margin-top: .15rem; font-style: italic; }
.topic-snippet { font-size: .85rem; color: var(--text-secondary); margin-top: .2rem; }
.topic-snippet mark { background: rgba(168, 85, 247, .35); color: var(--text-primary); padding: 0 .1em; border-radius: 2px; }
.topic-pinned .topic-item { border-left: 2px solid var(--accent-purple); padding-left: .6rem; }
.topic-dangling { opacity: .6; }
.topic-more { font-size: .8rem; color: var(--text-muted); margin-top: .6rem; }

/* ── Topic editor (docs/topic-pages.md §7: in-browser overlay editing) ─────────────── */
.topic-editor .topic-edit-help { font-size: .82rem; color: var(--text-secondary); margin: .25rem 0 1rem; }
.topic-edit-area { width: 100%; box-sizing: border-box; min-height: 22rem; padding: .75rem .9rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .85rem; line-height: 1.5;
  color: var(--text-primary); background: var(--bg-darker); border: 1px solid var(--border-subtle);
  border-radius: 6px; resize: vertical; }
.topic-edit-area:focus { outline: none; border-color: var(--accent-blue); }
.topic-edit-bar { display: flex; align-items: center; gap: .6rem; margin-top: .6rem; }
.topic-edit-token { padding: .45rem .6rem; font-size: .8rem; color: var(--text-primary);
  background: var(--bg-card); border: 1px solid var(--border-subtle); border-radius: 6px; width: 12rem; }
.topic-edit-save { padding: .45rem 1.1rem; font-size: .85rem; font-weight: 600; color: #fff;
  background: var(--gradient-primary); border: none; border-radius: 6px; cursor: pointer; }
.topic-edit-save:hover { filter: brightness(1.1); }
.topic-edit-cancel { font-size: .82rem; color: var(--text-muted); text-decoration: none; }
.topic-edit-msg { font-size: .82rem; color: var(--accent-cyan); }

/* Editor split-pane + live preview */
.topic-edit-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; align-items: start; }
.topic-edit-grid .topic-edit-area { min-height: 26rem; }
.topic-edit-preview-label { font-size: .8rem; text-transform: uppercase; letter-spacing: .06em;
  color: var(--text-secondary); margin: 0 0 .4rem; }
.topic-preview-pane { border: 1px solid var(--border-subtle); border-radius: 6px; padding: .75rem 1rem;
  min-height: 26rem; max-height: 42rem; overflow: auto; background: var(--bg-dark); }
.topic-preview-pane .topic { max-width: none; }
@media (max-width: 820px) { .topic-edit-grid { grid-template-columns: 1fr; } }

/* Page footer: provenance + edit/history/undo */
.page-footer { margin-top: 2rem; padding-top: .6rem; border-top: 1px solid var(--border-subtle);
  font-size: .8rem; color: var(--text-secondary); }
.page-footer a { color: inherit; text-decoration: underline; }
.page-footer-undo { background: none; border: 0; padding: 0; font: inherit; color: inherit;
  text-decoration: underline; cursor: pointer; }
