/* ============================================
   iFrameMX AI Chat - Frontend Chat Styles
   ============================================ */

/* CSS Variables */
.ifmx-chat-right,
.ifmx-chat-left {
    --ifmx-font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-family: var(--ifmx-font);
    z-index: 999999;
    position: fixed;
    bottom: 20px;
}

.ifmx-chat-right { right: 20px; }
.ifmx-chat-left  { left: 20px; }

/* Floating Button */
.ifmx-chat-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--ifmx-primary, #0066cc);
    color: #fff;
    border: none;
    border-radius: 50px;
    padding: 12px 24px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(0,0,0,0.25);
    transition: transform 0.2s, box-shadow 0.2s;
    z-index: 999999;
}

.ifmx-chat-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 28px rgba(0,0,0,0.35);
}

.ifmx-chat-btn:active {
    transform: scale(0.97);
}

.ifmx-btn-content {
    display: flex;
    align-items: center;
    gap: 8px;
}

.ifmx-btn-icon {
    font-size: 22px;
    line-height: 1;
}

.ifmx-btn-icon-img {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
}

.ifmx-btn-text {
    white-space: nowrap;
}

/* Chat Container */
.ifmx-chat-container {
    position: fixed;
    bottom: 90px;
    width: 380px;
    max-width: calc(100vw - 40px);
    max-height: 600px;
    height: 550px;
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 8px 40px rgba(0,0,0,0.2);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: ifmx-slide-up 0.3s ease-out;
    font-family: var(--ifmx-font);
}

.ifmx-chat-right .ifmx-chat-container { right: 0; }
.ifmx-chat-left  .ifmx-chat-container { left: 0; }

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

/* Header */
.ifmx-chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px;
    background: var(--ifmx-primary, #0066cc);
    color: #fff;
    flex-shrink: 0;
}

.ifmx-header-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.ifmx-header-avatar {
    font-size: 28px;
    line-height: 1;
}

.ifmx-header-title {
    font-weight: 700;
    font-size: 15px;
}

.ifmx-header-sub {
    font-size: 12px;
    opacity: 0.85;
    display: flex;
    align-items: center;
    gap: 4px;
}

.ifmx-header-sub::before {
    content: '';
    display: inline-block;
    width: 7px;
    height: 7px;
    background: #4cff4c;
    border-radius: 50%;
}

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

.ifmx-chat-close:hover { background: rgba(255,255,255,0.35); }

/* Body */
.ifmx-chat-body {
    flex: 1;
    overflow-y: auto;
    background: #f7f8fa;
}

/* Lead Form */
.ifmx-lead-form {
    padding: 24px 20px;
}

.ifmx-form-header {
    text-align: center;
    margin-bottom: 20px;
}

.ifmx-form-icon {
    font-size: 40px;
    display: block;
    margin-bottom: 8px;
}

.ifmx-form-header h3 {
    margin: 0 0 6px;
    font-size: 17px;
    color: #1a1a2e;
}

.ifmx-form-header p {
    margin: 0;
    font-size: 13px;
    color: #666;
}

.ifmx-field {
    margin-bottom: 14px;
}

.ifmx-field label {
    display: block;
    margin-bottom: 4px;
    font-size: 13px;
    font-weight: 600;
    color: #333;
}

.ifmx-field input {
    width: 100%;
    padding: 10px 14px;
    border: 2px solid #e0e0e0;
    border-radius: 10px;
    font-size: 14px;
    font-family: var(--ifmx-font);
    transition: border-color 0.2s;
    box-sizing: border-box;
}

.ifmx-field input:focus {
    outline: none;
    border-color: var(--ifmx-primary, #0066cc);
    box-shadow: 0 0 0 3px rgba(0,102,204,0.1);
}

.ifmx-btn-submit {
    width: 100%;
    padding: 12px;
    background: var(--ifmx-primary, #0066cc);
    color: #fff;
    border: none;
    border-radius: 10px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
    margin-top: 8px;
}

.ifmx-btn-submit:hover { opacity: 0.9; }
.ifmx-btn-submit:active { transform: scale(0.98); }
.ifmx-btn-submit:disabled { opacity: 0.5; cursor: not-allowed; }

/* Chat Messages */
.ifmx-chat-messages {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.ifmx-messages-list {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
}

.ifmx-message {
    margin-bottom: 12px;
    max-width: 85%;
    animation: ifmx-msg-in 0.25s ease-out;
}

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

.ifmx-msg-user {
    margin-left: auto;
}

.ifmx-msg-bubble {
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.45;
    word-wrap: break-word;
}

.ifmx-msg-bot .ifmx-msg-bubble {
    background: #fff;
    color: #333;
    border: 1px solid #e8e8e8;
    border-bottom-left-radius: 4px;
}

.ifmx-msg-user .ifmx-msg-bubble {
    background: var(--ifmx-primary, #0066cc);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.ifmx-msg-time {
    font-size: 10px;
    color: #999;
    margin-top: 3px;
    padding: 0 4px;
}

.ifmx-msg-user .ifmx-msg-time { text-align: right; }

/* Typing indicator */
.ifmx-typing {
    padding: 10px 20px;
    display: flex;
    gap: 5px;
}

.ifmx-typing span {
    width: 8px;
    height: 8px;
    background: #999;
    border-radius: 50%;
    animation: ifmx-bounce 1.4s infinite ease-in-out both;
}

.ifmx-typing span:nth-child(1) { animation-delay: -0.32s; }
.ifmx-typing span:nth-child(2) { animation-delay: -0.16s; }
.ifmx-typing span:nth-child(3) { animation-delay: 0s; }

@keyframes ifmx-bounce {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1); }
}

/* Chat Input */
.ifmx-chat-input {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    background: #fff;
    border-top: 1px solid #e8e8e8;
    flex-shrink: 0;
}

.ifmx-chat-input textarea {
    flex: 1;
    border: 2px solid #e0e0e0;
    border-radius: 12px;
    padding: 10px 14px;
    font-size: 14px;
    font-family: var(--ifmx-font);
    resize: none;
    max-height: 100px;
    transition: border-color 0.2s;
}

.ifmx-chat-input textarea:focus {
    outline: none;
    border-color: var(--ifmx-primary, #0066cc);
}

.ifmx-chat-input button {
    width: 40px;
    height: 40px;
    border: none;
    background: var(--ifmx-primary, #0066cc);
    color: #fff;
    border-radius: 50%;
    font-size: 16px;
    cursor: pointer;
    flex-shrink: 0;
    transition: opacity 0.2s, transform 0.1s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.ifmx-chat-input button:disabled { opacity: 0.4; cursor: not-allowed; }
.ifmx-chat-input button:not(:disabled):hover { opacity: 0.9; }
.ifmx-chat-input button:not(:disabled):active { transform: scale(0.95); }

/* Error state */
.ifmx-error {
    background: #fff0f0;
    color: #c0392b;
    padding: 12px;
    margin: 8px;
    border-radius: 8px;
    font-size: 13px;
    text-align: center;
}

/* Mobile responsive */
@media (max-width: 480px) {
    .ifmx-chat-container {
        width: 100%;
        max-width: 100%;
        height: 100%;
        max-height: 100%;
        bottom: 0;
        border-radius: 0;
        position: fixed;
    }

    .ifmx-chat-right .ifmx-chat-container,
    .ifmx-chat-left .ifmx-chat-container {
        right: 0;
        left: 0;
    }

    .ifmx-chat-btn {
        padding: 14px 20px;
        border-radius: 50px;
    }

    .ifmx-btn-text { display: none; }
}

/* ─── Close Ticket Button ─── */
.ifmx-close-ticket {
    padding: 8px 16px;
    border-top: 1px solid rgba(0,0,0,0.08);
    text-align: center;
}
.ifmx-close-ticket-btn {
    background: #f0f0f0;
    border: 1px solid #ddd;
    border-radius: 8px;
    padding: 8px 20px;
    font-size: 13px;
    cursor: pointer;
    color: #555;
    transition: all 0.2s;
}
.ifmx-close-ticket-btn:hover {
    background: #e8e8e8;
    border-color: #ccc;
    color: #333;
}

/* ─── Bot Avatar in Header ─── */
.ifmx-header-avatar-img {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
}

/* ─── Bot Avatar in Messages ─── */
.ifmx-msg-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    object-fit: cover;
    margin-right: 6px;
    flex-shrink: 0;
    align-self: flex-end;
}
.ifmx-msg-bot {
    display: flex;
    align-items: flex-start;
}

/* ─── Consent Checkbox ─── */
.ifmx-consent-field {
	margin: 12px 0;
	padding: 10px 12px;
	background: #f0f7ff;
	border-radius: 8px;
	border: 1px solid #d0e4f7;
}

.ifmx-consent-label {
	display: flex;
	align-items: flex-start;
	gap: 8px;
	font-size: 12px;
	line-height: 1.4;
	color: #444;
	cursor: pointer;
}

.ifmx-consent-label input[type="checkbox"] {
	width: 16px;
	height: 16px;
	margin-top: 2px;
	flex-shrink: 0;
	cursor: pointer;
}

.ifmx-consent-label span {
	flex: 1;
}

/* ─── Embedded Mode ─── */
.ifmx-chat-embedded .ifmx-chat-container {
    display: flex !important;
    position: static !important;
    width: 100% !important;
    height: 500px !important;
    max-height: 70vh;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.1);
    overflow: hidden;
}
.ifmx-chat-embedded {
    position: relative;
    width: 100%;
    max-width: 420px;
    margin: 0 auto;
}
