/**
 * JAMIL-AI Frontend Stylesheet
 * Description: Modern, responsive, and animated styles for the
 * AI-powered chat widget.
 * Version: 3.0.0 (Consolidated Fixes)
 */

/* --- 1. Root Variables for Easy Theming --- */
:root {
    --jamil-color-primary: #007bff;
    --jamil-color-primary-text: #ffffff;
    --jamil-color-secondary: #f0f2f5;
    --jamil-color-bot-bubble: #e4e6eb;
    --jamil-color-text-dark: #1c1e21;
    --jamil-color-text-light: #65676b;
    --jamil-font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    --jamil-border-radius-widget: 12px;
    --jamil-border-radius-bubble: 18px;
    --jamil-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    --jamil-transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
}


/* --- 2. Main Toggle Button --- */
.jamil-ai-toggle-btn {
    position: fixed;
    bottom: 20px;
    right: 20px;
    background-color: var(--jamil-color-primary);
    color: var(--jamil-color-primary-text);
    border-radius: 50px;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--jamil-shadow);
    cursor: pointer;
    z-index: 99998;
    transition: var(--jamil-transition);
    transform: scale(1);
    padding: 12px 20px;
    gap: 10px;
    overflow: hidden;
}

.jamil-ai-toggle-text {
    font-weight: 600;
    font-size: 16px;
    line-height: 1;
    white-space: nowrap;
}

.jamil-ai-toggle-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
}

.jamil-ai-toggle-btn .jamil-ai-toggle-icon {
    font-size: 28px;
    line-height: 1;
}

.jamil-ai-toggle-btn.is-hidden {
    transform: scale(0);
    opacity: 0;
    pointer-events: none;
}


/* --- 3. Chatbox Container --- */
.jamil-ai-chatbox {
    position: fixed;
    bottom: 40px;
    right: 20px;
    width: 360px;
    height: 90vh;
    max-height: 550px;
    background-color: #fff;
    border-radius: var(--jamil-border-radius-widget);
    box-shadow: var(--jamil-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden; /* CORRECTED: Reverted from clip to hidden for better compatibility */
    z-index: 99999;
    font-family: var(--jamil-font-family);
    transform: translateY(20px) scale(0.95);
    opacity: 0;
    visibility: hidden;
    transition: var(--jamil-transition);
}

.jamil-ai-chatbox.open {
    transform: translateY(0) scale(1);
    opacity: 1;
    visibility: visible;
}


/* --- 4. Chatbox Header --- */
.jamil-ai-header {
    background-color: var(--jamil-color-primary);
    color: var(--jamil-color-primary-text);
    padding: 12px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
    position: relative; 
    z-index: 3;
}

.jamil-ai-header .jamil-ai-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    margin-right: 12px;
    border: 2px solid rgba(255, 255, 255, 0.5);
    position: relative;
}

.jamil-ai-header .jamil-ai-avatar img {
    position: relative;
    z-index: 2;
    border-radius: 50%;
    display: block;
    width: 100%;
    height: 100%;
}

.jamil-ai-header .jamil-ai-title {
    font-size: 16px;
    font-weight: 600;
    flex-grow: 1;
}

.jamil-ai-header .jamil-ai-close-btn {
    background: none; border: none;
    color: var(--jamil-color-primary-text);
    font-size: 24px; font-weight: 300;
    cursor: pointer; opacity: 0.8;
    transition: opacity 0.2s;
}

.jamil-ai-header .jamil-ai-close-btn:hover {
    opacity: 1;
}


/* --- 5. Messages Area --- */
.jamil-ai-messages {
    flex-grow: 1;
    background-color: var(--jamil-color-secondary);
    padding: 16px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 4px;
    position: relative;
    z-index: 2;
}

.jamil-ai-message-wrapper {
    display: flex; flex-direction: column;
    max-width: 85%;
    animation: fadeIn 0.4s ease-out;
}

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

.jamil-ai-message-user { align-self: flex-end; }
.jamil-ai-message-bot { align-self: flex-start; }

.jamil-ai-message {
    padding: 10px 14px;
    border-radius: var(--jamil-border-radius-bubble);
    line-height: 1.4; word-wrap: break-word;
}

.jamil-ai-message-user .jamil-ai-message {
    background-image: linear-gradient(45deg, #007bff, #0056b3);
    color: var(--jamil-color-primary-text);
    border-bottom-right-radius: 4px;
}

.jamil-ai-message-bot .jamil-ai-message {
    background-color: var(--jamil-color-bot-bubble);
    color: var(--jamil-color-text-dark);
    border-bottom-left-radius: 4px;
}
.jamil-ai-message-text { font-size: 15px; }

.jamil-ai-message-timestamp {
    font-size: 11px;
    color: var(--jamil-color-text-light);
    margin-top: 5px;
    text-align: right;
    opacity: 0.7;
}

.jamil-ai-message-user .jamil-ai-message-timestamp {
    color: rgba(255, 255, 255, 0.7);
}


/* --- 6. Input & Form Area --- */
.jamil-ai-input-area {
    display: flex; align-items: center;
    padding: 12px;
    background-color: #fff;
    position: relative;
    border-top: 1px solid #ddd;
    z-index: 2;
}

.jamil-ai-input-area .jamil-ai-input {
    flex-grow: 1; border: none; padding: 10px;
    font-size: 15px; resize: none; background-color: transparent;
}
.jamil-ai-input-area .jamil-ai-input:focus { outline: none; }
.jamil-ai-input-area .jamil-ai-send-btn {
    background: none; border: none; width: 36px; height: 36px;
    font-size: 20px; color: var(--jamil-color-primary); cursor: pointer;
    border-radius: 50%; display: flex; align-items: center; justify-content: center;
}
.jamil-ai-input-area .jamil-ai-send-btn:hover { background-color: rgba(0, 0, 0, 0.05); }


/* --- 7. Mobile Responsiveness --- */
@media (max-width: 480px) {
    .jamil-ai-toggle-btn { bottom: 16px; right: 16px; }
    .jamil-ai-chatbox {
        width: calc(100% - 32px); height: 95%; max-height: 700px;
        bottom: 16px; right: 16px; border-radius: 12px; z-index: 100000;
    }
}


/* --- 8. ANIMATION KEYFRAMES --- */
@keyframes jamil-ai-sweep {
    0% { background-position: 150% 0; }
    100% { background-position: -150% 0; }
}
@keyframes jamil-ai-spin-border {
    to { transform: rotate(360deg); }
}
@keyframes typing-blink {
    0%, 80%, 100% { transform: scale(0); opacity: 0; }
    40% { transform: scale(1); opacity: 1; }
}


/* --- 9. MAIN CHATBOX BORDER --- */
.jamil-ai-chatbox::before {
    content: '';
    position: absolute;
    z-index: 1;
    inset: 0;
    border-radius: var(--jamil-border-radius-widget);
    padding: 2px;
    background: conic-gradient(from 180deg at 50% 50%, #4285F4, #EA4335, #FBBC05, #34A853, #4285F4);
    -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
    -webkit-mask-composite: xor;
    mask-composite: exclude;
    animation: jamil-ai-spin-border 4s linear infinite;
    opacity: 0;
    transition: opacity 0.5s ease;
}

.jamil-ai-chatbox.open::before {
    opacity: 1;
}


/* --- 10. THIN LINE & AVATAR ANIMATIONS --- */
.jamil-ai-messages::before,
.jamil-ai-input-area::before {
    content: '';
    position: absolute;
    left: 0; right: 0;
    height: 6px;
    background-image: linear-gradient(to right, transparent, #4285F4, #EA4335, #FBBC05, #34A853, #4285F4, transparent);
    background-size: 200% 100%;
    animation: jamil-ai-sweep 4s linear infinite;
    opacity: 0;
    transition: opacity 0.5s ease-in-out;
}
.jamil-ai-messages::before { top: 0; }
.jamil-ai-input-area::before { top: -1px; }

.jamil-ai-header .jamil-ai-avatar::after {
    content: '';
    position: absolute;
    inset: -3px;
    border-radius: 50%;
    border: 2px solid transparent;
    background: conic-gradient(from 90deg at 50% 50%, #FBBC05, #EA4335, #4285F4, #34A853, #FBBC05) border-box;
    -webkit-mask: linear-gradient(#fff 0 0) padding-box, linear-gradient(#fff 0 0);
    -webkit-mask-composite: destination-out;
    mask-composite: exclude;
    animation: jamil-ai-spin-border 3s linear infinite;
    opacity: 0;
    transition: opacity 0.5s ease;
}

.jamil-ai-chatbox.open .jamil-ai-messages::before,
.jamil-ai-chatbox.open .jamil-ai-input-area::before,
.jamil-ai-chatbox.open .jamil-ai-header .jamil-ai-avatar::after {
    opacity: 1;
}

.jamil-ai-chatbox.open .jamil-ai-input-area.sending-pulse::before {
    animation-duration: 0.8s;
}


/* --- 11. TYPING INDICATOR --- */
.jamil-ai-typing .jamil-ai-message-text {
    display: flex;
    align-items: center;
    gap: 5px;
}
.jamil-ai-typing .typing-dot {
    width: 8px;
    height: 8px;
    background-color: var(--jamil-color-text-light);
    border-radius: 50%;
    animation: typing-blink 1.4s infinite both;
}
.jamil-ai-typing .typing-dot:nth-child(2) { animation-delay: 0.2s; }
.jamil-ai-typing .typing-dot:nth-child(3) { animation-delay: 0.4s; }


/* --- 12. MARKDOWN & SUGGESTED REPLIES --- */
.jamil-ai-message-text ul,
.jamil-ai-message-text ol {
    padding-left: 20px;
    margin: 8px 0;
}
.jamil-ai-message-text li {
    margin-bottom: 4px;
}
.jamil-ai-message-text strong {
    font-weight: 600;
}
.jamil-ai-reply-chips {
    padding: 8px 16px 12px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    background-color: var(--jamil-color-secondary);
    z-index: 2;
}
.jamil-ai-chip {
    background-color: #fff;
    color: var(--jamil-color-primary);
    border: 1px solid var(--jamil-color-primary);
    border-radius: 20px;
    padding: 8px 16px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}
.jamil-ai-chip:hover {
    background-color: var(--jamil-color-primary);
    color: #fff;
}


/* --- 13. CONTACT FORM --- */
.jamil-ai-contact-form {
    padding: 16px;
    border-top: 1px solid #ddd;
    background: #fff;
    z-index: 2;
    /* CORRECTED: Removed position: relative */
}
.jamil-ai-contact-form .jamil-ai-form-group { margin-bottom: 12px; }
.jamil-ai-contact-form label {
    font-size: 14px;
    font-weight: 500;
    margin-bottom: 4px;
    display: block;
}
.jamil-ai-contact-form input[type="text"],
.jamil-ai-contact-form input[type="email"] {
    width: 100%;
    padding: 10px;
    border: 1px solid #ccc;
    border-radius: 6px;
    font-size: 15px;
}
.jamil-ai-contact-form .jamil-ai-btn {
    width: 100%;
    padding: 12px;
    border: none;
    border-radius: 6px;
    background-color: var(--jamil-color-primary);
    color: var(--jamil-color-primary-text);
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
}