/* ============================================================
   CMS OBJECT: Image Gallery
   Views: _ImageGallery.cshtml, AdminImageGallery/ImageGallery.cshtml
   Dependencies: Bootstrap 5, jQuery UI sortable in edit mode
   ============================================================ */

/* Image count controls the maximum card width; Bootstrap handles the flex layout. */
.cms-image-gallery__items[data-image-count="1"] :is(.cms-image-gallery__item, .cms-image-gallery__editor-item) {
    max-width: 100%;
}

.cms-image-gallery__items[data-image-count="2"] :is(.cms-image-gallery__item, .cms-image-gallery__editor-item) {
    max-width: 45%;
}

.cms-image-gallery__items[data-image-count="3"] :is(.cms-image-gallery__item, .cms-image-gallery__editor-item) {
    max-width: 30%;
}

.cms-image-gallery__items[data-image-count="4"] :is(.cms-image-gallery__item, .cms-image-gallery__editor-item) {
    max-width: 22%;
}

.cms-image-gallery__items[data-image-count="5"] :is(.cms-image-gallery__item, .cms-image-gallery__editor-item) {
    max-width: 18%;
}

.cms-image-gallery__items[data-image-count="6"] :is(.cms-image-gallery__item, .cms-image-gallery__editor-item) {
    max-width: 15%;
}

.cms-image-gallery__items {
    flex-wrap: nowrap !important;
    overflow-x: auto;
    padding-bottom: 1rem;
}

:is(.cms-image-gallery__item, .cms-image-gallery__editor-item) {
    flex: 0 0 auto;
    max-width: 100%;
}

:is(.cms-image-gallery__item, .cms-image-gallery__editor-item) img {
    width: 100%;
    max-width: 400px;
    height: auto;
    transition: transform .2s ease;
}

:is(.cms-image-gallery__item, .cms-image-gallery__editor-item) img:hover {
    transform: scale(1.02);
}

.cms-image-gallery__editor-item textarea {
    display: block;
    width: 100%;
    max-width: 400px;
    margin: 2px auto;
}

/* Editor row controls */
.cms-image-gallery__editor-row-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
    padding-bottom: .75rem;
}

.cms-image-gallery__editor-row-title {
    position: relative;
    flex: 1;
}

.cms-image-gallery__editor-action {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: 0;
    border-radius: 50%;
    background: transparent;
    transition: all .2s ease;
}

.cms-image-gallery__editor-action--add {
    color: #0d6efd;
}

.cms-image-gallery__editor-action--remove {
    color: #dc3545;
}

.cms-image-gallery__editor-action--add:hover {
    background-color: rgba(13, 110, 253, .1);
    transform: scale(1.1);
}

.cms-image-gallery__editor-action--remove:hover {
    background-color: rgba(220, 53, 69, .1);
    transform: scale(1.1);
}

/* Editor image controls */
.cms-image-gallery__editor-item .position-relative {
    overflow: hidden;
}

.cms-image-gallery__editor-controls {
    position: absolute;
    inset: 0;
    display: flex;
    justify-content: space-between;
    padding: 8px;
    pointer-events: none;
    background: linear-gradient(to bottom, rgba(0, 0, 0, .4), transparent 40%);
    opacity: 0;
    transition: opacity .2s ease;
}

.cms-image-gallery__editor-item:hover .cms-image-gallery__editor-controls {
    opacity: 1;
}

:is(.cms-image-gallery__editor-image-handle, .cms-image-gallery__editor-control) {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    z-index: 1100;
    pointer-events: auto;
    border: 0;
    border-radius: 50%;
    background: rgba(0, 0, 0, .5);
    color: #fff;
    cursor: pointer;
    transition: all .2s ease;
}

:is(.cms-image-gallery__editor-image-handle, .cms-image-gallery__editor-control):hover {
    background: rgba(0, 0, 0, .8);
    transform: scale(1.1);
}

.cms-image-gallery__editor-control--remove:hover {
    background: rgba(220, 53, 69, .8);
}

.ui-sortable-helper .cms-image-gallery__editor-controls {
    display: none;
}

/* Object typography retains the project brand color. */
.cms-image-gallery .cms-image-gallery__heading,
.cms-image-gallery .cms-image-gallery__row-title {
    color: #f58025 !important;
}

.cms-image-gallery__editor .cms-image-gallery__row-title {
    font-size: 34px !important;
    font-weight: 300 !important;
}

.cms-image-gallery__editor-image-placeholder {
    width: 160px;
    height: 240px;
    margin: 5px;
    border: 2px dashed #aaa;
    background: #f8f9fa;
    opacity: .7;
}

.cms-image-gallery__editor-row-placeholder {
    height: 100px;
    margin-bottom: 1rem;
    border: 2px dashed #aaa;
    background: #f8f9fa;
}

/* Editor themes stay family-scoped and public themes continue using Bootstrap. */
.cms-image-gallery__editor .cms-image-gallery--theme-light {
    background-color: #f8f9fa;
    color: #212529;
}

.cms-image-gallery__editor .cms-image-gallery--theme-dark {
    background-color: #212529;
    color: #fff;
}

.cms-image-gallery__editor .cms-image-gallery--theme-gray {
    background-color: #6c757d;
    color: #fff;
}

.cms-image-gallery__editor
    :is(
        .cms-image-gallery--theme-light,
        .cms-image-gallery--theme-dark,
        .cms-image-gallery--theme-gray,
        .cms-image-gallery--theme-none
    )
    :is(input, textarea) {
    margin-bottom: .5rem;
    border: 0;
    background-color: transparent !important;
    box-shadow: none;
    resize: none;
}

.cms-image-gallery__editor
    :is(.cms-image-gallery--theme-dark, .cms-image-gallery--theme-gray)
    :is(input, textarea) {
    color: #fff;
}

.cms-image-gallery__editor
    :is(.cms-image-gallery--theme-dark, .cms-image-gallery--theme-gray)
    :is(.cms-image-gallery__editor-row-handle, .cms-image-gallery__editor-image-handle) {
    color: #fff !important;
}

/* Add Existing selection surface */
.cms-image-gallery__selection {
    min-height: 80vh;
    padding: 20px 0 60px;
    margin-bottom: 40px;
    position: relative;
    background-color: #fafafa;
    border-bottom: 3px solid #dee2e6;
}

.cms-image-gallery__selection::after {
    content: "";
    position: absolute;
    bottom: -10px;
    left: 50%;
    width: 80%;
    height: 2px;
    background: linear-gradient(90deg, transparent, #f58025, transparent);
    box-shadow: 0 2px 8px rgba(245, 128, 37, .3);
    transform: translateX(-50%);
}

.cms-image-gallery__selection-card {
    margin-top: 20px;
    margin-bottom: 25px;
    position: relative;
    padding: 15px !important;
    border: 2px solid #e9ecef !important;
    border-radius: 8px !important;
    box-shadow: 0 2px 8px rgba(0, 0, 0, .08);
    transition: all .3s ease;
}

.cms-image-gallery__selection-card:hover {
    border-color: #f58025 !important;
    box-shadow: 0 8px 25px rgba(245, 128, 37, .15);
    transform: translateY(-2px);
}

.cms-image-gallery__selection-card::before {
    content: "Image Gallery Preview";
    position: absolute;
    top: -12px;
    left: 20px;
    z-index: 15;
    padding: 4px 12px;
    color: #6c757d;
    background: #fff;
    border: 1px solid #dee2e6;
    border-radius: 4px;
    font-size: .85rem;
    font-weight: 500;
}

.cms-image-gallery__selection-action {
    display: none !important;
    top: 15px !important;
    right: 15px !important;
    z-index: 20;
    padding: 8px;
    color: #f58025;
    background: #fff;
    border-radius: 50%;
    box-shadow: 0 2px 8px rgba(0, 0, 0, .15);
    transition: all .2s ease;
}

.cms-image-gallery__selection-action:hover {
    color: #fff;
    background: #f58025;
    transform: scale(1.1);
}

.cms-image-gallery__selection-card:hover .cms-image-gallery__selection-action {
    display: block !important;
}

@media (max-width: 767.98px) {
    .cms-image-gallery__selection-action {
        display: block !important;
    }
}

@media (max-width: 575.98px) {
    .cms-image-gallery__items {
        flex-wrap: wrap !important;
    }

    .cms-image-gallery__items[data-image-count="1"]
        :is(.cms-image-gallery__item, .cms-image-gallery__editor-item) {
        max-width: 75%;
    }

    .cms-image-gallery__items :is(.cms-image-gallery__item, .cms-image-gallery__editor-item) {
        max-width: 45%;
    }
}
