/* Shared Ask AI rail chrome — Service Desk WorkItemAskAiWorkspace is the visual reference. */

.nucleus-ask-ai-rail,
.work-item-ask-ai--layout {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 0;
    height: 100%;
    max-height: 100%;
}

.nucleus-ask-ai-rail__quick,
.work-item-ask-ai-quick {
    flex-shrink: 0;
    width: 100%;
    margin-bottom: 0.25rem;
}

.nucleus-ask-ai-rail__quick .mud-input-control,
.work-item-ask-ai-quick-select {
    width: 100%;
}

.nucleus-ask-ai-rail__toolbar,
.work-item-ask-ai-advanced-row {
    display: flex;
    align-items: flex-start;
    gap: 0.375rem;
    flex-shrink: 0;
    width: 100%;
    max-width: 100%;
    margin-bottom: 0.5rem;
    min-width: 0;
    box-sizing: border-box;
}

.nucleus-ask-ai-rail__toolbar-spacer {
    flex: 1 1 auto;
    min-width: 0;
}

.nucleus-ask-ai-rail__body {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 0;
    min-width: 0;
}

/*
 * Entity Ask AI host — mirrors Service Desk .service-desk-ask-ai-rail-host.
 * Tab wrappers must fill the rail body; without this the composer stacks at the top.
 */
.nucleus-detail-rail-ask-ai-host {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 0;
    width: 100%;
    height: 100%;
    max-height: 100%;
    overflow: hidden;
}

/* Bootstrap .d-none uses !important — keep hide working when host sets display:flex */
.nucleus-detail-rail-ask-ai-host.d-none {
    display: none !important;
}

.nucleus-detail-rail-ask-ai-host > .nucleus-ask-ai-panel {
    flex: 1 1 auto;
    min-height: 0;
    width: 100%;
    height: 100%;
    max-height: 100%;
    overflow: hidden;
}

/* Fallback: any direct body child that hosts the panel */
.nucleus-context-panel-content:has(.nucleus-ask-ai-panel) > div:has(> .nucleus-ask-ai-panel):not(.d-none),
.account-detail-right-rail-card__body:has(.nucleus-ask-ai-panel) > div:has(> .nucleus-ask-ai-panel):not(.d-none) {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 0;
    width: 100%;
    height: 100%;
    max-height: 100%;
    overflow: hidden;
}

.nucleus-context-panel-content > div:has(> .nucleus-ask-ai-panel) > .nucleus-ask-ai-panel,
.account-detail-right-rail-card__body > div:has(> .nucleus-ask-ai-panel) > .nucleus-ask-ai-panel {
    flex: 1 1 auto;
    min-height: 0;
    width: 100%;
    height: 100%;
    max-height: 100%;
    overflow: hidden;
}

/*
 * When Ask AI host is visible, lock outer rail scroll (SD :has(.service-desk-ask-ai-rail-host)).
 */
.nucleus-context-panel-content:has(> .nucleus-detail-rail-ask-ai-host:not(.d-none)),
.nucleus-detail-rail-card__body:has(> .nucleus-detail-rail-ask-ai-host:not(.d-none)),
.nucleus-detail-rail-card__body.nucleus-context-panel-content:has(> .nucleus-detail-rail-ask-ai-host:not(.d-none)),
.account-detail-right-rail-card__body:has(> .nucleus-detail-rail-ask-ai-host:not(.d-none)),
.account-detail-right-rail-card__body.nucleus-context-panel-content:has(> .nucleus-detail-rail-ask-ai-host:not(.d-none)),
.nucleus-context-panel-content:has(> div:has(> .nucleus-ask-ai-panel):not(.d-none)),
.account-detail-right-rail-card__body:has(> div:has(> .nucleus-ask-ai-panel):not(.d-none)) {
    overflow-x: hidden;
    overflow-y: hidden;
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 0;
    height: 100%;
}

.nucleus-detail-side-panel:has(.nucleus-detail-rail-ask-ai-host:not(.d-none)),
.nucleus-detail-side-panel:has(.nucleus-ask-ai-panel) {
    display: flex;
    flex-direction: column;
    min-height: 0;
    height: 100%;
    overflow: hidden;
}

.nucleus-detail-side-panel:has(.nucleus-ask-ai-panel) > .nucleus-context-panel-content {
    flex: 1 1 auto;
    min-height: 0;
}

/* Fill chain: panel → layout → UIC → messages scroll, composer pinned */
.nucleus-ask-ai-panel--fill-height .nucleus-ask-ai-rail,
.nucleus-ask-ai-panel--fill-height .nucleus-ask-ai-rail__body,
.nucleus-ask-ai-panel--fill-height .nucleus-ask-ai-rail-chat,
.nucleus-ask-ai-panel--fill-height .nucleus-ask-ai-rail-chat.unified-chat-wrapper,
.nucleus-ask-ai-panel--fill-height .nucleus-ask-ai-rail-chat .unified-chat-wrapper,
.nucleus-ask-ai-panel--fill-height .nucleus-ask-ai-rail-chat .unified-chat-container,
.nucleus-ask-ai-panel--fill-height .nucleus-ask-ai-rail-chat .unified-chat-main,
.nucleus-ask-ai-panel--fill-height .nucleus-ask-ai-rail-chat .chat-panel {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 0;
    min-width: 0;
    height: 100%;
    max-height: 100%;
    width: 100%;
}

/* Rail is ~420px; default chat-panel min-width is A4-wide and breaks the flex column */
.nucleus-ask-ai-rail-chat .chat-panel,
.nucleus-ask-ai-panel--fill-height .nucleus-ask-ai-rail-chat .chat-panel {
    min-width: 0 !important;
    flex-basis: auto !important;
    border-right: none;
}

.nucleus-ask-ai-rail-chat .chat-messages-body {
    flex: 1 1 0;
    min-height: 0;
    overflow-y: auto;
}

.nucleus-ask-ai-rail-chat .entity-chat-landing,
.nucleus-ask-ai-rail-empty {
    padding: 1.25rem 0.75rem;
    text-align: center;
}

.nucleus-ask-ai-rail-chat .chat-input-wrapper {
    flex-shrink: 0;
    margin-top: auto;
}

.nucleus-ask-ai-rail-chat .chat-input-panel {
    border: none;
    box-shadow: none;
    background: transparent;
    padding: 0;
}

.nucleus-ask-ai-rail-chat .nucleus-ask-ai-rail-composer,
.nucleus-ask-ai-rail-chat .work-item-ask-ai-composer {
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    padding-top: 0.15rem;
    border-top: 1px solid var(--mud-palette-divider);
    background: var(--mud-palette-surface);
}

.nucleus-ask-ai-rail-chat .work-item-ask-ai-send {
    align-self: stretch;
    width: 100%;
}

.nucleus-ask-ai-rail .work-item-ask-ai-clear-btn.mud-button-root {
    flex: 0 0 auto;
    align-self: flex-start;
    min-height: 2.25rem;
    padding-left: 0.25rem !important;
    padding-right: 0.25rem !important;
    white-space: nowrap;
}
