/* Knowledge capture v1: app styles on top of the shared SDI Lab ui.css. */

:root {
  /* Graph identity colours (validated categorical slots 1-3). */
  --series-person: #2a78d6;
  --series-project: #eb6834;
  --series-decision: #1baf7a;
}
@media (prefers-color-scheme: dark) {
  :root {
    --series-person: #3987e5;
    --series-project: #d95926;
    --series-decision: #199e70;
  }
}

/* The hidden attribute must win over component display rules (e.g. .btn is inline-flex). */
[hidden] { display: none !important; }

.visually-hidden, .done-mark {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0);
  white-space: nowrap; border: 0;
}
.skip-link { position: absolute; left: -9999px; top: 0; }
.skip-link:focus { left: 8px; top: 8px; z-index: 20; background: var(--surface); padding: 6px 10px; border-radius: var(--radius-small); }

.topbar .app-home { color: var(--text); text-decoration: none; }
.topbar .app-home:hover { text-decoration: underline; }

/* ---- Capture badge: a dot and "Capturing" / "Paused"; the link around it is the tap target ---- */
.status-link { display: inline-flex; align-items: center; text-decoration: none; }
.status-badge { display: inline-flex; align-items: center; gap: 6px; }
.status-link:hover .status-text { text-decoration: underline; }
.status-dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: currentColor; flex: none; }

/* The top bar is sticky above 640 px only (ui.css); anchors must clear it there. */
@media (min-width: 641px) { [id] { scroll-margin-top: 72px; } }

.section-gap { margin-top: 20px; }
.no-margin { margin: 0; }
.kpi-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); margin-top: 16px; }

/* ---- Ask ---- */
.ask-form { display: flex; flex-wrap: wrap; gap: 8px; align-items: stretch; }
.ask-form input { flex: 1 1 200px; min-width: 0; }
.ask-form .btn { flex: 0 0 auto; }
.ask-card .chips { margin-top: 12px; }
.chips { list-style: none; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex; align-items: center; min-height: 40px; padding: 4px 14px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--border);
  color: var(--text); text-decoration: none; font-size: 0.9rem;
}
.chip:hover { border-color: var(--accent); }
.chip[aria-current="true"] { background: var(--accent-weak); border-color: var(--accent); color: var(--accent); font-weight: 600; }
.answer-head { gap: 8px; margin-bottom: 8px; }
#answer[aria-busy="true"] { opacity: 0.6; transition: opacity 120ms ease; }
.weak-note { color: var(--warn); font-weight: 600; margin-bottom: 6px; }
.passages { list-style: none; padding: 0; margin: 0; }
.passage + .passage { border-top: 1px solid var(--border); }
.passage-head { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; min-height: 40px; padding: 4px 0; color: var(--text); text-decoration: none; }
/* Citations (same pattern as the on-site AI box): "▸ [1] Title", the passage opens below. */
summary.passage-head { list-style: none; cursor: pointer; flex-wrap: nowrap; align-items: baseline; padding: 9px 0; }
summary.passage-head::-webkit-details-marker { display: none; }
/* A chevron drawn with borders: points right, turns down when open. */
summary.passage-head::before {
  content: ""; flex: none; width: 7px; height: 7px; margin: 0 4px 0 2px;
  border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted);
  rotate: -45deg; translate: 0 -2px; transition: rotate 150ms ease;
}
details[open] > summary.passage-head::before { rotate: 45deg; }
summary.passage-head:hover .passage-title { text-decoration: underline; text-underline-offset: 2px; }
.passage-title { flex: 1; }
.cite { font-weight: 700; color: var(--muted); font-variant-numeric: tabular-nums; flex: none; }
.open-note { display: inline-flex; align-items: center; min-height: 40px; margin-bottom: 4px; }
.passage-text {
  margin: 2px 0 10px; padding: 10px 12px;
  border-left: 3px solid var(--accent); background: var(--surface-2);
  border-radius: 0 var(--radius-small) var(--radius-small) 0;
  white-space: pre-line; overflow-wrap: anywhere;
}

/* ---- Lists and tables where the whole row is the link ---- */
.link-list { list-style: none; padding: 0; margin: 0; }
.link-list > li + li { border-top: 1px solid var(--border); }
.row-link { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 40px; padding: 6px 0; color: var(--text); text-decoration: none; }
.row-link .row-main { color: var(--accent); }
a.row-link:hover .row-main { text-decoration: underline; text-underline-offset: 2px; }
.row-links tbody tr { position: relative; }
.row-links a.row-target::after { content: ""; position: absolute; inset: 0; }

/* ---- Sources: switch, add form + preview, log ---- */
.add-head { gap: 10px 16px; }
.pause-form { gap: 10px; margin: 0; }
.pause-form .switch { font-weight: 600; }
.paused-note { color: var(--warn); font-weight: 600; margin: 10px 0 0; }
.add-grid { display: grid; gap: 20px; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); margin-top: 14px; align-items: start; }
.preview { border-left: 1px solid var(--border); padding-left: 20px; min-width: 0; }
.preview h3 { margin-bottom: 8px; }
#preview[aria-busy="true"] { opacity: 0.6; transition: opacity 120ms ease; }
.preview-title { margin-bottom: 8px; overflow-wrap: anywhere; }
.preview-list { margin: 0; }
.preview-list dt { font-weight: 600; font-size: 0.9rem; margin-top: 8px; }
.preview-list dd { margin: 2px 0 0; overflow-wrap: anywhere; }
.preview-list ul { margin: 0; padding-left: 18px; }
.preview-list li + li { margin-top: 2px; }
.preview-state.problem { color: var(--bad); }
.preview-state.muted { color: var(--muted); }
.unknown-owner { color: var(--warn); }
.log-table td { overflow-wrap: anywhere; }
.privacy summary, .links-table summary { font-weight: 600; padding: 8px 0; min-height: 40px; }
.privacy h3 { margin-top: 12px; }

/* ---- Footer: quiet reset link, in line with "All demos" ---- */
.footer { align-items: center; }
.inline-form { display: inline-flex; margin: 0; }
.link-button { display: inline-flex; align-items: center; background: none; border: 0; padding: 0; font: inherit; color: var(--muted); text-decoration: underline; text-underline-offset: 2px; cursor: pointer; }
.link-button:hover { color: var(--text); }

/* ---- Notes ---- */
.filter-form { margin-bottom: 12px; }
.filter-form input[type="search"] { flex: 1; min-width: 0; max-width: 360px; }
.note-links { display: flex; align-items: center; gap: 8px; }
.note-links a { color: var(--muted); }
.tabs a { gap: 5px; }
.md details.fold { margin: 1.4em 0 0.5em; }
.md details.fold > summary { font-weight: 700; font-size: 1.08rem; padding-bottom: 4px; border-bottom: 1px solid var(--border); }
.note-body { max-width: 820px; }

/* Rendered Markdown */
.md { overflow-wrap: anywhere; }
.md > :first-child { margin-top: 0; }
.md h2 { font-size: 1.08rem; margin: 1.4em 0 0.5em; padding-bottom: 4px; border-bottom: 1px solid var(--border); }
.md h3, .md h4, .md h5, .md h6 { font-size: 0.98rem; margin: 1.2em 0 0.4em; }
.md ul, .md ol { padding-left: 22px; margin: 0 0 0.75rem; }
.md li + li { margin-top: 3px; }
.md li:has(.done-mark) { color: var(--muted); text-decoration: line-through; }
.md li:has(.done-mark) a { color: inherit; }
.md blockquote { margin: 0 0 0.75rem; padding: 8px 12px; border-left: 3px solid var(--border); background: var(--surface-2); border-radius: 0 var(--radius-small) var(--radius-small) 0; }
.md blockquote p:last-child { margin: 0; }
.md table { border-collapse: collapse; margin: 0 0 0.75rem; display: block; overflow-x: auto; }
.md th, .md td { border: 1px solid var(--border); padding: 5px 9px; text-align: left; font-size: 0.9rem; }
.md th { background: var(--surface-2); }
.md code { background: var(--surface-2); padding: 1px 4px; border-radius: 4px; }
.md pre code { background: none; padding: 0; }
.md-image { color: var(--muted); font-style: italic; }
.md-fallback { white-space: pre-wrap; overflow-wrap: anywhere; max-height: 480px; overflow: auto; }

/* ---- Graph ---- */
.graph-card { padding: 8px; }
.graph-tools { display: flex; padding: 4px 4px 0; }
.graph-tools input { flex: 1 1 220px; min-width: 0; max-width: 420px; }
.graph-status { margin: 4px 8px 0; min-height: 1.2em; }
.graph-canvas { width: 100%; height: 580px; }
.graph-loading { display: grid; place-items: center; height: 100%; margin: 0; }

@media (max-width: 860px) {
  .add-grid { grid-template-columns: 1fr; }
  .preview { border-left: 0; padding-left: 0; border-top: 1px solid var(--border); padding-top: 14px; }
}
@media (max-width: 640px) {
  /* Tap targets of at least 40px for this app's own controls */
  .status-link, .link-button, .breadcrumb a, .note-links a, .show-all { min-height: 40px; }
  .show-all { display: inline-flex; align-items: center; }
  .breadcrumb a { display: inline-flex; align-items: center; }
  /* Compact enough to stay on the first row next to the app name and "!" */
  .topbar .status-badge { gap: 4px; padding: 1px 6px; font-size: 0.72rem; }
  /* Note-type tabs: one row that scrolls sideways */
  .tabs { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .tabs::-webkit-scrollbar { display: none; }
  .tabs a { white-space: nowrap; flex: none; }
  .graph-canvas { height: 440px; }
  .table th, .table td { padding: 7px 9px; }
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .log-table .date-part { display: none; }
}
