﻿/*==========================================================
  Root
==========================================================*/
:root {
    --ai-primary: #0d6efd;
    --ai-primary-hover: #0b5ed7;
    --ai-bg: #ffffff;
    --ai-border: #e9ecef;
    --ai-user-bg: #0d6efd;
    --ai-user-color: #ffffff;
    --ai-bot-bg: #f8f9fa;
    --ai-bot-color: #212529;
    --ai-shadow: 0 .5rem 1.5rem rgba(0,0,0,.15);
    --ai-radius: 18px;
}
/*==========================================================
  Floating Button
==========================================================*/
.ai-chat-toggle {
    position: fixed;
    right: 25px;
    bottom: 25px;
    width: 62px;
    height: 62px;
    border: 0;
    border-radius: 50%;
    background: var(--ai-primary);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 800;
    box-shadow: var(--ai-shadow);
    transition: .25s;
}

    .ai-chat-toggle:hover {
        background: var(--ai-primary-hover);
        transform: translateY(-3px);
    }

    .ai-chat-toggle i {
        font-size: 1.45rem;
    }

.ai-chat-badge {
    position: absolute;
    top: -10px;
    left: 4px;
    min-width: 20px;
    height: 20px;
    border-radius: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: .80rem;
    font-weight: 700;
}
/*==========================================================
  Widget
==========================================================*/
.ai-chat-widget {
    position: fixed;
    right: 25px;
    bottom: 100px;
    width: 390px;
    max-width: calc(100vw - 30px);
    height: 680px;
    max-height: 82vh;
    background: var(--ai-bg);
    border: 1px solid var(--ai-border);
    border-radius: var(--ai-radius);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: var(--ai-shadow);
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px);
    transition: .25s;
    z-index: 1079;
}

    .ai-chat-widget.show {
        opacity: 1;
        visibility: visible;
        transform: translateY(0);
    }
/*==========================================================
  Header
==========================================================*/
.ai-chat-header {
    background: linear-gradient(135deg, var(--ai-primary), #3b82f6);
    color: #fff;
    padding: 1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.ai-chat-header-info {
    display: flex;
    align-items: center;
    gap: .75rem;
}

.ai-header-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: rgba(255,255,255,.15);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

    .ai-header-avatar i {
        font-size: 1.35rem;
        color: #fff;
    }

    .ai-header-avatar img {
        width: 100%;
        height: 100%;
        object-fit: cover;
        border-radius: 50%;
    }

.ai-header-title {
    font-size: 1rem;
    font-weight: 700;
    line-height: 1.3;
}

.ai-header-status {
    display: flex;
    align-items: center;
    gap: .35rem;
    margin-top: .2rem;
    font-size: .8rem;
    opacity: .95;
}

    .ai-header-status span {
        width: 8px;
        height: 8px;
        border-radius: 50%;
        background: #22c55e;
        box-shadow: 0 0 8px #22c55e;
    }

.ai-chat-actions {
    display: flex;
    align-items: center;
    gap: .25rem;
}

    .ai-chat-actions .btn {
        width: 36px;
        height: 36px;
        border-radius: .65rem;
        display: flex;
        align-items: center;
        justify-content: center;
        text-decoration: none;
        transition: .2s;
    }

        .ai-chat-actions .btn:hover {
            background: rgba(255,255,255,.12);
        }

        .ai-chat-actions .btn i {
            font-size: 1rem;
        }

    .ai-chat-actions .btn-close {
        opacity: .9;
    }

        .ai-chat-actions .btn-close:hover {
            opacity: 1;
        }
/*==========================================================
  Messages
==========================================================*/
.ai-chat-messages {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 1rem;
    background: #f8f9fa;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    scroll-behavior: smooth;
}

    .ai-chat-messages::-webkit-scrollbar {
        width: 7px;
    }

    .ai-chat-messages::-webkit-scrollbar-thumb {
        background: #ced4da;
        border-radius: 50px;
    }

        .ai-chat-messages::-webkit-scrollbar-thumb:hover {
            background: #adb5bd;
        }

    .ai-chat-messages::-webkit-scrollbar-track {
        background: transparent;
    }
/*==========================================================
  Welcome
==========================================================*/
.ai-welcome {
    margin: auto;
    width: 100%;
    max-width: 320px;
    text-align: center;
    color: #6c757d;
}

.ai-welcome-icon {
    width: 90px;
    height: 90px;
    margin: 0 auto 1.25rem;
    border-radius: 50%;
  
    
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

    .ai-welcome-icon img {
        width: 65px;
        height: 65px;
        object-fit: contain;
    }

.ai-welcome h5 {
    margin-bottom: .75rem;
    font-weight: 700;
    color: #212529;
}

.ai-welcome p {
    margin-bottom: 1.5rem;
    line-height: 2;
    font-size: .95rem;
}

.ai-welcome-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: .75rem;
}

    .ai-welcome-actions .btn {
        border-radius: 50px;
        display: inline-flex;
        align-items: center;
        gap: .5rem;
        transition: .2s;
    }

        .ai-welcome-actions .btn i {
            font-size: .95rem;
        }

.ai-suggestion:hover {
    transform: translateY(-2px);
}
/*==========================================================
  Message
==========================================================*/
.ai-message {
    display: flex;
    align-items: flex-end;
    gap: .75rem;
    animation: aiFade .25s ease;
}

    .ai-message.user {
        flex-direction: row-reverse;
    }

.ai-avatar {
    width: 40px;
    height: 40px;
    flex-shrink: 0;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #e9ecef;
    color: #495057;
    overflow: hidden;
}

    .ai-avatar img {
        width: 100%;
        height: 100%;
        object-fit: cover;
    }

    .ai-avatar i {
        font-size: 1rem;
    }

.ai-message.user .ai-avatar {
    background: var(--ai-primary);
    color: #fff;
}

.ai-content {
    max-width: 78%;
    width: fit-content;
    display: flex;
    flex-direction: column;
}

.ai-message.user .ai-content {
    align-items: flex-end;
}

.ai-bubble {
    width: fit-content;
    max-width: 100%;
    background: var(--ai-bot-bg);
    color: var(--ai-bot-color);
    padding: .65rem 1rem;
    border-radius: 16px;
    line-height: 1.55;
    font-size: .9rem;
    word-break: break-word;
    white-space: pre-wrap;
    box-shadow: 0 2px 8px rgba(0,0,0,.05);
}

.ai-message.user .ai-bubble {
    background: var(--ai-user-bg);
    color: var(--ai-user-color);
}

.ai-time {
    margin-top: .35rem;
    padding: 0 .4rem;
    font-size: .72rem;
    color: #adb5bd;
}

.ai-message.user .ai-time {
    text-align: left;
}
/*==========================================================
  Bubble Content
==========================================================*/
.ai-bubble p {
    margin: 0;
}

    .ai-bubble p + p {
        margin-top: .75rem;
    }

.ai-bubble strong {
    font-weight: 700;
}

.ai-bubble ul,
.ai-bubble ol {
    margin: .75rem 0;
    padding-inline-start: 1.25rem;
}

.ai-bubble li {
    margin-bottom: .35rem;
}

.ai-bubble a {
    color: inherit;
    text-decoration: underline;
}

.ai-bubble img {
    display: block;
    max-width: 100%;
    border-radius: 12px;
    margin-top: .5rem;
}

.ai-bubble code {
    padding: .15rem .4rem;
    border-radius: 6px;
    background: rgba(0,0,0,.08);
    font-family: Consolas, monospace;
    font-size: .85rem;
}

.ai-message.user .ai-bubble code {
    background: rgba(255,255,255,.18);
}

.ai-bubble pre {
    margin-top: .75rem;
    margin-bottom: 0;
    padding: 1rem;
    overflow: auto;
    border-radius: 12px;
    background: #212529;
    color: #fff;
    direction: ltr;
    text-align: left;
}

    .ai-bubble pre code {
        background: transparent;
        padding: 0;
        color: inherit;
    }
/*==========================================================
  Animation
==========================================================*/
@keyframes aiFade {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}
/*==========================================================
  Footer
==========================================================*/
.ai-chat-footer {
    position: relative;
    padding: 1rem;
    border-top: 1px solid var(--ai-border);
    background: #fff;
    flex-shrink: 0;
    display: flex;
    align-items: flex-end;
    gap: .75rem;
}
.ai-counter {
    position: absolute;
    bottom: 20px;
    left: 100px; /* اگر RTL است */
    font-size: .72rem;
    color: #9ca3af;
    pointer-events: none;
    user-select: none;
    transition: .2s;
}

.ai-counter.warning {
    color: #f59e0b;
}

.ai-counter.danger {
    color: #ef4444;
}
/*==========================================================
  Textarea
==========================================================*/
#aiMessage {
    flex: 1;
    resize: none;
    min-height: 48px;
    max-height: 80px;
    padding: .75rem 1rem;
    border: 1px solid var(--ai-border);
    border-radius: 14px;
    background: #fff;
    color: #212529;
    font-size: .95rem;
    line-height: 1.5;
    overflow-y: auto;
    transition: .2s;
    scrollbar-width: none; /* Firefox */
    -ms-overflow-style: none; /* IE/Edge */
}

    #aiMessage::-webkit-scrollbar {
        display: none; /* Chrome, Safari, Opera */
    }

    #aiMessage:focus {
        outline: none;
        border-color: var(--ai-primary);
        box-shadow: 0 0 0 .2rem rgba(13,110,253,.15);
    }

    #aiMessage::placeholder {
        color: #adb5bd;
    }

    #aiMessage:disabled {
        background: #f8f9fa;
        cursor: not-allowed;
    }
/*==========================================================
  Send Button
==========================================================*/
#aiSend {
    width: 48px;
    height: 48px;
    border: 0;
    border-radius: 14px;
    background: var(--ai-primary);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    cursor: pointer;
    transition: .2s;
}

    #aiSend:hover:not(:disabled) {
        background: var(--ai-primary-hover);
    }

    #aiSend:active:not(:disabled) {
        transform: scale(.96);
    }

    #aiSend:disabled {
        opacity: .7;
        cursor: not-allowed;
    }

    #aiSend i {
        font-size: 1rem;
    }

    #aiSend .spinner-border {
        width: 18px;
        height: 18px;
        border-width: 2px;
    }
/*==========================================================
  Typing Indicator
==========================================================*/
.ai-thinking {
    display: flex;
    align-items: center;
    gap: 4px;
    min-height: 18px;
}

    .ai-thinking span {
        width: 8px;
        height: 8px;
        border-radius: 50%;
        background: #adb5bd;
        animation: aiTyping 1.2s infinite ease-in-out;
    }

        .ai-thinking span:nth-child(2) {
            animation-delay: .2s;
        }

        .ai-thinking span:nth-child(3) {
            animation-delay: .4s;
        }

@keyframes aiTyping {
    0%,80%,100% {
        transform: scale(.7);
        opacity: .35;
    }

    40% {
        transform: scale(1);
        opacity: 1;
    }
}
/*==========================================================
  Responsive
==========================================================*/
@media (max-width:576px) {
    .ai-chat-toggle {
        right: 15px;
        bottom: 120px;
    }

    .ai-chat-widget {
        right: 12px;
        left: 12px;
        bottom: 86px;
        width: auto;
        max-width: none;
        height: calc(100vh - 100px);
        max-height: none;
        border-radius: 16px;
    }

    .ai-content {
        max-width: 88%;
    }

    .ai-chat-footer {
        padding: .75rem;
    }
}
