/* Knowledge Library hero visualization — scoped to .library-viz. Outer canvas is transparent.
   Phases (data-phase): ingest → organize → analyze → review → reset. */

.library-viz {
  --lv-ink: #172235;
  --lv-muted: rgba(23, 34, 53, 0.6);
  --lv-faint: rgba(23, 34, 53, 0.42);
  --lv-line: rgba(23, 34, 53, 0.09);
  --lv-blue: #3c5294;
  --lv-cyan: #0ea5e9;
  --lv-cyan-deep: #0369a1;
  --lv-teal: #0f766e;
  --lv-amber: #b45309;
  --lv-ease: cubic-bezier(0.3, 0, 0.2, 1);
  container-type: inline-size;
  width: 100%;
  font-family: var(--font-inter-tight, "Inter Tight", system-ui, sans-serif);
  color: var(--lv-ink);
}

.library-viz__stage {
  position: relative;
  top: -20px;
  width: 100%;
  aspect-ratio: 4 / 3;
}

:where(.library-viz) p {
  margin: 0;
}

:where(.library-viz) :is(ul, ol) {
  margin: 0;
  padding: 0;
  list-style: none;
}

/* Library window */
.library-viz__window {
  position: absolute;
  top: 2%;
  left: 0;
  width: 75%;
  height: 92%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow:
    0 0 0 1px rgba(23, 34, 53, 0.06),
    0 32px 60px -30px rgba(15, 23, 42, 0.5),
    0 14px 26px -18px rgba(15, 23, 42, 0.35);
}

.library-viz__bar {
  display: flex;
  align-items: center;
  gap: 1.6cqw;
  padding: 1.3cqw 1.8cqw;
  border-bottom: 1px solid var(--lv-line);
}

.library-viz__dots {
  display: flex;
  gap: 5px;
}

.library-viz__dots i {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: rgba(23, 34, 53, 0.14);
}

.library-viz__crumb {
  font-size: clamp(10px, 1.6cqw, 12px);
  font-weight: 600;
  line-height: 1.3;
  white-space: nowrap;
}

.library-viz__crumb b {
  margin: 0 0.5em;
  font-weight: 500;
  color: var(--lv-faint);
}

.library-viz__search {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  padding: 0.5cqw 1.3cqw;
  border-radius: 999px;
  background: rgba(23, 34, 53, 0.05);
  font-size: clamp(9.5px, 1.45cqw, 11px);
  font-weight: 500;
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  color: var(--lv-faint);
}

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

.library-viz__body {
  display: grid;
  flex: 1 1 auto;
  min-height: 0;
  grid-template-columns: 41% minmax(0, 1fr);
}

/* Plant tree */
.library-viz__tree {
  padding: 1.6cqw 1.2cqw;
  border-right: 1px solid var(--lv-line);
  background: rgba(23, 34, 53, 0.025);
}

.library-viz__plant {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 0 0.8cqw;
  font-size: clamp(10.5px, 1.75cqw, 13px);
  font-weight: 600;
  line-height: 1.3;
}

.library-viz__plant::before {
  content: "";
  width: 9px;
  height: 9px;
  border: 1.5px solid var(--lv-ink);
  border-radius: 2.5px;
}

.library-viz__line {
  margin-top: 1.5cqw;
  padding: 0 0.8cqw 0.5cqw;
  font-size: clamp(8px, 1.2cqw, 9.5px);
  font-weight: 600;
  line-height: 1.3;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  white-space: nowrap;
  color: var(--lv-faint);
}

.library-viz__nodes {
  display: grid;
  gap: 1px;
}

.library-viz__node {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 0.55cqw 0.8cqw;
  border-radius: 6px;
  font-size: clamp(10px, 1.6cqw, 12px);
  font-weight: 500;
  line-height: 1.3;
  white-space: nowrap;
}

.library-viz__node-name {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.library-viz__node-name::before {
  content: "";
  flex-shrink: 0;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: rgba(23, 34, 53, 0.22);
  transition: background-color 0.3s ease, box-shadow 0.3s ease;
}

.library-viz__count {
  display: grid;
  flex-shrink: 0;
  min-width: 2.2em;
  padding: 0 0.5em;
  border-radius: 999px;
  background: rgba(23, 34, 53, 0.06);
  font-size: 0.86em;
  font-weight: 600;
  line-height: 1.6;
  text-align: center;
  font-variant-numeric: tabular-nums;
  color: var(--lv-muted);
}

.library-viz__count > span {
  grid-area: 1 / 1;
  transition: opacity 0.25s ease, transform 0.25s ease;
}

.library-viz__count-now {
  opacity: 0;
  transform: translateY(5px);
}

/* Import drop zone */
.library-viz__main {
  display: flex;
  flex-direction: column;
  gap: 1cqw;
  min-width: 0;
  padding: 1.6cqw 1.8cqw;
}

.library-viz__main-title {
  font-size: clamp(8.5px, 1.25cqw, 10px);
  font-weight: 600;
  line-height: 1.3;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--lv-blue);
}

.library-viz__drop {
  position: relative;
  flex: 1 1 auto;
  padding: 1.2cqw;
  border: 1.5px dashed rgba(23, 34, 53, 0.16);
  border-radius: 10px;
  transition: border-color 0.4s ease, background-color 0.4s ease;
}

.library-viz__drop-hint {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: clamp(9.5px, 1.45cqw, 11px);
  font-weight: 500;
  color: var(--lv-faint);
  transition: opacity 0.3s ease;
}

.library-viz__files {
  position: relative;
  display: grid;
  gap: 0.7cqw;
}

.library-viz__file {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  grid-template-rows: auto auto;
  column-gap: 1cqw;
  row-gap: 2px;
  align-items: center;
  padding: 0.75cqw 1cqw;
  border: 1px solid var(--lv-line);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 6px 14px -12px rgba(23, 34, 53, 0.5);
  opacity: 0;
  transform: translateY(-14px);
  transition: opacity 0.35s ease, transform 0.45s var(--lv-ease);
}

.library-viz__type {
  grid-row: 1 / span 2;
  display: grid;
  place-items: center;
  min-width: 3.6cqw;
  padding: 0.45cqw 0.5cqw;
  border-radius: 5px;
  font-size: clamp(7px, 1.05cqw, 8.5px);
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: 0.04em;
  color: var(--lv-type);
  background: color-mix(in srgb, var(--lv-type) 11%, transparent);
}

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

.library-viz__file-name {
  overflow: hidden;
  font-size: clamp(9.5px, 1.5cqw, 11.5px);
  font-weight: 600;
  line-height: 1.25;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.library-viz__tag {
  justify-self: start;
  padding: 0 0.6em;
  border-radius: 999px;
  background: rgba(3, 105, 161, 0.09);
  font-size: clamp(8px, 1.2cqw, 9.5px);
  font-weight: 600;
  line-height: 1.6;
  white-space: nowrap;
  color: var(--lv-cyan-deep);
  opacity: 0;
  transform: scale(0.85);
  transform-origin: left center;
  transition: opacity 0.25s ease, transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.library-viz__filed {
  position: absolute;
  top: 1.2cqw;
  left: 1.2cqw;
  right: 1.2cqw;
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: clamp(9.5px, 1.5cqw, 11.5px);
  font-weight: 600;
  line-height: 1.3;
  color: var(--lv-teal);
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.library-viz__filed::before {
  content: "";
  flex-shrink: 0;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
}

/* Ingest: files drop in one by one, then pick up a machine tag */
.library-viz[data-phase="ingest"] .library-viz__drop {
  border-color: rgba(14, 165, 233, 0.55);
  background: rgba(14, 165, 233, 0.04);
}

.library-viz:is([data-phase="ingest"], [data-phase="organize"], [data-phase="analyze"], [data-phase="review"]) .library-viz__drop-hint {
  opacity: 0;
}

.library-viz[data-phase="ingest"] .library-viz__file {
  opacity: 1;
  transform: none;
  transition-delay: calc(var(--i) * 0.3s + 0.2s);
}

.library-viz[data-phase="ingest"] .library-viz__tag {
  opacity: 1;
  transform: none;
  transition-delay: calc(var(--i) * 0.3s + 0.75s);
}

/* Organize: each file slides into its machine, whose count ticks up */
.library-viz[data-phase="organize"] .library-viz__file {
  opacity: 0;
  transform: translateX(-34%) scale(0.92);
  transition: opacity 0.4s ease, transform 0.5s var(--lv-ease);
  transition-delay: calc(var(--i) * 0.16s);
}

.library-viz[data-phase="organize"] .library-viz__tag {
  opacity: 1;
  transform: none;
}

.library-viz[data-phase="organize"] .library-viz__node {
  animation: library-viz-flash 0.9s ease calc(var(--i) * 0.16s + 0.3s) both;
}

@keyframes library-viz-flash {
  0% { background-color: rgba(14, 165, 233, 0); }
  30% { background-color: rgba(14, 165, 233, 0.16); }
  100% { background-color: rgba(14, 165, 233, 0); }
}

.library-viz:is([data-phase="organize"], [data-phase="analyze"], [data-phase="review"]) .library-viz__count-was {
  opacity: 0;
  transform: translateY(-5px);
}

.library-viz:is([data-phase="organize"], [data-phase="analyze"], [data-phase="review"]) .library-viz__count-now {
  opacity: 1;
  transform: none;
}

.library-viz[data-phase="organize"] .library-viz__count > span {
  transition-delay: calc(var(--i) * 0.16s + 0.45s);
}

.library-viz:is([data-phase="organize"], [data-phase="analyze"], [data-phase="review"]) .library-viz__count {
  color: var(--lv-cyan-deep);
  background: rgba(3, 105, 161, 0.09);
}

.library-viz:is([data-phase="organize"], [data-phase="analyze"], [data-phase="review"]) .library-viz__filed {
  opacity: 1;
  transform: none;
}

.library-viz[data-phase="organize"] .library-viz__filed {
  transition-delay: 1.3s;
}

.library-viz[data-phase="review"] .library-viz__node--gap .library-viz__node-name::before {
  background: var(--lv-amber);
  box-shadow: 0 0 0 3px rgba(180, 83, 9, 0.18);
}

/* Steps panel: each phase is clickable */
.library-viz__panel {
  position: absolute;
  top: 7%;
  right: 0;
  width: clamp(190px, 33%, 248px);
  padding: 9px 14px 10px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.85);
  box-shadow: 0 10px 28px -16px rgba(23, 34, 53, 0.28), 0 0 0 1px rgba(23, 34, 53, 0.04);
  -webkit-backdrop-filter: blur(14px) saturate(1.15);
  backdrop-filter: blur(14px) saturate(1.15);
}

.library-viz__panel-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: clamp(11.5px, 2.05cqw, 13px);
  font-weight: 600;
  line-height: 1.3;
  white-space: nowrap;
}

.library-viz__panel-dot {
  position: relative;
  width: 7px;
  height: 7px;
  flex-shrink: 0;
  border-radius: 50%;
  background: var(--lv-cyan);
}

.library-viz__panel-dot::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 1px solid var(--lv-cyan);
  opacity: 0;
  animation: library-viz-echo 1.4s ease-out infinite;
}

.library-viz[data-step="4"] .library-viz__panel-dot {
  background: var(--lv-teal);
}

.library-viz[data-step="4"] .library-viz__panel-dot::after {
  animation: none;
}

@keyframes library-viz-echo {
  0% { transform: scale(1); opacity: 0.8; }
  100% { transform: scale(2.6); opacity: 0; }
}

.library-viz__steps {
  display: grid;
  gap: 2px;
  margin-top: 9px;
  padding-top: 7px;
  border-top: 1px solid rgba(23, 34, 53, 0.08);
}

.library-viz__step {
  display: flex;
  align-items: center;
  gap: 8px;
  width: calc(100% + 10px);
  margin: 0 -5px;
  padding: 2px 5px;
  border: 0;
  border-radius: 6px;
  background: none;
  font: inherit;
  font-size: clamp(11px, 1.95cqw, 12.5px);
  font-weight: 500;
  line-height: 1.35;
  text-align: left;
  white-space: nowrap;
  color: rgba(23, 34, 53, 0.42);
  cursor: pointer;
  transition: color 0.35s ease, background-color 0.2s ease;
  -webkit-tap-highlight-color: transparent;
}

.library-viz__step:hover {
  background: rgba(23, 34, 53, 0.05);
}

.library-viz__step:focus-visible {
  outline: 2px solid #2563eb;
  outline-offset: 1px;
}

.library-viz__step[data-state="active"] {
  color: var(--lv-ink);
}

.library-viz__step[data-state="done"] {
  color: rgba(23, 34, 53, 0.78);
}

.library-viz__step-mark {
  position: relative;
  width: 13px;
  height: 13px;
  flex-shrink: 0;
  border-radius: 50%;
  border: 1.5px solid rgba(23, 34, 53, 0.2);
  transition: background-color 0.3s ease, border-color 0.3s ease;
}

.library-viz__step[data-state="active"] .library-viz__step-mark {
  border-color: var(--lv-cyan);
  border-right-color: rgba(14, 165, 233, 0.15);
  animation: library-viz-spin 0.9s linear infinite;
}

.library-viz.is-pinned .library-viz__step[data-state="active"] .library-viz__step-mark {
  animation: none;
  border-color: var(--lv-cyan);
  background: rgba(14, 165, 233, 0.15);
}

.library-viz__step[data-state="done"] .library-viz__step-mark {
  border-color: var(--lv-cyan-deep);
  background: var(--lv-cyan-deep);
}

.library-viz[data-step="4"] .library-viz__steps li:last-child .library-viz__step-mark {
  border-color: var(--lv-teal);
  background: var(--lv-teal);
}

.library-viz__step[data-state="done"] .library-viz__step-mark::after {
  content: "";
  position: absolute;
  left: 3.5px;
  top: 1.5px;
  width: 3px;
  height: 6px;
  border: solid #fff;
  border-width: 0 1.5px 1.5px 0;
  transform: rotate(45deg);
}

@keyframes library-viz-spin {
  to { transform: rotate(360deg); }
}

/* Gap analysis card: coverage per machine, then the gap it found */
.library-viz__gaps {
  position: absolute;
  bottom: 2%;
  right: 0;
  width: 45%;
  padding: 12px 14px 14px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.74);
  border: 1px solid rgba(255, 255, 255, 0.85);
  box-shadow: 0 10px 28px -14px rgba(23, 34, 53, 0.3), 0 0 0 1px rgba(23, 34, 53, 0.04);
  -webkit-backdrop-filter: blur(14px) saturate(1.15);
  backdrop-filter: blur(14px) saturate(1.15);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.5s ease, transform 0.5s ease;
}

.library-viz:is([data-phase="analyze"], [data-phase="review"]) .library-viz__gaps {
  opacity: 1;
  transform: none;
}

.library-viz__gaps-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  padding-bottom: 8px;
  border-bottom: 1px solid rgba(23, 34, 53, 0.08);
  font-size: clamp(11.5px, 2cqw, 13.5px);
  font-weight: 600;
  line-height: 1.3;
}

.library-viz__gaps-title span {
  font-size: 0.82em;
  font-weight: 500;
  color: var(--lv-faint);
}

.library-viz__coverage {
  display: grid;
  gap: 6px;
  padding-top: 9px;
}

.library-viz__coverage li {
  display: grid;
  grid-template-columns: 44% minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  font-size: clamp(9.5px, 1.6cqw, 11.5px);
  font-weight: 500;
  line-height: 1.3;
  white-space: nowrap;
}

.library-viz__coverage-name {
  overflow: hidden;
  text-overflow: ellipsis;
}

.library-viz__meter {
  height: 5px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(23, 34, 53, 0.08);
}

.library-viz__meter i {
  display: block;
  width: calc(var(--c) * 100%);
  height: 100%;
  border-radius: inherit;
  background: var(--lv-cyan-deep);
  transform: scaleX(0);
  transform-origin: left center;
  transition: transform 0.7s var(--lv-ease), background-color 0.3s ease;
}

.library-viz:is([data-phase="analyze"], [data-phase="review"]) .library-viz__meter i {
  transform: none;
}

.library-viz[data-phase="analyze"] .library-viz__meter i {
  transition-delay: calc(var(--i) * 0.28s + 0.35s);
}

.library-viz[data-phase="review"] .library-viz__coverage .is-gap .library-viz__meter i {
  background: var(--lv-amber);
}

.library-viz__gap {
  display: grid;
  gap: 3px;
  margin-top: 10px;
  padding: 9px 11px;
  border: 1px dashed rgba(180, 83, 9, 0.45);
  border-radius: 10px;
  background: rgba(255, 251, 235, 0.85);
  opacity: 0;
  transform: scale(0.94);
  transform-origin: center bottom;
  transition: opacity 0.3s ease, transform 0.45s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.library-viz[data-phase="review"] .library-viz__gap {
  opacity: 1;
  transform: none;
}

.library-viz__gap-flag {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: clamp(8.5px, 1.3cqw, 10px);
  font-weight: 600;
  line-height: 1.3;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--lv-amber);
}

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

.library-viz__gap-title {
  font-size: clamp(10.5px, 1.8cqw, 12.5px);
  font-weight: 600;
  line-height: 1.3;
}

.library-viz__gap-note {
  font-size: clamp(9.5px, 1.5cqw, 11px);
  font-weight: 500;
  line-height: 1.3;
  color: var(--lv-muted);
}

.library-viz.is-paused *,
.library-viz.is-paused *::before,
.library-viz.is-paused *::after {
  animation-play-state: paused !important;
}

/* Narrow containers: taller stage, window full width between the two glass panels */
@container (max-width: 480px) {
  .library-viz__stage {
    aspect-ratio: 0.82;
  }

  .library-viz__window {
    top: 17%;
    width: 100%;
    height: 66%;
    border-radius: 12px;
  }

  .library-viz__search,
  .library-viz__file-name {
    display: none;
  }

  .library-viz__body {
    grid-template-columns: 48% minmax(0, 1fr);
  }

  .library-viz__node {
    padding: 2px 5px;
    font-size: 10px;
  }

  .library-viz__line {
    margin-top: 7px;
    font-size: 8px;
  }

  .library-viz__file {
    grid-template-rows: auto;
    padding: 4px 6px;
  }

  .library-viz__type {
    grid-row: auto;
    min-width: 26px;
  }

  .library-viz__panel {
    top: 0;
    width: 64%;
    padding: 7px 9px 8px;
    border-radius: 10px;
  }

  .library-viz__panel-title {
    gap: 6px;
    font-size: 11px;
  }

  .library-viz__steps {
    margin-top: 6px;
    padding-top: 5px;
  }

  .library-viz__step {
    gap: 6px;
    font-size: 10.5px;
  }

  .library-viz__step-mark {
    width: 11px;
    height: 11px;
  }

  .library-viz__step[data-state="done"] .library-viz__step-mark::after {
    left: 2.6px;
    top: 0.8px;
  }

  .library-viz__gaps {
    bottom: 0;
    width: 78%;
    padding: 9px 10px 10px;
    border-radius: 10px;
  }

  .library-viz__coverage {
    gap: 4px;
  }

  .library-viz__gap {
    margin-top: 7px;
    padding: 6px 8px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .library-viz *,
  .library-viz *::before,
  .library-viz *::after {
    animation: none !important;
    transition: none !important;
  }
}
