/* دستیار هوش‌مصنوعی StoreX Widget Styles */

/* Import Vazir font for Persian text */
@import url('https://cdn.jsdelivr.net/gh/rastikerdar/vazir-font@v30.1.0/dist/font-face.css');

#storex-chat-widget {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 9999;
    font-family: 'Vazir', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
}

/* Floating Chat Button */
#storex-chat-button {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, #009893, #0A9396);
    box-shadow: 0 4px 20px rgba(0, 152, 147, 0.3);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    border: none;
    position: relative;
    animation: chatButtonPulse 3s ease-in-out infinite;
}

/* Attention-grabbing pulse animation */
@keyframes chatButtonPulse {
    0%, 100% {
        transform: scale(1);
        box-shadow: 0 4px 20px rgba(0, 152, 147, 0.3);
    }
    50% {
        transform: scale(1.05);
        box-shadow: 0 6px 30px rgba(0, 152, 147, 0.5);
    }
}

/* Stop animation after first interaction */
#storex-chat-button.animated {
    animation: none;
}

/* Tooltip for floating button - minimal and outside button */
#storex-chat-button::before {
    content: 'چت با دستیار';
    position: absolute;
    right: calc(4px); /* place outside to the left, closer */
    top: 50%;
    transform: translateY(-50%);
    background: #1f1f1f;
    color: #fff;
    padding: 6px 10px;
    border-radius: 6px;
    font-size: 12px;
    font-family: 'Vazir', sans-serif;
    font-weight: 400;
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease, visibility 0.2s ease;
    z-index: 10000;
}

#storex-chat-button::after {
    content: '';
    position: absolute;
    right: 100%;
    top: 50%;
    transform: translate(2px, -50%);
    border: 6px solid transparent;
    border-right-color: #1f1f1f; /* arrow pointing to button */
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease, visibility 0.2s ease;
    z-index: 10000;
}

#storex-chat-button:hover::before,
#storex-chat-button:hover::after {
    opacity: 1;
    visibility: visible;
}

#storex-chat-button:hover {
    transform: scale(1.06);
}

#storex-chat-button img {
    width: 35px;
    height: 35px;
    object-fit: contain;
}

/* Chat Window */
#storex-chat-window {
    position: absolute;
    bottom: 70px;
    right: 0;
    width: 350px;
    height: 500px;
    background: #F7F7F7;
    border-radius: 15px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: slideUp 0.3s ease-out;
    transform: translateX(0);
}

/* Expanded chat window size */
#storex-chat-window.expanded {
    width: 800px;
    height: 80vh;
    max-height: 900px;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Chat Header */
#storex-chat-header {
    background: linear-gradient(135deg, #009893, #0A9396);
    color: white;
    padding: 15px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-radius: 15px 15px 0 0;
}

#storex-chat-header h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    font-family: 'Vazir', sans-serif;
    direction: rtl;
    text-align: right;
}

#storex-chat-close {
    background: none;
    border: none;
    color: white;
    font-size: 24px;
    cursor: pointer;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background-color 0.2s ease;
}

#storex-chat-close:hover {
    background-color: rgba(255, 255, 255, 0.2);
}

/* Chat Messages */
#storex-chat-messages {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    background: #F7F7F7;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.storex-message {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    animation: fadeIn 0.3s ease-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.storex-bot-message {
    justify-content: flex-start;
    flex-direction: row;
}

.storex-user-message {
    justify-content: flex-end;
    flex-direction: row;
}

.storex-avatar {
    width: 35px;
    height: 35px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
    order: 1;
    background-color: #f8f9fa;
    padding: 6px;
    border: 1px solid #e9ecef;
    cursor: pointer;
    position: relative;
    transition: all 0.3s ease;
}

.storex-avatar:hover {
    transform: scale(1.1);
    box-shadow: 0 2px 8px rgba(0, 152, 147, 0.3);
}

/* Assistant Avatar Tooltip */
.storex-bot-message .storex-avatar[data-api-type="support"]::before {
    content: 'دستیار پشتیبانی فنی StoreX';
    position: absolute;
    bottom: -35px;
    left: 50%;
    transform: translateX(-50%);
    background: linear-gradient(135deg, #1D1F27, #2C2C2C);
    color: white;
    padding: 6px 10px;
    border-radius: 6px;
    font-size: 11px;
    font-family: 'Vazir', sans-serif;
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
    z-index: 1000;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    border: 1px solid #009893;
    width: 180px;
    text-align: center;
}

.storex-bot-message .storex-avatar[data-api-type="sales"]::before {
    content: 'مشاور فروش StoreX';
    position: absolute;
    bottom: -35px;
    left: 50%;
    transform: translateX(-50%);
    background: linear-gradient(135deg, #1D1F27, #2C2C2C);
    color: white;
    padding: 6px 10px;
    border-radius: 6px;
    font-size: 11px;
    font-family: 'Vazir', sans-serif;
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
    z-index: 1000;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    border: 1px solid #009893;
    width: 180px;
    text-align: center;
}

.storex-bot-message .storex-avatar::after {
    content: '';
    position: absolute;
    bottom: -30px;
    left: 50%;
    transform: translateX(-50%);
    border: 4px solid transparent;
    border-top-color: #1D1F27;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
    z-index: 1000;
}

.storex-bot-message .storex-avatar:hover::before,
.storex-bot-message .storex-avatar:hover::after {
    opacity: 1;
    visibility: visible;
}

.storex-bot-message .storex-avatar {
    order: 1;
}

.storex-user-message .storex-avatar {
    order: 2;
}

.storex-message-content {
    max-width: 80%;
    padding: 12px 16px;
    border-radius: 18px;
    font-size: 14px;
    line-height: 1.4;
    word-wrap: break-word;
    direction: rtl;
    text-align: right;
    font-family: 'Vazir', sans-serif;
}

.storex-bot-message .storex-message-content {
    background: #E9D8A6;
    color: #1D1F27;
    border-bottom-left-radius: 5px;
    margin-left: 10px;
    margin-right: 0;
    order: 2;
}

.storex-user-message .storex-message-content {
    background: linear-gradient(135deg, #009893, #0A9396);
    color: white;
    border-bottom-right-radius: 5px;
    margin-right: 10px;
    margin-left: 0;
    order: 1;
}

/* Chat Input */
#storex-chat-input {
    padding: 20px;
    background: white;
    border-top: 1px solid #E9D8A6;
    display: flex;
    gap: 10px;
    align-items: center;
}

/* API Selector Styles */
#storex-api-selector {
    position: absolute;
    inset: 0; /* fill chat window */
    display: none; /* Hidden by default */
    z-index: 1000;
    padding: 20px;
    background: rgba(248, 249, 250, 0.85);
    backdrop-filter: blur(6px);
}

#storex-api-selector.show {
    display: flex;
    align-items: center;
    justify-content: center;
}

#storex-api-selector .storex-api-panel {
    width: 90%;
    max-width: 520px;
    background: #ffffff;
    border: 2px solid #e9ecef;
    border-radius: 16px;
    box-shadow: 0 14px 40px rgba(0,0,0,0.15);
    padding: 20px;
}

.storex-api-buttons {
    display: flex;
    gap: 12px;
    flex-direction: row;
    justify-content: center;
}

.storex-api-selector-title {
    text-align: center;
    margin-bottom: 15px;
    font-size: 16px;
    font-weight: 700;
    color: #1D1F27;
    font-family: 'Vazir', sans-serif;
}

.storex-api-btn {
    min-width: 180px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 14px 18px;
    border: 2px solid #e9ecef;
    background-color: #fff;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 15px;
    font-weight: 600;
    font-family: 'Vazir', sans-serif;
}

.storex-api-btn:hover {
    border-color: var(--storex-primary);
    background-color: #f0f9ff;
    transform: translateY(-1px);
}

.storex-api-btn.active {
    border-color: var(--storex-primary);
    background: linear-gradient(135deg, var(--storex-primary), #0A9396);
    color: #fff;
}

.storex-api-icon { font-size: 16px; }
.storex-api-text { font-size: 12px; }

@media (max-width: 480px) {
    .storex-api-buttons { flex-direction: column; }
    .storex-api-btn { min-width: 100%; }
}



/* Ticket Section */
#storex-ticket-section {
    padding: 15px 20px;
    background: #F7F7F7;
    border-top: 1px solid #E9D8A6;
    text-align: center;
}

#storex-ticket-button {
    background: #0A9396; /* flat color */
    color: #fff;
    border: 1px solid #0A9396; /* subtle border */
    padding: 10px 18px;
    border-radius: 10px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    transition: background-color 0.15s ease, border-color 0.15s ease;
    min-width: 140px;
    font-family: 'Vazir', sans-serif;
    box-shadow: none; /* no shadow */
}

#storex-ticket-button:hover {
    background: #0b8a8d;
    border-color: #0b8a8d;
}

#storex-ticket-button:active {
    transform: translateY(0);
}

#storex-message-input {
    flex: 1;
    padding: 12px 16px;
    border: 2px solid #E9D8A6;
    border-radius: 25px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s ease;
    background: #F7F7F7;
    direction: rtl;
    text-align: right;
    font-family: 'Vazir', sans-serif;
    min-height: 44px;
    box-sizing: border-box;
}

#storex-message-input:focus {
    border-color: #009893;
    background: white;
}

#storex-send-button {
    background: #009893; /* flat color */
    color: white;
    border: 1px solid #009893;
    padding: 12px 16px;
    border-radius: 25px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    transition: background-color 0.2s ease, border-color 0.2s ease, opacity 0.2s ease;
    min-width: 80px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: 'Vazir', sans-serif;
    flex-shrink: 0;
    white-space: nowrap;
    overflow: hidden;
}

#storex-send-button:hover {
    background: #0A9396;
    border-color: #0A9396;
}

#storex-send-button:active {
    opacity: 0.95;
}

#storex-send-button:disabled {
    background: #94D2BD;
    border-color: #94D2BD;
    cursor: not-allowed;
    opacity: 0.8;
}

/* Response Status Animation */
.storex-response-status {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 20px;
    background: linear-gradient(135deg, #E9D8A6, #D4A574);
    border-radius: 15px;
    margin: 10px 20px;
    font-family: 'Vazir', sans-serif;
    font-size: 13px;
    color: #1D1F27;
    font-weight: 500;
    animation: fadeInUp 0.3s ease-out;
}

.storex-response-status .status-icon {
    font-size: 16px;
    animation: pulse 1.5s ease-in-out infinite;
}

.storex-response-status .status-text {
    flex: 1;
    text-align: center;
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes pulse {
    0%, 100% {
        transform: scale(1);
        opacity: 1;
    }
    50% {
        transform: scale(1.1);
        opacity: 0.7;
    }
}

.storex-typing {
    display: inline-flex;
    gap: 6px;
    align-items: center;
}

.storex-typing-dot {
    width: 8px;
    height: 8px;
    background: #009893;
    border-radius: 50%;
    animation: typing 1.4s infinite ease-in-out;
}

.storex-typing-dot:nth-child(1) { animation-delay: -0.32s; }
.storex-typing-dot:nth-child(2) { animation-delay: -0.16s; }

@keyframes typing {
    0%, 80%, 100% {
        transform: scale(0.8);
        opacity: 0.5;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* Scrollbar Styling */
#storex-chat-messages::-webkit-scrollbar {
    width: 6px;
}

#storex-chat-messages::-webkit-scrollbar-track {
    background: #F7F7F7;
}

#storex-chat-messages::-webkit-scrollbar-thumb {
    background: #94D2BD;
    border-radius: 3px;
}

#storex-chat-messages::-webkit-scrollbar-thumb:hover {
    background: #009893;
}

/* Responsive Design */
@media (max-width: 480px) {
    #storex-chat-window {
        width: calc(100vw - 40px);
        right: 0;
        left: 20px;
        height: 450px;
    }
    
    #storex-chat-button {
        width: 55px;
        height: 55px;
    }
    
    #storex-chat-button img {
        width: 30px;
        height: 30px;
        object-fit: contain;
    }
    
    #storex-ticket-button {
        padding: 10px 20px;
        font-size: 13px;
        min-width: 120px;
    }
}

/* Ensure chat window stays visible on medium screens */
@media (max-width: 768px) {
    #storex-chat-window {
        width: 320px;
        right: 0;
    }
}

/* For very small screens, position chat window to the left */
@media (max-width: 400px) {
    #storex-chat-window {
        width: calc(100vw - 20px);
        right: 10px;
        left: 10px;
    }
}

/* RTL Support */
/* Chat widget stays in bottom-right for all languages */

.rtl #storex-chat-window {
    right: auto;
    left: 0;
}

.rtl .storex-user-message {
    flex-direction: row;
}

.rtl .storex-bot-message {
    flex-direction: row;
}

.rtl .storex-bot-message .storex-message-content {
    border-bottom-left-radius: 18px;
    border-top-right-radius: 5px;
    margin-left: 10px;
    margin-right: 0;
}

.rtl .storex-user-message .storex-message-content {
    border-bottom-right-radius: 18px;
    border-top-left-radius: 5px;
    margin-right: 10px;
    margin-left: 0;
}

/* RTL Tooltip positioning */
.rtl #storex-chat-button::before {
    right: 4.3rem;
}

.rtl #storex-chat-button::after {
    right: auto;
    left: -8px;
    border-left-color: transparent;
    border-right-color: #1D1F27;
    filter: drop-shadow(2px 0 4px rgba(0, 0, 0, 0.3));
}

/* Force RTL for all chat content */
#storex-chat-messages {
    direction: rtl;
}

#storex-chat-messages .storex-message {
    direction: rtl;
}

#storex-chat-messages .storex-message-content {
    direction: rtl;
    text-align: justify;
}

/* RTL placeholder text */
#storex-message-input::placeholder {
    direction: rtl;
    text-align: right;
}

/* Custom CSS Variables for Dynamic Colors */
#storex-chat-widget {
    --primary-color: #009893;
    --secondary-color: #E9D8A6;
    --accent-color: #EE9B00;
    --dark-color: #1D1F27;
    --light-color: #F7F7F7;
    --neutral-color: #94D2BD;
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    #storex-chat-window {
        background: #1D1F27;
    }
    
    #storex-chat-messages {
        background: #1D1F27;
    }
    
    .storex-bot-message .storex-message-content {
        background: #2C2C2C;
        color: #F7F7F7;
    }
    
    .storex-avatar {
        background-color: #2D2F37;
        border-color: #444;
    }
    
    #storex-message-input {
        background: #2C2C2C;
        border-color: #559AE6;
        color: #F7F7F7;
    }
    
    #storex-message-input:focus {
        background: #1D1F27;
        border-color: #009893;
    }
    
    #storex-chat-input {
        background: #1D1F27;
        border-top-color: #2C2C2C;
    }
    
    #storex-api-selector {
        background-color: rgba(45, 47, 55, 0.95);
        border-color: #444;
    }

    /* Make API selector panel dark so white text is visible */
    #storex-api-selector .storex-api-panel {
        background: #2D2F37;
        border-color: #444;
    }
    
    .storex-api-selector-title {
        color: #F7F7F7;
    }
    
    .storex-api-btn {
        background-color: #1D1F27;
        border-color: #444;
        color: #fff;
    }
    
    .storex-api-btn:hover {
        border-color: var(--storex-primary);
        background-color: #2D2F37;
    }
    
    
    #storex-ticket-section {
        background: #1D1F27;
        border-top-color: #2C2C2C;
    }
    
    .storex-response-status {
        background: linear-gradient(135deg, #2C2C2C, #3A3A3A);
        color: #F7F7F7;
    }
}
