/* Widget Container */
#manuopus-chat-widget {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 10000;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

/* Floating Button (FAB) */
#chat-fab {
    width: 60px;
    height: 60px;
    background: #0d6efd;
    color: white;
    border-radius: 50%;
    box-shadow: 0 4px 15px rgba(13, 110, 253, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    font-size: 28px;
    position: relative;
}

#chat-fab:hover {
    transform: scale(1.1);
}

#chat-fab .badge-notify {
    position: absolute;
    top: 0;
    right: 0;
    width: 14px;
    height: 14px;
    background: #dc3545;
    border-radius: 50%;
    border: 2px solid white;
    display: none; /* Show via JS */
}

/* Chat Window */
#chat-window {
    position: absolute;
    bottom: 80px;
    right: 0;
    width: 350px;
    height: 500px;
    background: white;
    border-radius: 12px;
    box-shadow: 0 5px 30px rgba(0,0,0,0.15);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform-origin: bottom right;
    transform: scale(0);
    opacity: 0;
    transition: all 0.3s ease;
    border: 1px solid #e9ecef;
}

#chat-window.open {
    transform: scale(1);
    opacity: 1;
}

/* Header */
.chat-header {
    background: #0d6efd;
    color: white;
    padding: 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chat-header h5 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
}

.chat-close {
    cursor: pointer;
    opacity: 0.8;
    transition: 0.2s;
}
.chat-close:hover { opacity: 1; }

/* Messages Area */
.chat-body {
    flex: 1;
    padding: 15px;
    overflow-y: auto;
    background: #f8f9fa;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.msg {
    max-width: 80%;
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 14px;
    line-height: 1.4;
    position: relative;
    word-wrap: break-word;
}

.msg-admin {
    background: white;
    color: #212529;
    align-self: flex-start;
    border-bottom-left-radius: 2px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

.msg-user {
    background: #0d6efd;
    color: white;
    align-self: flex-end;
    border-bottom-right-radius: 2px;
    box-shadow: 0 1px 2px rgba(13, 110, 253, 0.2);
}

.msg-time {
    font-size: 10px;
    margin-top: 4px;
    opacity: 0.7;
    text-align: right;
    display: block;
}

/* Input Area */
.chat-footer {
    padding: 15px;
    background: white;
    border-top: 1px solid #e9ecef;
}

.chat-input-group {
    display: flex;
    gap: 10px;
}

#chat-input {
    flex: 1;
    border: 1px solid #ced4da;
    border-radius: 20px;
    padding: 8px 15px;
    font-size: 14px;
    outline: none;
}

#chat-input:focus {
    border-color: #0d6efd;
}

#chat-send {
    background: #0d6efd;
    color: white;
    border: none;
    border-radius: 50%;
    width: 38px;
    height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: 0.2s;
}

#chat-send:disabled {
    background: #adb5bd;
    cursor: not-allowed;
}

#chat-status {
    font-size: 12px;
    color: #6c757d;
    text-align: center;
    margin-top: 8px;
    font-style: italic;
}

/* Mobile Responsive */
@media (max-width: 480px) {
    #manuopus-chat-widget {
        bottom: 20px;
        bottom: calc(20px + env(safe-area-inset-bottom)); /* Safe area per iPhone X+ */
        right: 15px;
        z-index: 10002; /* Altissimo */
    }

    #chat-window {
        position: fixed; /* Si sgancia dal parent relative */
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100vw;
        height: 100vh; /* Fallback */
        height: 100dvh; /* Dynamic viewport height per browser mobile moderni */
        border-radius: 0;
        z-index: 10001; /* Sopra al FAB */
        transform-origin: center center; /* Animazione dal centro o fade */
    }
}
