/**
 * Pharmabot Chatbot Widget - Global Styles
 * Stili per il chatbot globale persistente in tutte le pagine
 * Versione: 1.0.0
 */

/* =============================================
   CHATBOT CONTAINER - Posizione fissa bottom-right
   ============================================= */
#pharmabot-chatbot-container {
    position: fixed !important;
    bottom: 20px !important;
    right: 20px !important;
    z-index: 9999 !important;
    font-family: 'Inter', sans-serif;
}

/* =============================================
   CHATBOT BUBBLE (Icona principale)
   ============================================= */
#pharmabot-chatbot-bubble {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(15, 118, 110, 0.4);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    overflow: hidden;
    border: 3px solid #fff;
    background: linear-gradient(135deg, var(--teal-700, #0f766e) 0%, var(--teal-800, #115e59) 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

#pharmabot-chatbot-bubble:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 25px rgba(15, 118, 110, 0.5);
}

#pharmabot-chatbot-bubble img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
}

/* =============================================
   TOOLTIP POPUP (Messaggio al passaggio mouse)
   ============================================= */
#pharmabot-tooltip {
    position: absolute;
    bottom: 75px;
    right: 0;
    background: linear-gradient(135deg, #0f766e 0%, #115e59 100%);
    color: white;
    padding: 12px 16px;
    border-radius: 12px;
    font-size: 14px;
    font-weight: 600;
    white-space: nowrap;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    opacity: 0;
    visibility: hidden;
    transform: translateY(10px);
    transition: opacity 0.3s ease, transform 0.3s ease, visibility 0.3s ease;
    max-width: 280px;
    white-space: normal;
    text-align: center;
    line-height: 1.4;
}

#pharmabot-tooltip::after {
    content: '';
    position: absolute;
    bottom: -8px;
    right: 24px;
    width: 0;
    height: 0;
    border-left: 8px solid transparent;
    border-right: 8px solid transparent;
    border-top: 8px solid #115e59;
}

#pharmabot-chatbot-bubble:hover + #pharmabot-tooltip,
#pharmabot-tooltip.show {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

/* Pulse animation per attirare attenzione iniziale */
@keyframes pharmabot-pulse {
    0% {
        box-shadow: 0 0 0 0 rgba(15, 118, 110, 0.7);
    }
    70% {
        box-shadow: 0 0 0 15px rgba(15, 118, 110, 0);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(15, 118, 110, 0);
    }
}

#pharmabot-chatbot-bubble.pulse {
    animation: pharmabot-pulse 2s infinite;
}

/* =============================================
   CHATBOT WINDOW
   ============================================= */
#pharmabot-chatbot-window {
    position: absolute;
    bottom: 80px;
    right: 0;
    width: 380px;
    max-width: calc(100vw - 40px);
    height: 520px;
    max-height: calc(100vh - 120px);
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    pointer-events: none;
    transition: opacity 0.3s ease, transform 0.3s ease;
}

#pharmabot-chatbot-window.open {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

/* =============================================
   CHATBOT HEADER
   ============================================= */
.pharmabot-header {
    background: linear-gradient(135deg, var(--teal-700, #0f766e) 0%, var(--teal-800, #115e59) 100%);
    position: relative;
    overflow: hidden;
    flex-shrink: 0;
}

.pharmabot-header-image {
    width: 100%;
    height: 60px;
    object-fit: cover;
    opacity: 0.95;
}

.pharmabot-header-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    background: linear-gradient(135deg, rgba(15, 118, 110, 0.85) 0%, rgba(17, 94, 89, 0.85) 100%);
}

.pharmabot-header-title {
    display: flex;
    align-items: center;
    gap: 10px;
}

.pharmabot-header-title h3 {
    font-weight: 700;
    font-size: 1.1rem;
    font-family: 'Montserrat', sans-serif;
    color: #fff;
    margin: 0;
}

#pharmabot-close-btn {
    background: none;
    border: none;
    color: #fff;
    font-size: 28px;
    font-weight: 700;
    cursor: pointer;
    transition: color 0.2s ease;
    line-height: 1;
    padding: 0 4px;
}

#pharmabot-close-btn:hover {
    color: #ccfbf1;
}

/* =============================================
   STATUS INDICATOR
   ============================================= */
.pharmabot-status-indicator {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #10b981;
    animation: pharmabot-status-pulse 2s ease-in-out infinite;
}

.pharmabot-status-indicator.offline {
    background: #ef4444;
    animation: pharmabot-status-pulse-offline 2s ease-in-out infinite;
}

.pharmabot-status-indicator.connecting {
    background: #f59e0b;
    animation: pharmabot-status-pulse-connecting 1s ease-in-out infinite;
}

@keyframes pharmabot-status-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7); }
    50% { box-shadow: 0 0 0 6px rgba(16, 185, 129, 0); }
}

@keyframes pharmabot-status-pulse-offline {
    0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.7); }
    50% { box-shadow: 0 0 0 6px rgba(239, 68, 68, 0); }
}

@keyframes pharmabot-status-pulse-connecting {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* =============================================
   PRIVACY CONSENT CONTAINER
   ============================================= */
#pharmabot-privacy-consent {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    flex: 1;
    padding: 24px;
    text-align: center;
    background: #fff;
}

#pharmabot-privacy-consent p {
    font-size: 14px;
    color: #475569;
    margin-bottom: 20px;
    line-height: 1.6;
}

#pharmabot-privacy-consent a {
    color: var(--teal-700, #0f766e);
    text-decoration: underline;
}

#pharmabot-accept-privacy {
    background: var(--teal-700, #0f766e);
    color: #fff;
    font-weight: 700;
    padding: 12px 28px;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    transition: background 0.2s ease;
    font-family: 'Montserrat', sans-serif;
    font-size: 15px;
}

#pharmabot-accept-privacy:hover {
    background: var(--teal-800, #115e59);
}

/* =============================================
   CHAT MESSAGES AREA
   ============================================= */
#pharmabot-chat-ui {
    display: none;
    flex-direction: column;
    flex: 1;
    overflow: hidden;
}

#pharmabot-chat-ui.active {
    display: flex;
}

#pharmabot-messages {
    flex: 1;
    padding: 16px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background-image: url('/assets/images/sfondo.JPG');
    background-size: cover;
    background-position: center;
    background-attachment: local;
    position: relative;
}

#pharmabot-messages::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.92);
    z-index: 0;
    pointer-events: none;
}

#pharmabot-messages > * {
    position: relative;
    z-index: 1;
}

/* Scrollbar Styling */
#pharmabot-messages::-webkit-scrollbar {
    width: 8px;
}

#pharmabot-messages::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

#pharmabot-messages::-webkit-scrollbar-thumb {
    background: var(--teal-700, #0f766e);
    border-radius: 4px;
}

#pharmabot-messages::-webkit-scrollbar-thumb:hover {
    background: var(--teal-800, #115e59);
}

/* =============================================
   CHAT MESSAGES
   ============================================= */
.pharmabot-message {
    max-width: 85%;
    padding: 12px 16px;
    border-radius: 12px;
    font-size: 14px;
    line-height: 1.5;
    word-wrap: break-word;
}

.pharmabot-message.bot {
    background: #f0fdfa;
    border-left: 3px solid var(--teal-700, #0f766e);
    align-self: flex-start;
}

.pharmabot-message.user {
    background: #ccfbf1;
    border-right: 3px solid var(--teal-700, #0f766e);
    align-self: flex-end;
}

/* AI Provider Badge */
.pharmabot-ai-badge {
    border-top: 1px solid #e2e8f0;
    padding-top: 8px;
    margin-top: 10px;
    font-size: 11px;
    color: #64748b;
    display: flex;
    align-items: center;
    gap: 4px;
}

/* =============================================
   CHAT INPUT AREA
   ============================================= */
#pharmabot-input-container {
    padding: 12px 16px;
    border-top: 1px solid #e2e8f0;
    background: #fff;
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

#pharmabot-upload-btn {
    background: #e2e8f0;
    color: #64748b;
    border: none;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.2s ease;
    flex-shrink: 0;
}

#pharmabot-upload-btn:hover {
    background: #cbd5e1;
}

#pharmabot-input {
    flex: 1;
    padding: 10px 14px;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

#pharmabot-input:focus {
    border-color: var(--teal-700, #0f766e);
    box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.1);
}

#pharmabot-send-btn {
    background: var(--teal-700, #0f766e);
    color: #fff;
    border: none;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.2s ease;
    flex-shrink: 0;
}

#pharmabot-send-btn:hover {
    background: var(--teal-800, #115e59);
}

#pharmabot-send-btn:disabled,
#pharmabot-input:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

#pharmabot-file-input {
    display: none;
}

/* =============================================
   LOADER ANIMATION
   ============================================= */
.pharmabot-loader {
    border: 3px solid #f3f3f3;
    border-top: 3px solid var(--teal-700, #0f766e);
    border-radius: 50%;
    width: 24px;
    height: 24px;
    animation: pharmabot-spin 1s linear infinite;
}

@keyframes pharmabot-spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* =============================================
   INTERACTIVE UI - Pharmacy Buttons
   ============================================= */
.pharmabot-pharmacy-card {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #fff;
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    cursor: pointer;
    margin-top: 10px;
}

.pharmabot-pharmacy-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
}

.pharmabot-pharmacy-card h4 {
    margin: 0 0 4px 0;
    font-size: 15px;
    font-weight: 600;
}

.pharmabot-pharmacy-card p {
    margin: 0;
    font-size: 13px;
    opacity: 0.9;
}

.pharmabot-select-btn {
    padding: 8px 18px;
    background: #fff;
    color: #667eea;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    font-size: 13px;
    cursor: pointer;
    transition: background 0.2s ease;
    white-space: nowrap;
}

.pharmabot-select-btn:hover {
    background: #f0f0f0;
}

/* Confirmation Buttons */
.pharmabot-confirm-buttons {
    display: flex;
    gap: 10px;
    margin-top: 16px;
    flex-wrap: wrap;
}

.pharmabot-btn-confirm {
    flex: 1;
    min-width: 140px;
    padding: 14px 20px;
    background: linear-gradient(135deg, #11998e 0%, #38ef7d 100%);
    color: #fff;
    border: none;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.2s ease;
    box-shadow: 0 4px 12px rgba(17, 153, 142, 0.3);
}

.pharmabot-btn-confirm:hover {
    transform: scale(1.02);
}

.pharmabot-btn-modify {
    flex: 1;
    min-width: 140px;
    padding: 14px 20px;
    background: #f5f5f5;
    color: #333;
    border: 2px solid #ddd;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s ease;
}

.pharmabot-btn-modify:hover {
    background: #e8e8e8;
}

/* =============================================
   DISABLED BUTTONS (after user response)
   ============================================= */
.pharmabot-btn-disabled {
    opacity: 0.5 !important;
    cursor: not-allowed !important;
    pointer-events: none !important;
    filter: grayscale(30%);
}

.pharmabot-btn-disabled:hover {
    transform: none !important;
    background: inherit !important;
}

.pharmabot-card-disabled {
    opacity: 0.5 !important;
    cursor: not-allowed !important;
    pointer-events: none !important;
    filter: grayscale(30%);
}

.pharmabot-card-disabled:hover {
    transform: none !important;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15) !important;
}

.pharmabot-container-disabled {
    opacity: 0.5 !important;
    pointer-events: none !important;
    filter: grayscale(30%);
}

/* =============================================
   ERROR MODAL
   ============================================= */
.pharmabot-error-modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10001;
}

.pharmabot-error-modal-content {
    background: #fff;
    border-radius: 12px;
    padding: 24px;
    max-width: 400px;
    margin: 16px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
}

.pharmabot-error-modal h3 {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0 0 16px 0;
    font-size: 18px;
    color: #1f2937;
}

.pharmabot-error-modal p {
    color: #4b5563;
    margin: 0 0 20px 0;
    white-space: pre-wrap;
    line-height: 1.5;
}

.pharmabot-error-modal-buttons {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
}

.pharmabot-modal-dismiss {
    padding: 8px 16px;
    color: #6b7280;
    background: none;
    border: none;
    cursor: pointer;
    border-radius: 6px;
}

.pharmabot-modal-dismiss:hover {
    color: #374151;
}

.pharmabot-modal-action {
    padding: 8px 16px;
    background: #2563eb;
    color: #fff;
    border: none;
    border-radius: 6px;
    cursor: pointer;
}

.pharmabot-modal-action:hover {
    background: #1d4ed8;
}

/* =============================================
   RESPONSIVE DESIGN
   ============================================= */
@media (max-width: 480px) {
    #pharmabot-chatbot-container {
        bottom: 15px !important;
        right: 15px !important;
    }

    #pharmabot-chatbot-bubble {
        width: 56px;
        height: 56px;
    }

    #pharmabot-chatbot-window {
        width: calc(100vw - 30px);
        height: calc(100vh - 100px);
        bottom: 70px;
        right: 0;
        border-radius: 12px;
    }

    #pharmabot-tooltip {
        max-width: 220px;
        font-size: 13px;
        right: 0;
    }

    .pharmabot-message {
        max-width: 90%;
    }
}

@media (max-width: 360px) {
    #pharmabot-chatbot-window {
        width: 100vw;
        height: calc(100vh - 80px);
        right: -15px;
        bottom: 65px;
        border-radius: 12px 12px 0 0;
    }
}

/* =============================================
   ACCESSIBILITY
   ============================================= */
#pharmabot-chatbot-bubble:focus,
#pharmabot-close-btn:focus,
#pharmabot-accept-privacy:focus,
#pharmabot-send-btn:focus,
#pharmabot-upload-btn:focus {
    outline: 2px solid var(--teal-500, #14b8a6);
    outline-offset: 2px;
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    #pharmabot-chatbot-bubble,
    #pharmabot-chatbot-window,
    #pharmabot-tooltip,
    .pharmabot-status-indicator {
        transition: none;
        animation: none;
    }
}
