/* ==========================================================================
   Text Alignment Utilities
   ========================================================================== */
.text-justify-center {
    text-align: center;
}

.text-justify-left {
    text-align: left;
}

/* ==========================================================================
   Tab Components
   ========================================================================== */
.tabs {
    text-align: center;
    margin-bottom: 20px;
}

.tab-link {
    background-color: var(--nav-bg-color);
    color: var(--text-color);
    border: none;
    border-radius: 8px;
    padding: 10px 20px;
    text-decoration: none;
    font-weight: bold;
    display: inline-block;
    transition: background-color 0.2s;
    cursor: pointer;
    margin: 0 5px;
}

.tab-link:hover, .tab-link.active {
    background-color: var(--link-hover-color);
    color: var(--main-color);
}

/* ==========================================================================
   Title Components
   ========================================================================== */
.page-main-title {
    background-color: var(--bg-color);
    border: 3px solid var(--link-hover-color);
    border-radius: 15px;
    padding: 10px 30px;
    text-align: center;
    margin-bottom: 30px;
    display: inline-block; /* Ensures the border fits the content */
}

.page-main-title h1 {
    font-family: 'Lora', serif;
    font-size: 2.8em;
    margin: 0;
}

.content-section h2 {
    font-family: 'Lora', serif;
    font-size: 2em;
    margin-top: 0;
    text-align: center;
    border-bottom: 2px solid var(--nav-bg-color);
    padding-bottom: 10px;
    margin-bottom: 20px;
}

/* Backwards compatibility for series page title if it's still in use */
.series-page-title {
    background-color: var(--bg-color);
    border: 3px solid var(--link-hover-color);
    border-radius: 15px;
    padding: 10px 30px;
    text-align: center;
    margin-bottom: 30px;
}

.series-page-title h2 {
    font-family: 'Lora', serif;
    font-size: 2.5em;
    margin: 0;
    border-bottom: none; /* Override the border from the general h2 */
}


/* ==========================================================================
   Grid Components
   ========================================================================== */
.series-grid,
.gallery-grid,
.product-grid {
    display: grid;
    column-gap: 25px;
    row-gap: 50px;
    padding-bottom: 25px; /* Add space after the last row of the grid */
}

.series-grid {
    grid-template-columns: repeat(3, 1fr);
}

/* --- Dynamic Gallery Grid Classes --- */
.gallery-grid.grid-cols-1 { grid-template-columns: 1fr; }
.gallery-grid.grid-cols-2 { grid-template-columns: repeat(2, 1fr); }
.gallery-grid.grid-cols-3 { grid-template-columns: repeat(3, 1fr); }
.gallery-grid.grid-cols-4 { grid-template-columns: repeat(4, 1fr); }


/* --- Responsive Grid Adjustments --- */
@media (max-width: 992px) {
    .gallery-grid.grid-cols-4, .gallery-grid.grid-cols-3 {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (max-width: 768px) {
    .series-grid, 
    .gallery-grid.grid-cols-4, .gallery-grid.grid-cols-3, .gallery-grid.grid-cols-2 {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 576px) {
    .series-grid,
    .gallery-grid,
    .product-grid {
        grid-template-columns: 1fr;
    }
}

/* ==========================================================================
   Grid View Controls
   ========================================================================== */
.grid-view-controls {
    text-align: right;
    margin-bottom: 20px;
}

.view-btn {
    background-color: var(--nav-bg-color);
    color: var(--text-color);
    border: 2px solid var(--link-hover-color);
    border-radius: 5px;
    padding: 5px 10px;
    cursor: pointer;
    font-weight: bold;
    transition: background-color 0.2s, color 0.2s;
}

.view-btn:hover {
    background-color: var(--link-hover-color);
    color: var(--main-color);
}

.view-btn.active {
    background-color: var(--link-hover-color);
    color: var(--main-color);
}


/* ==========================================================================
   Card Components
   ========================================================================== */

/* --- Base Card Style --- */
.card {
    background-color: transparent;
    color: var(--text-color);
    text-align: center;
    transition: transform 0.2s;
    display: flex;
    flex-direction: column;
    height: 100%;
}

.card:hover {
    transform: translateY(-5px);
}

.card img {
    max-width: 100%;
    height: auto;
    display: block;
    border-radius: 8px;
}

.card .card-info {
    padding: 15px 5px;
}

/* --- Structured Grid Card (for series index, resource images, and gallery lists) --- */
.series-grid .card,
.resource-images .card,
.gallery-grid .card {
    background-color: var(--main-color);
    border: 3px solid var(--link-hover-color);
    border-radius: 12px;
    padding: 10px;
}

.card .card-header {
    height: 1.5em; 
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 15px;
}

.card .card-header h2,
.card .card-header h3 {
    margin: 0;
    font-size: 1.2em;
    line-height: 1.2;
    border-bottom: none;
}

.card .card-image-container {
    flex-grow: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 10px 0;
}

.card .card-image-container img {
    max-height: 400px;
    width: auto;
    object-fit: contain;
}

.card .card-footer {
    margin-top: auto;
    padding: 5px;
}

/* ==========================================================================
   Redemption Card Specific Styling
   ========================================================================== */
.redemption-card {
    max-width: 20%;
    margin: 0 auto; /* Center the smaller card within its grid container */
}

.redemption-letter {
    max-width: 50%; /* Make the letter larger */
    margin: 0 auto;
}


/* ==========================================================================
   Button Components
   ========================================================================== */
.series-grid-button {
    background-color: var(--link-hover-color);
    color: var(--main-color);
    border-radius: 8px;
    padding: 10px 20px;
    text-decoration: none;
    font-weight: bold;
    display: inline-block;
    transition: background-color 0.2s;
}

.series-grid-button:hover {
    background-color: var(--text-color);
}

.card-info a.series-grid-button,
.card-footer a.series-grid-button {
    transition: background-color 0.2s, transform 0.2s;
}

.card-info a.series-grid-button:hover,
.card-footer a.series-grid-button:hover {
    transform: translateY(-2px);
}

/* ==========================================================================
   Catalogue Form
   ========================================================================== */
.catalogue-form {
    display: flex;
    flex-direction: column;
    align-items: flex-start; /* Justify to the left */
    gap: 20px; /* Vertical spacing between rows */
}

.catalogue-form .form-row {
    display: flex;
    flex-wrap: wrap;
    gap: 25px; /* Spacing between form elements in a row */
    width: 100%;
}

.catalogue-form .form-group {
    display: flex;
    flex-direction: column; /* Stack label on top of input */
    gap: 5px;
    flex: 1; /* Allow groups to grow */
    min-width: 200px; /* Prevent elements from becoming too small */
}

.catalogue-form .form-group label {
    font-weight: bold;
    text-align: left;
}

.catalogue-form .form-group select,
.catalogue-form .form-group input {
    padding: 8px;
    border-radius: 5px;
    border: 1px solid var(--nav-bg-color);
    background-color: var(--bg-color);
    color: var(--text-color);
    font-size: 1em;
}

.catalogue-form .form-group button {
    align-self: flex-end; /* Align button to the bottom of its container */
    height: 100%;
}

.form-row-adv {
    display: flex;
    gap: 25px;
    width: 100%;
}
.form-group-adv {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 15px;
}
.checkbox-list {
    max-height: 200px;
    overflow-y: auto;
    border: 1px solid var(--nav-bg-color);
    padding: 10px;
    border-radius: 5px;
    text-align: left;
}
.checkbox-list div {
    margin-bottom: 5px;
}

/* --- Catalogue Contents Summary --- */
.catalogue-summary-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 15px;
    background-color: #2d3748; /* A slightly lighter shade from your theme */
    padding: 10px;
    border-radius: 8px;
    border: 1px solid #4a5568; /* Border color from your theme */
    margin-bottom: 0.5rem; /* Adjusted back to 2rem for better spacing */
}
.summary-item {
    background-color: #1a202c; /* Main dark background from your theme */
    padding: 7px;
    border-radius: 6px;
    text-align: center;
    font-size: 1em;
    color: #cbd5e0; /* A light text color from your theme */
}
.summary-item strong {
    display: block;
    margin-bottom: 8px;
    color: #a0aec0; /* A slightly dimmer text color for the label */
    font-family: 'Roboto', sans-serif;
}

/* --- News Index Image Styling --- */
.news-item-image-container {
    margin: 15px 0;
    overflow: hidden;
    border-radius: 6px;
}

.news-item-image-container img {
    width: 100%;
    height: 150px; /* Fixed height for a consistent look */
    object-fit: cover; /* Ensures the image covers the area without distortion */
    display: block;
    transition: transform 0.3s ease;
}

.news-item-image-container a:hover img {
    transform: scale(1.05); /* Slight zoom effect on hover */
}

/* --- Debug Popup --- */
.debug-popup-overlay {
    position: fixed; 
    top: 0; 
    left: 0; 
    width: 100%; 
    height: 100%;
    background-color: rgba(0,0,0,0.7); 
    z-index: 1000;
    display: flex; 
    align-items: center; 
    justify-content: center;
}
.debug-popup-content {
    background-color: #2d3748; 
    color: #e2e8f0; 
    border: 2px solid #4a5568;
    border-radius: 8px; 
    padding: 20px; 
    width: 80%; 
    max-width: 900px;
    max-height: 80vh; 
    overflow-y: auto; 
    box-shadow: 0 5px 25px rgba(0,0,0,0.5);
    font-family: monospace, monospace;
}
.debug-popup-content h2 { 
    margin-top: 0; 
    color: #a0aec0; 
    border-bottom: 1px solid #4a5568; 
    padding-bottom: 10px; 
}
.debug-popup-content pre { 
    white-space: pre-wrap; 
    word-wrap: break-word; 
    font-size: 14px; 
}
.debug-popup-content .close-btn {
    float: right; 
    font-size: 24px; 
    font-weight: bold; 
    color: #a0aec0;
    cursor: pointer; 
    border: none; 
    background: none;
}

/* === Catalogue filters: mobile-friendly layout === */

/* Use grid for all rows of filter groups; auto-fit into columns and stack on phones */
.catalogue-form .form-row,
.catalogue-form .form-row-adv {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 16px 20px; /* row/column gaps */
  width: 100%;
}

/* Let groups shrink nicely and inputs fill width */
.catalogue-form .form-group,
.catalogue-form .form-group-adv {
  min-width: 0; /* prevents overflow on very narrow screens */
}

.catalogue-form input[type="text"],
.catalogue-form select,
.catalogue-form button,
.catalogue-form .btn {
  width: 100%;
  max-width: 100%;
}

/* Checkbox list: make sure it fits smaller screens */
.catalogue-form .checkbox-list {
  max-height: 240px;
  overflow-y: auto;
}

/* Actions row (Search / Reset etc.) — flexible & sticky on phones */
.catalogue-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 6px;
}

@media (max-width: 640px) {
  .catalogue-actions {
    position: sticky;
    bottom: 0;
    padding: 10px 8px;
    background: rgba(2, 2, 37, 0.92); /* matches --bg-color with slight alpha */
    border-top: 1px solid rgba(212, 210, 255, 0.25); /* matches theme accent */
    z-index: 5;
  }
  .catalogue-actions .btn,
  .catalogue-actions button {
    flex: 1 1 100%;
  }
}

/* Smallest screens: force single column if needed */
@media (max-width: 480px) {
  .catalogue-form .form-row,
  .catalogue-form .form-row-adv {
    grid-template-columns: 1fr;
  }
}

/* Advanced search: stack on phones, multi-column on wider screens */
.catalogue-form .form-row-adv {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 16px 20px; /* row / column gaps */
  width: 100%;
}

/* Ensure groups don't overflow on narrow screens */
.catalogue-form .form-group-adv {
  min-width: 0;
}

/* Inputs stretch to container width */
.catalogue-form .form-group-adv input[type="text"],
.catalogue-form .form-group-adv select {
  width: 100%;
  max-width: 100%;
}

/* Defensive overrides in case older styles force floats/flex */
.catalogue-form .form-group-adv {
  float: none;
}
.catalogue-form .form-row-adv > .form-group-adv {
  display: block; /* ensure each item is a block in its grid cell */
}

/* Small phones: force single column */
@media (max-width: 480px) {
  .catalogue-form .form-row-adv {
    grid-template-columns: 1fr;
  }
}

.badge-limited {
  display: inline-block;
  margin-left: 6px;
  padding: 2px 6px;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,.25);
  font-size: .85em;
  opacity: .9;
  vertical-align: middle;
}

/* ──────────────────────────────────────── */
/*  Grid tile images – always centre crop   */
/* ──────────────────────────────────────── */

.gallery-grid .grid-item img,
.grid-view-controls + .gallery-grid .grid-item img, /* fallback for nested selectors */
.grid-item > img {          /* just in case the image is a direct child */
    display: block;        /* removes the small bottom‑gap that inline images create */
    width: 100%;           /* make it fill the tile horizontally */
    height: auto;          /* keep aspect ratio (object-fit will crop vertically) */
    object-fit: cover;     /* fill the entire tile, cropping as needed */
    object-position: center;   /* centre‑crop the image */
}

/* Support both legacy '.card-image-container' and current '.card-image' wrappers */
.card .card-image {
    flex-grow: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 10px 0;
}

.card .card-image img {
    max-height: 400px;
    width: auto;
    object-fit: contain;
}


/* Ensure images inside gallery-grid cards are centered */
.gallery-grid .card .card-image,
.gallery-grid .card .card-image-container {
    display: flex;
    align-items: center;
    justify-content: center;
}

.gallery-grid .card .card-image img,
.gallery-grid .card .card-image-container img {
    display: block;
    margin: 0 auto;
}


/* Center images in series detail resource tiles (Trade Show, Limited, Unlimited) */
.resource-images .card {
    display: flex;
    justify-content: center;
    align-items: center;
}
.resource-images .card img {
    display: block;
    margin: 0 auto;
    height: auto;
}


/* Center the resource-images block itself (series detail tiles) */
.resource-images {
    display: grid;
    place-items: center;
    text-align: center; /* fallback for very old browsers */
}
