/* ——— Kimi-style attachments & file preview ——— */

/* Composer: strip بالای textarea داخل input-wrapper */
.file-preview-area.has-attachments:not(.is-empty) {
    display: block !important;
    width: 100% !important;
    max-width: 100% !important;
    flex: none !important;
    padding: 10px 12px 0 !important;
    margin: 0 !important;
    border: none !important;
    background: transparent !important;
    max-height: none !important;
}

.file-preview-area.has-attachments:not(.is-empty) + .composer-stack,
.composer-stack {
    width: 100%;
}

.composer-main {
    display: block;
    width: 100%;
}

.composer-main > .file-preview-area {
    width: 100%;
}

/* نوار افقی فایل */
.kimi-attach-strip {
    position: relative;
    width: 100%;
    min-width: 0;
    padding-bottom: 8px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.06);
    margin-bottom: 4px;
}

.kimi-attach-strip--chat {
    border-bottom: none;
    margin-bottom: 0;
    padding-bottom: 0;
}

[data-theme="dark"] .kimi-attach-strip {
    border-bottom-color: rgba(255, 255, 255, 0.08);
}

.kimi-attach-strip__viewport {
    width: 100%;
    min-width: 0;
    overflow-x: auto;
    overflow-y: hidden;
    scroll-behavior: smooth;
    scrollbar-width: none;
    -ms-overflow-style: none;
    cursor: grab;
    touch-action: pan-x;
}

.kimi-attach-strip__viewport.is-grabbing {
    cursor: grabbing;
    scroll-behavior: auto;
    user-select: none;
}

.kimi-attach-strip__viewport::-webkit-scrollbar {
    display: none;
}

.kimi-attach-strip__track {
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    gap: 8px;
    width: max-content;
    min-height: 52px;
    padding: 2px 4px;
    align-items: center;
}

/* composer: دکمه‌ها روی لبهٔ نوار */
.kimi-attach-strip--composer .kimi-attach-strip__viewport {
    padding-inline: 34px;
}

.kimi-attach-strip--composer .kimi-attach-strip__nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    z-index: 5;
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 1px solid rgba(0, 0, 0, 0.08);
    background: #fff;
    color: #6b7280;
    cursor: pointer;
    display: grid;
    place-items: center;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    transition: background 0.15s, border-color 0.15s, box-shadow 0.15s;
}

.kimi-attach-strip--composer .kimi-attach-strip__nav--prev {
    inset-inline-start: 2px;
}

.kimi-attach-strip--composer .kimi-attach-strip__nav--next {
    inset-inline-end: 2px;
}

.kimi-attach-strip--composer .kimi-attach-strip__nav:hover:not(:disabled) {
    background: #f9fafb;
    border-color: rgba(0, 0, 0, 0.12);
    color: #111;
    box-shadow: 0 3px 12px rgba(11, 87, 208, 0.12);
}

.kimi-attach-strip--composer .kimi-attach-strip__nav:disabled,
.kimi-attach-strip--composer .kimi-attach-strip__nav[hidden] {
    opacity: 0;
    pointer-events: none;
    visibility: hidden;
}

/* چت: بدون دکمهٔ قبلی/بعدی */
.kimi-attach-strip--chat .kimi-attach-strip__nav {
    display: none !important;
}

.kimi-attach-strip--chat .kimi-attach-strip__viewport {
    padding-inline: 2px;
}

[data-theme="dark"] .kimi-attach-strip--composer .kimi-attach-strip__nav {
    background: #2a2b2c;
    border-color: rgba(255, 255, 255, 0.1);
    color: #9ca3af;
}

/* کارت فایل */
.kimi-file-wrap {
    position: relative;
    flex: 0 0 auto;
}

.kimi-file-card {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 10px;
    min-width: 168px;
    max-width: 220px;
    padding: 10px 12px;
    border-radius: 12px;
    border: 1px solid rgba(0, 0, 0, 0.06);
    background: #f3f4f6;
    cursor: pointer;
    text-align: start;
    color: inherit;
    font: inherit;
    transition: background 0.15s, border-color 0.15s;
}

.kimi-file-card:hover {
    background: #eceef1;
    border-color: rgba(0, 0, 0, 0.1);
}

[data-theme="dark"] .kimi-file-card {
    background: #2a2b2c;
    border-color: rgba(255, 255, 255, 0.08);
}

[data-theme="dark"] .kimi-file-card:hover {
    background: #35363a;
}

.kimi-file-card__icon {
    flex-shrink: 0;
    width: 36px;
    height: 36px;
    border-radius: 8px;
    background: #e5e7eb;
    display: grid;
    place-items: center;
    color: #6b7280;
}

.kimi-file-card__icon svg {
    width: 18px;
    height: 18px;
}

.kimi-file-card__icon--code {
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: -0.04em;
    font-family: ui-monospace, monospace;
}

[data-theme="dark"] .kimi-file-card__icon {
    background: #3d3e42;
    color: #9ca3af;
}

.kimi-file-card--image .kimi-file-card__icon {
    padding: 0;
    overflow: hidden;
    background: #e5e7eb;
}

.kimi-file-card--image .kimi-file-card__icon img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.kimi-file-card__meta {
    min-width: 0;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.kimi-file-card__name {
    font-size: 0.8125rem;
    font-weight: 500;
    color: #111827;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.25;
}

.kimi-file-card__sub {
    font-size: 0.75rem;
    font-weight: 400;
    color: #6b7280;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

[data-theme="dark"] .kimi-file-card__name { color: #f3f4f6; }
[data-theme="dark"] .kimi-file-card__sub { color: #9ca3af; }

.kimi-file-wrap .remove-file-btn {
    top: 2px;
    left: 2px;
    width: 18px;
    height: 18px;
    font-size: 11px;
    background: #fff;
    border-color: rgba(0, 0, 0, 0.1);
    z-index: 2;
}

/* آپلود */
.kimi-file-card--uploading {
    cursor: wait;
    pointer-events: none;
    opacity: 0.92;
}

.kimi-file-card--uploading .kimi-file-card__icon {
    position: relative;
}

.kimi-upload-ring {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    font-size: 0.55rem;
    font-weight: 700;
    color: #4b5563;
}

/* چت: نوار پیوست کاربر */
.chat-kimi-attach {
    width: 100%;
    max-width: 100%;
    margin: 0 0 8px;
    padding: 0;
    background: transparent;
    border: none;
}

.chat-kimi-attach .kimi-attach-strip--chat {
    border-bottom: none;
    margin-bottom: 0;
    padding-bottom: 0;
}

.user-message .message-body:has(.chat-kimi-attach) {
    background: transparent !important;
    padding: 0 !important;
    max-width: min(100%, calc(100vw - 88px)) !important;
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
}

.user-message .user-message-text {
    background-color: var(--bg-message-user);
    padding: 10px 16px;
    border-radius: 18px;
    border-top-right-radius: 4px;
    max-width: fit-content;
    display: inline-block;
    align-self: flex-start;
}

/* پنل پیش‌نمایش Kimi */
body.kimi-panel-open {
    overflow: hidden;
}

.kimi-file-panel {
    position: fixed;
    inset: 0;
    z-index: 130000;
    display: flex;
    justify-content: flex-end;
    pointer-events: none;
}

.kimi-file-panel[hidden] {
    display: none !important;
}

.kimi-file-panel.is-open {
    pointer-events: auto;
}

.kimi-file-panel__backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.35);
    opacity: 0;
    transition: opacity 0.25s ease;
}

.kimi-file-panel.is-open .kimi-file-panel__backdrop {
    opacity: 1;
}

.kimi-file-panel__drawer {
    position: relative;
    z-index: 1;
    width: min(58vw, 720px);
    max-width: 100%;
    height: 100%;
    background: #fff;
    display: flex;
    flex-direction: column;
    box-shadow: -8px 0 32px rgba(0, 0, 0, 0.12);
    transform: translateX(100%);
    transition: transform 0.28s cubic-bezier(0.22, 1, 0.36, 1);
}

.kimi-file-panel.is-open .kimi-file-panel__drawer {
    transform: translateX(0);
}

[data-theme="dark"] .kimi-file-panel__drawer {
    background: #1e1f20;
    box-shadow: -8px 0 40px rgba(0, 0, 0, 0.45);
}

.kimi-file-panel__header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.08);
    flex-shrink: 0;
}

[data-theme="dark"] .kimi-file-panel__header {
    border-bottom-color: rgba(255, 255, 255, 0.08);
}

.kimi-file-panel__title {
    flex: 1;
    min-width: 0;
    font-size: 0.9rem;
    font-weight: 600;
    color: #111;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

[data-theme="dark"] .kimi-file-panel__title {
    color: #f3f4f6;
}

.kimi-file-panel__tabs {
    display: flex;
    gap: 4px;
    padding: 3px;
    background: #f3f4f6;
    border-radius: 8px;
    flex-shrink: 0;
}

[data-theme="dark"] .kimi-file-panel__tabs {
    background: #2a2b2c;
}

.kimi-file-panel__tab {
    padding: 5px 12px;
    border: none;
    border-radius: 6px;
    background: transparent;
    font-size: 0.78rem;
    font-weight: 500;
    color: #6b7280;
    cursor: pointer;
}

.kimi-file-panel__tab.is-active {
    background: #fff;
    color: #111;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}

[data-theme="dark"] .kimi-file-panel__tab.is-active {
    background: #3d3e42;
    color: #f3f4f6;
}

.kimi-file-panel__tab[hidden] {
    display: none;
}

.kimi-file-panel__actions {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}

.kimi-file-panel__btn {
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: #6b7280;
    cursor: pointer;
    display: grid;
    place-items: center;
}

.kimi-file-panel__btn:hover {
    background: #f3f4f6;
    color: #111;
}

[data-theme="dark"] .kimi-file-panel__btn:hover {
    background: #2a2b2c;
    color: #f3f4f6;
}

.kimi-file-panel__body {
    flex: 1;
    min-height: 0;
    overflow: auto;
    background: #fafafa;
}

[data-theme="dark"] .kimi-file-panel__body {
    background: #161617;
}

.kimi-file-panel__loading,
.kimi-file-panel__hint {
    padding: 48px 24px;
    text-align: center;
    color: #6b7280;
    font-size: 0.9rem;
}

.kimi-file-panel__code {
    margin: 0;
    padding: 16px 18px;
    font-size: 0.8rem;
    line-height: 1.55;
    overflow: auto;
    white-space: pre-wrap;
    word-break: break-word;
    direction: ltr;
    text-align: left;
    color: #1f2937;
    background: #fafafa;
    min-height: 100%;
}

[data-theme="dark"] .kimi-file-panel__code {
    color: #e5e7eb;
    background: #161617;
}

.kimi-file-panel__iframe {
    width: 100%;
    height: 100%;
    min-height: min(80vh, 600px);
    border: none;
    background: #fff;
}

.kimi-file-panel__image {
    display: block;
    max-width: 100%;
    margin: 0 auto;
    padding: 16px;
}

/* اندیکاتور پاسخ — خنثی‌تر */
.ai-thinking-dots > span {
    background: #9ca3af !important;
}

.ai-thinking-text {
    color: #6b7280 !important;
    font-weight: 400 !important;
    animation: none !important;
}

@media (max-width: 768px) {
    .kimi-file-panel__drawer {
        width: 100%;
    }

    .kimi-file-card {
        min-width: 148px;
        max-width: 180px;
    }
}
