:root {
    /* Fallback variables, strictly overridden by inline CSS */
    --aiprochat-bg: #ffffff;
    --aiprochat-msg-area-bg: #f8fafc;
    --aiprochat-text-dark: #1e293b;
    --aiprochat-text-light: #64748b;
    --aiprochat-msg-user: var(--aiprochat-primary, #3b82f6);
    --aiprochat-msg-ai: #f1f5f9;
    --aiprochat-radius: 16px;
    --aiprochat-font: system-ui, -apple-system, sans-serif;
    --aiprochat-input-bg: #f8fafc;
    --aiprochat-border: #cbd5e1;
}

.aiprochat-container {
    position: fixed;
    bottom: 30px;
    z-index: 999999;
    font-family: var(--aiprochat-font);
}

.aiprochat-tooltip {
    position: absolute;
    top: 50%;
    transform: translateY(-50%) translateX(20px);
    background-color: var(--aiprochat-primary);
    color: white;
    padding: 10px 18px;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 600;
    opacity: 0;
    visibility: hidden;
    transition: all 0.4s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    white-space: nowrap;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.2), 0 4px 6px -2px rgba(0, 0, 0, 0.1);
    pointer-events: none;
    letter-spacing: 0.3px;
}

.aiprochat-tooltip::after {
    content: '';
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    border-width: 6px;
    border-style: solid;
}

/* Tooltip position: Above the button */
.aiprochat-container .aiprochat-tooltip {
    top: -55px;
    left: 50%;
    transform: translateX(-50%) translateY(10px);
    right: auto;
}
.aiprochat-container .aiprochat-tooltip::after {
    top: auto;
    bottom: -11px;
    left: 50%;
    transform: translateX(-50%);
    border-color: var(--aiprochat-primary) transparent transparent transparent;
}
.aiprochat-container:hover .aiprochat-tooltip {
    opacity: 1;
    visibility: visible;
    transform: translateX(-50%) translateY(0);
}
.aiprochat-tooltip {
    position: absolute;
    bottom: 85px;
    right: 5px;
    background: #fff;
    padding: 10px 18px;
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    font-size: 14px;
    font-weight: 500;
    z-index: 9999;
    border: 1px solid #eee;
    display: flex;
    align-items: center;
    gap: 10px;
    animation: aipc-bounce 2s infinite;
    white-space: nowrap;
}

.tooltip-close {
    cursor: pointer;
    font-size: 18px;
    color: #94a3b8;
    line-height: 1;
}

.tooltip-close:hover { color: #eb4034; }

@keyframes aipc-bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-5px); }
}

/* Hide tooltip if chat window is opened */
.aiprochat-container.aiprochat-is-open .aiprochat-tooltip,
.aiprochat-container:has(.aiprochat-open) .aiprochat-tooltip,
.aiprochat-tooltip.aipc-hidden {
    opacity: 0 !important; visibility: hidden !important; pointer-events: none !important;
}

.aiprochat-button {
    width: 65px;
    height: 65px;
    background: linear-gradient(135deg, var(--aiprochat-primary) 0%, rgba(0,0,0,0.3) 150%);
    color: white;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 32px;
    cursor: pointer;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.2), 0 4px 6px -2px rgba(0, 0, 0, 0.1);
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275), box-shadow 0.3s ease;
    overflow: hidden;
}

.aiprochat-button:hover {
    transform: scale(1.1) rotate(5deg);
    box-shadow: 0 15px 25px -5px rgba(0, 0, 0, 0.25), 0 8px 10px -6px rgba(0, 0, 0, 0.15);
}

.aiprochat-window {
    width: 380px;
    height: 550px;
    max-height: calc(100vh - 120px);
    background-color: var(--aiprochat-bg);
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25), 0 0 0 1px rgba(0,0,0,0.05);
    display: flex;
    flex-direction: column;
    position: absolute;
    bottom: 85px;
    transition: all 0.4s cubic-bezier(0.16, 1, 0.3, 1);
    transform: translateY(20px) scale(0.95);
    overflow: hidden;
    z-index: 10000;
}

.aiprochat-window.aiprochat-open {
    opacity: 1 !important;
    visibility: visible !important;
    transform: translateY(0) scale(1);
    animation: aipc-reveal 0.5s ease-out;
}

@keyframes aipc-reveal {
    from { opacity: 0; transform: translateY(20px) scale(0.95); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

/* Status Dot Pulsing */
.status-dot.pulsing {
    position: relative;
    background: #10b981;
}

.status-dot.pulsing::after {
    content: '';
    position: absolute;
    top: -2px; left: -2px; right: -2px; bottom: -2px;
    border-radius: 50%;
    border: 2px solid #10b981;
    animation: aipc-pulse 2s infinite;
}

@keyframes aipc-pulse {
    0% { transform: scale(1); opacity: 0.8; }
    100% { transform: scale(2); opacity: 0; }
}

/* Chips Style */
.aiprochat-chips {
    display: flex;
    gap: 8px;
    padding: 10px 15px;
    overflow-x: auto;
    background: var(--aiprochat-bg);
    scrollbar-width: none;
    border-top: 1px solid rgba(0,0,0,0.03);
}

.aiprochat-chips::-webkit-scrollbar { display: none; }

.aipc-chip {
    white-space: nowrap;
    background: #fff;
    border: 1px solid var(--aiprochat-border);
    color: var(--aiprochat-text-main);
    padding: 6px 12px;
    border-radius: 16px;
    font-size: 12.5px;
    cursor: pointer;
    transition: all 0.2s;
    font-weight: 500;
    box-shadow: 0 1px 2px rgba(0,0,0,0.03);
}

.aipc-chip:hover {
    border-color: var(--aiprochat-primary);
    background: var(--aiprochat-primary);
    color: #fff;
    transform: translateY(-1px);
}

/* Fullscreen mode classes */
.aiprochat-window.aiprochat-fullscreen {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100vw;
    height: 100dvh; /* Dynamic Viewport Height for Keyboard */
    max-height: 100dvh;
    border-radius: 0 !important;
    z-index: 2147483647;
    transform: none !important;
    display: flex;
    flex-direction: column;
}

.aiprochat-window.aiprochat-fullscreen .aiprochat-messages {
    flex: 1;
    overflow-y: auto;
}

.aiprochat-window.aiprochat-fullscreen .aiprochat-header,
.aiprochat-window.aiprochat-fullscreen .aiprochat-input-area {
    border-radius: 0 !important;
    flex-shrink: 0;
}

.aiprochat-header {
    background: linear-gradient(135deg, var(--aiprochat-primary), rgba(0,0,0,0.2) 150%);
    color: white;
    padding: 20px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

.aiprochat-header-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.aiprochat-header-icon {
    font-size: 24px;
    background: rgba(255,255,255,0.2);
    width: 42px;
    height: 42px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 12px;
    backdrop-filter: blur(4px);
    overflow: hidden;
}

.aiprochat-header h4 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    color: white;
    letter-spacing: 0.3px;
    line-height: 1.2;
}

.aiprochat-status {
    font-size: 12px;
    color: rgba(255,255,255,0.85);
    display: flex;
    align-items: center;
    margin-top: 4px;
}

.status-dot {
    width: 8px;
    height: 8px;
    background-color: #4ade80;
    border-radius: 50%;
    display: inline-block;
    margin-right: 6px;
    box-shadow: 0 0 0 2px rgba(74, 222, 128, 0.3);
}

.aiprochat-header-controls {
    display: flex;
    align-items: center;
    gap: 8px;
}

#aiprochat-fullscreen, #aiprochat-close {
    background: rgba(255,255,255,0.1);
    border: none;
    color: white;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

#aiprochat-close {
    font-size: 22px;
}

#aiprochat-fullscreen:hover, #aiprochat-close:hover {
    background: rgba(255,255,255,0.25);
}

.aiprochat-messages {
    flex-grow: 1;
    padding: 20px;
    overflow-y: auto;
    background-color: var(--aiprochat-msg-area-bg);
    display: flex;
    flex-direction: column;
    gap: 12px;
    scroll-behavior: smooth;
    background-image: radial-gradient(var(--aiprochat-border) 1px, transparent 1px);
    background-size: 16px 16px;
    color: var(--aiprochat-text-dark);
}

.aiprochat-messages::-webkit-scrollbar {
    width: 6px;
}
.aiprochat-messages::-webkit-scrollbar-thumb {
    background-color: var(--aiprochat-border);
    border-radius: 10px;
}

.aiprochat-message {
    padding: 12px 16px;
    max-width: 85%;
    word-wrap: break-word;
    font-size: 14px;
    line-height: 1.5;
    position: relative;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
    animation: fadeInMsg 0.3s ease-out forwards;
}

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

.ai-message {
    background-color: var(--aiprochat-msg-ai);
    color: var(--aiprochat-text-dark);
    align-self: flex-start;
    border-radius: 18px 18px 18px 4px;
}

.user-message {
    background: linear-gradient(135deg, var(--aiprochat-primary), rgba(0,0,0,0.2) 150%);
    color: white;
    align-self: flex-end;
    margin-left: auto;
    border-radius: 18px 18px 4px 18px;
}

.message-timestamp {
    font-size: 11px;
    opacity: 0.7;
    margin-top: 6px;
    text-align: right;
}
.ai-message .message-timestamp {
    color: var(--aiprochat-text-light);
}
.user-message .message-timestamp {
    color: rgba(255,255,255,0.9);
}

.aiprochat-input-area {
    padding: 12px 16px;
    background-color: var(--aiprochat-bg);
    border-top: 1px solid var(--aiprochat-border);
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.aiprochat-extra-actions {
    display: flex;
    gap: 12px;
    padding-left: 4px;
}

.aipc-action-btn {
    background: transparent;
    border: none;
    color: var(--aiprochat-text-light);
    cursor: pointer;
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    border-radius: 6px;
}

.aipc-action-btn:hover {
    color: var(--aiprochat-primary);
    background: rgba(var(--aiprochat-primary-rgb, 59, 130, 246), 0.1);
    transform: translateY(-2px);
}

.aiprochat-input-wrapper {
    display: flex;
    align-items: center;
    background-color: var(--aiprochat-input-bg);
    border: 1px solid var(--aiprochat-border);
    border-radius: 24px;
    padding-right: 6px;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.aiprochat-input-wrapper:focus-within {
    border-color: var(--aiprochat-primary);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
    background-color: var(--aiprochat-bg);
}

#aiprochat-input {
    flex-grow: 1;
    padding: 10px 18px;
    border: none !important;
    background: transparent !important;
    outline: none !important;
    font-size: 14px;
    color: var(--aiprochat-text-dark);
    font-family: inherit;
    box-shadow: none !important;
}

#aiprochat-send {
    background-color: var(--aiprochat-primary);
    color: white;
    border: none;
    width: 34px;
    height: 34px;
    border-radius: 50% !important;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    flex-shrink: 0;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}

#aiprochat-send:hover {
    transform: scale(1.1);
    background-color: color-mix(in srgb, var(--aiprochat-primary) 85%, black);
}

#aiprochat-send:active {
    transform: scale(0.95);
}

.typing-indicator {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px 8px;
}

.typing-dot {
    width: 6px;
    height: 6px;
    background-color: var(--aiprochat-border);
    border-radius: 50%;
    animation: typing 1.4s infinite ease-in-out both;
}

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

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

@media (max-width: 480px) {
    .aiprochat-container {
        bottom: 20px;
        right: 20px !important;
        left: auto !important;
        z-index: 2147483647;
    }
    .aiprochat-window {
        width: calc(100vw - 40px);
        height: min(600px, calc(100vh - 140px));
        bottom: 85px;
        right: 0 !important;
        left: auto !important;
        border-radius: 20px !important;
    }
    .aiprochat-container[style*="left"] .aiprochat-window {
        left: 0 !important;
        right: auto !important;
    }
    
    /* When input is focused on mobile, try to keep the area visible */
    .aiprochat-window:focus-within {
        /* Optional: adjust height if needed, but 100dvh usually handles it */
    }

    .aiprochat-header {
        padding: 15px;
    }
    .aiprochat-message {
        max-width: 92%;
        font-size: 14px;
        padding: 10px 14px;
    }
    .aipc-chip {
        font-size: 12px;
        padding: 6px 12px;
    }
    .aiprochat-input-area {
        padding: 12px;
        background: #fff;
    }
    #aiprochat-input {
        font-size: 16px; /* Prevents iOS auto-zoom on focus */
        padding: 10px 14px;
    }
}
