/* ==========================================================================
   VIFM AI Chatbot Widget Styles v1.2
   ========================================================================== */

/* Toggle Button */
.vifm-chat-toggle {
    position: fixed;
    bottom: 24px;
    left: 24px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, #1a3c6e 0%, #2a5da8 100%);
    color: #fff;
    border: none;
    cursor: pointer;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 20px rgba(26, 60, 110, 0.4);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.vifm-chat-toggle:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 24px rgba(26, 60, 110, 0.5);
}

.vifm-chat-toggle svg {
    width: 28px;
    height: 28px;
    fill: currentColor;
}

/* Pulse animation on toggle */
.vifm-chat-toggle::after {
    content: "";
    position: absolute;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background: rgba(26, 60, 110, 0.3);
    animation: vifmPulse 2s ease-out infinite;
    pointer-events: none;
}

@keyframes vifmPulse {
    0% {
        transform: scale(1);
        opacity: 0.6;
    }
    100% {
        transform: scale(1.6);
        opacity: 0;
    }
}

/* Chat Panel */
.vifm-chat-panel {
    position: fixed;
    bottom: 96px;
    left: 24px;
    width: 400px;
    height: 560px;
    background: #fff;
    border-radius: 20px;
    box-shadow: 0 12px 48px rgba(0, 0, 0, 0.15), 0 2px 8px rgba(0, 0, 0, 0.08);
    z-index: 9999;
    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;
}

.vifm-chat-panel.vifm-chat-open {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

/* Header */
.vifm-chat-header {
    background: linear-gradient(135deg, #1a3c6e 0%, #2a5da8 100%);
    color: #fff;
    padding: 18px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.vifm-chat-header-title {
    font-size: 16px;
    font-weight: 600;
    line-height: 1.3;
    display: flex;
    align-items: center;
    gap: 10px;
}

.vifm-chat-header-title svg {
    width: 22px;
    height: 22px;
    fill: currentColor;
    flex-shrink: 0;
}

.vifm-chat-close {
    background: rgba(255, 255, 255, 0.15);
    border: none;
    color: #fff;
    cursor: pointer;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    transition: background 0.15s;
}

.vifm-chat-close:hover {
    background: rgba(255, 255, 255, 0.25);
}

/* Powered-by bar */
.vifm-chat-powered {
    text-align: center;
    font-size: 11px;
    color: #9ca3af;
    padding: 4px 0;
    background: #fff;
    border-top: 1px solid #f0f1f3;
    flex-shrink: 0;
}

/* Messages Area */
.vifm-chat-body {
    flex: 1;
    overflow-y: auto;
    padding: 18px 16px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    background: #f5f7fa;
}

.vifm-chat-body::-webkit-scrollbar {
    width: 4px;
}

.vifm-chat-body::-webkit-scrollbar-track {
    background: transparent;
}

.vifm-chat-body::-webkit-scrollbar-thumb {
    background: #c5c9d1;
    border-radius: 4px;
}

/* Message Bubbles */
.vifm-chat-msg {
    max-width: 88%;
    padding: 12px 16px;
    border-radius: 18px;
    font-size: 14px;
    line-height: 1.6;
    word-wrap: break-word;
    animation: vifmMsgFadeIn 0.25s ease-out;
}

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

.vifm-chat-msg-user {
    background: linear-gradient(135deg, #1a3c6e 0%, #2a5da8 100%);
    color: #fff;
    align-self: flex-end;
    border-bottom-right-radius: 6px;
    white-space: pre-wrap;
    box-shadow: 0 2px 8px rgba(26, 60, 110, 0.2);
}

.vifm-chat-msg-assistant {
    background: #fff;
    color: #1a1a2e;
    align-self: flex-start;
    border-bottom-left-radius: 6px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
    border: 1px solid #e8ecf1;
}

/* Rendered markdown inside assistant messages */
.vifm-chat-msg-assistant p {
    margin: 0 0 6px 0;
}

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

.vifm-chat-msg-assistant br {
    display: block;
    content: "";
    margin-top: 2px;
}

.vifm-chat-msg-assistant strong {
    font-weight: 600;
    color: #1a3c6e;
}

.vifm-chat-msg-assistant em {
    font-style: italic;
}

.vifm-chat-msg-assistant code {
    background: #f0f2f5;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 13px;
    font-family: monospace;
}

.vifm-chat-msg-assistant a {
    color: #2a5da8;
    text-decoration: none;
    border-bottom: 1px solid rgba(42, 93, 168, 0.3);
    transition: border-color 0.15s, color 0.15s;
}

.vifm-chat-msg-assistant a:hover {
    color: #1a3c6e;
    border-bottom-color: #1a3c6e;
}

.vifm-chat-msg-assistant ul {
    margin: 6px 0 8px 0;
    padding-left: 0;
    list-style: none;
}

.vifm-chat-msg-assistant ul li {
    position: relative;
    padding-left: 18px;
    margin-bottom: 4px;
}

.vifm-chat-msg-assistant ul li::before {
    content: "";
    position: absolute;
    left: 4px;
    top: 8px;
    width: 6px;
    height: 6px;
    background: #2a5da8;
    border-radius: 50%;
}

.vifm-chat-msg-assistant h4,
.vifm-chat-msg-assistant h5,
.vifm-chat-msg-assistant h6 {
    margin: 8px 0 4px 0;
    font-weight: 600;
    color: #1a3c6e;
    line-height: 1.3;
}

.vifm-chat-msg-assistant h4 {
    font-size: 15px;
}

.vifm-chat-msg-assistant h5 {
    font-size: 14px;
}

.vifm-chat-msg-assistant h6 {
    font-size: 13px;
}

/* Numbered list support (from markdown 1. 2. 3.) */
.vifm-chat-msg-assistant ol {
    margin: 6px 0 8px 0;
    padding-left: 22px;
    counter-reset: none;
}

.vifm-chat-msg-assistant ol li {
    margin-bottom: 4px;
}

/* Typing Indicator */
.vifm-chat-typing {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 12px 16px;
    background: #fff;
    border: 1px solid #e8ecf1;
    border-radius: 18px;
    border-bottom-left-radius: 6px;
    align-self: flex-start;
    max-width: 70px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
    animation: vifmMsgFadeIn 0.25s ease-out;
}

.vifm-chat-typing span {
    width: 7px;
    height: 7px;
    background: #2a5da8;
    border-radius: 50%;
    animation: vifmTypingBounce 1.2s infinite ease-in-out;
}

.vifm-chat-typing span:nth-child(2) {
    animation-delay: 0.2s;
}

.vifm-chat-typing span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes vifmTypingBounce {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.3;
    }
    30% {
        transform: translateY(-6px);
        opacity: 1;
    }
}

/* Footer / Input */
.vifm-chat-footer {
    padding: 14px 16px;
    border-top: 1px solid #e8ecf1;
    display: flex;
    align-items: center;
    gap: 10px;
    background: #fff;
    flex-shrink: 0;
}

.vifm-chat-input {
    flex: 1;
    border: 1.5px solid #d1d5db;
    border-radius: 24px;
    padding: 10px 18px;
    font-size: 14px;
    outline: none;
    resize: none;
    font-family: inherit;
    line-height: 1.4;
    max-height: 80px;
    transition: border-color 0.2s, box-shadow 0.2s;
    background: #f9fafb;
}

.vifm-chat-input:focus {
    border-color: #2a5da8;
    box-shadow: 0 0 0 3px rgba(42, 93, 168, 0.1);
    background: #fff;
}

.vifm-chat-input::placeholder {
    color: #9ca3af;
}

.vifm-chat-send {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: linear-gradient(135deg, #1a3c6e 0%, #2a5da8 100%);
    color: #fff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: opacity 0.15s, transform 0.15s;
}

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

.vifm-chat-send:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none;
}

.vifm-chat-send svg {
    width: 18px;
    height: 18px;
    fill: currentColor;
}

/* ==========================================================================
   Inline Contact Form
   ========================================================================== */

.vifm-chat-form {
    align-self: flex-start;
    max-width: 92%;
    background: #fff;
    border: 1.5px solid #2a5da8;
    border-radius: 18px;
    padding: 18px 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    animation: vifmMsgFadeIn 0.3s ease-out;
    box-shadow: 0 2px 12px rgba(42, 93, 168, 0.1);
}

.vifm-chat-form-title {
    font-size: 14px;
    font-weight: 600;
    color: #1a3c6e;
    margin-bottom: 2px;
}

.vifm-form-input {
    border: 1.5px solid #d1d5db;
    border-radius: 10px;
    padding: 9px 14px;
    font-size: 13px;
    font-family: inherit;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
    background: #f9fafb;
    width: 100%;
    box-sizing: border-box;
}

.vifm-form-input:focus {
    border-color: #2a5da8;
    box-shadow: 0 0 0 2px rgba(42, 93, 168, 0.1);
    background: #fff;
}

.vifm-form-textarea {
    resize: vertical;
    min-height: 50px;
    max-height: 100px;
}

.vifm-form-submit {
    background: linear-gradient(135deg, #1a3c6e 0%, #2a5da8 100%);
    color: #fff;
    border: none;
    border-radius: 10px;
    padding: 10px 20px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.15s, transform 0.15s;
    font-family: inherit;
}

.vifm-form-submit:hover {
    transform: scale(1.02);
}

.vifm-form-submit:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.vifm-form-status {
    font-size: 12px;
    min-height: 16px;
}

.vifm-form-success {
    text-align: center;
    padding: 12px 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.vifm-form-success p {
    margin: 0;
    font-size: 14px;
    font-weight: 500;
    color: #1a5a2a;
}

/* RTL form support */
[dir="rtl"] .vifm-chat-form,
html[lang="ar"] .vifm-chat-form {
    align-self: flex-end;
}

[dir="rtl"] .vifm-form-input,
html[lang="ar"] .vifm-form-input {
    text-align: right;
    direction: rtl;
}

/* ==========================================================================
   RTL Support
   ========================================================================== */

[dir="rtl"] .vifm-chat-toggle,
html[lang="ar"] .vifm-chat-toggle {
    left: auto;
    right: auto;
    left: 24px;
}

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

[dir="rtl"] .vifm-chat-msg-user,
html[lang="ar"] .vifm-chat-msg-user {
    align-self: flex-start;
    border-bottom-right-radius: 18px;
    border-bottom-left-radius: 6px;
}

[dir="rtl"] .vifm-chat-msg-assistant,
html[lang="ar"] .vifm-chat-msg-assistant {
    align-self: flex-end;
    border-bottom-left-radius: 18px;
    border-bottom-right-radius: 6px;
}

[dir="rtl"] .vifm-chat-input,
html[lang="ar"] .vifm-chat-input {
    text-align: right;
    direction: rtl;
}

[dir="rtl"] .vifm-chat-send svg,
html[lang="ar"] .vifm-chat-send svg {
    transform: scaleX(-1);
}

[dir="rtl"] .vifm-chat-msg-assistant ul li,
html[lang="ar"] .vifm-chat-msg-assistant ul li {
    padding-left: 0;
    padding-right: 18px;
}

[dir="rtl"] .vifm-chat-msg-assistant ul li::before,
html[lang="ar"] .vifm-chat-msg-assistant ul li::before {
    left: auto;
    right: 4px;
}

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

@media (max-width: 600px) {
    .vifm-chat-panel {
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        height: 80vh;
        border-radius: 20px 20px 0 0;
    }

    .vifm-chat-panel.vifm-chat-open {
        transform: translateY(0) scale(1);
    }

    .vifm-chat-toggle {
        bottom: 16px;
        left: 16px;
        width: 54px;
        height: 54px;
    }

    .vifm-chat-msg {
        max-width: 92%;
    }

    [dir="rtl"] .vifm-chat-panel,
    html[lang="ar"] .vifm-chat-panel {
        left: 0;
        right: 0;
    }
}
