/* ── Chat With File — sidebar (ChatGPT-style, RTL) ─────────────────────── */

.chat-with-file .cwf-shell {
    display: flex;
    align-items: stretch;
    gap: 0;
    min-width: 0;
    position: relative;
}

.chat-with-file .cwf-shell__main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    position: relative;
    z-index: 1;
}

.chat-with-file--chatting .cwf-shell {
    --cwf-shell-height: min(calc(100dvh - 5.5rem), 52rem);
    height: var(--cwf-shell-height);
    border: 1px solid var(--surface-border, #e5e7eb);
    border-radius: 1.25rem;
    background: var(--surface, #fff);
    overflow: visible;
    box-shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 8px 24px rgba(15, 23, 42, .06);
}

.chat-with-file--chatting .cwf-shell__main {
    min-height: 0;
    overflow: hidden;
    border-radius: 1.25rem 0 0 1.25rem;
}

.chat-with-file--chatting .cwf-sidebar {
    border-radius: 0 1.25rem 1.25rem 0;
}

/* ── Sidebar panel ─────────────────────────────────────────────────────── */

.chat-with-file .cwf-sidebar {
    --cwf-sidebar-width: 17.5rem;
    --cwf-sidebar-collapsed: 3.25rem;
    flex-shrink: 0;
    width: var(--cwf-sidebar-width);
    display: flex;
    flex-direction: column;
    border-inline-start: 1px solid var(--surface-border, #e5e7eb);
    background: var(--surface-alt, #f9fafb);
    transition: width .22s ease, transform .22s ease;
    overflow: visible;
    min-height: 0;
    position: relative;
    z-index: 30;
    isolation: isolate;
}

.chat-with-file--chatting .cwf-sidebar {
    border-inline-start: 0;
    border-inline-end: 1px solid var(--surface-border, #e5e7eb);
}

.chat-with-file .cwf-sidebar--collapsed {
    width: var(--cwf-sidebar-collapsed);
}

.chat-with-file .cwf-sidebar__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .5rem;
    padding: .65rem .65rem .45rem;
    flex-shrink: 0;
}

.chat-with-file .cwf-sidebar--collapsed .cwf-sidebar__head {
    justify-content: center;
    padding-inline: .45rem;
}

.chat-with-file .cwf-sidebar__brand {
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    font-size: .88rem;
    font-weight: 600;
    color: var(--text, #111827);
    min-width: 0;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.chat-with-file .cwf-sidebar__brand i {
    color: var(--brand, #6366f1);
    font-size: 1rem;
}

.chat-with-file .cwf-sidebar__icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.15rem;
    height: 2.15rem;
    padding: 0;
    border: 0;
    border-radius: .55rem;
    background: transparent;
    color: var(--text-muted, #6b7280);
    cursor: pointer;
    flex-shrink: 0;
    transition: background .15s ease, color .15s ease;
}

.chat-with-file .cwf-sidebar__icon-btn:hover {
    background: rgba(15, 23, 42, .06);
    color: var(--text, #111827);
}

.chat-with-file .cwf-sidebar__icon-btn svg {
    width: 1.15rem;
    height: 1.15rem;
    display: block;
}

.chat-with-file .cwf-sidebar__top-actions {
    display: flex;
    flex-direction: column;
    gap: .35rem;
    padding: 0 .65rem .55rem;
    flex-shrink: 0;
}

.chat-with-file .cwf-sidebar--collapsed .cwf-sidebar__top-actions {
    padding-inline: .45rem;
    align-items: center;
}

.chat-with-file .cwf-sidebar__new-chat {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .5rem;
    width: 100%;
    padding: .55rem .75rem;
    border: 1px solid var(--surface-border, #d1d5db);
    border-radius: .75rem;
    background: var(--surface, #fff);
    color: var(--text, #111827);
    font-size: .86rem;
    font-weight: 500;
    cursor: pointer;
    transition: border-color .15s ease, background .15s ease, box-shadow .15s ease;
}

.chat-with-file .cwf-sidebar__new-chat:hover {
    border-color: var(--brand, #6366f1);
    background: rgba(99, 102, 241, .04);
    box-shadow: 0 1px 3px rgba(15, 23, 42, .06);
}

.chat-with-file .cwf-sidebar--collapsed .cwf-sidebar__new-chat {
    width: 2.15rem;
    height: 2.15rem;
    padding: 0;
    border-radius: .55rem;
}

.chat-with-file .cwf-sidebar--collapsed .cwf-sidebar__new-chat span,
.chat-with-file .cwf-sidebar--collapsed .cwf-sidebar__search,
.chat-with-file .cwf-sidebar--collapsed .cwf-sidebar__section-title,
.chat-with-file .cwf-sidebar--collapsed .cwf-sidebar__nav-label,
.chat-with-file .cwf-sidebar--collapsed .cwf-sidebar__empty,
.chat-with-file .cwf-sidebar--collapsed .cwf-nav-item__delete {
    display: none !important;
}

.chat-with-file .cwf-sidebar__search {
    position: relative;
    padding: 0 .65rem .55rem;
    flex-shrink: 0;
}

.chat-with-file .cwf-sidebar__search i {
    position: absolute;
    inset-inline-start: 1.15rem;
    top: 50%;
    transform: translateY(-50%);
    font-size: .82rem;
    color: var(--text-muted, #9ca3af);
    pointer-events: none;
}

.chat-with-file .cwf-sidebar__search-input {
    width: 100%;
    padding: .48rem .65rem .48rem 2rem;
    border: 1px solid transparent;
    border-radius: .65rem;
    background: rgba(15, 23, 42, .04);
    color: var(--text, #111827);
    font-size: .82rem;
    outline: 0;
    transition: border-color .15s ease, background .15s ease;
}

.chat-with-file .cwf-sidebar__search-input::placeholder {
    color: var(--text-muted, #9ca3af);
}

.chat-with-file .cwf-sidebar__search-input:focus {
    border-color: rgba(99, 102, 241, .35);
    background: var(--surface, #fff);
}

.chat-with-file .cwf-sidebar__scroll {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 0 .45rem .65rem;
    min-height: 0;
}

.chat-with-file .cwf-sidebar:has(.cwf-nav-item--menu-open) .cwf-sidebar__scroll {
    overflow: visible;
}

.chat-with-file .cwf-nav-item--menu-open {
    position: relative;
    z-index: 50;
}

.chat-with-file .cwf-sidebar__section {
    margin-bottom: .85rem;
}

.chat-with-file .cwf-sidebar__section-title {
    margin: 0 0 .35rem;
    padding: .25rem .55rem;
    font-size: .72rem;
    font-weight: 600;
    letter-spacing: .02em;
    color: var(--text-muted, #9ca3af);
    text-transform: none;
}

.chat-with-file .cwf-sidebar__nav {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: .15rem;
}

.chat-with-file .cwf-nav-item {
    display: flex;
    align-items: center;
    gap: .15rem;
    min-width: 0;
}

.chat-with-file .cwf-nav-item__btn {
    flex: 1;
    display: flex;
    align-items: center;
    gap: .55rem;
    min-width: 0;
    padding: .52rem .65rem;
    border: 0;
    border-radius: .65rem;
    background: transparent;
    color: var(--text, #111827);
    font-size: .84rem;
    text-align: start;
    cursor: pointer;
    transition: background .15s ease, color .15s ease;
}

.chat-with-file .cwf-nav-item__btn:hover {
    background: rgba(15, 23, 42, .06);
}

.chat-with-file .cwf-nav-item__btn--disabled {
    cursor: default;
    opacity: .55;
}

.chat-with-file .cwf-nav-item__btn--disabled:hover {
    background: transparent;
}

.chat-with-file .cwf-nav-item--active .cwf-nav-item__btn {
    background: rgba(99, 102, 241, .12);
    color: var(--brand, #4f46e5);
    font-weight: 600;
}

.chat-with-file .cwf-nav-item__icon {
    flex-shrink: 0;
    font-size: .95rem;
    color: var(--text-muted, #6b7280);
}

.chat-with-file .cwf-nav-item--active .cwf-nav-item__icon {
    color: var(--brand, #6366f1);
}

.chat-with-file .cwf-nav-item__label {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    line-height: 1.45;
}

.chat-with-file .cwf-nav-item__delete {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.85rem;
    height: 1.85rem;
    padding: 0;
    border: 0;
    border-radius: .45rem;
    background: transparent;
    color: var(--text-muted, #9ca3af);
    cursor: pointer;
    opacity: 0;
    flex-shrink: 0;
    transition: opacity .15s ease, background .15s ease, color .15s ease;
}

.chat-with-file .cwf-nav-item__menu-wrap {
    position: relative;
    flex-shrink: 0;
}

.chat-with-file .cwf-nav-item__menu-trigger {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.85rem;
    height: 1.85rem;
    padding: 0;
    border: 0;
    border-radius: .45rem;
    background: transparent;
    color: var(--text-muted, #9ca3af);
    cursor: pointer;
    opacity: 0;
    transition: opacity .15s ease, background .15s ease, color .15s ease;
}

.chat-with-file .cwf-nav-item:hover .cwf-nav-item__menu-trigger,
.chat-with-file .cwf-nav-item:focus-within .cwf-nav-item__menu-trigger,
.chat-with-file .cwf-nav-item--menu-open .cwf-nav-item__menu-trigger {
    opacity: 1;
}

.chat-with-file .cwf-nav-item__menu-trigger:hover {
    background: rgba(15, 23, 42, .06);
    color: var(--text, #111827);
}

.chat-with-file .cwf-nav-item__menu {
    position: absolute;
    inset-inline-end: 0;
    inset-inline-start: auto;
    top: calc(100% + .25rem);
    z-index: 100;
    min-width: 9.5rem;
    padding: .35rem;
    border: 1px solid var(--surface-border, #e5e7eb);
    border-radius: .75rem;
    background: var(--surface, #fff);
    box-shadow: 0 8px 24px rgba(15, 23, 42, .12);
}

.chat-with-file .cwf-nav-item__menu-action {
    display: flex;
    align-items: center;
    gap: .55rem;
    width: 100%;
    padding: .5rem .65rem;
    border: 0;
    border-radius: .5rem;
    background: transparent;
    color: var(--text, #111827);
    font-size: .84rem;
    text-align: start;
    cursor: pointer;
    transition: background .15s ease, color .15s ease;
}

.chat-with-file .cwf-nav-item__menu-action:hover {
    background: rgba(15, 23, 42, .06);
}

.chat-with-file .cwf-nav-item__menu-action--danger {
    color: #dc3545;
}

.chat-with-file .cwf-nav-item__menu-action--danger:hover {
    background: rgba(220, 53, 69, .08);
    color: #b02a37;
}

.chat-with-file .cwf-nav-item__menu-action i {
    font-size: .95rem;
    width: 1rem;
    text-align: center;
}

.chat-with-file .cwf-nav-item__rename-form {
    flex: 1;
    min-width: 0;
}

.chat-with-file .cwf-nav-item__rename-input {
    width: 100%;
    padding: .48rem .65rem;
    border: 1px solid var(--brand, #6366f1);
    border-radius: .65rem;
    background: var(--surface, #fff);
    color: var(--text, #111827);
    font-size: .84rem;
    outline: 0;
    box-shadow: 0 0 0 3px rgba(99, 102, 241, .12);
}

.chat-with-file .cwf-sidebar__menu-dismiss {
    position: absolute;
    inset: 0;
    z-index: 15;
    border: 0;
    background: transparent;
    cursor: default;
}

.chat-with-file .cwf-nav-item:hover .cwf-nav-item__delete,
.chat-with-file .cwf-nav-item:focus-within .cwf-nav-item__delete {
    opacity: 1;
}

.chat-with-file .cwf-nav-item__delete:hover {
    background: rgba(220, 53, 69, .1);
    color: #dc3545;
}

.chat-with-file .cwf-sidebar__empty {
    margin: 0;
    padding: .45rem .65rem;
    font-size: .78rem;
    color: var(--text-muted, #9ca3af);
    line-height: 1.65;
}

.chat-with-file .cwf-sidebar__backdrop {
    display: none;
}

/* ── Chat header toggle (when sidebar collapsed) ─────────────────────────── */

.chat-with-file .cwf-chat__sidebar-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.15rem;
    height: 2.15rem;
    padding: 0;
    border: 1px solid var(--surface-border, #e5e7eb);
    border-radius: .55rem;
    background: transparent;
    color: var(--text-muted, #6b7280);
    cursor: pointer;
    flex-shrink: 0;
    transition: border-color .15s ease, color .15s ease, background .15s ease;
}

.chat-with-file .cwf-chat__sidebar-toggle:hover {
    border-color: var(--brand, #6366f1);
    color: var(--brand, #6366f1);
    background: rgba(99, 102, 241, .05);
}

.chat-with-file .cwf-chat__sidebar-toggle svg {
    width: 1.15rem;
    height: 1.15rem;
}

.chat-with-file:not(.chat-with-file--sidebar-collapsed) .cwf-chat__sidebar-toggle {
    display: none;
}

/* ── Chat panel inside shell ───────────────────────────────────────────── */

.chat-with-file--chatting .cwf-chat {
    height: 100%;
    min-height: 0;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    overflow: hidden;
}

.chat-with-file .cwf-mobile-menu-btn {
    display: none;
}

/* ── Mobile drawer ─────────────────────────────────────────────────────── */

@media (max-width: 991.98px) {
    .chat-with-file .cwf-mobile-menu-btn {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 2.15rem;
        height: 2.15rem;
        padding: 0;
        border: 1px solid var(--surface-border, #e5e7eb);
        border-radius: .55rem;
        background: transparent;
        color: var(--text-muted, #6b7280);
        cursor: pointer;
        flex-shrink: 0;
        margin-inline-end: .5rem;
    }

    .chat-with-file .cwf-mobile-menu-btn:hover {
        border-color: var(--brand, #6366f1);
        color: var(--brand, #6366f1);
        background: rgba(99, 102, 241, .05);
    }

    .chat-with-file .cwf-mobile-menu-btn svg {
        width: 1.15rem;
        height: 1.15rem;
    }

    .chat-with-file .cwf-shell {
        position: relative;
    }

    .chat-with-file .cwf-sidebar {
        position: absolute;
        inset-block: 0;
        inset-inline-start: 0;
        z-index: 30;
        width: min(var(--cwf-sidebar-width), 88vw);
        transform: translateX(100%);
        box-shadow: -8px 0 32px rgba(15, 23, 42, .12);
    }

    .chat-with-file .cwf-sidebar--mobile-open {
        transform: translateX(0);
    }

    .chat-with-file .cwf-sidebar--collapsed:not(.cwf-sidebar--mobile-open) {
        width: min(var(--cwf-sidebar-width), 88vw);
        transform: translateX(100%);
    }

    .chat-with-file .cwf-sidebar--mobile-open.cwf-sidebar--collapsed {
        width: min(var(--cwf-sidebar-width), 88vw);
    }

    .chat-with-file .cwf-sidebar__backdrop {
        display: block;
        position: absolute;
        inset: 0;
        z-index: 25;
        border: 0;
        background: rgba(15, 23, 42, .35);
        cursor: pointer;
    }

    .chat-with-file .cwf-chat__sidebar-toggle {
        display: inline-flex !important;
    }

    .chat-with-file--chatting .cwf-shell {
        --cwf-shell-height: min(calc(100dvh - 4.5rem), 52rem);
    }
}

@media (max-width: 767.98px) {
    .chat-with-file--chatting .cwf-shell {
        border-radius: .85rem;
    }
}
