/*
 * AI yordamchi vidjeti (components/widgets/ChatbotWidget.php, web/js/chatbot.js).
 *
 * Pastki o'ng burchak. O'ng tomondagi `.side-rail` ekran o'rtasida turadi,
 * shuning uchun ular to'qnashmaydi. z-index a11y niqobi (99990) dan past.
 */

.cb {
    --cb-primary: #1f57e0;
    --cb-primary-dark: #0b44b8;
    --cb-primary-50: #eaf1ff;
    --cb-ink: #0f1b3d;
    --cb-text: #33405a;
    --cb-muted: #6b7385;
    --cb-line: #dbe3f1;
    --cb-bg: #f4f7fc;
    --cb-surface: #ffffff;

    position: fixed;
    right: 24px;
    bottom: 24px;
    z-index: 9990;
    font-family: var(--font-primary, "Montserrat", Arial, sans-serif);
}

/*
 * "Yuqoriga" tugmasi (gorom/css/style.css: right 60px, bottom 45px) chat
 * tugmasi bilan ustma-ust tushardi — uni chat tugmasi tepasiga, bir
 * vertikal chiziqqa ko'taramiz. Bu fayl faqat vidjet yoqilganda ulanadi.
 */
.scrolltop {
    right: 30px;
    bottom: 100px;
}

/* ---- Suzuvchi tugma --------------------------------------------- */

.cb-launcher {
    position: relative;
    display: grid;
    place-items: center;
    width: 62px;
    height: 62px;
    padding: 0;
    color: #fff;
    border: 0;
    border-radius: 50%;
    background: linear-gradient(135deg, #2f6bff, var(--cb-primary-dark));
    box-shadow: 0 10px 26px rgba(11, 68, 184, .38);
    cursor: pointer;
    transition: transform .2s ease, box-shadow .2s ease;
}

.cb-launcher::before {
    content: "";
    position: absolute;
    inset: -8px;
    border-radius: 50%;
    border: 2px solid rgba(47, 107, 255, .35);
    animation: cb-pulse 2.4s ease-out infinite;
    pointer-events: none;
}

.cb-launcher:hover {
    transform: translateY(-2px);
    box-shadow: 0 14px 30px rgba(11, 68, 184, .45);
}

.cb-launcher:focus-visible {
    outline: 3px solid #ffb400;
    outline-offset: 3px;
}

.cb-launcher svg {
    width: 28px;
    height: 28px;
}

.cb-launcher__close,
.cb.is-open .cb-launcher__icon {
    display: none;
}

.cb.is-open .cb-launcher__close {
    display: block;
}

.cb.is-open .cb-launcher::before {
    animation: none;
    opacity: 0;
}

@keyframes cb-pulse {
    0% { transform: scale(.9); opacity: 1; }
    100% { transform: scale(1.25); opacity: 0; }
}

/* ---- Panel ------------------------------------------------------ */

.cb-panel {
    position: absolute;
    right: 0;
    bottom: 76px;
    display: flex;
    flex-direction: column;
    width: 380px;
    height: min(600px, calc(100vh - 130px));
    overflow: hidden;
    background: var(--cb-bg);
    border-radius: 20px;
    box-shadow: 0 24px 60px rgba(15, 27, 61, .28);
    transform-origin: bottom right;
    animation: cb-in .22s ease-out;
}

.cb-panel[hidden] {
    display: none;
}

@keyframes cb-in {
    from { opacity: 0; transform: translateY(12px) scale(.97); }
    to { opacity: 1; transform: none; }
}

.cb-head {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 14px 16px 18px;
    color: #fff;
    background: linear-gradient(120deg, var(--cb-primary-dark), #2f6bff);
}

.cb-head__avatar {
    display: grid;
    flex: 0 0 42px;
    place-items: center;
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 0 0 2px rgba(255, 255, 255, .35);
}

/* Akademiya logosi — oq doira ichida, qirqilmasdan */
.cb-head__avatar img {
    display: block;
    width: 34px;
    height: 34px;
    object-fit: contain;
}

.cb-head__text {
    display: flex;
    flex: 1;
    flex-direction: column;
    min-width: 0;
}

.cb-head__title {
    font-size: 16px;
    font-weight: 700;
    line-height: 1.25;
}

.cb-head__status {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 12.5px;
    opacity: .9;
}

.cb-head__status::before {
    content: "";
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #2fd47a;
    box-shadow: 0 0 0 2px rgba(47, 212, 122, .3);
}

.cb-head__btn {
    display: grid;
    place-items: center;
    width: 34px;
    height: 34px;
    padding: 0;
    color: #fff;
    border: 0;
    border-radius: 10px;
    background: transparent;
    cursor: pointer;
}

.cb-head__btn:hover,
.cb-head__btn:focus-visible {
    background: rgba(255, 255, 255, .16);
}

.cb-head__btn svg {
    width: 18px;
    height: 18px;
}

/* ---- Xabarlar --------------------------------------------------- */

.cb-body {
    display: flex;
    flex: 1;
    flex-direction: column;
    gap: 10px;
    padding: 16px 14px;
    overflow-y: auto;
    overscroll-behavior: contain;
    scroll-behavior: smooth;
}

.cb-msg {
    max-width: 86%;
    padding: 11px 14px;
    font-size: 14px;
    line-height: 1.5;
    color: var(--cb-text);
    white-space: normal;
    word-wrap: break-word;
    overflow-wrap: anywhere;
    background: var(--cb-surface);
    border-radius: 16px 16px 16px 4px;
    box-shadow: 0 1px 2px rgba(15, 27, 61, .06);
}

.cb-msg p {
    margin: 0 0 8px;
}

.cb-msg p:last-child,
.cb-msg ul:last-child {
    margin-bottom: 0;
}

/* Sayt shablonidagi `ul { list-style: none }` ni bosadi */
.cb-msg ul {
    margin: 0 0 8px;
    padding-left: 18px;
    list-style: disc;
}

.cb-msg li {
    display: list-item;
    margin: 2px 0;
    list-style: inherit;
}

.cb-msg a {
    color: var(--cb-primary);
    font-weight: 600;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.cb-msg--user {
    align-self: flex-end;
    color: #fff;
    background: var(--cb-primary);
    border-radius: 16px 16px 4px 16px;
}

.cb-msg--error {
    color: #8a1c1c;
    background: #fff1f1;
}

.cb-sources {
    margin-top: 10px;
    padding-top: 8px;
    font-size: 12.5px;
    border-top: 1px solid var(--cb-line);
}

.cb-sources__title {
    display: block;
    margin-bottom: 4px;
    color: var(--cb-muted);
}

.cb-sources a {
    display: block;
    margin: 2px 0;
    font-weight: 500;
}

/* Javobga baho: 👍 / 👎 */
.cb-feedback {
    display: flex;
    gap: 6px;
    margin-top: 8px;
}

.cb-feedback__btn {
    padding: 2px 8px;
    border: 1px solid var(--cb-line);
    border-radius: 999px;
    background: #fff;
    font-size: 13px;
    line-height: 1.6;
    cursor: pointer;
    opacity: .75;
    transition: opacity .15s, border-color .15s, background-color .15s;
}

.cb-feedback__btn:hover,
.cb-feedback__btn:focus-visible {
    border-color: var(--cb-primary);
    background: var(--cb-primary-50);
    opacity: 1;
}

.cb-feedback--done {
    color: var(--cb-muted);
    font-size: 12px;
}

.cb-typing {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    color: var(--cb-muted);
}

.cb-typing i {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--cb-primary);
    opacity: .35;
    animation: cb-dot 1.2s infinite;
}

.cb-typing i:nth-child(2) { animation-delay: .15s; }
.cb-typing i:nth-child(3) { animation-delay: .3s; }

.cb-typing span {
    margin-left: 6px;
    font-size: 12.5px;
}

@keyframes cb-dot {
    0%, 60%, 100% { opacity: .35; transform: none; }
    30% { opacity: 1; transform: translateY(-3px); }
}

/* ---- Mavzu tugmalari -------------------------------------------- */

.cb-topics {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.cb-topic {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 10px 16px;
    font: inherit;
    font-size: 14px;
    font-weight: 500;
    text-align: left;
    color: var(--cb-primary-dark);
    border: 1px solid var(--cb-line);
    border-radius: 999px;
    background: var(--cb-surface);
    cursor: pointer;
    transition: background-color .15s ease, border-color .15s ease;
}

.cb-topic:hover,
.cb-topic:focus-visible {
    border-color: var(--cb-primary);
    background: var(--cb-primary-50);
    outline: none;
}

.cb-topic:disabled {
    opacity: .55;
    cursor: default;
}

/* ---- Kiritish maydoni ------------------------------------------- */

.cb-form {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    padding: 12px 14px 6px;
    background: var(--cb-surface);
    border-top: 1px solid var(--cb-line);
}

.cb-input {
    flex: 1;
    min-height: 46px;
    max-height: 120px;
    padding: 12px 14px;
    font: inherit;
    font-size: 14px;
    line-height: 1.4;
    color: var(--cb-ink);
    resize: none;
    border: 1px solid var(--cb-line);
    border-radius: 14px;
    background: var(--cb-bg);
}

.cb-input:focus {
    border-color: var(--cb-primary);
    outline: none;
    box-shadow: 0 0 0 3px rgba(31, 87, 224, .15);
}

.cb-send {
    display: grid;
    flex: 0 0 46px;
    place-items: center;
    width: 46px;
    height: 46px;
    padding: 0;
    color: #fff;
    border: 0;
    border-radius: 14px;
    background: var(--cb-primary);
    cursor: pointer;
    transition: background-color .15s ease, opacity .15s ease;
}

.cb-send:hover {
    background: var(--cb-primary-dark);
}

.cb-send:disabled {
    opacity: .45;
    cursor: default;
}

.cb-send svg {
    width: 20px;
    height: 20px;
}

.cb-note {
    margin: 0;
    padding: 0 14px 10px;
    font-size: 11px;
    line-height: 1.35;
    text-align: center;
    color: var(--cb-muted);
    background: var(--cb-surface);
}

/* ---- Telefon ---------------------------------------------------- */

@media (max-width: 575px) {
    .cb {
        right: 16px;
        bottom: 16px;
    }

    .cb-launcher {
        width: 56px;
        height: 56px;
    }

    .scrolltop {
        right: 19px;
        bottom: 86px;
    }

    .cb.is-open .cb-launcher {
        display: none;
    }

    .cb-panel {
        position: fixed;
        inset: 0;
        width: auto;
        height: auto;
        border-radius: 0;
    }
}

@media (prefers-reduced-motion: reduce) {
    .cb-launcher::before,
    .cb-panel,
    .cb-typing i {
        animation: none;
    }
}

@media print {
    .cb {
        display: none;
    }
}
