/* ── Chat With File — گفتگو (ChatGPT-style surface) ───────────────────────── */

.chat-with-file--chatting .ut-page-header,
.chat-with-file--chatting .ut-phase-stepper,
.chat-with-file--chatting .cwf-mobile-menu-btn {
    display: none;
}

.chat-with-file--chatting .cwf-shell__main > .ut-alerts {
    margin: .65rem .75rem 0;
}

.chat-with-file .cwf-chat {
    --cwf-chat-max: 46rem;
    --cwf-composer-radius: 1.75rem;
    --cwf-send-size: 2.25rem;
    display: flex;
    flex-direction: column;
    min-height: min(78dvh, 52rem);
    height: min(78dvh, 52rem);
    border: 1px solid var(--surface-border, #e5e7eb);
    border-radius: 1.25rem;
    background: var(--surface, #fff);
    overflow: hidden;
    box-shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 8px 24px rgba(15, 23, 42, .06);
    position: relative;
}

/* ── Header ─────────────────────────────────────────────────────────────── */

.chat-with-file .cwf-chat__header {
    display: flex;
    align-items: center;
    gap: .65rem;
    flex-wrap: wrap;
    padding: .7rem 1rem;
    border-bottom: 1px solid var(--surface-border, #e5e7eb);
    background: var(--surface, #fff);
    flex-shrink: 0;
}

.chat-with-file .cwf-chat__back {
    display: inline-flex;
    align-items: center;
    gap: .35rem;
    padding: .35rem .65rem;
    border: 1px solid var(--surface-border, #e5e7eb);
    border-radius: 999px;
    background: transparent;
    color: var(--text-muted, #6b7280);
    font-size: .82rem;
    cursor: pointer;
    transition: border-color .15s ease, color .15s ease, background .15s ease;
}

.chat-with-file .cwf-chat__back:hover {
    border-color: var(--brand, #6366f1);
    color: var(--brand, #6366f1);
    background: rgba(99, 102, 241, .05);
}

.chat-with-file .cwf-chat__title {
    font-size: .95rem;
    font-weight: 600;
    margin: 0;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chat-with-file .cwf-chat__docs {
    display: flex;
    gap: .35rem;
    flex-wrap: wrap;
    margin-inline-start: auto;
    min-width: 0;
}

.chat-with-file .cwf-chat__docs .badge {
    border: 1px solid var(--surface-border, #e5e7eb);
    font-weight: 500;
    font-size: .72rem;
    max-width: 14rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ── Message thread ─────────────────────────────────────────────────────── */

.chat-with-file .cwf-chat__body {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    scroll-behavior: smooth;
    background: linear-gradient(180deg, var(--surface, #fff) 0%, var(--surface-alt, #fafafa) 100%);
}

.chat-with-file .cwf-chat__thread {
    width: 100%;
    max-width: var(--cwf-chat-max);
    margin: 0 auto;
    padding: 1.25rem 1rem 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1.1rem;
}

.chat-with-file .cwf-chat__greeting {
    margin: auto;
    text-align: center;
    padding: 2.5rem 1rem;
    color: var(--text-muted, #6b7280);
}

.chat-with-file .cwf-chat__greeting p {
    margin: 0;
    font-size: 1.05rem;
    font-weight: 500;
    color: var(--text, #111827);
}

.chat-with-file .cwf-chat__greeting span {
    display: block;
    margin-top: .45rem;
    font-size: .85rem;
}

/* ── Messages ───────────────────────────────────────────────────────────── */

.chat-with-file .cwf-msg {
    display: flex;
    width: 100%;
}

.chat-with-file .cwf-msg--user {
    justify-content: flex-start;
}

.chat-with-file .cwf-msg--assistant {
    justify-content: flex-end;
}

.chat-with-file .cwf-msg__bubble {
    max-width: min(38rem, 92%);
    padding: .75rem 1rem;
    border-radius: 1.25rem;
    font-size: .95rem;
    line-height: 1.85;
    white-space: pre-wrap;
    word-break: break-word;
}

.chat-with-file .cwf-msg--user .cwf-msg__bubble {
    background: var(--brand, #6366f1);
    color: #fff;
    border-end-start-radius: .35rem;
    box-shadow: 0 2px 8px rgba(99, 102, 241, .22);
}

.chat-with-file .cwf-msg--assistant .cwf-msg__bubble {
    background: transparent;
    color: var(--text, #111827);
    max-width: 100%;
    padding: .35rem 0;
    border-radius: 0;
}

.chat-with-file .cwf-msg__thinking {
    display: flex;
    align-items: center;
    gap: .45rem;
    margin: 0 0 .25rem;
    font-size: .82rem;
    color: var(--text-muted, #6b7280);
}

.chat-with-file .cwf-msg__footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .5rem;
    flex-wrap: wrap;
    margin-top: .15rem;
    min-width: 0;
}

.chat-with-file .cwf-msg__actions {
    display: flex;
    align-items: center;
    gap: .15rem;
    opacity: .5;
    transition: opacity .15s ease;
}

.chat-with-file .cwf-sources-wrap {
    position: relative;
    flex-shrink: 1;
    min-width: 0;
    margin-inline-start: auto;
}

.chat-with-file .cwf-sources-pill {
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    max-width: min(18rem, 100%);
    padding: .35rem .65rem;
    border: 1px solid rgba(99, 102, 241, .28);
    border-radius: 999px;
    background: var(--surface-alt, #f9fafb);
    color: var(--brand, #4f46e5);
    font-size: .76rem;
    font-weight: 600;
    line-height: 1.4;
    cursor: pointer;
    transition: border-color .15s ease, background .15s ease, box-shadow .15s ease;
}

.chat-with-file .cwf-sources-pill:hover,
.chat-with-file .cwf-sources-pill--open {
    border-color: rgba(99, 102, 241, .45);
    background: rgba(99, 102, 241, .08);
    box-shadow: 0 1px 3px rgba(99, 102, 241, .12);
}

.chat-with-file .cwf-sources-pill__icons {
    display: inline-flex;
    align-items: center;
    gap: .1rem;
    flex-shrink: 0;
}

.chat-with-file .cwf-sources-pill__icons i {
    font-size: .9rem;
    line-height: 1;
}

.chat-with-file .cwf-sources-pill__label {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
}

.chat-with-file .cwf-sources-pill__caret {
    font-size: .7rem;
    opacity: .75;
    flex-shrink: 0;
    transition: transform .15s ease;
}

.chat-with-file .cwf-sources-pill--open .cwf-sources-pill__caret {
    transform: rotate(180deg);
}

.chat-with-file .cwf-sources-popover-dismiss {
    position: absolute;
    inset: 0;
    z-index: 60;
    border: 0;
    background: transparent;
    cursor: default;
}

.chat-with-file .cwf-sources-popover {
    position: absolute;
    inset-inline-end: 0;
    bottom: calc(100% + .45rem);
    z-index: 70;
    width: min(22rem, calc(100vw - 2rem));
    max-height: min(40vh, 16rem);
    display: flex;
    flex-direction: column;
    border: 1px solid var(--surface-border, #e5e7eb);
    border-radius: .85rem;
    background: var(--surface, #fff);
    box-shadow: 0 12px 40px rgba(15, 23, 42, .15);
    overflow: hidden;
}

.chat-with-file .cwf-sources-popover__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .5rem;
    padding: .65rem .75rem;
    border-bottom: 1px solid var(--surface-border, #e5e7eb);
    background: var(--surface-alt, #fafafa);
    flex-shrink: 0;
}

.chat-with-file .cwf-sources-popover__title {
    margin: 0;
    font-size: .82rem;
    font-weight: 700;
    color: var(--text, #111827);
}

.chat-with-file .cwf-sources-popover__close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.75rem;
    height: 1.75rem;
    padding: 0;
    border: 0;
    border-radius: .45rem;
    background: transparent;
    color: var(--text-muted, #6b7280);
    cursor: pointer;
}

.chat-with-file .cwf-sources-popover__close:hover {
    background: rgba(15, 23, 42, .06);
    color: var(--text, #111827);
}

.chat-with-file .cwf-sources-popover__list {
    list-style: none;
    margin: 0;
    padding: .45rem;
    overflow-y: auto;
}

.chat-with-file .cwf-sources-popover__item {
    display: flex;
    flex-direction: column;
    gap: .2rem;
    padding: .55rem .6rem;
    border-radius: .55rem;
    transition: background .15s ease;
}

.chat-with-file .cwf-sources-popover__item + .cwf-sources-popover__item {
    margin-top: .15rem;
}

.chat-with-file .cwf-sources-popover__item:hover {
    background: rgba(99, 102, 241, .06);
}

.chat-with-file .cwf-sources-popover__file {
    display: flex;
    align-items: flex-start;
    gap: .45rem;
    min-width: 0;
    color: var(--text, #111827);
    font-size: .82rem;
    font-weight: 600;
    line-height: 1.55;
}

.chat-with-file .cwf-sources-popover__file i {
    flex-shrink: 0;
    margin-top: .15rem;
    color: var(--brand, #6366f1);
}

.chat-with-file .cwf-sources-popover__filename {
    word-break: break-word;
}

.chat-with-file .cwf-sources-popover__pages {
    padding-inline-start: 1.35rem;
    font-size: .78rem;
    color: var(--text-muted, #6b7280);
    line-height: 1.5;
}

.chat-with-file .cwf-msg__stack {
    display: flex;
    flex-direction: column;
    gap: .35rem;
    width: 100%;
    max-width: min(38rem, 92%);
}

.chat-with-file .cwf-msg--assistant .cwf-msg__stack {
    max-width: 100%;
}

@media (hover: hover) {
    .chat-with-file .cwf-msg__actions {
        opacity: 0;
    }

    .chat-with-file .cwf-msg--assistant:hover .cwf-msg__actions,
    .chat-with-file .cwf-msg__actions:focus-within {
        opacity: 1;
    }
}

.chat-with-file .cwf-msg--assistant:has(.cwf-msg__action--active) .cwf-msg__actions {
    opacity: 1;
}

.chat-with-file .cwf-msg--assistant:has(.cwf-sources-pill--open) .cwf-msg__actions {
    opacity: 1;
}

.chat-with-file .cwf-msg__action {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    border: 0;
    border-radius: .5rem;
    background: transparent;
    color: var(--text-muted, #9ca3af);
    cursor: pointer;
    transition: background .15s ease, color .15s ease;
}

.chat-with-file .cwf-msg__action:hover {
    background: rgba(15, 23, 42, .06);
    color: var(--text, #111827);
}

.chat-with-file .cwf-msg__action--active {
    color: var(--brand, #6366f1);
    background: rgba(99, 102, 241, .1);
}

.chat-with-file .cwf-msg__action--copied {
    color: #16a34a;
}

.chat-with-file .cwf-msg__action i {
    font-size: 1rem;
    line-height: 1;
}

.chat-with-file .cwf-caret {
    display: inline-block;
    width: 2px;
    height: 1em;
    margin-inline-start: 2px;
    background: currentColor;
    vertical-align: text-bottom;
    animation: cwf-caret-blink 1s steps(1) infinite;
}

@keyframes cwf-caret-blink {
    50% { opacity: 0; }
}

/* ── Composer (ChatGPT-style pill) ─────────────────────────────────────── */

.chat-with-file .cwf-chat__footer {
    flex-shrink: 0;
    padding: .75rem 1rem 1rem;
    border-top: 1px solid var(--surface-border, #e5e7eb);
    background: var(--surface, #fff);
}

.chat-with-file .cwf-composer {
    width: 100%;
    max-width: var(--cwf-chat-max);
    margin: 0 auto;
}

.chat-with-file .cwf-composer__shell {
    position: relative;
    display: flex;
    align-items: flex-end;
    border: 1px solid var(--surface-border, #d1d5db);
    border-radius: var(--cwf-composer-radius);
    background: var(--surface-alt, #f9fafb);
    box-shadow: 0 1px 2px rgba(15, 23, 42, .05);
    transition: border-color .15s ease, box-shadow .15s ease;
}

.chat-with-file .cwf-composer__shell:focus-within {
    border-color: rgba(99, 102, 241, .45);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, .12);
    background: var(--surface, #fff);
}

.chat-with-file .cwf-composer__input {
    flex: 1;
    width: 100%;
    min-height: 3.25rem;
    max-height: 11rem;
    margin: 0;
    padding: .85rem 1rem;
    /* فضای دکمهٔ ارسال — متن زیر دکمه نرود */
    padding-inline-end: calc(var(--cwf-send-size) + 1.35rem);
    border: 0;
    outline: 0;
    resize: none;
    background: transparent;
    color: var(--text, #111827);
    font-size: .95rem;
    line-height: 1.6;
    field-sizing: content;
    overflow-y: auto;
}

.chat-with-file .cwf-composer__input::placeholder {
    color: var(--text-muted, #9ca3af);
}

.chat-with-file .cwf-composer__input:disabled {
    opacity: .65;
    cursor: not-allowed;
}

.chat-with-file .cwf-composer__send {
    position: absolute;
    inset-inline-end: .55rem;
    inset-block-end: .55rem;
    width: var(--cwf-send-size);
    height: var(--cwf-send-size);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 0;
    border-radius: 50%;
    padding: 0;
    background: var(--surface-border, #e5e7eb);
    color: var(--text-muted, #9ca3af);
    cursor: not-allowed;
    transition: background .15s ease, color .15s ease, transform .1s ease;
}

.chat-with-file .cwf-composer__send--active {
    background: var(--text, #111827);
    color: #fff;
    cursor: pointer;
}

.chat-with-file .cwf-composer__send--active:hover {
    background: var(--brand, #6366f1);
}

.chat-with-file .cwf-composer__send--active:active {
    transform: scale(.96);
}

.chat-with-file .cwf-composer__send:disabled {
    opacity: 1;
}

.chat-with-file .cwf-composer__send i {
    font-size: 1.05rem;
    line-height: 1;
}

.chat-with-file .cwf-composer__send .spinner-border {
    width: 1rem;
    height: 1rem;
    border-width: 2px;
}

.chat-with-file .cwf-composer__meta {
    margin: .45rem .25rem 0;
    text-align: center;
    font-size: .75rem;
    color: var(--text-muted, #9ca3af);
}

/* ── Responsive ─────────────────────────────────────────────────────────── */

@media (max-width: 768px) {
    .chat-with-file .cwf-chat {
        min-height: 72dvh;
        height: 72dvh;
        border-radius: .85rem;
    }

    .chat-with-file .cwf-msg__bubble {
        max-width: 96%;
    }

    .chat-with-file .cwf-chat__docs {
        margin-inline-start: 0;
        width: 100%;
    }

    .chat-with-file .cwf-chat__footer {
        padding-inline: .65rem;
    }
}

/* ── Dislike feedback modal ──────────────────────────────────────────────── */

.chat-with-file .cwf-feedback-modal {
    position: fixed;
    inset: 0;
    z-index: 1080;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.chat-with-file .cwf-feedback-modal__backdrop {
    position: absolute;
    inset: 0;
    border: 0;
    background: rgba(15, 23, 42, .45);
    cursor: pointer;
}

.chat-with-file .cwf-feedback-modal__panel {
    position: relative;
    width: min(32rem, 100%);
    border-radius: 1rem;
    background: var(--surface, #fff);
    border: 1px solid var(--surface-border, #e5e7eb);
    box-shadow: 0 16px 48px rgba(15, 23, 42, .18);
    padding: 1.1rem 1.15rem 1rem;
}

.chat-with-file .cwf-feedback-modal__title {
    margin: 0 0 .35rem;
    font-size: 1.05rem;
    font-weight: 700;
}

.chat-with-file .cwf-feedback-modal__lead {
    margin: 0 0 .85rem;
    font-size: .86rem;
    color: var(--text-muted, #6b7280);
    line-height: 1.7;
}

.chat-with-file .cwf-feedback-modal__chips {
    display: flex;
    flex-wrap: wrap;
    gap: .45rem;
    margin-bottom: .85rem;
}

.chat-with-file .cwf-feedback-chip {
    border: 1px solid var(--surface-border, #d1d5db);
    border-radius: 999px;
    background: var(--surface-alt, #f9fafb);
    color: var(--text, #111827);
    font-size: .82rem;
    padding: .35rem .75rem;
    cursor: pointer;
    transition: border-color .15s ease, background .15s ease, color .15s ease;
}

.chat-with-file .cwf-feedback-chip:hover {
    border-color: var(--brand, #6366f1);
}

.chat-with-file .cwf-feedback-chip--active {
    border-color: var(--brand, #6366f1);
    background: rgba(99, 102, 241, .1);
    color: var(--brand, #4f46e5);
}

.chat-with-file .cwf-feedback-modal__input {
    resize: vertical;
    min-height: 6.5rem;
    margin-bottom: .9rem;
}

.chat-with-file .cwf-feedback-modal__actions {
    display: flex;
    justify-content: flex-end;
    gap: .5rem;
}
