/**
 * EvAIChat Frontend Styles
 *
 * Stili per il widget chat nel frontend.
 *
 * @package EvAIChat
 * @since 1.0.0
 */

/* ==========================================================================
   Variabili CSS (sovrascrivibili da PHP)
   ========================================================================== */

:root {
    --evchat-primary: #d3770b;
    --evchat-primary-rgb: 211, 119, 11;
    --evchat-text: #333333;
    --evchat-bg: #ffffff;
    --evchat-width: 380px;
    --evchat-height: 500px;
    --evchat-border-radius: 12px;
    --evchat-shadow: 0 5px 40px rgba(0, 0, 0, 0.16);
    --evchat-transition: 0.3s ease;
}

/* ==========================================================================
   Widget Container
   ========================================================================== */

.evchat-widget {
    position: fixed;
    z-index: 999999;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
    font-size: 14px;
    line-height: 1.5;
    box-sizing: border-box;
}

.evchat-widget *,
.evchat-widget *::before,
.evchat-widget *::after {
    box-sizing: border-box;
}

/* Posizioni */
.evchat-position-bottom-right {
    bottom: 20px;
    right: 20px;
}

.evchat-position-bottom-left {
    bottom: 20px;
    left: 20px;
}

.evchat-position-top-right {
    top: 20px;
    right: 20px;
}

.evchat-position-top-left {
    top: 20px;
    left: 20px;
}

/* ==========================================================================
   Toggle Button
   ========================================================================== */

.evchat-toggle {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: var(--evchat-primary);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow:
        0 4px 12px rgba(0, 0, 0, 0.25),
        0 0 0 3px rgba(255, 255, 255, 0.9),
        0 0 20px color-mix(in srgb, var(--evchat-primary) 40%, transparent);
    transition: transform var(--evchat-transition), background var(--evchat-transition), box-shadow var(--evchat-transition);
    position: absolute;
    bottom: 0;
    right: 0;
    animation: evchat-pulse 2s ease-in-out infinite;
}

/* Animazione pulse per attirare l'attenzione */
@keyframes evchat-pulse {
    0%, 100% {
        box-shadow:
            0 4px 12px rgba(0, 0, 0, 0.25),
            0 0 0 3px rgba(255, 255, 255, 0.9),
            0 0 20px color-mix(in srgb, var(--evchat-primary) 40%, transparent);
    }
    50% {
        box-shadow:
            0 6px 16px rgba(0, 0, 0, 0.3),
            0 0 0 4px rgba(255, 255, 255, 1),
            0 0 30px color-mix(in srgb, var(--evchat-primary) 60%, transparent);
    }
}

.evchat-position-bottom-left .evchat-toggle,
.evchat-position-top-left .evchat-toggle {
    right: auto;
    left: 0;
}

.evchat-toggle:hover {
    transform: scale(1.1);
    background: color-mix(in srgb, var(--evchat-primary) 85%, black);
    animation: none;
    box-shadow:
        0 8px 24px rgba(0, 0, 0, 0.35),
        0 0 0 4px rgba(255, 255, 255, 1),
        0 0 40px color-mix(in srgb, var(--evchat-primary) 70%, transparent);
}

.evchat-toggle:focus {
    outline: 2px solid var(--evchat-primary);
    outline-offset: 2px;
}

.evchat-toggle-icon {
    color: #ffffff;
    width: 28px;
    height: 28px;
}

.evchat-toggle-icon svg {
    width: 100%;
    height: 100%;
}

/* ==========================================================================
   Teaser Message Box
   ========================================================================== */

.evchat-teaser {
    position: absolute;
    bottom: 75px;
    right: 0;
    background: var(--evchat-primary);
    border-radius: 12px;
    padding: 14px 18px;
    box-shadow:
        0 4px 20px rgba(0, 0, 0, 0.2),
        0 0 0 2px rgba(255, 255, 255, 0.3),
        0 0 25px rgba(var(--evchat-primary-rgb), 0.4);
    max-width: 280px;
    display: flex;
    align-items: flex-start;
    gap: 10px;
    animation: evchat-teaser-bounce 0.5s ease-out;
    transform-origin: bottom right;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.evchat-teaser:hover {
    transform: scale(1.03);
    box-shadow:
        0 6px 25px rgba(0, 0, 0, 0.25),
        0 0 0 2px rgba(255, 255, 255, 0.4),
        0 0 30px rgba(var(--evchat-primary-rgb), 0.5);
}

/* Freccia (triangolo) che punta verso il pulsante */
.evchat-teaser::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 var(--evchat-primary);
}

/* Animazione di entrata */
@keyframes evchat-teaser-bounce {
    0% {
        opacity: 0;
        transform: scale(0.8) translateY(10px);
    }
    60% {
        transform: scale(1.05) translateY(-3px);
    }
    100% {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

/* Posizionamento per bottom-left */
.evchat-position-bottom-left .evchat-teaser {
    right: auto;
    left: 0;
    transform-origin: bottom left;
}

.evchat-position-bottom-left .evchat-teaser::after {
    right: auto;
    left: 24px;
}

/* Posizionamento per top (sopra il pulsante diventa sotto) */
.evchat-position-top-right .evchat-teaser,
.evchat-position-top-left .evchat-teaser {
    bottom: auto;
    top: 75px;
    transform-origin: top right;
}

.evchat-position-top-right .evchat-teaser::after,
.evchat-position-top-left .evchat-teaser::after {
    bottom: auto;
    top: -8px;
    border-top: none;
    border-bottom: 8px solid var(--evchat-primary);
}

.evchat-position-top-left .evchat-teaser {
    transform-origin: top left;
    right: auto;
    left: 0;
}

.evchat-position-top-left .evchat-teaser::after {
    right: auto;
    left: 24px;
}

.evchat-teaser-content {
    flex: 1;
    color: #ffffff;
    font-size: 15px;
    font-weight: 500;
    line-height: 1.4;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.evchat-teaser-close {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    padding: 0;
    cursor: pointer;
    color: rgba(255, 255, 255, 0.8);
    flex-shrink: 0;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.2s ease;
}

.evchat-teaser-close:hover {
    color: #ffffff;
    background: rgba(255, 255, 255, 0.3);
}

.evchat-teaser-close svg {
    width: 14px;
    height: 14px;
}

/* Animazione uscita */
.evchat-teaser.evchat-teaser-hiding {
    animation: evchat-teaser-hide 0.3s ease-out forwards;
}

@keyframes evchat-teaser-hide {
    to {
        opacity: 0;
        transform: scale(0.8) translateY(10px);
    }
}

/* ==========================================================================
   Chat Container
   ========================================================================== */

.evchat-container {
    position: absolute;
    bottom: 75px;
    right: 0;
    width: var(--evchat-width);
    height: var(--evchat-height);
    max-height: calc(100vh - 100px);
    background: var(--evchat-bg);
    border-radius: var(--evchat-border-radius);
    box-shadow: var(--evchat-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: evchat-slide-up 0.3s ease;
}

.evchat-position-bottom-left .evchat-container,
.evchat-position-top-left .evchat-container {
    right: auto;
    left: 0;
}

.evchat-position-top-right .evchat-container,
.evchat-position-top-left .evchat-container {
    bottom: auto;
    top: 75px;
    animation: evchat-slide-down 0.3s ease;
}

@keyframes evchat-slide-up {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes evchat-slide-down {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ==========================================================================
   Header
   ========================================================================== */

.evchat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 15px 18px;
    background: var(--evchat-primary);
    color: #ffffff;
    flex-shrink: 0;
}

.evchat-title {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    color: inherit;
}

.evchat-header-actions {
    display: flex;
    gap: 8px;
}

.evchat-header-actions button {
    width: 32px;
    height: 32px;
    padding: 0;
    border: none;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 6px;
    color: #ffffff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background var(--evchat-transition);
}

.evchat-header-actions button:hover {
    background: rgba(255, 255, 255, 0.3);
}

.evchat-header-actions button svg {
    width: 16px;
    height: 16px;
}

/* ==========================================================================
   Messages Area
   ========================================================================== */

.evchat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 15px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: #f8f9fa;
}

.evchat-messages::-webkit-scrollbar {
    width: 6px;
}

.evchat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.evchat-messages::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 3px;
}

.evchat-messages::-webkit-scrollbar-thumb:hover {
    background: #a1a1a1;
}

/* ==========================================================================
   Message Bubbles
   ========================================================================== */

.evchat-message {
    display: flex;
    max-width: 85%;
    animation: evchat-message-in 0.2s ease;
}

@keyframes evchat-message-in {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.evchat-message-user {
    align-self: flex-end;
}

.evchat-message-bot {
    align-self: flex-start;
}

.evchat-message-content {
    padding: 10px 14px;
    border-radius: 16px;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.evchat-message-user .evchat-message-content {
    background: var(--evchat-primary);
    color: #ffffff;
    border-bottom-right-radius: 4px;
}

.evchat-message-bot .evchat-message-content {
    background: var(--evchat-bg);
    color: var(--evchat-text);
    border: 1px solid #e0e0e0;
    border-bottom-left-radius: 4px;
}

/* Markdown nel messaggio bot */
.evchat-message-bot .evchat-message-content p {
    margin: 0 0 10px;
}

.evchat-message-bot .evchat-message-content p:last-child {
    margin-bottom: 0;
}

.evchat-message-bot .evchat-message-content code {
    background: #f0f0f0;
    padding: 2px 5px;
    border-radius: 3px;
    font-size: 13px;
}

.evchat-message-bot .evchat-message-content pre {
    background: #2d2d2d;
    color: #f8f8f2;
    padding: 12px;
    border-radius: 6px;
    overflow-x: auto;
    margin: 10px 0;
}

.evchat-message-bot .evchat-message-content pre code {
    background: none;
    padding: 0;
    color: inherit;
}

.evchat-message-bot .evchat-message-content ul,
.evchat-message-bot .evchat-message-content ol {
    margin: 10px 0;
    padding-left: 20px;
}

.evchat-message-bot .evchat-message-content a {
    color: var(--evchat-primary);
    text-decoration: underline;
}

/* ==========================================================================
   Quick Questions
   ========================================================================== */

.evchat-quick-questions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 8px 16px 16px;
}

.evchat-quick-question {
    background: transparent;
    border: 1px solid var(--evchat-primary);
    color: var(--evchat-primary);
    padding: 8px 14px;
    border-radius: 18px;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: left;
    line-height: 1.3;
    font-family: inherit;
}

.evchat-quick-question:hover {
    background: var(--evchat-primary);
    color: #fff;
}

.evchat-quick-question:active {
    transform: scale(0.97);
}

/* Nascondi le domande rapide quando ci sono messaggi utente */
.evchat-messages.has-user-messages .evchat-quick-questions {
    display: none;
}

/* ==========================================================================
   Typing Indicator
   ========================================================================== */

.evchat-typing {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 12px 16px;
}

.evchat-typing-dot {
    width: 8px;
    height: 8px;
    background: #bbb;
    border-radius: 50%;
    animation: evchat-typing 1.4s infinite ease-in-out both;
}

.evchat-typing-dot:nth-child(1) {
    animation-delay: -0.32s;
}

.evchat-typing-dot:nth-child(2) {
    animation-delay: -0.16s;
}

@keyframes evchat-typing {
    0%, 80%, 100% {
        transform: scale(0.6);
        opacity: 0.5;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* ==========================================================================
   Input Area
   ========================================================================== */

.evchat-input-area {
    padding: 12px 15px;
    background: var(--evchat-bg);
    border-top: 1px solid #e0e0e0;
    flex-shrink: 0;
}

.evchat-form {
    display: flex;
    align-items: flex-end;
    gap: 10px;
}

.evchat-input {
    flex: 1;
    border: 1px solid #ddd;
    border-radius: 20px;
    padding: 10px 16px;
    font-size: 14px;
    font-family: inherit;
    resize: none;
    max-height: 120px;
    min-height: 42px;
    line-height: 1.4;
    outline: none;
    transition: border-color var(--evchat-transition);
}

.evchat-input:focus {
    border-color: var(--evchat-primary);
}

.evchat-input::placeholder {
    color: #999;
}

.evchat-send {
    width: 42px;
    height: 42px;
    border: none;
    border-radius: 50%;
    background: var(--evchat-primary);
    color: #ffffff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background var(--evchat-transition), transform var(--evchat-transition);
}

.evchat-send:hover {
    background: color-mix(in srgb, var(--evchat-primary) 90%, black);
    transform: scale(1.05);
}

.evchat-send:disabled {
    background: #ccc;
    cursor: not-allowed;
    transform: none;
}

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

/* ==========================================================================
   Email Form
   ========================================================================== */

.evchat-email-form {
    padding: 20px;
    text-align: center;
    background: #f8f9fa;
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.evchat-email-form p {
    margin: 0 0 15px;
    color: var(--evchat-text);
}

.evchat-email-input {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid #ddd;
    border-radius: 8px;
    font-size: 14px;
    margin-bottom: 15px;
    outline: none;
}

.evchat-email-input:focus {
    border-color: var(--evchat-primary);
}

.evchat-email-actions {
    display: flex;
    gap: 10px;
    justify-content: center;
}

.evchat-email-submit {
    padding: 10px 24px;
    background: var(--evchat-primary);
    color: #ffffff;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: background var(--evchat-transition);
}

.evchat-email-submit:hover {
    background: color-mix(in srgb, var(--evchat-primary) 90%, black);
}

.evchat-email-skip {
    padding: 10px 20px;
    background: transparent;
    color: #666;
    border: 1px solid #ddd;
    border-radius: 8px;
    font-size: 14px;
    cursor: pointer;
    transition: background var(--evchat-transition);
}

.evchat-email-skip:hover {
    background: #f0f0f0;
}

/* ==========================================================================
   Privacy Notice
   ========================================================================== */

.evchat-privacy-notice {
    padding: 8px 15px;
    text-align: center;
    background: #f8f9fa;
    border-top: 1px solid #e0e0e0;
}

.evchat-privacy-notice small {
    color: #666;
    font-size: 11px;
    line-height: 1.4;
}

.evchat-privacy-notice a {
    color: var(--evchat-primary);
    text-decoration: none;
    font-weight: 500;
}

.evchat-privacy-notice a:hover {
    text-decoration: underline;
}

/* ==========================================================================
   Branding
   ========================================================================== */

.evchat-branding {
    padding: 8px;
    text-align: center;
    background: #f8f9fa;
    border-top: 1px solid #e0e0e0;
}

.evchat-branding small {
    color: #999;
    font-size: 11px;
}

/* ==========================================================================
   Inline Widget (Shortcode)
   ========================================================================== */

.evchat-inline {
    width: 100%;
    max-width: 600px;
    margin: 20px auto;
}

.evchat-container-inline {
    position: relative;
    width: 100%;
    height: 100%;
    animation: none;
}

/* ==========================================================================
   Error State
   ========================================================================== */

.evchat-error {
    padding: 20px;
    background: #fff3f3;
    border: 1px solid #ffcccc;
    border-radius: 8px;
    color: #cc0000;
    text-align: center;
}

.evchat-message-error .evchat-message-content {
    background: #fff3f3;
    border-color: #ffcccc;
    color: #cc0000;
}

/* ==========================================================================
   Responsive
   ========================================================================== */

@media (max-width: 480px) {
    .evchat-widget {
        bottom: 10px !important;
        right: 10px !important;
        left: 10px !important;
    }

    .evchat-container {
        width: calc(100vw - 20px);
        height: calc(100vh - 100px);
        max-height: none;
        right: 0;
        left: 0;
        bottom: 70px;
        border-radius: var(--evchat-border-radius) var(--evchat-border-radius) 0 0;
    }

    .evchat-toggle {
        width: 56px;
        height: 56px;
    }

    .evchat-position-bottom-left .evchat-toggle,
    .evchat-position-bottom-right .evchat-toggle {
        right: 0;
        left: auto;
    }
}

/* ==========================================================================
   Modal Confirm
   ========================================================================== */

.evchat-modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.evchat-modal-overlay.evchat-modal-visible {
    opacity: 1;
}

.evchat-modal {
    background: var(--evchat-bg);
    border-radius: var(--evchat-border-radius);
    box-shadow: var(--evchat-shadow);
    width: 90%;
    max-width: 320px;
    transform: scale(0.9);
    transition: transform 0.2s ease;
    overflow: hidden;
}

.evchat-modal-overlay.evchat-modal-visible .evchat-modal {
    transform: scale(1);
}

.evchat-modal-header {
    padding: 15px 18px;
    background: var(--evchat-primary);
    color: #ffffff;
}

.evchat-modal-title {
    margin: 0;
    font-size: 15px;
    font-weight: 600;
}

.evchat-modal-body {
    padding: 20px 18px;
}

.evchat-modal-body p {
    margin: 0;
    color: var(--evchat-text);
    font-size: 14px;
    line-height: 1.5;
}

.evchat-modal-footer {
    padding: 12px 18px;
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    border-top: 1px solid #e0e0e0;
}

.evchat-modal-btn {
    padding: 8px 16px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: background var(--evchat-transition), transform var(--evchat-transition);
}

.evchat-modal-btn:hover {
    transform: translateY(-1px);
}

.evchat-modal-btn:focus {
    outline: 2px solid var(--evchat-primary);
    outline-offset: 2px;
}

.evchat-modal-btn-cancel {
    background: #f0f0f0;
    border: 1px solid #ddd;
    color: #666;
}

.evchat-modal-btn-cancel:hover {
    background: #e5e5e5;
}

.evchat-modal-btn-confirm {
    background: var(--evchat-primary);
    border: none;
    color: #ffffff;
}

.evchat-modal-btn-confirm:hover {
    background: color-mix(in srgb, var(--evchat-primary) 85%, black);
}

/* ==========================================================================
   Dark Mode Support (se il tema lo supporta)
   ========================================================================== */

@media (prefers-color-scheme: dark) {
    .evchat-widget[data-theme="auto"] {
        --evchat-bg: #1e1e1e;
        --evchat-text: #e0e0e0;
    }

    .evchat-widget[data-theme="auto"] .evchat-messages {
        background: #252525;
    }

    .evchat-widget[data-theme="auto"] .evchat-message-bot .evchat-message-content {
        background: #2d2d2d;
        border-color: #404040;
    }

    .evchat-widget[data-theme="auto"] .evchat-input-area {
        border-color: #404040;
    }

    .evchat-widget[data-theme="auto"] .evchat-input {
        background: #2d2d2d;
        border-color: #404040;
        color: #e0e0e0;
    }
}
