.pkg-layout {
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr);
  min-height: calc(100vh - 80px);
}

.pkg-side {
  position: sticky;
  top: 80px;
  align-self: start;
  max-height: calc(100vh - 80px);
  overflow-y: auto;
  padding: 1.25rem 1rem;
  border-right: 1px solid var(--surface-2);
}

.pkg-nav,
.pkg-cats {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.pkg-nav__item,
.pkg-cats__item {
  display: flex;
  justify-content: space-between;
  padding: 0.45rem 0.6rem;
  border-radius: 8px;
  color: var(--text);
  text-decoration: none;
  font-size: 0.875rem;
}

.pkg-cats__item {
  color: var(--text-muted);
  font-size: 0.82rem;
}

.pkg-nav__item:hover,
.pkg-cats__item:hover {
  background: var(--surface);
}

.pkg-nav__item--active {
  background: var(--surface);
  box-shadow: inset 3px 0 0 var(--wb);
}

.pkg-nav__count {
  color: var(--text-muted);
  font-size: 0.75rem;
}

.pkg-side__title {
  margin: 1.25rem 0.6rem 0.35rem;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.pkg-side__hint {
  margin: 1.25rem 0.6rem 0;
}

.pkg-main {
  padding: 1.5rem 2rem 6rem;
  min-width: 0;
  max-width: 1200px;
}

.pkg-search {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
}

.pkg-search__input {
  flex: 1;
  min-width: 0;
  padding: 0.85rem 1.1rem;
  border: 1px solid var(--surface-2);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 1rem;
}

.pkg-search__input:focus {
  outline: none;
  border-color: var(--wb);
  box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.2);
}

.pkg-intro h2 {
  font-size: 1.25rem;
  margin-bottom: 0.25rem;
}

.pkg-intro {
  margin-bottom: 1.25rem;
}

.pkg-section {
  margin-bottom: 1.75rem;
  scroll-margin-top: 90px;
}

.pkg-section__title {
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 0.65rem;
}

.pkg-section--fold > summary {
  cursor: pointer;
}

.pkg-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 0.75rem;
}

.pkg-card {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  padding: 0.95rem 1rem;
  border: 1px solid var(--surface-2);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  text-decoration: none;
  transition: border-color 0.15s, transform 0.15s;
}

.pkg-card:hover,
.pkg-card:focus-visible {
  border-color: var(--wb);
  transform: translateY(-1px);
  outline: none;
}

.pkg-card__head {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  min-width: 0;
}

.pkg-card__name {
  font-family: var(--mono);
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pkg-card__ver {
  margin-left: 0.5rem;
  color: var(--text-muted);
  font-size: 0.75rem;
  font-weight: 400;
  font-family: var(--mono);
}

.pkg-card__sum {
  flex: 1;
  color: var(--text-muted);
  font-size: 0.82rem;
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.pkg-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
}

.pkg-badge {
  padding: 0.12rem 0.5rem;
  border-radius: 999px;
  background: var(--bg);
  border: 1px solid var(--surface-2);
  color: var(--text-muted);
  font-size: 0.7rem;
  white-space: nowrap;
}

.pkg-badge--ok {
  color: var(--success);
  border-color: rgba(34, 197, 94, 0.35);
}

.pkg-badge--warn {
  color: var(--warning);
  border-color: rgba(245, 158, 11, 0.35);
}

.pkg-empty {
  padding: 2.5rem 0;
  color: var(--text-muted);
  text-align: center;
}

.pkg-empty--err {
  color: var(--error);
}

.pkg-rows {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--surface-2);
  border-radius: var(--radius);
  overflow: hidden;
}

.pkg-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto;
  gap: 1rem;
  align-items: center;
  padding: 0.55rem 1rem;
  color: var(--text);
  text-decoration: none;
  font-size: 0.85rem;
  background: var(--surface);
}

.pkg-row + .pkg-row {
  border-top: 1px solid var(--surface-2);
}

.pkg-row:hover {
  background: var(--surface-2);
}

.pkg-row__name {
  font-family: var(--mono);
}

.pkg-row__spec,
.pkg-row__ver {
  color: var(--text-muted);
  font-size: 0.78rem;
}

.pkg-back {
  display: inline-block;
  margin-bottom: 1rem;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.85rem;
}

.pkg-back:hover {
  color: var(--text);
}

.pkg-detail__head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 360px);
  gap: 1.5rem;
  align-items: start;
  margin-bottom: 1.25rem;
}

.pkg-detail__name {
  font-family: var(--mono);
  font-size: 1.6rem;
}

.pkg-detail__sum {
  margin: 0.35rem 0 0.75rem;
  color: var(--text-muted);
  font-size: 1rem;
}

.pkg-detail__import {
  display: inline-block;
  padding: 0.35rem 0.65rem;
  border-radius: 8px;
  background: var(--bg);
  border: 1px solid var(--surface-2);
  font-size: 0.8rem;
  color: var(--text-muted);
}

.pkg-actions {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  padding: 1rem;
  border: 1px solid var(--surface-2);
  border-radius: var(--radius);
  background: var(--surface);
}

.pkg-actions__state {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

.pkg-actions__req {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.pkg-actions__row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.pkg-actions__row .select {
  flex: 1 1 100%;
}

.pkg-actions__row .btn--primary {
  flex: 1;
}

.pkg-warn {
  margin-bottom: 1rem;
  padding: 0.75rem 1rem;
  border: 1px solid rgba(245, 158, 11, 0.4);
  border-radius: var(--radius);
  background: rgba(245, 158, 11, 0.08);
  color: var(--warning);
  font-size: 0.85rem;
}

.pkg-meta {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 0.75rem;
  padding: 0.85rem 1rem;
  margin-bottom: 1rem;
  border-radius: var(--radius);
  background: var(--surface);
}

.pkg-meta__item {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  min-width: 0;
  overflow-wrap: anywhere;
}

.pkg-links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 1.5rem;
}

.pkg-links a {
  text-decoration: none;
}

.pkg-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.pkg-chip {
  padding: 0.25rem 0.65rem;
  border-radius: 999px;
  border: 1px solid var(--surface-2);
  color: var(--text);
  text-decoration: none;
  font-family: var(--mono);
  font-size: 0.78rem;
}

.pkg-chip:hover {
  border-color: var(--wb);
}

.pkg-readme {
  padding: 1.25rem 1.5rem;
  border: 1px solid var(--surface-2);
  border-radius: var(--radius);
  background: var(--surface);
  line-height: 1.6;
  font-size: 0.92rem;
  overflow-wrap: anywhere;
}

.pkg-readme h1,
.pkg-readme h2,
.pkg-readme h3 {
  margin: 1.2em 0 0.5em;
  line-height: 1.25;
}

.pkg-readme h1:first-child,
.pkg-readme h2:first-child {
  margin-top: 0;
}

.pkg-readme p,
.pkg-readme ul,
.pkg-readme ol,
.pkg-readme pre,
.pkg-readme table {
  margin: 0 0 0.85em;
}

.pkg-readme ul,
.pkg-readme ol {
  padding-left: 1.4em;
}

.pkg-readme a {
  color: #a78bfa;
}

.pkg-readme img {
  max-width: 100%;
  height: auto;
}

.pkg-readme code {
  padding: 0.1em 0.35em;
  border-radius: 4px;
  background: var(--bg);
  font-size: 0.85em;
}

.pkg-readme pre,
.pkg-readme__plain {
  padding: 0.85rem 1rem;
  border-radius: 8px;
  background: var(--bg);
  overflow-x: auto;
  white-space: pre;
  font-size: 0.82rem;
}

.pkg-readme pre code {
  padding: 0;
  background: none;
}

.pkg-readme__plain {
  white-space: pre-wrap;
}

.pkg-readme table {
  border-collapse: collapse;
  display: block;
  overflow-x: auto;
}

.pkg-readme th,
.pkg-readme td {
  padding: 0.35rem 0.6rem;
  border: 1px solid var(--surface-2);
}

.pkg-log {
  position: fixed;
  right: 1.25rem;
  bottom: 1.25rem;
  z-index: 50;
  width: min(640px, calc(100vw - 2.5rem));
  border: 1px solid var(--surface-2);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.pkg-log[hidden] {
  display: none;
}

.pkg-log__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.45rem 0.85rem;
  border-bottom: 1px solid var(--surface-2);
}

.pkg-log__title {
  font-size: 0.78rem;
  color: var(--text-muted);
  font-family: var(--mono);
}

.pkg-log__body {
  max-height: 260px;
  overflow: auto;
  padding: 0.65rem 0.85rem;
  font-size: 0.75rem;
  white-space: pre-wrap;
  color: var(--text-muted);
  font-family: var(--mono);
}

@media (max-width: 900px) {
  .pkg-layout,
  .pkg-detail__head {
    grid-template-columns: 1fr;
  }

  .pkg-side {
    position: static;
    max-height: none;
    border-right: none;
    border-bottom: 1px solid var(--surface-2);
  }

  .pkg-main {
    padding: 1rem;
  }
}
