/* ── Library settings page ── */

:root {
  --library-color-company: #3b82f6;
  --library-color-team: #8b5cf6;
  --library-color-technical: #d97706;
  --library-color-process: #079455;
  --library-color-priorities: #ef4444;
  --library-color-custom: #999;
  --library-color-divider: rgba(0, 0, 0, 0.04);
  --library-color-hover: rgba(0, 0, 0, 0.03);
  --library-color-inline-code-bg: rgba(0, 0, 0, 0.04);
  --library-color-subtle-surface: rgba(0, 0, 0, 0.02);
  --library-color-priority-subtle: rgba(217, 119, 6, 0.08);
  --library-color-success-subtle: rgba(7, 148, 85, 0.08);
  --library-color-badge-subtle: rgba(0, 0, 0, 0.04);
  --library-color-code-surface: #f8f8f8;
  --library-color-chevron: #ccc;
}

/* ── Header area ── */
.library-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
}

.library-header-left h1 {
  font-size: 26px;
  font-weight: 700;
  color: var(--color-text-primary);
  margin: 0;
  letter-spacing: -0.01em;
}

.library-header-left p {
  font-size: 13px;
  color: var(--color-text-muted);
  margin: 4px 0 0;
}

.library-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

/* ── Search ── */
.library-search-wrap {
  position: relative;
  width: 100%;
  display: block;
  margin-bottom: 20px;
}

.library-search-icon {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--color-text-muted);
  pointer-events: none;
}

.library-search {
  width: 100%;
  padding: 6px 10px 6px 30px;
  background: var(--color-input-bg);
  border: 1px solid var(--color-border);
  border-radius: 6px;
  font-size: 12px;
  font-family: inherit;
  color: var(--color-text-primary);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.library-search:focus {
  border-color: var(--color-brand);
  box-shadow: 0 0 0 2px var(--color-brand-subtle);
}

.library-search::placeholder {
  color: var(--color-text-muted);
}

/* ── Tabs ── */
.library-tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--color-border);
  margin-bottom: 20px;
}

.library-tab {
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 500;
  color: var(--color-text-muted);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  transition: color 0.1s, border-color 0.1s;
  font-family: inherit;
  margin-bottom: -1px;
}

.library-tab:hover {
  color: var(--color-text-secondary);
}

.library-tab.active {
  color: var(--color-text-primary);
  border-bottom-color: var(--color-brand);
}

.library-tab-count {
  font-size: 11px;
  color: var(--color-text-muted);
  margin-left: 4px;
  font-weight: 400;
}

/* ── Category sections ── */
.library-category {
  margin-bottom: 24px;
}

.library-category-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0 0 8px;
  border-bottom: 1px solid var(--color-border);
  margin-bottom: 2px;
}

/* ── Document row ── */
.library-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  text-decoration: none;
  color: inherit;
  border-radius: 6px;
  transition: background 0.08s;
  cursor: pointer;
}

.library-row:hover {
  background: var(--color-hover, var(--library-color-hover));
}

.library-row:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px var(--color-brand-subtle);
  background: var(--color-hover, var(--library-color-hover));
}

.library-row + .library-row {
  border-top: 1px solid var(--library-color-divider);
}

.library-row-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
}

.library-row-dot-company {
  background: var(--library-color-company);
}

.library-row-dot-team {
  background: var(--library-color-team);
}

.library-row-dot-technical {
  background: var(--library-color-technical);
}

.library-row-dot-process {
  background: var(--library-color-process);
}

.library-row-dot-priorities {
  background: var(--library-color-priorities);
}

.library-row-dot-custom {
  background: var(--library-color-custom);
}

.library-row-priority {
  width: 16px;
  flex-shrink: 0;
  text-align: center;
}

.library-row-priority svg {
  width: 12px;
  height: 12px;
  color: var(--library-color-technical);
}

.library-row-body {
  flex: 1;
  min-width: 0;
}

.library-row-title {
  font-size: 13px;
  font-weight: 500;
  color: var(--color-text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.library-row-desc {
  font-size: 12px;
  color: var(--color-text-muted);
  margin-top: 1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.library-row-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.library-row-date {
  font-size: 11px;
  color: var(--color-text-muted);
  white-space: nowrap;
}

.library-row-author {
  font-size: 11px;
  color: var(--color-text-muted);
  white-space: nowrap;
}

.library-row-chevron {
  width: 14px;
  height: 14px;
  color: var(--library-color-chevron);
  flex-shrink: 0;
}

.library-revision-change-badge {
  display: inline-block;
  font-size: 11px;
  color: var(--color-text-muted, #999);
  margin-top: 2px;
}

/* ── Empty state ── */
.library-empty {
  text-align: center;
  padding: 48px 24px;
  color: var(--color-text-muted);
}

.library-empty-icon {
  width: 48px;
  height: 48px;
  margin: 0 auto 16px;
  color: var(--color-text-muted);
  opacity: 0.3;
}

.library-empty-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--color-text-secondary);
  margin: 0 0 6px;
}

.library-empty-desc {
  font-size: 13px;
  color: var(--color-text-muted);
  margin: 0 0 16px;
  max-width: 360px;
  margin-left: auto;
  margin-right: auto;
}

/* ── On-demand toggle (bottom) ── */
.library-toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  border-top: 1px solid var(--color-border);
  margin-top: 24px;
}

.library-toggle-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.library-toggle-label {
  font-size: 13px;
  font-weight: 500;
  color: var(--color-text-primary);
}

.library-toggle-hint {
  font-size: 12px;
  color: var(--color-text-muted);
}

.library-toggle-status {
  display: flex;
  align-items: center;
  gap: 8px;
}

.library-badge-enabled {
  font-size: 11px;
  font-weight: 500;
  padding: 2px 8px;
  border-radius: 10px;
  background: var(--library-color-success-subtle);
  color: var(--library-color-process);
}

.library-toggle-disable {
  font-size: 12px;
  color: var(--color-text-muted);
  background: none;
  border: none;
  cursor: pointer;
  font-family: inherit;
  padding: 2px 6px;
  border-radius: 4px;
  transition: color 0.1s, background 0.1s;
}

.library-toggle-disable:hover {
  color: var(--color-text-secondary);
  background: var(--color-hover);
}

/* ── Recent activity feed ── */
.library-recent-list {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.library-recent-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--library-color-divider);
}

.library-recent-item:last-child {
  border-bottom: none;
}

.library-recent-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  margin-top: 6px;
  flex-shrink: 0;
}

.library-recent-dot-created { background: var(--library-color-process); }
.library-recent-dot-updated { background: var(--library-color-company); }
.library-recent-dot-archived { background: var(--library-color-custom); }

.library-recent-body {
  flex: 1;
  min-width: 0;
}

.library-recent-title {
  font-size: 13px;
  font-weight: 500;
  color: var(--color-text-primary);
}

.library-recent-title a {
  color: inherit;
  text-decoration: none;
}

.library-recent-title a:hover {
  text-decoration: underline;
}

.library-recent-action {
  font-size: 12px;
  font-weight: 400;
  color: var(--color-text-muted);
}

.library-recent-meta {
  font-size: 11px;
  color: var(--color-text-muted);
  margin-top: 2px;
}

/* ── Show page ── */
.library-detail-header {
  margin-bottom: 24px;
}

.library-detail-back {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  color: var(--color-text-muted);
  text-decoration: none;
  margin-bottom: 12px;
  transition: color 0.1s;
}

.library-detail-back:hover {
  color: var(--color-text-secondary);
}

.library-detail-back svg {
  width: 14px;
  height: 14px;
}

.library-detail-title-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.library-detail-title {
  font-size: 22px;
  font-weight: 700;
  color: var(--color-text-primary);
  margin: 0;
  letter-spacing: -0.01em;
}

.library-detail-badges {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
}

.library-badge {
  font-size: 11px;
  font-weight: 500;
  padding: 2px 8px;
  border-radius: 10px;
}

.library-badge-category {
  background: var(--library-color-badge-subtle);
  color: var(--color-text-secondary);
}

.library-badge-priority {
  background: var(--library-color-priority-subtle);
  color: var(--library-color-technical);
}

.library-detail-meta {
  font-size: 12px;
  color: var(--color-text-muted);
  margin-top: 6px;
}

.library-detail-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

/* ── Detail tabs ── */
.library-detail-tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--color-border);
  margin-bottom: 20px;
}

.library-detail-tab {
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 500;
  color: var(--color-text-muted);
  text-decoration: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: color 0.1s;
}

.library-detail-tab:hover {
  color: var(--color-text-secondary);
}

.library-detail-tab.active {
  color: var(--color-text-primary);
  border-bottom-color: var(--color-brand);
}

/* ── Content area ── */
.library-content {
  max-width: 720px;
  font-size: 14px;
  line-height: 1.7;
  color: var(--color-text-primary);
}

.library-content h1, .library-content h2, .library-content h3 {
  margin: 20px 0 8px;
  color: var(--color-text-primary);
}

.library-content h1 { font-size: 20px; font-weight: 700; }
.library-content h2 { font-size: 17px; font-weight: 600; }
.library-content h3 { font-size: 15px; font-weight: 600; }

.library-content p {
  margin: 0 0 12px;
}

.library-content ul, .library-content ol {
  margin: 0 0 12px;
  padding-left: 24px;
}

.library-content li {
  margin-bottom: 4px;
}

.library-content code {
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 0.9em;
  padding: 1px 5px;
  background: var(--library-color-inline-code-bg);
  border-radius: 4px;
}

.library-content pre {
  background: var(--library-color-code-surface);
  padding: 12px 16px;
  border-radius: 8px;
  overflow-x: auto;
  margin: 0 0 12px;
}

.library-content pre code {
  background: none;
  padding: 0;
}

.library-content table {
  width: 100%;
  border-collapse: collapse;
  margin: 0 0 12px;
  font-size: 13px;
}

.library-content th, .library-content td {
  padding: 6px 10px;
  border: 1px solid var(--color-border);
  text-align: left;
}

.library-content th {
  font-weight: 600;
  background: var(--library-color-subtle-surface);
}

.library-content strong {
  font-weight: 600;
}

/* ── No results (search) ── */
.library-no-results {
  text-align: center;
  padding: 24px;
  font-size: 13px;
  color: var(--color-text-muted);
  display: none;
}

/* ── Tab panels ── */
.library-tab-panel {
  display: none;
}

.library-tab-panel.active {
  display: block;
}

/* ── History (on show page) ── */
.library-revision-list {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.library-revision-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--library-color-divider);
}

.library-revision-row:last-child {
  border-bottom: none;
}

.library-revision-number {
  font-size: 12px;
  font-weight: 600;
  color: var(--color-text-muted);
  min-width: 24px;
}

.library-revision-body {
  flex: 1;
  min-width: 0;
}

.library-revision-author {
  font-size: 13px;
  font-weight: 500;
  color: var(--color-text-primary);
}

.library-revision-date {
  font-size: 12px;
  color: var(--color-text-muted);
  margin-top: 1px;
}

.library-revision-source {
  font-size: 11px;
  color: var(--color-text-muted);
}

.library-revision-actions {
  flex-shrink: 0;
}

/* ──────────────────────────────────────────────────────────────────
 * Revision diff
 *
 * Used by library docs (prose) and connector skill files (code).
 * Typography is inherited from the container by default so library
 * diffs read like the documents they describe. Use --code modifier
 * for actual source files where monospace communicates intent.
 * ────────────────────────────────────────────────────────────────── */

.revision-diff {
  --diff-del-fg: #991b1b;
  --diff-del-bg: rgba(220, 38, 38, 0.07);
  --diff-del-bg-strong: rgba(220, 38, 38, 0.22);
  --diff-ins-fg: #166534;
  --diff-ins-bg: rgba(22, 163, 74, 0.07);
  --diff-ins-bg-strong: rgba(22, 163, 74, 0.22);
  --diff-fold-color: var(--color-text-muted, #6b7280);
  --diff-gutter-color: color-mix(in srgb, var(--color-text-muted, #6b7280) 60%, transparent);

  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
  line-height: 1.55;
  color: var(--color-text-primary, #111);
  margin: 10px 0 4px;
}

.revision-diff--prose {
  font-family: inherit; /* Inter / system reading stack */
}

.revision-diff--code {
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 12.5px;
  line-height: 1.5;
}

.revision-diff--empty {
  padding: 10px 14px;
  color: var(--color-text-muted);
  background: var(--library-color-subtle-surface, rgba(0, 0, 0, 0.02));
  border-radius: 6px;
  font-size: 13px;
}

/* Hunk: a group of related lines. Bordered on the left to signal a
 * change region without wrapping the whole thing in a card. */
.revision-diff-hunk {
  display: flex;
  flex-direction: column;
  border-left: 2px solid var(--color-border, rgba(0, 0, 0, 0.08));
  padding: 2px 0;
}

.revision-diff-hunk:has(.revision-diff-line--del),
.revision-diff-hunk:has(.revision-diff-line--ins) {
  border-left-color: color-mix(in srgb, var(--diff-ins-fg) 50%, transparent);
}

/* Line: gutter(old) · gutter(new) · mark · content */
.revision-diff-line {
  display: grid;
  grid-template-columns: 36px 36px 16px 1fr;
  column-gap: 0;
  padding: 1px 0 1px 10px;
}

.revision-diff-line--del {
  background: var(--diff-del-bg);
}

.revision-diff-line--ins {
  background: var(--diff-ins-bg);
}

.revision-diff-gutter {
  text-align: right;
  padding-right: 10px;
  color: var(--diff-gutter-color);
  font-variant-numeric: tabular-nums;
  font-size: 11px;
  line-height: 1.55;
  user-select: none;
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", Menlo, monospace;
}

.revision-diff-mark {
  text-align: center;
  font-weight: 600;
  user-select: none;
  color: var(--diff-gutter-color);
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 12px;
}

.revision-diff-line--del .revision-diff-mark { color: var(--diff-del-fg); }
.revision-diff-line--ins .revision-diff-mark { color: var(--diff-ins-fg); }

.revision-diff-content {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  min-width: 0;
}

.revision-diff-line--del .revision-diff-content { color: var(--diff-del-fg); }
.revision-diff-line--ins .revision-diff-content { color: var(--diff-ins-fg); }

/* Word-level intra-line highlights — stronger background inside line bg */
.revision-diff-word {
  background: transparent;
  color: inherit;
  border-radius: 2px;
  padding: 0 1px;
}

.revision-diff-word--del { background: var(--diff-del-bg-strong); }
.revision-diff-word--ins { background: var(--diff-ins-bg-strong); }

/* Fold pill between hunks — signals "nothing interesting here" */
.revision-diff-fold {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  color: var(--diff-fold-color);
  padding: 4px 0 4px 12px;
  font-variant-numeric: tabular-nums;
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", Menlo, monospace;
}

.revision-diff-fold::before {
  content: "···";
  font-weight: 600;
  letter-spacing: 0.05em;
}

/* Summary chrome: a plain disclosure affordance, not a code widget. */
.revision-changes {
  margin-top: 10px;
}

.revision-changes > summary {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  list-style: none;
  cursor: pointer;
  color: var(--color-text-primary);
  font-size: 13px;
  font-weight: 500;
  padding: 4px 10px 4px 8px;
  border-radius: 6px;
  user-select: none;
  transition: background 120ms ease;
}

.revision-changes > summary::-webkit-details-marker { display: none; }

.revision-changes > summary::before {
  content: "";
  width: 0;
  height: 0;
  border-left: 4px solid currentColor;
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
  transition: transform 160ms ease;
  opacity: 0.55;
}

.revision-changes[open] > summary::before {
  transform: rotate(90deg);
}

.revision-changes > summary:hover {
  background: var(--library-color-hover, rgba(0, 0, 0, 0.03));
}

.revision-changes-stat {
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: var(--color-text-muted);
  font-weight: 500;
}

.revision-changes-stat--add { color: var(--diff-ins-fg); }
.revision-changes-stat--del { color: var(--diff-del-fg); }

/* Mobile: tighter gutter, word-wrap takes priority */
@media (max-width: 640px) {
  .revision-diff-line {
    grid-template-columns: 28px 28px 14px 1fr;
    padding-left: 6px;
  }
  .revision-diff-gutter { padding-right: 6px; font-size: 10.5px; }
  .revision-diff { font-size: 12.5px; }
}

/* Dark-mode token participation */
@media (prefers-color-scheme: dark) {
  .revision-diff {
    --diff-del-fg: #fca5a5;
    --diff-del-bg: rgba(220, 38, 38, 0.12);
    --diff-del-bg-strong: rgba(220, 38, 38, 0.32);
    --diff-ins-fg: #86efac;
    --diff-ins-bg: rgba(22, 163, 74, 0.12);
    --diff-ins-bg-strong: rgba(22, 163, 74, 0.32);
  }
}
