/* MFC Chatbot Widget Styles */
/* These styles are also injected into Shadow DOM for full isolation */

:host,
.mfc-chatbot-container {
    --mfc-primary: var(--mfc-bubble-color, #0073aa);
    --mfc-primary-hover: color-mix(in srgb, var(--mfc-primary) 85%, black);
    --mfc-bg: #ffffff;
    --mfc-bg-secondary: #f0f2f5;
    --mfc-text: #1a1a1a;
    --mfc-text-light: #6b7280;
    --mfc-border: #e5e7eb;
    --mfc-visitor-bg: var(--mfc-primary);
    --mfc-visitor-text: #ffffff;
    --mfc-bot-bg: #f0f2f5;
    --mfc-bot-text: #1a1a1a;
    --mfc-radius: 12px;
    --mfc-shadow: 0 5px 40px rgba(0, 0, 0, 0.16);
    --mfc-z-index: 999999;

    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    box-sizing: border-box;
}

*, *::before, *::after {
    box-sizing: border-box;
}

/* Bubble */
.mfc-chatbot-bubble {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--mfc-primary);
    color: #fff;
    border: none;
    cursor: pointer;
    z-index: var(--mfc-z-index);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    animation: mfcBubbleBreathe 2.6s ease-in-out infinite;
}

.mfc-chatbot-bubble::before,
.mfc-chatbot-bubble::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 50%;
    background: var(--mfc-primary);
    z-index: -1;
    opacity: 0.6;
    animation: mfcBubblePulse 2.2s cubic-bezier(0.22, 1, 0.36, 1) infinite;
}

.mfc-chatbot-bubble::after {
    animation-delay: 1.1s;
}

.mfc-chatbot-bubble:hover,
.mfc-chatbot-bubble.mfc-open {
    animation: none;
}

.mfc-chatbot-bubble:hover::before,
.mfc-chatbot-bubble:hover::after,
.mfc-chatbot-bubble.mfc-open::before,
.mfc-chatbot-bubble.mfc-open::after {
    animation: none;
    opacity: 0;
}

.mfc-chatbot-bubble:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
}

@keyframes mfcBubbleBreathe {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.06); }
}

@keyframes mfcBubblePulse {
    0% { transform: scale(1); opacity: 0.55; }
    80% { transform: scale(1.7); opacity: 0; }
    100% { transform: scale(1.7); opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
    .mfc-chatbot-bubble,
    .mfc-chatbot-bubble::before,
    .mfc-chatbot-bubble::after {
        animation: none;
    }
}

.mfc-chatbot-bubble svg {
    width: 28px;
    height: 28px;
    fill: currentColor;
}

.mfc-chatbot-bubble .mfc-close-icon {
    display: none;
}

.mfc-chatbot-bubble.mfc-open .mfc-chat-icon {
    display: none;
}

.mfc-chatbot-bubble.mfc-open .mfc-close-icon {
    display: block;
}

/* Chat Window */
.mfc-chatbot-window {
    position: fixed;
    bottom: 90px;
    right: 20px;
    width: 380px;
    height: 520px;
    max-height: calc(100vh - 120px);
    background: var(--mfc-bg);
    border-radius: var(--mfc-radius);
    box-shadow: var(--mfc-shadow);
    z-index: var(--mfc-z-index);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    pointer-events: none;
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.mfc-chatbot-window.mfc-visible {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: all;
}

/* Header */
.mfc-chatbot-header {
    background: var(--mfc-primary);
    color: #fff;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.mfc-chatbot-header-title {
    font-size: 16px;
    font-weight: 600;
    margin: 0;
}

.mfc-chatbot-header-close {
    background: none;
    border: none;
    color: #fff;
    cursor: pointer;
    padding: 4px;
    opacity: 0.8;
    transition: opacity 0.2s;
}

.mfc-chatbot-header-close:hover {
    opacity: 1;
}

.mfc-chatbot-header-close svg {
    width: 20px;
    height: 20px;
    fill: currentColor;
}

/* Messages */
.mfc-chatbot-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.mfc-chatbot-messages::-webkit-scrollbar {
    width: 4px;
}

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

.mfc-chatbot-messages::-webkit-scrollbar-thumb {
    background: var(--mfc-border);
    border-radius: 2px;
}

/* Message */
.mfc-chatbot-message {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 16px;
    word-wrap: break-word;
    animation: mfcFadeIn 0.3s ease;
}

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

.mfc-chatbot-message.mfc-visitor {
    align-self: flex-end;
    background: var(--mfc-visitor-bg);
    color: var(--mfc-visitor-text);
    border-bottom-right-radius: 4px;
}

.mfc-chatbot-message.mfc-bot {
    align-self: flex-start;
    background: var(--mfc-bot-bg);
    color: var(--mfc-bot-text);
    border-bottom-left-radius: 4px;
}

.mfc-chatbot-message.mfc-system {
    align-self: center;
    background: none;
    color: var(--mfc-text-light);
    font-size: 12px;
    font-style: italic;
    padding: 4px 0;
}

.mfc-msg-link {
    color: var(--mfc-primary);
    text-decoration: underline;
    word-break: break-word;
}

.mfc-chatbot-message.mfc-visitor .mfc-msg-link {
    color: #fff;
    text-decoration: underline;
}

.mfc-msg-link:hover {
    text-decoration: none;
}

/* Typing Indicator */
.mfc-chatbot-typing {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 12px 16px;
    background: var(--mfc-bot-bg);
    border-radius: 16px;
    border-bottom-left-radius: 4px;
    align-self: flex-start;
    animation: mfcFadeIn 0.3s ease;
}

.mfc-chatbot-typing-dot {
    width: 8px;
    height: 8px;
    background: var(--mfc-text-light);
    border-radius: 50%;
    animation: mfcBounce 1.4s infinite ease-in-out;
}

.mfc-chatbot-typing-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.mfc-chatbot-typing-dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes mfcBounce {
    0%, 80%, 100% {
        transform: scale(0.6);
        opacity: 0.4;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* Buttons */
.mfc-chatbot-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 8px;
    align-self: flex-start;
    max-width: 100%;
    animation: mfcFadeIn 0.3s ease;
}

.mfc-chatbot-button {
    padding: 8px 16px;
    border: 1.5px solid var(--mfc-primary);
    background: transparent;
    color: var(--mfc-primary);
    border-radius: 20px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    transition: background 0.2s, color 0.2s;
    white-space: nowrap;
}

.mfc-chatbot-button:hover {
    background: var(--mfc-primary);
    color: #fff;
}

.mfc-chatbot-button:disabled {
    opacity: 0.5;
    cursor: default;
}

/* Action Buttons (link-style: tel:, viber:, https:, ...) */
.mfc-chatbot-action-buttons {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 8px;
    align-self: flex-start;
    width: 85%;
    animation: mfcFadeIn 0.3s ease;
}

.mfc-chatbot-action-btn {
    display: block;
    padding: 10px 16px;
    border: 1.5px solid var(--mfc-primary);
    background: var(--mfc-primary);
    color: #fff;
    border-radius: 20px;
    text-decoration: none;
    font-size: 13px;
    font-weight: 600;
    text-align: center;
    transition: opacity 0.2s, transform 0.1s;
}

.mfc-chatbot-action-btn:hover {
    opacity: 0.9;
    color: #fff;
}

.mfc-chatbot-action-btn:active {
    transform: translateY(1px);
}

/* Email Capture */
.mfc-chatbot-email-form {
    display: flex;
    gap: 8px;
    margin-top: 8px;
    align-self: flex-start;
    width: 85%;
    animation: mfcFadeIn 0.3s ease;
}

.mfc-chatbot-email-input {
    flex: 1;
    padding: 8px 12px;
    border: 1.5px solid var(--mfc-border);
    border-radius: 20px;
    font-size: 13px;
    outline: none;
    transition: border-color 0.2s;
}

.mfc-chatbot-email-input:focus {
    border-color: var(--mfc-primary);
}

.mfc-chatbot-email-submit {
    padding: 8px 16px;
    background: var(--mfc-primary);
    color: #fff;
    border: none;
    border-radius: 20px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    transition: background 0.2s;
}

.mfc-chatbot-email-submit:hover {
    background: var(--mfc-primary-hover);
}

/* Input Area */
.mfc-chatbot-input-area {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    border-top: 1px solid var(--mfc-border);
    background: var(--mfc-bg);
    flex-shrink: 0;
}

.mfc-chatbot-input {
    flex: 1;
    padding: 10px 14px;
    border: 1.5px solid var(--mfc-border);
    border-radius: 24px;
    font-size: 14px;
    outline: none;
    background: var(--mfc-bg);
    color: var(--mfc-text);
    transition: border-color 0.2s;
}

.mfc-chatbot-input:focus {
    border-color: var(--mfc-primary);
}

.mfc-chatbot-input::placeholder {
    color: var(--mfc-text-light);
}

.mfc-chatbot-send {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--mfc-primary);
    color: #fff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.2s, transform 0.1s;
}

.mfc-chatbot-send:hover {
    background: var(--mfc-primary-hover);
}

.mfc-chatbot-send:active {
    transform: scale(0.95);
}

.mfc-chatbot-send:disabled {
    opacity: 0.5;
    cursor: default;
}

.mfc-chatbot-send svg {
    width: 18px;
    height: 18px;
    fill: currentColor;
}

/* Powered by */
.mfc-chatbot-powered {
    text-align: center;
    padding: 4px 0 8px;
    font-size: 10px;
    color: var(--mfc-text-light);
    background: var(--mfc-bg);
    flex-shrink: 0;
}

/* Mobile responsive */
@media (max-width: 480px) {
    .mfc-chatbot-window {
        width: calc(100vw - 16px);
        height: calc(100vh - 80px);
        max-height: calc(100vh - 80px);
        bottom: 72px;
        right: 8px;
        border-radius: 16px;
    }

    .mfc-chatbot-bubble {
        bottom: 12px;
        right: 12px;
        width: 54px;
        height: 54px;
    }
}
