/**
 * Gramps Media Gallery Styles
 */

/* Container */
.gramps-media-container {
    min-height: 80vh;
    background: #f7f0e4;
    color: #33271c;
    padding: 18px;
}

.gramps-media-filterbar {
    display: grid;
    grid-template-columns: repeat(4, minmax(170px, 1fr)) auto;
    gap: 10px;
    align-items: end;
    margin: 0 0 18px;
    padding: 14px;
    background: #fffaf0;
    border: 1px solid #d8c8ad;
    box-shadow: 0 10px 26px rgba(65, 42, 22, 0.08);
}

.gramps-media-filterbar__field {
    display: grid;
    gap: 5px;
    margin: 0;
}

.gramps-media-filterbar__field span {
    color: #75614d;
    font-family: 'Lora', Georgia, serif;
    font-size: 12px;
    font-weight: 700;
}

.gramps-media-filterbar__field select {
    width: 100%;
    min-height: 36px;
    border: 1px solid #d8c8ad;
    background: #fff;
    color: #33271c;
    border-radius: 4px;
}

.gramps-media-filterbar__button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    min-height: 36px;
    padding: 0 15px;
    border: 1px solid #57351f;
    border-radius: 4px;
    background: #7d4b2b;
    color: #fff;
    font-weight: 700;
    cursor: pointer;
}

.gramps-media-filterbar__button:hover,
.gramps-media-filterbar__button:focus {
    background: #57351f;
    color: #fff;
}

/* Sidebar */
.gramps-media-sidebar {
    background: #fff;
    border-right: 1px solid #e2e8f0;
    min-height: 80vh;
}

.gramps-media-sidebar__header {
    padding: 0;
    border-bottom: 1px solid #e2e8f0;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #fff;
}

/* Segmented Control - Clean with sliding highlight */
.gramps-media-tabs.nav.nav-pills {
    position: relative;
    display: flex !important;
    width: 100%;
    background: rgba(255, 255, 255, 0.15);
    border-radius: 0;
    padding: 0;
    margin: 0;
}

/* Sliding highlight indicator */
.gramps-media-tabs.nav.nav-pills::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 33.333%;
    height: 100%;
    background: rgba(255, 255, 255, 0.15);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 0;
}

/* Move indicator to 2nd tab */
.gramps-media-tabs.nav.nav-pills:has(.nav-item:nth-child(2) .nav-link.active)::before {
    transform: translateX(100%);
}

/* Move indicator to 3rd tab */
.gramps-media-tabs.nav.nav-pills:has(.nav-item:nth-child(3) .nav-link.active)::before {
    transform: translateX(200%);
}

.gramps-media-tabs.nav.nav-pills .nav-item {
    flex: 1;
    z-index: 1;
    margin: 0 !important;
    padding: 0 !important;
}

/* Reset all button styles */
.gramps-media-tabs.nav.nav-pills .nav-link,
.gramps-media-tabs.nav.nav-pills .nav-link.active,
.gramps-media-tabs.nav.nav-pills .nav-link:hover,
.gramps-media-tabs.nav.nav-pills .nav-link:focus {
    display: flex !important;
    align-items: center;
    justify-content: center;
    width: 100%;
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
    outline: none !important;
    border-radius: 0 !important;
    margin: 0 !important;
    padding: 0.875rem 0 !important;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    transition: color 0.3s ease;
}

/* Text colors */
.gramps-media-tabs.nav.nav-pills .nav-link {
    color: rgba(255, 255, 255, 0.7) !important;
}

.gramps-media-tabs.nav.nav-pills .nav-link:hover {
    color: rgba(255, 255, 255, 0.9) !important;
}

.gramps-media-tabs.nav.nav-pills .nav-link.active {
    color: #fff !important;
}

/* Hide icons */
.gramps-media-tabs.nav.nav-pills .nav-link i {
    display: none;
}

/* Search input in persons tab */
.gramps-media-sidebar__search {
    background: #f8fafc;
    border-bottom: 1px solid #e2e8f0;
}

.gramps-media-sidebar__search .input-group-text {
    border-color: #e2e8f0;
}

.gramps-media-sidebar__search .form-control {
    border-color: #e2e8f0;
}

.gramps-media-sidebar__search .form-control:focus {
    border-color: #667eea;
    box-shadow: none;
}

/* Persons list items */
#persons-list .list-group-item {
    cursor: pointer;
}

#persons-list .gramps-person-item {
    padding-left: 8px;
    padding-right: 8px;
}

#persons-list .gramps-person-dates {
    font-size: 0.8rem;
    color: #6c757d;
}

#persons-list .list-group-item.active .gramps-person-dates {
    color: rgba(255, 255, 255, 0.7);
}

/* Loading spinner for persons */
#persons-list .gramps-loading {
    padding: 2rem;
    text-align: center;
    color: #6c757d;
}

#persons-list .gramps-loading .spinner-border {
    width: 1.5rem;
    height: 1.5rem;
}

/* No results message */
#persons-list .gramps-no-results {
    padding: 2rem;
    text-align: center;
    color: #6c757d;
}

.gramps-media-sidebar .list-group.list-group-flush .list-group-item {
    border: none;
    border-bottom: 1px solid #f1f5f9;
    padding-left: 8px;
    padding-right: 8px;
    padding-top: 0.875rem;
    padding-bottom: 0.875rem;
}

.gramps-media-sidebar .list-group-item.active {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

/* Scrollable lists (albums and persons) */
.gramps-media-sidebar .tab-content {
    max-height: calc(80vh - 60px); /* viewport minus header */
    overflow-y: auto;
}

#tab-wp-albums .list-group,
#tab-collections .list-group,
#persons-list {
    max-height: calc(80vh - 120px);
    overflow-y: auto;
}

/* Custom scrollbar for sidebar lists */
.gramps-media-sidebar .tab-content::-webkit-scrollbar,
#tab-wp-albums .list-group::-webkit-scrollbar,
#tab-collections .list-group::-webkit-scrollbar,
#persons-list::-webkit-scrollbar {
    width: 6px;
}

.gramps-media-sidebar .tab-content::-webkit-scrollbar-track,
#tab-wp-albums .list-group::-webkit-scrollbar-track,
#tab-collections .list-group::-webkit-scrollbar-track,
#persons-list::-webkit-scrollbar-track {
    background: #f1f5f9;
}

.gramps-media-sidebar .tab-content::-webkit-scrollbar-thumb,
#tab-wp-albums .list-group::-webkit-scrollbar-thumb,
#tab-collections .list-group::-webkit-scrollbar-thumb,
#persons-list::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 3px;
}

.gramps-media-sidebar .tab-content::-webkit-scrollbar-thumb:hover,
#tab-wp-albums .list-group::-webkit-scrollbar-thumb:hover,
#tab-collections .list-group::-webkit-scrollbar-thumb:hover,
#persons-list::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

/* Gallery area */
.gramps-media-gallery {
    padding: 1.5rem;
    background: #fffaf0;
    border: 1px solid #d8c8ad;
    box-shadow: 0 10px 26px rgba(65, 42, 22, 0.08);
}

.gramps-media-gallery__header {
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid #d8c8ad;
}

/* Masonry grid - override Bootstrap flexbox */
#masonry-gallery {
    display: block !important;
}

/* Gallery grid items */
.gramps-gallery-item {
    margin-bottom: 1rem;
    float: left;
    width: 25%;
    padding: 5px;
}

@media (max-width: 991px) {
    .gramps-gallery-item {
        width: 33.333%;
    }
}

@media (max-width: 767px) {
    .gramps-gallery-item {
        width: 50%;
    }
}

.gramps-gallery-item .bg-image {
    cursor: pointer;
    overflow: hidden;
}

/* Shadow on hover - on wrapper */
.gramps-gallery-item {
    transition: box-shadow 0.3s ease;
    border-radius: 0.5rem;
}

.gramps-gallery-item:hover {
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.3);
}

/* Mask hidden by default, visible on hover */
.gramps-gallery-item .mask {
    opacity: 0;
    transition: opacity 0.3s ease;
}

.gramps-gallery-item .bg-image:hover .mask {
    opacity: 1;
}

/* Caption overlay - dark background, white text, 1 line */
.gramps-gallery-caption {
    background: rgba(0, 0, 0, 0.75);
    font-size: 0.8rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Responsive sidebar */
@media (max-width: 991px) {
    .gramps-media-filterbar {
        grid-template-columns: repeat(2, minmax(170px, 1fr));
    }

    .gramps-media-filterbar__button {
        grid-column: 1 / -1;
    }

    .gramps-media-sidebar {
        min-height: auto;
        max-height: 250px;
        overflow-y: auto;
        border-right: none;
        border-bottom: 1px solid #e2e8f0;
    }
}

@media (max-width: 575px) {
    .gramps-media-container {
        padding: 10px;
    }

    .gramps-media-filterbar {
        grid-template-columns: 1fr;
    }

    .gramps-media-gallery {
        padding: 1rem;
    }
}

/* ========================================
   SKELETON LOADING
   ======================================== */

/* Container for skeletons */
.gramps-skeleton-grid {
    position: relative;
}

/* Individual skeleton item */
.gramps-skeleton-item {
    margin-bottom: 1rem;
    float: left;
    width: 25%;
    padding: 5px;
}

@media (max-width: 991px) {
    .gramps-skeleton-item {
        width: 33.333%;
    }
}

@media (max-width: 767px) {
    .gramps-skeleton-item {
        width: 50%;
    }
}

/* Skeleton placeholder box */
.gramps-skeleton-box {
    background: linear-gradient(90deg, #e2e8f0 0%, #f1f5f9 50%, #e2e8f0 100%);
    background-size: 200% 100%;
    animation: gramps-shimmer 1.5s ease-in-out infinite;
    border-radius: 0.5rem;
    /* Random-ish heights for visual variety */
}

.gramps-skeleton-item:nth-child(4n+1) .gramps-skeleton-box { height: 180px; }
.gramps-skeleton-item:nth-child(4n+2) .gramps-skeleton-box { height: 220px; }
.gramps-skeleton-item:nth-child(4n+3) .gramps-skeleton-box { height: 160px; }
.gramps-skeleton-item:nth-child(4n+4) .gramps-skeleton-box { height: 200px; }

/* Shimmer animation */
@keyframes gramps-shimmer {
    0% {
        background-position: -200% 0;
    }
    100% {
        background-position: 200% 0;
    }
}

/* Hide real gallery during loading */
.gramps-gallery-grid.loading #masonry-gallery {
    opacity: 0;
    position: absolute;
    visibility: hidden;
}

/* Skeleton wrapper */
.gramps-skeleton-wrapper {
    transition: opacity 0.4s ease;
}

.gramps-skeleton-wrapper.hidden {
    opacity: 0;
    pointer-events: none;
}

/* Gallery reveal animation */
.gramps-gallery-grid.loaded #masonry-gallery {
    animation: gramps-gallery-reveal 0.5s ease forwards;
}

@keyframes gramps-gallery-reveal {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Individual item staggered reveal (optional enhancement) */
.gramps-gallery-grid.loaded .gramps-gallery-item {
    animation: gramps-item-reveal 0.4s ease backwards;
}

.gramps-gallery-grid.loaded .gramps-gallery-item:nth-child(1) { animation-delay: 0.05s; }
.gramps-gallery-grid.loaded .gramps-gallery-item:nth-child(2) { animation-delay: 0.1s; }
.gramps-gallery-grid.loaded .gramps-gallery-item:nth-child(3) { animation-delay: 0.15s; }
.gramps-gallery-grid.loaded .gramps-gallery-item:nth-child(4) { animation-delay: 0.2s; }
.gramps-gallery-grid.loaded .gramps-gallery-item:nth-child(5) { animation-delay: 0.25s; }
.gramps-gallery-grid.loaded .gramps-gallery-item:nth-child(6) { animation-delay: 0.3s; }
.gramps-gallery-grid.loaded .gramps-gallery-item:nth-child(7) { animation-delay: 0.35s; }
.gramps-gallery-grid.loaded .gramps-gallery-item:nth-child(8) { animation-delay: 0.4s; }
.gramps-gallery-grid.loaded .gramps-gallery-item:nth-child(n+9) { animation-delay: 0.45s; }

@keyframes gramps-item-reveal {
    from {
        opacity: 0;
        transform: scale(0.95);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}
