.library-summary,
.library-controls {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 22px;
  box-shadow: 0 14px 38px rgba(7, 20, 43, 0.08);
  padding: clamp(1.2rem, 3vw, 2rem);
}

.library-summary h2,
.library-controls h2 {
  color: var(--navy);
  margin-top: 0;
}

.library-stats {
  display: grid;
  gap: 0.8rem;
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.library-stats div {
  background: #edf5fb;
  border-top: 5px solid var(--blue);
  border-radius: 14px;
  display: grid;
  gap: 0.25rem;
  min-width: 0;
  padding: 1rem;
}

.library-stats div:nth-child(2) {
  border-top-color: var(--teal);
}

.library-stats div:nth-child(3) {
  border-top-color: #c58d00;
}

.library-stats div:nth-child(4) {
  border-top-color: var(--navy);
}

.library-stats strong {
  color: var(--navy);
  font-size: clamp(1.7rem, 4vw, 2.5rem);
  line-height: 1;
}

.library-stats span {
  color: var(--muted);
  font-weight: 750;
}

.library-filter-grid {
  align-items: end;
  display: grid;
  gap: 0.8rem;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.library-filter-grid label {
  color: var(--navy);
  display: grid;
  font-weight: 850;
  gap: 0.35rem;
}

.library-filter-grid input,
.library-filter-grid select,
.library-filter-grid button {
  background: #fff;
  border: 2px solid #49637a;
  border-radius: 12px;
  color: var(--ink);
  font: inherit;
  min-height: 48px;
  padding: 0.65rem 0.75rem;
  width: 100%;
}

.library-filter-grid button {
  background: var(--yellow);
  border-color: #8b6500;
  color: var(--navy);
  cursor: pointer;
  font-weight: 900;
}

.library-result-count {
  color: var(--navy);
  font-weight: 800;
  margin-bottom: 0;
}

.document-grid {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.document-card {
  background: #fff;
  border: 1px solid #c7d5e3;
  border-left: 7px solid var(--blue);
  border-radius: 18px;
  box-shadow: 0 12px 30px rgba(7, 20, 43, 0.08);
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding: 1.35rem;
}

.document-card:nth-child(3n + 2) {
  border-left-color: var(--teal);
}

.document-card:nth-child(3n + 3) {
  border-left-color: #c58d00;
}

.document-card[hidden] {
  display: none;
}

.document-card-top {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  justify-content: space-between;
}

.document-id,
.document-status {
  border-radius: 999px;
  display: inline-flex;
  font-size: 0.78rem;
  font-weight: 900;
  min-height: 32px;
  padding: 0.35rem 0.7rem;
}

.document-id {
  background: var(--navy);
  color: #fff;
}

.document-status {
  background: var(--yellow-soft);
  border: 1px solid #8b6500;
  color: #533c00;
}

.document-card h3 {
  color: var(--navy);
  font-size: 1.3rem;
  line-height: 1.18;
  margin-bottom: 0.5rem;
}

.document-card > p {
  color: var(--muted);
}

.document-boundary {
  background: #fff9d8;
  border: 1px solid #8b6500;
  border-radius: 12px;
  color: #3d2c00 !important;
  padding: 0.8rem;
}

.document-card dl {
  margin: 0.3rem 0 1rem;
}

.document-card dl div {
  border-top: 1px solid var(--line);
  display: grid;
  gap: 0.5rem;
  grid-template-columns: 7.5rem minmax(0, 1fr);
  padding: 0.55rem 0;
}

.document-card dt {
  color: var(--navy);
  font-weight: 850;
}

.document-card dd {
  color: var(--muted);
  margin: 0;
  overflow-wrap: anywhere;
}

.document-links,
.document-section-links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
}

.document-link,
.document-section-links a {
  align-items: center;
  border: 2px solid var(--blue);
  border-radius: 999px;
  color: var(--blue);
  display: inline-flex;
  font-weight: 850;
  min-height: 44px;
  padding: 0.5rem 0.75rem;
  text-decoration: none;
}

.document-link-status {
  background: #f4f0e2;
  border: 1px solid #8b6500;
  border-radius: 12px;
  color: #4b3700;
  font-weight: 750;
  padding: 0.75rem;
}

.document-card details {
  margin-top: auto;
}

.document-status-link,
.document-title-link {
  text-decoration-thickness: 2px;
  text-underline-offset: 0.18em;
}

.document-status-link {
  justify-content: center;
  text-decoration: none;
}

.document-status-link:hover,
.document-status-link:focus-visible {
  background: #ffec86;
  color: #201700;
}

.document-title-link {
  color: var(--navy);
}

.document-title-link:hover {
  color: var(--blue);
}

body.pf-high-contrast .library-summary,
body.pf-high-contrast .library-controls,
body.pf-high-contrast .library-stats div,
body.pf-high-contrast .document-card,
body.pf-high-contrast .document-link-status {
  background: #fff !important;
  border-color: #000 !important;
  box-shadow: none !important;
  color: #000 !important;
}

body.pf-high-contrast .library-summary *,
body.pf-high-contrast .library-controls *,
body.pf-high-contrast .library-stats *,
body.pf-high-contrast .document-card * {
  color: #000 !important;
}

body.pf-high-contrast .document-id,
body.pf-contrast .document-id {
  background: #000 !important;
  border-color: #000 !important;
  color: #fff !important;
}

body.pf-high-contrast .document-status,
body.pf-high-contrast .document-status-link,
body.pf-contrast .document-status,
body.pf-contrast .document-status-link {
  background: #fff000 !important;
  border-color: #000 !important;
  color: #000 !important;
}

body.pf-high-contrast .document-link,
body.pf-high-contrast .document-section-links a,
body.pf-high-contrast .document-title-link,
body.pf-contrast .document-link,
body.pf-contrast .document-section-links a,
body.pf-contrast .document-title-link {
  background: #fff !important;
  border-color: #0000c8 !important;
  color: #0000c8 !important;
}

@media (max-width: 900px) {
  .library-stats,
  .library-filter-grid,
  .document-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 640px) {
  .library-stats,
  .library-filter-grid,
  .document-grid {
    grid-template-columns: 1fr;
  }

  .document-card dl div {
    grid-template-columns: 1fr;
  }
}
