/**
 * Full-height AI chat shell: centered thread (~820px), soft surface, sticky header.
 */
:root {
    --ai-chat-max-width: 820px;
    --ai-chat-assistant-max-width: 760px;
    --ai-chat-surface: #f8fafc;
    --ai-chat-header-bg: #ffffff;
    --ai-chat-composer-bg: #ffffff;
    --ai-chat-header-border: #e2e8f0;
}

.ai-chat-scroll,
.ai-chat-composer-textarea {
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-gutter: stable;
    scrollbar-width: thin;
    scrollbar-color: #cbd5e1 transparent;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}

.ai-chat-scroll {
    background: var(--ai-chat-surface);
}

.ai-chat-scroll::-webkit-scrollbar,
.ai-chat-composer-textarea::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

.ai-chat-scroll::-webkit-scrollbar-track,
.ai-chat-composer-textarea::-webkit-scrollbar-track {
    background: transparent;
}

.ai-chat-scroll::-webkit-scrollbar-thumb,
.ai-chat-composer-textarea::-webkit-scrollbar-thumb {
    background-color: #cbd5e1;
    border-radius: 999px;
}

.ai-chat-scroll:hover::-webkit-scrollbar-thumb,
.ai-chat-composer-textarea:hover::-webkit-scrollbar-thumb {
    background-color: #94a3b8;
}

.ai-chat-scroll::-webkit-scrollbar-thumb:hover,
.ai-chat-composer-textarea::-webkit-scrollbar-thumb:hover {
    background-color: #94a3b8;
}

.ai-chat-scroll::-webkit-scrollbar-corner,
.ai-chat-composer-textarea::-webkit-scrollbar-corner {
    background: transparent;
}

.ai-chat-thread,
.ai-chat-composer-inner {
    width: 100%;
    max-width: var(--ai-chat-max-width);
    margin-left: auto;
    margin-right: auto;
    padding-left: 1rem;
    padding-right: 1rem;
}

@media (min-width: 768px) {
    .ai-chat-thread,
    .ai-chat-composer-inner {
        padding-left: 1.25rem;
        padding-right: 1.25rem;
    }
}

.ai-chat-sticky-header {
    flex-shrink: 0;
    position: sticky;
    top: 0;
    z-index: 100;
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-bottom: 1px solid #eef2f7;
}

/* Marvella One — compact sticky header */
.ai-orch-header.ai-chat-sticky-header {
    padding-top: 0.5rem;
    padding-bottom: 0.5rem;
}

.ai-orch-header .ai-chat-thread {
    gap: 0.625rem;
    align-items: center;
}

.ai-orch-header .ai-orch-badge {
    width: 30px;
    height: 30px;
    font-size: 0.875rem;
    border-radius: 0.5rem;
    flex-shrink: 0;
    background: linear-gradient(135deg, #6f7bff 0%, #b97cff 100%);
    color: #fff;
}

.ai-orch-header .ai-orch-title {
    font-size: 0.9375rem;
    line-height: 1.25;
    margin-bottom: 0;
}

.ai-orch-header .ai-orch-subtitle {
    display: block;
    font-size: 0.75rem;
    line-height: 1.2;
    margin-top: 0.125rem;
    color: #64748b;
}

.ai-orch-header .ai-orch-force-agent {
    min-width: 10.5rem;
}

.ai-orch-header .ai-orch-force-agent .form-label {
    margin-bottom: 0.125rem;
    font-size: 0.6875rem;
    line-height: 1.2;
}

.ai-orch-header .ai-orch-force-agent .form-select {
    padding-top: 0.2rem;
    padding-bottom: 0.2rem;
    min-height: 1.75rem;
    font-size: 0.8125rem;
}

/* Desktop: full viewport height below ERP nav */
@media (min-width: 768px) {
    body:has(.ai-orch-page),
    body:has(.ai-chat-page) {
        overflow: hidden;
        background: var(--ai-chat-surface);
    }

    body:has(.ai-orch-page) .container,
    body:has(.ai-chat-page) .container {
        margin-top: 0 !important;
        padding-left: 0 !important;
        padding-right: 0 !important;
        max-width: 100% !important;
    }

    body:has(.ai-chat-page) .container > h4.mb-3 {
        display: none;
    }

    .ai-orch-page,
    .ai-chat-page {
        position: fixed;
        top: var(--erp-header-height, 110px);
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        margin: 0 !important;
        overflow: hidden;
        z-index: 1;
        background: var(--ai-chat-surface);
    }

    .ai-orch-page .ai-orch-card,
    .ai-chat-page .ai-chat-shell-card {
        width: 100%;
        height: 100%;
        max-width: 100%;
        margin: 0;
        border: 0;
        border-radius: 0;
        box-shadow: none !important;
        background: var(--ai-chat-surface);
    }

    .ai-orch-page .ai-orch-messages.ai-chat-scroll,
    .ai-chat-page .ai-chat-shell-messages.ai-chat-scroll {
        overflow-y: scroll;
    }

    .ai-chat-page .ai-chat-shell-composer-wrap {
        border-top: 1px solid var(--ai-chat-header-border);
        box-shadow: 0 -4px 16px rgba(15, 23, 42, 0.04);
    }

    .ai-chat-page #ai-chat-date-row {
        background: var(--ai-chat-composer-bg);
        border-top: 1px solid var(--ai-chat-header-border);
        max-width: var(--ai-chat-max-width);
        margin-left: auto;
        margin-right: auto;
        width: 100%;
        padding-left: 1.25rem !important;
        padding-right: 1.25rem !important;
    }
}

.ai-orch-page,
.ai-chat-page {
    overflow: hidden;
    margin-top: 0 !important;
}

.ai-orch-page > .col-12,
.ai-chat-page > .col-12 {
    height: 100%;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.ai-orch-page .ai-orch-card,
.ai-chat-page .ai-chat-shell-card {
    flex: 1;
    min-height: 0;
    height: 100%;
    display: flex;
    flex-direction: column;
}

.ai-orch-page .ai-orch-card > .card-header,
.ai-chat-page .ai-chat-shell-card > .ai-chat-sticky-header {
    flex-shrink: 0;
}

.ai-orch-page .ai-orch-card > .card-body,
.ai-chat-page .ai-chat-shell-card > .card-body {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.ai-orch-page .ai-orch-messages,
.ai-chat-page .ai-chat-shell-messages {
    flex: 1 1 auto;
    min-height: 0;
    max-height: none;
}

.ai-orch-page .ai-orch-form,
.ai-chat-page .ai-chat-shell-composer-wrap,
.ai-chat-page #ai-chat-date-row {
    flex: 0 0 auto;
    flex-shrink: 0;
    z-index: 3;
}

.ai-orch-page .ai-orch-form.ai-chat-composer-dock {
    background: linear-gradient(180deg, rgba(248, 250, 252, 0) 0%, var(--ai-chat-surface) 32%);
    border: 0;
    box-shadow: none;
}

.ai-chat-page .ai-chat-shell-composer-wrap {
    background: var(--ai-chat-composer-bg);
}

.ai-chat-page .ai-chat-shell-composer-wrap {
    padding-top: 0.75rem;
    padding-bottom: 0.75rem;
}

/* In-thread message bubbles (orchestrator + booking) */
.ai-chat-turn {
    display: flex;
    width: 100%;
    margin-bottom: 1.25rem;
}

.ai-chat-turn--user {
    justify-content: flex-end;
}

.ai-chat-turn--assistant,
.ai-chat-turn--bot {
    justify-content: flex-start;
    align-items: flex-start;
    gap: 0.625rem;
}

.ai-chat-turn-stack,
.ai-chat-turn-body {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    min-width: 0;
}

.ai-chat-turn-stack,
.ai-chat-turn--bot .ai-chat-turn-body,
.ai-chat-turn--assistant .ai-chat-turn-stack {
    max-width: min(var(--ai-chat-assistant-max-width), 100%);
}

.ai-chat-turn--user .ai-chat-msg-bubble {
    max-width: min(85%, 32rem);
}

.ai-chat-agent-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.2rem;
    font-size: 0.75rem;
    font-weight: 500;
    line-height: 1.25;
    color: #64748b;
    margin-bottom: 0.5rem;
    padding: 0;
    background: transparent;
    border: 0;
}

.ai-chat-agent-badge--pending {
    color: #94a3b8;
}

.ai-chat-msg-bubble {
    line-height: 1.55;
    font-size: 0.9375rem;
    white-space: pre-wrap;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.ai-chat-msg-bubble--user {
    padding: 0.75rem 1rem;
    border-radius: 18px;
    background: linear-gradient(145deg, #1d4ed8 0%, #3b82f6 55%, #60a5fa 100%);
    color: #fff;
    box-shadow: 0 4px 14px rgba(37, 99, 235, 0.25);
}

.ai-chat-msg-bubble--assistant {
    width: 100%;
    max-width: min(var(--ai-chat-assistant-max-width), 100%);
    padding: 1rem 1.25rem;
    border-radius: 18px;
    background: #f8fafc;
    color: #1e293b;
    border: 1px solid #e5e7eb;
    box-shadow: none;
}

.ai-chat-msg-bubble--assistant .ai-chat-msg-text,
.ai-chat-msg-bubble--assistant .ai-orch-msg-text {
    line-height: 1.65;
}

.ai-chat-msg-footer {
    margin-top: 0.5rem;
}

.ai-chat-agent-open {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    font-size: 0.8125rem;
    color: #2563eb;
    text-decoration: none;
}

.ai-chat-agent-open:hover {
    text-decoration: underline;
}

.ai-chat-turn-avatar {
    width: 1.75rem;
    height: 1.75rem;
    border-radius: 50%;
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(145deg, #6366f1 0%, #4f46e5 100%);
    color: #fff;
    font-size: 0.8rem;
    box-shadow: none;
    margin-top: 1.5rem;
    opacity: 0.9;
}

.ai-orch-thinking {
    font-style: italic;
}

.ai-orch-thinking::after {
    content: '...';
    display: inline-block;
    animation: ai-orch-dots 1.4s infinite;
}

@keyframes ai-orch-dots {
    0%, 20% { content: '.'; }
    40% { content: '..'; }
    60%, 100% { content: '...'; }
}

[dir="rtl"] .ai-chat-turn--user {
    justify-content: flex-end;
}

[dir="rtl"] .ai-chat-turn-stack,
[dir="rtl"] .ai-chat-turn-body {
    align-items: flex-end;
}

[dir="rtl"] .ai-chat-msg-text {
    text-align: start;
}

/* Floating ChatGPT-style composer */
.ai-chat-composer-dock {
    position: sticky;
    bottom: 0;
    padding: 0.5rem 0 1rem;
}

.ai-chat-composer-dock .ai-chat-composer-inner {
    padding-bottom: 0;
}

.ai-chat-composer-shell {
    display: flex;
    align-items: flex-end;
    gap: 0.5rem;
    width: 100%;
    padding: 0.65rem 0.65rem 0.65rem 1rem;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 24px;
    box-shadow:
        0 4px 24px rgba(15, 23, 42, 0.08),
        0 1px 3px rgba(15, 23, 42, 0.05);
}

.ai-chat-composer-textarea {
    flex: 1 1 auto;
    min-width: 0;
    border: 0;
    outline: none;
    resize: none;
    background: transparent;
    min-height: 1.5rem;
    max-height: 160px;
    overflow-y: auto;
    line-height: 1.5;
    font-size: 0.9375rem;
    color: #1e293b;
    padding: 0.3rem 0;
    margin: 0;
    field-sizing: content;
}

.ai-chat-composer-textarea::placeholder {
    color: #94a3b8;
}

.ai-chat-composer-textarea:focus {
    outline: none;
    box-shadow: none;
}

.ai-chat-composer-send {
    width: 2.25rem;
    height: 2.25rem;
    min-width: 2.25rem;
    border-radius: 50%;
    border: 0;
    background: #2563eb;
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 1rem;
    line-height: 1;
    transition: background 0.15s ease, opacity 0.15s ease, transform 0.1s ease;
}

.ai-chat-composer-send:not(:disabled):hover {
    background: #1d4ed8;
}

.ai-chat-composer-send:not(:disabled):active {
    transform: scale(0.96);
}

.ai-chat-composer-send:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.ai-orch-page .ai-orch-messages,
.ai-chat-shell-embedded__chat .ai-orch-messages {
    scroll-padding-bottom: 1.5rem;
}

.ai-orch-page .ai-orch-messages .ai-chat-thread,
.ai-chat-shell-embedded__chat .ai-orch-messages .ai-chat-thread {
    padding-bottom: 0.5rem;
}

/* Shared Marvella One hero */
.ai-orch-card {
    background: var(--ai-chat-surface);
}

.ai-orch-messages {
    min-height: 12rem;
}

.ai-orch-orb {
    width: 84px;
    height: 84px;
    background: linear-gradient(135deg, #6f7bff 0%, #b97cff 100%);
    color: #fff;
    font-size: 36px;
    border-radius: 50%;
    box-shadow: 0 10px 30px rgba(111, 123, 255, 0.35);
}

.ai-orch-orb--indigo {
    background: linear-gradient(135deg, #6366f1 0%, #4338ca 100%);
    box-shadow: 0 10px 30px rgba(99, 102, 241, 0.35);
}

.ai-orch-hero-subtitle {
    max-width: 26rem;
    margin-left: auto;
    margin-right: auto;
}

.ai-orch-msg-text {
    white-space: pre-wrap;
    word-wrap: break-word;
}

/* Embedded shell — toolbar above chat (Project AI, report agents, etc.) */
@media (min-width: 768px) {
    html:has(.ai-chat-shell-embedded),
    body:has(.ai-chat-shell-embedded) {
        overflow: hidden;
        background: var(--ai-chat-surface);
    }

    body:has(.ai-chat-shell-embedded) .container {
        margin-top: 0 !important;
        padding-left: 0.75rem !important;
        padding-right: 0.75rem !important;
        max-width: 100% !important;
        height: calc(100vh - var(--erp-header-height, 110px));
        display: flex;
        flex-direction: column;
        overflow: hidden;
        padding-bottom: 0.5rem;
    }

    body:has(.ai-chat-shell-embedded) .container > h4.mb-3 {
        display: none;
    }
}

.ai-chat-shell-embedded {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    width: 100%;
}

.ai-chat-shell-embedded > .col-12 {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.ai-chat-shell-embedded__top {
    flex: 0 0 auto;
    overflow-y: auto;
    max-height: min(36vh, 300px);
    padding-bottom: 0.5rem;
    scrollbar-width: thin;
    scrollbar-color: #cbd5e1 transparent;
}

.ai-chat-shell-embedded__top::-webkit-scrollbar {
    width: 6px;
}

.ai-chat-shell-embedded__top::-webkit-scrollbar-thumb {
    background-color: #cbd5e1;
    border-radius: 999px;
}

.ai-chat-shell-embedded__chat {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
    z-index: 1;
}

.ai-chat-shell-embedded__chat .ai-orch-card {
    flex: 1;
    min-height: 0;
    height: 100%;
    max-height: 100%;
    display: flex;
    flex-direction: column;
}

.ai-chat-shell-embedded__chat .ai-orch-card > .card-header {
    flex-shrink: 0;
}

.ai-chat-shell-embedded__chat .ai-orch-card > .card-body {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.ai-chat-shell-embedded__chat .ai-orch-messages {
    flex: 1 1 auto;
    min-height: 0;
    max-height: none;
}

.ai-chat-shell-embedded__chat .ai-orch-messages.ai-chat-scroll {
    overflow-y: auto;
}

.ai-chat-shell-embedded__chat .ai-orch-form.ai-chat-composer-dock {
    flex: 0 0 auto;
    flex-shrink: 0;
    z-index: 3;
    background: linear-gradient(180deg, rgba(248, 250, 252, 0) 0%, var(--ai-chat-surface) 32%);
    border: 0;
    box-shadow: none;
}
