/**
 * Econobot RAG WordPress - Frontend Chat CSS
 * Stili accessibili e responsive per la chat
 */

/* Container principale */
.econobot-chat-container {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
    font-size: 14px;
    line-height: 1.6;
}

/* Chat Embed */
.econobot-chat-embed {
    display: flex;
    flex-direction: column;
    border: 1px solid #ddd;
    border-radius: 8px;
    overflow: hidden;
    background: #fff;
}

/* Area messaggi */
.econobot-chat-messages {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    background: #f8f9fa;
    scroll-behavior: smooth;
}

/* Riduci animazioni se preferito */
@media (prefers-reduced-motion: reduce) {
    .econobot-chat-messages {
        scroll-behavior: auto;
    }
}

/* Messaggio di benvenuto */
.econobot-welcome-message {
    text-align: center;
    color: #666;
    padding: 40px 20px;
}

.econobot-welcome-message p {
    margin: 0;
    font-size: 16px;
}

/* Singolo messaggio */
.econobot-message {
    margin-bottom: 16px;
    max-width: 80%;
    animation: slideIn 0.3s ease-out;
}

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

@media (prefers-reduced-motion: reduce) {
    .econobot-message {
        animation: none;
    }
}

.econobot-message-user {
    margin-left: auto;
}

.econobot-message-bot {
    margin-right: auto;
}

.econobot-message-error {
    background: #fee;
    border-left: 4px solid #d63638;
    padding: 12px;
    border-radius: 4px;
    color: #600;
}

/* Header messaggio */
.econobot-message-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
    font-size: 12px;
}

.econobot-message-author {
    font-weight: 600;
    color: #333;
}

.econobot-message-user .econobot-message-author {
    color: #fff;
}

.econobot-message-bot .econobot-message-author {
    color: #00a32a;
}

.econobot-message-time {
    color: #666;
    font-size: 11px;
}

.econobot-message-user .econobot-message-time {
    color: rgba(255,255,255,0.8);
}

/* Body messaggio */
.econobot-message-body {
    background: #fff;
    padding: 12px 16px;
    border-radius: 12px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
    word-wrap: break-word;
}

.econobot-message-user .econobot-message-body {
    background: #0073aa;
    color: #fff !important;
    border-bottom-right-radius: 4px;
}

.econobot-message-user .econobot-message-body * {
    color: #fff !important;
}

.econobot-message-bot .econobot-message-body {
    background: #fff;
    border: 1px solid #ddd;
    border-bottom-left-radius: 4px;
    color: #333;
}

.econobot-message-body a {
    color: #0073aa;
    text-decoration: underline;
}

.econobot-message-user .econobot-message-body a {
    color: #b3e0ff !important;
}

/* Input wrapper */
.econobot-chat-input-wrapper {
    display: flex;
    gap: 8px;
    padding: 16px;
    background: #fff;
    border-top: 1px solid #ddd;
}

.screen-reader-text {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0,0,0,0);
    white-space: nowrap;
    border: 0;
}

/* Input textarea */
.econobot-chat-input {
    flex: 1;
    padding: 10px 12px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-family: inherit;
    font-size: 14px;
    resize: none;
    transition: border-color 0.2s;
}

.econobot-chat-input:focus {
    outline: none;
    border-color: #0073aa;
    box-shadow: 0 0 0 2px rgba(0, 115, 170, 0.1);
}

.econobot-chat-input:disabled {
    background: #f5f5f5;
    cursor: not-allowed;
}

/* Pulsante invio */
.econobot-chat-send {
    padding: 10px 20px;
    background: #0073aa;
    color: #fff;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 600;
    transition: background 0.2s;
    display: flex;
    align-items: center;
    gap: 6px;
}

.econobot-chat-send:hover:not(:disabled) {
    background: #005a87;
}

.econobot-chat-send:focus {
    outline: 2px solid #0073aa;
    outline-offset: 2px;
}

.econobot-chat-send:disabled {
    background: #ccc;
    cursor: not-allowed;
}

.econobot-send-icon {
    display: inline-block;
    font-size: 12px;
}

/* Status bar */
.econobot-chat-status {
    padding: 8px 16px;
    background: #f0f6fc;
    border-top: 1px solid #c3e6ff;
    font-size: 13px;
    color: #0073aa;
    display: none;
}

.econobot-chat-status:not(:empty) {
    display: block;
}

.econobot-status-loading::before {
    content: "⏳ ";
}

.econobot-status-error {
    background: #fcf0f1;
    border-color: #f8d7da;
    color: #d63638;
}

.econobot-status-error::before {
    content: "⚠️ ";
}

/* Chat Floating */
.econobot-chat-floating {
    position: fixed !important;
    bottom: 100px;
    right: 20px;
    z-index: 2147483647 !important; /* Max z-index possibile */
    pointer-events: auto !important;
}

.econobot-chat-toggle {
    width: 70px;
    height: 70px;
    border-radius: 10px;
    background: transparent;
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(0,0,0,0.3);
    transition: all 0.3s;
    padding: 0;
    overflow: hidden;
    position: relative;
    z-index: 2147483647 !important; /* STESSO z-index massimo del parent */
    pointer-events: auto !important;
}

.econobot-chat-toggle img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.econobot-toggle-icon {
    display: none;
}

.econobot-chat-toggle:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 24px rgba(0,0,0,0.4);
}

.econobot-chat-toggle:focus {
    outline: 3px solid #0073aa;
    outline-offset: 4px;
}

/* Tooltip */
.econobot-tooltip {
    position: absolute;
    bottom: 90px; /* Sopra il chatbot (70px altezza + 20px margine) */
    right: 0;
    left: auto;
    background: #fff;
    color: #333;
    padding: 12px 20px;
    border-radius: 12px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.25);
    font-size: 14px;
    font-weight: 500;
    line-height: 1.4;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
    max-width: 280px;
    min-width: 250px;
    white-space: normal;
    z-index: 2147483645; /* Sotto finestra chat */
    transform: translateY(10px);
}

.econobot-tooltip::after {
    content: '';
    position: absolute;
    bottom: -8px; /* Freccia verso il basso */
    right: 25px; /* Allineata a destra vicino al chatbot */
    width: 0;
    height: 0;
    border-style: solid;
    border-width: 8px 8px 0 8px;
    border-color: #fff transparent transparent transparent;
}

.econobot-chat-toggle:hover + .econobot-tooltip,
.econobot-tooltip.show {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.econobot-tooltip.hide {
    opacity: 0;
    visibility: hidden;
    transform: translateY(10px);
}

.econobot-chat-window {
    position: fixed !important; /* FIXED come header del sito! */
    bottom: 190px !important; /* 100px (container bottom) + 70px (toggle height) + 20px (gap) */
    right: 20px !important; /* Allineato con container */
    width: 380px;
    max-width: calc(100vw - 40px);
    height: 500px;
    display: flex;
    flex-direction: column;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 8px 30px rgba(0,0,0,0.3);
    overflow: hidden;
    z-index: 2147483647 !important; /* Max z-index - SAME stacking context as header now */
    pointer-events: auto !important;
}

.econobot-chat-window[hidden] {
    display: none;
}

.econobot-chat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px;
    background: #0073aa;
    color: #fff;
    position: relative;
    z-index: 2147483646 !important; /* Alto come la finestra */
}

.econobot-chat-header h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    color: #fff;
}

.econobot-chat-close {
    background: transparent;
    color: #fff;
    border: none;
    font-size: 28px;
    line-height: 1;
    cursor: pointer;
    padding: 0;
    width: 32px;
    height: 32px;
    border-radius: 4px;
    transition: background 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

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

.econobot-chat-close:focus {
    outline: 2px solid #fff;
    outline-offset: 2px;
}

.econobot-chat-floating .econobot-chat-messages {
    flex: 1;
    height: auto;
}

/* Responsive */
@media (max-width: 600px) {
    .econobot-message {
        max-width: 90%;
    }
    
    .econobot-chat-window {
        width: calc(100vw - 40px);
        height: calc(100vh - 120px);
    }
    
    .econobot-send-text {
        display: none;
    }
}

/* High contrast mode */
@media (prefers-contrast: high) {
    .econobot-chat-input,
    .econobot-message-body {
        border-width: 2px;
    }
    
    .econobot-chat-send:focus,
    .econobot-chat-input:focus {
        outline-width: 3px;
    }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    .econobot-chat-embed {
        background: #1a1a1a;
        border-color: #444;
    }
    
    .econobot-chat-messages {
        background: #222;
    }
    
    .econobot-message-body {
        background: #333;
        color: #fff;
        border-color: #444;
    }
    
    .econobot-message-user .econobot-message-body {
        background: #0073aa;
    }
    
    .econobot-chat-input {
        background: #333;
        color: #fff;
        border-color: #444;
    }
    
    .econobot-chat-input-wrapper {
        background: #1a1a1a;
        border-color: #444;
    }
}

/* Responsive tooltip per mobile */
@media screen and (max-width: 480px) {
    .econobot-tooltip {
        max-width: calc(100vw - 100px);
        min-width: 200px;
        right: 5px;
        font-size: 13px;
        padding: 10px 16px;
    }
    
    .econobot-tooltip::after {
        right: 20px;
    }
}

/* ============================================
   UPLOAD FILE E PULSANTI RIASSUNTO
   ============================================ */

/* Bottone Upload */
.econobot-chat-upload {
    background: transparent;
    border: none;
    padding: 8px;
    cursor: pointer;
    font-size: 20px;
    line-height: 1;
    transition: transform 0.2s ease, opacity 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.econobot-chat-upload:hover {
    transform: scale(1.1);
    opacity: 0.8;
}

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

.econobot-chat-upload:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.econobot-upload-icon {
    display: block;
}

/* Input file nascosto */
.econobot-chat-file-input {
    display: none !important;
}

/* Pulsanti riassunto inline */
.econobot-summary-buttons {
    display: flex;
    gap: 10px;
    margin-top: 12px;
    flex-wrap: wrap;
}

.econobot-summary-btn {
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.econobot-summary-yes {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.econobot-summary-yes:hover {
    background: linear-gradient(135deg, #5568d3 0%, #653a91 100%);
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(102, 126, 234, 0.3);
}

.econobot-summary-no {
    background: #f0f0f0;
    color: #333;
}

.econobot-summary-no:hover {
    background: #e0e0e0;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.15);
}

.econobot-summary-btn:active {
    transform: translateY(0);
}

/* Responsive */
@media (max-width: 480px) {
    .econobot-summary-buttons {
        flex-direction: column;
    }
    
    .econobot-summary-btn {
        width: 100%;
    }
}
