/**
 * غلاف تطبيق الشات — /app/chat
 */
:root {
    --app-chat-bar-height: 52px;
    --app-chat-pad-x: 8px;
    --app-chat-chrome-est: 200px;
}

html:has(body.mt-app-chat-shell) {
    height: 100%;
}

body.mt-app-chat-shell {
    margin: 0;
    overflow: hidden;
    height: 100dvh;
    background: #0a0f0c;
}

body.mt-app-chat-shell #reading-progress,
body.mt-app-chat-shell .notice-bar {
    display: none !important;
}

.mt-app-chat-topbar {
    position: sticky;
    top: 0;
    z-index: 1200;
    height: var(--app-chat-bar-height);
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 12px;
    background: rgba(10, 15, 12, 0.92);
    border-bottom: 1px solid rgba(82, 183, 136, 0.28);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}

.mt-app-chat-topbar__brand {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    flex: 1;
    text-decoration: none;
    color: #e8f5e9;
}

.mt-app-chat-topbar__brand strong {
    font-size: 0.95rem;
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.mt-app-chat-topbar__actions {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

.mt-app-chat-topbar__btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 36px;
    padding: 0 12px;
    border-radius: 10px;
    border: 1px solid rgba(183, 228, 199, 0.35);
    background: rgba(255, 255, 255, 0.08);
    color: #e8f5e9;
    font-family: inherit;
    font-size: 0.82rem;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease;
}

.mt-app-chat-topbar__btn:hover,
.mt-app-chat-topbar__btn:focus-visible {
    background: rgba(45, 106, 79, 0.85);
    border-color: rgba(82, 183, 136, 0.6);
    color: #fff;
}

.mt-app-chat-topbar__btn--accent {
    background: linear-gradient(135deg, #2d6a4f, #40916c);
    border-color: transparent;
    color: #fff;
}

.mt-app-chat-topbar__btn--icon {
    width: 36px;
    padding: 0;
}

.mt-app-chat-topbar__btn[hidden] {
    display: none !important;
}

.mt-app-chat-main {
    display: flex;
    flex-direction: column;
    height: calc(100dvh - var(--app-chat-bar-height));
    min-height: 0;
    overflow: hidden;
}

.mt-app-chat-alert {
    margin: 10px 12px 0;
    padding: 12px 14px;
    border-radius: 10px;
    background: #fef3c7;
    border: 1px solid #f59e0b;
    color: #92400e;
    font-size: 0.9rem;
}

.ai-chat-section--app {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    min-height: 0;
    height: 100%;
    padding: 4px 0;
    overflow: hidden;
}

.ai-chat-section--app .ai-chat-section__bg {
    position: fixed;
    top: var(--app-chat-bar-height);
    left: 0;
    width: 100%;
    height: calc(100dvh - var(--app-chat-bar-height));
    object-fit: cover;
    object-position: center;
    z-index: 0;
}

.ai-chat-section--app .ai-chat-section__overlay {
    position: fixed;
    top: var(--app-chat-bar-height);
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1;
    pointer-events: none;
}

.ai-chat-section--app .ai-chat-section__inner {
    position: relative;
    z-index: 2;
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: 720px;
    margin-inline: auto;
    padding-inline: var(--app-chat-pad-x);
    min-height: 0;
    height: 100%;
    box-sizing: border-box;
}

.ai-chat-section--app .tayibat-live-chat-wrap--app {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    min-height: 0;
    height: 100%;
    max-width: 100%;
    margin: 0;
}

.ai-chat-section--app .tayibat-live-chat-wrap.reveal {
    opacity: 1;
    transform: none;
}

/* ── شبكة التطبيق: الرسائل تأخذ كل المساحة المتبقية ── */
.ai-chat-section--app #ai-chat-container.tayibat-live-chat--app-shell {
    display: grid !important;
    grid-template-columns: 1fr;
    grid-template-rows: auto auto auto minmax(0, 1fr) auto;
    grid-template-areas:
        "head"
        "previews"
        "chips"
        "messages"
        "foot";
    height: 100% !important;
    max-height: 100% !important;
    min-height: 0 !important;
    border-radius: 16px;
    overflow: hidden;
}

.ai-chat-section--app .tayibat-live-chat__head {
    grid-area: head;
    padding: 8px 12px;
    flex-shrink: 0;
}

.ai-chat-section--app .tayibat-live-chat__avatar {
    width: 40px;
    height: 40px;
    font-size: 1.2rem;
}

.ai-chat-section--app .tayibat-live-chat__title {
    font-size: 0.95rem;
}

.ai-chat-section--app .tayibat-live-chat__status {
    font-size: 0.75rem;
}

.ai-chat-section--app .tayibat-lc-vision-previews {
    grid-area: previews;
}

.ai-chat-section--app .tayibat-live-chat__chips {
    grid-area: chips;
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    max-height: 44px;
    padding: 6px 10px;
    gap: 6px;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
}

.ai-chat-section--app .tayibat-lc-chip {
    font-size: 0.76rem;
    padding: 5px 9px;
    flex-shrink: 0;
}

.ai-chat-section--app .tayibat-live-chat--ai .tayibat-live-chat__messages-scene {
    display: none;
}

.ai-chat-section--app .tayibat-live-chat__messages-shell {
    grid-area: messages;
    min-height: 0 !important;
    max-height: none !important;
    height: 100% !important;
    overflow: hidden !important;
    display: flex !important;
    flex-direction: column !important;
    width: 100%;
}

.ai-chat-section--app .tayibat-live-chat--ai .tayibat-live-chat__messages,
.ai-chat-section--app #ai-chat-messages {
    flex: 1 1 auto !important;
    min-height: 0 !important;
    height: 100% !important;
    max-height: none !important;
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
    overflow-x: hidden !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;
    overscroll-behavior: contain;
    padding: 10px 10px 12px;
    word-break: break-word;
    overflow-wrap: anywhere;
}

.ai-chat-section--app .tayibat-lc-msg__bubble--app-welcome {
    font-size: 0.88rem;
    line-height: 1.65;
}

.ai-chat-section--app .tayibat-lc-msg__bubble {
    max-width: min(94%, 100%);
}

.ai-chat-section--app .tayibat-live-chat__foot {
    grid-area: foot;
    flex-shrink: 0;
}

/* إخفاء شريط الأدوات السفلي داخل التطبيق — يوفر مساحة للرسائل */
.ai-chat-section--app .tayibat-live-chat__toolbar {
    display: none !important;
}

/* شريط الإدخال: أدوات أفقية بجانب الحقل (لا عمود جانبي) */
.ai-chat-section--app .tayibat-live-chat--ai .tayibat-live-chat__foot--composer {
    padding: 8px 10px calc(8px + env(safe-area-inset-bottom, 0px)) !important;
    margin: 0 !important;
    border-radius: 0 !important;
}

.ai-chat-section--app .tayibat-live-chat--ai .tayibat-live-chat__composer {
    display: grid !important;
    grid-template-columns: auto 1fr 48px;
    grid-template-areas: "tools input send";
    gap: 8px !important;
    align-items: flex-end !important;
    flex-wrap: nowrap !important;
}

.ai-chat-section--app .tayibat-live-chat--ai .tayibat-live-chat__composer-side {
    grid-area: tools;
    flex-direction: row !important;
    flex-wrap: nowrap;
    gap: 6px !important;
    order: unset !important;
    width: auto !important;
}

.ai-chat-section--app .tayibat-live-chat--ai .tayibat-live-chat__input-wrap {
    grid-area: input;
    order: unset !important;
    flex: none !important;
    min-width: 0;
}

.ai-chat-section--app .tayibat-live-chat--ai .tayibat-lc-send-btn--composer {
    grid-area: send;
    order: unset !important;
    width: 48px !important;
    height: 48px !important;
    min-height: 48px;
    align-self: flex-end;
}

.ai-chat-section--app .tayibat-live-chat--ai .tayibat-lc-neo-btn {
    width: 40px;
    height: 40px;
    min-height: 40px;
}

.ai-chat-section--app .tayibat-live-chat--ai .tayibat-live-chat__input--composer {
    min-height: 44px;
    max-height: 96px;
    font-size: 16px;
}

.ai-chat-section--app .tayibat-live-chat__meta-hint--desk,
.ai-chat-section--app .tayibat-live-chat__meta-hint--mob {
    display: none !important;
}

.ai-chat-section--app .tayibat-live-chat__meta-hint--app-legal {
    display: block;
    font-size: 0.65rem;
    line-height: 1.4;
    color: rgba(183, 228, 199, 0.7);
    text-align: center;
    width: 100%;
}

.ai-chat-section--app .tayibat-live-chat__meta {
    padding-top: 4px;
    justify-content: center;
}

.ai-chat-section--app .ai-chat-section__disclaimer {
    display: none;
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* إلغاء قيود ai-hero-canva على التطبيق */
.ai-chat-section.ai-chat-section--app .tayibat-live-chat--ai .tayibat-live-chat__messages-shell,
.ai-chat-section--app.ai-chat-section .tayibat-live-chat--ai .tayibat-live-chat__messages-shell {
    min-height: 0 !important;
    max-height: none !important;
}

@media (max-width: 640px) {
    .ai-chat-section.ai-chat-section--app .tayibat-live-chat--ai .tayibat-live-chat__messages-shell {
        min-height: 0 !important;
        max-height: none !important;
    }
}

@media (display-mode: standalone) {
    .mt-app-chat-topbar__btn--install {
        display: none !important;
    }
}

@media (max-width: 480px) {
    .mt-app-chat-topbar {
        padding: 0 8px;
    }

    .mt-app-chat-topbar__btn--text-short {
        padding: 0 8px;
        font-size: 0.78rem;
    }

    :root {
        --app-chat-pad-x: 4px;
    }

    .ai-chat-section--app .tayibat-live-chat__head {
        padding: 6px 10px;
    }

    .ai-chat-section--app .tayibat-live-chat__counter {
        font-size: 0.68rem;
        padding: 2px 6px;
    }
}
