/*
 * Inspection file preview modal layout.
 * Loaded after bundled scoped CSS (see App.razor) because MudFileUpload uses height:100% on its
 * input area and scoped styles do not apply to overlay child markup.
 *
 * MudOverlay with child content renders in-place. The shell fixed app bar stacks above
 * .mud-main-content, so top padding clears the header. Panel height must not use a raw 90vh
 * alone—that exceeds the padded flex area on tablets and clips the footer; cap height with
 * the same vertical budget as the content padding (custom property below).
 */

.preview-overlay-content {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    min-height: 100%;
    padding-left: 1rem;
    padding-right: 1rem;
    padding-top: calc(1rem + env(safe-area-inset-top, 0px) + var(--mud-appbar-height, 64px));
    padding-bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
    /* Sum of vertical padding; must stay in sync with padding-top + padding-bottom expressions. */
    --preview-overlay-pad-y: calc(
        2rem + env(safe-area-inset-top, 0px) + env(safe-area-inset-bottom, 0px) +
            var(--mud-appbar-height, 64px)
    );
    box-sizing: border-box;
}

/* Grid rows: header | divider | body (fills) | footer (content-sized, capped). */
.preview-overlay-panel {
    width: 90vw;
    max-width: 1200px;
    /* Visible viewport minus overlay vertical padding (app bar, safe areas); avoids footer clipping on tablets. */
    height: min(90vh, calc(100dvh - var(--preview-overlay-pad-y)));
    max-height: min(90vh, calc(100dvh - var(--preview-overlay-pad-y)));
    display: grid !important;
    grid-template-rows: auto auto minmax(0, 1fr) auto;
    grid-template-columns: 1fr;
    overflow: hidden;
    background-color: var(--mud-palette-surface);
    border-radius: var(--mud-default-borderradius);
    box-shadow: 0 11px 15px -7px rgba(0, 0, 0, 0.2), 0 24px 38px 3px rgba(0, 0, 0, 0.14), 0 9px 46px 8px rgba(0, 0, 0, 0.12);
}

.preview-overlay-panel > .preview-overlay-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    min-width: 0;
    gap: 1rem;
}

.preview-overlay-panel > .preview-overlay-body {
    min-height: 0 !important;
    padding: 1rem;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    justify-content: center;
    background-color: var(--mud-palette-background);
}

.preview-overlay-panel > .preview-overlay-footer {
    display: flex !important;
    flex-direction: row !important;
    align-items: center !important;
    padding: 0.5rem 1rem;
    border-top: 1px solid var(--mud-palette-divider);
    height: auto !important;
    max-height: 5rem !important;
    min-height: 0 !important;
    overflow: visible;
    box-sizing: border-box;
}

.preview-overlay-file-size {
    flex: 0 0 auto;
    white-space: nowrap;
}

.preview-overlay-footer-upload {
    height: auto !important;
    max-height: 4rem !important;
    flex: 0 0 auto !important;
    display: inline-flex !important;
    align-items: center !important;
    margin-left: auto;
}

@media (max-width: 480px) {
    .preview-overlay-panel > .preview-overlay-footer {
        flex-wrap: wrap !important;
        max-height: none !important;
    }

    .preview-overlay-footer-upload {
        width: 100%;
        justify-content: flex-end;
    }
}

.preview-overlay-footer-upload .mud-file-upload,
.preview-overlay-footer-upload .mud-input-control,
.preview-overlay-footer-upload .mud-input-control.mud-file-upload,
.preview-overlay-footer-upload .mud-input-control-input-container,
.preview-overlay-footer-upload .mud-input-control-input-container > div {
    height: auto !important;
    max-height: 4rem !important;
    min-height: 0 !important;
    flex-grow: 0 !important;
    align-items: center !important;
}

.preview-overlay-image-wrapper {
    flex: 1 1 auto;
    min-height: 0;
    min-width: 0;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

/* Frame is the positioning context for MpImageAnnotation (single img + canvas). */
.preview-overlay-image-frame {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 0;
    width: 100%;
    height: 100%;
    min-width: 0;
    max-width: 100%;
    max-height: 100%;
}

.preview-overlay-image-frame .mp-image-annotation-container.preview-overlay-annotation-layer {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    display: block;
}

/* Same element paints the bitmap and receives object-fit: contain as the annotation interop layer. */
.preview-overlay-image-frame .mp-image-annotation-container.preview-overlay-annotation-layer .mp-image-annotation-image {
    width: 100%;
    height: 100%;
    object-fit: contain;
    object-position: center;
}

.preview-overlay-image-frame .mp-image-annotation-container.preview-overlay-annotation-layer .mp-image-annotation-canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: auto;
    background: transparent;
}

.preview-overlay-video {
    max-width: 100%;
    max-height: 100%;
    border-radius: var(--mud-default-borderradius);
}

.preview-overlay-pdf {
    width: 100%;
    height: 100%;
    border: none;
    border-radius: var(--mud-default-borderradius);
}

.preview-overlay-unsupported {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    text-align: center;
}

.preview-title-truncate {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
    min-width: 0;
}
