/* Production normalization for operational pages.
   Every selector is rooted to a page namespace to avoid cross-page regressions. */
:where(
    .sales-container,
    .sc-container,
    .ld-container,
    .customer-page,
    .settings-page,
    .intent-page,
    .intent-detail-page,
    .flowise-page,
    .log-detail-container,
    .stats-page,
    .kpi-page,
    .facebook-pages-page,
    .zi-page,
    .permissions-container
) {
    min-width: 0;
}

/* Chat workspace sizing fix: the workspace is already below the app top bar,
   so it must fill its parent rather than create a second 100dvh viewport. */
.chat-dashboard-body .app-shell,
.chat-dashboard-body .app-main {
    height: 100dvh;
    min-height: 0;
    overflow: hidden;
}

.chat-dashboard-body .app-top {
    position: relative;
    flex: 0 0 var(--sh-top-h, 60px);
}

.chat-dashboard-body .app-content {
    display: flex;
    flex: 1 1 auto;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
}

.chat-dashboard-body .chat-app-shell,
.chat-dashboard-body .chat-app-main,
.chat-dashboard-body .chat-app-main > .container,
.chat-dashboard-body .dashboard-shell,
.chat-dashboard-body .conversation-page,
.chat-dashboard-body .dashboard-layout,
.chat-dashboard-body .chat-wrapper {
    width: 100%;
    height: 100% !important;
    max-height: 100% !important;
    min-height: 0;
}

.chat-dashboard-body .chat-app-shell,
.chat-dashboard-body .chat-app-main,
.chat-dashboard-body .dashboard-shell,
.chat-dashboard-body .conversation-page {
    flex: 1 1 auto;
    overflow: hidden;
}

.chat-dashboard-body .chat-app-main {
    padding: 0;
}

.chat-dashboard-body .conversations-panel,
.chat-dashboard-body .thread-panel,
.chat-dashboard-body .chat-panel,
.chat-dashboard-body .info-panel {
    height: 100% !important;
    max-height: 100% !important;
    min-height: 0;
    overflow: hidden;
}

.chat-dashboard-body .conversations-panel,
.chat-dashboard-body .thread-panel,
.chat-dashboard-body .chat-panel {
    display: flex;
    flex-direction: column;
}

.chat-dashboard-body .conversations-list,
.chat-dashboard-body .thread-scroll,
.chat-dashboard-body .message-scroll,
.chat-dashboard-body .info-panel {
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior-y: contain;
    -webkit-overflow-scrolling: touch;
    scrollbar-gutter: stable;
}

.chat-dashboard-body .message-scroll {
    position: relative;
    flex: 1 1 0;
    height: 0;
    overflow-x: hidden;
    touch-action: pan-y;
}

.chat-dashboard-body :where(.chat-header, .composer, .conversations-header, .thread-panel-header, .thread-search, .conversations-load-more) {
    flex: 0 0 auto;
}

.chat-dashboard-body :where(.chat-header, .header-user, .header-info, .header-subtitle, .labels-container) {
    min-width: 0;
}

.chat-dashboard-body .message-bubble,
.chat-dashboard-body .message-bubble :where(p, a, code, pre) {
    max-width: 100%;
    overflow-wrap: anywhere;
    word-break: break-word;
}

.chat-dashboard-body .message-bubble :where(img, video) {
    max-width: min(100%, 420px);
    height: auto;
}

/* Compact company toolbar on /<company>/ (for example /irc/). */
.chat-dashboard-body .dashboard-header-collapsible {
    display: block;
    flex: 0 0 auto;
    max-height: 52px;
    margin: 0;
    padding: 0.35rem 0.75rem;
    overflow: visible;
}

.chat-dashboard-body .hero-section.company-hero,
.chat-dashboard-body .hero-section.company-hero .hero-content {
    width: 100%;
    min-width: 0;
}

.chat-dashboard-body .hero-section.company-hero .hero-header {
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    min-height: 40px;
    gap: 0.75rem;
}

.chat-dashboard-body .hero-section.company-hero .hero-title {
    flex: 1 1 auto;
    width: auto;
    min-width: 0;
    font-size: 0.92rem;
    line-height: 1.2;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-dashboard-body .hero-section.company-hero .hero-actions {
    display: flex;
    flex: 0 0 auto;
    flex-wrap: nowrap;
    align-items: center;
    margin-left: auto;
    gap: 0.4rem;
}

.chat-dashboard-body .hero-section.company-hero .hero-btn {
    min-height: 32px;
    padding: 0.35rem 0.65rem;
    font-size: 0.72rem;
    white-space: nowrap;
}

@media (max-width: 1180px) and (min-width: 769px) {
    .chat-dashboard-body .header-actions .message-count { display: none; }
    .chat-dashboard-body .message-scroll { padding-inline: 1rem; }
}

@media (max-width: 768px) {
    .chat-dashboard-body .app-top {
        flex-basis: var(--sh-top-h, 60px);
        min-height: var(--sh-top-h, 60px);
        padding-inline: 12px;
    }

    .chat-dashboard-body .chat-app-shell { grid-template-rows: minmax(0, 1fr) !important; }

    .chat-dashboard-body .dashboard-shell {
        display: flex;
        flex-direction: column;
    }

    .chat-dashboard-body .dashboard-layout,
    .chat-dashboard-body .chat-wrapper {
        flex: 1 1 auto;
        height: auto !important;
        min-height: 0;
        overflow: hidden;
    }

    .chat-dashboard-body .dashboard-mobile-toggles {
        flex: 0 0 auto;
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .chat-dashboard-body .dashboard-shell[data-mobile-panel='chat'] .chat-panel,
    .chat-dashboard-body .dashboard-shell[data-mobile-panel='conversations'] .conversations-panel,
    .chat-dashboard-body .dashboard-shell[data-mobile-panel='info'] .info-panel {
        display: flex !important;
        width: 100%;
        height: 100% !important;
    }

    .chat-dashboard-body .dashboard-shell[data-mobile-panel='chat'] :where(.conversations-panel, .info-panel),
    .chat-dashboard-body .dashboard-shell[data-mobile-panel='conversations'] :where(.chat-panel, .info-panel),
    .chat-dashboard-body .dashboard-shell[data-mobile-panel='info'] :where(.chat-panel, .conversations-panel) {
        display: none !important;
    }

    .chat-dashboard-body .conversation-page .chat-wrapper { display: flex; }
    .chat-dashboard-body .conversation-page :where(.thread-panel, .info-panel) { display: none !important; }

    .chat-dashboard-body .conversation-page .chat-panel {
        display: flex !important;
        width: 100%;
        height: 100% !important;
        border: 0;
    }

    .chat-dashboard-body .chat-header {
        gap: 0.5rem;
        min-height: 58px;
        padding: 0.55rem 0.65rem;
    }

    .chat-dashboard-body .header-avatar { width: 36px; height: 36px; }

    .chat-dashboard-body .header-name {
        max-width: 42vw;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .chat-dashboard-body :where(.header-subtitle, .message-count) { display: none; }

    .chat-dashboard-body .chat-header { flex-wrap: wrap; }

    .chat-dashboard-body .header-user { flex: 1 1 0; }

    .chat-dashboard-body .header-actions {
        flex: 1 0 100%;
        justify-content: flex-end;
        gap: 0.4rem;
    }

    .chat-dashboard-body .header-actions :where(.mode-action, .crm-drawer-toggle) {
        min-height: 34px;
        padding: 0.35rem 0.55rem;
        font-size: 0.7rem;
    }

    .chat-dashboard-body :where(.crm-drawer-toggle, .mobile-chat-back) {
        display: inline-flex;
        flex: 0 0 auto;
    }

    .chat-dashboard-body.crm-pane-open .conversation-page .info-panel {
        position: fixed;
        inset: var(--sh-top-h, 60px) 0 0 auto;
        z-index: 120;
        display: flex !important;
        width: min(88vw, 360px);
        height: calc(100dvh - var(--sh-top-h, 60px)) !important;
        max-height: none !important;
        background: var(--asa-surface, #fff);
        box-shadow: -16px 0 36px rgba(15, 23, 42, 0.22);
    }

    .chat-dashboard-body.crm-pane-open .conversation-page .crm-drawer-close {
        display: inline-flex;
    }

    .chat-dashboard-body .message-scroll {
        padding: 0.75rem;
        scrollbar-gutter: auto;
    }

    .chat-dashboard-body .message { max-width: 90%; }

    .chat-dashboard-body .composer {
        padding: 0.5rem max(0.5rem, env(safe-area-inset-right)) max(0.5rem, env(safe-area-inset-bottom)) max(0.5rem, env(safe-area-inset-left));
    }

    .chat-dashboard-body .composer .mode-alert { display: none; }
    .chat-dashboard-body .composer-form { align-items: flex-end; }
    .chat-dashboard-body .composer-input { min-width: 0; max-height: 30dvh; }
    .chat-dashboard-body .composer-send { flex: 0 0 auto; min-width: 64px; }
}

/* Static presentation formerly embedded in templates. */
.section-title--danger {
    color: var(--danger, #c7504a);
}

.btn-connect-page {
    padding: 14px 32px;
    font-size: 16px;
}

.settings-empty-state {
    padding: 2rem;
    color: var(--text-light);
    text-align: center;
}

.settings-empty-state__icon {
    margin-bottom: .5rem;
    font-size: 2rem;
}

.customer-empty-icon {
    font-size: 2.5rem;
}

.chip-group--center {
    justify-content: center;
}

.export-btn--customers {
    border-color: rgba(16, 185, 129, .5);
    background: rgba(16, 185, 129, .25);
}

.export-btn--leads {
    border-color: rgba(56, 189, 248, .5);
    background: rgba(56, 189, 248, .22);
}

.export-btn--interactive {
    cursor: pointer;
}

.export-btn--sync {
    cursor: pointer;
    border-color: rgba(245, 158, 11, .5);
    background: rgba(245, 158, 11, .25);
}

.import-status {
    align-self: center;
    color: rgba(245, 243, 255, .85);
    font-size: .66rem;
}

:where(
    .sales-container,
    .sc-container,
    .ld-container,
    .customer-page,
    .settings-page,
    .intent-page,
    .intent-detail-page,
    .flowise-page,
    .log-detail-container,
    .stats-page,
    .kpi-page,
    .facebook-pages-page,
    .zi-page,
    .permissions-container
) :where(img, video, canvas, iframe) {
    max-width: 100%;
}

:where(
    .sales-container,
    .sc-container,
    .ld-container,
    .customer-page,
    .settings-page,
    .intent-page,
    .intent-detail-page,
    .flowise-page,
    .log-detail-container,
    .stats-page,
    .kpi-page,
    .facebook-pages-page,
    .zi-page,
    .permissions-container
) :where(p, td, th, dd, pre, code, .card, .panel) {
    overflow-wrap: anywhere;
}

:where(
    .sales-container,
    .sc-container,
    .ld-container,
    .customer-page,
    .settings-page,
    .intent-page,
    .intent-detail-page,
    .flowise-page,
    .log-detail-container,
    .stats-page,
    .kpi-page,
    .facebook-pages-page,
    .zi-page,
    .permissions-container
) :where(input, textarea, select) {
    max-width: 100%;
}

:where(
    .sales-container,
    .sc-container,
    .ld-container,
    .customer-page,
    .settings-page,
    .intent-page,
    .intent-detail-page,
    .flowise-page,
    .log-detail-container,
    .stats-page,
    .kpi-page,
    .facebook-pages-page,
    .zi-page,
    .permissions-container
) :where(button, .btn, [role="button"]) {
    touch-action: manipulation;
}

:where(
    .sales-container,
    .sc-container,
    .ld-container,
    .settings-page,
    .intent-page,
    .flowise-page,
    .log-detail-container,
    .stats-page,
    .facebook-pages-page,
    .zi-page,
    .permissions-container
) :where(.table-wrapper, .table-container, .data-table-wrap) {
    max-width: 100%;
    overflow-x: auto;
    overscroll-behavior-inline: contain;
    -webkit-overflow-scrolling: touch;
}

@media (max-width: 700px) {
    :where(
        .sales-container,
        .sc-container,
        .ld-container,
        .customer-page,
        .settings-page,
        .intent-page,
        .intent-detail-page,
        .flowise-page,
        .log-detail-container,
        .stats-page,
        .kpi-page,
        .facebook-pages-page,
        .zi-page,
        .permissions-container
    ) :where(button, .btn, [role="button"], input, select) {
        min-height: 44px;
    }

    :where(.sales-container, .sc-container, .ld-container, .log-detail-container, .permissions-container) {
        padding-inline: 12px;
    }

    :where(.sales-hero, .sc-hero, .ld-hero, .detail-hero, .settings-header) {
        border-radius: 12px;
    }
}

@media (prefers-reduced-motion: reduce) {
    :where(
        .sales-container,
        .sc-container,
        .ld-container,
        .settings-page,
        .intent-page,
        .flowise-page,
        .log-detail-container,
        .stats-page,
        .kpi-page,
        .facebook-pages-page,
        .zi-page,
        .permissions-container
    ) *,
    :where(
        .sales-container,
        .sc-container,
        .ld-container,
        .settings-page,
        .intent-page,
        .flowise-page,
        .log-detail-container,
        .stats-page,
        .kpi-page,
        .facebook-pages-page,
        .zi-page,
        .permissions-container
    ) *::before,
    :where(
        .sales-container,
        .sc-container,
        .ld-container,
        .settings-page,
        .intent-page,
        .flowise-page,
        .log-detail-container,
        .stats-page,
        .kpi-page,
        .facebook-pages-page,
        .zi-page,
        .permissions-container
    ) *::after {
        scroll-behavior: auto !important;
        animation-duration: .01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: .01ms !important;
    }
}
