/**
 * Boss Analytics Pro - Chat Widget CSS
 * by Devsviluppo
 */

/* Reset box-sizing for widget */
.ba-chat-widget *,
.ba-chat-widget *::before,
.ba-chat-widget *::after {
    box-sizing: border-box;
}

/* Widget Container */
.ba-chat-widget {
    position: fixed;
    bottom: 20px;
    z-index: 999999;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

.ba-chat-widget.position-right {
    right: 20px;
}

.ba-chat-widget.position-left {
    left: 20px;
}

/* Toggle Button - Logo Rotondo */
.ba-chat-toggle,
.ba-chat-widget .ba-chat-toggle,
.ba-chat-widget button.ba-chat-toggle {
    width: 60px !important;
    height: 60px !important;
    min-width: 60px !important;
    min-height: 60px !important;
    max-width: 60px !important;
    max-height: 60px !important;
    border-radius: 50% !important;
    -webkit-border-radius: 50% !important;
    -moz-border-radius: 50% !important;
    -ms-border-radius: 50% !important;
    -o-border-radius: 50% !important;
    border: none !important;
    cursor: pointer;
    display: flex !important;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 20px rgba(0,0,0,0.25);
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden !important;
    -webkit-clip-path: circle(50%) !important;
    clip-path: circle(50%) !important;
    aspect-ratio: 1 / 1 !important;
}

.ba-chat-toggle:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 25px rgba(0,0,0,0.3);
}

.ba-chat-toggle svg {
    width: 28px;
    height: 28px;
    fill: white;
    transition: transform 0.3s;
}

.ba-chat-toggle.open svg {
    transform: rotate(90deg);
}

/* Se vuoi usare un'immagine come logo */
.ba-chat-toggle img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
}

.ba-chat-toggle .ba-notification-dot {
    position: absolute;
    top: -2px;
    right: -2px;
    width: 18px;
    height: 18px;
    background: #ef4444;
    border-radius: 50%;
    border: 2px solid white;
    display: none;
    animation: ba-pulse 2s infinite;
}

.ba-chat-toggle .ba-notification-dot.show {
    display: block;
}

@keyframes ba-pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.2); }
}

/* Chat Window */
.ba-chat-window {
    position: absolute;
    bottom: 75px;
    width: 380px;
    max-width: calc(100vw - 40px);
    height: 520px;
    max-height: calc(100vh - 120px);
    background: white;
    border-radius: 16px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.2);
    display: none;
    flex-direction: column;
    overflow: hidden;
    animation: ba-slideUp 0.3s ease;
}

.ba-chat-widget.position-right .ba-chat-window {
    right: 0;
}

.ba-chat-widget.position-left .ba-chat-window {
    left: 0;
}

.ba-chat-window.open {
    display: flex;
}

@keyframes ba-slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Chat Header */
.ba-widget-header {
    padding: 16px;
    color: white;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

.ba-widget-avatar {
    width: 45px;
    height: 45px;
    min-width: 45px;
    border-radius: 50%;
    background: rgba(255,255,255,0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.3rem;
    overflow: hidden;
}

.ba-widget-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
}

.ba-widget-info {
    flex: 1;
    min-width: 0;
}

.ba-widget-info h4 {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ba-widget-info p {
    margin: 2px 0 0;
    font-size: 0.8rem;
    opacity: 0.9;
}

.ba-widget-close {
    margin-left: auto;
    background: rgba(255,255,255,0.2);
    border: none;
    width: 32px;
    height: 32px;
    min-width: 32px;
    border-radius: 50%;
    cursor: pointer;
    color: white;
    font-size: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
    line-height: 1;
}

.ba-widget-close:hover {
    background: rgba(255,255,255,0.3);
}

/* Welcome Screen */
.ba-widget-welcome {
    flex: 1;
    padding: 25px 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    overflow-y: auto;
}

.ba-widget-welcome-icon {
    font-size: 2.5rem;
    margin-bottom: 12px;
}

.ba-widget-welcome h3 {
    margin: 0 0 8px;
    font-size: 1.2rem;
    color: #333;
}

.ba-widget-welcome p {
    margin: 0 0 20px;
    color: #666;
    font-size: 0.9rem;
    line-height: 1.5;
}

.ba-widget-start-btn {
    padding: 12px 30px;
    border: none;
    border-radius: 30px;
    font-size: 0.95rem;
    font-weight: 600;
    color: white;
    cursor: pointer;
    transition: all 0.3s;
    box-shadow: 0 4px 15px rgba(0,0,0,0.2);
}

.ba-widget-start-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0,0,0,0.25);
}

/* Pre-chat Form */
.ba-widget-prechat {
    flex: 1;
    padding: 20px;
    display: none;
    overflow-y: auto;
}

.ba-widget-prechat.active {
    display: block;
}

/* Ticket Form (Offline Mode) */
.ba-widget-ticket {
    flex: 1;
    padding: 20px;
    display: none;
    overflow-y: auto;
}

.ba-widget-ticket.active {
    display: block;
}

.ba-ticket-header {
    text-align: center;
    margin-bottom: 20px;
}

.ba-ticket-icon {
    font-size: 2.5rem;
    margin-bottom: 10px;
}

.ba-ticket-header h4 {
    margin: 0 0 5px;
    color: #333;
    font-size: 1.1rem;
}

.ba-ticket-header p {
    margin: 0;
    color: #666;
    font-size: 0.85rem;
}

/* Ticket Success */
.ba-widget-ticket-success {
    flex: 1;
    padding: 30px 20px;
    display: none;
    text-align: center;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.ba-widget-ticket-success.active {
    display: flex;
}

.ba-ticket-success-icon {
    font-size: 3rem;
    margin-bottom: 15px;
    animation: ba-bounceIn 0.5s ease;
}

@keyframes ba-bounceIn {
    0% { transform: scale(0); }
    50% { transform: scale(1.2); }
    100% { transform: scale(1); }
}

.ba-widget-ticket-success h4 {
    margin: 0 0 10px;
    color: #333;
    font-size: 1.2rem;
}

.ba-widget-ticket-success p {
    margin: 0 0 15px;
    color: #666;
    font-size: 0.9rem;
    line-height: 1.5;
}

.ba-ticket-id {
    background: #f0f9ff;
    padding: 10px 20px;
    border-radius: 8px;
    color: #0369a1;
    font-size: 0.9rem;
    margin-bottom: 20px;
}

.ba-btn-secondary {
    background: #e5e7eb !important;
    color: #374151 !important;
}

.ba-btn-secondary:hover {
    background: #d1d5db !important;
}

/* Online Status in Header */
.ba-online-status {
    font-size: 0.75rem !important;
    opacity: 1 !important;
}

.ba-widget-prechat h4 {
    margin: 0 0 15px;
    color: #333;
    font-size: 1rem;
}

.ba-prechat-field {
    margin-bottom: 12px;
}

.ba-prechat-field label {
    display: block;
    font-size: 0.8rem;
    color: #555;
    margin-bottom: 4px;
}

.ba-prechat-field input,
.ba-prechat-field textarea {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid #ddd;
    border-radius: 10px;
    font-size: 0.9rem;
    transition: border-color 0.2s;
    box-sizing: border-box;
    font-family: inherit;
}

.ba-prechat-field input:focus,
.ba-prechat-field textarea:focus {
    outline: none;
    border-color: var(--ba-widget-color, #8b5cf6);
}

.ba-prechat-submit {
    width: 100%;
    padding: 12px;
    border: none;
    border-radius: 10px;
    font-size: 0.95rem;
    font-weight: 600;
    color: white;
    cursor: pointer;
    margin-top: 8px;
}

/* Chat Messages */
.ba-widget-messages {
    flex: 1;
    overflow-y: auto;
    padding: 15px;
    display: none;
    flex-direction: column;
    gap: 10px;
    background: #f9fafb;
}

.ba-widget-messages.active {
    display: flex;
}

.ba-widget-msg {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 0.9rem;
    line-height: 1.4;
    animation: ba-msgIn 0.3s ease;
    word-wrap: break-word;
}

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

.ba-widget-msg.visitor {
    align-self: flex-end;
    color: white;
    border-bottom-right-radius: 4px;
}

.ba-widget-msg.operator {
    align-self: flex-start;
    background: white;
    border: 1px solid #e5e5e5;
    color: #333;
    border-bottom-left-radius: 4px;
}

.ba-widget-msg-time {
    font-size: 0.65rem;
    opacity: 0.7;
    margin-top: 4px;
}

.ba-widget-msg-image {
    max-width: 180px;
    border-radius: 8px;
    cursor: pointer;
    display: block;
}

.ba-widget-msg-file {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 10px;
    background: rgba(0,0,0,0.05);
    border-radius: 8px;
    text-decoration: none;
    color: inherit;
    font-size: 0.85rem;
}

.ba-widget-msg.visitor .ba-widget-msg-file {
    background: rgba(255,255,255,0.2);
}

.ba-widget-msg-file:hover {
    background: rgba(0,0,0,0.1);
}

/* Waiting Message */
.ba-waiting-message {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 20px;
    text-align: center;
    background: #f0f9ff;
    border-radius: 12px;
    margin: 10px 0;
    animation: ba-fadeIn 0.3s ease;
}

.ba-waiting-icon {
    font-size: 2rem;
    margin-bottom: 8px;
    animation: ba-bounce 1s infinite;
}

@keyframes ba-bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-5px); }
}

.ba-waiting-text {
    color: #0369a1;
    font-size: 0.85rem;
    line-height: 1.5;
}

/* Typing Indicator */
.ba-typing-indicator {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 10px 14px;
    background: white;
    border-radius: 16px;
    width: fit-content;
    border: 1px solid #e5e5e5;
    margin: 5px 0;
    animation: ba-fadeIn 0.2s ease;
}

@keyframes ba-fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.ba-typing-indicator span:not(.ba-typing-text) {
    width: 6px;
    height: 6px;
    background: #999;
    border-radius: 50%;
    animation: ba-typingDot 1.4s infinite;
}

.ba-typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.ba-typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

@keyframes ba-typingDot {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
    30% { transform: translateY(-4px); opacity: 1; }
}

.ba-typing-text {
    font-size: 0.75rem;
    color: #888;
    margin-left: 6px;
}

/* Chat Input */
.ba-widget-input {
    padding: 12px;
    border-top: 1px solid #eee;
    display: none;
    gap: 8px;
    align-items: flex-end;
    background: white;
    flex-shrink: 0;
}

.ba-widget-input.active {
    display: flex;
}

.ba-widget-attach {
    width: 38px;
    height: 38px;
    min-width: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #f0f0f0;
    border-radius: 50%;
    cursor: pointer;
    font-size: 16px;
    transition: background 0.2s;
}

.ba-widget-attach:hover {
    background: #e0e0e0;
}

.ba-widget-input textarea {
    flex: 1;
    border: 1px solid #ddd;
    border-radius: 20px;
    padding: 10px 14px;
    font-size: 0.9rem;
    resize: none;
    max-height: 80px;
    font-family: inherit;
    min-width: 0;
}

.ba-widget-input textarea:focus {
    outline: none;
    border-color: var(--ba-widget-color, #8b5cf6);
}

.ba-widget-send {
    width: 40px;
    height: 40px;
    min-width: 40px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s;
}

.ba-widget-send:hover {
    transform: scale(1.1);
}

.ba-widget-send svg {
    width: 18px;
    height: 18px;
}

/* Proactive Popup */
.ba-proactive-popup {
    position: absolute;
    bottom: 75px;
    background: white;
    border-radius: 16px;
    padding: 18px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.2);
    max-width: 280px;
    width: calc(100vw - 50px);
    display: none;
    animation: ba-slideUp 0.3s ease;
}

.ba-chat-widget.position-right .ba-proactive-popup {
    right: 0;
}

.ba-chat-widget.position-left .ba-proactive-popup {
    left: 0;
}

.ba-proactive-popup.show {
    display: block;
}

.ba-proactive-popup::after {
    content: '';
    position: absolute;
    bottom: -8px;
    right: 25px;
    width: 0;
    height: 0;
    border-left: 10px solid transparent;
    border-right: 10px solid transparent;
    border-top: 10px solid white;
}

.ba-proactive-close {
    position: absolute;
    top: 8px;
    right: 10px;
    background: none;
    border: none;
    font-size: 18px;
    color: #999;
    cursor: pointer;
    padding: 5px;
    line-height: 1;
}

.ba-proactive-operator {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
}

.ba-proactive-avatar {
    width: 35px;
    height: 35px;
    min-width: 35px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 0.9rem;
    overflow: hidden;
}

.ba-proactive-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.ba-proactive-name {
    font-weight: 600;
    color: #333;
    font-size: 0.9rem;
}

.ba-proactive-message {
    color: #555;
    line-height: 1.5;
    margin-bottom: 12px;
    font-size: 0.9rem;
}

.ba-proactive-btn {
    width: 100%;
    padding: 10px;
    border: none;
    border-radius: 10px;
    font-weight: 600;
    font-size: 0.9rem;
    color: white;
    cursor: pointer;
    transition: opacity 0.2s;
}

.ba-proactive-btn:hover {
    opacity: 0.9;
}

/* Powered by */
.ba-widget-powered {
    text-align: center;
    padding: 6px;
    font-size: 0.65rem;
    color: #999;
    background: #f9f9f9;
    border-top: 1px solid #eee;
    flex-shrink: 0;
}

.ba-widget-powered a {
    color: #8b5cf6;
    text-decoration: none;
}

/* Footer with end chat */
.ba-widget-footer {
    display: none;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    background: #f9f9f9;
    border-top: 1px solid #eee;
    flex-shrink: 0;
}

.ba-widget-end-chat {
    background: #ef4444;
    border: none;
    color: white;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    padding: 8px 14px;
    border-radius: 6px;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 4px;
}

.ba-widget-end-chat:hover {
    background: #dc2626;
    transform: scale(1.02);
}

.ba-widget-powered-inline {
    font-size: 0.65rem;
    color: #999;
}

.ba-widget-powered-inline a {
    color: #8b5cf6;
    text-decoration: none;
}

/* Pre-chat form row */
.ba-prechat-row {
    display: flex;
    gap: 10px;
}

.ba-prechat-row .ba-prechat-field {
    flex: 1;
}

/* ==================== RESPONSIVE ==================== */

/* Tablet */
@media (max-width: 768px) {
    .ba-chat-widget {
        bottom: 15px;
    }
    
    .ba-chat-widget.position-right {
        right: 15px;
    }
    
    .ba-chat-widget.position-left {
        left: 15px;
    }
    
    .ba-chat-toggle,
    .ba-chat-widget .ba-chat-toggle {
        width: 56px !important;
        height: 56px !important;
        min-width: 56px !important;
        min-height: 56px !important;
        max-width: 56px !important;
        max-height: 56px !important;
        border-radius: 50% !important;
        -webkit-clip-path: circle(50%) !important;
        clip-path: circle(50%) !important;
    }
    
    .ba-chat-toggle svg {
        width: 24px;
        height: 24px;
    }
}

/* Mobile */
@media (max-width: 480px) {
    .ba-chat-widget {
        bottom: 10px;
    }
    
    .ba-chat-widget.position-right {
        right: 10px;
    }
    
    .ba-chat-widget.position-left {
        left: 10px;
    }
    
    .ba-chat-toggle,
    .ba-chat-widget .ba-chat-toggle {
        width: 52px !important;
        height: 52px !important;
        min-width: 52px !important;
        min-height: 52px !important;
        max-width: 52px !important;
        max-height: 52px !important;
        border-radius: 50% !important;
        -webkit-clip-path: circle(50%) !important;
        clip-path: circle(50%) !important;
    }
    
    .ba-chat-toggle svg {
        width: 22px;
        height: 22px;
    }
    
    .ba-chat-window {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        max-width: 100%;
        height: 100%;
        max-height: 100%;
        border-radius: 0;
        animation: ba-fadeIn 0.2s ease;
    }
    
    .ba-chat-widget.position-right .ba-chat-window,
    .ba-chat-widget.position-left .ba-chat-window {
        right: 0;
        left: 0;
    }
    
    @keyframes ba-fadeIn {
        from { opacity: 0; }
        to { opacity: 1; }
    }
    
    .ba-widget-header {
        padding: 14px;
        border-radius: 0;
    }
    
    .ba-widget-avatar {
        width: 40px;
        height: 40px;
        min-width: 40px;
    }
    
    .ba-widget-info h4 {
        font-size: 0.95rem;
    }
    
    .ba-widget-close {
        width: 36px;
        height: 36px;
        min-width: 36px;
        font-size: 22px;
    }
    
    .ba-widget-welcome {
        padding: 20px 15px;
    }
    
    .ba-widget-welcome-icon {
        font-size: 2rem;
    }
    
    .ba-widget-welcome h3 {
        font-size: 1.1rem;
    }
    
    .ba-widget-welcome p {
        font-size: 0.85rem;
    }
    
    .ba-widget-start-btn {
        padding: 12px 25px;
        font-size: 0.9rem;
    }
    
    .ba-widget-prechat {
        padding: 15px;
    }
    
    .ba-widget-messages {
        padding: 12px;
    }
    
    .ba-widget-msg {
        max-width: 90%;
        padding: 10px 12px;
        font-size: 0.88rem;
    }
    
    .ba-widget-input {
        padding: 10px;
    }
    
    .ba-widget-input textarea {
        padding: 10px 12px;
        font-size: 16px; /* Previene zoom su iOS */
    }
    
    .ba-widget-send {
        width: 38px;
        height: 38px;
        min-width: 38px;
    }
    
    .ba-proactive-popup {
        position: fixed;
        bottom: auto;
        top: 50%;
        left: 50%;
        right: auto;
        transform: translate(-50%, -50%);
        width: calc(100vw - 40px);
        max-width: 320px;
        animation: ba-scaleIn 0.3s ease;
    }
    
    .ba-chat-widget.position-right .ba-proactive-popup,
    .ba-chat-widget.position-left .ba-proactive-popup {
        right: auto;
        left: 50%;
    }
    
    .ba-proactive-popup::after {
        display: none;
    }
    
    @keyframes ba-scaleIn {
        from {
            opacity: 0;
            transform: translate(-50%, -50%) scale(0.9);
        }
        to {
            opacity: 1;
            transform: translate(-50%, -50%) scale(1);
        }
    }
    
    /* Overlay per popup su mobile */
    .ba-proactive-popup.show::before {
        content: '';
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0,0,0,0.4);
        z-index: -1;
    }
}

/* Extra small phones */
@media (max-width: 360px) {
    .ba-chat-toggle,
    .ba-chat-widget .ba-chat-toggle {
        width: 48px !important;
        height: 48px !important;
        min-width: 48px !important;
        min-height: 48px !important;
        max-width: 48px !important;
        max-height: 48px !important;
        border-radius: 50% !important;
        -webkit-clip-path: circle(50%) !important;
        clip-path: circle(50%) !important;
    }
    
    .ba-chat-toggle svg {
        width: 20px;
        height: 20px;
    }
    
    .ba-widget-header {
        padding: 12px;
        gap: 10px;
    }
    
    .ba-widget-avatar {
        width: 36px;
        height: 36px;
        min-width: 36px;
        font-size: 1.1rem;
    }
    
    .ba-widget-info h4 {
        font-size: 0.9rem;
    }
    
    .ba-widget-info p {
        font-size: 0.75rem;
    }
}

/* Landscape mobile */
@media (max-height: 500px) and (orientation: landscape) {
    .ba-chat-window {
        height: 100vh;
        max-height: 100vh;
    }
    
    .ba-widget-welcome {
        padding: 15px;
    }
    
    .ba-widget-welcome-icon {
        font-size: 1.5rem;
        margin-bottom: 8px;
    }
    
    .ba-widget-welcome h3 {
        font-size: 1rem;
        margin-bottom: 5px;
    }
    
    .ba-widget-welcome p {
        margin-bottom: 10px;
    }
}

/* Safe area for notched phones */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
    @media (max-width: 480px) {
        .ba-chat-window {
            padding-bottom: env(safe-area-inset-bottom);
        }
        
        .ba-widget-input {
            padding-bottom: calc(10px + env(safe-area-inset-bottom));
        }
    }
}
