
.attachments-browser {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr));
  grid-gap: 4rem 4rem;

  @media (min-width: 40em) { grid-template-columns: repeat(auto-fill, minmax(23rem, 1fr)); }

  .attachment--preview {
    .attachment__name { display: block; }

    img {
      border: 1px solid var(--color-border);
      max-width: calc(100% - 2px);
      max-height: 10rem;

      + .spinner {
        display: none;
        position: absolute;
        margin: 0;
      }

      &[data-loading] {
        opacity: 0;
        width: 0;
        + .spinner { display: initial; }
      }
    }
  }

  .attachment--file {
    background-color: transparent;
    border-radius: 0;
    max-width: none;
    width: 100%;

    &::before {
      display: none;
    }

    &::after {
      background-position-y: 55%;
      background-size: 45%;
      bottom: calc(100% - 12rem);
      max-width: 16rem;
      margin: 0 auto;
      pointer-events: none;
    }
  }

  .attachment__frame {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 10rem;
    position: relative;
  }

  .attachment__name {
    white-space: nowrap !important;
  }
}

.attachments-browser--strip {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  grid-auto-flow: column;
  grid-template-columns: repeat(auto-fill, 16rem);
  grid-gap: 2rem 2rem;
  padding-bottom: 0.5em;

  @media (max-width: 39.95em) {
    width: calc(100% + (2 * var(--page-padding)));
    margin-left: var(--negative-page-padding);
    overflow-y: hidden;
  }

  .attachment__source { display: none !important; }
  .attachment--file::after { bottom: calc(100% - 13rem); }
  .attachment__size { white-space: nowrap; }
  .attachment__caption { margin: 0.625em; }

  > figure {
    max-width: 16rem;
    display: block;
  }
}

.attachments-browser--strip-time .attachment__time {
  display: none;
}

.attachments-browser--standalone {
  grid-template-columns: repeat(auto-fill, minmax(14rem, 1fr));
  grid-gap: 2rem 2rem;
  overflow-x: initial;
  grid-auto-flow: row;
}

.attachments-browser--collection {
  display: inline-grid;
  justify-items: center;
  padding: 1rem 0 0.5rem;
  overflow-x: initial;

  @media (min-width: 40em) { padding: var(--base-space) 0 var(--half-space); }
}

/* Filetype and sender filters */
.attachments-filter { display: inline-block; }

.attachment__caption {
  color: var(--color--txt);
  display: block;
  font-size: 0.875em;
  font-weight: 500;
  line-height: 1.2;
  margin: 0.625em 1.25em;
  overflow: hidden;
  text-align: center;

  @media (min-width: 40em) {
    font-size: 0.75em;
    line-height: 1.3;
  }

  .attachment__name,
  .attachment__source {
    display: block;
  }

  .attachment__name {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .attachment__source {
    font-weight: normal;
    max-height: 2.6em;
    padding-bottom: 0.2em;
    overflow-y: hidden;
  }

  .attachment__size {
    color: var(--color-txt--subtle-on-message-content);
    font-weight: normal;
  }

  .attachment--preview & {
    .attachment__name { display: inline; white-space: normal; }
    .attachment__name + .attachment__size::before { content: ' · '; }
  }

  .attachment--file & {
    .attachment__name + .attachment__size::before { content: ''; }
  }

  .attachment__size {
    color: var(--color-txt--subtle);
  }
}

.attachment--file {
  background-color: var(--color-bg--surface-glint);
  border-radius: 10px;
  position: relative;
  width: calc(100% / 4 - 10px);
  border: 0;
  padding: 0 !important;
  margin: 0 6px 6px 0 !important;
  min-width: 150px; /* Uses pixels to avoid font scaling factor breakage */
  max-width: 200px;

  .attachment__name {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: block;
  }

  &::before {
    content: "";
    display: block;
    padding-top: 45%;
  }

  &::after {
    background: url("/assets/icons/attachments/text-files-3de18e47.svg") center 1.5em / 25% no-repeat;
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    right: 0;
    z-index: 0;
  }

  [data-color-scheme="dark"] & {
    &::after { background-image: url("/assets/icons/attachments/text-files-reverse-98788575.svg"); }
  }

  &.attachment--jpg,
  &.attachment--jpeg,
  &.attachment--png,
  &.attachment--gif,
  &.attachment--psd {
    &::after { background-image: url("/assets/icons/attachments/images-1346058e.svg"); }

    [data-color-scheme="dark"] & {
      &::after { background-image: url("/assets/icons/attachments/images-reverse-6850a029.svg"); }
    }
  }

  &.attachment--pdf {
    &::after { background-image: url("/assets/icons/attachments/pdfs-770c85af.svg"); }

    [data-color-scheme="dark"] & {
      &::after { background-image: url("/assets/icons/attachments/pdfs-reverse-2044372c.svg"); }
    }
  }

  &.attachment--doc,
  &.attachment--docx,
  &.attachment--pages,
  &.attachment--txt,
  &.attachment--odt {
    &::after { background-image: url("/assets/icons/attachments/documents-8d1a51da.svg"); }

    [data-color-scheme="dark"] & {
      &::after { background-image: url("/assets/icons/attachments/documents-reverse-9d480bc8.svg"); }
    }
  }

  &.attachment--csv,
  &.attachment--xls,
  &.attachment--xlsx,
  &.attachment--numbers,
  &.attachment--ods {
    &::after { background-image: url("/assets/icons/attachments/spreadsheets-d281f477.svg"); }

    [data-color-scheme="dark"] & {
      &::after { background-image: url("/assets/icons/attachments/spreadsheets-reverse-b7f87f5a.svg"); }
    }
  }

  &.attachment--ppt,
  &.attachment--pptx,
  &.attachment--keynote,
  &.attachment--odp {
    &::after { background-image: url("/assets/icons/attachments/presentations-2b1f45a9.svg"); }

    [data-color-scheme="dark"] & {
      &::after { background-image: url("/assets/icons/attachments/presentations-reverse-7001fa33.svg"); }
    }
  }

  &.attachment--mp4,
  &.attachment--mov,
  &.attachment--avi,
  &.attachment--mp3,
  &.attachment--m4v {
    &::after { background-image: url("/assets/icons/attachments/media-515be8c6.svg"); }

    [data-color-scheme="dark"] & {
      &::after { background-image: url("/assets/icons/attachments/media-reverse-c78b46f9.svg"); }
    }
  }

  &.attachment--zip,
  &.attachment--rar {
    &::after { background-image: url("/assets/icons/attachments/zip-files-600aa33c.svg"); }

    [data-color-scheme="dark"] & {
      &::after { background-image: url("/assets/icons/attachments/zip-files-reverse-df04b400.svg"); }
    }
  }

  &.attachment--ics {
    &::after { background-image: url("/assets/icons/attachments/calendar-invites-ee74786b.svg"); }

    [data-color-scheme="dark"] & {
      &::after { background-image: url("/assets/icons/attachments/calendar-invites-reverse-9150369e.svg"); }
    }
  }
}

.attachment--lightboxable img {
  cursor: zoom-in;
}

/* Topic attachments */
.topic_attachments__button {
  margin-top: var(--half-space);

  @media (min-width: 60em) {
    position: absolute;
    bottom: 0;
    right: 0;
    z-index: 1;
  }
}
