/**
 * عطرمهدی - تماس با مشتری
 * استایل فرانت‌اند
 * Version: 1.0.0
 */

:root {
    --atremahdi-primary: #0a5c36;
    --atremahdi-whatsapp: #25D366;
    --atremahdi-whatsapp-dark: #128C7E;
    --atremahdi-telegram: #0088cc;
    --atremahdi-telegram-dark: #229ED9;
    --atremahdi-bale: #29B6F6;
    --atremahdi-bale-dark: #0288D1;
    --atremahdi-phone: #4CAF50;
    --atremahdi-phone-dark: #2E7D32;
    --atremahdi-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
    --atremahdi-shadow-lg: 0 20px 60px rgba(0, 0, 0, 0.25);
    --atremahdi-radius: 16px;
    --atremahdi-transition: cubic-bezier(0.34, 1.56, 0.64, 1);
    --atremahdi-z: 99999;
}

/* === Wrapper === */
.atremahdi-cw-wrap {
    position: fixed;
    bottom: 24px;
    z-index: var(--atremahdi-z);
    font-family: 'Vazirmatn', 'Tahoma', sans-serif;
    direction: rtl;
    box-sizing: border-box;
}

.atremahdi-cw-wrap *,
.atremahdi-cw-wrap *::before,
.atremahdi-cw-wrap *::after {
    box-sizing: border-box;
}

.atremahdi-cw-pos-left {
    left: 24px;
}

.atremahdi-cw-pos-right {
    right: 24px;
}

/* === دکمه اصلی شناور === */
.atremahdi-cw-main-btn {
    position: relative;
    width: 64px;
    height: 64px;
    border: none;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--atremahdi-primary), color-mix(in srgb, var(--atremahdi-primary) 70%, black));
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 8px 24px rgba(10, 92, 54, 0.4), 0 0 0 0 rgba(10, 92, 54, 0.5);
    transition: all 0.4s var(--atremahdi-transition);
    animation: atremahdi-cw-bounce-in 0.8s var(--atremahdi-transition);
    overflow: visible;
}

.atremahdi-cw-main-btn:hover {
    transform: scale(1.08) rotate(8deg);
    box-shadow: 0 12px 32px rgba(10, 92, 54, 0.5);
}

.atremahdi-cw-main-btn:active {
    transform: scale(0.95);
}

.atremahdi-cw-main-btn.is-open {
    transform: rotate(135deg);
    background: linear-gradient(135deg, #f44336, #d32f2f);
    box-shadow: 0 8px 24px rgba(244, 67, 54, 0.4);
}

/* پالس انیمیشن */
.atremahdi-cw-pulse {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background: var(--atremahdi-primary);
    z-index: -1;
    animation: atremahdi-cw-pulse 2.5s infinite;
}

.atremahdi-cw-pulse-2 {
    animation-delay: 1.25s;
}

@keyframes atremahdi-cw-pulse {
    0% {
        transform: scale(1);
        opacity: 0.7;
    }
    100% {
        transform: scale(1.8);
        opacity: 0;
    }
}

@keyframes atremahdi-cw-bounce-in {
    0% {
        transform: scale(0);
        opacity: 0;
    }
    60% {
        transform: scale(1.2);
        opacity: 1;
    }
    100% {
        transform: scale(1);
    }
}

/* آیکون‌های دکمه اصلی */
.atremahdi-cw-main-icon {
    position: absolute;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
}

.atremahdi-cw-icon-close {
    opacity: 0;
    transform: rotate(-90deg) scale(0.5);
}

.atremahdi-cw-main-btn.is-open .atremahdi-cw-icon-default {
    opacity: 0;
    transform: rotate(-90deg) scale(0.5);
}

.atremahdi-cw-main-btn.is-open .atremahdi-cw-icon-close {
    opacity: 1;
    transform: rotate(-135deg) scale(1);
}

/* بَج نشانگر تعداد */
.atremahdi-cw-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background: #f44336;
    color: #fff;
    font-size: 12px;
    font-weight: 700;
    min-width: 22px;
    height: 22px;
    padding: 0 6px;
    border-radius: 11px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid #fff;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
    animation: atremahdi-cw-badge-pulse 2s infinite;
}

@keyframes atremahdi-cw-badge-pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}

/* تولتیپ */
.atremahdi-cw-main-btn[data-tooltip]::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 50%;
    transform: translateY(50%);
    background: #2c3e50;
    color: #fff;
    padding: 8px 14px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: all 0.3s ease;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.atremahdi-cw-pos-left .atremahdi-cw-main-btn[data-tooltip]::after {
    right: 80px;
}

.atremahdi-cw-pos-right .atremahdi-cw-main-btn[data-tooltip]::after {
    left: 80px;
}

.atremahdi-cw-main-btn:hover[data-tooltip]::after {
    opacity: 1;
    transform: translateY(50%) translateX(0);
}

.atremahdi-cw-pos-left .atremahdi-cw-main-btn:hover[data-tooltip]::after {
    transform: translateY(50%) translateX(-8px);
}

.atremahdi-cw-pos-right .atremahdi-cw-main-btn:hover[data-tooltip]::after {
    transform: translateY(50%) translateX(8px);
}

/* === پنل پاپ‌آپ === */
.atremahdi-cw-panel {
    position: absolute;
    bottom: 80px;
    width: 340px;
    max-width: calc(100vw - 48px);
    background: #fff;
    border-radius: 20px;
    box-shadow: var(--atremahdi-shadow-lg);
    overflow: hidden;
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px) scale(0.9);
    transform-origin: bottom;
    transition: all 0.4s var(--atremahdi-transition);
}

.atremahdi-cw-panel.is-open {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
}

.atremahdi-cw-pos-left .atremahdi-cw-panel {
    left: 0;
}

.atremahdi-cw-pos-right .atremahdi-cw-panel {
    right: 0;
}

/* هدر پنل */
.atremahdi-cw-panel-header {
    padding: 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    color: #fff;
    position: relative;
    overflow: hidden;
}

.atremahdi-cw-panel-header::before {
    content: '';
    position: absolute;
    top: -50%;
    right: -50%;
    width: 200%;
    height: 200%;
    background: radial-gradient(circle, rgba(255, 255, 255, 0.15) 0%, transparent 70%);
    animation: atremahdi-cw-shine 4s infinite;
}

@keyframes atremahdi-cw-shine {
    0%, 100% { transform: rotate(0deg); }
    50% { transform: rotate(180deg); }
}

.atremahdi-cw-panel-header-content {
    display: flex;
    align-items: center;
    gap: 12px;
    position: relative;
    z-index: 1;
}

.atremahdi-cw-avatar {
    width: 48px;
    height: 48px;
    background: rgba(255, 255, 255, 0.2);
    backdrop-filter: blur(10px);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid rgba(255, 255, 255, 0.3);
}

.atremahdi-cw-panel-header-text h3 {
    margin: 0 0 2px;
    font-size: 16px;
    font-weight: 700;
    color: #fff;
}

.atremahdi-cw-status {
    font-size: 12px;
    color: rgba(255, 255, 255, 0.9);
    display: flex;
    align-items: center;
    gap: 6px;
}

.atremahdi-cw-status::before {
    content: '';
    width: 8px;
    height: 8px;
    background: #4caf50;
    border-radius: 50%;
    box-shadow: 0 0 0 0 rgba(76, 175, 80, 0.7);
    animation: atremahdi-cw-status-pulse 2s infinite;
}

@keyframes atremahdi-cw-status-pulse {
    0% { box-shadow: 0 0 0 0 rgba(76, 175, 80, 0.7); }
    70% { box-shadow: 0 0 0 8px rgba(76, 175, 80, 0); }
    100% { box-shadow: 0 0 0 0 rgba(76, 175, 80, 0); }
}

.atremahdi-cw-panel-close {
    background: rgba(255, 255, 255, 0.15);
    border: none;
    color: #fff;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    position: relative;
    z-index: 1;
}

.atremahdi-cw-panel-close:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: rotate(90deg);
}

/* بدنه پنل */
.atremahdi-cw-panel-body {
    padding: 16px;
}

.atremahdi-cw-welcome {
    background: linear-gradient(135deg, #f8f9fa, #e9ecef);
    padding: 14px 16px;
    border-radius: 12px;
    margin-bottom: 14px;
    position: relative;
}

.atremahdi-cw-welcome::before {
    content: '';
    position: absolute;
    bottom: -8px;
    right: 24px;
    width: 16px;
    height: 16px;
    background: #f8f9fa;
    transform: rotate(45deg);
}

.atremahdi-cw-welcome p {
    margin: 0;
    font-size: 13px;
    color: #555;
    line-height: 1.7;
}

/* کانال‌ها */
.atremahdi-cw-channels {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.atremahdi-cw-channel {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 12px 14px;
    background: #f8f9fa;
    border-radius: 14px;
    text-decoration: none;
    color: #333;
    transition: all 0.3s ease;
    border: 2px solid transparent;
    position: relative;
    overflow: hidden;
}

.atremahdi-cw-channel::before {
    content: '';
    position: absolute;
    top: 0;
    right: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.4), transparent);
    transition: right 0.6s ease;
}

.atremahdi-cw-channel:hover::before {
    right: 100%;
}

.atremahdi-cw-channel:hover {
    transform: translateX(-6px);
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.1);
    border-color: rgba(0, 0, 0, 0.05);
}

.atremahdi-cw-channel-icon {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    flex-shrink: 0;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.15);
    transition: all 0.3s ease;
}

.atremahdi-cw-channel:hover .atremahdi-cw-channel-icon {
    transform: scale(1.1) rotate(5deg);
}

.atremahdi-cw-channel-whatsapp .atremahdi-cw-channel-icon {
    background: linear-gradient(135deg, #25D366, #128C7E);
}

.atremahdi-cw-channel-telegram .atremahdi-cw-channel-icon {
    background: linear-gradient(135deg, #0088cc, #229ED9);
}

.atremahdi-cw-channel-bale .atremahdi-cw-channel-icon {
    background: linear-gradient(135deg, #29B6F6, #0288D1);
}

.atremahdi-cw-channel-phone .atremahdi-cw-channel-icon {
    background: linear-gradient(135deg, #4CAF50, #2E7D32);
}

.atremahdi-cw-channel-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.atremahdi-cw-channel-title {
    font-size: 14px;
    font-weight: 700;
    color: #2c3e50;
}

.atremahdi-cw-channel-desc {
    font-size: 11px;
    color: #7f8c8d;
}

.atremahdi-cw-channel-arrow {
    color: #bdc3c7;
    transition: all 0.3s ease;
}

.atremahdi-cw-channel:hover .atremahdi-cw-channel-arrow {
    color: var(--atremahdi-primary);
    transform: translateX(-4px);
}

/* فوتر پنل */
.atremahdi-cw-panel-footer {
    padding: 12px 20px;
    background: #f8f9fa;
    border-top: 1px solid #e9ecef;
    text-align: center;
}

.atremahdi-cw-footer-text {
    font-size: 11px;
    color: #95a5a6;
    font-weight: 500;
}

/* === حالت بدون پاپ‌آپ: دکمه‌های شناور مستقل === */
.atremahdi-cw-floating-channels {
    display: flex;
    flex-direction: column;
    gap: 12px;
    align-items: flex-start;
}

.atremahdi-cw-pos-right .atremahdi-cw-floating-channels {
    align-items: flex-end;
}

.atremahdi-cw-float-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0;
    width: 56px;
    height: 56px;
    border-radius: 28px;
    background: #fff;
    text-decoration: none;
    color: #fff;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.15);
    transition: all 0.4s var(--atremahdi-transition);
    overflow: hidden;
    position: relative;
    animation: atremahdi-cw-slide-in 0.6s var(--atremahdi-transition) backwards;
}

.atremahdi-cw-floating-channels .atremahdi-cw-float-btn:nth-child(1) { animation-delay: 0.1s; }
.atremahdi-cw-floating-channels .atremahdi-cw-float-btn:nth-child(2) { animation-delay: 0.2s; }
.atremahdi-cw-floating-channels .atremahdi-cw-float-btn:nth-child(3) { animation-delay: 0.3s; }
.atremahdi-cw-floating-channels .atremahdi-cw-float-btn:nth-child(4) { animation-delay: 0.4s; }

@keyframes atremahdi-cw-slide-in {
    from {
        opacity: 0;
        transform: translateX(-40px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.atremahdi-cw-pos-right .atremahdi-cw-float-btn {
    animation-name: atremahdi-cw-slide-in-right;
}

@keyframes atremahdi-cw-slide-in-right {
    from {
        opacity: 0;
        transform: translateX(40px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.atremahdi-cw-float-icon {
    width: 56px;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.3s ease;
}

.atremahdi-cw-float-whatsapp .atremahdi-cw-float-icon {
    background: linear-gradient(135deg, #25D366, #128C7E);
}

.atremahdi-cw-float-telegram .atremahdi-cw-float-icon {
    background: linear-gradient(135deg, #0088cc, #229ED9);
}

.atremahdi-cw-float-bale .atremahdi-cw-float-icon {
    background: linear-gradient(135deg, #29B6F6, #0288D1);
}

.atremahdi-cw-float-phone .atremahdi-cw-float-icon {
    background: linear-gradient(135deg, #4CAF50, #2E7D32);
}

.atremahdi-cw-float-label {
    font-size: 13px;
    font-weight: 600;
    color: #2c3e50;
    padding-left: 14px;
    white-space: nowrap;
}

.atremahdi-cw-float-btn:hover {
    width: 160px;
    transform: scale(1.05);
    box-shadow: 0 10px 28px rgba(0, 0, 0, 0.25);
}

/* === ریسپانسیو === */
@media (max-width: 768px) {
    .atremahdi-cw-wrap {
        /* بالاتر آوردن ویجت برای جلوگیری از همپوشانی با نوار سبد خرید موبایل وودمارت */
        bottom: 80px;
    }
    
    .atremahdi-cw-pos-left {
        left: 16px;
    }
    
    .atremahdi-cw-pos-right {
        right: 16px;
    }
    
    .atremahdi-cw-main-btn {
        width: 56px;
        height: 56px;
    }
    
    .atremahdi-cw-panel {
        width: calc(100vw - 32px);
        max-width: 320px;
        bottom: 72px;
    }
    
    .atremahdi-cw-main-btn[data-tooltip]::after {
        display: none;
    }
    
    .atremahdi-cw-float-btn {
        width: 48px;
        height: 48px;
    }
    
    .atremahdi-cw-float-icon {
        width: 48px;
        height: 48px;
    }
}

/* حرکت ورودی ویجت */
.atremahdi-cw-wrap {
    animation: atremahdi-cw-fade-up 0.8s ease;
}

@keyframes atremahdi-cw-fade-up {
    from {
        opacity: 0;
        transform: translateY(30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* انیمیشن مورب ورودی کانال‌ها */
.atremahdi-cw-panel.is-open .atremahdi-cw-channel {
    animation: atremahdi-cw-channel-in 0.5s ease backwards;
}

.atremahdi-cw-panel.is-open .atremahdi-cw-channel:nth-child(1) { animation-delay: 0.1s; }
.atremahdi-cw-panel.is-open .atremahdi-cw-channel:nth-child(2) { animation-delay: 0.15s; }
.atremahdi-cw-panel.is-open .atremahdi-cw-channel:nth-child(3) { animation-delay: 0.2s; }
.atremahdi-cw-panel.is-open .atremahdi-cw-channel:nth-child(4) { animation-delay: 0.25s; }

@keyframes atremahdi-cw-channel-in {
    from {
        opacity: 0;
        transform: translateX(20px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

/* انیمیشن ورودی پیام خوش‌آمدگویی */
.atremahdi-cw-panel.is-open .atremahdi-cw-welcome {
    animation: atremahdi-cw-fade-in 0.5s ease 0.05s backwards;
}

@keyframes atremahdi-cw-fade-in {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* === همپوشانی با المان‌های موبایل وودمارت/ووکامرس === */
/* نوار موبایل وودمارت معمولاً ارتفاع 50-60px دارد، ویجت را بالاتر می‌بریم */
@media (max-width: 1024px) {
    body.woodmart-dark .atremahdi-cw-wrap,
    body[class*="woodmart"] .atremahdi-cw-wrap,
    .woocommerce-active .atremahdi-cw-wrap {
        bottom: 80px;
    }
}

@media (max-width: 580px) {
    /* موبایل کوچک - بالاتر از نوار پایین وودمارت */
    .atremahdi-cw-wrap {
        bottom: 84px;
    }
    
    .atremahdi-cw-pos-left,
    .atremahdi-cw-pos-right {
        left: 14px;
        right: auto;
    }
    
    .atremahdi-cw-pos-right {
        right: 14px;
        left: auto;
    }
    
    .atremahdi-cw-main-btn {
        width: 54px;
        height: 54px;
    }
    
    .atremahdi-cw-panel {
        bottom: 68px;
        width: calc(100vw - 28px);
        max-width: 300px;
    }
    
    .atremahdi-cw-panel-header {
        padding: 16px;
    }
    
    .atremahdi-cw-panel-header-text h3 {
        font-size: 15px;
    }
    
    .atremahdi-cw-avatar {
        width: 42px;
        height: 42px;
    }
    
    .atremahdi-cw-channel {
        padding: 10px 12px;
    }
    
    .atremahdi-cw-channel-icon {
        width: 40px;
        height: 40px;
    }
}

/* وقتی نوار موبایل وودمارت فعال است (تشخیص از body class) */
body.xs-stack-nav-active .atremahdi-cw-wrap,
body.act-scroll .atremahdi-cw-wrap,
body.woodmart-mobile-nav .atremahdi-cw-wrap {
    bottom: 90px !important;
}

/* جلوگیری از پوشانده شدن توسط فوتر استیکی موبایل */
@media (max-width: 480px) {
    .atremahdi-cw-wrap {
        bottom: 88px;
    }
    
    .atremahdi-cw-pos-left {
        left: 12px;
    }
    
    .atremahdi-cw-pos-right {
        right: 12px;
    }
}

/* جلوگیری از همپوشانی با نوار اعلان بالای صفحه موبایل */
@media (max-width: 480px) and (orientation: portrait) {
    .atremahdi-cw-wrap {
        bottom: 90px;
    }
}

/* حالت لنداسکیپ موبایل */
@media (max-width: 900px) and (orientation: landscape) and (max-height: 500px) {
    .atremahdi-cw-wrap {
        bottom: 16px;
    }
    
    .atremahdi-cw-panel {
        bottom: 72px;
    }
    
    .atremahdi-cw-main-btn {
        width: 48px;
        height: 48px;
    }
}

/* === سازگاری با نوار مدیریت وردپرس در موبایل === */
@media (max-width: 782px) {
    body.admin-bar .atremahdi-cw-wrap {
        bottom: 100px;
    }
}

/* وقتی کیبورد موبایل باز است */
@media (max-width: 768px) {
    body.atremahdi-keyboard-open .atremahdi-cw-wrap {
        bottom: 16px !important;
        opacity: 0.5;
    }
}

/* === سازگاری با iPhone X+ notch (env safe-area) === */
@supports (padding: max(0px)) {
    .atremahdi-cw-wrap {
        bottom: max(24px, env(safe-area-inset-bottom));
    }
    
    @media (max-width: 768px) {
        .atremahdi-cw-wrap {
            bottom: max(80px, env(safe-area-inset-bottom));
        }
        
        .atremahdi-cw-pos-left {
            left: max(16px, env(safe-area-inset-left));
        }
        
        .atremahdi-cw-pos-right {
            right: max(16px, env(safe-area-inset-right));
        }
    }
    
    @media (max-width: 480px) {
        .atremahdi-cw-wrap {
            bottom: max(88px, env(safe-area-inset-bottom));
        }
    }
}
