@import url("https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap");

:root {
  /* Design tokens */
  --bg-main: #F8FAFC;
  --bg-surface: #FFFFFF;
  --text-primary: #0F172A;
  --brand-primary: #1D52FF;
  --brand-accent: #00E5FF;
  --brand-alert: #FF5500;
  --border-neutral: #E2E8F0;

  /* Semantic aliases (used throughout stylesheet) */
  --bg: var(--bg-main);
  --surface: var(--bg-surface);
  --surface-2: var(--border-neutral);
  --text: var(--text-primary);
  --muted: #64748B;
  --accent: var(--brand-primary);
  --accent-dim: rgba(29, 82, 255, 0.1);
  --live: var(--brand-alert);
  --doc: #0D9488;
  --manual: #6366F1;
  --search: var(--brand-primary);
  --advice: var(--brand-alert);
  --advice-dim: rgba(255, 85, 0, 0.12);
  --line: var(--brand-primary);
  --font: "Inter", "SF Pro Text", "Roboto Flex", system-ui, sans-serif;
  --mono: ui-monospace, "Cascadia Code", "Segoe UI Mono", monospace;
  --on-brand: #FFFFFF;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  overflow: hidden;
}

/* Reset default link styling (avoids purple/blue browser defaults) */
a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

a.text-link {
  font-weight: 500;
}

a.text-link:hover {
  color: #1642CC;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  padding: 0.65rem 1rem;
  border-bottom: 1px solid var(--surface-2);
  background: var(--surface);
  min-height: 52px;
  flex-shrink: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: nowrap;
}

.logo-link {
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
  line-height: 0;
  text-decoration: none;
}

.logo-link:hover {
  text-decoration: none;
  opacity: 0.9;
}

.logo-link:focus-visible {
  outline: 2px solid var(--brand-primary);
  outline-offset: 3px;
  border-radius: 4px;
}

.brand .logo,
.logo-link .logo {
  display: block;
  height: 2rem;
  width: auto;
  max-width: min(11rem, 40vw);
  object-fit: contain;
}

.brand .tagline {
  margin-left: 0.75rem;
  color: var(--muted);
  font-size: 0.85rem;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.upload-btn {
  cursor: pointer;
  font-size: 0.85rem;
  padding: 0.4rem 0.75rem;
  border-radius: 6px;
  background: var(--surface-2);
  border: 1px solid transparent;
}

.upload-btn:hover {
  border-color: var(--accent);
}

.status-pill {
  font-size: 0.75rem;
  font-family: var(--mono);
  color: var(--muted);
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  background: var(--bg);
}

.status-pill.busy {
  color: var(--accent);
}

.main-nav {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.nav-link {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.85rem;
  padding: 0.35rem 0.65rem;
  border-radius: 6px;
  white-space: nowrap;
}

.nav-link:hover {
  color: var(--text);
  background: var(--surface-2);
  text-decoration: none;
}

.nav-link.active {
  color: var(--brand-primary);
  background: var(--accent-dim);
  text-decoration: none;
}

.notes-page,
.documents-page {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
}

.app-body {
  display: flex;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.notes-rail {
  width: 240px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--surface-2);
}

.notebooks-list {
  list-style: none;
  margin: 0;
  padding: 0.4rem 0.5rem;
  overflow-y: auto;
  max-height: 38vh;
  border-bottom: 1px solid var(--surface-2);
}

.notebook-item {
  padding: 0.5rem 0.6rem;
  border-radius: 8px;
  cursor: pointer;
  margin-bottom: 0.3rem;
  border: 1px solid transparent;
}

.notebook-item-row {
  display: flex;
  align-items: flex-start;
  gap: 0.35rem;
}

.notebook-item-body {
  flex: 1;
  min-width: 0;
}

.notebook-item-delete {
  flex-shrink: 0;
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
  padding: 0.15rem 0.25rem;
  border-radius: 4px;
  opacity: 0;
  transition: opacity 0.15s, color 0.15s;
}

.notebook-item:hover .notebook-item-delete,
.notebook-item-delete:focus {
  opacity: 1;
}

.notebook-item-delete:hover {
  color: #f87171;
  background: rgba(248, 113, 113, 0.15);
}

.rail-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 0.75rem;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  border-bottom: 1px solid var(--surface-2);
}

.rail-header-actions {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.btn-recycle {
  position: relative;
  color: var(--muted);
}

.btn-share {
  color: var(--muted);
}

.btn-share:hover:not(:disabled) {
  color: var(--accent);
}

.btn-share:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.btn-recycle:hover:not(:disabled) {
  color: #f87171;
}

.btn-recycle:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.recycle-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 14px;
  height: 14px;
  padding: 0 3px;
  border-radius: 999px;
  background: #f87171;
  color: #fff;
  font-size: 0.58rem;
  font-weight: 700;
  line-height: 14px;
  text-align: center;
  pointer-events: none;
}

.recycle-modal {
  width: min(480px, 92vw);
}

.recycle-modal-head {
  margin-bottom: 0.75rem;
}

.recycle-modal-head h3 {
  margin: 0;
}

.recycle-dialog-hint {
  margin: 0.35rem 0 0;
  font-size: 0.82rem;
  color: var(--muted);
  line-height: 1.4;
}

.recycle-dialog-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 50vh;
  overflow-y: auto;
}

.recycle-dialog-item {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  padding: 0.65rem 0;
  border-bottom: 1px solid var(--surface-2);
}

.recycle-dialog-item:last-child {
  border-bottom: none;
}

.recycle-dialog-item-body {
  flex: 1;
  min-width: 0;
}

.recycle-dialog-item-title {
  display: block;
  font-weight: 600;
  font-size: 0.9rem;
}

.recycle-dialog-item-meta {
  display: block;
  font-size: 0.72rem;
  color: var(--muted);
  margin-top: 0.15rem;
}

.recycle-dialog-item-actions {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  flex-shrink: 0;
}

.btn-sm {
  font-size: 0.72rem;
  padding: 0.25rem 0.5rem;
}

.recycle-empty {
  padding: 1rem 0;
  color: var(--muted);
  font-size: 0.85rem;
  text-align: center;
}

.confirm-message {
  margin: 0.75rem 0 0;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.45;
}

.notebook-item:hover {
  background: var(--surface-2);
}

.notebook-item.active {
  background: var(--accent-dim);
  border-color: var(--accent);
}

.notebook-item-title {
  display: block;
  font-weight: 600;
  font-size: 0.85rem;
}

.notebook-item-meta {
  display: block;
  font-size: 0.68rem;
  color: var(--muted);
  margin-top: 0.15rem;
}

.rail-header-sessions {
  border-top: none;
}

.note-item-muted {
  color: var(--muted);
  cursor: default;
  font-size: 0.8rem;
}

.notebook-badge {
  display: inline-block;
  font-size: 0.62rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 0.12rem 0.4rem;
  border-radius: 4px;
  margin-right: 0.4rem;
  background: rgba(99, 102, 241, 0.12);
  color: #4338CA;
  vertical-align: middle;
}

.notes-list {
  list-style: none;
  margin: 0;
  padding: 0.5rem;
  overflow-y: auto;
  flex: 1;
}

.note-item {
  padding: 0.6rem 0.65rem;
  border-radius: 8px;
  cursor: pointer;
  margin-bottom: 0.35rem;
  border: 1px solid transparent;
  position: relative;
}

.note-item:hover {
  background: var(--surface-2);
}

.note-item.active {
  background: var(--accent-dim);
  border-color: var(--accent);
}

.note-item-title {
  display: block;
  font-weight: 600;
  font-size: 0.88rem;
  margin-bottom: 0.2rem;
}

.note-item-preview {
  display: block;
  font-size: 0.75rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.note-item-date {
  display: block;
  font-size: 0.65rem;
  font-family: var(--mono);
  color: var(--muted);
  margin-top: 0.25rem;
}

.note-title-input {
  background: var(--bg);
  border: 1px solid var(--surface-2);
  color: var(--text);
  border-radius: 6px;
  padding: 0.35rem 0.6rem;
  font-size: 0.9rem;
  min-width: 180px;
  font-family: inherit;
}

.btn-icon,
.btn-secondary {
  cursor: pointer;
  font-size: 0.8rem;
  padding: 0.35rem 0.6rem;
  border-radius: 6px;
  border: 1px solid var(--surface-2);
  background: var(--surface-2);
  color: var(--text);
  font-family: inherit;
}

.btn-icon {
  width: 28px;
  height: 28px;
  padding: 0;
  line-height: 1;
}

.btn-secondary:hover,
.btn-icon:hover {
  border-color: var(--accent);
}

.btn-danger {
  cursor: pointer;
  font-size: 0.8rem;
  padding: 0.35rem 0.6rem;
  border-radius: 6px;
  border: 1px solid rgba(239, 68, 68, 0.35);
  background: rgba(239, 68, 68, 0.08);
  color: #B91C1C;
  font-family: inherit;
}

.btn-danger:hover {
  background: rgba(239, 68, 68, 0.15);
  border-color: #DC2626;
}

.note-item-row {
  display: flex;
  align-items: flex-start;
  gap: 0.35rem;
}

.note-item-body {
  flex: 1;
  min-width: 0;
}

.note-item-delete {
  flex-shrink: 0;
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
  padding: 0.15rem 0.25rem;
  border-radius: 4px;
  opacity: 0;
  transition: opacity 0.15s, color 0.15s;
}

.note-item:hover .note-item-delete,
.note-item-delete:focus {
  opacity: 1;
}

.note-item-delete:hover {
  color: #f87171;
  background: rgba(248, 113, 113, 0.15);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr);
  flex: 1;
  min-width: 0;
  min-height: 0;
  position: relative;
  overflow: hidden;
}

.workspace.sidecar-collapsed {
  grid-template-columns: minmax(0, 1fr) 2.75rem;
}

.workspace.sidecar-collapsed .lead-lines {
  display: none;
}

.notepad-pane {
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
}

.sidecar-pane {
  min-height: 0;
  min-width: 0;
}

.note-docs-panel {
  border-top: 1px solid var(--surface-2);
  background: var(--surface);
  max-height: 160px;
  display: flex;
  flex-direction: column;
}

.note-docs-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.75rem;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.badge {
  font-size: 0.65rem;
  padding: 0.1rem 0.4rem;
  border-radius: 10px;
  background: var(--accent-dim);
  color: var(--accent);
  font-family: var(--mono);
}

.note-docs-list {
  list-style: none;
  margin: 0;
  padding: 0 0.75rem 0.5rem;
  overflow-y: auto;
  flex: 1;
}

.note-doc-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8rem;
  padding: 0.25rem 0;
}

.note-doc-name {
  color: var(--doc);
  text-decoration: none;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
  background: none;
  border: none;
  padding: 0;
  font: inherit;
  text-align: left;
}

.note-doc-name:hover {
  text-decoration: underline;
  color: var(--brand-primary);
}

.note-item-loading {
  color: var(--muted);
  font-size: 0.8rem;
  padding: 0.75rem;
  cursor: default;
}

.note-doc-meta {
  font-size: 0.7rem;
  color: var(--muted);
  font-family: var(--mono);
}

.btn-unlink {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 1rem;
  padding: 0 0.25rem;
}

.btn-unlink:hover {
  color: #f87171;
}

.note-docs-hint {
  margin: 0;
  padding: 0.25rem 0.75rem 0.5rem;
  font-size: 0.7rem;
  color: var(--muted);
}

.note-docs-hint .text-link {
  margin-left: 0.25rem;
}

.note-doc-empty {
  color: var(--muted);
  font-size: 0.8rem;
}

.modal {
  border: 1px solid var(--surface-2);
  border-radius: 10px;
  padding: 1.25rem;
  background: var(--surface);
  color: var(--text);
  max-width: 520px;
}

.modal::backdrop {
  background: rgba(0, 0, 0, 0.55);
}

.modal label {
  display: block;
  margin-bottom: 0.75rem;
  font-size: 0.85rem;
}

.modal input,
.modal textarea,
.modal select {
  display: block;
  width: 100%;
  margin-top: 0.35rem;
  padding: 0.5rem;
  border-radius: 6px;
  border: 1px solid var(--surface-2);
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
}

.modal-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
  margin-top: 1rem;
}

/* Documents manager page */
.documents-page .documents-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr);
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.documents-page .linked-notes-list a {
  color: var(--accent);
}

.documents-list-pane,
.documents-detail-pane {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.documents-list-pane {
  border-right: 1px solid var(--surface-2);
}

.documents-filters {
  display: flex;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--surface-2);
}

.documents-filters select {
  flex: 1;
  padding: 0.35rem;
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--surface-2);
}

.documents-table-wrap {
  flex: 1 1 auto;
  min-height: 12rem;
  overflow: auto;
  padding: 0.5rem;
}

.documents-table .table-empty,
.documents-table .table-error {
  padding: 1.25rem 0.75rem;
  color: var(--muted);
  font-size: 0.85rem;
  text-align: center;
}

.documents-table .table-error {
  color: #f87171;
}

.documents-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.documents-table th {
  text-align: left;
  padding: 0.5rem;
  color: var(--muted);
  font-size: 0.7rem;
  text-transform: uppercase;
  border-bottom: 1px solid var(--surface-2);
}

.documents-table td {
  padding: 0.55rem 0.5rem;
  border-bottom: 1px solid var(--surface-2);
}

.documents-table tr {
  cursor: pointer;
}

.documents-table tr:hover {
  background: var(--surface-2);
}

.documents-table tr.selected {
  background: var(--accent-dim);
}

.context-expander {
  margin: 0;
  border-top: 1px solid var(--surface-2);
  border-radius: 0;
  background: var(--surface);
  flex-shrink: 0;
  min-height: 2.25rem;
}

.context-expander summary {
  padding: 0.45rem 0.75rem;
  cursor: pointer;
  font-size: 0.78rem;
  color: var(--muted);
  user-select: none;
  list-style: none;
}

.context-expander summary::-webkit-details-marker {
  display: none;
}

.context-expander summary::before {
  content: "▸";
  display: inline-block;
  margin-right: 0.45rem;
  transition: transform 0.15s;
}

.context-expander[open] summary::before {
  transform: rotate(90deg);
}

.context-expander[open] summary {
  color: var(--text);
  border-bottom: 1px solid var(--surface-2);
}

.context-inline-form {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  padding: 0.75rem;
}

.context-inline-form label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.78rem;
  color: var(--muted);
}

.context-inline-form input,
.context-inline-form select,
.context-inline-form textarea {
  font-family: inherit;
  font-size: 0.85rem;
  padding: 0.4rem 0.55rem;
  border-radius: 6px;
  border: 1px solid var(--surface-2);
  background: var(--bg);
  color: var(--text);
}

.context-inline-form textarea {
  resize: vertical;
  min-height: 4.5rem;
}

.doc-chat-layer {
  position: fixed;
  inset: 0;
  z-index: 1000;
  pointer-events: none;
}

.doc-chat-layer > .doc-chat-fab,
.doc-chat-layer > .doc-chat-popup {
  pointer-events: auto;
}

.doc-chat-fab {
  position: fixed;
  right: 1.25rem;
  bottom: 1.25rem;
  z-index: 1000;
  width: 3.25rem;
  height: 3.25rem;
  border: none;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 1.35rem;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.28);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s, box-shadow 0.15s;
}

.doc-chat-fab:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 22px rgba(0, 0, 0, 0.32);
}

.doc-chat-popup {
  position: fixed;
  right: 1.25rem;
  bottom: 1.25rem;
  z-index: 1002;
  width: min(24rem, calc(100vw - 2rem));
  max-height: min(34rem, calc(100vh - 2rem));
  display: flex;
  flex-direction: column;
  border: 1px solid var(--surface-2);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.35);
  overflow: hidden;
}

.doc-chat-popup.is-minimized {
  max-height: none;
}

.doc-chat-popup.is-minimized .doc-chat-popup-body {
  display: none;
}

.doc-chat-popup-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.65rem 0.75rem;
  border-bottom: 1px solid var(--surface-2);
  background: var(--bg);
}

.doc-chat-popup-title-wrap {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

.doc-chat-popup-title-wrap strong {
  font-size: 0.88rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.doc-chat-popup-sub {
  font-size: 0.68rem;
  color: var(--muted);
}

.doc-chat-popup-controls {
  display: flex;
  gap: 0.25rem;
  flex-shrink: 0;
}

.doc-chat-icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.65rem;
  height: 1.65rem;
  border: 1px solid var(--surface-2);
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  line-height: 1;
  padding: 0;
}

.doc-chat-minimize-btn .material-symbols-outlined {
  font-size: 1.05rem;
  line-height: 1;
}

.doc-chat-minimize-btn .material-symbols-outlined:last-child {
  display: none;
}

.doc-chat-minimize-btn.is-maximize .material-symbols-outlined:first-child {
  display: none;
}

.doc-chat-minimize-btn.is-maximize .material-symbols-outlined:last-child {
  display: inline-flex;
}

.doc-chat-icon-btn:hover {
  color: var(--text);
  background: var(--surface-2);
}

.doc-chat-popup-body {
  display: flex;
  flex-direction: column;
  min-height: 0;
  flex: 1;
  padding: 0.65rem;
}

.doc-chat-messages {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  flex: 1;
  min-height: 10rem;
  max-height: 22rem;
  overflow-y: auto;
  padding: 0.35rem 0.15rem 0.65rem;
  margin-bottom: 0.5rem;
}

.doc-chat-empty {
  margin: 0;
  font-size: 0.82rem;
  color: var(--muted);
}

.doc-chat-bubble {
  max-width: 94%;
  padding: 0.55rem 0.7rem;
  border-radius: 10px;
  font-size: 0.85rem;
  line-height: 1.45;
  word-break: break-word;
}

.doc-chat-user {
  align-self: flex-end;
  background: var(--accent-dim);
  border: 1px solid rgba(61, 156, 245, 0.25);
  white-space: pre-wrap;
}

.doc-chat-assistant {
  align-self: flex-start;
  background: var(--bg);
  border: 1px solid var(--surface-2);
  max-width: 100%;
}

.doc-chat-assistant .card-body-md {
  font-size: 0.82rem;
}

.doc-chat-assistant .card-body-md .md-h {
  font-size: 0.76rem;
}

.doc-chat-thinking {
  opacity: 0.7;
  font-style: italic;
}

.doc-chat-form textarea {
  width: 100%;
  box-sizing: border-box;
  font-family: inherit;
  font-size: 0.85rem;
  padding: 0.55rem 0.65rem;
  border-radius: 8px;
  border: 1px solid var(--surface-2);
  background: var(--bg);
  color: var(--text);
  resize: vertical;
}

.doc-chat-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.doc-chat-bubble-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 0.45rem;
}

.nb-chat-save-btn {
  font-size: 0.75rem;
}

.state-pill {
  font-size: 0.7rem;
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
  text-transform: uppercase;
}

.state-active {
  background: rgba(16, 185, 129, 0.2);
  color: var(--doc);
}

.state-archived {
  background: rgba(139, 156, 179, 0.2);
  color: var(--muted);
}

.detail-empty {
  padding: 2rem 1rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.detail-content {
  padding: 1rem;
  overflow-y: auto;
  flex: 1;
}

.detail-content.hidden {
  display: none !important;
}

[hidden] {
  display: none !important;
}

.hidden {
  display: none !important;
}

.detail-meta {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.doc-name-input {
  flex: 1;
  min-width: 160px;
  padding: 0.4rem 0.6rem;
  border-radius: 6px;
  border: 1px solid var(--surface-2);
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
}

.detail-section {
  margin-bottom: 1.25rem;
}

.detail-section h4 {
  margin: 0 0 0.5rem;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.linked-notes-list,
.versions-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.linked-notes-list li,
.versions-list li {
  padding: 0.35rem 0;
  font-size: 0.85rem;
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  align-items: center;
}

.muted {
  color: var(--muted);
  font-size: 0.8rem;
}

#context-editor {
  width: 100%;
  padding: 0.6rem;
  border-radius: 6px;
  border: 1px solid var(--surface-2);
  background: var(--bg);
  color: var(--text);
  font-family: var(--mono);
  font-size: 0.8rem;
  margin-bottom: 0.5rem;
  resize: vertical;
}

.btn-sm {
  font-size: 0.7rem !important;
  padding: 0.2rem 0.4rem !important;
}

.pane {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.pane-title {
  padding: 0.5rem 1rem;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  border-bottom: 1px solid var(--surface-2);
  background: var(--surface);
}

.pane-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  flex-wrap: wrap;
  padding: 0.5rem 1rem;
  border-bottom: 1px solid var(--surface-2);
  background: var(--surface);
}

.pane-title-row .pane-title {
  padding: 0;
  border: none;
  background: transparent;
}

.btn-fact-check {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.75rem;
  height: 1.75rem;
  padding: 0;
  border: 1px solid var(--surface-2);
  border-radius: 6px;
  background: var(--bg);
  color: var(--muted);
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}

.note-editor {
  display: flex;
  flex: 1;
  min-height: 0;
  min-width: 0;
}

.skills-sidebar {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  padding: 0.85rem 0.55rem;
  border-right: 1px solid var(--surface-2);
  background: var(--surface);
  flex-shrink: 0;
}

.skill-tool {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.3rem;
  width: 4.5rem;
}

.skill-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  padding: 0;
  border: 1px solid var(--surface-2);
  border-radius: 8px;
  background: var(--bg);
  color: var(--muted);
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}

.skill-btn .material-symbols-outlined {
  font-size: 1.25rem;
  line-height: 1;
}

.skill-btn:hover {
  color: var(--text);
  border-color: var(--accent);
}

.skill-btn.active {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-dim);
}

.skill-tool-toggle .skill-btn-toggle.active {
  color: #0d9488;
  border-color: #0d9488;
  background: rgba(13, 148, 136, 0.12);
}

.skill-tool-toggle .skill-label {
  color: var(--muted);
}

.skill-tool-toggle .skill-btn-toggle.active + .skill-label,
.skill-tool-toggle:has(.skill-btn-toggle.active) .skill-label {
  color: #0d9488;
}

.skill-label {
  font-size: 0.62rem;
  line-height: 1.15;
  text-align: center;
  color: var(--muted);
  max-width: 4.5rem;
}

.note-editor-main {
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.note-toolbar {
  display: flex;
  align-items: center;
  gap: 0.15rem;
  padding: 0.35rem 0.5rem;
  border-bottom: 1px solid var(--surface-2);
  background: var(--surface);
  flex-shrink: 0;
  position: sticky;
  top: 0;
  z-index: 2;
}

.toolbar-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.85rem;
  height: 1.85rem;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.toolbar-btn .material-symbols-outlined {
  font-size: 1.05rem;
}

.toolbar-btn:hover {
  color: var(--text);
  background: var(--surface-2);
  border-color: var(--surface-2);
}

.toolbar-sep {
  width: 1px;
  height: 1.25rem;
  margin: 0 0.2rem;
  background: var(--surface-2);
}

.notepad-wrap.skill-armed .notepad {
  cursor: text;
  box-shadow: inset 0 0 0 1px rgba(61, 156, 245, 0.35);
}

.notepad-wrap.skill-armed::after {
  content: attr(data-skill-hint);
  position: absolute;
  top: 0.5rem;
  right: 0.75rem;
  font-size: 0.68rem;
  color: var(--accent);
  pointer-events: none;
  opacity: 0.9;
}

.btn-fact-check:hover {
  color: var(--text);
  border-color: var(--accent);
}

.btn-fact-check.active {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-dim);
}

.notepad-wrap {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.sidecar-accordion-trigger {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  margin: 0;
  padding: 0.5rem 1rem;
  border: none;
  border-bottom: 1px solid var(--surface-2);
  background: var(--surface);
  color: var(--muted);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  cursor: pointer;
  text-align: left;
  flex-shrink: 0;
}

.sidecar-accordion-trigger:hover:not(:disabled) {
  color: var(--text);
  background: var(--surface-2);
}

.sidecar-accordion-trigger:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.sidecar-accordion-chevron {
  display: inline-block;
  width: 0;
  height: 0;
  border-top: 5px solid transparent;
  border-bottom: 5px solid transparent;
  border-left: 6px solid currentColor;
  transition: transform 0.15s;
  flex-shrink: 0;
}

.sidecar-accordion-trigger[aria-expanded="true"] .sidecar-accordion-chevron {
  transform: rotate(90deg);
}

.sidecar-accordion-title {
  flex: 1;
  min-width: 0;
}

.sidecar-accordion-trigger .scoped-badge {
  margin-left: auto;
  text-transform: none;
  letter-spacing: 0;
}

.sidecar-body {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.sidecar-pane.is-collapsed .sidecar-body {
  display: none;
}

.sidecar-pane.is-collapsed .sidecar-accordion-trigger {
  flex-direction: column;
  justify-content: flex-start;
  align-items: center;
  gap: 0.65rem;
  height: 100%;
  padding: 0.75rem 0.35rem;
  border-bottom: none;
  writing-mode: vertical-rl;
  text-orientation: mixed;
}

.sidecar-pane.is-collapsed .sidecar-accordion-trigger .scoped-badge {
  margin-left: 0;
  writing-mode: horizontal-tb;
}

.sidecar-pane.is-collapsed .sidecar-accordion-trigger[aria-expanded="false"] .sidecar-accordion-chevron {
  transform: rotate(180deg);
}

.scoped-badge {
  margin-left: 0.5rem;
  padding: 0.15rem 0.45rem;
  border-radius: 4px;
  background: var(--accent-dim);
  color: var(--accent);
  text-transform: none;
  letter-spacing: 0;
  font-weight: 600;
}

.notepad-pane {
  border-right: 1px solid var(--surface-2);
}

.notepad {
  flex: 1;
  padding: 1.25rem 1.5rem;
  overflow-y: auto;
  outline: none;
  line-height: 1.65;
  font-size: 1rem;
}

.notepad ul,
.notepad ol {
  margin: 0.35rem 0;
  padding-left: 1.5rem;
}

.notepad li {
  margin: 0.15rem 0;
}

.notepad ul {
  list-style-type: disc;
}

.notepad ul ul {
  list-style-type: circle;
}

.notepad ul ul ul {
  list-style-type: square;
}

.notepad ol {
  list-style-type: decimal;
}

.notepad ol ol {
  list-style-type: lower-alpha;
}

.notepad ol ol ol {
  list-style-type: lower-roman;
}

.notepad:empty::before {
  content: attr(data-placeholder);
  color: var(--muted);
  pointer-events: none;
}

.notepad .entity-highlight,
.notepad .search-marker,
.notepad .problem-highlight,
.notepad .fact-check-highlight,
.notepad .pm-highlight,
.notepad .chat-highlight {
  cursor: pointer;
}

.notepad .skill-highlight {
  position: relative;
  box-decoration-break: clone;
}

.notepad .skill-highlight-clear {
  display: none;
  vertical-align: super;
  width: 1.05rem;
  height: 1.05rem;
  margin-left: 0.12rem;
  padding: 0;
  border: 1.5px solid rgba(255, 255, 255, 0.95);
  border-radius: 999px;
  background: #dc2626;
  color: #fff;
  cursor: pointer;
  line-height: 1;
  flex-shrink: 0;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
  transform: translateY(-0.08em);
}

.notepad .skill-highlight-clear::before {
  content: "×";
  display: block;
  font-size: 0.82rem;
  font-weight: 800;
  line-height: 0.95rem;
  text-align: center;
}

.notepad .skill-highlight:hover .skill-highlight-clear,
.notepad .skill-highlight-clear:focus-visible {
  display: inline-block;
}

.notepad .skill-highlight-clear:hover {
  background: #b91c1c;
}

.notepad .entity-highlight {
  background: var(--accent-dim);
  border-bottom: 2px solid var(--accent);
  border-radius: 2px;
  cursor: pointer;
  transition: background 0.15s;
}

.notepad .entity-highlight.active,
.notepad .entity-highlight:hover {
  background: rgba(61, 156, 245, 0.45);
}

.notepad .search-marker {
  background: rgba(56, 189, 248, 0.2);
  border-bottom: 2px dashed var(--search);
  border-radius: 2px;
  cursor: pointer;
}

.notepad .search-marker.active,
.notepad .search-marker:hover {
  background: rgba(56, 189, 248, 0.4);
}

.notepad .problem-highlight {
  background: var(--advice-dim);
  border-bottom: 2px solid var(--advice);
  border-radius: 3px;
  cursor: pointer;
  box-decoration-break: clone;
  transition: background 0.15s;
}

.notepad .problem-highlight.active,
.notepad .problem-highlight:hover {
  background: rgba(245, 158, 11, 0.42);
}

.notepad .chat-highlight {
  background: rgba(99, 102, 241, 0.16);
  border-bottom: 2px solid #6366f1;
  border-radius: 3px;
  box-decoration-break: clone;
  transition: background 0.15s;
}

.notepad .chat-highlight.active,
.notepad .chat-highlight:hover {
  background: rgba(99, 102, 241, 0.32);
}

.notepad .fact-check-highlight {
  border-radius: 2px;
  cursor: pointer;
  box-decoration-break: clone;
  border-bottom: 2px solid var(--muted);
  background: rgba(139, 156, 179, 0.18);
  transition: background 0.15s;
}

.notepad .fact-check-highlight[data-verdict="supported"] {
  border-bottom-color: #10b981;
  background: rgba(16, 185, 129, 0.2);
}

.notepad .fact-check-highlight[data-verdict="unsupported"] {
  border-bottom-color: #f87171;
  background: rgba(248, 113, 113, 0.2);
}

.notepad .fact-check-highlight[data-verdict="mixed"] {
  border-bottom-color: #f59e0b;
  background: rgba(245, 158, 11, 0.22);
}

.notepad .fact-check-highlight.active,
.notepad .fact-check-highlight:hover {
  filter: brightness(1.15);
}

.notepad .pm-highlight {
  background: rgba(20, 184, 166, 0.18);
  border-bottom: 2px solid #14b8a6;
  border-radius: 3px;
  box-decoration-break: clone;
}

.notepad .pm-highlight.active,
.notepad .pm-highlight:hover {
  background: rgba(20, 184, 166, 0.35);
}

.pm-badge {
  display: inline-block;
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 0.1rem 0.35rem;
  margin-right: 0.35rem;
  border-radius: 3px;
  background: rgba(20, 184, 166, 0.2);
  color: #0f766e;
}

.pm-maturity {
  display: inline-block;
  font-size: 0.62rem;
  font-weight: 600;
  text-transform: uppercase;
  padding: 0.08rem 0.3rem;
  margin-right: 0.35rem;
  border-radius: 3px;
  border: 1px solid var(--border);
}

.pm-maturity-draft { color: #b45309; background: rgba(245, 158, 11, 0.12); }
.pm-maturity-partial { color: #0369a1; background: rgba(56, 189, 248, 0.12); }
.pm-maturity-confirmed { color: #047857; background: rgba(16, 185, 129, 0.12); }
.pm-maturity-stale { color: #6b7280; background: rgba(107, 114, 128, 0.12); }

.pm-followups {
  margin-top: 0.65rem;
  padding: 0.55rem 0.65rem;
  border-radius: 6px;
  background: rgba(245, 158, 11, 0.1);
  border: 1px solid rgba(245, 158, 11, 0.25);
}

.pm-followups-label {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #b45309;
  margin-bottom: 0.35rem;
}

.pm-followups-list {
  margin: 0;
  padding-left: 1.1rem;
  font-size: 0.88rem;
}

.pm-delta-callout {
  margin: 0.35rem 0 0.5rem;
  padding: 0.45rem 0.55rem;
  border-radius: 6px;
  background: rgba(20, 184, 166, 0.1);
  font-size: 0.88rem;
}

.pm-card-actions {
  margin-top: 0.5rem;
}

.btn-sm {
  font-size: 0.78rem;
  padding: 0.2rem 0.55rem;
}

.search-suggestion {
  position: absolute;
  left: 1rem;
  right: 1rem;
  bottom: 1rem;
  z-index: 20;
  padding: 0.85rem 1rem;
  border-radius: 10px;
  background: var(--surface-2);
  border: 1px solid var(--search);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

.search-suggestion-text {
  margin: 0 0 0.75rem;
  font-size: 0.88rem;
  color: var(--text);
  line-height: 1.45;
}

.search-suggestion-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

/* Shared buttons */
.btn {
  font-size: 0.8rem;
  padding: 0.4rem 0.75rem;
  border-radius: 6px;
  cursor: pointer;
  border: 1px solid transparent;
  font-family: inherit;
  line-height: 1.2;
}

.btn-primary {
  background: var(--brand-primary);
  color: var(--on-brand);
  font-weight: 600;
}

.btn-primary:hover {
  background: #1642CC;
}

.btn-ghost {
  background: var(--surface-2);
  color: var(--text);
  border-color: var(--surface-2);
}

.btn-ghost:hover {
  border-color: var(--muted);
}

.search-suggestion .btn-primary {
  background: var(--brand-primary);
  color: var(--on-brand);
}

.sidecar-pane {
  background: var(--surface);
  border-left: 1px solid var(--surface-2);
}

.sidecar-overview-pin {
  display: none;
  flex-shrink: 0;
  border-bottom: 1px solid var(--surface-2);
  background: var(--bg);
}

.sidecar-overview-pin.is-visible {
  display: block;
}

.sidecar-overview-label {
  padding: 0.4rem 1rem 0;
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.running-overview {
  display: none;
  padding: 0.35rem 1rem 0.55rem;
  font-size: 0.78rem;
  line-height: 1.4;
  color: var(--text);
  background: var(--bg);
  max-height: min(22vh, 150px);
  overflow-y: auto;
}

.running-overview.has-content {
  display: block;
}

.sidecar-insights-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.sidecar-insights-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.45rem 1rem;
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  border-bottom: 1px solid var(--surface-2);
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 2;
}

.insights-count {
  font-size: 0.62rem;
  padding: 0.1rem 0.4rem;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text);
  letter-spacing: 0;
  font-weight: 600;
}

.insight-cards-list {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  padding: 0.65rem 1rem 1rem;
}

.insight-cards-list:empty {
  display: none;
  padding: 0;
}

.sidecar-insights-scroll .context-card {
  padding: 0;
  overflow: hidden;
}

.insight-card-header {
  display: flex;
  align-items: flex-start;
  gap: 0.35rem;
  padding: 0.55rem 0.65rem;
  border-bottom: 1px solid transparent;
  cursor: pointer;
}

.insight-card.is-collapsed .insight-card-header {
  border-bottom-color: transparent;
}

.insight-card:not(.is-collapsed) .insight-card-header {
  border-bottom-color: var(--surface-2);
}

.insight-drag-handle,
.insight-toggle-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.45rem;
  height: 1.45rem;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  flex-shrink: 0;
}

.insight-drag-handle {
  cursor: grab;
  user-select: none;
  touch-action: none;
}

.insight-drag-handle:active {
  cursor: grabbing;
}

.insight-drag-handle .material-symbols-outlined,
.insight-toggle-btn .material-symbols-outlined {
  font-size: 1.05rem;
  line-height: 1;
}

.insight-drag-handle:hover,
.insight-toggle-btn:hover {
  color: var(--text);
  background: var(--surface-2);
  border-color: var(--surface-2);
}

.insight-toggle-btn .icon-expanded {
  display: none;
}

.insight-card:not(.is-collapsed) .insight-toggle-btn .icon-collapsed {
  display: none;
}

.insight-card:not(.is-collapsed) .insight-toggle-btn .icon-expanded {
  display: inline-flex;
}

.insight-card-heading {
  flex: 1;
  min-width: 0;
}

.insight-card-title {
  font-size: 0.82rem;
  font-weight: 600;
  line-height: 1.35;
  display: flex;
  align-items: center;
  gap: 0.45rem;
  flex-wrap: wrap;
}

.context-card[data-layer="factcheck"] .insight-card-title {
  flex-wrap: wrap;
}

.insight-card-preview {
  margin: 0.28rem 0 0;
  font-size: 0.74rem;
  line-height: 1.4;
  color: var(--muted);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.insight-card:not(.is-collapsed) .insight-card-preview {
  display: none;
}

.insight-card-actions {
  display: flex;
  align-items: flex-start;
  gap: 0.25rem;
  flex-shrink: 0;
}

.insight-card-body {
  padding: 0.55rem 0.65rem 0.65rem;
}

.insight-card.is-collapsed .insight-card-body {
  display: none;
}

.context-card.is-dragging {
  opacity: 0.55;
}

.context-card.is-drop-target {
  box-shadow: inset 0 0 0 2px rgba(61, 156, 245, 0.45);
}

.sidecar-insights-scroll .context-card .card-body {
  font-size: 0.8rem;
  line-height: 1.42;
}

.sidecar-insights-scroll .context-card .card-title {
  font-size: 0.82rem;
}

.running-overview .md-h,
.running-overview h2,
.running-overview h3 {
  font-size: 0.82rem;
  font-weight: 600;
  margin: 0.75rem 0 0.35rem;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.running-overview .md-h:first-child,
.running-overview h2:first-child,
.running-overview h3:first-child {
  margin-top: 0;
}

.running-overview .md-ul,
.running-overview ul {
  margin: 0.25rem 0 0.6rem 1.1rem;
  padding: 0;
}

.running-overview .md-ul li,
.running-overview ul li {
  margin: 0.2rem 0;
  line-height: 1.4;
}

.running-overview .md-p,
.running-overview p {
  margin: 0.35rem 0;
  font-weight: 400;
  color: var(--text);
}

.running-overview strong {
  font-weight: 600;
  color: inherit;
}

.running-overview em {
  font-style: italic;
  color: var(--muted);
}

/* Legacy class kept for any external refs; layout uses .insight-cards-list */
.sidecar-cards {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.context-card {
  padding: 0.85rem 1rem;
  border-radius: 8px;
  background: var(--bg);
  border: 1px solid var(--surface-2);
  transition: border-color 0.15s, opacity 0.15s;
}

.context-card[data-layer="live"] {
  border-left: 3px solid var(--live);
}

.context-card[data-layer="document"] {
  border-left: 3px solid var(--doc);
}

.context-card[data-layer="manual"] {
  border-left: 3px solid var(--manual);
}

.context-card[data-layer="search"] {
  border-left: 3px solid var(--search);
}

.context-card[data-layer="factcheck"] {
  border-left: 3px solid #8b9cb3;
}

.context-card[data-layer="factcheck"] .card-title {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.fact-check-badge {
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  padding: 0.12rem 0.4rem;
  border-radius: 4px;
  background: rgba(139, 156, 179, 0.2);
  color: var(--muted);
  border: 1px solid rgba(139, 156, 179, 0.35);
}

.fact-check-badge[data-verdict="supported"] {
  background: rgba(16, 185, 129, 0.2);
  color: #6ee7b7;
  border-color: rgba(16, 185, 129, 0.35);
}

.fact-check-badge[data-verdict="unsupported"] {
  background: rgba(239, 68, 68, 0.12);
  color: #B91C1C;
  border-color: rgba(239, 68, 68, 0.35);
}

.fact-check-badge[data-verdict="mixed"] {
  background: rgba(255, 85, 0, 0.12);
  color: #C2410C;
  border-color: rgba(255, 85, 0, 0.35);
}

.context-card[data-layer="advice"] {
  border-left: 4px solid var(--advice);
  background: var(--advice-dim);
  box-shadow: none;
}

.context-card[data-layer="advice"] .card-title {
  color: var(--advice);
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.problem-solving-badge,
.advice-card-badge,
.chat-badge {
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  padding: 0.12rem 0.4rem;
  border-radius: 4px;
  background: var(--advice-dim);
  color: var(--advice);
  border: 1px solid rgba(245, 158, 11, 0.35);
}

.chat-badge {
  background: rgba(99, 102, 241, 0.15);
  color: #818cf8;
  border-color: rgba(99, 102, 241, 0.35);
}

.context-card[data-layer="chat"] {
  border-left: 3px solid #818cf8;
}

.context-card[data-layer="chat"] .card-title-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.5rem;
}

.context-card[data-layer="chat"] .card-title-main {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  min-width: 0;
}

.insight-clear-btn {
  display: none;
  width: 1.05rem;
  height: 1.05rem;
  margin-top: 0.05rem;
  padding: 0;
  border: 1.5px solid rgba(255, 255, 255, 0.95);
  border-radius: 999px;
  background: #dc2626;
  color: #fff;
  cursor: pointer;
  line-height: 1;
  flex-shrink: 0;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
}

.insight-clear-btn::before {
  content: "×";
  display: block;
  font-size: 0.82rem;
  font-weight: 800;
  line-height: 0.95rem;
  text-align: center;
}

.context-card.insight-card .insight-clear-btn {
  display: inline-block;
}

.context-card.insight-card .insight-clear-btn:hover {
  background: #b91c1c;
}

.context-card[data-layer="chat"] .insight-clear-btn {
  display: inline-block;
}

.context-card[data-layer="chat"] .insight-clear-btn:hover {
  background: #b91c1c;
}

.context-card[data-layer="chat"] .card-body-md h2,
.context-card[data-layer="chat"] .md-h {
  color: #818cf8;
  font-size: 0.82rem;
  margin-top: 0.65rem;
}

.context-card[data-layer="advice"] .card-body-md h2,
.context-card[data-layer="advice"] .md-h {
  color: var(--advice);
  font-size: 0.82rem;
  margin-top: 0.65rem;
}

.context-card[data-layer="advice"] .card-body-md ol {
  margin: 0.35rem 0 0.5rem 1.2rem;
  padding: 0;
}

.context-card[data-layer="advice"] .card-body-md li {
  margin: 0.25rem 0;
  line-height: 1.45;
}

.context-card .card-sources {
  margin-top: 0.5rem;
  font-size: 0.7rem;
}

.context-card .card-sources a {
  color: var(--search);
  text-decoration: none;
  display: block;
  margin-top: 0.2rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.context-card .card-sources a:hover {
  text-decoration: underline;
}

.context-card .card-sources span {
  color: var(--muted);
  display: block;
  margin-top: 0.2rem;
}

.context-card.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent-dim);
}

.context-card .card-title {
  font-weight: 600;
  font-size: 0.9rem;
  margin-bottom: 0.35rem;
}

.context-card .card-body {
  font-size: 0.85rem;
  color: var(--muted);
  line-height: 1.5;
}

.card-body-md {
  color: var(--text);
}

.card-body-md .md-h {
  margin: 0.65rem 0 0.35rem;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.card-body-md .md-h:first-child {
  margin-top: 0;
}

.card-body-md .md-p {
  margin: 0.35rem 0;
  line-height: 1.55;
}

.card-body-md .md-spacer {
  height: 0.25rem;
}

.card-body-md .md-ul {
  margin: 0.35rem 0 0.5rem 1.1rem;
  padding: 0;
}

.card-body-md .md-ul li {
  margin: 0.25rem 0;
  line-height: 1.45;
}

.card-body-md .md-ol {
  margin: 0.35rem 0 0.5rem 1.1rem;
  padding: 0;
}

.card-body-md .md-ol li {
  margin: 0.25rem 0;
  line-height: 1.45;
}

.card-body-md strong {
  color: var(--text);
  font-weight: 600;
}

.card-body-md em {
  color: var(--muted);
  font-style: italic;
}

.card-body-md .md-table {
  width: 100%;
  border-collapse: collapse;
  margin: 0.5rem 0;
  font-size: 0.78rem;
}

.card-body-md .md-table th,
.card-body-md .md-table td {
  border: 1px solid var(--surface-2);
  padding: 0.35rem 0.5rem;
  text-align: left;
  vertical-align: top;
}

.card-body-md .md-table th {
  background: var(--surface-2);
  color: var(--text);
  font-weight: 600;
}

.context-card .card-source {
  margin-top: 0.5rem;
  font-size: 0.7rem;
  font-family: var(--mono);
  color: var(--muted);
  opacity: 0.8;
}

.lead-lines {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 10;
  overflow: visible;
}

.lead-lines path {
  fill: none;
  stroke: var(--line);
  stroke-width: 2;
  opacity: 0;
  transition: opacity 0.2s;
}

.lead-lines path.visible {
  opacity: 0.85;
}

.lead-lines path.visible.flash {
  animation: lead-line-flash 1s ease-in-out infinite;
}

@keyframes lead-line-flash {
  0%,
  100% {
    opacity: 0.55;
    stroke-width: 2;
  }
  50% {
    opacity: 1;
    stroke-width: 3;
  }
}

@media (max-width: 1100px) {
  .notes-rail {
    width: 180px;
  }
}

@media (max-width: 1024px) {
  .notes-rail {
    width: 200px;
  }
}

@media (max-width: 860px) {
  .app-body {
    flex-direction: column;
  }
  .notes-rail {
    width: 100%;
    max-height: 120px;
    flex-shrink: 0;
    border-right: none;
    border-bottom: 1px solid var(--surface-2);
  }
  .notes-list {
    display: flex;
    flex-direction: row;
    gap: 0.35rem;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 0.5rem;
  }
  .note-item {
    min-width: 140px;
    margin-bottom: 0;
    flex-shrink: 0;
  }
  .workspace {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 1.2fr) minmax(0, 1fr);
  }
  .workspace.sidecar-collapsed {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 1fr) auto;
  }
  .sidecar-pane {
    border-left: none;
    border-top: 1px solid var(--surface-2);
  }
  .sidecar-pane.is-collapsed {
    min-height: 0;
    max-height: none;
  }
  .sidecar-pane.is-collapsed .sidecar-accordion-trigger {
    flex-direction: row;
    writing-mode: horizontal-tb;
    height: auto;
    width: 100%;
    padding: 0.5rem 1rem;
    border-bottom: 1px solid var(--surface-2);
  }
  .sidecar-pane.is-collapsed .sidecar-accordion-trigger .scoped-badge {
    margin-left: auto;
  }
  .documents-page .documents-layout {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 1fr) minmax(0, 1fr);
  }
  .lead-lines {
    display: none;
  }
}

/* Login */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--bg);
}

.login-card {
  width: min(400px, 92vw);
  padding: 2rem;
  background: var(--surface);
  border: 1px solid var(--surface-2);
  border-radius: 10px;
}

.login-sub {
  color: var(--muted);
  margin: 0 0 1.25rem;
  font-size: 0.9rem;
}

.login-form label {
  display: block;
  margin-bottom: 0.75rem;
  font-size: 0.85rem;
}

.login-form input {
  display: block;
  width: 100%;
  margin-top: 0.25rem;
  padding: 0.45rem 0.6rem;
  border-radius: 6px;
  border: 1px solid var(--border-neutral);
  background: var(--bg-surface);
  color: var(--text-primary);
}

.login-error {
  color: #f87171;
  font-size: 0.85rem;
}

.login-hint {
  margin-top: 1rem;
  font-size: 0.75rem;
  color: var(--muted);
}

.user-label {
  font-size: 0.8rem;
  color: var(--muted);
  margin-right: 0.5rem;
}

.shared-badge {
  font-size: 0.7rem;
  color: var(--accent);
  margin-left: 0.2rem;
}

html:has(body.settings-page) {
  overflow-x: hidden;
}

body.settings-page {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  overflow-y: auto;
}

.settings-main {
  flex: 1;
}

.settings-page .settings-main {
  padding: 1.5rem;
  max-width: 920px;
}

.settings-panel {
  background: var(--surface);
  border: 1px solid var(--surface-2);
  border-radius: 8px;
  padding: 1.25rem;
}

.settings-desc {
  color: var(--muted);
  font-size: 0.88rem;
}

.settings-form label {
  display: block;
  margin: 0.75rem 0;
  font-size: 0.85rem;
}

.settings-form input[type="text"],
.settings-form input[type="password"],
.settings-form input[type="email"] {
  display: block;
  width: 100%;
  margin-top: 0.25rem;
  padding: 0.4rem 0.55rem;
  border-radius: 6px;
  border: 1px solid var(--surface-2);
  background: var(--bg);
  color: var(--text);
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.share-form label {
  display: block;
  margin: 0.5rem 0;
  font-size: 0.85rem;
}

.share-dialog-hint {
  margin: 0 0 0.75rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.share-list-empty {
  padding: 0.5rem 0;
  font-size: 0.85rem;
  color: var(--muted);
}

.share-list {
  list-style: none;
  margin: 1rem 0 0;
  padding: 0;
}

.share-list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.35rem 0;
  font-size: 0.85rem;
  border-bottom: 1px solid var(--surface-2);
}

.settings-panel + .settings-panel {
  margin-top: 1.25rem;
}

.settings-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
}

.settings-subhead {
  margin: 0 0 0.75rem;
  font-size: 0.95rem;
}

.admin-user-form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0 1rem;
}

.admin-users-table-wrap {
  margin-top: 1.25rem;
  overflow-x: auto;
}

.admin-users-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.admin-users-table th,
.admin-users-table td {
  padding: 0.55rem 0.65rem;
  text-align: left;
  border-bottom: 1px solid var(--surface-2);
}

.admin-users-table th {
  color: var(--muted);
  font-weight: 600;
}

.admin-users-empty {
  color: var(--muted);
  text-align: center;
  padding: 1rem;
}

.admin-users-actions {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  white-space: nowrap;
}

.admin-self-hint {
  font-size: 0.75rem;
  color: var(--muted);
}

.role-pill {
  display: inline-block;
  padding: 0.12rem 0.45rem;
  border-radius: 999px;
  font-size: 0.72rem;
  background: var(--surface-2);
  color: var(--muted);
}

.role-pill.role-admin {
  background: rgba(96, 165, 250, 0.15);
  color: #93c5fd;
}

.btn-sm {
  padding: 0.25rem 0.55rem;
  font-size: 0.78rem;
}

.inline-badge {
  position: static;
  margin-left: 0.35rem;
  vertical-align: middle;
}

/* --- Overview doc page --- */

html:has(body.overview-page),
body.overview-page {
  overflow-x: hidden;
  overflow-y: auto;
  height: auto;
  min-height: 100%;
}

.overview-main {
  max-width: 920px;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 3rem;
}

.overview-hero {
  margin-bottom: 2rem;
}

.overview-hero h1 {
  margin: 0 0 0.75rem;
  font-size: 1.75rem;
  letter-spacing: -0.02em;
}

.overview-lead {
  color: var(--muted);
  font-size: 1.05rem;
  line-height: 1.55;
  margin: 0;
}

.overview-toc {
  background: var(--surface);
  border: 1px solid var(--surface-2);
  border-radius: 8px;
  padding: 1.25rem 1.5rem;
  margin-bottom: 2.5rem;
}

.overview-toc h2 {
  margin: 0 0 0.75rem;
  font-size: 1rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.overview-toc ol {
  margin: 0;
  padding-left: 1.25rem;
  columns: 2;
  column-gap: 2rem;
}

@media (max-width: 640px) {
  .overview-toc ol {
    columns: 1;
  }
}

.overview-toc li {
  margin: 0.35rem 0;
  break-inside: avoid;
}

.overview-section {
  margin-bottom: 2.5rem;
  scroll-margin-top: 1rem;
}

.overview-section h2 {
  margin: 0 0 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--surface-2);
  font-size: 1.35rem;
}

.overview-section h3 {
  margin: 1.5rem 0 0.65rem;
  font-size: 1.05rem;
  color: var(--text);
}

.overview-section p,
.overview-section li {
  line-height: 1.6;
  color: var(--text);
}

.overview-section ul,
.overview-section ol {
  padding-left: 1.35rem;
}

.overview-section li {
  margin: 0.35rem 0;
}

.overview-table-wrap {
  overflow-x: auto;
  margin: 1rem 0;
}

.overview-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.overview-table th,
.overview-table td {
  border: 1px solid var(--surface-2);
  padding: 0.55rem 0.75rem;
  text-align: left;
  vertical-align: top;
}

.overview-table th {
  background: var(--surface);
  font-weight: 600;
}

.overview-table tbody tr:nth-child(even) {
  background: rgba(248, 250, 252, 0.85);
}

.overview-table code {
  font-family: var(--mono);
  font-size: 0.85em;
}

.overview-pre {
  background: var(--surface);
  border: 1px solid var(--surface-2);
  border-radius: 8px;
  padding: 1rem 1.1rem;
  overflow-x: auto;
  font-family: var(--mono);
  font-size: 0.78rem;
  line-height: 1.45;
  color: var(--muted);
  margin: 1rem 0;
}

.overview-diagram {
  background: var(--surface);
  border: 1px solid var(--surface-2);
  border-radius: 8px;
  padding: 1.25rem;
  margin: 1rem 0;
  overflow-x: auto;
}

.overview-diagram .mermaid {
  display: flex;
  justify-content: center;
}

.overview-callout {
  background: var(--accent-dim);
  border-left: 3px solid var(--accent);
  border-radius: 0 6px 6px 0;
  padding: 0.85rem 1rem;
  margin: 1rem 0;
  font-size: 0.92rem;
}

.overview-footer {
  margin-top: 2rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border-neutral);
  color: var(--muted);
  font-size: 0.88rem;
}

.app-footer {
  flex-shrink: 0;
  padding: 0.55rem 1rem;
  border-top: 1px solid var(--border-neutral);
  background: var(--bg-surface);
  color: var(--muted);
  font-size: 0.75rem;
  text-align: center;
}

.login-page .app-footer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
}

.login-card .logo-link {
  display: flex;
  justify-content: center;
  margin-bottom: 0.75rem;
}

.login-card .logo-link .logo {
  height: 2.5rem;
  max-width: min(13rem, 75vw);
}

.overview-api-list {
  list-style: none;
  padding: 0;
  margin: 0.5rem 0;
}

.overview-api-list li {
  padding: 0.35rem 0;
  border-bottom: 1px solid var(--border-neutral);
  font-family: var(--mono);
  font-size: 0.85rem;
}

.overview-api-list li:last-child {
  border-bottom: none;
}

.overview-principles {
  counter-reset: principle;
  list-style: none;
  padding: 0;
}

.overview-principles li {
  counter-increment: principle;
  position: relative;
  padding-left: 2rem;
  margin: 0.75rem 0;
}

.overview-principles li::before {
  content: counter(principle);
  position: absolute;
  left: 0;
  top: 0.1rem;
  width: 1.35rem;
  height: 1.35rem;
  border-radius: 999px;
  background: var(--accent-dim);
  color: var(--accent);
  font-size: 0.75rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}
