/* استایل‌های ویجت چت عمومی */

.poshtiban-widget {
    position: fixed;
    z-index: 999999;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
}

/* موقعیت‌های مختلف ویجت */
.poshtiban-widget.bottom-right {
    bottom: 20px;
    right: 20px;
}

.poshtiban-widget.bottom-left {
    bottom: 20px;
    left: 20px;
}

.poshtiban-widget.top-right {
    top: 20px;
    right: 20px;
}

.poshtiban-widget.top-left {
    top: 20px;
    left: 20px;
}

/* دکمه باز کردن چت */
.poshtiban-toggle {
    width: var(--widget-size, 60px);
    height: var(--widget-size, 60px);
    border-radius: 50%;
    background: var(--widget-color, #0084ff);
    border: none;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    transition: all 0.3s ease;
    position: relative;
}

.poshtiban-toggle:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
}

.poshtiban-toggle svg {
    width: calc(var(--widget-size, 60px) * 0.46);
    height: calc(var(--widget-size, 60px) * 0.46);
}

.poshtiban-toggle .close-icon {
    position: absolute;
}

/* افکت‌ها */
.poshtiban-toggle.pulse {
    animation: poshtiban-pulse 1.8s infinite;
}

.poshtiban-toggle.bounce {
    animation: poshtiban-bounce 1.5s infinite;
}

@keyframes poshtiban-pulse {
    0% { box-shadow: 0 0 0 0 rgba(0, 132, 255, 0.4); }
    70% { box-shadow: 0 0 0 15px rgba(0, 132, 255, 0); }
    100% { box-shadow: 0 0 0 0 rgba(0, 132, 255, 0); }
}

@keyframes poshtiban-bounce {
    0%, 20%, 53%, 80%, 100% {transform: translate3d(0,0,0);}
    40%, 43% {transform: translate3d(0, -8px, 0);}
    70% {transform: translate3d(0, -4px, 0);}
    90% {transform: translate3d(0,-2px,0);}
}

/* نشان اعلان */
.notification-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: #ff3838;
    color: white;
    border-radius: 10px;
    padding: 2px 8px;
    font-size: 11px;
    font-weight: bold;
    min-width: 20px;
    text-align: center;
}

/* پنجره چت */
.poshtiban-window {
    position: absolute;
    width: 360px;
    max-width: 98vw;
    height: 520px;
    background: white;
    border-radius: 12px;
    box-shadow: 0 5px 40px rgba(0, 0, 0, 0.16);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: slideUp 0.3s ease;
}

/* موقعیت پنجره بر اساس موقعیت دکمه */
.poshtiban-widget.bottom-right .poshtiban-window {
    bottom: 80px;
    right: 0;
}

.poshtiban-widget.bottom-left .poshtiban-window {
    bottom: 80px;
    left: 0;
}

.poshtiban-widget.top-right .poshtiban-window {
    top: 80px;
    right: 0;
}

.poshtiban-widget.top-left .poshtiban-window {
    top: 80px;
    left: 0;
}

/* انیمیشن */
@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* هدر چت */
.poshtiban-header {
    background: var(--widget-color, #0084ff);
    color: white;
    padding: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.header-info h3 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
}

.status-indicator {
    display: inline-flex;
    align-items: center;
    font-size: 12px;
    margin-top: 5px;
}

.status-indicator::before {
    content: '';
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-left: 6px;
    display: inline-block;
}

.status-indicator.online::before {
    background: #4caf50;
}

.status-indicator.offline::before {
    background: #f44336;
}

.minimize-btn {
    background: none;
    border: none;
    color: white;
    cursor: pointer;
    padding: 5px;
}

.minimize-btn svg {
    width: 20px;
    height: 20px;
}

/* فرم شروع چت */
.poshtiban-start-form {
    padding: 30px 20px;
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.poshtiban-start-form h4 {
    margin: 0 0 20px 0;
    text-align: center;
    color: #333;
}

#start-chat-form {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

#start-chat-form input,
#start-chat-form textarea {
    padding: 12px;
    border: 1px solid #ddd;
    border-radius: 8px;
    font-size: 14px;
    font-family: inherit;
    transition: border-color 0.3s ease;
}

#start-chat-form input:focus,
#start-chat-form textarea:focus {
    outline: none;
    border-color: var(--widget-color, #0084ff);
}

#start-chat-form textarea {
    min-height: 80px;
    resize: vertical;
}

.start-chat-btn {
    padding: 12px 24px;
    background: var(--widget-color, #0084ff);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.3s ease;
}

.start-chat-btn:hover {
    opacity: 0.9;
}

/* بخش پیام‌ها */
.poshtiban-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background: #f5f5f5;
    position: relative;
}

.messages-container {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* پیشنهادهای هوشمند */
.poshtiban-suggestions {
    position: absolute;
    top: 16px;
    right: 12px;
    width: 260px;
    max-height: 260px;
    background: #ecf0f3;
    border-radius: 18px;
    box-shadow: 12px 12px 24px #c9ced3, -12px -12px 24px #ffffff;
    padding: 12px;
    overflow: hidden;
    z-index: 5;
    border: 1px solid #e6e6e6;
    animation: slideInSuggestion 0.25s ease;
}

.suggestions-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 6px;
}

.suggestions-actions {
    display: flex;
    align-items: center;
    gap: 6px;
}

.suggestion-prev,
.suggestion-next {
    width: 26px;
    height: 26px;
    border: none;
    border-radius: 50%;
    background: #ecf0f3;
    box-shadow: inset 3px 3px 6px #c9ced3, inset -3px -3px 6px #ffffff;
    cursor: pointer;
    font-size: 14px;
    line-height: 1;
    color: #555;
    transition: all 0.2s ease;
}

.suggestion-prev:disabled,
.suggestion-next:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.close-suggestions {
    background: none;
    border: none;
    font-size: 16px;
    cursor: pointer;
    line-height: 1;
    color: #666;
}

.suggestions-list-wrapper {
    overflow-x: auto;
    overflow-y: hidden;
    scroll-snap-type: x mandatory;
    padding-bottom: 6px;
}

.suggestions-list {
    display: flex;
    flex-direction: row;
    gap: 12px;
    min-width: max-content;
    scroll-snap-type: x mandatory;
}

.suggestion-card {
    background: #ecf0f3;
    border-radius: 12px;
    padding: 12px;
    box-shadow: inset 6px 6px 12px #d0d4d8, inset -6px -6px 12px #ffffff;
    min-width: 210px;
    scroll-snap-align: start;
}

.suggestion-title {
    font-weight: 600;
    font-size: 13px;
    margin-bottom: 4px;
    color: #111;
}

.suggestion-excerpt {
    font-size: 12px;
    color: #555;
    margin-bottom: 6px;
}

.suggestion-link {
    font-size: 12px;
    color: var(--widget-color, #0084ff);
    text-decoration: none;
    font-weight: 600;
}

.suggestion-link:hover {
    text-decoration: underline;
}

@keyframes slideInSuggestion {
    from { transform: translateX(12px); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* استایل حباب‌های پیام مدرن */
.chat-message .message-bubble {
    border-radius: 16px;
    background: linear-gradient(145deg, #ffffff, #f1f3f6);
    box-shadow: 4px 4px 12px rgba(0,0,0,0.05), -3px -3px 8px rgba(255,255,255,0.9);
}

.chat-message.user .message-bubble {
    background: linear-gradient(145deg, var(--widget-color, #0084ff), #4fa3ff);
    color: #fff;
    box-shadow: 6px 6px 14px rgba(0,132,255,0.25), -4px -4px 10px rgba(255,255,255,0.15);
}

.chat-message.admin .message-bubble,
.chat-message.system .message-bubble {
    background: linear-gradient(145deg, #ffffff, #eef1f5);
}

/* ریسپانسیو قوی‌تر برای موبایل */
@media (max-width: 480px) {
    .poshtiban-window {
        width: calc(100vw - 16px);
        height: calc(100vh - 40px);
        border-radius: 14px;
        bottom: 8px !important;
        right: 8px !important;
        left: 8px !important;
        top: auto !important;
    }
    .poshtiban-suggestions {
        position: fixed;
        right: 12px;
        left: 12px;
        bottom: 90px;
        top: auto;
        width: auto;
        max-height: 220px;
    }
    .messages-container {
        padding-bottom: 20px;
    }
    .message-bubble {
        max-width: 90%;
    }
}

.chat-message {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    animation: fadeIn 0.25s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

.chat-message.user {
    flex-direction: row-reverse;
}

.message-bubble {
    max-width: 80%;
    padding: 12px 14px;
    border-radius: 18px;
    word-wrap: break-word;
    background: linear-gradient(145deg, #ffffff, #f1f3f6);
    box-shadow: 4px 4px 12px rgba(0,0,0,0.05), -3px -3px 8px rgba(255,255,255,0.9);
}

.chat-message.user .message-bubble {
    background: linear-gradient(145deg, var(--widget-color, #0084ff), #4fa3ff);
    color: white;
    border-bottom-left-radius: 4px;
    box-shadow: 6px 6px 14px rgba(0,132,255,0.25), -4px -4px 10px rgba(255,255,255,0.15);
}

.chat-message.admin .message-bubble,
.chat-message.system .message-bubble {
    background: linear-gradient(145deg, #ffffff, #eef1f5);
    color: #333;
    border-bottom-right-radius: 4px;
    box-shadow: inset 2px 2px 6px rgba(0,0,0,0.05);
}

.chat-message.system .message-bubble {
    background: #fff3cd;
    color: #856404;
    font-style: italic;
    text-align: center;
    max-width: 90%;
}

.message-time {
    font-size: 11px;
    color: #999;
    margin-top: 4px;
}

/* بخش ورودی پیام */
.poshtiban-input {
    padding: 15px;
    background: white;
    border-top: 1px solid #e0e0e0;
}

.poshtiban-options {
    margin-bottom: 8px;
    font-size: 12px;
    color: #555;
    display: flex;
    align-items: center;
    gap: 6px;
}

.input-group {
    display: flex;
    gap: 10px;
    align-items: flex-end;
}

#message-input {
    flex: 1;
    padding: 10px 14px;
    border: 1px solid #ddd;
    border-radius: 24px;
    resize: none;
    font-family: inherit;
    font-size: 14px;
    line-height: 1.4;
    max-height: 120px;
    transition: border-color 0.3s ease;
}

#message-input:focus {
    outline: none;
    border-color: var(--widget-color, #0084ff);
}

.send-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--widget-color, #0084ff);
    border: none;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s ease;
}

.send-btn:hover {
    transform: scale(1.05);
}

.send-btn svg {
    width: 20px;
    height: 20px;
}

/* نشانگر تایپ کردن */
.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 10px;
    align-items: center;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #999;
    animation: typing 1.4s infinite;
}

.typing-indicator span:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-indicator span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing {
    0%, 60%, 100% {
        transform: translateY(0);
    }
    30% {
        transform: translateY(-10px);
    }
}

/* ویجت سایدبار */
.poshtiban-sidebar-widget {
    text-align: center;
    padding: 15px;
}

.open-chat-sidebar {
    width: 100%;
    padding: 10px 20px;
    background: var(--widget-color, #0084ff);
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 16px;
    transition: background 0.3s ease;
}

.open-chat-sidebar:hover {
    opacity: 0.9;
}

/* Responsive Mobile Configurable (Dynamic with JS) */
@media (max-width: 700px) {
  .poshtiban-window {
    position: fixed !important;
    top: 0 !important;
    right: 0 !important;
    left: auto !important;
    bottom: auto !important;
    width: var(--mobile-width, 100vw) !important;
    height: var(--mobile-height, 90vh) !important;
    max-width: 100vw !important;
    min-width: 0;
    max-height: 100vh !important;
    min-height: 320px;
    border-radius: 0 0 24px 0 !important; /* فقط پایین چپ گرد باشد */
    margin: 0;
    z-index: 999999;
    overflow: hidden;
    box-shadow: 0 8px 32px rgba(0,0,0,0.09);
  }
  .poshtiban-messages {
    padding: 8px;
  }
  .poshtiban-start-form {
    padding: 10px;
    min-height: 160px;
  }
  .poshtiban-suggestions {
    left: 0;
    right: 0;
    width: 100vw;
    max-width: 100vw;
  }
  .message-bubble { max-width: 96%; }
}
