/* FluxCertify: responsive presentation only.
 * Keep this file LAST in App.razor's stylesheet list.
 * Desktop declarations and grid columns stay authoritative. Mobile card/home
 * layouts are selected before desktop settings are loaded.
 * Compact viewport: <= 1024px; large touch tablets: <= 1366px.
 * The matching query is also used by fcResponsive.js and the navigation scopes.
 */

/* Added markup is layout-neutral on desktop. */
.fc-table-scroll,
.fc-native-file-input {
    display: contents;
}

.fc-touch-only {
    display: none;
}

@media (max-width: 1024px), (max-width: 1366px) and (pointer: coarse) {
    :root {
        --fc-mobile-gap: 0.75rem;
        --fc-mobile-top: calc(3.75rem + env(safe-area-inset-top, 0px));
        --fc-mobile-edge: max(0.75rem, env(safe-area-inset-left, 0px));
    }

    html, body {
        width: 100%;
        min-width: 0;
        margin: 0;
        -webkit-text-size-adjust: 100%;
        text-size-adjust: 100%;
    }

    /* One page scroll area; controls with their own scrolling keep it. */
    .flux-app-shell {
        min-height: 100svh;
    }

    .flux-app-shell > main.content,
    .flux-app-shell.menu-compact > main.content {
        display: flex;
        flex-direction: column;
        height: var(--fc-viewport-height, 100dvh);
        min-width: 0;
        margin-left: 0;
        padding: var(--fc-mobile-top) max(0.75rem, env(safe-area-inset-right, 0px))
                 max(0.75rem, env(safe-area-inset-bottom, 0px)) var(--fc-mobile-edge);
        overflow: auto;
        scroll-padding-block: 1rem 4.5rem;
        -webkit-overflow-scrolling: touch;
    }

    .flux-app-shell.menu-unavailable > main.content {
        padding-top: max(1rem, env(safe-area-inset-top, 0px));
    }

    main.content > * {
        min-width: 0;
        flex-shrink: 0;
    }

    .fc-page-shell-title-row {
        flex: 0 0 auto;
        gap: 0.5rem;
        margin-bottom: 0.75rem;
    }

    .fc-page-shell-title-row .fc-page-shell-title {
        flex: 1 1 auto;
        margin-bottom: 0;
        padding-right: 0;
    }

    .fc-page-shell-title-row .fc-page-shell-title-addon {
        min-width: 0;
        max-width: 100%;
        margin-left: 0.75rem;
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    .fc-page-shell-title-row .fc-page-shell-title-actions {
        width: auto;
        margin: 0;
        gap: 0.5rem;
    }

    .fc-page-shell-local-actions,
    .fc-card-layout-actions,
    .fc-card-layout-toolbar,
    .home-layout-actions {
        flex-wrap: wrap;
    }

    .pagetitle {
        min-height: 2.75rem;
        margin-top: 0;
        font-size: clamp(1.1rem, 3.6vw, 1.4rem);
        overflow-wrap: anywhere;
    }

    .fc-global-header-actions {
        flex: 0 1 auto;
        gap: 0.5rem;
        max-width: 100%;
    }

    .fc-global-header-actions .fc-global-header-search {
        flex: 1 1 8rem;
        max-width: none;
    }

    .fc-global-header-search > div,
    .fc-global-header-search .loading-border-container {
        width: 100% !important;
        min-width: 0;
        max-width: 100%;
    }

    /* Upload remains available, including on phones. */
    .fc-global-header-actions .fc-global-header-filedrop {
        display: block;
        flex: 0 0 2rem;
        width: 2rem;
        min-width: 2rem;
        height: 30px;
        margin-right: 0;
    }

    .fc-global-header-filedrop .drop-zone {
        height: 100% !important;
    }

    .fc-global-header-actions .fc-global-user-summary-text {
        min-width: 0;
    }

    .fc-global-header-actions .fc-global-user-summary-name {
        white-space: normal;
        overflow-wrap: anywhere;
    }

    /* Cards fill the remaining viewport. Only their body scrolls; the footer
     * remains a normal flex child at the bottom, without a sticky gap. */
    .flux-app-shell > main.content:has(> .cardwrapper) {
        overflow: hidden;
        padding-bottom: 0;
    }

    .content > .cardwrapper {
        flex: 1 1 0;
        height: auto;
        min-height: 0;
        min-width: 0;
        overflow: hidden;
    }

    .content > .cardwrapper > .cardbodywrapper {
        flex: 1 1 0;
        height: auto;
        min-height: 0;
        min-width: 0;
        overflow: hidden;
    }

    .content > .cardwrapper > .cardbodywrapper > .scrollablecardcontent,
    .content > .cardwrapper > .cardbodywrapper > .scrollablecardcontentHome,
    .content > .cardwrapper > .cardbodywrapper > .scrollablecardcontentHome2 {
        flex: 1 1 0;
        height: auto;
        min-height: 0;
        min-width: 0;
        overflow: auto;
        gap: var(--fc-mobile-gap);
        -webkit-overflow-scrolling: touch;
    }

    .content > .cardwrapper > .cardfooter {
        position: relative;
        bottom: auto;
        flex: 0 0 auto;
        z-index: 40;
        height: auto;
        min-height: 3rem;
        margin-top: 0;
        padding: 0.5rem 0.5rem max(0.5rem, env(safe-area-inset-bottom, 0px));
        background: var(--fc-surface);
        border-radius: var(--fc-radius) var(--fc-radius) 0 0;
        box-shadow: 0 -2px 8px rgba(25, 40, 50, 0.06);
    }

    .cardfooter .cardfooterbuttoncontainer {
        flex-wrap: wrap;
        justify-content: flex-end;
        min-width: 0;
        max-width: 100%;
        margin-top: 0;
        gap: 0.5rem;
    }

    .content .screenheight2 {
        flex: 1 1 auto;
        height: auto;
        min-height: 22rem;
        min-width: 0;
    }

    .content .screenheight {
        height: auto;
        min-width: 0;
        flex-wrap: wrap;
    }

    .content .groupcontainer {
        min-width: 0 !important;
        max-width: 100% !important;
        box-sizing: border-box;
    }

    .content .groupitems,
    .e-dialog .groupitems {
        min-width: 0;
        max-width: 100%;
    }

    .groupitems > div,
    .e-dlg-content > div {
        min-width: 0;
        max-width: 100%;
        box-sizing: border-box;
    }

    .fc-inline-row,
    .fc-inline-row-compact,
    .fc-form-row,
    .fc-display-flex-gap-20,
    .fc-display-flex-gap-10,
    .fc-display-flex-gap-5 {
        flex-wrap: wrap;
        min-width: 0;
    }

    .fc-form-row > .e-input-group,
    .fc-inline-row > .e-input-group,
    .fc-inline-row-compact > .e-input-group {
        flex: 1 1 10rem;
        min-width: 0;
    }

    .e-input-group,
    .e-control-wrapper,
    .fc-pw,
    .fc-text-field,
    .person-card,
    .kunde-vcard {
        max-width: 100%;
        box-sizing: border-box;
    }

    /* Do not stretch row-height for SfGrid: virtual scrolling calculates with RowHeight.
     * Header and body use the SAME minimum table width; Syncfusion keeps scroll in sync.
     */
    .e-grid {
        min-width: 0;
        max-width: 100%;
    }

    .e-grid .e-gridheader .e-table,
    .e-grid .e-gridcontent .e-table {
        min-width: var(--fc-grid-min-width, 100%);
    }

    .e-grid .e-gridcontent > .e-content {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior-x: contain;
    }

    .modern-table-wrapper,
    .fc-table-scroll {
        display: block;
        width: 100%;
        min-width: 0;
        max-width: 100%;
        overflow: auto;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior-x: contain;
    }

    .fc-table-scroll > table {
        min-width: 100%;
    }

    /* Popups may be attached to body, outside main.content. */
    /* Syncfusion retains its own container, alignment and drag coordinates.
     * Bound the dialog itself rather than replacing its positioning model. */
    .e-dialog {
        min-width: 0 !important;
        max-width: calc(100vw - 1rem - env(safe-area-inset-left, 0px) - env(safe-area-inset-right, 0px)) !important;
        min-height: 0 !important;
        max-height: calc(var(--fc-viewport-height, 100dvh) - 1rem - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px)) !important;
    }

    .e-dialog .e-dlg-header {
        white-space: normal;
        overflow-wrap: anywhere;
    }

    .e-dialog .e-dlg-content {
        flex: 1 1 auto;
        min-height: 0;
        min-width: 0;
        overflow: auto;
        -webkit-overflow-scrolling: touch;
    }

    .e-dialog .e-footer-content {
        display: flex;
        flex-wrap: wrap;
        justify-content: flex-end;
        gap: 0.5rem;
    }

    .e-dialog .e-footer-content .e-btn {
        margin: 0;
        white-space: normal;
    }

    .e-popup.e-popup-open:not(.e-dialog),
    .fc-global-user-popover,
    .dropdown-menu {
        max-width: calc(100vw - 1rem) !important;
        box-sizing: border-box;
    }

    .fc-viewport-popup {
        translate: var(--fc-popup-shift-x, 0px) 0;
    }

    .e-toast-container {
        max-width: calc(100vw - 1rem) !important;
    }

    .e-toast-container .e-toast {
        width: 100% !important;
        max-width: 100%;
        box-sizing: border-box;
    }

    .dropdown-menu {
        max-height: min(65dvh, 28rem);
        overflow-y: auto;
    }

    .e-tab .e-tab-header,
    .e-btn-group,
    .e-button-group {
        max-width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Native input gets the tap directly: no server roundtrip before iOS file picker. */
    .fc-file-drop-zone .fc-native-file-input,
    .drop-zone .fc-native-file-input,
    .zertifikat-drop-zone .fc-native-file-input,
    .dokument-drop-zone .fc-native-file-input {
        display: block;
        position: absolute;
        inset: 0;
        z-index: 2;
    }

    .fc-file-drop-zone .fc-native-file-input input[type="file"],
    .drop-zone .fc-native-file-input input[type="file"],
    .zertifikat-drop-zone .fc-native-file-input input[type="file"],
    .dokument-drop-zone .fc-native-file-input input[type="file"] {
        position: absolute;
        inset: 0;
        width: 100% !important;
        height: 100% !important;
        opacity: 0;
        pointer-events: auto;
        cursor: pointer;
    }

    .fc-touch-only {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        min-width: 2.5rem;
        min-height: 2.5rem;
        padding: 0.25rem 0.5rem;
        border: 1px solid var(--fc-border);
        border-radius: var(--fc-radius);
        background: var(--fc-surface);
        color: var(--fc-primary);
    }

    /* Preserve component metrics, including input/label geometry and button height. */
    .fc-card-layout-action,
    .home-layout-action,
    .fc-global-popover-link,
    .cardfooter button,
    .btn-add,
    .dropdown-menu > button,
    .fc-pwtoggle,
    .filedrop-choose-folder,
    .groupicons .fc-icon--interactive {
        touch-action: manipulation;
    }

}

@media (max-width: 600px) {
    .content .groupcontainer,
    .fc-card-layout-default > .fc-card-layout-item-default .groupcontainer {
        width: 100% !important;
        max-width: 100% !important;
    }

    .fc-page-shell-title-row .fc-page-shell-title {
        gap: 0.5rem;
    }

    .fc-page-shell-title-row .fc-page-shell-title-addon {
        flex-basis: 100%;
        margin-left: 0;
    }

    .e-dialog {
        width: calc(100vw - 1rem) !important;
    }

    /* Auth tables contain form labels, so stack cells instead of shrinking inputs. */
    .screencenter {
        flex: 1 0 auto;
        height: auto;
        min-height: 0;
        padding: 1rem 0;
        align-items: flex-start;
    }

    .screencenter > form,
    .screencenter > div {
        width: 100%;
        max-width: 26rem;
        min-width: 0;
    }

    .customBorder,
    .customBorder > tbody,
    .customBorder tr,
    .customBorder td {
        display: block;
        width: 100%;
        box-sizing: border-box;
    }

    .customBorder td.customLabel {
        text-align: left;
        margin-top: 0.75rem;
        margin-bottom: 0.25rem;
    }

    .customBorder .customInput {
        width: 100%;
        max-width: 100%;
    }

    .content .errorbox {
        width: 100%;
        height: auto;
        min-height: 65dvh;
        position: relative;
        inset: auto;
        transform: none;
    }

    .errorbuttoncontainer {
        flex-wrap: wrap;
        gap: 0.75rem;
    }

    .unauthcustombox {
        width: 100%;
        max-width: 100%;
        box-sizing: border-box;
    }
}

/* Keep transitions comfortable without changing desktop motion settings. */
@media (prefers-reduced-motion: reduce) and (max-width: 1024px) {
    .fc-sidebar,
    .flux-app-shell > main.content {
        transition: none;
    }
}


/* Compact viewport: keep desktop declarations above intact. */
@media (max-width: 1024px), (max-width: 1366px) and (pointer: coarse) {

    /* Virtual grids require a definite viewport height; never alter their RowHeight. */
    .content .screenheight2:has(> .e-grid) {
        flex: 1 0 auto;
        height: max(22rem, calc(var(--fc-viewport-height, 100dvh) - 12rem));
    }

    .content .screenheight2 > .e-grid {
        height: 100% !important;
    }

    .e-grid .e-pager {
        white-space: normal;
        max-width: 100%;
    }

    /* SFInput.css and the Syncfusion theme own field sizes and floating labels. */

    .loopTableDiv, .dlgDiv {
        min-width: 0;
        max-width: 100%;
        box-sizing: border-box;
    }

    .loopTableDiv {
        -webkit-overflow-scrolling: touch;
    }

    .modern-table-wrapper:focus-visible,
    .fc-table-scroll:focus-visible {
        outline: 2px solid var(--fc-primary);
        outline-offset: 2px;
    }

}


/* Keep page titles and local actions aligned on tablets. Global actions live in the menu. */
@media (min-width: 768px) and (max-width: 1024px),
       (min-width: 768px) and (max-width: 1366px) and (pointer: coarse) {
    .fc-page-shell-title-row {
        flex-wrap: nowrap;
        align-items: center;
        gap: 0.75rem;
        margin-bottom: 0.25rem;
    }

    .fc-page-shell-title-row .fc-page-shell-title {
        flex: 1 1 auto;
        min-width: 0;
    }

    .fc-page-shell-title-row .fc-page-shell-title-actions {
        flex: 0 1 auto;
        flex-wrap: nowrap;
        width: auto;
        max-width: 65%;
        margin-left: auto;
    }

    .fc-page-shell-local-actions {
        flex: 0 0 auto;
    }

    .fc-global-header-actions .fc-global-header-search {
        flex: 0 1 auto;
        width: min(250px, 32vw);
        max-width: 100%;
    }
}

/* A second header row is reserved for phones, not all touch devices. */
@media (max-width: 767px) {
    .fc-page-shell-title-row {
        flex-wrap: wrap;
    }

    .fc-page-shell-title-row .fc-page-shell-title {
        flex-basis: 100%;
    }

    .fc-page-shell-title-row .fc-page-shell-title-actions {
        flex: 1 1 100%;
        width: 100%;
    }

    .fc-global-header-actions {
        flex: 1 1 auto;
    }
}


/* Compact layouts are independent of saved desktop card/dashboard geometry. */
@media (max-width: 1024px), (max-width: 1366px) and (pointer: coarse) {
    .fc-card-layout-default.fc-card-layout-mobile {
        display: flex;
        flex-direction: column;
        gap: var(--fc-mobile-gap);
        width: 100%;
        min-width: 0;
    }

    .fc-card-layout-mobile > .fc-card-layout-item-default,
    .fc-card-layout-mobile .groupcontainer {
        width: 100% !important;
        min-width: 0 !important;
        max-width: 100% !important;
        height: auto !important;
        max-height: none !important;
    }

    .fc-card-layout-actions,
    .fc-card-layout-toolbar,
    .fc-workflow-desktop-editor,
    .fc-global-header-actions:not(.fc-global-header-actions--navigation) {
        display: none !important;
    }

    .fc-page-shell-title-actions:empty,
    .fc-page-shell-local-actions:empty {
        display: none;
    }

    .fc-global-header-actions--navigation {
        display: flex;
        flex-direction: column;
        align-items: stretch;
        width: 100%;
        gap: 0.75rem;
    }

    .fc-global-header-actions--navigation .fc-global-header-search {
        display: flex;
        flex: 0 0 auto;
        width: 100%;
        max-width: 100%;
    }

    .fc-global-header-actions--navigation .fc-global-header-filedrop {
        display: block;
        flex: 0 0 auto;
        width: 100%;
        min-width: 0;
        height: 2.75rem;
        margin: 0;
    }

    .fc-global-header-actions--navigation .filedrop-drop-label {
        display: inline;
    }

    .fc-global-header-actions--navigation .fc-global-user-host {
        display: flex;
        flex-direction: column;
        align-items: stretch;
        order: -1;
    }

    .fc-global-header-actions--navigation .fc-global-user-button {
        justify-content: flex-start;
        width: 100%;
        height: auto;
        min-height: 2.75rem;
        gap: 0.75rem;
        padding: 0.25rem;
        border-radius: var(--fc-radius);
    }

    .fc-global-navigation-username {
        min-width: 0;
        overflow-wrap: anywhere;
        text-align: left;
        color: var(--fc-text);
        font-size: 0.84rem;
    }

    .fc-global-header-actions--navigation .fc-global-user-popover {
        position: static;
        display: none;
        width: 100%;
        min-width: 0;
        max-width: 100% !important;
        margin-top: 0.5rem;
        transform: none !important;
        box-shadow: none;
    }

    .fc-global-header-actions--navigation .fc-global-user-popover.is-open {
        display: block;
    }

    .fc-global-header-actions--navigation .fc-global-popover-link {
        min-height: 2.75rem;
    }

    .fc-file-drop-zone:focus-within {
        outline: 2px solid var(--fc-primary);
        outline-offset: 2px;
    }
}
