/* Provides shared styles for the application's custom layout, form, card, and table elements. */
/* Lets the custom layout element expose its children without adding a layout box. */
ims-layout {
    display: contents;
}

/* Styles the colored title area at the top of reusable forms. */
ims-form-heading {
    background-color: var(--surface-color-primary);
    padding: calc((var(--fluid) * 0.5rem) + 1.5rem);

    /* Sets form heading text to white and removes default heading spacing. */
    & :is(h1, h2, h3, h4, h5, h6) {
        color: var(--text-white);
        margin: 0;
    }
}

/* Adds consistent padding and vertical spacing to the content area of forms. */
ims-form-content {
    padding-inline: calc((var(--fluid) * 0.5rem) + 1.5rem);
    padding-block: calc((var(--fluid) * 0.5rem) + 1.5rem);

    display: flex;
    flex-direction: column;
    gap: 1rem;
}
/* Aligns table title content, actions, and headings across the available row. */
ims-table-title {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
}

/* Hides empty form-item containers so optional fields do not leave gaps. */
ims-form-item {
    /* Removes empty form fields from layout flow. */
    &:empty {
        display: none;
    }
}


/* Keeps pagination controls usable when their contents exceed the available width. */
.paginator {
    overflow-x: auto;
    border-top: none !important;
    padding-inline: calc((var(--fluid) * 0.5rem) + 0.5rem) !important;
}

/* Overlays an image preview and file picker within a shared grid cell. */
ims-image-picker {
    display: grid;
    grid-template-rows: 1fr;
    grid-template-columns: 1fr;
    background-color: var(--surface-light-dark);

    /* Layers the preview and file picker in the same grid cell. */
    >* {
        grid-row: 1;
        grid-column: 1;
    }
    /* Hides the file input when an image preview is present. */
    &:has(img[src]) input {
        opacity: 0;
    }

    /* Repeats the preview-state rule so the file input remains hidden with any rendered image source. */
    &:has(img[src]) input {
        opacity: 0;
    }

    /* Removes default file-input chrome while retaining the shared surface styling. */
    input[type="file"] {
        border: none;
        outline: none;
        background: var(--surface-light-dark);

        /* Keeps the file input's borderless appearance on hover. */
        &:hover {
            border: none;
            outline: none;
        }

        /* Styles the native file chooser control inside the input. */
        &::file-selector-button {
            border: none;
            outline: none;
            background: var(--surface-white);
            padding: 0.5rem 1rem;
            cursor: pointer;
            vertical-align: middle;
        }
    }

    /* Hides file selection when the picker is disabled. */
    input[type="file"]:disabled {
        display: none;
    }
    /* Hides the empty preview placeholder when file selection is disabled. */
    &:has(input[type="file"]:disabled) :is(img:not([src]), img[src=""], img[src="none"]) {
        opacity: 0;
    }
}

/* Defines the shared card width, alignment, and surface styling. */
ims-card {
    width: fit-content;
    margin-inline: auto;
    min-width: min(80ch, 100%);

    /* Styles the card header as a primary-color banner. */
    header {
        padding: calc((var(--fluid) * 0.5rem) + 1rem);
        background-color: var(--surface-color-primary);

        /* Keeps direct header content readable against the primary surface. */
        &>* {
            color: var(--text-white);
        }

        /* Normalizes headings within card headers. */
        :is(h1, h2, h3, h4, h5, h6) {
            font-size: var(--font-size-1);
            margin: 0;
        }
    }

    /* Lays out the card body as a padded vertical content stack. */
    section {
        border: none;
        display: flex;
        flex-direction: column;
        gap: 1rem;
        padding: calc((var(--fluid) * 0.5rem) + 1rem);
        margin: 0;
        background-color: var(--surface-white);
    }
}

/* Constrains page content to a centered, readable column with vertical spacing. */
ims-page {
    min-width: min(80ch, 100%);
    max-width: 80ch;
    margin-inline: auto;
    margin-block: calc((var(--fluid) * 3rem) + 1rem);
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

/* Makes tables horizontally scrollable when their columns exceed the viewport. */
ims-table {
    width: 100%;
    overflow-x: auto;
    display: block;

    /* Reserves space for QuickGrid column options when there are no indexed rows. */
    &:not(:has(tbody tr[aria-rowindex])):has(.col-options) {
        /* overflow-x: visible; */
        padding-bottom: 100px;
        margin-bottom: -100px;
    }

    /* Preserves dropdown room below populated QuickGrid tables with column options. */
    &:has(tbody tr[aria-rowindex]:nth-child(1)):has(.col-options) {
        padding-bottom: 100px;
        margin-bottom: -100px;
    }
}