/* Shell geometry aliases. Brand tokens remain in tokens.css. */
:root {
    --em-app-header-height: 56px;
    --em-app-rail-width: 80px;
    --em-app-bottom-height: 64px;
    --em-app-bottom-reserve: calc(var(--em-app-bottom-height) + env(safe-area-inset-bottom, 0px));
}

:is(.em-app-layout, .em-auth-layout) :is(input, textarea, select, button, [tabindex]):is(:focus, :focus-visible) {
    outline: none !important;
}
:is(.em-operational-shell, .em-auth-layout) input { caret-color: var(--color-primary); }
:is(.em-operational-shell, .em-auth-layout) ::selection { background: var(--color-primary-light); color: var(--color-primary-dark); }

/* Overlays keep their public contracts and their existing z-index hierarchy. */
:is(.em-operational-shell, .em-auth-layout) .app-bottom-sheet-wrapper {
    pointer-events: none;
    padding-inline: env(safe-area-inset-left, 0px) env(safe-area-inset-right, 0px);
    padding-top: env(safe-area-inset-top, 0px);
    max-height: var(--em-visual-height, 100dvh);
}
:is(.em-operational-shell, .em-auth-layout) .app-bottom-sheet {
    pointer-events: auto;
    max-height: min(85dvh, calc(var(--em-visual-height, 100dvh) - env(safe-area-inset-top, 0px) - 16px));
}
:is(.em-operational-shell, .em-auth-layout) :is(.app-modal__body, .app-bottom-sheet__body) {
    min-height: 0;
    overscroll-behavior: contain;
}
:is(.em-operational-shell, .em-auth-layout) .app-modal-wrapper {
    padding: max(var(--space-4), env(safe-area-inset-top, 0px)) max(var(--space-4), env(safe-area-inset-right, 0px)) max(var(--space-4), env(safe-area-inset-bottom, 0px)) max(var(--space-4), env(safe-area-inset-left, 0px));
    max-height: var(--em-visual-height, 100dvh);
}
:is(.em-operational-shell, .em-auth-layout) .app-modal {
    max-height: calc(var(--em-visual-height, 100dvh) - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px) - 32px);
}
:is(.em-operational-shell, .em-auth-layout) .app-modal--fullscreen { height: calc(var(--em-visual-height, 100dvh) - 16px); }
:is(.em-operational-shell, .em-auth-layout) :is(.app-modal__footer, .app-bottom-sheet__footer) { flex-wrap: wrap; }

@media (max-width: 1199px) {
    .em-operational-shell .em-page-shell { min-width: 0; max-width: 100%; }
    /* Keep the semantic h1/focus target; the compact shell already names the page. */
    .em-operational-shell .em-page-header .em-page-title {
        position: absolute;
        width: 1px;
        height: 1px;
        padding: 0;
        margin: -1px;
        overflow: hidden;
        clip-path: inset(50%);
        white-space: nowrap;
    }
    .em-operational-shell .em-page-header { min-width: 0; }
    .em-operational-shell .em-datagrid-toolbar__search { min-width: 0; flex-basis: 240px; }
    .em-operational-shell .em-datagrid-search-input { min-width: 0; width: 100%; }
    .em-operational-shell :is(.em-prod-form-grid, .em-cat-form-grid) > * { min-width: 0; }
    :is(.em-operational-shell, .em-auth-layout) :is(input:not([type=checkbox]):not([type=radio]), textarea, select) { font-size: 16px; }
    :is(.em-operational-shell, .em-auth-layout) :is(.em-input-wrapper, .em-select-trigger, .em-datagrid-search-box) { min-height: 44px; }
    :is(.em-operational-shell, .em-auth-layout) :is(.app-modal__close-btn, .app-bottom-sheet__close-btn, .app-btn, .em-action-menu__trigger, .em-context-menu__trigger) { min-height: 44px; min-width: 44px; }
    .em-operational-shell .app-toast-host { top: calc(var(--em-app-header-height) + env(safe-area-inset-top, 0px) + var(--space-2)); }
}

@media (max-width: 767px) {
    :is(.em-operational-shell, .em-auth-layout) .app-modal-wrapper { padding: max(var(--space-2), env(safe-area-inset-top, 0px)) max(var(--space-2), env(safe-area-inset-right, 0px)) max(var(--space-2), env(safe-area-inset-bottom, 0px)) max(var(--space-2), env(safe-area-inset-left, 0px)); }
    .em-operational-shell .em-page-shell { padding: var(--space-4); }
    .em-operational-shell :is(.em-page-header__actions, .em-prod-form-actions, .em-cat-form-actions) { flex-wrap: wrap; }
    .em-operational-shell .em-datagrid-toolbar { padding: var(--space-3); }
    .em-operational-shell .em-datagrid-toolbar__filters { min-width: 0; max-width: 100%; }
    .em-operational-shell :is(.em-prod-edit-btn, .em-btn-icon, .em-action-add-btn, .em-stepper-btn, .em-tab-nav__item, .em-fila-badge-action) { min-height: 44px; min-width: 44px; }
    :is(.em-operational-shell, .em-auth-layout) .app-bottom-sheet-wrapper { padding-bottom: 0; }
    :is(.em-operational-shell, .em-auth-layout) .app-bottom-sheet { border-radius: var(--radius-xl) var(--radius-xl) 0 0; }
    :is(.em-operational-shell, .em-auth-layout) .app-toast-host { left: max(var(--space-4), env(safe-area-inset-left, 0px)); right: max(var(--space-4), env(safe-area-inset-right, 0px)); }
    .em-auth-layout .app-toast-host { top: max(var(--space-4), env(safe-area-inset-top, 0px)); }
    html[data-em-keyboard-open] .em-shell-bottom-nav { visibility: hidden; pointer-events: none; }
}

@media (pointer: coarse) {
    .em-operational-shell :is(.em-prod-edit-btn, .em-cat-edit-btn, .em-tab-nav__item, .em-action-menu__item, .em-context-menu__item) { min-height: 44px; min-width: 44px; }
}
@media (prefers-reduced-motion: reduce) {
    :is(.em-operational-shell, .em-auth-layout) :is(.app-bottom-sheet, .app-modal) { animation: none; }
}
