[hidden] { display: none !important; }

:root {
  --bg: #111318;
  --fg: #dde1ea;
  --muted: #72788a;
  --border: #252933;
  --accent: #7da8e0;
  --accent-soft: #1f2a3d;
  --accent-brand: #3f4756;
  --link: #8ec5ff;
  --link-hover: #b8dcff;
  --tag-bg: #243246;
  --tag-fg: #a8c5ec;
  --broken: #e07070;
  --code-bg: #1a1d26;
  --sidebar-bg: #0c0e14;
  --highlight: #252a38;
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
  --duration-base: 200ms;
  --ease-out: cubic-bezier(.16, 1, .3, 1);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font:
    16px/1.6 -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    Inter,
    sans-serif;
  background: var(--bg);
  color: var(--fg);
}

a {
  color: var(--link);
  text-decoration: none;
}
a:hover {
  color: var(--link-hover);
  text-decoration: underline;
}
a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 2px;
}

code {
  background: var(--code-bg);
  padding: 1px 5px;
  border-radius: 3px;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 0.92em;
}

pre {
  background: var(--code-bg);
  padding: 12px 14px;
  border-radius: 6px;
  overflow-x: auto;
}

pre code {
  background: none;
  padding: 0;
}

.skip-link {
  position: absolute;
  top: -40px;
  left: 0;
  background: var(--accent);
  color: white;
  padding: 8px;
  text-decoration: none;
  z-index: 100;
  border-radius: 0 0 4px 0;
}
.skip-link:focus {
  top: 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 20px;
  background: var(--sidebar-bg);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  font-weight: 700;
  font-size: 1.05em;
  color: var(--fg);
  display: flex;
  align-items: center;
  gap: 7px;
  letter-spacing: -0.01em;
}
.brand-icon {
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  object-fit: contain;
  display: block;
}
.brand:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 2px;
}

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

.btn {
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--fg);
  padding: 6px 14px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.9em;
  transition: background-color var(--duration-base) ease, border-color var(--duration-base) ease;
}
.btn:hover {
  background: var(--accent-soft);
}
.btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.btn.primary {
  background: var(--accent-brand);
  color: white;
  border-color: var(--accent-brand);
}
.btn.primary:hover {
  opacity: 0.9;
}
.btn.primary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.btn.ghost {
  background: transparent;
  border-color: transparent;
}
.btn.ghost:hover {
  background: var(--accent-soft);
  border-color: var(--border);
}
.btn.danger {
  background: var(--broken);
  color: #fff;
  border-color: var(--broken);
  font-weight: 600;
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.2);
}
.btn.danger:hover {
  background: #d05858;
  border-color: #d05858;
}
.btn-tiny {
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.95em;
  padding: 0 4px;
  transition: color var(--duration-base) ease;
}
.btn-tiny:hover {
  color: var(--accent);
}
.btn-tiny:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-radius: 2px;
}

.layout {
  display: grid;
  grid-template-columns: var(--col-sidebar, 240px) minmax(0, 1fr) var(--col-query, 320px);
  gap: 0;
  min-height: calc(100vh - 50px);
}

/* Secondary-page layout: sidebar + main only (settings, review, bookmarklet) */
.layout--secondary {
  display: grid;
  grid-template-columns: var(--col-sidebar, 240px) minmax(0, 1fr);
  min-height: calc(100vh - 50px);
}
.layout--secondary:has(.sidebar.collapsed) {
  grid-template-columns: 44px minmax(0, 1fr);
}
.layout--secondary > main {
  min-width: 0;
  overflow-x: hidden;
}

/* ── Sidebar shell ─────────────────────────────────── */
.sidebar {
  display: flex;
  flex-direction: column;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  font-size: 0.92em;
  position: sticky;
  top: 50px;
  height: calc(100vh - 50px);
  align-self: start;
  overflow: hidden;
}

/* Header: full width row, ghost icon + wordmark side by side */
.sidebar-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 14px 16px;
  border-bottom: 1px solid var(--border);
  text-decoration: none;
  color: var(--fg);
  flex-shrink: 0;
}
.sidebar-head:hover { color: var(--accent); text-decoration: none; }
.sidebar-head:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}
.head-logo {
  width: 28px;
  height: 28px;
  object-fit: contain;
  flex-shrink: 0;
  display: none; /* hidden when expanded — wordmark only */
}
.head-wordmark {
  font-size: 1.55em;
  font-weight: 800;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  line-height: 1;
}

/* Main row: icon-rail + sidebar-body */
.sidebar-main {
  display: flex;
  flex-direction: row;
  flex: 1;
  min-height: 0;
}

/* ── Icon rail (44 px wide, always visible) ─────────── */
.icon-rail {
  width: 44px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  background: var(--sidebar-bg);
  overflow: hidden;
}

.rail-top {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 10px 0 6px;
  gap: 4px;
}

.rail-bottom {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 6px 0 10px;
  gap: 4px;
  border-top: 1px solid var(--border);
}

.rail-btn,
.rail-link {
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  color: var(--muted);
  border-radius: 8px;
  cursor: pointer;
  text-decoration: none;
  transition: background-color 100ms ease, color 100ms ease;
  flex-shrink: 0;
}

.rail-btn:hover,
.rail-link:hover {
  background: var(--accent-soft);
  color: var(--accent);
  text-decoration: none;
}

.rail-btn[aria-pressed="true"] {
  background: var(--accent-soft);
  color: var(--accent);
}

.rail-link.active {
  color: var(--accent);
  background: var(--accent-soft);
}

.rail-btn:focus-visible,
.rail-link:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

/* ── Collapsible sidebar body ───────────────────────── */
.sidebar-body {
  flex: 1;
  min-width: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 12px 10px 0;
  display: flex;
  flex-direction: column;
}

/* Sibling-style sectioned nav links */
.nav-sections {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 4px 0 12px;
}
.nav-section {
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.nav-section-title {
  font-size: 0.7em;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--muted);
  font-weight: 700;
  padding: 0 8px 6px;
}
.nav-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 10px;
  font-size: 0.9em;
  color: var(--fg);
  text-decoration: none;
  border-radius: 6px;
  border: none;
  background: transparent;
  cursor: pointer;
  width: 100%;
  text-align: left;
  font-family: inherit;
  border-left: 2px solid transparent;
  transition: background-color 100ms ease, color 100ms ease, border-color 100ms ease;
}
.nav-link:hover {
  background: var(--accent-soft);
  color: var(--accent);
  text-decoration: none;
}
.nav-link.active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
  border-left-color: var(--accent);
}
.nav-link .ico { color: var(--muted); flex-shrink: 0; }
.nav-link.active .ico,
.nav-link:hover .ico { color: var(--accent); }
.nav-label {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.nav-count {
  font-size: 0.72em;
  font-weight: 600;
  color: var(--muted);
  background: var(--bg);
  border: 1px solid var(--border);
  padding: 1px 7px;
  border-radius: 9999px;
  font-feature-settings: "tnum";
  min-width: 22px;
  text-align: center;
  flex-shrink: 0;
}

/* Footer: full sidebar width, sticky bottom */
.sidebar-foot {
  flex-shrink: 0;
  padding: 10px 12px 14px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: var(--sidebar-bg);
}
.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 6px;
  border-radius: 999px;
  min-width: 0;
}
.user-avatar {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--accent);
  color: var(--sidebar-bg);
  font-size: 0.72em;
  font-weight: 700;
  letter-spacing: 0.04em;
}
.user-handle {
  font-size: 0.82em;
  color: var(--fg);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}
.sidebar-collapse {
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 0.78em;
  text-align: center;
  padding: 6px 6px;
  cursor: pointer;
  border-radius: 6px;
  transition: background-color 100ms ease, color 100ms ease;
}
.sidebar-collapse:hover { background: var(--accent-soft); color: var(--accent); }
.sidebar-collapse:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

/* Collapsed state: shrink to 44px icon rail only */
.sidebar.collapsed .sidebar-body { display: none; }
.sidebar.collapsed .head-wordmark { display: none; }
.sidebar.collapsed .head-logo {
  display: block;
}
.sidebar.collapsed .sidebar-head {
  justify-content: center;
  padding: 14px 0 16px;
  gap: 0;
}
.sidebar.collapsed .user-handle { display: none; }
.sidebar.collapsed .collapse-text { display: none; }
.sidebar.collapsed .sidebar-collapse::before {
  content: "»»";
  display: inline-block;
}
.sidebar.collapsed .sidebar-foot {
  padding: 10px 6px 14px;
  align-items: center;
}
.sidebar.collapsed .sidebar-user {
  padding: 4px 0;
  justify-content: center;
}
.sidebar.collapsed .resize-sidebar { display: none; }
.layout:has(.sidebar.collapsed) {
  grid-template-columns: 44px minmax(0, 1fr) var(--col-query, 320px);
}
@media (max-width: 1100px) {
  .layout:has(.sidebar.collapsed) {
    grid-template-columns: 44px 1fr;
  }
}

.sb-panel {
  display: flex;
  flex-direction: column;
}

.sb-panel-hdr {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 2px 4px 10px;
}

.sb-panel-title {
  font-size: 0.7em;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
  font-weight: 700;
}

.sb-panel-meta {
  font-size: 0.72em;
  color: var(--muted);
  font-feature-settings: "tnum";
}

.sidebar-search { margin: 0 0 12px; position: relative; }

.sidebar-search input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 7px 10px;
  font-size: 0.85em;
  background: var(--bg);
  color: var(--fg);
  transition: border-color 120ms ease, box-shadow 120ms ease;
}
.sidebar-search input:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.sections {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-bottom: 12px;
}

.section { border-radius: 6px; overflow: hidden; }
.section[open] { background: rgba(0, 0, 0, 0.02); }
@media (prefers-color-scheme: dark) {
  .section[open] { background: rgba(255, 255, 255, 0.025); }
}

.section > summary {
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 7px 8px;
  font-weight: 500;
  color: var(--fg);
  font-size: 0.86em;
  border-radius: 6px;
  user-select: none;
}
.section > summary::-webkit-details-marker { display: none; }
.section > summary::before {
  content: "";
  display: inline-block;
  width: 0; height: 0;
  border-left: 4px solid currentColor;
  border-top: 3px solid transparent;
  border-bottom: 3px solid transparent;
  margin-right: 6px;
  opacity: 0.4;
  transition: transform 150ms ease;
  flex-shrink: 0;
}
.section[open] > summary::before { transform: rotate(90deg); }
.section > summary:hover { background: var(--accent-soft); }
.section > summary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.section-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
}
.section-label .ico { color: var(--muted); flex-shrink: 0; }

.section-count {
  font-size: 0.72em;
  font-weight: 600;
  color: var(--muted);
  background: var(--bg);
  border: 1px solid var(--border);
  padding: 1px 7px;
  border-radius: 9999px;
  font-feature-settings: "tnum";
  min-width: 22px;
  text-align: center;
  flex-shrink: 0;
}

.section ul {
  list-style: none;
  padding: 2px 0 6px 26px;
  margin: 0;
}
.section li { padding: 0; }

.page-link {
  display: block;
  padding: 4px 8px;
  border-radius: 5px;
  color: var(--fg);
  font-size: 0.86em;
  line-height: 1.35;
  white-space: normal;
  overflow-wrap: anywhere;
  border-left: 2px solid transparent;
  transition: background-color 100ms ease, border-color 100ms ease;
}
.page-link:hover { background: var(--accent-soft); text-decoration: none; }
.page-link:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
  background: var(--accent-soft);
}
.page-link.current {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
  border-left-color: var(--accent);
}

/* legacy aliases — kept so nothing hard-errors if referenced elsewhere */
.sidebar-panel { margin-top: 4px; padding: 10px 4px 6px; }
.panel-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; padding: 0 4px; }
.panel-label { display: inline-flex; align-items: center; gap: 6px; font-size: 0.7em; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted); font-weight: 700; }
.panel-count { font-size: 0.72em; font-weight: 600; color: var(--muted); background: var(--bg); border: 1px solid var(--border); padding: 1px 7px; border-radius: 9999px; }

.url-add {
  display: flex;
  gap: 4px;
  margin-bottom: 8px;
  padding: 0 4px;
}
.url-add input {
  flex: 1;
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 5px 8px;
  font-size: 0.78em;
  background: var(--bg);
  color: var(--fg);
  transition: border-color 120ms ease, box-shadow 120ms ease;
}
.url-add input:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft);
}
.url-add .btn {
  padding: 4px 10px;
  font-size: 0.78em;
  border: 1px solid var(--border);
}

.file-drop {
  margin: 6px 0 10px;
  padding: 12px 10px;
  border: 1px dashed var(--border);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.02);
  text-align: center;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 4px;
  transition: border-color 120ms ease, background-color 120ms ease;
}
.file-drop:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.file-drop.dragging {
  border-color: var(--link);
  background: rgba(142, 197, 255, 0.08);
  border-style: solid;
}
.file-drop.uploading {
  opacity: 0.6;
  pointer-events: none;
}
.file-drop-label {
  font-size: 0.82em;
  color: var(--fg);
}
.file-drop-btn {
  background: none;
  border: none;
  color: var(--link);
  cursor: pointer;
  font: inherit;
  padding: 0;
  text-decoration: underline;
}
.file-drop-btn:hover { color: var(--link-hover); }
.file-drop-hint {
  font-size: 0.72em;
  color: var(--muted);
}

.raw-list { list-style: none; padding: 0; margin: 0; }
.raw-list li {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 6px;
  border-radius: 5px;
  font-size: 0.82em;
  transition: background-color 100ms ease;
}
.raw-list li:hover { background: var(--accent-soft); }

.raw-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--fg);
}

.icon-btn {
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background-color 100ms ease, color 100ms ease;
  flex-shrink: 0;
}
.icon-btn:hover { color: var(--accent); background: var(--bg); }
.icon-btn.destructive:hover { color: var(--broken); }
.icon-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* old footer — no longer rendered, kept for safety */
.sidebar-footer { display: none; }
.footer-link { display: none; }

.empty {
  color: var(--muted);
  font-size: 0.82em;
  font-style: italic;
  padding: 4px;
  margin: 0;
}

.content {
  padding: 28px 40px 60px;
  max-width: 800px;
  width: 100%;
  overflow-x: hidden;
}

.content h1 {
  margin-top: 0;
}

.frontmatter {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 0.82em;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  padding-bottom: 12px;
  margin-bottom: 20px;
}

.meta-item {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.meta-label {
  color: var(--fg);
  font-weight: 500;
  white-space: nowrap;
}

.meta-value {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.meta-badge {
  display: inline-block;
  background: var(--accent-soft);
  color: var(--accent);
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 0.85em;
  font-weight: 500;
}

.meta-pill {
  display: inline-block;
  background: var(--accent-soft);
  color: var(--accent);
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 0.8em;
}

.meta-chip {
  display: inline-block;
  background: var(--tag-bg);
  color: var(--tag-fg);
  padding: 3px 8px;
  border-radius: 4px;
  font-size: 0.8em;
  text-decoration: none;
  border: 1px solid rgba(168, 197, 236, 0.18);
  transition: background-color var(--duration-base) ease, color var(--duration-base) ease, border-color var(--duration-base) ease;
}
.meta-chip:hover {
  background: var(--link);
  color: #0c1220;
  border-color: var(--link);
}
.meta-chip:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
.meta-chip.broken {
  color: var(--broken);
  background: transparent;
  border: 1px solid var(--broken);
  padding: 2px 7px;
}

.body {
  font-size: 1.02em;
}
.page-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}
.page-header h1 {
  margin: 0;
  font-size: 2.15rem;
  line-height: 1.05;
}
.body h1,
.body h2,
.body h3 {
  margin-top: 1.5em;
}

.wikilink {
  color: var(--link);
  text-decoration: none;
  border-bottom: 1px dashed rgba(142, 197, 255, 0.4);
  padding: 0 1px;
  transition: color 120ms ease, background-color 120ms ease, border-color 120ms ease;
}
.wikilink:hover {
  color: var(--link-hover);
  background: rgba(142, 197, 255, 0.08);
  border-bottom-color: var(--link-hover);
  text-decoration: none;
}
.wikilink:focus-visible {
  outline: 2px solid var(--link);
  outline-offset: 2px;
}
.wikilink.broken {
  color: var(--broken);
  border-bottom-color: rgba(224, 112, 112, 0.5);
  cursor: help;
}
.wikilink.broken::after {
  content: "?";
  font-size: 0.7em;
  vertical-align: super;
}

.backlinks {
  margin-top: 50px;
  padding-top: 16px;
  border-top: 2px solid var(--border);
}
.backlinks h3 {
  font-size: 0.85em;
  text-transform: uppercase;
  color: var(--muted);
}
.backlinks ul {
  padding-left: 20px;
}

.query-panel {
  background: var(--sidebar-bg);
  border-left: 1px solid var(--border);
  padding: 20px 16px;
  position: sticky;
  top: 50px;
  align-self: start;
  max-height: calc(100vh - 50px);
  overflow-y: auto;
  box-shadow: -1px 0 3px rgba(0, 0, 0, 0.05);
  /* relative for resize handle */
  isolation: isolate;
}

.query-panel h3 {
  margin: 0 0 10px;
  font-size: 0.78em;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
}

.query-panel textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px;
  font-family: inherit;
  font-size: 0.92em;
  background: var(--bg);
  color: var(--fg);
  resize: vertical;
  transition: border-color var(--duration-base) ease, box-shadow var(--duration-base) ease;
}
.query-panel textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft);
}

.checkbox {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 8px 0;
  font-size: 0.84em;
  color: var(--muted);
}
.checkbox input {
  cursor: pointer;
}
.checkbox input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.answer-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 8px 0;
}

.answer-actions .muted {
  font-size: 0.8em;
  margin: 0;
}

.answer {
  white-space: pre-wrap;
  font-size: 0.92em;
  line-height: 1.6;
  margin-top: 12px;
  padding: 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  min-height: 40px;
  word-wrap: break-word;
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.05);
}

.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: #222;
  color: white;
  padding: 10px 18px;
  border-radius: 5px;
  font-size: 0.9em;
  box-shadow: var(--shadow);
  z-index: 1000;
  max-width: 600px;
}
@media (prefers-reduced-motion: no-preference) {
  .toast {
    transition: transform 0.25s ease;
  }
  .toast.show {
    transform: translateX(-50%) translateY(0);
  }
}
@media (prefers-reduced-motion: reduce) {
  .toast.show {
    transform: translateX(-50%) translateY(0);
  }
}

.confirm-dialog {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--sidebar-bg);
  color: var(--fg);
  padding: 0;
  width: min(540px, 92vw);
  max-height: 80vh;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
}
.confirm-dialog::backdrop { background-color: rgba(0, 0, 0, 0.6); }

.dialog-content { padding: 22px 24px 18px; }
.dialog-content h3 {
  margin: 0 0 6px;
  font-size: 1.05em;
  font-weight: 600;
  color: var(--fg);
}
.dialog-intro {
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 0.92em;
}
.dialog-list {
  margin: 0 0 16px;
  padding-left: 20px;
  font-size: 0.88em;
  color: var(--fg);
  line-height: 1.55;
}
.dialog-list li { margin-bottom: 4px; }
.dialog-warning {
  margin: 0 0 18px;
  padding: 8px 12px;
  background: rgba(224, 112, 112, 0.08);
  border-left: 3px solid var(--broken);
  border-radius: 4px;
  font-size: 0.85em;
  color: var(--fg);
}
.dialog-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  padding: 14px 24px;
  border-top: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.15);
}

@media (max-width: 1100px) {
  .layout {
    grid-template-columns: var(--col-sidebar, 240px) 1fr;
  }
  .query-panel {
    display: none;
  }
}

@media (max-width: 720px) {
  .layout {
    grid-template-columns: 44px 1fr;
  }
  .sidebar-body {
    display: none;
  }
  .content {
    padding: 20px;
  }
}

/* ── B8: Activity bar ───────────────────────────────── */
.activity-bar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: var(--accent);
  color: white;
  font-size: 0.78em;
  padding: 5px 16px;
  z-index: 800;
  transform: translateY(100%);
  transition: transform 200ms var(--ease-out);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.activity-bar.active { transform: translateY(0); }

/* ── B17: Inline editor overlay ─────────────────────── */
.editor-overlay {
  position: fixed;
  inset: 0;
  z-index: 1100;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.editor-box {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  width: 100%;
  max-width: 800px;
  max-height: calc(100vh - 80px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.editor-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.editor-title {
  font-size: 0.85em;
  color: var(--muted);
}
.editor-actions { display: flex; gap: 8px; }
.editor-textarea {
  flex: 1;
  border: none;
  outline: none;
  padding: 16px;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 0.88em;
  line-height: 1.6;
  background: var(--bg);
  color: var(--fg);
  resize: none;
  min-height: 0;
}
.editor-status {
  padding: 8px 16px;
  font-size: 0.8em;
  color: var(--muted);
  border-top: 1px solid var(--border);
  min-height: 32px;
  flex-shrink: 0;
}

/* ── B13: Resize handles ─────────────────────────────── */
.resize-h {
  position: absolute;
  top: 0; bottom: 0;
  width: 6px;
  cursor: col-resize;
  z-index: 20;
  background: transparent;
  transition: background-color 120ms ease;
}
.resize-h:hover, .resize-h.dragging { background: var(--accent); opacity: 0.3; }
.resize-sidebar { right: -3px; }
.resize-query { left: -3px; }

/* ── B16: Command palette ────────────────────────────── */
.cmd-palette {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 80px;
}
.cmd-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
}
.cmd-box {
  position: relative;
  width: 560px;
  max-width: calc(100vw - 32px);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
  overflow: hidden;
}
.cmd-box input {
  width: 100%;
  border: none;
  border-bottom: 1px solid var(--border);
  padding: 16px 18px;
  font-size: 1em;
  background: transparent;
  color: var(--fg);
  outline: none;
}
.cmd-results {
  list-style: none;
  margin: 0;
  padding: 6px;
  max-height: 340px;
  overflow-y: auto;
}
.cmd-item {
  padding: 9px 12px;
  border-radius: 7px;
  font-size: 0.9em;
  cursor: pointer;
  color: var(--fg);
  display: flex;
  align-items: center;
  gap: 8px;
}
.cmd-item:hover, .cmd-item.selected {
  background: var(--accent-soft);
  color: var(--accent);
}
.cmd-item-type {
  font-size: 0.72em;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  min-width: 44px;
}
.cmd-hint {
  position: absolute;
  bottom: 10px; right: 14px;
  font-size: 0.72em;
  color: var(--muted);
  pointer-events: none;
}
kbd {
  display: inline-block;
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 0.85em;
  font-family: inherit;
}

/* ── B5: Chat history panel ─────────────────────────── */
.chat-history-section {
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}
.chat-history-hdr {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}
.chat-history-label {
  font-size: 0.72em;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  font-weight: 700;
}
.chat-history-list {
  display: flex;
  flex-direction: column;
  gap: 3px;
  max-height: 200px;
  overflow-y: auto;
}
.chat-history-item {
  padding: 7px 10px;
  border-radius: 6px;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--bg);
  transition: background-color 100ms ease, border-color 100ms ease;
}
.chat-history-item:hover { background: var(--accent-soft); border-color: var(--accent); }
.chat-history-q {
  font-size: 0.82em;
  color: var(--fg);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-history-meta {
  font-size: 0.72em;
  color: var(--muted);
  margin-top: 2px;
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
    transition: none !important;
  }
}

/* KaTeX overrides for dark mode visibility */
.katex { font-size: 1.05em; }
@media (prefers-color-scheme: dark) {
  .katex { color: var(--fg); }
}

/* Mermaid diagram block */
.mermaid {
  background: var(--code-bg);
  padding: 14px;
  border-radius: 8px;
  margin: 16px 0;
  text-align: center;
  overflow-x: auto;
}

/* Numbered citation marker in answers */
.answer sup.cite {
  font-size: 0.7em;
  color: var(--link);
  background: var(--accent-soft);
  padding: 1px 4px;
  border-radius: 3px;
  font-weight: 600;
  margin: 0 2px;
  font-feature-settings: "tnum";
}
.answer p { margin: 0 0 10px; }
.answer h3 {
  font-size: 0.85em;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin: 18px 0 8px;
  border-top: 1px solid var(--border);
  padding-top: 12px;
}
.answer h4, .answer h5 { font-size: 0.95em; margin: 12px 0 6px; }
.answer ul { padding-left: 18px; margin: 0 0 10px; }
.answer ul li { margin-bottom: 4px; }
.answer .wikilink { color: var(--accent); }
.answer .wikilink:hover { text-decoration: underline; }
