#aichat-widget {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 9999;
}

#aichat-widget *:not(.material-symbols-rounded) {
    font-family: 'Poppins', sans-serif !important;
}

.material-symbols-rounded {
    font-family: 'Material Symbols Rounded' !important;

    /* ... lines 12-129 ... */
    .aichat-message-content {
        display: inline-block;
        /* --- ADJUST BUBBLE PADDING HERE --- */
        padding: 8px 12px;

        /* --- ADJUST FONT THICKNESS HERE --- */
        /* 400=Regular, 500=Medium, 600=SemiBold */
        font-weight: 400;

        border-radius: 18px;
        max-width: 80%;
        word-wrap: break-word;
        /* Improved typography */
        line-height: 1.5;
    }

    font-weight: normal;
    font-style: normal;
    display: inline-block;
    line-height: 1;
    text-transform: none;
    letter-spacing: normal;
    word-wrap: normal;
    white-space: nowrap;
    direction: ltr;
}

#aichat-toggle {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, #006FBA 0%, #2481e4 100%);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.3s ease;
}

#aichat-toggle:hover {
    transform: scale(1.1);
}

#aichat-container {
    position: absolute;
    /* --- ADJUST POSITION HERE --- */
    bottom: 75px;
    right: 5px;

    /* --- ADJUST SIZE HERE --- */
    /* Width: Min 300px, Max 400px, but responsive */
    width: clamp(350px, 85vw, 350px);
    /* Height: Min 500px, Max 700px, but responsive */
    height: clamp(400px, 75vh, 600px);

    /* Safety caps to keep it on screen */
    max-height: calc(100vh - 120px);
    max-width: calc(100vw - 40px);

    background: white;
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

#aichat-header {
    background: linear-gradient(135deg, #006FBA 0%, #2481e4 100%);
    color: white;
    /* --- ADJUST HEADER PADDING HERE --- */
    /* 12px = Top/Bottom, 17px = Left/Right */
    padding: 17px 17px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

#aichat-header h3 {
    margin: 0;
    color: white;
    font-weight: 600;
    display: flex;
    align-items: center;
}

#aichat-header h3 span {
    display: inline-block;
    vertical-align: middle;
}

#aichat-close {
    background: none;
    border: none;
    color: white;
    font-size: 20px;
    cursor: pointer;
    padding: 0;
    line-height: 1;
}

#aichat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background: #f7f9fc;
}

.aichat-message {
    margin-bottom: 16px;
    animation: slideIn 0.3s ease;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.aichat-message-user {
    text-align: right;
}

.aichat-message-bot {
    text-align: left;
}

.aichat-message-content {
    display: inline-block;
    padding: 8px 12px;
    border-radius: 18px;
    max-width: 80%;
    word-wrap: break-word;
    font-weight: 400;
    line-height: 1.5;
    font-size: clamp(13px, 2.5vw, 14px) !important;
    font-style: normal !important;
}

.aichat-message-content p,
.aichat-message-content ul,
.aichat-message-content ol,
.aichat-message-content li,
.aichat-message-content span {
    font-size: inherit !important;
    line-height: inherit !important;
}

.aichat-message-user .aichat-message-content {
    background: linear-gradient(135deg, #006FBA 0%, #2481e4 100%);
    color: white;
    text-align: left;
    /* Keep user text left or regular */
}

.aichat-message-bot .aichat-message-content {
    background: white;
    color: #333;
    border: 1px solid #e1e8ed;
    width: 100%;
    /* Allow full width up to max-width */
    text-align: left;
    /* Default alignment */
}

/* Markdown Styles (Consolidated at the bottom) */
.aichat-message-content p {
    margin: 0 0 4px 0 !important;
    text-align: left;
}

.aichat-message-content p:last-child {
    margin-bottom: 0;
}

.aichat-message-content strong {
    font-weight: 700;
}

#aichat-actions {
    padding: 8px 15px;
    background: white;
    border-top: 1px solid #e1e8ed;
}

.aichat-btn-secondary {
    width: 100%;
    padding: 8px;
    background: white;
    border: 2px solid #006FBA;
    color: #006FBA;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.aichat-btn-secondary:hover {
    background: #006FBA;
    color: white;
}

#aichat-input-area {
    display: flex;
    padding: 12px 15px;
    background: white;
    border-top: 1px solid #e1e8ed;
}

#aichat-input {
    flex: 1;
    padding: 10px;
    border: 2px solid #e1e8ed;
    border-radius: 24px;
    outline: none;
    font-size: 1rem !important;
    min-width: 0;
}

#aichat-input:focus {
    border-color: #006FBA;
}

#aichat-send {
    margin-left: 10px;
    padding: 10px 16px;
    background: linear-gradient(135deg, #006FBA 0%, #2481e4 100%);
    color: white;
    border: none;
    border-radius: 24px;
    cursor: pointer;
    font-weight: 600;
    transition: transform 0.2s ease;
    white-space: nowrap;
}

#aichat-send:hover {
    transform: scale(1.05);
}

#aichat-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.aichat-typing {
    display: inline-block;
    padding: 12px 16px;
    background: white;
    border: 1px solid #e1e8ed;
    border-radius: 18px;
}

.aichat-typing span {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #006FBA;
    margin: 0 2px;
    animation: bounce 1.4s infinite ease-in-out;
}

.aichat-typing span:nth-child(1) {
    animation-delay: -0.32s;
}

.aichat-typing span:nth-child(2) {
    animation-delay: -0.16s;
}

@keyframes bounce {

    0%,
    80%,
    100% {
        transform: scale(0);
    }

    40% {
        transform: scale(1);
    }
}

/* Ensure font inheritance for form elements */
input,
button,
textarea,
select {
    font-family: inherit;
}

/* Responsive Font Sizes */
#aichat-header h3 {
    font-size: clamp(16px, 4vw, 18px);
}

#aichat-input,
.aichat-btn-secondary {
    font-size: 12px;
}

/* Feedback Buttons */
.aichat-feedback {
    display: flex;
    gap: 8px;
    margin-top: 4px;
    padding-left: 4px;
    opacity: 0.8;
}

.aichat-feedback-btn {
    background: none;
    border: none;
    cursor: pointer;
    color: #94a3b8;
    /* Slate 400 */
    padding: 4px;
    border-radius: 4px;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.aichat-feedback-btn:hover {
    background: #e2e8f0;
    color: #475569;
}

.aichat-feedback-btn.active {
    color: #006FBA;
}

.aichat-feedback-btn .material-symbols-rounded {
    font-size: 14px;
}

.aichat-suggestions {
    margin-top: 10px;
    margin-bottom: 16px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    z-index: 5;
    position: relative;
}

.aichat-suggestion-btn {
    background: white;
    border: 1px solid #006FBA;
    color: #006FBA;
    padding: 8px 14px;
    /* Larger touch target */
    border-radius: 16px;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
    white-space: normal;
    /* Allow wrapping */
    text-align: left;
    max-width: 100%;
    line-height: 1.3;
}

.aichat-suggestion-btn:hover {
    background: #006FBA;
    color: white;
}

/* Mobile: Revert to Bottom-Right/Bottom-Sheet style instead of Center */
@media (max-width: 480px) {

    /* --- MOBILE CONTAINER --- */
    #aichat-container {
        position: fixed;
        /* Reset Desktop Positions */
        top: auto;
        left: 50%;
        transform: translateX(-50%);
        /* True Center Horizontally */

        /* Responsive Dimensions */
        bottom: 90px !important;
        right: auto !important;

        /* Fluid Width: 92% of screen, capped at 400px */
        width: 95vw;
        max-width: 400px;

        /* Taller Height for Mobile: 60-70% of screen height */
        height: 70vh;
        max-height: 700px;

        border-radius: 16px;
        box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    }

    /* --- TOGGLE BUTTON (Launcher) --- */
    #aichat-toggle {
        width: 60px;
        height: 60px;
        bottom: 20px;
        right: 20px;
    }

    #aichat-toggle svg {
        width: 32px;
        height: 32px;
    }

    /* --- HEADER --- */
    #aichat-header {
        padding: 16px 20px;
    }

    #aichat-header h3 {
        /* Fluid Font: starts at 18px */
        font-size: clamp(18px, 5vw, 20px);
        gap: 10px;
    }

    /* Header Icon (Font Icon) */
    #aichat-header h3 .material-symbols-rounded {
        font-size: clamp(24px, 6vw, 28px) !important;
        margin-right: 0 !important;
        /* Managed by gap */
    }

    /* Close Button */
    #aichat-close {
        font-size: 28px !important;
        padding: 5px;
        width: 36px;
        height: 36px;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    /* --- MESSAGE AREA --- */
    #aichat-messages {
        padding: 15px;
    }

    .aichat-message-content {
        /* Inherit global responsive size */
        padding: 10px 14px;
        line-height: 1.5;
    }

    /* --- ACTION BUTTONS (WhatsApp) --- */
    #aichat-actions {
        padding: 12px 20px;
    }

    .aichat-btn-secondary {
        /* Touch target size (~44px height min) */
        padding: 12px;
        font-size: clamp(14px, 4vw, 16px);
        height: auto;
    }

    /* FIX: Target the SVG inside the button, NOT the missing class */
    .aichat-btn-secondary svg {
        width: 24px;
        height: 24px;
        /* Ensure it scales */
        min-width: 24px;
    }

    /* If there are any font icons in buttons later */
    .aichat-btn-secondary .material-symbols-rounded {
        font-size: 24px !important;
    }

    /* --- INPUT AREA --- */
    #aichat-input-area {
        padding: 12px 15px;
        gap: 8px;
    }

    #aichat-input {
        box-sizing: border-box;
        /* Fix height calc */
        font-size: 16px !important;
        /* Prevent iOS Zoom */
        padding: 0 16px;
        /* Remove vertical padding */
        height: 48px;
        line-height: normal;
    }

    #aichat-send {
        box-sizing: border-box;
        padding: 0 20px;
        font-size: 14px;
        height: 48px;
        /* Match input height */
        display: flex;
        /* Center text */
        align-items: center;
        justify-content: center;
    }
}

/* --- ENHANCED MARKDOWN SUPPORT (MERGED) --- */

/* Headers */
.aichat-message-content h1,
.aichat-message-content h2,
.aichat-message-content h3,
.aichat-message-content h4,
.aichat-message-content h5,
.aichat-message-content h6 {
    font-weight: 700;
    margin: 8px 0 4px 0 !important;
    color: #111827;
    line-height: 1.3;
}

.aichat-message-content h1 {
    font-size: 1.4em;
}

.aichat-message-content h2 {
    font-size: 1.25em;
}

.aichat-message-content h3 {
    font-size: 1.1em;
}

/* Lists */
.aichat-message-content ul,
.aichat-message-content ol {
    margin: 4px 0 8px 0 !important;
    padding-left: 24px;
}

.aichat-message-content li {
    margin-bottom: 2px;
    padding-left: 4px;
}

.aichat-message-content ul {
    list-style-type: disc;
}

.aichat-message-content ol {
    list-style-type: decimal;
}

/* Typography */
.aichat-message-content strong {
    font-weight: 700;
    color: #000;
}

.aichat-message-content em {
    font-style: italic;
}

.aichat-message-content blockquote {
    border-left: 4px solid #006FBA;
    margin: 12px 0;
    padding-left: 12px;
    color: #4b5563;
    font-style: italic;
    background: #f9fafb;
}

/* Links */
.aichat-message-content a {
    color: #006FBA;
    text-decoration: none;
    font-weight: 500;
}

.aichat-message-content a:hover {
    text-decoration: underline;
}

/* Code */
.aichat-message-content code {
    background: #f3f4f6;
    padding: 2px 6px;
    border-radius: 4px;
    font-family: monospace;
    font-size: 0.9em;
    color: #d14;
}

.aichat-message-content pre {
    background: #1f2937;
    color: #f3f4f6;
    padding: 12px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 12px 0;
}

.aichat-message-content pre code {
    background: transparent;
    color: inherit;
    padding: 0;
    font-size: 0.85em;
}