/* skills-viewer.css — styles for the skills viewer component */
/* Uses the same CSS variables as loglog-viewer.css */

/* ── Variable aliases (mirror loglog-viewer.css) ── */
.sv-root {
  --bg2: var(--header-bg);
  --bg3: var(--border);
  --bd:  var(--border);
  --txt: var(--text);
  --txt2: var(--text-muted);
  --acc: var(--link);
  --blue: var(--link);
}

/* ── Scrollbar ── */
.sv-root ::-webkit-scrollbar { width: 6px; height: 6px; }
.sv-root ::-webkit-scrollbar-track { background: transparent; }
.sv-root ::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
.sv-root ::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }
.sv-root * { scrollbar-width: thin; scrollbar-color: var(--border) transparent; }

/* ── Root container ── */
.sv-root {
  display: block;
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
}

/* ── Outer wrap: main + sidebar side by side (sidebar on the right) ── */
.sv-wrap {
  display: flex;
  flex-direction: row-reverse;
  width: 100%;
  min-height: calc(100vh - 56px); /* leave room for the page header */
  align-items: flex-start;
}

/* ── Sidebar (right side) ── */
.sv-sidebar {
  width: 240px;
  flex-shrink: 0;
  position: sticky;
  top: 56px; /* matches page header height */
  height: calc(100vh - 56px);
  overflow-y: auto;
  border-left: 1px solid var(--border);
  background: var(--header-bg);
  padding: 12px 0 20px;
}

.sv-sidebar-section {
  margin-bottom: 16px;
}

.sv-sidebar-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  padding: 0 14px 6px;
}

/* Faceted pill list (used for type and for each facet group) */
.sv-pill-list {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 0 10px;
}

.sv-sidebar-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 11px;
  font-size: 12px;
  color: var(--text);
  cursor: pointer;
  background: var(--bg);
  border: 1px solid var(--border);
  text-align: left;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
  line-height: 1.4;
}

.sv-sidebar-pill:hover {
  border-color: var(--link);
  color: var(--link);
}

.sv-sidebar-pill.active {
  background: var(--link);
  color: var(--bg);
  border-color: var(--link);
}

.sv-sidebar-pill.active .sv-pill-count {
  color: inherit;
  opacity: 0.85;
}

.sv-pill-name {
  white-space: nowrap;
}

.sv-pill-count {
  font-size: 10px;
  color: var(--text-muted);
  flex-shrink: 0;
}

/* ── Main content area ── */
.sv-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

/* ── Sticky viewer header ── */
.sv-hdr {
  position: sticky;
  top: 56px; /* page header height */
  z-index: 50;
  background: var(--header-bg);
  border-bottom: 1px solid var(--border);
  padding: 10px 14px 8px;
}

.sv-hdr-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.sv-title {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--link);
  margin: 0;
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sv-count {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
}

.sv-filter-btn {
  display: none; /* shown on mobile */
  background: var(--header-bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 5px 10px;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
}

/* Free-text search row: floating popup anchored to the page-header
   magnifying-glass toggle. Hidden by default. State persists across hide/
   show because we only toggle display. */
.sv-search-row {
  display: none;
  position: fixed;
  top: 64px;
  right: 14px;
  z-index: 90;
  gap: 8px;
  align-items: center;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
  width: 320px;
  max-width: calc(100vw - 28px);
}

.sv-search-row.sv-search-row-open {
  display: flex;
}

.sv-search {
  flex: 1;
  min-width: 0;
  padding: 7px 12px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--header-bg);
  color: var(--text);
  font-size: 14px;
}

.sv-search:focus {
  outline: none;
  border-color: var(--link);
}

/* Icon buttons injected into the page header next to the theme toggle. */
.page-search-toggle,
.page-sidebar-toggle {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 5px 8px;
  border-radius: 6px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
  margin-right: 6px;
}

.page-search-toggle:hover,
.page-sidebar-toggle:hover {
  border-color: var(--link);
  color: var(--link);
}

.page-search-toggle.active,
.page-sidebar-toggle.active {
  border-color: var(--link);
  color: var(--link);
  background: var(--header-bg);
}

/* Collapse the desktop sidebar when toggled off. Mobile sidebar uses its
   own slide-in mechanism via .open and is unaffected. */
.sv-wrap.sv-collapsed-sidebar > .sv-sidebar {
  display: none;
}

/* ── Tag query (in sidebar) ── */
.sv-sidebar-query {
  padding: 0 10px;
}

.sv-sidebar-query .sv-sidebar-label {
  padding: 0 0 6px;
}

.sv-query-row {
  display: flex;
  gap: 4px;
  align-items: center;
  margin-bottom: 4px;
}

.sv-query {
  flex: 1;
  min-width: 0;
  padding: 6px 9px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.sv-query:focus {
  outline: none;
  border-color: var(--link);
}

.sv-query-clear {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 4px 7px;
  border-radius: 5px;
  cursor: pointer;
  font-size: 12px;
  line-height: 1;
  flex-shrink: 0;
}

.sv-query-clear:hover {
  color: var(--link);
  border-color: var(--link);
}

.sv-query-status {
  font-size: 11px;
  color: var(--text-muted);
  min-height: 14px;
  word-break: break-word;
}

.sv-query-status.sv-query-error {
  color: #f44336;
}

/* ── Card list ── */
.sv-list {
  padding: 0 0 60vh; /* bottom breathing room so collapsing the last card never makes the document shorter than the viewport */
  margin: 0;
  list-style: none;
  overflow-anchor: auto;
}

/* ── Individual skill card ── */
.sv-card {
  border-bottom: 1px solid var(--border);
  /* Leave room for the sticky page header (56px) + viewer header when a
     deep-link scrolls a card to the top. */
  scroll-margin-top: 110px;
}

.sv-card-hdr {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 16px;
  cursor: pointer;
  user-select: none;
}

.sv-card-hdr:hover {
  background: var(--header-bg);
}

.sv-card-hdr-left {
  flex: 1;
  min-width: 0;
}

.sv-card-name-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 3px;
}

.sv-card-name {
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text);
}

.sv-card-desc {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.5;
  margin-top: 4px;
}

.sv-card-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 6px;
}

/* Arrow (left side, consistent with loglog-viewer) */
.sv-card-arrow {
  color: var(--text-muted);
  font-size: 11px;
  flex-shrink: 0;
  width: 12px;
  text-align: center;
  margin-right: 6px;
  margin-top: 5px;
  transition: transform 0.18s;
}

.sv-card.open .sv-card-arrow {
  transform: rotate(90deg);
}

/* Card body (hidden by default).
   Left padding indents the sections under the skill arrow column so the
   nesting is visually obvious. */
.sv-body {
  display: none;
  padding: 0 16px 14px 36px;
  background: var(--header-bg);
  border-top: 1px solid var(--border);
}

.sv-card.open .sv-body {
  display: block;
}

/* ── Section inside card body (foldable) ── */
.sv-section {
  border-top: 1px solid var(--border);
}

.sv-section:first-child {
  border-top: none;
}

.sv-section-hdr {
  display: flex;
  align-items: center;
  padding: 8px 0;
  cursor: pointer;
  user-select: none;
}

.sv-section-hdr:hover .sv-section-label {
  color: var(--link);
}

.sv-section-arrow {
  color: var(--text-muted);
  font-size: 10px;
  width: 12px;
  text-align: center;
  margin-right: 6px;
  flex-shrink: 0;
  transition: transform 0.18s;
}

.sv-section.open .sv-section-arrow {
  transform: rotate(90deg);
}

.sv-section-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  transition: color 0.12s;
}

.sv-section-content {
  display: none;
  padding: 0 0 10px 20px;
  font-size: 14px;
  line-height: 1.65;
  color: var(--text);
}

.sv-section.open .sv-section-content {
  display: block;
}

/* Foldable steps inside lists (e.g. "The move"): the first sentence is the
   visible heading; the rest folds underneath. Default closed. */
.sv-li-foldable {
  list-style: none;
  margin-left: -16px; /* offset the lost <li> bullet so the arrow column lines up */
}

.sv-li-foldable .sv-li-hdr {
  display: flex;
  align-items: flex-start;
  cursor: pointer;
  padding: 2px 0;
}

.sv-li-foldable .sv-li-hdr:hover .sv-li-head {
  color: var(--link);
}

.sv-li-arrow {
  color: var(--text-muted);
  font-size: 10px;
  width: 12px;
  text-align: center;
  margin-right: 6px;
  margin-top: 5px;
  flex-shrink: 0;
  transition: transform 0.18s;
}

.sv-li-foldable.open .sv-li-arrow {
  transform: rotate(90deg);
}

.sv-li-head {
  flex: 1;
  min-width: 0;
}

.sv-li-body {
  display: none;
  padding: 4px 0 6px 18px; /* indent body under the heading text */
}

.sv-li-foldable.open .sv-li-body {
  display: block;
}

.sv-section-content p {
  margin: 0 0 8px;
}

.sv-section-content p:last-child {
  margin-bottom: 0;
}

.sv-section-content ul,
.sv-section-content ol {
  margin: 0 0 8px 20px;
  padding: 0;
}

.sv-section-content li {
  margin-bottom: 3px;
}

.sv-section-content h4 {
  font-size: 13px;
  font-weight: 600;
  margin: 10px 0 4px;
  color: var(--text);
}

.sv-section-content strong {
  font-weight: 600;
  color: var(--text);
}

.sv-section-content em {
  font-style: italic;
}

.sv-section-content code {
  font-family: ui-monospace, monospace;
  font-size: 12px;
  background: var(--border);
  padding: 1px 4px;
  border-radius: 3px;
  color: var(--link);
}

/* Clickable deep-link to another skill (replaces <code>slug</code> when slug
   resolves). Same look as <code> but underlines on hover. */
.sv-skill-link {
  font-family: ui-monospace, monospace;
  font-size: 12px;
  background: var(--border);
  padding: 1px 4px;
  border-radius: 3px;
  color: var(--link);
  text-decoration: none;
  cursor: pointer;
}

.sv-skill-link:hover {
  text-decoration: underline;
  background: var(--link);
  color: var(--bg);
}

/* Flash highlight for a card when it's the target of a deep-link click. */
.sv-card-flash {
  animation: sv-card-flash 1.4s ease-out;
}

@keyframes sv-card-flash {
  0%   { background-color: rgba(88, 166, 255, 0.22); }
  100% { background-color: transparent; }
}

/* ── Tags and badges ── */
.sv-badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 2px 7px;
  border-radius: 4px;
  flex-shrink: 0;
}

.sv-badge-atomic {
  background: rgba(88, 166, 255, 0.18);
  color: #58a6ff;
}

.sv-badge-composed {
  background: rgba(166, 88, 255, 0.18);
  color: #a658ff;
}

.sv-badge-recipe {
  background: rgba(255, 166, 88, 0.18);
  color: #ff9800;
}

.sv-tag {
  display: inline-block;
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 10px;
  background: var(--border);
  color: var(--text-muted);
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
  border: none;
  line-height: 1.4;
}

.sv-tag:hover {
  background: var(--link);
  color: var(--bg);
}

.sv-tag.active {
  background: var(--link);
  color: var(--bg);
}

/* ── Empty state ── */
.sv-empty {
  text-align: center;
  padding: 50px 20px;
  color: var(--text-muted);
  font-size: 14px;
}

/* ── Loading ── */
.sv-loading {
  text-align: center;
  padding: 50px 20px;
  color: var(--text-muted);
}

/* ── Mobile: sidebar overlay (slides in from the right) ── */
@media (max-width: 700px) {
  .sv-sidebar {
    position: fixed;
    top: 0;
    right: 0;
    height: 100vh;
    z-index: 200;
    transform: translateX(100%);
    transition: transform 0.22s ease;
    box-shadow: -4px 0 20px rgba(0, 0, 0, 0.3);
  }

  .sv-sidebar.open {
    transform: translateX(0);
  }

  .sv-sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 199;
  }

  .sv-sidebar-overlay.open {
    display: block;
  }

  .sv-filter-btn {
    display: inline-block;
  }

  .sv-hdr {
    top: 56px;
  }

  .sv-card-hdr {
    padding: 10px 12px;
  }

  .sv-body {
    padding: 0 12px 14px;
  }
}

/* Provenance marker: ==text== in SKILL.md becomes span.inferred.
   Marks sentences the library added (invented or inferred) rather than
   took from the source book, verbatim or reframed. Subtle tint, both themes. */
.inferred {
  background: rgba(127, 140, 160, 0.14);
  border-radius: 3px;
  padding: 0 3px;
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
}

:root[data-theme="light"] .inferred {
  background: rgba(90, 105, 130, 0.10);
}
