/**
 * POKBON AI Assistant Chat Widget Styles
 */

/* Variables */
:root {
    --pai-primary-color: #0073aa;
    --pai-primary-hover: #005a87;
    --pai-primary-light: rgba(0, 115, 170, 0.1);
    --pai-bg-color: #ffffff;
    --pai-text-color: #333333;
    --pai-border-color: #e0e0e0;
    --pai-shadow-color: rgba(0, 0, 0, 0.1);
    --pai-shadow-hover: rgba(0, 0, 0, 0.15);
    --pai-success-color: #46b450;
    --pai-error-color: #dc3232;
    --pai-warning-color: #ffb900;
}

/* Main Widget Container */
.pai-chat-widget {
    position: fixed;
    z-index: 999999;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-size: 13px; /* Standardized font size */
    line-height: 1.5;
}

/* Toggle Button */
.pai-chat-toggle {
    width: 56px;
    height: 56px;
    background: var(--pai-primary-color);
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 4px 12px var(--pai-shadow-color);
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    border: none;
}

.pai-chat-toggle:hover {
    background: var(--pai-primary-hover);
    transform: scale(1.05);
    box-shadow: 0 6px 20px var(--pai-shadow-hover);
}

.pai-toggle-icon {
    color: white;
    margin-bottom: 2px;
}

.pai-toggle-icon svg {
    width: 24px;
    height: 24px;
}

.pai-toggle-text {
    color: white;
    font-size: 10px;
    font-weight: 600;
    text-align: center;
    line-height: 1;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.pai-toggle-badge {
    position: absolute;
    top: -2px;
    right: -2px;
    background: #ff4d4f;
    color: white;
    border-radius: 50%;
    min-width: 18px;
    height: 18px;
    font-size: 10px;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid white;
    padding: 0 4px;
}

/* Chat Window */
.pai-chat-window {
    position: absolute;
    bottom: 75px;
    width: 360px;
    height: 520px; /* Standard height */
    max-height: calc(100vh - 100px);
    background: var(--pai-bg-color);
    border-radius: 16px;
    box-shadow: 0 12px 48px rgba(0, 0, 0, 0.15);
    border: 1px solid var(--pai-border-color);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: pai-slide-in 0.4s cubic-bezier(0.165, 0.84, 0.44, 1);
}

@keyframes pai-slide-in {
    from {
        opacity: 0;
        transform: translateY(30px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.pai-chat-window.minimized {
    height: 64px;
}

/* Header */
.pai-chat-header {
    background: var(--pai-primary-color);
    color: white;
    padding: 16px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.pai-header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.pai-avatar {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    overflow: hidden;
    background: white;
    padding: 2px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.pai-avatar img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.pai-header-info {
    flex: 1;
}

.pai-header-title {
    font-weight: 700;
    font-size: 15px;
    letter-spacing: -0.3px;
}

.pai-header-status {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    opacity: 0.9;
    font-weight: 500;
}

.pai-status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #52c41a;
    box-shadow: 0 0 0 2px rgba(82, 196, 26, 0.2);
}

.pai-header-right {
    display: flex;
    gap: 2px;
}

.pai-header-btn {
    background: rgba(255, 255, 255, 0.15);
    border: none;
    color: white;
    width: 30px;
    height: 30px;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    opacity: 1;
}

.pai-header-btn:hover {
    background: rgba(255, 255, 255, 0.3);
}

.pai-header-btn svg {
    width: 16px;
    height: 16px;
    fill: white;
}

/* Quick Actions */
.pai-quick-actions {
    padding: 12px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    background: #fdfdfd;
    border-bottom: 1px solid #f0f0f0;
}

.pai-quick-btn {
    flex: 1 1 calc(50% - 4px);
    min-width: 120px;
    padding: 10px 12px;
    border: 1px solid #eee;
    border-radius: 10px;
    background: white;
    color: #444;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: all 0.2s;
}

.pai-quick-btn:hover {
    border-color: var(--pai-primary-color);
    color: var(--pai-primary-color);
    background: var(--pai-primary-light);
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}

.pai-quick-btn svg {
    width: 16px;
    height: 16px;
    opacity: 0.7;
}

/* Messages */
.pai-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background: #fff;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.pai-message {
    max-width: 85%;
    display: flex;
    flex-direction: row;
    align-items: flex-start;
    gap: 8px;
}

.pai-message-bot {
    align-self: flex-start;
}

.pai-message-user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

/* Message Avatars (inline in chat bubbles) */
.pai-message-avatar {
    width: 28px;
    height: 28px;
    min-width: 28px;
    border-radius: 50%;
    overflow: hidden;
    flex-shrink: 0;
    margin-top: 2px;
}

.pai-message-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.pai-message-text {
    padding: 12px 16px;
    border-radius: 14px;
    font-size: 13.5px;
    line-height: 1.5;
    position: relative;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

.pai-message-bot .pai-message-text {
    background: #f0f2f5;
    color: #1c1e21;
    border-bottom-left-radius: 4px;
}

.pai-message-user .pai-message-text {
    background: var(--pai-primary-color);
    color: white;
    border-bottom-right-radius: 4px;
}

.pai-message-time {
    font-size: 10px;
    color: #8c939d;
    margin-top: 4px;
    font-weight: 500;
}

.pai-message-user .pai-message-time {
    text-align: right;
}

/* Input Area */
.pai-input-area {
    padding: 16px 20px;
    background: white;
    border-top: 1px solid #f0f0f0;
}

.pai-input-wrapper {
    display: flex;
    align-items: center;
    gap: 12px;
    background: #f8f9fa;
    padding: 8px 8px 8px 16px;
    border-radius: 24px;
    border: 1px solid #e8e8e8;
    transition: all 0.2s;
}

.pai-input-wrapper:focus-within {
    border-color: var(--pai-primary-color);
    background: white;
    box-shadow: 0 0 0 3px var(--pai-primary-light);
}

.pai-message-input {
    flex: 1;
    border: none;
    background: transparent;
    padding: 4px 0;
    font-size: 14px;
    resize: none;
    max-height: 100px;
    outline: none;
    color: #1c1e21;
}

.pai-send-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--pai-primary-color);
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
}

.pai-send-btn:hover {
    transform: scale(1.1);
    background: var(--pai-primary-hover);
}

.pai-send-btn:disabled {
    background: #d9d9d9;
    cursor: not-allowed;
    transform: none;
}

.pai-send-text {
    display: none; /* Hide text, use icon only */
}

/* Footer */
.pai-chat-footer {
    padding: 8px 20px;
    background: #f9f9f9;
    text-align: center;
    border-top: 1px solid #eee;
}

.pai-powered-by {
    font-size: 10px;
    color: #999;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.pai-privacy-link {
    font-size: 10px;
    color: var(--pai-primary-color);
    text-decoration: none;
    margin-left: 8px;
}

/* Positions — explicit left/right auto to prevent theme CSS conflicts */
.pai-position-bottom-right { bottom: 20px; right: 20px; left: auto !important; }
.pai-position-bottom-left { bottom: 20px; left: 20px; right: auto !important; }
.pai-position-top-right { top: 20px; right: 20px; left: auto !important; bottom: auto; }
.pai-position-top-left { top: 20px; left: 20px; right: auto !important; bottom: auto; }

/* Chat window anchoring based on widget position */
.pai-position-bottom-right .pai-chat-window,
.pai-position-top-right .pai-chat-window { right: 0; left: auto; }
.pai-position-bottom-left .pai-chat-window,
.pai-position-top-left .pai-chat-window { left: 0; right: auto; }

/* Notification Popup */
.pai-notification-popup {
    position: absolute;
    bottom: 80px;
    left: 0;
    right: auto;
    background: white;
    border-radius: 8px;
    box-shadow: 0 4px 12px var(--pai-shadow-color);
    border: 1px solid var(--pai-border-color);
    padding: 12px 16px;
    min-width: 200px;
    animation: slide-down 0.3s ease;
}

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

.pai-notification-content {
    display: flex;
    align-items: center;
    gap: 12px;
}

.pai-notification-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    overflow: hidden;
    flex-shrink: 0;
}

.pai-notification-message {
    flex: 1;
}

.pai-notification-text {
    font-size: 13px;
    color: var(--pai-text-color);
    margin-bottom: 2px;
    line-height: 1.3;
}

.pai-notification-time {
    font-size: 11px;
    color: #646970;
}

/* Responsive Design */
@media (max-width: 768px) {
    /* Ensure widget container is visible on mobile */
    .pai-chat-widget {
        bottom: 15px !important;
        z-index: 999999 !important;
    }

    .pai-position-bottom-left {
        left: 15px !important;
        right: auto !important;
    }

    .pai-position-bottom-right {
        right: 15px !important;
        left: auto !important;
    }

    .pai-chat-toggle {
        width: 52px;
        height: 52px;
    }

    .pai-toggle-text {
        font-size: 9px;
    }

    .pai-chat-window {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100vw;
        height: 100vh;
        max-height: 100vh;
        max-width: 100vw;
        border-radius: 0;
        z-index: 9999999;
    }

    .pai-messages {
        padding: 10px 15px;
    }

    .pai-quick-actions {
        padding: 10px 15px;
    }

    .pai-input-area {
        padding: 10px 15px;
    }

    .pai-chat-header {
        padding: 12px 15px;
    }

    .pai-message {
        max-width: 95%;
    }

    .pai-message-text {
        font-size: 15px;
        padding: 14px 16px;
    }
}

@media (max-width: 480px) {
    .pai-chat-widget {
        bottom: 12px !important;
    }

    .pai-position-bottom-left {
        left: 12px !important;
    }

    .pai-position-bottom-right {
        right: 12px !important;
    }

    .pai-chat-toggle {
        width: 50px;
        height: 50px;
    }

    .pai-chat-window {
        width: 100vw;
        height: 100vh;
    }

    .pai-message-text {
        font-size: 16px;
        padding: 16px 18px;
    }

    .pai-send-btn {
        min-width: 60px;
        padding: 12px 12px;
    }

    .pai-send-text {
        display: none;
    }

    .pai-quick-btn {
        padding: 14px 12px;
        font-size: 14px;
    }

    .pai-messages {
        padding: 8px 12px;
    }

    .pai-input-area {
        padding: 8px 12px;
    }

    .pai-message-input {
        font-size: 16px;
        padding: 14px 16px;
    }
}

/* Dark Mode Support */
@media (prefers-color-scheme: dark) {
    :root {
        --pai-bg-color: #1a1a1a;
        --pai-text-color: #e0e0e0;
        --pai-border-color: #333333;
        --pai-shadow-color: rgba(0, 0, 0, 0.3);
        --pai-shadow-hover: rgba(0, 0, 0, 0.5);
    }

    .pai-message-bot .pai-message-text {
        background: #2a2a2a;
        color: var(--pai-text-color);
    }

    .pai-quick-actions {
        background: #2a2a2a;
    }

    .pai-messages {
        background: #1f1f1f;
    }

    .pai-input-area {
        background: #2a2a2a;
    }

    .pai-chat-footer {
        background: #2a2a2a;
    }
}

/* Smooth Scrolling */
.pai-messages {
    scrollbar-width: thin;
    scrollbar-color: var(--pai-border-color) transparent;
}

.pai-messages::-webkit-scrollbar {
    width: 6px;
}

.pai-messages::-webkit-scrollbar-track {
    background: transparent;
}

.pai-messages::-webkit-scrollbar-thumb {
    background: var(--pai-border-color);
    border-radius: 3px;
}

.pai-messages::-webkit-scrollbar-thumb:hover {
    background: #646970;
}

/* Loading and Error States */
.pai-message-error {
    background: var(--pai-error-color) !important;
    color: white !important;
}

.pai-message-sending {
    opacity: 0.6;
}

.pai-send-btn.sending {
    background: #646970;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* Cart Action Buttons & Navigation Links */
.pai-cart-actions,
.pai-nav-links {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 8px 12px;
    margin-bottom: 8px;
}

.pai-action-btn {
    display: inline-block;
    padding: 6px 14px;
    border-radius: 16px;
    font-size: 12px;
    font-weight: 500;
    text-decoration: none;
    cursor: pointer;
    transition: all 0.2s ease;
    border: 1px solid transparent;
    text-align: center;
}

.pai-btn-primary {
    background: var(--pai-primary-color);
    color: #fff;
    border-color: var(--pai-primary-color);
}

.pai-btn-primary:hover {
    background: var(--pai-primary-hover);
    border-color: var(--pai-primary-hover);
    color: #fff;
    text-decoration: none;
}

.pai-btn-secondary {
    background: #f0f0f0;
    color: var(--pai-text-color);
    border-color: var(--pai-border-color);
}

.pai-btn-secondary:hover {
    background: #e0e0e0;
    text-decoration: none;
}

.pai-btn-outline {
    background: transparent;
    color: var(--pai-primary-color);
    border-color: var(--pai-primary-color);
}

.pai-btn-outline:hover {
    background: var(--pai-primary-light);
    text-decoration: none;
}

/* Clickable Links in Chat Messages */
.pai-chat-link {
    color: var(--pai-primary-color);
    text-decoration: underline;
    word-break: break-all;
}

.pai-chat-link:hover {
    color: var(--pai-primary-hover);
}