/* Knowledge Library "What Knowledge Library delivers" panel visuals. Section shell, cards and panel
   surfaces come from platform-capabilities.css; variables are the shared --cap-* set. */

/* File type badge, shared by the file list and search results */
.library-type {
  display: grid;
  place-items: center;
  flex-shrink: 0;
  width: 44px;
  padding: 3px 0;
  border-radius: 6px;
  background: color-mix(in srgb, var(--library-type) 10%, transparent);
  font-size: 10px;
  font-weight: 700;
  line-height: 1.3;
  letter-spacing: 0.04em;
  color: var(--library-type);
}

.library-type--pdf { --library-type: #b91c1c; }
.library-type--doc { --library-type: #1d4ed8; }
.library-type--dwg { --library-type: #6d28d9; }
.library-type--video { --library-type: #0f766e; }
.library-type--sheet { --library-type: #15803d; }

/* =========================================================
   Card 1 — Plant explorer
   ========================================================= */
.library-explorer__body {
  display: grid;
  grid-template-columns: minmax(0, 34%) minmax(0, 1fr);
  gap: 24px;
}

.library-explorer__tree,
.library-explorer__machines,
.library-explorer__folders {
  margin: 0;
  padding: 0;
  list-style: none;
}

.library-explorer__tree {
  display: grid;
  align-content: start;
  gap: 14px;
}

.library-explorer__area-name {
  padding: 0 10px 6px;
  font-size: 11px;
  font-weight: 600;
  line-height: 1.35;
  letter-spacing: 0.11em;
  text-transform: uppercase;
  color: var(--cap-faint);
}

.library-explorer__machines {
  display: grid;
  gap: 2px;
}

.library-explorer__machine {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 7px 10px;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 500;
  line-height: 1.3;
}

.library-explorer__machine span {
  min-width: 28px;
  padding: 0 7px;
  border-radius: 999px;
  background: rgba(23, 34, 53, 0.06);
  font-size: 12px;
  font-weight: 600;
  line-height: 1.6;
  text-align: center;
  color: var(--cap-muted);
}

.library-explorer__machine.is-selected {
  background: var(--cap-blue-soft);
  box-shadow: inset 2px 0 0 var(--cap-blue);
  font-weight: 600;
  color: var(--cap-blue);
}

.library-explorer__machine.is-selected span {
  background: rgba(60, 82, 148, 0.12);
  color: var(--cap-blue);
}

.library-explorer__view {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
  padding-left: 24px;
  border-left: 1px solid var(--cap-line);
}

.library-explorer__view-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 2px 12px;
}

.library-explorer__view-title {
  font-size: clamp(17px, 2.6cqi, 20px);
  font-weight: 600;
  line-height: 1.25;
  letter-spacing: -0.015em;
}

.library-explorer__folders {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(128px, 1fr));
  gap: 10px;
}

.library-explorer__folder {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 14px;
  border: 1px solid var(--cap-line);
  border-radius: 12px;
  background: #fff;
}

.library-explorer__folder-icon {
  position: relative;
  width: 22px;
  height: 16px;
  margin: 3px 0 10px;
  border-radius: 2px 4px 4px 4px;
  background: rgba(60, 82, 148, 0.16);
}

.library-explorer__folder-icon::before {
  content: "";
  position: absolute;
  top: -3px;
  left: 0;
  width: 9px;
  height: 4px;
  border-radius: 2px 2px 0 0;
  background: rgba(60, 82, 148, 0.16);
}

.library-explorer__folder-name {
  font-size: 15px;
  font-weight: 600;
  line-height: 1.3;
}

.library-explorer__folder-count {
  font-size: 13px;
  font-weight: 500;
  line-height: 1.35;
  color: var(--cap-faint);
}

@container (max-width: 560px) {
  .library-explorer__body {
    grid-template-columns: minmax(0, 1fr);
    gap: 18px;
  }

  .library-explorer__view {
    padding: 18px 0 0;
    border-left: 0;
    border-top: 1px solid var(--cap-line);
  }

  .library-explorer__folders {
    grid-template-columns: repeat(auto-fill, minmax(112px, 1fr));
  }
}

/* =========================================================
   Card 2 — File storage list
   ========================================================= */
.library-files__list {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  margin: 0;
  padding: 0;
  list-style: none;
}

/* Rows share any height the paired card adds, so spacing stays even */
.library-files__row {
  display: grid;
  flex: 1 1 auto;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  align-content: center;
  gap: 14px;
  padding: 12px 0;
}

.library-files__row + .library-files__row {
  border-top: 1px solid rgba(23, 34, 53, 0.07);
}

.library-files__name {
  overflow: hidden;
  font-size: 15px;
  font-weight: 500;
  line-height: 1.35;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.library-files__machine {
  padding: 1px 8px;
  border-radius: 999px;
  background: rgba(3, 105, 161, 0.08);
  font-size: 12px;
  font-weight: 600;
  line-height: 1.5;
  white-space: nowrap;
  color: var(--cap-cyan-deep);
}

@container (max-width: 400px) {
  .library-files__row {
    grid-template-columns: auto minmax(0, 1fr);
    row-gap: 4px;
  }

  .library-files__row .library-type {
    grid-row: 1 / span 2;
  }

  .library-files__machine {
    justify-self: start;
  }
}

/* =========================================================
   Card 3 — Search
   ========================================================= */
.library-search__field {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border: 1px solid var(--cap-line-strong);
  border-radius: 12px;
  box-shadow: 0 0 0 4px var(--cap-blue-soft);
}

.library-search__icon {
  position: relative;
  flex-shrink: 0;
  width: 14px;
  height: 14px;
  border: 1.75px solid var(--cap-blue);
  border-radius: 50%;
}

.library-search__icon::after {
  content: "";
  position: absolute;
  right: -5px;
  bottom: -4px;
  width: 6px;
  height: 1.75px;
  border-radius: 1px;
  background: var(--cap-blue);
  transform: rotate(45deg);
}

.library-search__query {
  min-width: 0;
  font-size: 15px;
  font-weight: 500;
  line-height: 1.35;
}

.library-search__query span {
  display: inline-block;
  position: relative;
  max-width: 100%;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  vertical-align: top;
}

.library-search__count {
  margin-top: -4px;
  font-size: 12.5px;
  font-weight: 500;
  line-height: 1.35;
  color: var(--cap-faint);
}

.library-search__results {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.library-search__hit {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  justify-content: center;
  gap: 8px;
  padding: 14px 16px;
  border: 1px solid var(--cap-line);
  border-radius: 12px;
}

.library-search__hit-head {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.library-search__doc {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  font-size: 15px;
  font-weight: 600;
  line-height: 1.3;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.library-search__where {
  flex-shrink: 0;
  font-size: 12.5px;
  font-weight: 600;
  line-height: 1.35;
  color: var(--cap-blue);
}

.library-search__snippet {
  font-size: 14px;
  line-height: 1.45;
  color: rgba(23, 34, 53, 0.78);
}

.library-search__snippet mark {
  padding: 0 2px;
  border-radius: 3px;
  background: rgba(60, 82, 148, 0.13);
  font-weight: 600;
  color: var(--cap-ink);
}

/* =========================================================
   Card 4 — Gap analysis (opt-in)
   ========================================================= */
.library-gaps__toggle {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 12.5px;
  font-weight: 600;
  line-height: 1.35;
  color: var(--cap-teal);
}

.library-gaps__switch {
  position: relative;
  width: 26px;
  height: 15px;
  border-radius: 999px;
  background: var(--cap-teal);
}

.library-gaps__switch::after {
  content: "";
  position: absolute;
  top: 2px;
  right: 2px;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: #fff;
}

.library-gaps__coverage {
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.library-gaps__coverage li {
  display: grid;
  grid-template-columns: minmax(0, 38%) minmax(0, 1fr);
  align-items: center;
  gap: 14px;
}

.library-gaps__coverage p {
  overflow: hidden;
  font-size: 14px;
  font-weight: 500;
  line-height: 1.35;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.library-gaps__meter {
  height: 6px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(23, 34, 53, 0.07);
}

.library-gaps__meter i {
  display: block;
  width: calc(var(--c) * 100%);
  height: 100%;
  border-radius: inherit;
  background: var(--cap-blue);
  transform-origin: left center;
  transition: transform 0.8s var(--cap-ease);
}

.library-gaps__coverage .is-gap p {
  color: var(--cap-amber);
  font-weight: 600;
}

.library-gaps__coverage .is-gap .library-gaps__meter i {
  background: var(--cap-amber);
}

.library-gaps__card {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: auto;
  padding: 14px 16px;
  border: 1px dashed rgba(161, 98, 7, 0.45);
  border-radius: 14px;
  background: rgba(161, 98, 7, 0.035);
}

.library-gaps__flag {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 10.5px;
  font-weight: 600;
  line-height: 1.4;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--cap-amber);
}

.library-gaps__flag::before {
  content: "";
  width: 7px;
  height: 7px;
  border: 1.5px solid currentColor;
  border-radius: 50%;
}

.library-gaps__title {
  font-size: 16px;
  font-weight: 600;
  line-height: 1.3;
  letter-spacing: -0.01em;
  text-wrap: balance;
}

.library-gaps__chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 2px;
}

/* =========================================================
   Card 5 — Version history
   ========================================================= */
.library-versions__list {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.library-versions__rev {
  display: grid;
  flex: 1 1 auto;
  grid-template-columns: 32px minmax(0, 1fr) auto;
  align-items: center;
  align-content: center;
  gap: 14px;
  padding: 12px 14px;
  border: 1px solid var(--cap-line);
  border-radius: 12px;
}

.library-versions__badge {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: rgba(23, 34, 53, 0.05);
  font-size: 13px;
  font-weight: 700;
  color: var(--cap-faint);
}

.library-versions__name {
  font-size: 15px;
  font-weight: 600;
  line-height: 1.3;
}

.library-versions__note {
  margin-top: 2px;
  font-size: 13.5px;
  line-height: 1.4;
  color: var(--cap-muted);
}

.library-versions__rev:not(.is-current) .library-versions__name {
  color: var(--cap-faint);
}

.library-versions__rev.is-current {
  border-color: rgba(15, 118, 110, 0.26);
  background: var(--cap-teal-soft);
}

.library-versions__rev.is-current .library-versions__badge {
  background: var(--cap-teal);
  color: #fff;
}

/* =========================================================
   Scroll reveals (only once the shared script has enhanced the section)
   ========================================================= */

/* Explorer: tree rows first, then the selected machine's folders */
.platform-cap.is-enhanced .library-explorer__folder {
  opacity: 0;
  transform: translateY(8px);
  transition-property: opacity, transform;
  transition-duration: 0.5s;
  transition-timing-function: var(--cap-ease);
}

.platform-cap.is-enhanced .is-inview .library-explorer__folder {
  opacity: 1;
  transform: none;
}

.library-explorer__folder:nth-child(1) { transition-delay: 0.4s; }
.library-explorer__folder:nth-child(2) { transition-delay: 0.47s; }
.library-explorer__folder:nth-child(3) { transition-delay: 0.54s; }
.library-explorer__folder:nth-child(4) { transition-delay: 0.61s; }
.library-explorer__folder:nth-child(5) { transition-delay: 0.68s; }

/* Search: the query types in, then the results appear */
.platform-cap.is-enhanced .library-search__query span {
  clip-path: inset(0 100% 0 0);
  transition: clip-path 0.9s steps(26, end) 0.15s;
}

.platform-cap.is-enhanced .is-inview .library-search__query span {
  clip-path: inset(0);
}

.platform-cap.is-enhanced .library-search__count {
  opacity: 0;
  transition: opacity 0.4s ease 1.05s;
}

.platform-cap.is-enhanced .is-inview .library-search__count {
  opacity: 1;
}

.library-search__results > :nth-child(1) { transition-delay: 1.1s; }
.library-search__results > :nth-child(2) { transition-delay: 1.22s; }

/* Gap analysis: coverage fills, then the gap appears */
.platform-cap.is-enhanced .library-gaps__meter i {
  transform: scaleX(0);
}

.platform-cap.is-enhanced .is-inview .library-gaps__meter i {
  transform: none;
}

.library-gaps__coverage li:nth-child(1) .library-gaps__meter i { transition-delay: 0.25s; }
.library-gaps__coverage li:nth-child(2) .library-gaps__meter i { transition-delay: 0.35s; }
.library-gaps__coverage li:nth-child(3) .library-gaps__meter i { transition-delay: 0.45s; }
.library-gaps__coverage li:nth-child(4) .library-gaps__meter i { transition-delay: 0.55s; }
.library-gaps__coverage li:nth-child(5) .library-gaps__meter i { transition-delay: 0.65s; }

.platform-cap.is-enhanced .library-gaps__card {
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.5s var(--cap-ease) 1.1s, transform 0.5s var(--cap-ease) 1.1s;
}

.platform-cap.is-enhanced .is-inview .library-gaps__card {
  opacity: 1;
  transform: none;
}

/* Versions: earlier revisions settle, then the current one slides in on top */
.library-versions__list > :nth-child(1) { transition-delay: 0.45s; }
.library-versions__list > :nth-child(2) { transition-delay: 0s; }
.library-versions__list > :nth-child(3) { transition-delay: 0.09s; }

.platform-cap.is-enhanced .library-versions__list > .is-current {
  transform: translateY(-14px);
}

.platform-cap.is-enhanced .is-inview .library-versions__list > .is-current {
  transform: none;
}
