/* =====================================================
   INOKHARID - ویجت چت آنلاین پشتیبانی
   هماهنگ با متغیرهای رنگی و استایل کلی قالب (--ik-*)
   ===================================================== */

.ik-chat-widget {
    position: fixed;
    bottom: 24px;
    left: 24px; /* سایت راست‌چین است؛ گوشه پایین-چپ کمتر مزاحم محتواست */
    z-index: 99999;
    font-family: 'Vazirmatn', 'Tahoma', 'Arial', sans-serif;
    direction: rtl;
}

/* ---------- دکمه شناور ---------- */
.ik-chat-fab {
    width: 62px;
    height: 62px;
    border-radius: var(--ik-radius-full, 9999px);
    background: linear-gradient(145deg, var(--ik-primary, #360404), var(--ik-primary-light, #5a0a0a));
    box-shadow: var(--ik-shadow-lg, 0 8px 40px rgba(54,4,4,.12)), 0 0 0 0 rgba(245,166,35,.5);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    transition: var(--ik-transition, all .25s cubic-bezier(.4,0,.2,1));
    animation: ik-chat-pulse 2.6s ease-in-out infinite;
}

.ik-chat-fab:hover {
    transform: translateY(-3px) scale(1.04);
    box-shadow: var(--ik-shadow-lg, 0 8px 40px rgba(54,4,4,.12)), 0 0 0 8px rgba(245,166,35,.12);
}

.ik-chat-fab svg {
    width: 26px;
    height: 26px;
    stroke: #fff;
    transition: transform .25s ease, opacity .2s ease;
}

.ik-chat-fab .ik-chat-icon-close {
    position: absolute;
    opacity: 0;
    transform: scale(.5) rotate(-45deg);
}

.ik-chat-widget.is-open .ik-chat-fab .ik-chat-icon-chat {
    opacity: 0;
    transform: scale(.5) rotate(45deg);
}

.ik-chat-widget.is-open .ik-chat-fab .ik-chat-icon-close {
    opacity: 1;
    transform: scale(1) rotate(0deg);
}

@keyframes ik-chat-pulse {
    0%, 100% { box-shadow: var(--ik-shadow-lg, 0 8px 40px rgba(54,4,4,.12)), 0 0 0 0 rgba(245,166,35,.35); }
    50%      { box-shadow: var(--ik-shadow-lg, 0 8px 40px rgba(54,4,4,.12)), 0 0 0 10px rgba(245,166,35,0); }
}

.ik-chat-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 20px;
    height: 20px;
    padding: 0 4px;
    border-radius: 999px;
    background: var(--ik-accent, #F5A623);
    color: var(--ik-text-on-accent, #1A0808);
    font-size: 11px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid #fff;
}

/* ---------- پنجره چت ---------- */
.ik-chat-panel {
    position: fixed;
    bottom: 100px;
    left: 24px;
    width: 360px;
    max-width: calc(100vw - 32px);
    height: 520px;
    max-height: calc(100vh - 140px);
    max-height: calc(100dvh - 140px);
    background: var(--ik-bg-card, #fff);
    border-radius: var(--ik-radius-lg, 22px);
    box-shadow: var(--ik-shadow-lg, 0 8px 40px rgba(54,4,4,.12));
    border: 1px solid var(--ik-border, #ECECEC);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    transform: translateY(16px) scale(.97);
    pointer-events: none;
    transform-origin: bottom left;
    transition: var(--ik-transition, all .25s cubic-bezier(.4,0,.2,1));
}

.ik-chat-widget.is-open .ik-chat-panel {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

/* ---------- هدر پنجره ---------- */
.ik-chat-header {
    background: linear-gradient(135deg, var(--ik-primary, #360404), var(--ik-primary-dark, #1e0202));
    color: var(--ik-text-on-primary, #fff);
    padding: 16px 18px;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

.ik-chat-header .ik-chat-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--ik-accent, #F5A623);
    color: var(--ik-text-on-accent, #1A0808);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 15px;
    flex-shrink: 0;
}

.ik-chat-header .ik-chat-title-wrap {
    flex: 1;
    min-width: 0;
}

.ik-chat-header .ik-chat-title {
    font-size: 15px;
    font-weight: 700;
    margin: 0 0 2px;
}

.ik-chat-header .ik-chat-status {
    font-size: 12px;
    opacity: .85;
    display: flex;
    align-items: center;
    gap: 6px;
}

.ik-chat-header .ik-chat-status-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #4ADE80;
    box-shadow: 0 0 0 2px rgba(255,255,255,.25);
    flex-shrink: 0;
}

.ik-chat-header .ik-chat-close-btn {
    background: rgba(255,255,255,.12);
    border: none;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background .2s ease;
}

.ik-chat-header .ik-chat-close-btn:hover {
    background: rgba(255,255,255,.22);
}

.ik-chat-header .ik-chat-close-btn svg {
    width: 16px;
    height: 16px;
    stroke: #fff;
}

/* ---------- بدنه: فرم شروع گفتگو ---------- */
.ik-chat-body {
    flex: 1;
    overflow-y: auto;
    background: var(--ik-bg-section, #FAFAFA);
}

.ik-chat-start {
    padding: 22px 20px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    height: 100%;
    box-sizing: border-box;
}

.ik-chat-start p.ik-chat-intro {
    margin: 0 0 4px;
    font-size: 13.5px;
    color: var(--ik-text-muted, #80706E);
    line-height: 1.9;
}

.ik-chat-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.ik-chat-field label {
    font-size: 12.5px;
    font-weight: 600;
    color: var(--ik-text, #201414);
}

.ik-chat-field label .ik-chat-optional {
    font-weight: 400;
    color: var(--ik-text-light, #B3A6A4);
    font-size: 11.5px;
}

.ik-chat-field input {
    border: 1px solid var(--ik-border, #ECECEC);
    background: #fff;
    border-radius: var(--ik-radius-sm, 8px);
    padding: 11px 13px;
    font-family: inherit;
    font-size: 13.5px;
    color: var(--ik-text, #201414);
    outline: none;
    transition: var(--ik-transition, all .25s cubic-bezier(.4,0,.2,1));
    direction: rtl;
}

.ik-chat-field input::placeholder {
    color: var(--ik-text-light, #B3A6A4);
}

.ik-chat-field input:focus {
    border-color: var(--ik-primary, #360404);
    box-shadow: 0 0 0 3px rgba(54,4,4,.07);
}

.ik-chat-field input.ik-input-error {
    border-color: var(--ik-error, #C62828);
}

.ik-chat-field .ik-chat-error-msg {
    font-size: 11.5px;
    color: var(--ik-error, #C62828);
    display: none;
}

.ik-chat-field.has-error .ik-chat-error-msg {
    display: block;
}

.ik-chat-start-btn {
    margin-top: 4px;
    background: var(--ik-accent, #F5A623);
    color: var(--ik-text-on-accent, #1A0808);
    border: none;
    border-radius: var(--ik-radius-sm, 8px);
    padding: 12px 16px;
    font-family: inherit;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: var(--ik-transition, all .25s cubic-bezier(.4,0,.2,1));
}

.ik-chat-start-btn:hover {
    background: var(--ik-accent-dark, #D4881A);
    transform: translateY(-1px);
}

.ik-chat-start-btn svg {
    width: 17px;
    height: 17px;
    stroke: var(--ik-text-on-accent, #1A0808);
}

.ik-chat-privacy-note {
    font-size: 11px;
    color: var(--ik-text-light, #B3A6A4);
    text-align: center;
    margin: 2px 0 0;
    line-height: 1.7;
}

/* ---------- بدنه: پیام‌ها ---------- */
.ik-chat-messages {
    display: none;
    flex-direction: column;
    gap: 10px;
    padding: 16px;
    height: 100%;
    box-sizing: border-box;
    overflow-y: auto;
}

.ik-chat-widget.ik-chat-active .ik-chat-messages { display: flex; }
.ik-chat-widget.ik-chat-active .ik-chat-start { display: none; }

.ik-chat-msg {
    max-width: 82%;
    padding: 10px 13px;
    border-radius: var(--ik-radius-md, 14px);
    font-size: 13.5px;
    line-height: 1.8;
    word-break: break-word;
}

.ik-chat-msg.ik-msg-agent {
    align-self: flex-start;
    background: #fff;
    border: 1px solid var(--ik-border, #ECECEC);
    color: var(--ik-text, #201414);
    border-bottom-left-radius: 4px;
}

.ik-chat-msg.ik-msg-user {
    align-self: flex-end;
    background: var(--ik-primary, #360404);
    color: var(--ik-text-on-primary, #fff);
    border-bottom-right-radius: 4px;
}

.ik-chat-msg-time {
    display: block;
    font-size: 10px;
    opacity: .6;
    margin-top: 4px;
}

.ik-chat-typing {
    align-self: flex-start;
    display: none;
    align-items: center;
    gap: 4px;
    background: #fff;
    border: 1px solid var(--ik-border, #ECECEC);
    padding: 11px 14px;
    border-radius: var(--ik-radius-md, 14px);
    border-bottom-left-radius: 4px;
}

.ik-chat-typing.is-visible { display: flex; }

.ik-chat-typing span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--ik-text-light, #B3A6A4);
    animation: ik-typing-bounce 1.2s infinite ease-in-out;
}

.ik-chat-typing span:nth-child(2) { animation-delay: .15s; }
.ik-chat-typing span:nth-child(3) { animation-delay: .3s; }

@keyframes ik-typing-bounce {
    0%, 60%, 100% { transform: translateY(0); opacity: .5; }
    30% { transform: translateY(-4px); opacity: 1; }
}

/* ---------- فوتر: ورودی پیام ---------- */
.ik-chat-footer {
    display: none;
    align-items: center;
    gap: 8px;
    padding: 12px 14px;
    border-top: 1px solid var(--ik-border, #ECECEC);
    background: #fff;
    flex-shrink: 0;
}

.ik-chat-widget.ik-chat-active .ik-chat-footer { display: flex; }

.ik-chat-footer textarea {
    flex: 1;
    resize: none;
    border: 1px solid var(--ik-border, #ECECEC);
    border-radius: var(--ik-radius-sm, 8px);
    padding: 10px 12px;
    font-family: inherit;
    font-size: 13.5px;
    color: var(--ik-text, #201414);
    outline: none;
    max-height: 90px;
    min-height: 42px;
    line-height: 1.6;
    transition: var(--ik-transition, all .25s cubic-bezier(.4,0,.2,1));
}

.ik-chat-footer textarea:focus {
    border-color: var(--ik-primary, #360404);
    box-shadow: 0 0 0 3px rgba(54,4,4,.07);
}

.ik-chat-send-btn {
    width: 42px;
    height: 42px;
    border-radius: var(--ik-radius-sm, 8px);
    background: var(--ik-primary, #360404);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: var(--ik-transition, all .25s cubic-bezier(.4,0,.2,1));
}

.ik-chat-send-btn:hover { background: var(--ik-primary-hover, #4a0606); }
.ik-chat-send-btn:disabled { opacity: .5; cursor: not-allowed; }

.ik-chat-send-btn svg {
    width: 18px;
    height: 18px;
    stroke: #fff;
    transform: scaleX(-1); /* راست به چپ */
}

/* ---------- اسکرول‌بار ---------- */
.ik-chat-messages::-webkit-scrollbar,
.ik-chat-body::-webkit-scrollbar {
    width: 5px;
}
.ik-chat-messages::-webkit-scrollbar-thumb,
.ik-chat-body::-webkit-scrollbar-thumb {
    background: var(--ik-border, #ECECEC);
    border-radius: 10px;
}

/* ---------- موبایل ---------- */
/* وقتی نوار پایین شناور قالب (تب‌بار) فعال است، دکمه چت باید بالاتر از آن
   قرار بگیرد نه پشت آن. متغیر --ik-tabbar-clear توسط قالب تعریف می‌شود و
   ارتفاع امن تب‌بار + safe-area را مشخص می‌کند؛ اگر قالب فعال نبود یا این
   متغیر تعریف نشده بود، مقدار پیش‌فرض 24px استفاده می‌شود. */
@media (max-width: 1024px) {
    .ik-chat-widget {
        bottom: calc(var(--ik-tabbar-clear, 24px) + 10px);
    }
    .ik-chat-panel {
        bottom: calc(var(--ik-tabbar-clear, 24px) + 74px);
    }
}

@media (max-width: 480px) {
    .ik-chat-widget {
        left: 16px;
    }
    .ik-chat-panel {
        left: 16px;
        width: calc(100vw - 32px);
        height: calc(100vh - calc(var(--ik-tabbar-clear, 24px) + 74px) - 16px);
        height: calc(100dvh - calc(var(--ik-tabbar-clear, 24px) + 74px) - 16px);
        max-height: calc(100vh - calc(var(--ik-tabbar-clear, 24px) + 74px) - 16px);
        max-height: calc(100dvh - calc(var(--ik-tabbar-clear, 24px) + 74px) - 16px);
    }
    .ik-chat-fab {
        width: 56px;
        height: 56px;
    }
}
