/* MKS Chat Widget */
.mks-chat-widget {
    --mks-chat-primary: var(--mks-color-primary, #3b82f6);
    --mks-chat-shadow: 0 8px 32px rgba(15, 23, 42, 0.18), 0 2px 8px rgba(15, 23, 42, 0.08);
    --mks-chat-radius: 16px;
    --mks-chat-transition: 0.4s cubic-bezier(0.34, 1.3, 0.64, 1);
}

/* Floating button */
.mks-chat-btn {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 64px;
    height: 64px;
    padding: 0;
    border: none;
    border-radius: 50%;
    overflow: visible;
    cursor: pointer;
    z-index: 9998;
    background: transparent;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    box-shadow: 0 4px 16px rgba(59, 130, 246, 0.35);
}

.mks-chat-btn:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 24px rgba(59, 130, 246, 0.45);
}

.mks-chat-btn:active {
    transform: scale(0.96);
}

.mks-chat-btn img {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    object-fit: cover;
    display: block;
    position: relative;
    z-index: 1;
}

.mks-chat-btn__pulse {
    position: absolute;
    inset: -4px;
    border-radius: 50%;
    background: var(--mks-chat-primary);
    opacity: 0.35;
    animation: mksChatPulse 2.5s ease-out infinite;
    z-index: 0;
}

.mks-chat-widget.is-open .mks-chat-btn__pulse {
    animation: none;
    opacity: 0;
}

.mks-chat-btn__badge {
    position: absolute;
    top: -2px;
    left: -2px;
    z-index: 2;
    min-width: 22px;
    height: 22px;
    padding: 0 6px;
    border-radius: 999px;
    background: #ef4444;
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    line-height: 22px;
    text-align: center;
    box-shadow: 0 2px 8px rgba(239, 68, 68, 0.45);
    border: 2px solid #fff;
    pointer-events: none;
    animation: mksChatBadgePop 0.35s ease;
}

.mks-chat-btn.has-unread .mks-chat-btn__pulse {
    background: #ef4444;
    animation-duration: 1.6s;
}

.mks-chat-btn.mks-chat-btn--alert {
    animation: mksChatBtnShake 0.55s ease;
}

.mks-chat-btn.mks-chat-btn--alert .mks-chat-btn__badge {
    animation: mksChatBadgePop 0.35s ease, mksChatBadgePulse 1s ease 0.35s 2;
}

@keyframes mksChatBtnShake {
    0%, 100% { transform: scale(1) rotate(0); }
    20% { transform: scale(1.08) rotate(-6deg); }
    40% { transform: scale(1.1) rotate(6deg); }
    60% { transform: scale(1.08) rotate(-4deg); }
    80% { transform: scale(1.05) rotate(3deg); }
}

@keyframes mksChatBadgePulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.2); }
}

@keyframes mksChatBadgePop {
    from {
        transform: scale(0.5);
        opacity: 0;
    }
    to {
        transform: scale(1);
        opacity: 1;
    }
}

@keyframes mksChatPulse {
    0% {
        transform: scale(1);
        opacity: 0.4;
    }
    70% {
        transform: scale(1.35);
        opacity: 0;
    }
    100% {
        transform: scale(1.35);
        opacity: 0;
    }
}

/* Backdrop */
.mks-chat-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.35);
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
    z-index: 9998;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.35s ease, visibility 0.35s ease;
}

.mks-chat-backdrop.is-visible {
    opacity: 1;
    visibility: visible;
}

/* Chat panel */
.mks-chat-screen {
    position: fixed;
    z-index: 9999;
    bottom: 100px;
    right: 24px;
    width: 340px;
    max-width: calc(100vw - 32px);
    background: #fff;
    border-radius: var(--mks-chat-radius);
    box-shadow: var(--mks-chat-shadow);
    overflow: hidden;
    transform-origin: bottom right;
    transform: scale(0.85) translateY(20px);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition:
        transform var(--mks-chat-transition),
        opacity 0.35s ease,
        visibility 0.35s ease;
}

.mks-chat-screen:not(.mks-chat-hide) {
    transform: scale(1) translateY(0);
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

/* Close button */
.mks-close-chat {
    position: absolute;
    left: 12px;
    top: 12px;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: rgba(255, 255, 255, 0.9);
    border-radius: 50%;
    font-size: 18px;
    color: #64748b;
    cursor: pointer;
    z-index: 2;
    transition: background 0.2s, color 0.2s, transform 0.2s;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
}

.mks-close-chat:hover {
    background: #fee2e2;
    color: #ef4444;
    transform: rotate(90deg);
}

/* Header */
.mks-cch {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 20px 20px 12px;
    background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
}

.mks-cch__avatar {
    width: 72px;
    height: 72px;
    border-radius: 14px;
    object-fit: cover;
    flex-shrink: 0;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.mks-cch__text {
    flex: 1;
    min-width: 0;
    padding-top: 4px;
}

.mks-cch__title {
    display: block;
    font-size: 17px;
    color: #1e293b;
    font-weight: 700;
    margin: 0 0 4px;
    line-height: 1.3;
}

.mks-cch__subtitle {
    font-size: 14px;
    color: #475569;
    margin: 0 0 4px;
    line-height: 1.4;
}

.mks-cch__hint {
    color: #94a3b8;
    font-size: 12px;
    line-height: 1.5;
}

/* Divider */
.mks-ccd-chat {
    width: calc(100% - 40px);
    height: 1px;
    background: linear-gradient(90deg, transparent, #e2e8f0, transparent);
    margin: 0 auto;
}

/* Message bubble */
.mks-cci {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 16px 20px;
}

.mks-cci__avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
}

.mks-cci__bubble {
    flex: 1;
    background: #f1f5f9;
    padding: 12px 16px;
    color: #475569;
    border-radius: 4px 16px 16px 16px;
    font-size: 13.5px;
    line-height: 1.65;
    position: relative;
    opacity: 0;
    transform: translateY(8px);
    animation: mksChatMessageIn 0.5s ease 0.3s forwards;
}

.mks-cci__text {
    margin: 0 0 10px;
}

.mks-cci__hint {
    margin: 10px 0 0;
    font-size: 12px;
    color: #94a3b8;
    line-height: 1.5;
}

.mks-cci__login {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 8px 14px;
    border-radius: 10px;
    background: var(--mks-chat-primary);
    color: #fff !important;
    font-size: 13px;
    font-weight: 600;
    text-decoration: none !important;
    transition: transform 0.2s ease, opacity 0.2s ease;
}

.mks-cci__login:hover {
    transform: translateY(-1px);
    opacity: 0.92;
    color: #fff !important;
}

@keyframes mksChatMessageIn {
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Social links section */
.mks-ccs {
    padding: 8px 20px 20px;
    background: #fafbfc;
    border-top: 1px solid #f1f5f9;
}

.mks-ccs__title {
    display: block;
    color: #334155;
    font-size: 13px;
    font-weight: 600;
    text-align: center;
    margin: 0 0 12px;
}

.mks-ccl {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
    width: 100%;
    margin: 0 auto;
}

.mks-ccl__link {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 8px 12px;
    border-radius: 12px;
    background: #fff;
    border: 1px solid #e2e8f0;
    text-decoration: none;
    transition: transform 0.25s ease, box-shadow 0.25s ease, border-color 0.25s ease;
    min-width: 72px;
}

.mks-ccl__link:hover {
    transform: translateY(-3px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    border-color: var(--mks-chat-primary);
}

.mks-ccl-icon {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    object-fit: cover;
}

.mks-ccl__name {
    font-size: 11px;
    color: #64748b;
    font-weight: 500;
}

/* Logged-in live support chat inside floating widget */
.mks-chat-screen--live {
    display: flex;
    flex-direction: column;
    width: 380px;
    max-height: min(640px, calc(100vh - 120px));
}

.mks-chat-screen--live .mks-cch {
    padding: 16px 20px 10px;
    flex-shrink: 0;
}

.mks-chat-screen--live .mks-cch__avatar {
    width: 52px;
    height: 52px;
    border-radius: 12px;
}

.mks-chat-screen--live .mks-cch__title {
    font-size: 15px;
}

.mks-chat-screen--live .mks-cch__subtitle {
    font-size: 13px;
}

.mks-chat-screen--live .mks-cch__hint {
    display: none;
}

.mks-chat-live {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.mks-chat-live .mks-sc--widget {
    height: 420px;
    min-height: 280px;
    max-height: none;
    border: none;
    border-radius: 0;
    box-shadow: none;
    border-top: 1px solid #e2e8f0;
}

.mks-chat-live .mks-sc__welcome {
    padding: 24px 16px;
}

.mks-chat-live .mks-sc__welcome-icon {
    font-size: 32px;
}

.mks-chat-live .mks-sc__welcome h3 {
    font-size: 0.9375rem;
}

.mks-chat-live .mks-sc__welcome p {
    font-size: 0.8125rem;
}

.mks-chat-live .mks-sc__bubble {
    max-width: 86%;
    font-size: 0.8125rem;
}

.mks-chat-live .mks-sc__composer {
    padding: 10px 12px;
}

.mks-chat-live .mks-sc__input {
    padding: 8px 14px;
    font-size: 0.8125rem;
}

.mks-chat-live .mks-sc__send {
    width: 40px;
    height: 40px;
    font-size: 14px;
}

/* Hidden state — reset legacy slide-out rules from style.css/mks9.css */
.mks-chat-widget .mks-chat-screen.mks-chat-hide {
    transform: scale(0.85) translateY(20px);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.mks-chat-widget .mks-chat-screen:not(.mks-chat-hide) {
    transform: scale(1) translateY(0);
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

/* Mobile */
@media (max-width: 480px) {
    .mks-chat-btn {
        bottom: 16px;
        right: 16px;
        width: 56px;
        height: 56px;
    }

    .mks-chat-btn img {
        width: 56px;
        height: 56px;
    }

    .mks-chat-btn__badge {
        min-width: 20px;
        height: 20px;
        line-height: 20px;
        font-size: 10px;
        padding: 0 5px;
    }

    .mks-chat-screen {
        bottom: 84px;
        right: 16px;
        left: 16px;
        width: auto;
        max-width: none;
        transform-origin: bottom center;
    }

    .mks-chat-screen--live {
        width: auto;
        max-height: calc(100vh - 100px);
    }

    .mks-chat-live .mks-sc--widget {
        height: min(420px, calc(100vh - 220px));
        min-height: 240px;
    }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    .mks-chat-btn__pulse {
        animation: none;
    }

    .mks-cci__bubble {
        animation: none;
        opacity: 1;
        transform: none;
    }

    .mks-chat-screen,
    .mks-chat-backdrop {
        transition-duration: 0.01ms;
    }
}
