.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}

.library-page main {
  min-height: calc(100vh - 180px);
}

.library-hero {
  min-height: 350px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 310px;
  align-items: center;
  gap: 60px;
  padding: 56px 54px;
  border: 1px solid var(--line);
  border-radius: 30px;
  background:
    radial-gradient(circle at 88% 8%, rgba(201, 242, 97, 0.34), transparent 31%),
    linear-gradient(135deg, rgba(255, 255, 255, 0.98), rgba(226, 247, 239, 0.92));
  box-shadow: var(--shadow);
}

.library-hero h1 {
  margin: 14px 0 20px;
  font-size: clamp(42px, 5.6vw, 68px);
  line-height: 1.08;
  letter-spacing: -0.055em;
}

.library-hero h1 em {
  color: var(--green);
  font-style: normal;
}

.library-hero > div > p:last-child {
  max-width: 650px;
  margin: 0;
  color: var(--muted);
  font-size: 16px;
  line-height: 1.8;
}

.library-summary {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.library-summary div {
  min-height: 132px;
  display: grid;
  place-content: center;
  text-align: center;
  border: 1px solid rgba(10, 115, 86, 0.16);
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.78);
}

.library-summary strong,
.library-summary span {
  display: block;
}

.library-summary strong {
  color: var(--green-deep);
  font-size: 40px;
  letter-spacing: -0.06em;
}

.library-summary span {
  margin-top: 5px;
  color: var(--muted);
  font-size: 12px;
}

.library-section {
  padding: 58px 0 82px;
}

.library-heading,
.gallery-title-row,
.gallery-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}

.library-heading {
  margin-bottom: 22px;
}

.library-heading .eyebrow,
.library-heading h2,
.gallery-title-row h2,
.gallery-title-row p {
  margin: 0;
}

.library-heading h2,
.gallery-title-row h2 {
  font-size: 32px;
  letter-spacing: -0.04em;
}

.library-search input {
  width: min(320px, 42vw);
  min-height: 44px;
  padding: 0 15px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--white);
  color: var(--ink);
}

.folder-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 20px;
}

.folder-card {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: var(--white);
  box-shadow: 0 14px 38px rgba(23, 59, 48, 0.07);
  cursor: pointer;
  transition: transform 180ms ease, box-shadow 180ms ease;
}

.folder-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 22px 52px rgba(23, 59, 48, 0.13);
}

.folder-cover {
  position: relative;
  aspect-ratio: 16 / 10;
  display: grid;
  place-items: center;
  overflow: hidden;
  color: var(--green);
  background: linear-gradient(135deg, #e1f4eb, #f3f8df);
  font-size: 42px;
  font-weight: 800;
}

.folder-level-badge {
  position: absolute;
  top: 12px;
  right: 12px;
  padding: 5px 9px;
  border-radius: 999px;
  color: var(--green-deep);
  background: rgba(255, 255, 255, 0.9);
  font-size: 10px;
  font-weight: 700;
  box-shadow: 0 5px 14px rgba(23, 59, 48, 0.12);
}

.folder-delete-button {
  position: absolute;
  right: 12px;
  bottom: 12px;
  z-index: 2;
  min-height: 30px;
  padding: 0 10px;
  border: 1px solid #efc2b8;
  border-radius: 8px;
  color: #a23f2a;
  background: rgba(255, 248, 246, 0.94);
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
}

.folder-rename-button {
  position: absolute;
  left: 12px;
  bottom: 12px;
  z-index: 2;
  min-height: 30px;
  padding: 0 10px;
  border: 1px solid #a8d9c7;
  border-radius: 8px;
  color: var(--green-deep);
  background: rgba(243, 251, 247, 0.94);
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
}

.folder-cover img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

.folder-copy {
  padding: 18px 20px 20px;
}

.folder-copy strong,
.folder-copy span {
  display: block;
}

.folder-copy strong {
  overflow: hidden;
  font-size: 18px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.folder-copy span {
  margin-top: 7px;
  color: var(--muted);
  font-size: 12px;
}

.library-empty {
  padding: 70px 20px;
  border: 1px dashed #c9d8d1;
  border-radius: 20px;
  text-align: center;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.5);
}

.back-button {
  padding-left: 0;
}

.gallery-title-row p {
  margin-top: 7px;
  color: var(--muted);
  font-size: 13px;
}

.gallery-download-actions {
  display: flex;
  gap: 10px;
}

.gallery-download-actions .primary-button,
.gallery-download-actions .secondary-button,
.gallery-download-actions .danger-button {
  width: auto;
  margin: 0;
  padding-inline: 16px;
}

.gallery-toolbar {
  margin: 24px 0 20px;
  padding: 13px 15px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--white);
}

.toolbar-group {
  display: flex;
  align-items: center;
  gap: 9px;
  color: var(--muted);
  font-size: 12px;
}

.toolbar-group label {
  display: flex;
  align-items: center;
  gap: 7px;
}

.toolbar-group select,
.toolbar-button,
.segmented button {
  min-height: 34px;
  padding: 0 10px;
  border: 1px solid var(--line);
  color: var(--ink);
  background: #f9fbfa;
  cursor: pointer;
}

.toolbar-group select,
.toolbar-button {
  border-radius: 8px;
}

.segmented {
  display: flex;
}

.segmented button:first-child {
  border-radius: 8px 0 0 8px;
}

.segmented button:last-child {
  border-radius: 0 8px 8px 0;
}

.segmented button + button {
  margin-left: -1px;
}

.segmented button.active {
  position: relative;
  z-index: 1;
  border-color: var(--green);
  color: var(--green-deep);
  background: var(--mint);
  font-weight: 700;
}

.image-grid {
  --card-min: 220px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, var(--card-min)), 1fr));
  gap: 16px;
}

.image-grid.size-small { --card-min: 138px; gap: 11px; }
.image-grid.size-medium { --card-min: 220px; }
.image-grid.size-large { --card-min: 330px; gap: 20px; }

.image-grid.layout-masonry {
  display: block;
  columns: var(--card-min);
  column-gap: 16px;
}

.image-grid.layout-masonry .image-card {
  margin: 0 0 16px;
  break-inside: avoid;
}

.image-card {
  position: relative;
  overflow: hidden;
  border: 2px solid transparent;
  border-radius: 16px;
  background: var(--white);
  box-shadow: 0 10px 30px rgba(23, 59, 48, 0.08);
}

.image-card.selected {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(10, 115, 86, 0.12);
}

.image-preview-button {
  width: 100%;
  padding: 0;
  border: 0;
  background: #eaf1ed;
  cursor: zoom-in;
}

.layout-grid .image-preview-button {
  aspect-ratio: 1 / 1;
}

.image-preview-button img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

.layout-masonry .image-preview-button img {
  height: auto;
  max-height: 520px;
  object-fit: contain;
}

.image-select {
  position: absolute;
  top: 10px;
  left: 10px;
  z-index: 2;
  width: 22px;
  height: 22px;
  accent-color: var(--green);
}

.image-card-copy {
  padding: 12px;
}

.image-card-copy strong {
  display: block;
  overflow: hidden;
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.image-card-copy span {
  display: block;
  margin-top: 5px;
  color: var(--muted);
  font-size: 10px;
}

.image-card-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px;
  margin-top: 9px;
}

.image-card-actions.single-action {
  grid-template-columns: 1fr;
}

.image-download-link {
  min-height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 6px;
  border: 1px solid #a8d9c7;
  border-radius: 8px;
  color: var(--green);
  background: #f3fbf7;
  font-size: 11px;
  font-weight: 700;
  text-decoration: none;
}

.image-delete-button {
  width: 100%;
  min-height: 32px;
  padding: 0 6px;
  border: 1px solid #efc2b8;
  border-radius: 8px;
  color: #a23f2a;
  background: #fff8f6;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
}

.size-small .image-card-copy {
  padding: 9px;
}

.size-small .image-card-copy span {
  display: none;
}

.download-progress,
.upload-progress {
  margin-bottom: 18px;
  padding: 13px 15px;
  border: 1px solid #bddfce;
  border-radius: 12px;
  color: var(--green-deep);
  background: #effaf5;
  font-size: 13px;
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 15px;
  margin-top: 28px;
}

.pagination .secondary-button {
  width: auto;
}

.pagination span {
  color: var(--muted);
  font-size: 12px;
}

.library-admin-dialog {
  width: min(760px, 100%);
}

.admin-intro {
  margin: 18px 0 24px;
  color: var(--muted);
  line-height: 1.7;
}

.upload-folder-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.upload-folder-grid .field {
  margin: 0;
}

.library-drop-zone {
  display: grid;
  gap: 8px;
  margin-top: 18px;
  padding: 30px;
  border: 2px dashed #b9cec4;
  border-radius: 16px;
  text-align: center;
  background: #f7fbf9;
  cursor: pointer;
}

.library-drop-zone span,
.selected-files-summary {
  color: var(--muted);
  font-size: 12px;
}

.library-drop-zone input {
  max-width: 100%;
  margin: 10px auto 0;
}

.library-drop-zone small {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.6;
}

.upload-picker-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  width: min(520px, 100%);
  margin: 12px auto 4px;
}

.file-picker-label {
  display: grid;
  gap: 6px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 11px;
  color: var(--green-deep);
  background: var(--white);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

.file-picker-label input {
  width: 100%;
  margin: 0;
  color: var(--muted);
  font-size: 10px;
  font-weight: 400;
}

.selected-files-summary {
  margin-top: 12px;
}

.upload-progress > div {
  height: 8px;
  overflow: hidden;
  border-radius: 99px;
  background: #d7e9e0;
}

.upload-progress > div span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: var(--green);
  transition: width 180ms ease;
}

.upload-progress p {
  margin: 8px 0 0;
}

.rename-folder-dialog {
  width: min(520px, 100%);
}

.rename-folder-dialog form {
  margin-top: 24px;
}

.rename-folder-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 20px;
}

.rename-folder-actions .primary-button,
.rename-folder-actions .secondary-button {
  width: 100%;
  margin: 0;
}

.image-lightbox {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 60px 30px;
  background: rgba(5, 17, 13, 0.9);
}

.image-lightbox img {
  max-width: min(1200px, 94vw);
  max-height: calc(100vh - 140px);
  object-fit: contain;
}

.image-lightbox p {
  position: absolute;
  bottom: 18px;
  max-width: 80vw;
  overflow: hidden;
  color: white;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lightbox-close {
  position: absolute;
  top: 20px;
  right: 25px;
  border: 0;
  color: white;
  background: none;
  font-size: 38px;
  cursor: pointer;
}

@media (max-width: 900px) {
  .library-hero {
    grid-template-columns: 1fr;
    gap: 30px;
  }

  .library-summary {
    max-width: 360px;
  }

  .folder-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .gallery-toolbar,
  .gallery-title-row {
    align-items: flex-start;
    flex-direction: column;
  }

  .toolbar-group {
    flex-wrap: wrap;
  }
}

@media (max-width: 620px) {
  .library-hero {
    min-height: auto;
    padding: 40px 24px;
    border-radius: 22px;
  }

  .library-hero h1 {
    font-size: 40px;
  }

  .library-hero h1 br {
    display: none;
  }

  .library-heading {
    align-items: flex-start;
    flex-direction: column;
  }

  .library-search,
  .library-search input {
    width: 100%;
  }

  .folder-grid {
    grid-template-columns: 1fr;
  }

  .gallery-download-actions {
    width: 100%;
    flex-wrap: wrap;
  }

  .gallery-download-actions button {
    flex: 1;
  }

  .upload-folder-grid {
    grid-template-columns: 1fr;
  }

  .upload-picker-actions,
  .rename-folder-actions {
    grid-template-columns: 1fr;
  }

  .image-grid.size-large { --card-min: 260px; }
}
