.chat-button {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    border: none;
    outline: none;
}

.chat-button:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.5);
}

.chat-button:active {
    transform: scale(0.95);
}

.chat-icon-svg {
    width: 28px;
    height: 28px;
    color: white;
}

.chat-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 20px;
    height: 20px;
    border-radius: 10px;
    background: #ff4757;
    color: white;
    font-size: 12px;
    font-weight: bold;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 0 5px;
    box-shadow: 0 2px 8px rgba(255, 71, 87, 0.4);
}

.chat-badge.show {
    display: flex;
}

@keyframes pulse {
    0% {
        box-shadow: 0 0 0 0 rgba(102, 126, 234, 0.7);
    }
    70% {
        box-shadow: 0 0 0 15px rgba(102, 126, 234, 0);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(102, 126, 234, 0);
    }
}

.chat-button.has-notification {
    animation: pulse 2s infinite;
}

.chat-button.has-notification .chat-icon-svg {
    animation: shake 0.5s ease-in-out;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-3px) rotate(-5deg); }
    50% { transform: translateX(3px) rotate(5deg); }
    75% { transform: translateX(-3px) rotate(-5deg); }
}

.chat-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 9998;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.chat-overlay.show {
    opacity: 1;
    visibility: visible;
}

.chat-window {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 100vh;
    height: 100dvh;
    background: #fff;
    display: flex;
    flex-direction: column;
    z-index: 9999;
    overflow: hidden;
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.chat-window.show {
    transform: translateY(0);
}

.chat-header {
    padding: 16px 20px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
    padding-top: max(16px, env(safe-area-inset-top));
}

.header-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
    font-size: 16px;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #2ed573;
    flex-shrink: 0;
}

.status-dot.offline {
    background: #ff6b6b;
}

.close-btn {
    background: none;
    border: none;
    color: white;
    font-size: 28px;
    cursor: pointer;
    padding: 0;
    line-height: 1;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background 0.2s ease;
}

.close-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

.chat-messages {
    flex: 1;
    padding: 16px;
    overflow-y: auto;
    background: #f8f9fa;
    -webkit-overflow-scrolling: touch;
}

.welcome-message {
    text-align: center;
    padding: 20px;
    color: #666;
    font-size: 14px;
}

.message {
    margin-bottom: 12px;
    display: flex;
    flex-direction: column;
}

.message.visitor {
    align-items: flex-end;
}

.message.admin {
    align-items: flex-start;
}

.message-bubble {
    max-width: 85%;
    padding: 12px 16px;
    border-radius: 18px;
    font-size: 15px;
    line-height: 1.5;
    word-wrap: break-word;
}

.message.visitor .message-bubble {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-bottom-right-radius: 4px;
}

.message.admin .message-bubble {
    background: white;
    color: #333;
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.message-time {
    font-size: 11px;
    color: #999;
    margin-top: 4px;
    padding: 0 4px;
}

.chat-input-area {
    padding: 12px 16px;
    background: white;
    border-top: 1px solid #eee;
    display: flex;
    gap: 10px;
    align-items: flex-end;
    flex-shrink: 0;
    padding-bottom: max(12px, env(safe-area-inset-bottom));
}

#message-input {
    flex: 1;
    border: 1px solid #e0e0e0;
    border-radius: 22px;
    padding: 12px 18px;
    font-size: 16px;
    resize: none;
    outline: none;
    max-height: 100px;
    line-height: 1.4;
    font-family: inherit;
}

#message-input:focus {
    border-color: #667eea;
}

.send-btn {
    padding: 12px 24px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 22px;
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
    transition: opacity 0.2s ease, transform 0.2s ease;
    flex-shrink: 0;
}

.send-btn:hover {
    opacity: 0.9;
}

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

.send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.offline-notice {
    padding: 12px 16px;
    background: #fff3cd;
    color: #856404;
    font-size: 13px;
    text-align: center;
    flex-shrink: 0;
}

.offline-notice.hidden {
    display: none;
}

.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 12px 16px;
    background: white;
    border-radius: 18px;
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #ccc;
    animation: typing 1.4s infinite ease-in-out;
}

.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(-4px);
    }
}

@media (min-width: 480px) {
    .chat-button {
        width: 60px;
        height: 60px;
        bottom: 24px;
        right: 24px;
    }

    .chat-icon-svg {
        width: 30px;
        height: 30px;
    }

    .chat-overlay {
        display: block;
    }

    .chat-window {
        position: fixed;
        bottom: 96px;
        right: 24px;
        left: auto;
        width: 360px;
        height: 520px;
        max-height: calc(100vh - 120px);
        border-radius: 16px;
        box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
        transform: translateY(20px) scale(0.95);
        opacity: 0;
    }

    .chat-window.show {
        transform: translateY(0) scale(1);
        opacity: 1;
    }

    .chat-header {
        border-radius: 16px 16px 0 0;
        padding-top: 16px;
    }

    .chat-messages {
        border-radius: 0;
    }

    .chat-input-area {
        border-radius: 0 0 16px 16px;
        padding-bottom: 12px;
    }
}

@media (min-width: 768px) {
    .chat-button {
        bottom: 30px;
        right: 30px;
    }

    .chat-window {
        right: 30px;
        bottom: 100px;
    }
}
