/* ==========================================
   SapTour AI Chatbot - Frontend Styles
   ========================================== */

/* Chat Toggle Button */
.saptour-chatbot {
    position: fixed !important;
    bottom: 112px !important;
    left: 24px !important;
    right: auto !important;
    z-index: 999999 !important;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif !important;
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
    pointer-events: auto !important;
}

.saptour-chat-toggle {
    width: 48px !important;
    height: 48px !important;
    border-radius: 50% !important;
    background-color: #E8563A !important;
    background-image: linear-gradient(135deg, #E8563A 0%, #D44A2E 100%) !important;
    color: #fff !important;
    border: 2px solid #fff !important;
    cursor: pointer !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    box-shadow: 0 3px 10px rgba(232, 86, 58, 0.32), 0 0 0 3px rgba(232, 86, 58, 0.16) !important;
    transition: all 0.3s ease;
    position: relative !important;
    overflow: hidden !important;
    visibility: visible !important;
    opacity: 1 !important;
    pointer-events: auto !important;
    animation: saptour-pulse 2s infinite;
}

.saptour-chat-toggle:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 24px rgba(232, 86, 58, 0.5), 0 0 0 6px rgba(232, 86, 58, 0.15) !important;
}

.saptour-chat-toggle:active {
    transform: scale(0.95);
}

@keyframes saptour-pulse {
    0%, 100% { transform: scale(1); box-shadow: 0 3px 10px rgba(232, 86, 58, 0.32), 0 0 0 3px rgba(232, 86, 58, 0.16); }
    50% { transform: scale(1.05); box-shadow: 0 4px 14px rgba(232, 86, 58, 0.42), 0 0 0 5px rgba(232, 86, 58, 0.1); }
}

/* Pulse animation for unread */
.saptour-chat-toggle.saptour-has-unread::after {
    content: '';
    position: absolute;
    top: -4px;
    right: -4px;
    width: 18px;
    height: 18px;
    background: #FF3B30;
    border-radius: 50%;
    border: 2px solid #fff;
    animation: saptour-pulse 1.5s infinite;
}

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

/* Chat Panel - hidden by default, shown on click */
.saptour-chat-panel {
    position: fixed !important;
    bottom: 130px !important;
    left: 24px !important;
    right: auto !important;
    width: 380px !important;
    height: 520px !important;
    background: #fff !important;
    border-radius: 16px !important;
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.15) !important;
    display: none !important; /* Hidden by default */
    flex-direction: column !important;
    overflow: hidden !important;
    z-index: 1000000 !important;
    pointer-events: auto !important;
}

/* When panel is opened by JS, it gets display:flex */
.saptour-chat-panel.saptour-panel-open {
    display: flex !important;
    animation: saptour-slide-up 0.3s ease-out;
}

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

.saptour-chat-panel.saptour-closing {
    animation: saptour-slide-down 0.2s ease-in forwards;
}

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

/* Chat Header */
.saptour-chat-header {
    background: linear-gradient(135deg, #E8563A 0%, #D44A2E 100%);
    color: #fff;
    padding: 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.saptour-chat-header-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.saptour-chat-avatar {
    flex-shrink: 0;
}

.saptour-chat-header-text {
    display: flex;
    flex-direction: column;
}

.saptour-chat-title {
    font-size: 16px;
    font-weight: 600;
    margin: 0;
    line-height: 1.3;
}

.saptour-chat-subtitle {
    font-size: 12px;
    opacity: 0.85;
    line-height: 1.3;
}

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

.saptour-chat-action-btn {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: #fff;
    cursor: pointer;
    padding: 6px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.saptour-chat-action-btn:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* Messages Area */
.saptour-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: #f8f9fa;
    scroll-behavior: smooth;
}

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

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

.saptour-chat-messages::-webkit-scrollbar-thumb {
    background: #ddd;
    border-radius: 3px;
}

/* Message Bubbles */
.saptour-msg {
    max-width: 85%;
    padding: 12px 16px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.5;
    word-wrap: break-word;
    animation: saptour-msg-appear 0.3s ease-out;
}

@keyframes saptour-msg-appear {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* User message */
.saptour-msg-user {
    background: linear-gradient(135deg, #E8563A 0%, #D44A2E 100%);
    color: #fff;
    align-self: flex-end;
    border-bottom-right-radius: 4px;
}

/* Assistant message */
.saptour-msg-assistant {
    background: #fff;
    color: #333;
    align-self: flex-start;
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

/* System/welcome message */
.saptour-msg-system {
    background: #eef2ff;
    color: #4a5568;
    align-self: center;
    text-align: center;
    font-size: 13px;
    border-radius: 12px;
    max-width: 90%;
}

/* Thinking indicator */
.saptour-msg-thinking {
    background: #fff;
    color: #999;
    align-self: flex-start;
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
    display: flex;
    align-items: center;
    gap: 8px;
}

.saptour-thinking-dots {
    display: flex;
    gap: 4px;
}

.saptour-thinking-dot {
    width: 8px;
    height: 8px;
    background: #E8563A;
    border-radius: 50%;
    animation: saptour-dot-bounce 1.4s infinite ease-in-out both;
}

.saptour-thinking-dot:nth-child(1) { animation-delay: 0s; }
.saptour-thinking-dot:nth-child(2) { animation-delay: 0.2s; }
.saptour-thinking-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes saptour-dot-bounce {
    0%, 80%, 100% { transform: scale(0); opacity: 0.4; }
    40% { transform: scale(1); opacity: 1; }
}

/* Error message */
.saptour-msg-error {
    background: #fee;
    color: #c00;
    align-self: center;
    font-size: 13px;
    border-radius: 12px;
    max-width: 90%;
    text-align: center;
}

/* Input Area */
.saptour-chat-input-area {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 12px 16px;
    background: #fff;
    border-top: 1px solid #eee;
    flex-shrink: 0;
}

.saptour-chat-input {
    flex: 1;
    border: 1px solid #ddd;
    border-radius: 12px;
    padding: 10px 14px;
    font-size: 14px;
    line-height: 1.4;
    resize: none;
    max-height: 100px;
    min-height: 40px;
    outline: none;
    transition: border-color 0.2s;
    font-family: inherit;
    overflow-y: auto;
}

.saptour-chat-input:focus {
    border-color: #E8563A;
}

.saptour-chat-input::placeholder {
    color: #999;
}

.saptour-chat-send {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    background: linear-gradient(135deg, #E8563A 0%, #D44A2E 100%);
    color: #fff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
}

.saptour-chat-send:hover {
    transform: scale(1.05);
}

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

/* Mobile Responsive */
@media screen and (max-width: 480px) {
    .saptour-chat-panel {
        width: calc(100vw - 16px);
        height: calc(100vh - 80px);
        bottom: 80px;
        right: 8px;
        border-radius: 12px;
    }

    .saptour-chat-toggle {
        width: 52px;
        height: 52px;
        bottom: 16px;
        right: 16px;
    }

    .saptour-chatbot {
        bottom: 16px;
        right: 16px;
    }

    .saptour-msg {
        max-width: 90%;
    }
}

/* RTL Support */
[dir="rtl"] .saptour-chatbot,
.saptour-chatbot[data-lang="ar"] {
    right: auto;
    left: 24px;
}

[dir="rtl"] .saptour-chat-panel,
.saptour-chatbot[data-lang="ar"] .saptour-chat-panel {
    right: auto;
    left: 24px;
}

@media screen and (max-width: 480px) {
    [dir="rtl"] .saptour-chat-panel,
    .saptour-chatbot[data-lang="ar"] .saptour-chat-panel {
        left: 8px;
    }
}

/* ==========================================
   Admin Panel Styles
   ========================================== */

.saptour-chatbot-admin .saptour-admin-status {
    margin: 16px 0;
}

.saptour-status-card {
    padding: 16px 20px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 14px;
}

.saptour-status-ok {
    background: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb;
}

.saptour-status-warning {
    background: #fff3cd;
    color: #856404;
    border: 1px solid #ffeeba;
}

.saptour-status-icon {
    font-size: 20px;
}

.saptour-admin-info {
    background: #f8f9fa;
    border: 1px solid #e9ecef;
    border-radius: 8px;
    padding: 20px;
    margin-top: 20px;
}

.saptour-admin-info h3 {
    margin-top: 0;
    color: #333;
}

.saptour-admin-info ol,
.saptour-admin-info ul {
    padding-left: 20px;
}

.saptour-admin-info li {
    margin-bottom: 6px;
    line-height: 1.6;
}

.saptour-field-group {
    display: flex;
    align-items: center;
    gap: 8px;
}

.saptour-toggle-key {
    font-size: 13px;
}

/* Message content formatting */
.saptour-msg-assistant p {
    margin: 0 0 8px 0;
}

.saptour-msg-assistant p:last-child {
    margin-bottom: 0;
}

.saptour-msg-assistant ul,
.saptour-msg-assistant ol {
    margin: 4px 0;
    padding-left: 20px;
}

.saptour-msg-assistant li {
    margin-bottom: 2px;
}

.saptour-msg-assistant strong {
    color: #E8563A;
}

.saptour-msg-assistant a {
    color: #E8563A;
    text-decoration: underline;
}

.saptour-msg-assistant a:hover {
    color: #D44A2E;
}
