/* Peri V4 Premium UX Scoped CSS */
:root {
    --peri-primary: #14C6D8;
    --peri-secondary: #123B6A;
    --peri-light: rgba(248, 250, 252, 0.95);
    --peri-white: #ffffff;
    --peri-text: #334155;
    --peri-border: rgba(226, 232, 240, 0.7);
    --peri-shadow: 0 16px 40px rgba(18, 59, 106, 0.12);
    --peri-shadow-soft: 0 4px 12px rgba(0, 0, 0, 0.05);
    --peri-wa: #25D366;
}

.peri-widget {
    position: fixed;
    right: 24px;
    bottom: 24px;
    z-index: 9999;
    font-family: 'Inter', sans-serif;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    pointer-events: none;
}

/* Float Button */
.peri-btn {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background-color: var(--peri-white);
    border: 2px solid var(--peri-primary);
    box-shadow: var(--peri-shadow);
    cursor: pointer;
    overflow: hidden;
    padding: 0;
    transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: auto;
}

.peri-btn img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.peri-btn:hover {
    transform: scale(1.08) translateY(-4px);
    box-shadow: 0 20px 45px rgba(20, 198, 216, 0.25);
}

.peri-pulse {
    animation: periPulse 2.5s infinite cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes periPulse {
    0% { box-shadow: 0 0 0 0 rgba(20, 198, 216, 0.5); }
    70% { box-shadow: 0 0 0 18px rgba(20, 198, 216, 0); }
    100% { box-shadow: 0 0 0 0 rgba(20, 198, 216, 0); }
}

/* Chat Window (Glassmorphism) */
.peri-chat {
    width: 380px;
    height: 580px;
    background-color: rgba(255, 255, 255, 0.88);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-radius: 20px;
    box-shadow: var(--peri-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    margin-bottom: 20px;
    opacity: 0;
    pointer-events: none;
    visibility: hidden;
    transform: translateY(30px) scale(0.95);
    transform-origin: bottom right;
    transition: opacity 0.4s cubic-bezier(0.16, 1, 0.3, 1), transform 0.4s cubic-bezier(0.16, 1, 0.3, 1);
    border: 1px solid rgba(255, 255, 255, 0.5);
}

.peri-chat.open {
    opacity: 1;
    pointer-events: auto;
    visibility: visible;
    transform: translateY(0) scale(1);
}

/* Chat Header (Animated Gradient) */
.peri-header {
    background: linear-gradient(135deg, var(--peri-secondary) 0%, var(--peri-primary) 50%, var(--peri-secondary) 100%);
    background-size: 200% 200%;
    animation: gradientMove 8s ease infinite;
    padding: 18px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    color: var(--peri-white);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

@keyframes gradientMove {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

.peri-header-info {
    display: flex;
    align-items: center;
    gap: 14px;
}

.peri-header-avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.8);
    object-fit: cover;
    box-shadow: 0 0 10px rgba(255, 255, 255, 0.3);
}

.peri-header-text {
    display: flex;
    flex-direction: column;
}

.peri-name {
    font-weight: 700;
    font-size: 1.15rem;
    line-height: 1.2;
    letter-spacing: 0.3px;
}

.peri-status {
    font-size: 0.85rem;
    opacity: 0.95;
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 2px;
}

.peri-online-dot {
    width: 8px;
    height: 8px;
    background-color: #4ade80;
    border-radius: 50%;
    display: inline-block;
    box-shadow: 0 0 6px rgba(74, 222, 128, 0.6);
}

.peri-close {
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: var(--peri-white);
    width: 32px;
    height: 32px;
    border-radius: 50%;
    font-size: 1.5rem;
    cursor: pointer;
    transition: background-color 0.2s, transform 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.peri-close:hover {
    background: rgba(255, 255, 255, 0.25);
    transform: scale(1.1);
}

/* Chat Body */
.peri-body {
    flex: 1;
    padding: 20px 16px;
    overflow-y: auto;
    background-color: transparent;
    display: flex;
    flex-direction: column;
    gap: 14px;
    scrollbar-width: thin;
    scrollbar-color: rgba(20, 198, 216, 0.3) transparent;
}

.peri-body::-webkit-scrollbar {
    width: 6px;
}
.peri-body::-webkit-scrollbar-thumb {
    background-color: rgba(20, 198, 216, 0.3);
    border-radius: 10px;
}

/* Messages */
.peri-msg {
    max-width: 85%;
    padding: 14px 18px;
    font-size: 0.95rem;
    line-height: 1.5;
    word-wrap: break-word;
    animation: periFadeInUp 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
    opacity: 0;
    transform: translateY(15px);
    box-shadow: var(--peri-shadow-soft);
}

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

.peri-msg.peri {
    background-color: var(--peri-white);
    color: var(--peri-text);
    align-self: flex-start;
    border-radius: 18px 18px 18px 4px;
    border: 1px solid rgba(226, 232, 240, 0.8);
}

.peri-msg.user {
    background: linear-gradient(135deg, var(--peri-primary), #0fa6b5);
    color: var(--peri-white);
    align-self: flex-end;
    border-radius: 18px 18px 4px 18px;
    border: none;
}

/* Typing Indicator */
.peri-typing-indicator {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 14px 18px;
    background-color: var(--peri-white);
    align-self: flex-start;
    border-radius: 18px 18px 18px 4px;
    border: 1px solid rgba(226, 232, 240, 0.8);
    box-shadow: var(--peri-shadow-soft);
    animation: periFadeInUp 0.3s ease-out forwards;
}

.peri-typing-dot {
    width: 6px;
    height: 6px;
    background-color: #94a3b8;
    border-radius: 50%;
    animation: typingBounce 1.4s infinite ease-in-out;
}

.peri-typing-dot:nth-child(1) { animation-delay: 0s; }
.peri-typing-dot:nth-child(2) { animation-delay: 0.2s; }
.peri-typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingBounce {
    0%, 80%, 100% { transform: translateY(0); }
    40% { transform: translateY(-6px); }
}

/* Quick Actions */
.peri-quick-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 6px;
    margin-bottom: 6px;
    animation: periFadeInUp 0.4s ease forwards;
    animation-delay: 0.1s;
    opacity: 0;
}

.peri-action-btn {
    background-color: rgba(255, 255, 255, 0.9);
    border: 1.5px solid var(--peri-primary);
    color: var(--peri-secondary);
    padding: 10px 16px;
    border-radius: 20px;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    font-family: inherit;
    box-shadow: 0 2px 6px rgba(20, 198, 216, 0.1);
}

.peri-action-btn:hover {
    background-color: var(--peri-primary);
    color: var(--peri-white);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(20, 198, 216, 0.3);
}

.peri-action-btn:active {
    transform: scale(0.96);
}

/* WhatsApp CTA Button */
.peri-cta-btn {
    display: block;
    background: linear-gradient(135deg, #25D366 0%, #128C7E 100%);
    color: white;
    text-decoration: none;
    padding: 12px 20px;
    border-radius: 12px;
    margin-top: 12px;
    font-weight: 600;
    text-align: center;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(37, 211, 102, 0.3);
}

.peri-cta-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(37, 211, 102, 0.4);
    color: white;
}

.peri-cta-btn:active {
    transform: scale(0.98);
}

/* Input Area */
.peri-footer {
    padding: 16px;
    background-color: rgba(255, 255, 255, 0.95);
    border-top: 1px solid var(--peri-border);
    display: flex;
    gap: 12px;
    align-items: center;
}

.peri-input {
    flex: 1;
    border: 1.5px solid var(--peri-border);
    border-radius: 24px;
    padding: 12px 18px;
    font-size: 0.95rem;
    outline: none;
    font-family: inherit;
    background-color: var(--peri-light);
    transition: all 0.3s ease;
}

.peri-input:focus {
    border-color: var(--peri-primary);
    background-color: var(--peri-white);
    box-shadow: 0 0 0 3px rgba(20, 198, 216, 0.1);
}

.peri-send {
    background: linear-gradient(135deg, var(--peri-primary), #0fa6b5);
    color: var(--peri-white);
    border: none;
    border-radius: 24px;
    padding: 12px 20px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
    box-shadow: 0 4px 12px rgba(20, 198, 216, 0.25);
}

.peri-send:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(20, 198, 216, 0.35);
}
.peri-send:active {
    transform: scale(0.95);
}

/* Responsive */
@media (max-width: 768px) {
    .peri-widget {
        right: 16px;
        bottom: 16px;
    }
    
    .peri-chat {
        width: calc(100vw - 32px);
        height: 75vh;
        max-height: 600px;
        bottom: 0;
        margin-bottom: 16px;
    }

    .peri-header {
        padding: 14px 16px;
    }
    .peri-btn {
        width: 56px;
        height: 56px;
    }
    
    /* Mobile Fix for Input Area Overflow */
    .peri-footer {
        box-sizing: border-box;
        width: auto;
        align-self: stretch;
        max-width: 100%;
        padding: 12px;
        gap: 8px;
    }
    .peri-input {
        min-width: 0;
        flex: 1 1 auto;
        padding: 10px 14px;
        box-sizing: border-box;
        font-size: 16px !important;
    }
    .peri-send {
        flex-shrink: 0;
        padding: 10px 16px;
        white-space: nowrap;
        box-sizing: border-box;
    }
}

/* Accessibility: Reduced Motion */
@media (prefers-reduced-motion: reduce) {
    .peri-btn, .peri-chat, .peri-msg, .peri-action-btn, .peri-cta-btn, .peri-send, .peri-header {
        animation: none !important;
        transition: none !important;
        transform: none !important;
    }
    .peri-pulse {
        animation: none;
        box-shadow: none;
    }
    .peri-typing-indicator {
        animation: none;
    }
    .peri-typing-dot {
        animation: none;
    }
}
