/**
 * Claudio - Chatbot AI di MOTouristOffice
 * Widget chat-only: bottone flottante + pannello draggabile
 */

/* ---- Bottone flottante (draggabile) ---- */
#mto-help-btn {
    position: fixed;
    top: 50%;
    right: 0;
    transform: translateY(-50%);
    z-index: 2147483640;
    width: 36px;
    height: 52px;
    border-radius: 8px 0 0 8px;
    border: none;
    background: #0d6efd;
    color: #fff;
    font-size: 1.2rem;
    cursor: pointer;
    box-shadow: -2px 2px 8px rgba(0, 0, 0, 0.25);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, width 0.2s;
    touch-action: none;
    user-select: none;
}
#mto-help-btn:hover {
    background: #0b5ed7;
    width: 42px;
}
#mto-help-btn.mto-dragging {
    transition: none;
    opacity: 0.85;
}

/* ---- Pannello ---- */
#mto-help-panel {
    position: fixed;
    bottom: 0;
    right: 0;
    width: 380px;
    max-width: 100vw;
    height: 70vh;
    max-height: calc(100vh - 20px);
    z-index: 2147483641;
    background: #fff;
    border-radius: 12px 12px 0 0;
    box-shadow: -4px 0 24px rgba(0, 0, 0, 0.18);
    display: none;
    flex-direction: column;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 0.875rem;
    overflow: hidden;
}
#mto-help-panel.mto-help-open {
    display: flex;
}
#mto-help-panel.mto-dragging {
    transition: none;
    opacity: 0.92;
}

/* ---- Header (handle per drag) ---- */
.mto-help-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: #0d6efd;
    color: #fff;
    border-radius: 12px 12px 0 0;
    flex-shrink: 0;
    cursor: grab;
    user-select: none;
}
.mto-help-header:active {
    cursor: grabbing;
}
.mto-help-header h6 {
    margin: 0;
    font-size: 0.95rem;
    font-weight: 600;
    pointer-events: none;
}
.mto-help-close {
    background: none;
    border: none;
    color: #fff;
    font-size: 1.2rem;
    cursor: pointer;
    padding: 0 2px;
    line-height: 1;
    opacity: 0.8;
}
.mto-help-close:hover {
    opacity: 1;
}

/* ---- Body: flex column per scroll corretto ---- */
.mto-help-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    padding: 12px 16px 8px;
    min-height: 0; /* fix per flex overflow */
}

/* ---- Chat messages (scrollabile con scrollbar visibile) ---- */
.mto-help-chat-messages {
    flex: 1;
    overflow-y: scroll;
    padding-bottom: 8px;
    padding-right: 4px;
    min-height: 0;
    scroll-behavior: smooth;
}
/* Scrollbar visibile e stilizzata */
.mto-help-chat-messages::-webkit-scrollbar {
    width: 6px;
}
.mto-help-chat-messages::-webkit-scrollbar-track {
    background: transparent;
}
.mto-help-chat-messages::-webkit-scrollbar-thumb {
    background: #c0c0c0;
    border-radius: 3px;
}
.mto-help-chat-messages::-webkit-scrollbar-thumb:hover {
    background: #999;
}

/* ---- Chat bubbles ---- */
.mto-help-chat-bubble {
    max-width: 88%;
    padding: 8px 12px;
    margin-bottom: 8px;
    border-radius: 12px;
    font-size: 0.82rem;
    line-height: 1.5;
    word-wrap: break-word;
    overflow-wrap: break-word;
}
.mto-help-chat-bubble.user {
    background: #0d6efd;
    color: #fff;
    margin-left: auto;
    border-bottom-right-radius: 4px;
}
.mto-help-chat-bubble.assistant {
    background: #f0f0f0;
    color: #212529;
    margin-right: auto;
    border-bottom-left-radius: 4px;
}
.mto-help-chat-bubble.assistant .mto-help-content p {
    margin-bottom: 6px;
}
.mto-help-chat-bubble.assistant .mto-help-content p:last-child {
    margin-bottom: 0;
}
.mto-help-chat-bubble.assistant .mto-help-content ul,
.mto-help-chat-bubble.assistant .mto-help-content ol {
    padding-left: 18px;
    margin-bottom: 6px;
}
.mto-help-chat-bubble.assistant .mto-help-content li {
    margin-bottom: 2px;
}
.mto-help-chat-bubble.assistant .mto-help-content a {
    color: #0d6efd;
    text-decoration: underline;
}
.mto-help-chat-bubble.assistant .mto-help-content a:hover {
    color: #0b5ed7;
}
.mto-help-chat-bubble.assistant .mto-help-content table {
    width: 100%;
    font-size: 0.78rem;
    border-collapse: collapse;
    margin-bottom: 6px;
}
.mto-help-chat-bubble.assistant .mto-help-content th,
.mto-help-chat-bubble.assistant .mto-help-content td {
    border: 1px solid #dee2e6;
    padding: 3px 6px;
    text-align: left;
}
.mto-help-chat-bubble.assistant .mto-help-content th {
    background: #e9ecef;
    font-weight: 600;
}
.mto-help-chat-bubble.assistant .mto-help-content blockquote {
    border-left: 3px solid #0d6efd;
    padding: 4px 10px;
    margin: 6px 0;
    background: #f0f7ff;
    font-size: 0.8rem;
    color: #495057;
}
.mto-help-chat-bubble.assistant .mto-help-content code {
    background: #e9ecef;
    padding: 1px 4px;
    border-radius: 3px;
    font-size: 0.78rem;
}
.mto-help-chat-bubble.error {
    background: #f8d7da;
    color: #842029;
    margin-right: auto;
    border-bottom-left-radius: 4px;
}

/* ---- Feedback thumbs ---- */
.mto-help-feedback {
    display: flex;
    gap: 8px;
    margin-top: 4px;
    align-items: center;
}
.mto-help-feedback button {
    background: none;
    border: 1px solid #ced4da;
    border-radius: 4px;
    padding: 2px 8px;
    font-size: 0.75rem;
    cursor: pointer;
    color: #6c757d;
    transition: background 0.15s, color 0.15s;
}
.mto-help-feedback button:hover {
    background: #e9ecef;
}
.mto-help-feedback button.selected {
    border-color: #0d6efd;
    color: #0d6efd;
    background: #e7f1ff;
}
.mto-help-feedback .mto-feedback-thanks {
    font-size: 0.72rem;
    color: #198754;
    display: none;
}

/* ---- Escalation link (inline, after feedback) ---- */
.mto-help-escalation-link {
    font-size: 0.70rem;
    color: #6c757d;
    text-decoration: none;
    margin-left: auto;
    white-space: nowrap;
}
.mto-help-escalation-link:hover {
    color: #0d6efd;
    text-decoration: underline;
}

/* ---- Escalation suggestion (auto after N turns) ---- */
.mto-help-escalation-suggest {
    background: #fff3cd;
    border: 1px solid #ffc107;
    border-radius: 8px;
    padding: 8px 12px;
    margin-bottom: 8px;
    text-align: center;
    font-size: 0.78rem;
    color: #664d03;
}
.mto-help-escalation-suggest p {
    margin: 0 0 6px;
}
.mto-help-escalation-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 5px 14px;
    border: none;
    border-radius: 6px;
    background: #0d6efd;
    color: #fff;
    font-size: 0.78rem;
    cursor: pointer;
    transition: background 0.15s;
}
.mto-help-escalation-btn:hover {
    background: #0b5ed7;
}

/* ---- Chat input ---- */
.mto-help-chat-input {
    display: flex;
    gap: 6px;
    padding-top: 8px;
    border-top: 1px solid #e9ecef;
    flex-shrink: 0;
}
.mto-help-chat-input textarea {
    flex: 1;
    padding: 6px 10px;
    border: 1px solid #ced4da;
    border-radius: 6px;
    font-size: 0.82rem;
    resize: none;
    max-height: 80px;
    outline: none;
    font-family: inherit;
}
.mto-help-chat-input textarea:focus {
    border-color: #86b7fe;
    box-shadow: 0 0 0 3px rgba(13, 110, 253, 0.15);
}
.mto-help-chat-input button {
    padding: 6px 12px;
    border: none;
    border-radius: 6px;
    background: #0d6efd;
    color: #fff;
    cursor: pointer;
    align-self: flex-end;
}
.mto-help-chat-input button:hover {
    background: #0b5ed7;
}
.mto-help-chat-input button:disabled {
    background: #adb5bd;
    cursor: not-allowed;
}

/* ---- Disclaimer AI ---- */
.mto-help-disclaimer {
    font-size: 0.68rem;
    color: #adb5bd;
    text-align: center;
    padding: 4px 0 0;
    flex-shrink: 0;
}

/* ---- Typing indicator ---- */
.mto-help-typing {
    display: inline-flex;
    gap: 4px;
    padding: 8px 12px;
    background: #f0f0f0;
    border-radius: 12px;
    border-bottom-left-radius: 4px;
    margin-bottom: 8px;
}
.mto-help-typing span {
    width: 6px;
    height: 6px;
    background: #adb5bd;
    border-radius: 50%;
    animation: mtoTypingDot 1.2s infinite;
}
.mto-help-typing span:nth-child(2) { animation-delay: 0.2s; }
.mto-help-typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes mtoTypingDot {
    0%, 60%, 100% { opacity: 0.3; transform: scale(0.8); }
    30% { opacity: 1; transform: scale(1); }
}

/* ---- Responsive ---- */
@media (max-width: 480px) {
    #mto-help-panel {
        width: 100vw;
        height: 85vh;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        border-radius: 12px 12px 0 0;
    }
    #mto-help-btn {
        top: 50%;
        right: 0;
        width: 32px;
        height: 44px;
        font-size: 1rem;
    }
}
