/**
 * Frontend Widget Styles - Maatify AI Chatbot
 * Clean, Universal, Modern and Responsive CSS with dynamic theme variables.
 */

:root {
    --maatify-primary: #4F46E5;
    --maatify-bg: #ffffff;
    --maatify-surface: #f8fafc;
    --maatify-border: #e2e8f0;
    --maatify-text: #1e293b;
    --maatify-muted: #64748b;
    --maatify-font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
    --maatify-shadow: 0 14px 35px rgba(0, 0, 0, 0.15);
}

.maatify-chat-container {
    position: fixed;
    z-index: 999998;
    font-family: var(--maatify-font);
    box-sizing: border-box;
}

.maatify-chat-container * {
    box-sizing: border-box;
}

/* Positioning */
.maatify-chat-container.maatify-pos-right {
    right: 24px;
    bottom: 24px;
}

.maatify-chat-container.maatify-pos-left {
    left: 24px;
    bottom: 24px;
}

/* Mobile Elevated Position to avoid bottom navigation bars */
@media (max-width: 768px) {
    .maatify-chat-container.maatify-pos-right {
        right: 16px;
        bottom: 90px !important;
    }
    .maatify-chat-container.maatify-pos-left {
        left: 16px;
        bottom: 90px !important;
    }
}

/* Floating Launcher Toggle Button */
.maatify-chat-toggle {
    width: 62px;
    height: 62px;
    border-radius: 50%;
    background: var(--maatify-primary);
    color: #ffffff;
    border: 3px solid #ffffff;
    cursor: pointer;
    box-shadow: 0 8px 24px rgba(79, 70, 229, 0.35);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.25s ease;
    outline: none;
    position: relative;
    user-select: none;
    padding: 0;
}

.maatify-chat-toggle:hover {
    transform: translateY(-3px) scale(1.05);
    box-shadow: 0 12px 28px rgba(79, 70, 229, 0.45);
    color: #ffffff;
}

.maatify-chat-toggle:active {
    transform: scale(0.96);
}

.maatify-icon-open,
.maatify-icon-close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
}

.maatify-launcher-logo {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    object-fit: cover;
    background: #ffffff;
    padding: 2px;
    display: block;
}

/* Badge tooltip on toggle */
.maatify-toggle-badge {
    position: absolute;
    bottom: calc(100% + 10px);
    background: #1e293b;
    color: #ffffff;
    font-size: 12px;
    font-weight: 600;
    padding: 6px 12px;
    border-radius: 20px;
    white-space: nowrap;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.18);
    pointer-events: none;
    opacity: 0;
    transform: translateY(6px);
    transition: opacity 0.2s cubic-bezier(0.16, 1, 0.3, 1), transform 0.2s cubic-bezier(0.16, 1, 0.3, 1);
    z-index: 10;
}

.maatify-toggle-badge::after {
    content: '';
    position: absolute;
    top: 100%;
    border-width: 5px;
    border-style: solid;
    border-color: #1e293b transparent transparent transparent;
}

/* Position: Right (Default - badge expands inward to the left) */
.maatify-pos-right .maatify-toggle-badge {
    right: 0;
    left: auto;
}

.maatify-pos-right .maatify-toggle-badge::after {
    right: 26px; /* Centered over 62px toggle button */
    left: auto;
}

/* Position: Left (Badge expands inward to the right) */
.maatify-pos-left .maatify-toggle-badge {
    left: 0;
    right: auto;
}

.maatify-pos-left .maatify-toggle-badge::after {
    left: 26px; /* Centered over 62px toggle button */
    right: auto;
}

.maatify-chat-toggle:hover .maatify-toggle-badge {
    opacity: 1;
    transform: translateY(0);
}

/* Hide badge when chat window is open */
.maatify-chat-open .maatify-toggle-badge {
    display: none !important;
}

/* Popup Chat Window */
.maatify-chat-window {
    width: 380px;
    height: 600px;
    max-height: calc(100vh - 120px);
    background: #ffffff;
    border-radius: 16px;
    box-shadow: var(--maatify-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: absolute;
    bottom: 76px;
    right: 0;
    border: 1px solid var(--maatify-border);
    animation: maatify-slide-up 0.25s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.maatify-pos-left .maatify-chat-window {
    left: 0;
    right: auto;
}

@keyframes maatify-slide-up {
    from {
        opacity: 0;
        transform: translateY(18px) scale(0.97);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

@media (max-width: 480px) {
    .maatify-chat-window {
        width: calc(100vw - 32px);
        height: calc(100vh - 140px);
        max-height: 580px;
        right: 0;
        bottom: 74px;
    }
    .maatify-pos-left .maatify-chat-window {
        left: 0;
        right: auto;
    }
}

/* Window Header */
.maatify-chat-header {
    background: var(--maatify-primary);
    color: #ffffff;
    padding: 14px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-top-left-radius: 16px;
    border-top-right-radius: 16px;
}

.maatify-header-brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.maatify-avatar-frame {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: #ffffff;
    padding: 2px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 6px rgba(0,0,0,0.15);
    flex-shrink: 0;
}

.maatify-header-logo {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
}

.maatify-header-info {
    display: flex;
    flex-direction: column;
}

.maatify-header-title {
    margin: 0;
    font-size: 15px;
    font-weight: 700;
    color: #ffffff;
    line-height: 1.2;
}

.maatify-header-status {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    color: rgba(255, 255, 255, 0.85);
    margin-top: 2px;
}

.maatify-status-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #10b981;
    display: inline-block;
}

.maatify-header-actions button {
    background: rgba(255, 255, 255, 0.15);
    border: none;
    color: #ffffff;
    cursor: pointer;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s ease;
    padding: 0;
}

.maatify-header-actions button:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* Sub-bar with quick actions */
.maatify-chat-subbar {
    background: var(--maatify-surface);
    border-bottom: 1px solid var(--maatify-border);
    padding: 8px 14px;
    display: flex;
    justify-content: center;
    align-items: center;
}

.maatify-subbar-btn {
    background: #ffffff;
    border: 1px solid var(--maatify-border);
    color: var(--maatify-text);
    padding: 5px 14px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: all 0.15s ease;
}

.maatify-subbar-btn:hover {
    background: #f8fafc;
    border-color: var(--maatify-primary);
    color: var(--maatify-primary);
}

.maatify-message-content a {
    color: var(--maatify-primary);
    text-decoration: underline;
    font-weight: 600;
}

.maatify-message-content a:hover {
    filter: brightness(0.85);
}

/* Messages Container */
.maatify-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    background: #ffffff;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.maatify-message {
    display: flex;
    flex-direction: column;
    max-width: 82%;
    word-break: break-word;
}

.maatify-message.user {
    align-self: flex-end;
}

.maatify-message.ai,
.maatify-message.agent {
    align-self: flex-start;
}

.maatify-message-content {
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 13.5px;
    line-height: 1.5;
}

.maatify-message.user .maatify-message-content {
    background: var(--maatify-primary);
    color: #ffffff;
    border-bottom-right-radius: 3px;
}

.maatify-message.ai .maatify-message-content {
    background: #f1f5f9;
    color: var(--maatify-text);
    border: 1px solid #e2e8f0;
    border-bottom-left-radius: 3px;
}

.maatify-message.agent .maatify-message-content {
    background: #fcf0d7;
    color: #934F13;
    border: 1px solid #F9B637;
    border-bottom-left-radius: 3px;
}

.maatify-sender-tag {
    display: flex;
    align-items: center;
    gap: 2px;
    font-size: 11px;
    font-weight: 700;
    margin-bottom: 4px;
    color: var(--maatify-primary);
}

.maatify-message.agent .maatify-sender-tag {
    color: #864b00;
}

.maatify-message-time {
    font-size: 10px;
    color: var(--maatify-muted);
    margin-top: 3px;
    align-self: flex-end;
}

.maatify-message.system {
    align-self: center;
    background: #fef3c7;
    color: #92400e;
    font-size: 11.5px;
    padding: 6px 14px;
    border-radius: 20px;
    text-align: center;
    max-width: 90%;
}

/* Typing Indicator */
.maatify-typing-indicator {
    align-self: flex-start;
    display: flex;
    align-items: center;
    margin-top: 4px;
}

.maatify-typing-bubble {
    background: #f1f5f9;
    border: 1px solid #e2e8f0;
    padding: 8px 12px;
    border-radius: 14px;
    display: flex;
    gap: 4px;
}

.maatify-dot {
    width: 6px;
    height: 6px;
    background: #94a3b8;
    border-radius: 50%;
    animation: maatify-bounce 1.4s infinite ease-in-out both;
}

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

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

/* Footer & Input */
.maatify-chat-footer {
    padding: 10px 14px;
    background: var(--maatify-surface);
    border-top: 1px solid var(--maatify-border);
}

.maatify-chat-form {
    display: flex;
    align-items: center;
    background: #ffffff;
    border: 1px solid var(--maatify-border);
    border-radius: 24px;
    padding: 4px 6px 4px 14px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}

.maatify-chat-form:focus-within {
    border-color: var(--maatify-primary);
    box-shadow: 0 0 0 2px rgba(79, 70, 229, 0.15);
}

.maatify-chat-input {
    flex: 1;
    border: none;
    outline: none;
    background: transparent;
    font-size: 13.5px;
    color: var(--maatify-text);
    padding: 6px 0;
}

.maatify-send-btn {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: var(--maatify-primary);
    color: #ffffff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s ease, transform 0.1s ease;
    flex-shrink: 0;
    padding: 0;
}

.maatify-send-btn:hover {
    transform: scale(1.05);
    color: #ffffff;
}

.maatify-send-btn:active {
    transform: scale(0.95);
}

.maatify-chat-disclaimer {
    text-align: center;
    font-size: 10.5px;
    color: #94a3b8;
    margin-top: 6px;
}
