/**
 * The Stash Library Frontend Styles (V3 - AJAX Layout)
 * Main stylesheet for the public-facing display of The Stash Library.
 */

/* --- General Page & Layout --- */
.stash-library-archive-page #primary,
body.has-the-stash-shortcode #primary { /* Target pages with shortcode too */
    max-width: 100%; /* Allow our layout to use full width if theme allows */
}

.stash-layout-container {
    display: flex;
    flex-wrap: wrap; /* Allow sidebar to wrap on smaller screens */
    gap: 25px;       /* Space between sidebar and main content area */
    margin-top: 20px;
}

#stash-filters-sidebar {
    flex: 0 0 260px; /* Fixed width for the sidebar */
    max-width: 100%; /* Ensure it doesn't overflow on very small screens before wrapping */
    /* Optional: padding-right: 15px; if gap isn't enough or for border */
    /* Optional: border-right: 1px solid #e0e0e0; for a visual separator */
}

#stash-grid-main-content {
    flex: 1;          /* Main content area takes up the remaining space */
    min-width: 0;     /* Important for flex items to shrink properly and not overflow */
}

/* Responsive: Stack sidebar above content on smaller screens */
@media (max-width: 991px) { /* Common breakpoint for sidebar stacking */
    .stash-layout-container {
        flex-direction: column;
        gap: 20px;
    }
    #stash-filters-sidebar {
        flex: 0 0 auto; /* Reset flex-basis */
        width: 100%;    /* Make sidebar full width */
        padding-right: 0;
        border-right: none;
        border-bottom: 1px solid #e5e5e5; /* Add separator below filters when stacked */
        padding-bottom: 20px; /* Space below filters when stacked */
        margin-bottom: 20px; /* Space between stacked sidebar and grid */
    }
}

/* --- Filter Form in Sidebar --- */
#the-stash-library-filters-form h4 {
    margin-top: 0;
    margin-bottom: 18px;
    font-size: 1.25em;
    color: #2c3e50; /* Darker, professional blue-gray */
    border-bottom: 2px solid #0073aa; /* WordPress blue accent */
    padding-bottom: 8px;
}

#the-stash-library-filters-form .filter-group {
    margin-bottom: 18px;
}

#the-stash-library-filters-form .filter-group label, /* For select/input labels */
#the-stash-library-filters-form .filter-group legend { /* For fieldset legends (e.g., Tags) */
    font-weight: 600;
    display: block;
    margin-bottom: 6px;
    font-size: 0.9em;
    color: #454545;
}

#the-stash-library-filters-form .filter-group input[type="search"],
#the-stash-library-filters-form .filter-group select {
    width: 100%; /* Make form elements full width of the sidebar */
    padding: 9px 10px;
    border: 1px solid #ccd0d4; /* WordPress-like border */
    border-radius: 3px;
    box-sizing: border-box; /* Include padding and border in the element's total width and height */
    font-size: 0.95rem;
    background-color: #fff;
    color: #32373c;
    transition: border-color 0.1s ease-in-out;
}
#the-stash-library-filters-form .filter-group input[type="search"]:focus,
#the-stash-library-filters-form .filter-group select:focus {
    border-color: #007cba; /* WordPress focus blue */
    box-shadow: 0 0 0 1px #007cba;
    outline: 2px solid transparent; /* Remove default outline */
}

#the-stash-library-filters-form .filter-options-scrollbox { /* For tag checkboxes */
    max-height: 160px; /* Limit height for many tags */
    overflow-y: auto;
    border: 1px solid #ccd0d4;
    padding: 10px;
    background-color: #fff;
    border-radius: 3px;
}

#the-stash-library-filters-form .tag-checkbox {
    display: block; /* Each tag on a new line for better readability in scrollbox */
    margin-bottom: 5px;
    font-size: 0.9em;
    font-weight: normal; /* Tags are not legends */
    color: #32373c;
}
#the-stash-library-filters-form .tag-checkbox input[type="checkbox"] {
    margin-right: 7px;
    vertical-align: middle;
}

#the-stash-library-filters-form .filter-group.sort-filter select {
    margin-bottom: 8px; /* Space between sort dropdowns if they stack */
}
/* Ensure last select in sort doesn't have bottom margin if it's the only one or last */
#the-stash-library-filters-form .filter-group.sort-filter select:last-of-type {
    margin-bottom: 0;
}


#the-stash-library-filters-form .submit-filter button {
    width: 100%;
    padding: 10px 15px;
    font-size: 1em;
    font-weight: 500;
    margin-bottom: 10px;
    border-radius: 3px;
    cursor: pointer;
    text-align: center;
    text-decoration: none;
    border-width: 1px;
    border-style: solid;
}
#the-stash-library-filters-form .submit-filter button:last-child {
    margin-bottom: 0;
}
#the-stash-library-filters-form .button.button-primary {
    background-color: #0073aa;
    border-color: #006799;
    color: #fff;
}
#the-stash-library-filters-form .button.button-primary:hover,
#the-stash-library-filters-form .button.button-primary:focus {
    background-color: #005a87;
    border-color: #004a70;
    color: #fff;
}
#the-stash-library-filters-form .button.button-secondary {
    background-color: #f3f5f6;
    border-color: #dcdcde;
    color: #2c3338;
}
#the-stash-library-filters-form .button.button-secondary:hover,
#the-stash-library-filters-form .button.button-secondary:focus {
    background-color: #e8eaeb;
    border-color: #c9cacc;
    color: #1d2327;
}

/* --- Stash Items Grid --- */
.stash-library-grid {
    display: grid;
    /* Default to auto-fill, minmax for responsiveness within the main content area */
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); 
    gap: 20px; /* Gap between items */
    margin-bottom: 30px; /* Space before pagination */
}
.stash-grid-ajax-loader { /* Loader during AJAX calls */
    text-align:center;
    padding:40px 20px;
    font-size: 1.1em;
    color: #777;
}
.stash-grid-ajax-loader .dashicons { /* If using dashicon for loader */
    animation: spin 1s linear infinite;
    font-size: 2em;
}
.no-stash-items-found {
    padding: 25px;
    text-align: center;
    background-color: #f9f9f9;
    border: 1px dashed #ddd;
    border-radius: 4px;
    margin-top: 10px; /* If filters are above */
    color: #555;
}

.stash-item {
    border: 1px solid #e5e5e5; /* Lighter border */
    border-radius: 4px; /* Slightly more rounded */
    background-color: #fff;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
    transition: transform 0.15s ease-out, box-shadow 0.15s ease-out;
    display: flex;
    flex-direction: column;
    overflow: hidden; /* Clip content like long titles */
}
.stash-item:hover {
    transform: translateY(-3px);
    box-shadow: 0 4px 10px rgba(0,0,0,0.08);
}
a.stash-item-preview-trigger {
    text-decoration: none;
    color: inherit;
    display: flex;
    flex-direction: column;
    flex-grow: 1; /* Make the link fill the item */
}
.stash-item-thumbnail-wrapper {
    width: 100%;
    padding-top: 75%; /* 4:3 Aspect Ratio for thumbnails */
    position: relative;
    background-color: #f0f0f0; /* Placeholder bg for images */
    overflow: hidden; /* Ensure image fits */
}
.stash-item-thumbnail {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover; /* Scale image to cover, cropping if necessary */
    transition: transform 0.2s ease-in-out;
}
.stash-item:hover .stash-item-thumbnail {
    transform: scale(1.05); /* Slight zoom on hover */
}
.stash-item-title {
    font-size: 0.95em; /* Adjust for potentially smaller grid items */
    margin: 10px 12px 8px 12px;
    color: #32373c; /* WordPress text color */
    font-weight: 600;
    line-height: 1.3;
    text-align: center;
    /* Ensure titles don't break layout, use text-overflow if needed */
    min-height: 2.6em; /* Approx 2 lines */
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2; /* Limit to 2 lines */
    -webkit-box-orient: vertical;
}
.stash-item-tags {
    padding: 0 10px 10px 10px;
    margin-top: auto; /* Push tags to the bottom of the card */
    text-align: center;
    font-size: 0.8em;
}
.stash-item-tags .tag {
    display: inline-block;
    background-color: #f0f0f0; /* Lighter tag background */
    color: #50575e; /* Darker tag text */
    font-size: 0.9em; /* Relative to parent (.stash-item-tags) */
    padding: 2px 6px;
    border-radius: 3px;
    margin: 2px;
    font-weight: 500;
}

/* --- Pagination --- */
.stash-library-pagination {
    text-align: center;
    margin-top: 30px; /* Space above pagination */
    clear: both; /* Ensure it's below floated elements if any */
}
.stash-library-pagination ul {
    list-style: none;
    padding: 0;
    margin: 0;
    display: inline-block; /* Allows centering of the ul */
}
.stash-library-pagination ul li {
    display: inline;
    margin: 0 3px; /* Space between page numbers */
}
.stash-library-pagination .page-numbers {
    display: inline-block;
    padding: 8px 13px;
    border: 1px solid #dcdcde; /* WordPress-like border */
    text-decoration: none;
    color: #0073aa; /* WordPress blue */
    border-radius: 3px;
    font-size: 0.95em;
    transition: background-color 0.1s ease-in-out, color 0.1s ease-in-out, border-color 0.1s ease-in-out;
}
.stash-library-pagination .page-numbers.current,
.stash-library-pagination .page-numbers:hover,
.stash-library-pagination .page-numbers:focus {
    background-color: #0073aa;
    color: #fff;
    border-color: #006799;
}
.stash-library-pagination .page-numbers:hover:not(.current),
.stash-library-pagination .page-numbers:focus:not(.current) {
    background-color: #f3f5f6;
    color: #005a87;
    border-color: #c9cacc;
}
.stash-library-pagination .dots {
    padding: 8px 6px;
    color: #50575e;
}

/* --- Modal (Preview Popup) --- */
body.modal-open {
    overflow: hidden; /* Prevent background scroll when modal is open */
}
#stash-item-preview-modal {
    display: none; /* Hidden by default */
    position: fixed;
    z-index: 100000; /* Very high z-index to ensure it's on top */
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow-y: auto; /* Allow modal content to scroll if it's too long */
    background-color: rgba(25, 30, 35, 0.92); /* Darker, slightly transparent overlay */
    -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
}
#stash-item-preview-modal-content {
    background-color: #fff;
    margin: 2.5% auto; /* Centered, with some top margin */
    padding: 25px 30px;
    border: none;
    width: 90%;
    max-width: 780px; /* Max width for the modal */
    border-radius: 5px;
    position: relative;
    box-shadow: 0 10px 30px rgba(0,0,0,0.25);
    display: flex;
    flex-direction: column;
}
#stash-item-preview-modal-close {
    color: #656e77; /* Subtler close button */
    font-size: 2rem; /* Larger close icon */
    font-weight: 300; /* Lighter weight for '×' */
    position: absolute;
    top: 12px;
    right: 18px;
    background: none;
    border: none;
    padding: 0;
    line-height: 1;
    cursor: pointer;
    transition: color 0.15s ease;
}
#stash-item-preview-modal-close:hover,
#stash-item-preview-modal-close:focus {
    color: #1d2327; /* Darker on hover/focus */
    text-decoration: none;
    outline: none;
}
#stash-item-preview-loader {
    font-size: 1.25em;
    color: #50575e;
    padding: 60px 20px; /* More padding for loader text */
    text-align: center;
    min-height: 200px; /* Ensure loader has some space */
    display: flex;
    align-items: center;
    justify-content: center;
}
#stash-item-preview-details h2#stash-item-preview-modal-title {
    margin-top: 0;
    margin-bottom: 20px;
    color: #1d2327; /* Dark heading */
    border-bottom: 1px solid #e5e5e5;
    padding-bottom: 15px;
    font-size: 1.75em; /* Prominent title */
    font-weight: 600;
    line-height: 1.3;
}

/* Modal Gallery Styles */
.stash-item-preview-gallery {
    position: relative;
    margin-bottom: 25px;
    background-color: #f7f7f7; /* Light background for the gallery area */
    border-radius: 4px;
    overflow: hidden; /* Ensures nav buttons don't overflow rounded corners */
    border: 1px solid #e9e9e9;
}
.gallery-main-image {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 280px; /* Min height for gallery area */
    max-height: 520px; /* Max height for the main image */
}
.gallery-main-image img {
    width: auto; /* Let image scale naturally based on its aspect ratio */
    height: auto;
    max-width: 100%;
    max-height: 520px; /* Match container max height */
    object-fit: contain; /* Show the entire image, letterboxed if necessary */
    border-radius: 3px; /* Slight rounding if image is smaller than container */
}
.gallery-main-image .no-preview-image { /* If no images are available */
    padding: 20px;
    color: #777;
    font-style: italic;
}
.gallery-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background-color: rgba(30, 35, 40, 0.55); /* Semi-transparent background */
    color: white;
    border: none;
    padding: 10px; /* Adjust padding for button size */
    font-size: 26px; /* Size of arrow icon */
    cursor: pointer;
    border-radius: 50%; /* Circular buttons */
    line-height: 1;
    width: 46px;  /* Fixed width for button */
    height: 46px; /* Fixed height for button */
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s ease;
    z-index: 10; /* Ensure nav buttons are above the image */
    opacity: 0.8;
}
.gallery-nav:hover, .gallery-nav:focus {
    background-color: rgba(10, 15, 20, 0.75); /* Darker on hover/focus */
    opacity: 1;
    outline: none;
}
.gallery-nav.prev { left: 12px; }
.gallery-nav.next { right: 12px; }
.gallery-nav:disabled { /* If you implement disabled state */
    opacity: 0.3;
    cursor: default;
}


/* Modal Info Section (Description, Taxonomies, etc.) */
.stash-item-preview-info {
    padding-top: 10px;
}
.stash-item-preview-info h3 {
    font-size: 1.2em;
    color: #2c3338;
    margin-top: 22px; /* More space above section titles */
    margin-bottom: 10px;
    font-weight: 600;
    border-bottom: 1px solid #f0f0f0;
    padding-bottom: 6px;
}
.stash-item-preview-info h3:first-of-type {
    margin-top: 0; /* No top margin for the very first h3 (e.g., Description) */
}
.stash-item-preview-info p {
    margin: 0.5rem 0 1.1rem; /* Consistent paragraph spacing */
    line-height: 1.65;
    color: #3c434a; /* Slightly lighter text color */
    font-size: 0.95rem;
}
.stash-item-preview-info strong {
    color: #1d2327; /* Darker for strong emphasis */
    font-weight: 600;
}
.stash-item-description { /* Class for the description content div */
    background-color: #f9f9f9;
    padding: 15px;
    border-radius: 3px;
    margin-bottom: 1.5rem;
    border: 1px solid #eef0f2;
    font-size: 0.95rem;
    line-height: 1.7;
}
.license-name { /* For license terms with tooltips */
    cursor: help;
    border-bottom: 1px dotted #50575e;
    color: #0073aa; /* Link-like color */
}

/* Modal Downloadable Files List */
.download-files-list {
    list-style: none;
    padding: 0;
    margin: 0 0 1.5rem 0;
}
.download-files-list li {
    margin-bottom: 10px;
}
.download-stash-file-button { /* Specific class for download buttons */
    display: flex;
    align-items: center;
    width: 100%;
    text-align: left;
    padding: 12px 18px !important; /* Important to override general button styles if needed */
    background-color: #f0f3f5 !important; /* Lighter, distinct background */
    border: 1px solid #d5dbe0 !important;
    color: #2c3338 !important;
    border-radius: 3px;
    font-size: 0.95rem;
    font-weight: 500;
    transition: background-color 0.15s ease, border-color 0.15s ease;
    cursor: pointer;
}
.download-stash-file-button:hover,
.download-stash-file-button:focus {
    background-color: #e6eaed !important;
    border-color: #c8ced3 !important;
    outline: none;
}
.download-stash-file-button .dashicons {
    margin-right: 10px;
    font-size: 1.25em; /* Slightly larger icon */
    color: #454c54;
    vertical-align: middle;
}
.download-stash-file-button .file-size {
    margin-left: auto; /* Push file size to the right */
    font-size: 0.85em;
    color: #656e77;
}
.download-stash-file-button .loading-icon { /* For processing state */
    animation: spin 1s linear infinite;
}
.download-count-wrapper {
    margin-top: 20px;
    font-size: 0.9em;
    color: #50575e;
}

/* Animation for loader icon */
@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Screen reader text utility class */
.screen-reader-text {
	border: 0;
	clip: rect(1px, 1px, 1px, 1px);
	clip-path: inset(50%);
	height: 1px;
	margin: -1px;
	overflow: hidden;
	padding: 0;
	position: absolute !important;
	width: 1px;
	word-wrap: normal !important; /* Many WP themes include this, good practice */
}


/* --- Responsive Adjustments for Sidebar Layout & Grid --- */
/* Tablet and smaller */
@media (max-width: 767px) {
    .stash-layout-container {
        flex-direction: column; /* Stack sidebar on top of content */
    }
    #stash-filters-sidebar {
        width: 100%;
        flex-basis: auto; /* Allow it to take natural height */
        margin-bottom: 25px;
        padding-right: 0;
        border-right: none;
        border-bottom: 1px solid #e0e0e0; /* Separator line when stacked */
        padding-bottom: 25px; /* Spacing below filters */
    }
    .stash-library-grid {
        /* Adjust minmax for smaller items on mobile, e.g., 2 columns */
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); 
        gap: 15px;
    }
    .stash-item-title {
        font-size: 0.9em;
        min-height: 2.4em; /* Adjust if needed for smaller font */
    }
    #stash-item-preview-modal-content {
        margin: 5% auto; /* More top margin on mobile */
        padding: 20px;
    }
    #stash-item-preview-details h2#stash-item-preview-modal-title {
        font-size: 1.5em;
    }
    .gallery-main-image {
        min-height: 200px;
        max-height: 350px;
    }
    .gallery-main-image img {
        max-height: 350px;
    }
}

/* Small mobile */
@media (max-width: 480px) {
    #the-stash-library-filters-form .filter-group input[type="search"],
    #the-stash-library-filters-form .filter-group select {
        font-size: 0.9rem; /* Slightly smaller font for form elements */
    }
    #the-stash-library-filters-form .submit-filter button {
        font-size: 0.95em;
        padding: 9px 12px;
    }
    .stash-library-grid {
        grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); /* Even smaller items or 1 column */
        gap: 10px;
    }
     /* Or 1 column on very small screens:
    .stash-library-grid { grid-template-columns: 1fr; }
    */
    .stash-item-title {
        font-size: 0.85em;
    }
    .stash-library-pagination .page-numbers {
        padding: 6px 10px;
        font-size: 0.85em;
    }
    #stash-item-preview-modal-content {
        padding: 15px;
    }
     #stash-item-preview-details h2#stash-item-preview-modal-title {
        font-size: 1.3em;
    }
}
