/* mt-attachments — editor + public content tiles */

.mt-attachments {
    display: block;
    width: 100%;
    margin: 14px 0;
    user-select: none;
}

.mt-attachments__list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    width: 100%;
}

.mt-attachments__card {
    position: relative;
    box-sizing: border-box;
    width: 160px;
    min-height: 108px;
    border: 1px solid var(--mt-color-gray-300, #E4EBF6);
    border-radius: 6px;
    background: var(--mt-color-white, #ffffff);
    color: var(--mt-color-black, #112442);
    overflow: hidden;
    transition: background-color 0.2s, border-color 0.2s;
}

.mt-attachments__card-link {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    box-sizing: border-box;
    width: 100%;
    height: 100%;
    min-height: 108px;
    padding: 12px 28px 10px 10px;
    color: inherit;
    text-decoration: none;
    cursor: pointer;
}

.mt-attachments__card-link:hover,
.mt-attachments__card-link:focus {
    color: inherit;
    text-decoration: none;
}

.mt-attachments__card_file:hover,
.mt-attachments__card_file:focus-within {
    background: var(--mt-color-gray-200, #EDF2F9);
    border-color: var(--mt-color-gray-200, #EDF2F9);
}

.mt-attachments__name {
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
    font-family: 'Roboto', 'robotomedium', sans-serif;
    font-weight: 500;
    font-size: 12px;
    line-height: 16px;
    word-break: break-word;
}

.mt-attachments__meta {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-top: 10px;
    font-size: 12px;
    line-height: 16px;
    opacity: 0.9;
}

.mt-attachments__icon {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    object-fit: contain;
}

/* delete (X) — editor only */
.mt-attachments__remove {
    display: none;
    position: absolute;
    top: 4px;
    right: 4px;
    z-index: 3;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    border-radius: 4px;
    color: var(--mt-color-black, #112442);
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.2s, background-color 0.2s;
}

.mt-attachments__remove svg {
    display: block;
    pointer-events: none;
    fill: none;
    stroke: currentColor;
}

.mt-attachments__remove svg path {
    fill: none;
    stroke: currentColor;
}

.mce-content-body .mt-attachments__remove {
    display: flex;
    pointer-events: auto;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.mce-content-body .mt-attachments__card:hover .mt-attachments__remove,
.mce-content-body .mt-attachments__card:focus-within .mt-attachments__remove,
.mce-content-body .mt-attachments[data-mce-selected] .mt-attachments__remove,
.mce-content-body .mt-attachments.mt-attachments--active .mt-attachments__remove {
    opacity: 1;
}

/* Mobile editor: remove buttons always visible and readable on any tile */
@media (max-width: 767px), (hover: none) {
    .mce-content-body .mt-attachments__remove {
        opacity: 1;
    }

    .mce-content-body .mt-attachments__card_image .mt-attachments__remove {
        color: var(--mt-color-black, #112442);
        background: rgba(255, 255, 255, 0.92);
        box-shadow: 0 1px 4px rgba(17, 36, 66, 0.18);
    }

    .mce-content-body .mt-attachments__card_image .mt-attachments__remove:active {
        background: #fff;
    }
}

.mt-attachments__card_file .mt-attachments__remove:hover {
    background: rgba(0, 0, 0, 0.08);
}

/* image card */
.mt-attachments__card_image {
    position: relative;
    padding: 0;
    height: 108px;
    min-height: 108px;
    color: #fff;
    cursor: pointer;
}

.mt-attachments__card_image .mt-attachments__card-link {
    position: absolute;
    inset: 0;
    min-height: 0;
    padding: 0;
    color: #fff;
}

.mt-attachments__card_image .mt-attachments__preview {
    position: absolute;
    inset: 0;
    display: block;
    width: 100%;
    height: 100%;
    max-width: none;
    margin: 0;
    object-fit: cover;
    object-position: center;
    border-radius: inherit;
    z-index: 0;
}

/* Override .mt-material_content img sizing/margins in editor and public content */
.mt-material_content .mt-attachments img.mt-attachments__preview {
    position: absolute !important;
    inset: 0 !important;
    display: block !important;
    width: 100% !important;
    height: 100% !important;
    max-width: none !important;
    margin: 0 !important;
    border-radius: inherit !important;
    vertical-align: top !important;
    object-fit: cover !important;
    object-position: center !important;
}

.mt-material_content .mt-attachments img.mt-attachments__icon {
    position: static !important;
    width: 18px !important;
    height: 18px !important;
    max-width: none !important;
    margin: 0 !important;
    border-radius: 0 !important;
    object-fit: contain !important;
}

.mt-attachments__card_image .mt-attachments__name,
.mt-attachments__card_image .mt-attachments__meta {
    position: absolute;
    z-index: 2;
    opacity: 0;
    transition: opacity 0.2s;
    color: #fff;
}

.mt-attachments__card_image .mt-attachments__name {
    top: 10px;
    left: 10px;
    right: 32px;
}

.mt-attachments__card_image .mt-attachments__meta {
    left: 10px;
    right: 10px;
    bottom: 10px;
    margin-top: 0;
}

.mt-attachments__card_image:hover .mt-attachments__name,
.mt-attachments__card_image:hover .mt-attachments__meta,
.mt-attachments__card_image:focus-within .mt-attachments__name,
.mt-attachments__card_image:focus-within .mt-attachments__meta {
    opacity: 1;
}

.mt-attachments__card_image .mt-attachments__card-link::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: inherit;
    background: rgba(0, 0, 0, 0.55);
    opacity: 0;
    transition: opacity 0.2s;
    z-index: 1;
    pointer-events: none;
}

.mt-attachments__card_image:hover .mt-attachments__card-link::after,
.mt-attachments__card_image:focus-within .mt-attachments__card-link::after {
    opacity: 1;
}

.mt-attachments__card_image .mt-attachments__icon {
    filter: brightness(0) invert(1);
}

.mt-attachments__card_image .mt-attachments__remove {
    color: #fff;
}

.mt-attachments__card_image .mt-attachments__remove:hover {
    background: rgba(255, 255, 255, 0.15);
}

.mce-content-body .mt-attachments[data-mce-selected] {
    outline: 2px solid var(--mt-color-primary-500, #1F5BFF);
    outline-offset: 2px;
    border-radius: 6px;
}

.mce-content-body .mt-attachments__card-link {
    cursor: default;
}

@media (max-width: 767px) {
    .mt-attachments__card {
        width: calc((100% - 8px) / 2);
    }

    .mt-attachments__card_image {
        height: auto;
        aspect-ratio: 160 / 108;
    }
}
