/*
 * Shared presentation layer for authenticated workspaces, reports, and print preview.
 * Keep route-specific behavior in Blade/JS; this file owns only sizing, rhythm, and affordance.
 */

html {
    scrollbar-gutter: stable;
}

.tm-main-content {
    width: 100%;
    max-width: var(--tm-content-max-width);
    min-width: 0;
    padding: var(--tm-page-gutter) !important;
}

.tm-main-content > * {
    min-width: 0;
}

.tm-main-content > :where(.card, .row, .alert, .stock-workspace, form, section) {
    max-width: 100%;
}

/* Keep the current workspace visible while GET filters perform a full Laravel refresh. */
.tm-filter-loading {
    position: fixed;
    z-index: 1015;
    top: var(--tm-filter-loading-top, 0);
    left: var(--tm-filter-loading-left, 0);
    width: var(--tm-filter-loading-width, 100vw);
    height: var(--tm-filter-loading-height, 100vh);
    overflow: hidden;
    pointer-events: auto;
}

.tm-filter-loading__progress {
    position: absolute;
    z-index: 2;
    top: 0;
    right: 0;
    left: 0;
    height: 0.2rem;
    overflow: hidden;
    background: color-mix(in srgb, var(--tm-primary) 18%, transparent);
}

.tm-filter-loading__progress span {
    display: block;
    width: 38%;
    height: 100%;
    background: var(--tm-primary);
    animation: tm-filter-progress 1s ease-in-out infinite;
}

.tm-filter-loading__veil {
    display: flex;
    align-items: flex-start;
    justify-content: center;
    width: 100%;
    height: 100%;
    padding-top: clamp(2.5rem, 10vh, 6rem);
    background: color-mix(in srgb, var(--tm-surface) 20%, transparent);
    opacity: 0;
    transition: opacity 0.12s ease;
}

.tm-filter-loading.is-delayed .tm-filter-loading__veil {
    opacity: 1;
}

.tm-filter-loading__status {
    display: inline-flex;
    align-items: center;
    gap: var(--tm-space-2);
    min-height: var(--tm-control-height);
    padding: var(--tm-space-2) var(--tm-space-4);
    border: 1px solid color-mix(in srgb, var(--tm-primary) 30%, var(--tm-border));
    border-radius: var(--tm-radius-sm);
    color: var(--tm-heading);
    background: color-mix(in srgb, var(--tm-surface) 94%, transparent);
    box-shadow: var(--tm-shadow-md);
    font-size: var(--tm-font-size-sm);
    font-weight: var(--tm-font-weight-semibold);
}

.tm-filter-loading__status .bi {
    color: var(--tm-primary);
    animation: tm-filter-spin 0.8s linear infinite;
}

.tm-filter-navigation-pending form:where([method="get"], [method="GET"]) :where(select, button, input),
.tm-filter-navigation-pending [data-submit-on-change] {
    pointer-events: none;
}

@keyframes tm-filter-progress {
    from {
        transform: translateX(-110%);
    }

    to {
        transform: translateX(270%);
    }
}

@keyframes tm-filter-spin {
    to {
        transform: rotate(360deg);
    }
}

.tm-page-toolbar,
.tm-report-result-toolbar,
.tm-section-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: var(--tm-toolbar-gap);
    min-width: 0;
}

.tm-page-toolbar > *,
.tm-report-result-toolbar > *,
.tm-section-toolbar > * {
    min-width: 0;
}

.tm-page-toolbar :where(.btn, .btn-group),
.tm-report-result-toolbar :where(.btn, .btn-group),
.tm-section-toolbar :where(.btn, .btn-group) {
    flex: 0 0 auto;
}

.tm-main-content .card {
    min-width: 0;
}

.tm-main-content .card-header,
.tm-main-content .card-footer {
    padding: var(--tm-space-3) var(--tm-card-padding);
}

.tm-main-content .card-body {
    min-width: 0;
    padding: var(--tm-card-padding);
}

.tm-main-content :where(.card-header, .stock-panel-heading, .tm-form-section-header) h2,
.tm-main-content :where(.card-header, .stock-panel-heading, .tm-form-section-header) h3 {
    margin-bottom: 0;
    font-size: var(--tm-font-size-section-title);
}

/* Filters use one visual contract even when a page retains legacy form markup. */
.tm-main-content :where(
    .tm-report-filter-card,
    .tm-spare-filter-card,
    .tm-machine-filter-card,
    .tm-next-due-filter-card,
    .tm-filter-card
) {
    border: 1px solid var(--tm-border-soft) !important;
    box-shadow: var(--tm-shadow-xs) !important;
}

.tm-main-content :where(
    .tm-report-filter-grid,
    .tm-user-filter-grid,
    .tm-doc-filter-grid,
    .tm-todo-filter-grid,
    .tm-spare-filter-grid,
    .tm-machine-filter-grid,
    .tm-work-order-filter-grid,
    .tm-next-due-filter-grid,
    .stock-filter-grid,
    .stock-entry-filter-grid,
    .tm-filter-grid
) {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    gap: var(--tm-space-2) var(--tm-space-3);
}

.tm-main-content :where(
    .tm-report-filter-grid,
    .tm-user-filter-grid,
    .tm-doc-filter-grid,
    .tm-todo-filter-grid,
    .tm-spare-filter-grid,
    .tm-machine-filter-grid,
    .tm-work-order-filter-grid,
    .tm-next-due-filter-grid,
    .stock-filter-grid,
    .stock-entry-filter-grid,
    .tm-filter-grid
) > * {
    max-width: 100%;
    min-width: 0;
}

.tm-main-content :where(
    .tm-report-filter-grid,
    .tm-user-filter-grid,
    .tm-doc-filter-grid,
    .tm-todo-filter-grid,
    .tm-spare-filter-grid,
    .tm-machine-filter-grid,
    .tm-work-order-filter-grid,
    .tm-next-due-filter-grid,
    .stock-filter-grid,
    .stock-entry-filter-grid,
    .tm-filter-grid
) .form-label {
    display: block;
    max-width: 100%;
    margin-bottom: var(--tm-space-1);
    overflow: hidden;
    color: var(--tm-text-soft);
    font-size: var(--tm-font-size-label);
    font-weight: var(--tm-font-weight-semibold);
    line-height: 1.2;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.tm-main-content :where(
    .tm-report-filter-grid,
    .tm-user-filter-grid,
    .tm-doc-filter-grid,
    .tm-todo-filter-grid,
    .tm-spare-filter-grid,
    .tm-machine-filter-grid,
    .tm-work-order-filter-grid,
    .tm-next-due-filter-grid,
    .stock-filter-grid,
    .stock-entry-filter-grid,
    .tm-filter-grid
) :where(.form-control, .form-select, .tm-multi-filter-toggle, .tm-activity-multi-filter-toggle, .tm-spare-multi-filter-toggle) {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    min-height: var(--tm-control-height-sm);
}

.tm-main-content :where(
    .tm-multi-filter-toggle,
    .tm-activity-multi-filter-toggle,
    .tm-spare-multi-filter-toggle,
    .tm-next-due-dropdown > .btn
) > :where(span, [data-multi-filter-summary], [data-activity-report-filter-summary], [data-spare-link-filter-summary]) {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.tm-main-content :where(
    .tm-report-filter-actions,
    .tm-work-order-filter-actions,
    .tm-spare-filter-actions,
    .tm-machine-filter-actions,
    .tm-next-due-filter-actions,
    .stock-filter-actions,
    .tm-filter-actions
) {
    display: flex !important;
    align-items: end;
    justify-content: flex-end;
    flex-wrap: wrap;
    gap: var(--tm-space-2) !important;
    width: 100%;
    max-width: 100%;
    min-width: 0;
}

.tm-main-content :where(
    .tm-report-filter-actions,
    .tm-work-order-filter-actions,
    .tm-spare-filter-actions,
    .tm-machine-filter-actions,
    .tm-next-due-filter-actions,
    .stock-filter-actions,
    .tm-filter-actions
) .btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 1 auto !important;
    width: auto !important;
    min-width: 6.5rem;
    max-width: 11rem;
    min-height: var(--tm-control-height-sm);
    white-space: nowrap;
}

.tm-main-content :where(
    .tm-report-filter-actions,
    .tm-work-order-filter-actions,
    .tm-spare-filter-actions,
    .tm-machine-filter-actions,
    .tm-next-due-filter-actions,
    .stock-filter-actions,
    .tm-filter-actions
) .btn:only-child {
    max-width: 9rem;
}

.tm-searchable-multi-filter-field,
.tm-searchable-multi-filter,
.tm-searchable-multi-filter .dropdown,
.tm-searchable-multi-filter .tm-multi-filter-toggle {
    min-width: 0;
    max-width: 100%;
}

.tm-multi-filter-menu,
.tm-searchable-multi-filter-menu {
    max-width: min(26rem, calc(100vw - (2 * var(--tm-mobile-gutter))));
}

.tm-searchable-multi-filter-head {
    position: sticky;
    top: 0;
    z-index: 2;
    background: var(--tm-surface);
}

.tm-multi-filter-option {
    min-height: 2rem;
}

/* Tables favor scanability while retaining horizontal scrolling for wide business data. */
.tm-data-table-shell,
.tm-main-content .table-responsive {
    max-width: 100%;
    min-width: 0;
    border: 1px solid var(--tm-border-soft);
    border-radius: var(--tm-radius-sm);
    background: var(--tm-surface);
}

.tm-data-table,
.tm-main-content .table-responsive > .table {
    margin-bottom: 0;
    font-variant-numeric: tabular-nums;
}

.tm-data-table :where(th, td),
.tm-main-content .table-responsive > .table :where(th, td) {
    padding: 0.62rem 0.7rem;
    vertical-align: middle;
}

.tm-data-table thead th,
.tm-main-content .table-responsive > .table thead th {
    border-bottom-color: var(--tm-border-strong);
    background: var(--tm-surface-muted);
    color: var(--tm-text-soft);
    line-height: 1.25;
    white-space: nowrap;
}

.tm-data-table tbody tr:last-child > *,
.tm-main-content .table-responsive > .table tbody tr:last-child > * {
    border-bottom-width: 0;
}

.tm-report-footer-cell {
    max-width: 100%;
    min-width: 0;
    white-space: normal;
}

.tm-report-footer-totals {
    align-items: baseline;
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem 1.5rem;
    justify-content: flex-end;
    max-width: 100%;
    min-width: 0;
    white-space: normal;
    width: 100%;
}

.tm-report-footer-total {
    align-items: baseline;
    display: inline-flex;
    flex-wrap: wrap;
    gap: 0.25rem 0.5rem;
    justify-content: flex-end;
    max-width: 100%;
    min-width: 0;
    white-space: normal;
}

.tm-report-footer-label {
    overflow-wrap: anywhere;
}

.tm-main-content .table-responsive .tm-table-actions {
    width: 1%;
    white-space: nowrap;
}

.tm-main-content .table-responsive .tm-table-actions .btn-group {
    display: inline-flex;
    gap: 0.25rem;
}

.tm-main-content .table-responsive .tm-table-actions .btn {
    width: 2rem;
    min-width: 2rem;
    min-height: 2rem;
    padding: 0.25rem;
    border-radius: var(--tm-radius-sm) !important;
}

.tm-main-content .table .badge {
    display: inline-flex;
    align-items: center;
    min-height: 1.55rem;
    padding: 0.28rem 0.55rem;
    line-height: 1.1;
    white-space: nowrap;
}

.tm-main-content .pagination {
    flex-wrap: wrap;
    gap: 0.2rem;
    margin-bottom: 0;
}

.tm-main-content .pagination .page-link {
    min-width: 2.1rem;
    min-height: 2.1rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--tm-radius-sm) !important;
}

/* Modals and utility controls share clear focus and compact action rhythm. */
.modal-content {
    overflow: hidden;
    border-color: var(--tm-border);
    border-radius: var(--tm-radius);
    box-shadow: var(--tm-shadow-lg);
}

.modal-header,
.modal-footer {
    padding: var(--tm-space-3) var(--tm-space-4);
}

.modal-body {
    padding: var(--tm-space-4);
}

:where(a, button, input, select, textarea, [tabindex]):focus-visible {
    outline: 2px solid var(--tm-primary);
    outline-offset: 2px;
}

.tooltip-inner {
    max-width: 18rem;
    padding: 0.4rem 0.6rem;
    border-radius: var(--tm-radius-sm);
    font-size: var(--tm-font-size-sm);
    text-align: left;
}

.tm-public-report-shell {
    width: min(100%, 96rem);
}

@media (max-width: 991.98px) {
    .tm-page-toolbar,
    .tm-report-result-toolbar,
    .tm-section-toolbar {
        align-items: flex-start;
    }

    .tm-main-content :where(
        .tm-report-filter-grid,
        .tm-work-order-filter-grid,
        .tm-next-due-filter-grid,
        .stock-filter-grid,
        .stock-entry-filter-grid
    ) {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 575.98px) {
    html {
        scrollbar-gutter: auto;
    }

    .tm-main-content {
        padding: var(--tm-mobile-gutter) !important;
    }

    .tm-page-toolbar,
    .tm-report-result-toolbar,
    .tm-section-toolbar {
        align-items: stretch;
        flex-direction: column;
    }

    .tm-page-toolbar > :where(.d-flex, .btn-group),
    .tm-report-result-toolbar > :where(.d-flex, .btn-group),
    .tm-section-toolbar > :where(.d-flex, .btn-group) {
        width: 100%;
        flex-wrap: wrap;
    }

    .tm-main-content :where(
        .tm-report-filter-actions,
        .tm-work-order-filter-actions,
        .tm-spare-filter-actions,
        .tm-machine-filter-actions,
        .tm-next-due-filter-actions,
        .stock-filter-actions,
        .tm-filter-actions
    ) {
        display: grid !important;
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .tm-main-content :where(
        .tm-report-filter-actions,
        .tm-work-order-filter-actions,
        .tm-spare-filter-actions,
        .tm-machine-filter-actions,
        .tm-next-due-filter-actions,
        .stock-filter-actions,
        .tm-filter-actions
    ) .btn {
        width: 100% !important;
        min-width: 0;
        max-width: none;
    }

    .tm-data-table :where(th, td),
    .tm-main-content .table-responsive > .table :where(th, td) {
        padding: 0.55rem 0.6rem;
    }
}

@media (prefers-reduced-motion: reduce) {
    .tm-main-content *,
    .tm-main-content *::before,
    .tm-main-content *::after {
        scroll-behavior: auto !important;
        transition-duration: 0.01ms !important;
    }

    .tm-filter-loading__progress span,
    .tm-filter-loading__status .bi {
        animation: none !important;
    }

    .tm-filter-loading__progress span {
        width: 100%;
        transform: none;
    }
}

@media print {
    html {
        scrollbar-gutter: auto;
    }

    .tm-main-content {
        padding: 0 !important;
    }

    .tm-main-content .card,
    .tm-main-content .table-responsive {
        border-color: transparent !important;
        box-shadow: none !important;
    }

    .tm-data-table tfoot .tm-report-footer-cell {
        padding: 0.4rem !important;
        white-space: normal !important;
    }

    .tm-report-footer-totals {
        align-items: flex-end;
        flex-direction: column;
        gap: 0.15rem;
        width: 100%;
    }

    .tm-report-footer-total {
        max-width: 100%;
        white-space: normal !important;
    }

    .tm-filter-loading {
        display: none !important;
    }
}
/* Shared bulk-data actions and import workspace */
.tm-data-tools {
    align-items: center;
    background: var(--tm-surface, #fff);
    border: 1px solid var(--tm-border, #d7e1eb);
    display: flex;
    justify-content: space-between;
    margin-bottom: .75rem;
    min-height: 44px;
    padding: .375rem .5rem .375rem .75rem;
}

.tm-data-tools--footer {
    margin-bottom: 0;
    margin-top: .75rem;
}

.tm-data-tools__label,
.tm-data-tools__actions {
    align-items: center;
    display: flex;
    gap: .5rem;
}

.tm-data-tools__label {
    color: var(--tm-muted, #667085);
    font-size: .8125rem;
    font-weight: 600;
}

.tm-data-tools__actions .dropdown-menu {
    min-width: 13rem;
}

.tm-data-tools__actions .dropdown-item {
    align-items: center;
    display: flex;
    white-space: nowrap;
}

.tm-import-workspace {
    margin-inline: auto;
    max-width: 1120px;
}

.tm-import-intro {
    align-items: center;
    border-bottom: 1px solid var(--tm-border, #d7e1eb);
    display: flex;
    gap: 1rem;
    justify-content: space-between;
    padding-bottom: 1rem;
}

.tm-import-form {
    padding-block: 1.25rem;
}

.tm-import-dropzone {
    align-items: center;
    background: var(--tm-muted-surface, #f7f9fc);
    border: 1px dashed var(--tm-border-strong, #aab8c5);
    cursor: pointer;
    display: grid;
    gap: 1rem;
    grid-template-columns: auto minmax(0, 1fr) auto;
    min-height: 116px;
    padding: 1.25rem;
    transition: border-color .15s ease, background-color .15s ease;
}

.tm-import-dropzone:hover,
.tm-import-dropzone:focus-within {
    background: color-mix(in srgb, var(--tm-primary, #336699) 5%, #fff);
    border-color: var(--tm-primary, #336699);
}

.tm-import-dropzone.is-invalid {
    border-color: var(--tm-danger, #b33a3a);
}

.tm-import-dropzone input {
    height: 1px;
    opacity: 0;
    overflow: hidden;
    position: absolute;
    width: 1px;
}

.tm-import-dropzone__icon {
    align-items: center;
    background: var(--tm-surface, #fff);
    border: 1px solid var(--tm-border, #d7e1eb);
    color: var(--tm-primary, #336699);
    display: inline-flex;
    font-size: 1.5rem;
    height: 48px;
    justify-content: center;
    width: 48px;
}

.tm-import-dropzone__copy {
    display: grid;
    gap: .2rem;
    min-width: 0;
}

.tm-import-dropzone__copy span {
    color: var(--tm-muted, #667085);
    font-size: .875rem;
}

.tm-import-file-name {
    color: var(--tm-muted, #667085);
    font-size: .8125rem;
    margin-top: .4rem;
}

.tm-import-fields {
    border-top: 1px solid var(--tm-border, #d7e1eb);
    padding-top: 1.25rem;
}

@media (max-width: 575.98px) {
    .tm-data-tools,
    .tm-import-intro {
        align-items: stretch;
        flex-direction: column;
    }

    .tm-data-tools__actions > .btn,
    .tm-data-tools__actions > .dropdown,
    .tm-import-intro > .btn {
        flex: 1 1 auto;
    }

    .tm-data-tools__actions > .dropdown > .btn {
        width: 100%;
    }

    .tm-import-dropzone {
        grid-template-columns: auto minmax(0, 1fr);
    }

    .tm-import-dropzone > .btn {
        grid-column: 1 / -1;
    }
}
