/* ── AI Chat Page ──────────────────────────────────────────────────
   Font and CSS variables are inherited from kala-front.css
   ────────────────────────────────────────────────────────────────── */

body.km-ai-page {
    overflow: hidden;
    padding-bottom: 0;
}

body.km-ai-page .footer,
body.km-ai-page .mobile-nav {
    display: none;
}

.km-ai-chat-page {
    display: flex;
    flex-direction: column;
    max-width: 1100px;
    margin: 0 auto;
    width: 100%;
    overflow: hidden;
    /* height set via JS to fill remaining viewport */
}

/* ── Mobile topbar ─────────────────────────────────────────────── */
.km-ai-topbar {
    display: none;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.km-ai-topbar-title {
    font-size: 15px;
    font-weight: 700;
    color: var(--text);
}

/* ── Chat body ─────────────────────────────────────────────────── */
.km-ai-chat-body {
    flex: 1;
    overflow-y: auto;
    padding: 28px 56px;
    display: flex;
    flex-direction: column;
    gap: 24px;
    scroll-behavior: smooth;
    min-height: 0;
}

.km-ai-chat-body::-webkit-scrollbar {
    width: 6px;
}

.km-ai-chat-body::-webkit-scrollbar-thumb {
    background: #e2e8f0;
    border-radius: 6px;
}

/* ── Empty state ─────────────────────────────────────────────────── */
.km-ai-empty {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    gap: 10px;
    padding: 40px 20px;
    min-height: 300px;
}

.km-ai-logo {
    width: 72px;
    height: 72px;
    object-fit: contain;
    margin-bottom: 14px;
}

.km-ai-empty h2 {
    font-size: 20px;
    font-weight: 700;
    color: var(--text);
}

.km-ai-empty p {
    font-size: 14px;
    color: var(--muted);
    max-width: 340px;
    line-height: 1.9;
}

/* ── Messages ─────────────────────────────────────────────────── */
.km-ai-msg-row {
    display: flex;
    width: 100%;
}

.km-ai-bubble-user {
    background: #f1f5f9;
    color: var(--text);
    padding: 14px 18px;
    border-radius: 18px 18px 18px 4px;
    font-size: 14px;
    line-height: 2;
    max-width: 80%;
}

.km-ai-response {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.km-ai-response h3 {
    font-size: 16px;
    font-weight: 700;
    line-height: 1.8;
    color: var(--text);
}

.km-ai-response p {
    font-size: 14px;
    line-height: 2.1;
    color: var(--muted);
}

/* ── Typing indicator ─────────────────────────────────────────── */
.km-ai-typing {
    display: flex;
    gap: 5px;
    padding: 6px 0;
}

.km-ai-typing span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--primary);
    opacity: .3;
    animation: km-ai-blink 1.2s infinite;
}

.km-ai-typing span:nth-child(2) { animation-delay: .2s; }
.km-ai-typing span:nth-child(3) { animation-delay: .4s; }

@keyframes km-ai-blink {
    0%, 80%, 100% { opacity: .25; transform: scale(.85); }
    40% { opacity: 1; transform: scale(1); }
}

/* ── Product grid inside AI response ─────────────────────────── */
.km-ai-product-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 14px;
    margin-top: 4px;
}

.km-ai-product-grid .product-card {
    width: 100%;
}

.km-ai-product-grid .pc-title {
    -webkit-line-clamp: 4;
    height: calc(1.7em * 4);
}

/* ── Typing wait message ─────────────────────────────────────── */
.km-ai-typing-msg {
    font-size: 13px;
    line-height: 1.9;
    color: var(--text-2);
    margin-bottom: 10px;
}

/* ── Sales reply text ────────────────────────────────────────── */
.km-ai-sales-reply {
    margin-top: 16px;
    font-size: 16px;
    font-weight: 700;
    line-height: 2;
    color: var(--text-1);
    border-right: 3px solid var(--primary);
    padding-right: 12px;
}

/* ── Digikala price link ──────────────────────────────────────── */
.km-ai-dk-link {
    display: flex;
    align-items: center;
    gap: 5px;
    margin-top: 8px;
    font-size: 11.5px;
    color: #e3263a;
    font-weight: 600;
    text-decoration: none;
    border: 1px solid #fecaca;
    border-radius: 8px;
    padding: 5px 8px;
    background: #fff5f5;
    transition: background .15s;
    direction: rtl;
}

.km-ai-dk-link:hover {
    background: #fee2e2;
}

/* ── Input bar ─────────────────────────────────────────────────── */
.km-ai-input-wrap {
    padding: 12px 56px 20px;
    flex-shrink: 0;
    background: var(--white);
}

.km-ai-input-bar {
    border: 1.5px solid var(--primary);
    border-radius: 18px;
    background: var(--white);
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
}

.km-ai-input-bar textarea {
    flex: 1;
    border: none;
    outline: none;
    resize: none;
    font-family: inherit;
    font-size: 14px;
    line-height: 1.8;
    color: var(--text);
    max-height: 120px;
    padding: 8px 4px;
    background: transparent;
    direction: rtl;
}

.km-ai-input-bar textarea::placeholder {
    color: #b4b4b8;
}

.km-ai-icon-btn {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    transition: background .15s, opacity .15s;
}

.km-ai-mic-btn {
    background: var(--primary-l);
    color: var(--primary);
}

/* حالت ۲: در حال ضبط */
.km-ai-mic-btn.recording {
    background: #fef2f2;
    color: var(--red);
    animation: km-ai-mic-pulse 1.4s ease-in-out infinite;
}

@keyframes km-ai-mic-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, .35); }
    50% { box-shadow: 0 0 0 7px rgba(239, 68, 68, 0); }
}

/* حالت ۳: در انتظار پاسخ STT */
.km-ai-mic-btn.processing {
    background: #f1f5f9;
    color: #94a3b8;
    cursor: not-allowed;
    animation: km-ai-mic-spin 1s linear infinite;
}

@keyframes km-ai-mic-spin {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

.km-ai-send-btn {
    background: var(--primary);
    color: #fff;
}

.km-ai-send-btn:disabled {
    background: #fed7aa;
    cursor: default;
}

.km-ai-send-btn svg {
    transform: rotate(-90deg);
}

/* ── Mobile ─────────────────────────────────────────────────────── */
@media (max-width: 720px) {
    .km-ai-topbar {
        display: flex;
    }

    .km-ai-chat-body {
        padding: 20px 16px;
        gap: 18px;
    }

    .km-ai-input-wrap {
        padding: 10px 14px 16px;
    }

    .km-ai-product-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
    }

    .km-ai-bubble-user {
        max-width: 92%;
        font-size: 13.5px;
    }

    .km-ai-response h3 { font-size: 15px; }
    .km-ai-response p  { font-size: 13.5px; }
    .km-ai-empty h2    { font-size: 18px; }
    .km-ai-empty p     { font-size: 13px; }
}
