/* chat.css - Jivo-style Floating Chat Widget for Monolit-69 */

.web-chat-widget {
    position: fixed;
    bottom: 50px; /* Приподнял выше от края */
    right: 80px; /* Сдвинем чуть левее, чтобы не перекрывать Telegram-кнопку (которая на right: 20px) */
    z-index: 9999;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    font-family: 'Inter', -apple-system, sans-serif;
}

/* Floating Action Button */
.web-chat-btn {
    width: 68px;
    height: 68px;
    border-radius: 50%;
    background: var(--color-primary, #00ff88);
    color: #111;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(0, 255, 136, 0.4);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    border: none;
    outline: none;
}

.web-chat-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 20px rgba(0, 255, 136, 0.6);
}

@keyframes chatBounce {
    0%   { transform: translateY(0) scale(1); }
    10%  { transform: translateY(-15px) scale(1); }
    20%  { transform: translateY(0) scale(1); }
    25%  { transform: translateY(-5px) scale(1); }
    30%  { transform: translateY(0) scale(1); }
    100% { transform: translateY(0) scale(1); }
}

.web-chat-widget:not(.active) .web-chat-btn {
    animation: chatBounce 4s infinite ease-in-out;
}

.web-chat-widget:not(.active) .web-chat-btn:hover {
    animation: none;
}

.web-chat-btn svg {
    width: 34px;
    height: 34px;
    transition: transform 0.3s ease;
}

.web-chat-widget.active .web-chat-btn {
    opacity: 0;
    pointer-events: none;
    transform: scale(0);
}

.web-chat-widget.active .web-chat-btn svg {
    transform: rotate(90deg) scale(0);
    opacity: 0;
}

.web-chat-btn-close {
    position: absolute;
    width: 34px;
    height: 34px;
    opacity: 0;
    transform: rotate(-90deg) scale(0);
    transition: transform 0.3s ease, opacity 0.3s ease;
}

.web-chat-widget.active .web-chat-btn-close {
    opacity: 1;
    transform: rotate(0) scale(1);
}

/* Chat Panel */
.web-chat-panel {
    width: 350px;
    height: 500px;
    max-height: calc(100vh - 100px);
    max-width: calc(100vw - 40px);
    background: #1e1e24; /* match app style */
    border-radius: 16px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    margin-bottom: 20px;
    
    transform: translateY(20px) scale(0.9);
    opacity: 0;
    pointer-events: none;
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    transform-origin: bottom right;
    border: 1px solid rgba(255,255,255,0.05);
}

.web-chat-widget.active .web-chat-panel {
    transform: translateY(0) scale(1);
    opacity: 1;
    pointer-events: all;
}

/* Header Close Button */
.web-chat-header-close {
    background: none;
    border: none;
    color: rgba(255,255,255,0.5);
    cursor: pointer;
    padding: 6px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, color 0.2s;
    margin-left: auto;
    flex-shrink: 0;
}

.web-chat-header-close:hover {
    background: rgba(255,255,255,0.1);
    color: #fff;
}

/* Chat Header */
.web-chat-header {
    background: #2a2a32;
    padding: 16px;
    display: flex;
    align-items: center;
    border-bottom: 1px solid rgba(255,255,255,0.05);
}

.web-chat-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--color-primary, #00ff88);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 12px;
    color: #111;
}

.web-chat-title-group {
    flex: 1;
}

.web-chat-title {
    color: #fff;
    font-size: 16px;
    font-weight: 600;
    margin: 0 0 2px 0;
}

.web-chat-subtitle {
    color: #a0a0ab;
    font-size: 12px;
    margin: 0;
    display: flex;
    align-items: center;
    gap: 4px;
}

.web-chat-status {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--color-primary, #00ff88);
    box-shadow: 0 0 8px var(--color-primary, #00ff88);
}

.web-chat-status.offline {
    background: #ff4d4f;
    box-shadow: 0 0 8px rgba(255, 77, 79, 0.5);
}

/* Messages Area */
.web-chat-messages {
    flex: 1;
    padding: 16px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: #141418;
}

.web-chat-message {
    max-width: 85%;
    padding: 12px 16px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.4;
    word-break: break-word;
    animation: messageSlideIn 0.3s ease;
}

@keyframes messageSlideIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.web-chat-message.client {
    align-self: flex-end;
    background: var(--color-primary, #00ff88);
    color: #111;
    border-bottom-right-radius: 4px;
}

.web-chat-message.manager {
    align-self: flex-start;
    background: #2a2a32;
    color: #fff;
    border-bottom-left-radius: 4px;
}

.web-chat-time {
    font-size: 10px;
    margin-top: 4px;
    text-align: right;
    opacity: 0.7;
}

.web-chat-message.manager .web-chat-time {
    color: #a0a0ab;
}

/* Input Area */
.web-chat-input-area {
    background: #2a2a32;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.web-chat-name-input {
    width: 100%;
    background: #141418;
    color: #fff;
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 8px;
    padding: 8px 12px;
    font-size: 13px;
    font-family: inherit;
    outline: none;
    box-sizing: border-box;
    transition: border-color 0.2s;
}

.web-chat-name-input:focus {
    border-color: var(--color-primary, #00ff88);
}

.web-chat-name-input:disabled {
    opacity: 0.6;
    background: #111;
}

.web-chat-textarea-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    width: 100%;
}

.web-chat-textarea {
    flex: 1;
    background: #141418;
    color: #fff;
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 20px;
    padding: 12px 16px;
    font-size: 14px;
    resize: none;
    max-height: 100px;
    min-height: 20px;
    font-family: inherit;
    outline: none;
    transition: border-color 0.2s;
}

.web-chat-textarea:focus {
    border-color: var(--color-primary, #00ff88);
}

.web-chat-textarea::placeholder {
    color: #6a6a75;
}

.web-chat-send-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--color-primary, #00ff88);
    color: #111;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    transition: opacity 0.2s, transform 0.2s;
}

.web-chat-send-btn:active {
    transform: scale(0.95);
}

.web-chat-send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    background: #444;
    color: #888;
}

.web-chat-unread-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: #ff3b30;
    color: white;
    font-size: 11px;
    font-weight: bold;
    min-width: 20px;
    height: 20px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 6px;
    box-sizing: border-box;
    box-shadow: 0 2px 5px rgba(0,0,0,0.3);
    border: 2px solid #141418;
    transform: scale(0);
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.web-chat-unread-badge.visible {
    transform: scale(1);
}

/* Mobile Responsiveness */
@media (max-width: 600px) {
    .web-chat-panel {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: var(--chat-bottom, 0px);
        width: 100%;
        height: auto;
        max-width: none;
        max-height: none;
        margin: 0;
        border-radius: 0;
        transform: translateY(100%) scale(0.98);
        transform-origin: bottom center;
        z-index: 10000;
        /* iOS safe area: account for notch at top */
        padding-top: env(safe-area-inset-top, 0px);
    }

    .web-chat-widget.active .web-chat-panel {
        transform: translateY(0) scale(1);
    }

    /* Header gets extra top padding for the status bar on iPhone */
    .web-chat-header {
        padding-top: max(16px, env(safe-area-inset-top, 16px));
    }

    /* Input area: pad bottom for iPhone home bar */
    .web-chat-input-area {
        padding-bottom: max(12px, env(safe-area-inset-bottom, 12px));
    }

    .web-chat-btn {
        position: fixed;
        bottom: max(35px, calc(20px + env(safe-area-inset-bottom, 0px)));
        right: 20px;
        z-index: 10001;
        width: 56px;
        height: 56px;
    }

    .web-chat-btn svg {
        width: 28px;
        height: 28px;
    }

    .web-chat-btn-close {
        width: 38px;
        height: 38px;
    }

    /* Larger tap target for name input on mobile */
    .web-chat-name-input {
        font-size: 16px; /* prevents iOS auto-zoom on focus */
        padding: 10px 14px;
    }

    /* Larger message text area */
    .web-chat-textarea {
        font-size: 16px; /* prevents iOS auto-zoom on focus */
    }
}


/* Custom Scrollbar for Chat */
.web-chat-panel *::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
.web-chat-panel *::-webkit-scrollbar-track {
    background: transparent;
}
.web-chat-panel *::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.15);
    border-radius: 10px;
}
.web-chat-panel *::-webkit-scrollbar-thumb:hover {
    background: var(--color-primary, #00ff88);
}

.web-chat-messages {
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.15) transparent;
}
.web-chat-textarea {
    scrollbar-width: none;
}
.web-chat-textarea::-webkit-scrollbar {
    display: none; /* Hide scrollbar completely for the textarea to make it look cleaner */
}

/* Typing Indicator Animation */
.typing-indicator {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 12px 18px !important;
    min-width: 40px;
    height: 38px;
}
.typing-indicator span {
    display: inline-block;
    width: 6px;
    height: 6px;
    background-color: rgba(255, 255, 255, 0.7);
    border-radius: 50%;
    margin: 0 2px;
    animation: typingBounce 1.4s infinite both;
}
.typing-indicator span:nth-child(1) { animation-delay: -0.32s; }
.typing-indicator span:nth-child(2) { animation-delay: -0.16s; }

@keyframes typingBounce {
    0%, 80%, 100% { transform: scale(0); opacity: 0.5; }
    40% { transform: scale(1); opacity: 1; }
}
