:root {
  /* Tile grid */
  /* Tile grid - Item container */
  --tile-grid--item-container--gap: 22px;
  --tile-grid--item-container--items_per_row: var(--tile-grid--item-container--items_per_row, 4);
}
/* Main styling */
.paragraph--type--oxfcms-layout-tile-grid {
  .oxfcms-grid-container {
    container-name: tile_grid;
    container-type: inline-size;
    .oxfcms-grid-items {
      grid-template-columns: 1fr;
      gap: var(--tile-grid--item-container--gap);
      grid-template-columns: repeat(var(--tile-grid--item-container--items_per_row), 1fr);
      display: grid;
      grid-auto-rows: max-content;
      align-items: stretch;
      &.oxfcms-grid-paginated {
        /* Force grid layout when pagination is active */
        grid-template-columns: repeat(var(--tile-grid--item-container--items_per_row), 1fr) !important;
        /* Note: Responsive breakpoints are now handled by JavaScript for better control */
        /* The JavaScript calculates the optimal items per row and sets --tile-grid--item-container--items_per_row accordingly */
      }
      /* Responsive grid columns for NON-PAGINATED grids only */
      /* Paginated grids (.oxfcms-grid-paginated) use JavaScript for responsive behavior */
      &:not(.oxfcms-grid-paginated) {
        /* Default: Use configured grid-items-per-row */
        grid-template-columns: repeat(var(--tile-grid--item-container--items_per_row), 1fr);
      }
      > div {
        height: 100%;
        width: 100%;
        align-self: stretch; /* align item heights in a grid row */
        > section {
          height: 100%;
          width: 100%;
          align-self: stretch; /* align item heights in a grid row */
        }
      }
      article.oxfcms-listing-item,
      .oxfcms-selected-content-item,
      .paragraph--type--oxfcms-layout-card {
        height: 100%;
        width: 100%;
        align-self: stretch; /* align item heights in a grid row */
        section {
          height: 100%;
          width: 100%;
          align-self: stretch; /* align item heights in a grid row */
        }
      }
      /* Stretch cards to match row height while allowing standalone images to keep aspect */
      .oxfcms-layout-card-image,
      .oxfcms-layout-card-landscape-image,
      .oxfcms-layout-card-landscape-thumbnail,
      .oxfcms-layout-card-landscape-text-only,
      .oxfcms-layout-card-no-image,
      .oxfcms-layout-card-icon {
        align-self: stretch;
        height: 100%;
      }
      /* Keep standalone images from stretching vertically */
      .paragraph.paragraph--type--oxfcms-image {
        .oxfcms-image {
          align-self: start;
          /* Preserve image aspect and border radius for standalone images in grids */
          .oxfcms-image-link,
          .oxfcms-image-wrapper {
            display: block;
            border-radius: var(--image--image-border-radius, 11px);
            overflow: hidden;
            height: auto;
          }
        }
      }
    }
    .pagination {
      /* Create the standard pager layout: Previous | Page Numbers | Next */
      display: flex;
      align-items: center;
      justify-content: space-between;
      width: 100%; /* Full width of the grid container */
      .pagination-button {
        &.pagination__previous-btn {
          /* Previous button anchored to the left */
          order: 1;
          margin-right: auto;
        }
        &:not(.pagination__previous-btn) {
          /* Next button anchored to the right */
          order: 3;
          margin-left: auto;
        }
      }
      ul {
        /* Page numbers centered */
        order: 2;
        display: flex;
        list-style: none;
        margin: 0;
        gap: 0.5rem;
        flex: 0 0 auto; /* Don't grow or shrink */
        li {
          margin: 0;
          list-style: none;
        }
      }
      a {
        &:focus {
          outline: 2px solid #007bff;
          outline-offset: 2px;
        }
      }
      .pagination-info {
        font-size: 0.875rem;
        color: #6c757d;
        text-align: center;
      }
    }
  }
  .pagination-loading-indicator {
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255 255 255 / 90%);
    border-radius: 8px;
    padding: 2rem;
    box-shadow: 0 2px 8px rgba(0 0 0 / 10%);
    backdrop-filter: blur(4px);
    min-width: 200px;
    /* Ensure it appears above grid content */
    z-index: 10;
  }
  .pagination-throbber {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
  }
  .pagination-throbber-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid #f3f3f3;
    border-top: 3px solid #007acc;
    border-radius: 50%;
    animation: pagination-spin 1s linear infinite;
  }
  .pagination-throbber-text {
    font-size: 0.875rem;
    color: #666666;
    font-weight: 500;
  }
}
 /* Mercury-specific styling */
.mercury-editor-context {
  .oxfcms-grid-container {
    .oxfcms-grid-items {
      /* Slightly different styling for Mercury Editor */
      border-style: solid;
      border-color: #e9ecef;
      &:empty::before {
        content: "Add content using Mercury Editor";
      }
    }
  }
}
/* Layout Paragraphs-specific styling */
.layout-paragraphs-builder .oxfcms-grid-container {
  .oxfcms-grid-items {
    /* Enhanced visual feedback for Layout Paragraphs Builder */
    background-color: rgba(0 123 255 / 5%);
    /* Better hover state */
    &:hover {
      border-color: #007bff;
      background-color: rgba(0 123 255 / 10%);
    }
    /* Active state when dragging */
    &.lpb-layout-drop-zone-active {
      border-color: #28a745;
      background-color: rgba(40 167 69 / 10%);
    }
  }
}
/* Edit Mode Styles */
.oxfcms-grid-container[data-is-edit-mode="true"],
body.path-admin .oxfcms-grid-container,
body.layout-paragraphs-builder .oxfcms-grid-container {
  .oxfcms-grid-items {
    /* Ensure minimum height for empty regions in edit mode */
    min-height: 120px;
    /* Add visual indicator for drop zones */
    position: relative;
    /* Show border in edit mode for better visibility */
    border: 2px dashed #dddddd;
    border-radius: 4px;
    /* Add some padding for better usability */
    padding: 16px;
    /* When empty, show a helpful message */
    &:empty::before {
      content: "Drop content here";
      display: flex;
      align-items: center;
      justify-content: center;
      height: 100%;
      min-height: 88px; /* Account for padding */
      color: #999999;
      font-style: italic;
      pointer-events: none;
    }
    /* Remove pagination styling in edit mode */
    &[data-enable-pagination="false"] {
      display: grid !important;
    }
  }
  /* Hide pagination controls in edit mode */
  .pagination-wrapper {
    display: none !important;
  }
  /* Ensure grid layout is preserved in edit mode */
  .oxfcms-grid-items {
    display: grid !important;
    grid-template-columns: repeat(var(--tile-grid--item-container--items_per_row), 1fr) !important;
  }
}
/* Breakpoint - Small Desktop */
@media (width < 1280px) {
  .paragraph--type--oxfcms-layout-tile-grid {
    --tile-grid--item-container--gap: 20px;
  }
}
/* Breakpoint - Small Desktop/Tablet */
@media (width < 991px) {
  .paragraph--type--oxfcms-layout-tile-grid {
    .oxfcms-grid-container {
      .oxfcms-grid-items {
        &:not(.oxfcms-grid-paginated) {
          grid-template-columns: repeat(min(var(--tile-grid--item-container--items_per_row), 3), 1fr);
        }
      }
    }
  }
}
/* Breakpoint - Tablet */
@media (width < 768px) {
  .paragraph--type--oxfcms-layout-tile-grid {
    --tile-grid--item-container--gap: 48px;
    .oxfcms-grid-container {
      .oxfcms-grid-items {
        &:not(.oxfcms-grid-paginated) {
          grid-template-columns: 1fr;
        }
      }
    }
    .pagination {
      /* On mobile, stack the pagination vertically or use a more compact layout */
      flex-direction: column;
      gap: 1rem;
      align-items: center;
      .pagination-button {
        /* Reset order and margins for mobile stacking */
        order: unset;
        margin: 0;
      }
      ul {
        /* Reset order for mobile */
        order: unset;
      }
    }
  }
}
/* Breakpoint - Mobile */
@media (width < 481px) {
  .paragraph--type--oxfcms-layout-tile-grid {
    .pagination {
      flex-direction: row;
      justify-content: space-between;
      max-width: 100%;
      ul {
        gap: 0.25rem;
        li {
          /* Make page number buttons smaller on very small screens */
          font-size: 0.875rem;
        }
      }
    }
  }
}
/* Keyframes */
@keyframes pagination-spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}
/* Reduced motion support for loading spinner */
@media (prefers-reduced-motion: reduce) {
  .pagination-throbber-spinner {
    animation: none;
    border-top-color: transparent;
    border-right-color: transparent;
    border-bottom-color: #007acc;
    border-left-color: #007acc;
  }
}
