/* =========================================================================
   MAH Chatbot Widget — Styles
   Self-contained, responsive, attention-grabbing chatbot UI.
   ========================================================================= */

/* --- Toggle Button ---------------------------------------------------- */
.mah-chat-toggle {
    position: fixed;
    bottom: 28px;
    right: 28px;
    z-index: 9999;
    width: 64px;
    height: 64px;
    border-radius: 50%;
    border: none;
    background: linear-gradient(135deg, var(--clr-primary) 0%, var(--clr-primary-dark) 100%);
    color: #fff;
    font-size: 28px;
    cursor: pointer;
    box-shadow: 0 6px 24px rgba(51, 153, 255, 0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    animation: mah-bounce-in 0.6s ease forwards, mah-pulse-ring 2.5s ease-in-out 1.5s 3;
}

.mah-chat-toggle:hover {
    transform: scale(1.1);
    box-shadow: 0 8px 30px rgba(51, 153, 255, 0.55);
}

.mah-chat-toggle.open .mah-chat-icon-bubble {
    display: none;
}

.mah-chat-toggle.open .mah-chat-icon-close {
    display: block;
}

.mah-chat-icon-close {
    display: none;
    font-size: 26px;
    line-height: 1;
}

.mah-chat-icon-bubble {
    display: block;
    line-height: 1;
}

/* Pulse ring behind toggle */
.mah-chat-toggle::before {
    content: '';
    position: absolute;
    top: -6px;
    left: -6px;
    right: -6px;
    bottom: -6px;
    border-radius: 50%;
    border: 3px solid var(--clr-primary);
    opacity: 0;
    animation: mah-ring-pulse 2.5s ease-in-out 1.5s 3;
    pointer-events: none;
}

.mah-chat-toggle.open::before {
    animation: none;
    opacity: 0;
}

/* Unread badge */
.mah-chat-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #ef4444;
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 6px rgba(239, 68, 68, 0.5);
    animation: mah-badge-pop 0.35s ease forwards;
    font-family: var(--font-body, 'Inter', sans-serif);
}

.mah-chat-badge.hidden {
    display: none;
}

/* Teaser bubble */
.mah-chat-teaser {
    position: fixed;
    bottom: 100px;
    right: 28px;
    z-index: 9998;
    background: #fff;
    color: var(--clr-text-main, #111);
    padding: 12px 18px;
    border-radius: 16px 16px 4px 16px;
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.12);
    font-family: var(--font-body, 'Inter', sans-serif);
    font-size: 14px;
    max-width: 260px;
    line-height: 1.45;
    opacity: 0;
    transform: translateY(10px) scale(0.95);
    transition: opacity 0.35s ease, transform 0.35s ease;
    pointer-events: none;
}

.mah-chat-teaser.visible {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
    cursor: pointer;
}

.mah-chat-teaser-close {
    position: absolute;
    top: -8px;
    right: -8px;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    border: none;
    background: var(--clr-text-muted, #64748B);
    color: #fff;
    font-size: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

/* --- Chat Window ------------------------------------------------------- */
.mah-chat-window {
    position: fixed;
    bottom: 104px;
    right: 28px;
    z-index: 9998;
    width: 400px;
    max-height: 560px;
    border-radius: 20px;
    background: #fff;
    box-shadow: 0 16px 60px rgba(0, 0, 0, 0.18);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    transform: translateY(20px) scale(0.92);
    pointer-events: none;
    transition: opacity 0.35s ease, transform 0.35s ease;
    font-family: var(--font-body, 'Inter', sans-serif);
}

.mah-chat-window.open {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

/* Header */
.mah-chat-header {
    background: linear-gradient(135deg, var(--clr-primary-dark, #1E7DE6) 0%, var(--clr-primary, #3399FF) 100%);
    color: #fff;
    padding: 18px 20px;
    display: flex;
    align-items: center;
    gap: 14px;
    flex-shrink: 0;
}

.mah-chat-avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    flex-shrink: 0;
    backdrop-filter: blur(6px);
}

.mah-chat-header-info {
    flex: 1;
}

.mah-chat-header-name {
    font-weight: 700;
    font-size: 15px;
    margin-bottom: 2px;
}

.mah-chat-header-status {
    font-size: 12px;
    opacity: 0.85;
    display: flex;
    align-items: center;
    gap: 5px;
}

.mah-chat-header-status::before {
    content: '';
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #4ade80;
    display: inline-block;
    animation: mah-status-glow 2s ease-in-out infinite;
}

.mah-chat-header-close {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    margin-left: auto;
    transition: background 0.2s;
}

.mah-chat-header-close:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* Body */
.mah-chat-body {
    flex: 1;
    overflow-y: auto;
    padding: 16px 16px 8px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    background: #f8fafc;
    min-height: 280px;
    max-height: 380px;
    scroll-behavior: smooth;
}

/* Scrollbar */
.mah-chat-body::-webkit-scrollbar {
    width: 5px;
}

.mah-chat-body::-webkit-scrollbar-track {
    background: transparent;
}

.mah-chat-body::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.12);
    border-radius: 10px;
}

/* Messages */
.mah-msg {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 13.5px;
    line-height: 1.55;
    animation: mah-msg-in 0.3s ease forwards;
    word-wrap: break-word;
}

.mah-msg-bot {
    align-self: flex-start;
    background: #fff;
    color: var(--clr-text-main, #111);
    border: 1px solid rgba(0, 0, 0, 0.06);
    border-radius: 16px 16px 16px 4px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}

.mah-msg-user {
    align-self: flex-end;
    background: linear-gradient(135deg, var(--clr-primary, #3399FF), var(--clr-primary-dark, #1E7DE6));
    color: #fff;
    border-radius: 16px 16px 4px 16px;
}

/* Typing indicator */
.mah-typing {
    align-self: flex-start;
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 12px 18px;
    background: #fff;
    border-radius: 16px 16px 16px 4px;
    border: 1px solid rgba(0, 0, 0, 0.06);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}

.mah-typing-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--clr-primary, #3399FF);
    animation: mah-dot-bounce 1.4s ease-in-out infinite;
}

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

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

/* Quick-reply chips */
.mah-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 4px 0 8px;
    animation: mah-msg-in 0.3s ease forwards;
}

.mah-chip {
    padding: 8px 16px;
    border-radius: 20px;
    border: 1.5px solid var(--clr-primary, #3399FF);
    background: rgba(51, 153, 255, 0.06);
    color: var(--clr-primary, #3399FF);
    font-size: 12.5px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: var(--font-body, 'Inter', sans-serif);
    white-space: nowrap;
}

.mah-chip:hover {
    background: var(--clr-primary, #3399FF);
    color: #fff;
    transform: translateY(-1px);
    box-shadow: 0 3px 10px rgba(51, 153, 255, 0.3);
}

/* CTA link in messages */
.mah-msg a.mah-cta-link {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    color: var(--clr-primary, #3399FF);
    font-weight: 700;
    text-decoration: none;
    transition: color 0.2s;
}

.mah-msg-user a.mah-cta-link {
    color: #fff;
    text-decoration: underline;
}

.mah-msg a.mah-cta-link:hover {
    text-decoration: underline;
}

/* Call-to-action banner in chat */
.mah-cta-banner {
    background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
    color: #fff;
    border-radius: 14px;
    padding: 14px 16px;
    text-align: center;
    animation: mah-msg-in 0.3s ease forwards;
    align-self: stretch;
    max-width: 100%;
}

.mah-cta-banner p {
    margin: 0 0 10px;
    font-size: 13px;
    line-height: 1.45;
}

.mah-cta-banner a {
    display: inline-block;
    background: var(--clr-primary, #3399FF);
    color: #fff;
    padding: 8px 20px;
    border-radius: 20px;
    font-weight: 700;
    font-size: 13px;
    text-decoration: none;
    transition: background 0.2s, transform 0.2s;
}

.mah-cta-banner a:hover {
    background: var(--clr-primary-dark, #1E7DE6);
    transform: translateY(-1px);
}

/* Input bar */
.mah-chat-input-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 14px;
    border-top: 1px solid rgba(0, 0, 0, 0.06);
    background: #fff;
    flex-shrink: 0;
}

.mah-chat-input {
    flex: 1;
    border: 1.5px solid rgba(0, 0, 0, 0.1);
    border-radius: 22px;
    padding: 10px 16px;
    font-size: 13.5px;
    font-family: var(--font-body, 'Inter', sans-serif);
    outline: none;
    transition: border-color 0.2s;
    background: #f8fafc;
}

.mah-chat-input:focus {
    border-color: var(--clr-primary, #3399FF);
    background: #fff;
}

.mah-chat-input::placeholder {
    color: #94a3b8;
}

.mah-chat-send {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: linear-gradient(135deg, var(--clr-primary, #3399FF), var(--clr-primary-dark, #1E7DE6));
    color: #fff;
    font-size: 17px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s, box-shadow 0.2s;
    flex-shrink: 0;
}

.mah-chat-send:hover {
    transform: scale(1.08);
    box-shadow: 0 3px 12px rgba(51, 153, 255, 0.4);
}

/* Powered-by footer */
.mah-chat-footer {
    text-align: center;
    padding: 6px 0;
    font-size: 10px;
    color: #94a3b8;
    background: #fff;
    border-top: 1px solid rgba(0, 0, 0, 0.03);
    flex-shrink: 0;
}

/* --- Animations ------------------------------------------------------- */
@keyframes mah-bounce-in {
    0% {
        transform: scale(0) rotate(-45deg);
        opacity: 0;
    }

    60% {
        transform: scale(1.15) rotate(0deg);
        opacity: 1;
    }

    100% {
        transform: scale(1) rotate(0deg);
    }
}

@keyframes mah-ring-pulse {

    0%,
    100% {
        opacity: 0;
        transform: scale(1);
    }

    50% {
        opacity: 0.6;
        transform: scale(1.15);
    }
}

@keyframes mah-pulse-ring {

    0%,
    100% {
        box-shadow: 0 6px 24px rgba(51, 153, 255, 0.45);
    }

    50% {
        box-shadow: 0 6px 24px rgba(51, 153, 255, 0.45), 0 0 0 12px rgba(51, 153, 255, 0.15);
    }
}

@keyframes mah-badge-pop {
    0% {
        transform: scale(0);
    }

    70% {
        transform: scale(1.25);
    }

    100% {
        transform: scale(1);
    }
}

@keyframes mah-dot-bounce {

    0%,
    80%,
    100% {
        transform: scale(0.6);
        opacity: 0.4;
    }

    40% {
        transform: scale(1);
        opacity: 1;
    }
}

@keyframes mah-msg-in {
    from {
        opacity: 0;
        transform: translateY(8px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes mah-status-glow {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.4;
    }
}

/* --- Responsive: Mobile & Tablet Full-Screen Native Messenger --- */
@media (max-width: 768px) {
    .mah-chat-window {
        position: fixed;
        bottom: 0;
        right: 0;
        left: 0;
        top: 0;
        width: 100%;
        max-width: 100%;
        height: 100dvh;
        max-height: none;
        border-radius: 0;
        transform: translateY(100%); /* slide in from bottom */
        display: flex;
        flex-direction: column;
        box-sizing: border-box;
    }

    .mah-chat-window.open {
        transform: translateY(0); /* end slide */
    }

    .mah-chat-window.open~.mah-chat-toggle {
        display: none;
    }

    .mah-chat-body {
        max-height: none;
        flex: 1;
        padding-bottom: 16px;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch; /* smooth scroll on iOS */
    }

    .mah-chat-header {
        padding: 16px 18px;
        padding-top: env(safe-area-inset-top, 16px);
        border-radius: 0;
        position: sticky;
        top: 0;
        z-index: 10;
    }

    .mah-chat-toggle {
        bottom: 18px;
        right: 18px;
        width: 58px;
        height: 58px;
        font-size: 24px;
    }

    .mah-chat-teaser {
        right: 18px;
        bottom: 84px;
        max-width: 220px;
    }

    /* App Mode: Chat takes over the document entirely on mobile */
    body.mah-app-mode {
        background: #f8fafc !important;
        margin: 0 !important;
        padding: 0 !important;
        overflow: hidden !important;
    }
    
    body.mah-app-mode > *:not(.mah-chat-window):not(.mah-chat-toggle):not(.mah-chat-teaser) {
        display: none !important;
    }

    body.mah-app-mode .mah-chat-window {
        position: relative !important;
        width: 100% !important;
        height: 100dvh !important; /* Shrinks exactly when keyboard opens */
        max-height: 100dvh !important;
        border-radius: 0 !important;
        transform: none !important; /* No sliding translation in app mode */
        display: flex !important;
        flex-direction: column !important;
    }
}
