@import url('https://fonts.googleapis.com/css2?family=Vazirmatn:wght@300;400;500&display=swap');

/* --- General Styles for Chatbot --- */
#danak-chat-container {
    font-family: 'Vazirmatn', sans-serif;
    direction: rtl;
    width: 380px;
    max-width: 90vw;
    height: 70vh;
    max-height: 650px;
    border: 1px solid #333;
    border-radius: 15px;
    overflow: hidden;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
    background: #1a1a1a;
    display: flex;
    flex-direction: column;
}

/* --- Positioning Logic: Shortcode vs Floating --- */
/* By default, it's inline for shortcode */
#danak-chat-container {
    margin: 20px auto;
}
/* When used with floating button, it becomes fixed */
body > #danak-chat-container {
    position: fixed;
    bottom: 100px;
    left: 20px;
    margin: 0;
    z-index: 99998;
    transition: transform 0.3s ease-in-out, opacity 0.3s ease-in-out, visibility 0.3s;
}

/* --- Visibility States for Floating Mode --- */
body > #danak-chat-container.danak-chat-hidden {
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px) scale(0.95);
}
body > #danak-chat-container.danak-chat-visible {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
}

/* --- Chat Header --- */
#danak-chat-header {
    background: var(--danak-chatbot-primary-color);
    color: var(--danak-chatbot-title-color);
    padding: 12px 20px;
    text-align: center;
    font-size: 1.1em;
    font-weight: 500;
    border-bottom: 1px solid #444;
}

/* --- Chat Window & Messages --- */
#danak-chat-window {
    flex-grow: 1;
    padding: 20px;
    overflow-y: auto;
    background-color: #f5f2eb;
    display: flex;
    flex-direction: column;
}

.user-message, .bot-message {
    max-width: 80%;
    margin-bottom: 15px;
    padding: 10px 15px;
    border-radius: 20px;
    line-height: 1.6;
    word-wrap: break-word;
}

.user-message {
    background-color: var(--danak-chatbot-primary-color);
    color: #1a1a1a;
    border-bottom-right-radius: 5px;
    align-self: flex-end;
}

.bot-message {
    background-color: #ffffff;
    color: #333;
    border: 1px solid #e0e0e0;
    border-bottom-left-radius: 5px;
    align-self: flex-start;
}

.bot-message p, .user-message p { margin: 0; }

/* --- Input Area --- */
#danak-chat-input-area {
    border-top: 1px solid #333;
    padding: 10px;
    background-color: #f5f5f5;
}
#danak-chat-form { display: flex; align-items: center; }
#danak-user-input {
    flex-grow: 1; border: 1px solid #ccc; border-radius: 20px;
    padding: 10px 15px; font-size: 1em; font-family: 'Vazirmatn', sans-serif;
    outline: none; background: #fff; color: #333;
}
#danak-user-input:focus { border-color: var(--danak-chatbot-primary-color); }
#danak-send-btn {
    background-color: var(--danak-chatbot-primary-color);
    border: none; border-radius: 50%; width: 40px; height: 40px;
    margin-right: 10px; cursor: pointer; display: flex;
    align-items: center; justify-content: center;
    transition: filter 0.2s;
    overflow: hidden;
}
#danak-send-btn:hover { filter: brightness(0.9); }
#danak-send-btn svg { fill: #1a1a1a; transform: rotate(180deg); width: 22px; /* <<< این خط را اضافه کنید تا اندازه کنترل شود */
    height: 22px; /* <<< این خط را اضافه کنید تا اندازه کنترل شود */ }

/* --- Typing Indicator --- */
.typing-indicator { align-self: flex-start; padding: 10px 15px; }
.typing-indicator span { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background-color: #999; animation: typing 1.4s infinite; margin: 0 2px; }
.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }
@keyframes typing { 0%, 80%, 100% { transform: scale(0); } 40% { transform: scale(1.0); } }

/* --- Floating Button --- */
#danak-floating-chat-button {
    position: fixed;
    bottom: 20px;
    left: 20px;
    width: 60px;
    height: 60px;
    background-color: var(--danak-chatbot-button-color);
    border-radius: 50%;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 99999;
    transition: transform 0.2s ease-in-out;
}
#danak-floating-chat-button:hover { transform: scale(1.1); }
#danak-floating-chat-button svg { fill: #ffffff; }

/* --- Popup Modal Styles --- */

#danak-fab {
    position: fixed;

    width: 60px;
    height: 60px;
    background: var(--danak-chatbot-button-color, #a88f59); /* Use variable with fallback */
    border-radius: 50%;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 99998;
    transition: transform 0.2s ease-in-out;
}

#danak-fab:hover {
    transform: scale(1.1);
}

#danak-fab svg {
    fill: #ffffff;
}

#danak-popup-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.6);
    /* عدد بسیار بزرگ برای اطمینان از قرارگیری روی همه چیز */
    z-index: 2147483640; /* تقریبا ماکسیمم مقدار مجاز مرورگرها */
    display: none;
    opacity: 0;
    transition: opacity 0.3s ease;
}

#danak-popup-overlay.active {
    display: block;
    opacity: 1;
}

/* Popup Modal Window - NEW Positioning */
#danak-popup-modal {
    position: fixed;

    /* --- Animation Logic --- */
    transform: translateY(20px) scale(0.98); /* Start slightly lower and smaller */
    z-index: 2147483647;
    
    opacity: 0; /* Start fully transparent */
    visibility: hidden; /* Start completely hidden and unclickable */
    
    transition: opacity 0.3s ease, transform 0.3s ease, visibility 0.3s; /* Animate all properties */
}

#danak-popup-modal.active {
    opacity: 1; /* Become fully visible */
    visibility: visible; /* Become visible and clickable */
    transform: translateY(0) scale(1); /* Move to final position and full size */
}

#danak-popup-content {
    background-color: transparent; /* The chatbot itself has the background */
    border-radius: 15px;
    overflow: hidden;
    width: 380px; /* Match chatbot width */
    max-width: 90vw;
    display: flex;
    flex-direction: column;
}

/* Override the main chatbot styles when inside the popup */
#danak-popup-content #danak-chat-container {
    width: 100%;
    height: 70vh; /* Match chatbot height */
    max-height: 650px;
    margin: 0;
    border: none;
    box-shadow: none;
}

#danak-popup-close {
    position: absolute;
    top: -15px;
    right: -15px;
    background-color: white;
    color: var(--danak-chatbot-primary-color, #d4af37);
    border: 2px solid var(--danak-chatbot-primary-color, #d4af37);
    width: 36px;
    height: 36px;
    border-radius: 50%;
    font-size: 28px;
    line-height: 32px;
    text-align: center;
    cursor: pointer;
    font-weight: bold;
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
}

/* --- NEW: Animated Floating Button Styles (Original Structure + Fix) --- */

/* 1. Breathing animation for the main button */
@keyframes danakPulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.05); }
    100% { transform: scale(1); }
}

/* 1b. INVERSE animation to keep the icon stable */
@keyframes danakIconInversePulse {
    0% { transform: translate(-50%, -50%) scale(1); }
    50% { transform: translate(-50%, -50%) scale(0.952); } /* 1 / 1.05 ≈ 0.952 */
    100% { transform: translate(-50%, -50%) scale(1); }
}

/* 2. Base styles for the FAB */
#danak-fab {
    position: fixed;
    bottom: 25px;
    left: 25px;
    width: 60px;
    height: 60px;
    z-index: 2147483645;
    cursor: pointer;
    overflow: hidden;
    
    /* Apply the main pulse animation */
    animation: danakPulse 2.5s infinite ease-in-out;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2); /* Keep the shadow static */
    transition: transform 0.2s ease-in-out; /* Add transition for hover */
}

#danak-fab:hover {
    animation-play-state: paused;
    transform: scale(1.1);
}

/* 3. Style for the icon wrappers */
.danak-fab-icon {
    position: absolute;
    top: 50%;
    left: 50%;
    
    /* Apply the INVERSE pulse animation */
    animation: danakIconInversePulse 2.5s infinite ease-in-out;
    
    /* Transition for the open/close FADE effect */
    transition: opacity 0.3s ease-out;
    color: #ffffff;
}
/* <<< این بلوک کد جدید را اضافه کنید >>> */
.danak-fab-icon svg {
    display: block; /* Removes any extra space below the svg */
}

/* Specific size for the chat icon */
.danak-fab-svg-chat {
    width: 35px;
    height: 35px;
}

/* Specific (and larger) size for the robot icon to compensate for its viewBox */
.danak-fab-svg-robot {
    width: 62px;
    height: 62px;
}

/* Don't forget the close icon! */
.danak-fab-icon-close svg {
    width: 28px;
    height: 28px;
}

#danak-fab:hover .danak-fab-icon {
    animation: none; /* Stop the icon's inverse animation on hover */
    transform: translate(-50%, -50%) scale(1) !important; /* Force icon to reset to its original state */
}


.danak-fab-icon svg {
    display: block;
}

/* 4. Icon visibility logic (Simplified to FADE only, no rotation/scale) */
#danak-fab .danak-fab-icon-open {
    opacity: 1;
}
#danak-fab .danak-fab-icon-close {
    opacity: 0;
    pointer-events: none;
}

#danak-fab.is-open .danak-fab-icon-open {
    opacity: 0;
    pointer-events: none;
}
#danak-fab.is-open .danak-fab-icon-close {
    opacity: 1;
}

/* --- NEW: Live Status Indicator Styles (Upgraded with Glow Effect) --- */

/* 1. Make the header a flex container to align items easily */
#danak-chat-header {
    display: flex;
    align-items: center;
    justify-content: center;
}

/* 2. Style the indicator dot itself */
.danak-status-indicator {
    width: 10px;
    height: 10px;
    background-color: #2ecc71; /* A vibrant green */
    border-radius: 50%;
    margin-left: 8px; /* Space between the dot and the text */
    
    /* 3. Attach the animation */
    animation: danakGlowPulse 2s infinite ease-in-out;
}

/* 4. Define the NEW pulse animation that includes the glow effect */
@keyframes danakGlowPulse {
    0% {
        transform: scale(1);
        /* The initial, subtle glow */
        box-shadow: 0 0 6px 0 rgba(46, 204, 113, 0.7);
    }
    50% {
        transform: scale(1.2);
        /* The expanded, more intense glow at the peak of the pulse */
        box-shadow: 0 0 10px 2px rgba(46, 204, 113, 0.8);
    }
    100% {
        transform: scale(1);
        /* Return to the initial glow */
        box-shadow: 0 0 6px 0 rgba(46, 204, 113, 0.7);
    }
}

/* --- NEW: Branding Footer Styles --- */
.danak-chat-footer {
    text-align: center;
    padding: 2px 0;
    background-color: #f0f0f0; /* A slightly different background */
    border-top: 1px solid #e0e0e0;
}

.danak-chat-footer a {
    font-size: 12px;
    color: #888; /* Subtle gray color */
    text-decoration: none;
    transition: color 0.2s;
}

.danak-chat-footer a:hover {
    color: #555; /* Slightly darker on hover */
    text-decoration: underline;
}

/*
 * ===============================================
 * Universal Link Styling for Readability
 * ===============================================
 * Ensures links inside the chat window are always visible and match the theme color.
*/

#danak-chat-window .bot-message p a {
    /* Use the primary color variable defined by the user in settings */
    color: var(--danak-chatbot-primary-color, #d4af37);
    
    /* Make it slightly bolder and underlined to stand out */
    font-weight: 500; /* Use 500 for a semi-bold look */
    text-decoration: underline;
    
    /* Smooth transition for hover effect */
    transition: opacity 0.2s ease;
}

/* Make the link slightly lighter/faded on hover */
#danak-chat-window .bot-message p a:hover {
    opacity: 0.8;
}

/* Fix for long URLs breaking out of the chat bubble */
#danak-chat-window .bot-message p a,
#danak-chat-window .user-message p a {
    word-break: break-all;
    overflow-wrap: break-word; /* For better compatibility */
}

/* Ensure normal text still behaves correctly */
#danak-chat-window .bot-message p,
#danak-chat-window .user-message p {
    overflow-wrap: break-word; /* This is safe for normal text */
    white-space: pre-wrap;     /* This respects newlines from the AI */
}

/* --- NEW: Header Close Button Styles --- */

/* 1. Make the header a positioning context for the button */
#danak-chat-header {
    position: relative;
    /* Adjust padding to prevent title from overlapping the new button */
    padding: 12px 40px; 
}

/* 2. Style the close button itself */
#danak-header-close-btn {
    position: absolute;
    top: 50%;
    left: 10px; /* 10px from the left edge */
    transform: translateY(-50%); /* Vertically center it */
    cursor: pointer;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.2s;
}

/* 3. Style the SVG icon inside the button */
#danak-header-close-btn svg {
    width: 20px;
    height: 20px;
    fill: var(--danak-chatbot-title-color, #1a1a1a); /* Use the title color variable */
}

/* 4. Add a hover effect for better user experience */
#danak-header-close-btn:hover {
    opacity: 0.7;
}

/* --- NEW & UPGRADED: Dynamic & Minimal FAQ List Styles --- */

#danak-faq-container {
    padding: 0;
    border-top: 1px solid #e0e0e0;
    background-color: #f5f2eb; /* Fallback background */
}

/* The clickable header bar */
.danak-faq-header {
    font-size: 14px;
    font-weight: 500;
    color: #555;
    padding: 8px 15px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: background-color 0.2s, color 0.2s;
    position: relative; /* For the subtle bottom border */
}

/* Add a subtle underline that appears on hover */
.danak-faq-header::after {
    content: '';
    position: absolute;
    bottom: 0;
    right: 15px;
    left: 15px;
    height: 1px;
    background-color: #e0e0e0;
    transform: scaleX(0);
    transition: transform 0.3s ease;
}

.danak-faq-header:hover::after {
    transform: scaleX(1);
}

.danak-faq-header svg {
    width: 22px;
    height: 22px;
    fill: #888; /* A lighter color for the icon */
    transition: transform 0.3s ease-in-out, fill 0.2s;
}

.danak-faq-header:hover svg {
    fill: var(--danak-chatbot-primary-color, #d4af37); /* Use primary color on hover */
}

/* Rotate the header icon when active */
.danak-faq-header.active svg {
    transform: rotate(90deg);
}
.danak-faq-header.active {
    color: var(--danak-chatbot-primary-color, #d4af37); /* Use primary color for text when active */
}

/* The wrapper that slides up/down */
.danak-faq-items-wrapper {
    display: none;
    background-color: #ffffff;
    border-top: 1px solid #e0e0e0;
    padding: 5px 0;
    max-height: 150px;
    overflow-y: auto;
}

/* Custom scrollbar (remains the same) */
.danak-faq-items-wrapper::-webkit-scrollbar { width: 6px; }
.danak-faq-items-wrapper::-webkit-scrollbar-track { background: #f1f1f1; }
.danak-faq-items-wrapper::-webkit-scrollbar-thumb { background: #ccc; border-radius: 3px; }
.danac-faq-items-wrapper::-webkit-scrollbar-thumb:hover { background: #aaa; }


/* Container for the vertical buttons */
.danak-faq-items {
    display: flex;
    flex-direction: column;
}

/* Style for each question button */
.danak-faq-question {
    font-family: 'Vazirmatn', sans-serif;
    display: flex;
    align-items: center;
    width: 100%;
    text-align: right;
    padding: 10px 20px;
    background: none;
    border: none; /* Ensure no borders are applied */
    cursor: pointer;
    font-size: 14px;
    color: #444;
    transition: background-color 0.2s, color 0.2s, padding-right 0.2s ease;
    
    position: relative; /* Make it a positioning context for the pseudo-element */
}

/* --- NEW: Use ::after for a more stable separator line --- */
.danak-faq-question::after {
    content: '';
    position: absolute;
    bottom: 0;
    right: 20px; /* Match the right padding */
    left: 20px;  /* Match the left padding */
    height: 1px;
    background-color: #f0f0f0; /* The separator color */
}

/* Remove the separator line from the very last item in the list */
.danak-faq-items .danak-faq-question:last-child::after {
    display: none;
}

/* --- UPDATED: Use box-shadow for the hover effect --- */
.danak-faq-question:hover {
    background-color: rgba(212, 175, 55, 0.05);
    color: var(--danak-chatbot-primary-color, #d4af37);
    padding-right: 25px;
    
    /* Create the right-edge line using an inset box-shadow. This is more stable. */
    box-shadow: inset 3px 0 0 0 var(--danak-chatbot-primary-color, #d4af37);
}

/* Style for the small icon (remains mostly the same) */
.danak-faq-question .danak-faq-q-icon {
    width: 16px;
    height: 16px;
    fill: #bbb;
    margin-left: 10px;
    transition: fill 0.2s;
}

.danak-faq-question:hover .danak-faq-q-icon {
    fill: var(--danak-chatbot-primary-color, #d4af37);
}

.danak-faq-question span {
    flex-grow: 1;
}

/* --- FINAL & STABLE HEADER LAYOUT --- */

#danak-chat-header {
    position: relative; /* Essential for absolute positioning of children */
    display: flex;
    justify-content: center; /* Horizontally center the title and status dot */
    align-items: center;     /* Vertically center everything */
    padding: 8px 15px;
}

#danak-header-close-btn {
    position: absolute;
    top: 50%;
    left: 15px; /* Position from the left edge of the header */
    transform: translateY(-50%); /* Perfect vertical centering */
    cursor: pointer;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.2s;
}

#danak-clear-history-btn {
    position: absolute;
    top: 50%;
    right: 15px; 
    transform: translateY(-50%);
    cursor: pointer;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.2s, transform 0.3s;
}

#danak-header-close-btn svg, #danak-clear-history-btn svg {
    width: 20px;
    height: 20px;
    fill: var(--danak-chatbot-title-color, #1a1a1a);
}

#danak-header-close-btn:hover, #danak-clear-history-btn:hover {
    opacity: 0.7;
}

#danak-clear-history-btn:hover {
    transform: translateY(-50%) rotate(-90deg);
}
/* The status indicator and title span don't need extra styles, flexbox handles them */

/* تنظیم چیدمان فرم برای اینکه دکمه‌ها کنار هم باشند */
#danak-chat-form {
    display: flex;
    align-items: center;
    gap: 5px; /* فاصله بین دکمه‌ها */
}

/* استایل دکمه ارسال شما (برای اطمینان از فیکس بودن سایز) */
#danak-send-btn {
    flex-shrink: 0; /* جلوگیری از جمع شدن دکمه */
    width: 40px;
    height: 40px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

#danak-send-btn svg {
    width: 24px;
    height: 24px;
}

/* استایل دکمه میکروفون */
#danak-mic-btn {
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 5px;
    color: #888;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px; /* سایز ثابت */
    height: 40px; /* سایز ثابت */
    border-radius: 50%;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

#danak-mic-btn:hover {
    background-color: rgba(0,0,0,0.05);
    color: var(--danak-chatbot-primary-color);
}

/* انیمیشن وقتی در حال ضبط است */
#danak-mic-btn.is-listening {
    color: #e74c3c !important;
    background-color: rgba(231, 76, 60, 0.1);
    animation: micPulse 1.5s infinite;
}

@keyframes micPulse {
    0% { transform: scale(1); box-shadow: 0 0 0 0 rgba(231, 76, 60, 0.7); }
    70% { transform: scale(1.1); box-shadow: 0 0 0 8px rgba(231, 76, 60, 0); }
    100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(231, 76, 60, 0); }
}