/* Shared mobile/tablet baseline. Keep page-specific layout rules in their own assets. */
:root {
    --safe-area-top: env(safe-area-inset-top, 0px);
    --safe-area-right: env(safe-area-inset-right, 0px);
    --safe-area-bottom: env(safe-area-inset-bottom, 0px);
    --safe-area-left: env(safe-area-inset-left, 0px);
    --mobile-touch-target: 44px;
}

html,
body {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    overflow-x: hidden;
}

@supports (overflow: clip) {
    html,
    body {
        overflow-x: clip;
    }
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

img,
picture,
video,
svg,
iframe {
    max-width: 100%;
}

.se-shell,
.se-main,
.se-sidebar,
.se-guest-wrap,
.se-auth-page,
.tv1-app-shell,
.tv1-sidebar,
.customer-portal-shell,
.customer-portal-main__inner {
    min-height: 100vh;
    min-height: 100dvh;
}

.se-shell,
.se-sidebar,
.tv1-sidebar {
    height: 100vh;
    height: 100dvh;
}

.se-auth-shell {
    min-height: calc(100vh - 32px);
    min-height: calc(100dvh - 32px);
}

.crm-modal-card {
    max-height: 90vh;
    max-height: 90dvh;
}

@supports (height: 100dvh) {
    [class*="modal__card"],
    [class*="-modal-card"] {
        max-height: calc(100dvh - 20px);
    }
}

.se-mobile-bar,
.se-sidebar-backdrop {
    display: none;
}

@media screen and (max-width: 820px), (pointer: coarse) {
    input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]):not([type="hidden"]),
    select,
    textarea,
    [contenteditable="true"],
    .se-field,
    .se-input,
    .se-searchable-select__trigger {
        font-size: 16px !important;
    }

    input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]):not([type="hidden"]),
    select,
    .se-field,
    .se-input,
    .se-field--trigger,
    .se-searchable-select__trigger {
        min-height: var(--mobile-touch-target);
    }

    button,
    [role="button"],
    .se-btn,
    .se-btn-icon,
    .crm-icon-btn,
    .customer-icon-btn,
    a[class*="icon-btn"],
    button[class*="icon-btn"],
    button[class*="__close"],
    button[class*="-close"] {
        min-width: var(--mobile-touch-target);
        min-height: var(--mobile-touch-target);
    }

    .se-btn-icon,
    .crm-icon-btn,
    .customer-icon-btn,
    a[class*="icon-btn"],
    button[class*="icon-btn"],
    button[class*="__close"],
    button[class*="-close"] {
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    .crm-modal {
        padding-top: max(12px, var(--safe-area-top));
        padding-right: max(12px, var(--safe-area-right));
        padding-bottom: max(12px, var(--safe-area-bottom));
        padding-left: max(12px, var(--safe-area-left));
    }
}

/* Responsive shell for active admin/system pages. */
@media screen and (max-width: 1366px) {
    body.se-responsive-shell.se-mobile-nav-open {
        overflow: hidden;
    }

    .se-responsive-shell .se-shell {
        display: block;
        width: 100%;
        height: auto;
        min-height: 100vh;
        min-height: 100dvh;
    }

    .se-responsive-shell .se-layout {
        display: contents;
    }

    .se-responsive-shell .se-mobile-bar {
        position: sticky;
        top: 0;
        z-index: 40;
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 12px;
        min-height: calc(58px + var(--safe-area-top));
        padding-top: max(8px, var(--safe-area-top));
        padding-right: max(12px, var(--safe-area-right));
        padding-bottom: 8px;
        padding-left: max(12px, var(--safe-area-left));
        border-bottom: 1px solid rgba(96, 87, 159, 0.15);
        background: rgba(255, 255, 255, 0.94);
        box-shadow: 0 8px 24px rgba(30, 41, 59, 0.08);
        backdrop-filter: blur(12px);
    }

    .se-responsive-shell .se-mobile-menu-btn {
        display: inline-flex;
        align-items: center;
        gap: 9px;
        min-width: 44px;
        min-height: 44px;
        padding: 8px 12px;
        border: 1px solid #dedaf3;
        border-radius: 13px;
        background: #f7f5ff;
        color: #34306f;
        font: inherit;
        font-size: 13px;
        font-weight: 800;
        cursor: pointer;
    }

    .se-responsive-shell .se-mobile-menu-btn__icon {
        display: grid;
        gap: 4px;
        width: 18px;
        flex: 0 0 18px;
    }

    .se-responsive-shell .se-mobile-menu-btn__icon span {
        display: block;
        width: 100%;
        height: 2px;
        border-radius: 999px;
        background: currentColor;
        transition: transform 0.2s ease, opacity 0.2s ease;
    }

    .se-responsive-shell .se-mobile-menu-btn.is-open .se-mobile-menu-btn__icon span:first-child {
        transform: translateY(6px) rotate(45deg);
    }

    .se-responsive-shell .se-mobile-menu-btn.is-open .se-mobile-menu-btn__icon span:nth-child(2) {
        opacity: 0;
    }

    .se-responsive-shell .se-mobile-menu-btn.is-open .se-mobile-menu-btn__icon span:last-child {
        transform: translateY(-6px) rotate(-45deg);
    }

    .se-responsive-shell .se-mobile-bar__title {
        min-width: 0;
        overflow: hidden;
        color: #2f3545;
        font-size: 14px;
        font-weight: 800;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .se-responsive-shell .se-sidebar {
        position: fixed;
        inset-block: 0;
        inset-inline-start: 0;
        z-index: 60;
        width: min(320px, calc(100vw - 44px));
        height: 100vh;
        height: 100dvh;
        min-height: 0;
        margin: 0;
        padding-top: max(18px, var(--safe-area-top));
        padding-bottom: max(18px, var(--safe-area-bottom));
        box-sizing: border-box;
        transform: translateX(105%);
        visibility: hidden;
        pointer-events: none;
        transition: transform 0.24s ease, visibility 0.24s ease;
    }

    html[dir="ltr"] .se-responsive-shell .se-sidebar {
        transform: translateX(-105%);
    }

    .se-responsive-shell .se-sidebar.is-mobile-open,
    html[dir="ltr"] .se-responsive-shell .se-sidebar.is-mobile-open {
        transform: translateX(0);
        visibility: visible;
        pointer-events: auto;
    }

    .se-responsive-shell .se-sidebar-backdrop:not([hidden]) {
        position: fixed;
        inset: 0;
        z-index: 55;
        display: block;
        width: 100%;
        height: 100%;
        padding: 0;
        border: 0;
        background: rgba(15, 23, 42, 0.48);
        cursor: pointer;
        backdrop-filter: blur(2px);
    }

    .se-responsive-shell .se-main {
        width: 100%;
        min-width: 0;
        max-width: 100%;
        padding-top: 16px;
        padding-right: max(16px, var(--safe-area-right));
        padding-bottom: max(16px, var(--safe-area-bottom));
        padding-left: max(16px, var(--safe-area-left));
    }

    .se-responsive-shell :where(
        .crm-layout,
        .crm-page-slot,
        .se-card,
        .se-card-body,
        .se-page-head,
        .crm-top
    ) {
        min-width: 0;
        max-width: 100%;
    }

    .se-responsive-shell .crm-layout {
        padding: clamp(14px, 2.2vw, 24px);
    }

    .se-responsive-shell :where(.se-page-head, .crm-top, .se-page-actions) {
        flex-wrap: wrap;
    }

    .se-responsive-shell :where(.se-page-title, .se-page-desc, .crm-title, .crm-page-slot) {
        overflow-wrap: anywhere;
    }
}

/* Tablet shell guard: applies to every tenant screen, including large iPads
   using landscape or desktop-site mode. */
@media screen and (max-width: 1366px) {
    .tv1-body:not(.customer-portal-body) .tv1-mobile-bar {
        min-height: calc(58px + var(--safe-area-top));
        padding-top: max(8px, var(--safe-area-top)) !important;
        padding-right: max(12px, var(--safe-area-right)) !important;
        padding-left: max(12px, var(--safe-area-left)) !important;
    }

    .tv1-body:not(.customer-portal-body) .tv1-main {
        width: 100%;
        min-width: 0;
        max-width: 100%;
        padding-right: max(12px, var(--safe-area-right)) !important;
        padding-bottom: max(12px, var(--safe-area-bottom)) !important;
        padding-left: max(12px, var(--safe-area-left)) !important;
    }

    .tv1-body:not(.customer-portal-body) .tv1-sidebar {
        padding-top: max(18px, var(--safe-area-top));
        padding-bottom: max(18px, var(--safe-area-bottom));
    }

    .tv1-body:not(.customer-portal-body) :where(
        .tv1-main__inner,
        .tv1-page-wrap,
        .tv1-page-content,
        .tv1-index-layout__content,
        .tv1-index-layout__table-space,
        .tv1-index-layout__card-space,
        .tv1-detail-wrap,
        .tv1-detail-body,
        .tv1-detail-card
    ) {
        width: 100%;
        min-width: 0;
        max-width: 100%;
    }

    .tv1-body:not(.customer-portal-body) :where(
        .tv1-page-head,
        .tv1-index-layout__header,
        .tv1-index-layout__tools,
        .tv1-page-head__actions,
        .tv1-detail-head__top,
        .tv1-detail-head__actions
    ) {
        min-width: 0;
        max-width: 100%;
        flex-wrap: wrap;
    }

    .tv1-body:not(.customer-portal-body) :where(
        .tv1-index-layout__title-wrap,
        .tv1-index-layout__tools-start,
        .tv1-index-layout__tools-end,
        .tv1-detail-head__copy
    ) {
        min-width: 0;
        max-width: 100%;
    }

    .tv1-body:not(.customer-portal-body) .tv1-index-layout__tools-start {
        flex: 1 1 420px;
    }

    .tv1-body:not(.customer-portal-body) :where(
        .tv1-page-title,
        .tv1-page-subtitle,
        .tv1-detail-title,
        .tv1-detail-subtitle
    ) {
        overflow-wrap: anywhere;
    }

    .tv1-body:not(.customer-portal-body) .tv1-main :where([class*="-grid"], [class*="__grid"]) > * {
        min-width: 0;
    }

    .tv1-body:not(.customer-portal-body) :where(
        .tv1-tabs,
        .crm-tabs,
        .customer-tabs,
        .tv1-project-tabs
    ) {
        max-width: 100%;
        overflow-x: auto;
        overflow-y: hidden;
        overscroll-behavior-inline: contain;
        -webkit-overflow-scrolling: touch;
    }
}

@media print {
    html,
    body {
        width: auto;
        max-width: none;
        overflow: visible;
    }

    .se-shell,
    .se-main,
    .se-sidebar,
    .se-guest-wrap,
    .se-auth-page,
    .tv1-app-shell,
    .tv1-sidebar,
    .customer-portal-shell,
    .customer-portal-main__inner {
        min-height: 0;
        height: auto;
    }
}
