/* ==========================================================================
   Reaka — AI yordamchi vidjeti
   Sayt uslubiga mos: oq qog'oz panel, siyoh rangli tugmalar, yengil soyalar.
   ========================================================================== */

#app-chat {
    position: fixed;
    right: clamp(1rem, 3vw, 1.5rem);
    bottom: clamp(1rem, 3vw, 1.5rem);
    z-index: 90;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0.75rem;
    pointer-events: none;
}

#app-chat > * { pointer-events: auto; }

/* Modal (kirish oynasi yoki dialog) ochiq bo'lsa — vidjet chetga chiqib turadi:
   u alohida kompozit qatlam bo'lgani uchun `backdrop-filter` uni xiralashtira
   olmaydi va o'zi xira fon ustida yorqin bo'lib qolar edi. */
body.hisob-ochiq #app-chat,
body.oyna-ochiq #app-chat {
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--duration-fast) var(--ease-out);
}

/* ==========================================================================
   Ochish tugmasi
   ========================================================================== */

.chat-ochish {
    display: inline-flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.7rem 1.15rem 0.7rem 0.8rem;
    border: 1px solid var(--kok);
    border-radius: var(--radius-pill);
    background: var(--kok);
    color: #fff;
    font-family: var(--font-display);
    font-size: 0.95rem;
    font-weight: 700;
    letter-spacing: 0.01em;
    cursor: pointer;
    box-shadow: var(--shadow-lg);
    transition: transform var(--duration-fast) var(--ease-out),
                box-shadow var(--duration-fast) var(--ease-out),
                opacity var(--duration-base) var(--ease-out);
}

.chat-ochish:hover { transform: translateY(-2px); background: var(--kok-2); border-color: var(--kok-2); box-shadow: var(--shadow-glow); }
.chat-ochish:active { transform: translateY(0); }

.chat-ochish__belgi {
    display: grid;
    place-items: center;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.16);
}

.chat-ochish__belgi svg { width: 18px; height: 18px; }

/* Panel ochiqda tugma "yopish" holatiga o'tadi — mobil'da butunlay ketadi */
.chat-ochish.is-ochiq { opacity: 0; transform: scale(0.9); pointer-events: none; }

/* ==========================================================================
   Panel
   ========================================================================== */

.chat-panel {
    display: flex;
    flex-direction: column;
    width: min(400px, calc(100vw - 2rem));
    height: min(620px, calc(100vh - 7rem));
    background: var(--qogoz-2);
    border: 1px solid var(--chiziq-2);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg), var(--shadow-inset);
    overflow: hidden;
    opacity: 0;
    transform: translateY(16px) scale(0.97);
    transform-origin: bottom right;
    transition: opacity var(--duration-base) var(--ease-out),
                transform var(--duration-base) var(--ease-spring);
}

.chat-panel.is-ochiq { opacity: 1; transform: translateY(0) scale(1); }
.chat-panel[hidden] { display: none; }

/* --- sarlavha --- */

.chat-panel__bosh {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    padding: 0.85rem 0.9rem 0.85rem 1rem;
    background: linear-gradient(180deg, var(--siyoh) 0%, #12274d 100%);
    border-bottom: 2px solid var(--kok);
}

.chat-panel__bosh .chat-panel__nom b { color: #fff; }
.chat-panel__bosh .chat-panel__nom small { color: rgba(255, 255, 255, 0.55); }
.chat-panel__bosh .chat-panel__tugma { color: rgba(255, 255, 255, 0.6); }
.chat-panel__bosh .chat-panel__tugma:hover { background: rgba(255, 255, 255, 0.12); border-color: transparent; color: #fff; }
.chat-panel__bosh .chat-panel__avatar { background: #fff; color: var(--kok); }

.chat-panel__avatar {
    display: grid;
    place-items: center;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--kok);
    color: #fff;
    flex-shrink: 0;
}

.chat-panel__avatar svg { width: 20px; height: 20px; }

.chat-panel__nom { display: flex; flex-direction: column; line-height: 1.25; flex: 1; min-width: 0; }
.chat-panel__nom b { font-family: var(--font-display); font-size: 1rem; color: var(--text-primary); }
.chat-panel__nom small { font-size: 0.75rem; color: var(--text-tertiary); }

.chat-panel__tugma {
    display: grid;
    place-items: center;
    width: 32px;
    height: 32px;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-tertiary);
    cursor: pointer;
    transition: all var(--duration-fast) var(--ease-out);
}

.chat-panel__tugma:hover {
    background: var(--surface-glass);
    border-color: var(--surface-glass-border);
    color: var(--color-primary-light);
}

.chat-panel__tugma svg { width: 17px; height: 17px; }

/* ==========================================================================
   Xabarlar oqimi
   ========================================================================== */

.chat-oqim {
    flex: 1;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
    scrollbar-width: thin;
    scrollbar-color: rgba(15, 31, 56, 0.18) transparent;
}

.chat-oqim::-webkit-scrollbar { width: 7px; }
.chat-oqim::-webkit-scrollbar-thumb { background: rgba(15, 31, 56, 0.16); border-radius: 4px; }

/* --- salomlashuv --- */

.chat-salom { text-align: center; padding: 1.25rem 0.5rem 0.5rem; }

.chat-salom__belgi {
    display: grid;
    place-items: center;
    width: 52px;
    height: 52px;
    margin: 0 auto 0.85rem;
    border-radius: 50%;
    background: var(--kok-yumshoq);
    border: 1px solid rgba(29, 95, 214, 0.28);
    color: var(--color-primary-light);
}

.chat-salom__belgi svg { width: 26px; height: 26px; }
.chat-salom h3 { font-family: var(--font-display); font-size: 1.15rem; margin-bottom: 0.4rem; color: var(--text-primary); }
.chat-salom p { font-size: 0.88rem; line-height: 1.6; color: var(--text-secondary); }

.chat-taklif { display: flex; flex-direction: column; gap: 0.5rem; margin-top: 1.1rem; }

.chat-taklif__tugma {
    padding: 0.6rem 0.85rem;
    border: 1px solid var(--surface-glass-border);
    border-radius: var(--radius-md);
    background: var(--surface-glass);
    color: var(--text-secondary);
    font-size: 0.85rem;
    text-align: left;
    cursor: pointer;
    transition: all var(--duration-fast) var(--ease-out);
}

.chat-taklif__tugma:hover {
    background: var(--surface-glass-strong);
    border-color: rgba(29, 95, 214, 0.34);
    color: var(--color-primary-light);
    transform: translateX(2px);
}

/* --- xabar --- */

.chat-xabar { display: flex; gap: 0.55rem; animation: chat-kirish var(--duration-base) var(--ease-out); }

@keyframes chat-kirish {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

.chat-xabar--men { justify-content: flex-end; }

.chat-xabar--men .chat-xabar__ichi {
    max-width: 85%;
    padding: 0.65rem 0.9rem;
    border-radius: var(--radius-md) var(--radius-md) var(--radius-xs) var(--radius-md);
    background: var(--kok-yumshoq);
    border: 1px solid rgba(29, 95, 214, 0.26);
    color: var(--text-primary);
    font-size: 0.9rem;
    line-height: 1.55;
    white-space: pre-wrap;
    word-break: break-word;
}

.chat-xabar__avatar {
    display: grid;
    place-items: center;
    width: 28px;
    height: 28px;
    flex-shrink: 0;
    border-radius: 50%;
    background: var(--kok);
    color: #fff;
    margin-top: 2px;
}

.chat-xabar__avatar svg { width: 15px; height: 15px; }

.chat-xabar--bot .chat-xabar__ichi {
    flex: 1;
    min-width: 0;
    padding: 0.7rem 0.9rem;
    border-radius: var(--radius-xs) var(--radius-md) var(--radius-md) var(--radius-md);
    background: var(--qogoz-3);
    border: 1px solid var(--chiziq);
    color: var(--text-secondary);
    font-size: 0.9rem;
    line-height: 1.65;
    word-break: break-word;
}

.chat-xabar--bot.is-xato .chat-xabar__ichi {
    background: rgba(207, 74, 55, 0.1);
    border-color: rgba(207, 74, 55, 0.28);
    color: var(--gil);
}

.chat-xabar--bot.is-bloklangan .chat-xabar__ichi {
    background: rgba(217, 152, 26, 0.08);
    border-color: rgba(217, 152, 26, 0.24);
}

/* --- javob ichidagi matn --- */

.chat-xabar__ichi > *:first-child { margin-top: 0; }
.chat-xabar__ichi > *:last-child { margin-bottom: 0; }
.chat-xabar__ichi p { margin: 0 0 0.6rem; }
.chat-xabar__ichi h3,
.chat-xabar__ichi h4,
.chat-xabar__ichi h5,
.chat-xabar__ichi h6 {
    font-family: var(--font-display);
    font-size: 0.95rem;
    color: var(--text-primary);
    margin: 0.85rem 0 0.4rem;
}

.chat-xabar__ichi ul,
.chat-xabar__ichi ol { margin: 0 0 0.6rem; padding-left: 1.15rem; }
.chat-xabar__ichi li { margin-bottom: 0.3rem; }
.chat-xabar__ichi strong { color: var(--text-primary); font-weight: 650; }

.chat-xabar__ichi code {
    padding: 0.1rem 0.35rem;
    border-radius: var(--radius-xs);
    background: rgba(15, 31, 56, 0.08);
    font-size: 0.85em;
}

.chat-xabar__ichi a {
    color: var(--color-primary-light);
    text-decoration: underline;
    text-underline-offset: 3px;
    text-decoration-color: rgba(29, 95, 214, 0.42);
    transition: color var(--duration-fast) var(--ease-out);
}

.chat-xabar__ichi a:hover { color: var(--color-primary-lightest); text-decoration-color: currentColor; }

/* --- "yozmoqda" nuqtalari --- */

.chat-nuqta { display: inline-flex; gap: 4px; align-items: center; padding: 0.15rem 0; }

.chat-nuqta i {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--color-primary-light);
    opacity: 0.4;
    animation: chat-nafas 1.3s var(--ease-in-out) infinite;
}

.chat-nuqta i:nth-child(2) { animation-delay: 0.18s; }
.chat-nuqta i:nth-child(3) { animation-delay: 0.36s; }

@keyframes chat-nafas {
    0%, 60%, 100% { opacity: 0.32; transform: translateY(0); }
    30%           { opacity: 1;    transform: translateY(-3px); }
}

/* ==========================================================================
   Yozish maydoni
   ========================================================================== */

.chat-forma {
    display: flex;
    align-items: flex-end;
    gap: 0.5rem;
    padding: 0.75rem 0.85rem 0.5rem;
    border-top: 1px solid rgba(15, 31, 56, 0.09);
    background: rgba(15, 31, 56, 0.03);
}

.chat-forma__matn {
    flex: 1;
    min-height: 42px;
    max-height: 132px;
    padding: 0.65rem 0.85rem;
    border: 1px solid var(--surface-glass-border);
    border-radius: var(--radius-md);
    background: var(--qogoz);
    color: var(--text-primary);
    font-family: var(--font-sans);
    font-size: 0.9rem;
    line-height: 1.5;
    resize: none;
    transition: border-color var(--duration-fast) var(--ease-out),
                box-shadow var(--duration-fast) var(--ease-out);
}

.chat-forma__matn::placeholder { color: var(--text-tertiary); }

.chat-forma__matn:focus {
    outline: none;
    border-color: rgba(29, 95, 214, 0.5);
    box-shadow: 0 0 0 3px rgba(29, 95, 214, 0.14);
}

.chat-forma__yubor {
    display: grid;
    place-items: center;
    width: 42px;
    height: 42px;
    flex-shrink: 0;
    border: none;
    border-radius: var(--radius-md);
    background: var(--kok);
    color: #fff;
    cursor: pointer;
    transition: transform var(--duration-fast) var(--ease-out),
                opacity var(--duration-fast) var(--ease-out);
}

.chat-forma__yubor:hover:not(:disabled) { transform: translateY(-1px); }
.chat-forma__yubor:disabled { opacity: 0.45; cursor: default; }
.chat-forma__yubor svg { width: 19px; height: 19px; }

.chat-forma.is-band .chat-forma__matn { opacity: 0.7; }

.chat-eslatma {
    margin: 0;
    padding: 0 0.9rem 0.7rem;
    font-size: 0.7rem;
    line-height: 1.4;
    color: var(--text-tertiary);
    text-align: center;
    background: rgba(15, 31, 56, 0.03);
}

/* ==========================================================================
   Kichik ekran — panel butun ekranni egallaydi
   ========================================================================== */

@media (max-width: 640px) {
    #app-chat { right: 0; bottom: 0; left: 0; align-items: flex-end; }
    .chat-ochish { margin: 0 1rem 1rem auto; }

    .chat-panel {
        width: 100vw;
        height: 100dvh;
        max-height: none;
        border-radius: 0;
        border: none;
        transform-origin: bottom center;
    }

    body.chat-ochiq { overflow: hidden; }
}

@media (prefers-reduced-motion: reduce) {
    .chat-panel,
    .chat-ochish,
    .chat-xabar,
    .chat-nuqta i { transition: none; animation: none; }
}

/* Kirmagan foydalanuvchi: yozish maydoni yopiq turadi */
.chat-forma.is-yopiq {
    opacity: 0.55;
}

.chat-forma.is-yopiq .chat-forma__matn {
    cursor: not-allowed;
}

.chat-salom .btn {
    width: 100%;
    justify-content: center;
}
