/**
 * CRM Online Chat Widget Styles (Two-Way Messenger UI)
 * Clean, self-contained, minimal RTL styles.
 */

.crm-chat-wrapper {
    position: fixed;
    bottom: 20px;
    z-index: 999999;
    direction: rtl;
    font-family: inherit;
    box-sizing: border-box;
}

.crm-chat-wrapper *,
.crm-chat-wrapper *::before,
.crm-chat-wrapper *::after {
    box-sizing: border-box;
}

.crm-chat-pos-right {
    right: 20px;
}

.crm-chat-pos-left {
    left: 20px;
}

.crm-chat-toggle {
    position: relative;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: #2563eb;
    color: #ffffff;
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(37, 99, 235, 0.35);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s ease, background 0.2s ease;
    padding: 0;
}

.crm-chat-toggle:hover {
    background: #1d4ed8;
    transform: scale(1.05);
}

.crm-chat-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 20px;
    height: 20px;
    padding: 0 5px;
    border-radius: 999px;
    background: #ef4444;
    color: #ffffff;
    font-size: 11px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid #ffffff;
}

.crm-chat-panel {
    position: absolute;
    bottom: 70px;
    width: 340px;
    max-width: calc(100vw - 40px);
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 14px;
    box-shadow: 0 12px 32px rgba(15, 23, 42, 0.18);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.crm-chat-pos-right .crm-chat-panel {
    right: 0;
}

.crm-chat-pos-left .crm-chat-panel {
    left: 0;
}

.crm-chat-header {
    background: linear-gradient(135deg, #2563eb, #1d4ed8);
    color: #ffffff;
    padding: 12px 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

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

.crm-chat-online-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #4ade80;
    box-shadow: 0 0 0 3px rgba(74, 222, 128, 0.25);
}

.crm-chat-title {
    font-size: 14px;
    font-weight: 700;
}

.crm-chat-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.crm-chat-edit-user {
    background: rgba(255, 255, 255, 0.18);
    border: none;
    color: #ffffff;
    font-size: 11px;
    padding: 3px 8px;
    border-radius: 6px;
    cursor: pointer;
    font-family: inherit;
}

.crm-chat-edit-user:hover {
    background: rgba(255, 255, 255, 0.28);
}

.crm-chat-close {
    background: transparent;
    border: none;
    color: #ffffff;
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    padding: 0 4px;
    opacity: 0.85;
}

.crm-chat-close:hover {
    opacity: 1;
}

.crm-chat-body {
    margin: 0;
    display: flex;
    flex-direction: column;
    height: 410px;
    max-height: 72vh;
    background: #f8fafc;
}

.crm-chat-fields {
    padding: 10px 12px;
    background: #ffffff;
    display: flex;
    flex-direction: column;
    gap: 7px;
    border-bottom: 1px solid #e2e8f0;
}

.crm-chat-field input {
    width: 100%;
    padding: 7px 10px;
    border: 1px solid #cbd5e1;
    border-radius: 7px;
    font-size: 12.5px;
    font-family: inherit;
    color: #1e293b;
    background: #ffffff;
    outline: none;
    transition: border-color 0.15s ease;
}

.crm-chat-field input[dir="ltr"] {
    text-align: right;
}

.crm-chat-field input:focus {
    border-color: #2563eb;
}

.crm-chat-save-fields {
    width: 100%;
    padding: 7px 10px;
    background: #2563eb;
    color: #ffffff;
    border: none;
    border-radius: 7px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    transition: background-color 0.15s ease;
    text-align: center;
}

.crm-chat-save-fields:hover {
    background: #1d4ed8;
}

.crm-chat-save-fields:active {
    background: #1e40af;
}

.crm-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    background: #f1f5f9;
}

.crm-chat-welcome {
    align-self: center;
    background: #e2e8f0;
    color: #475569;
    font-size: 11.5px;
    padding: 6px 10px;
    border-radius: 8px;
    text-align: center;
    line-height: 1.5;
    margin-bottom: 4px;
}

.crm-chat-bubble-wrap {
    display: flex;
    flex-direction: column;
    max-width: 82%;
}

.crm-chat-bubble-wrap.is-customer {
    align-self: flex-start;
}

.crm-chat-bubble-wrap.is-agent {
    align-self: flex-end;
}

.crm-chat-msg {
    padding: 8px 12px;
    border-radius: 12px;
    font-size: 12.5px;
    line-height: 1.55;
    word-break: break-word;
    white-space: pre-wrap;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.crm-chat-bubble-wrap.is-customer .crm-chat-msg {
    background: #2563eb;
    color: #ffffff;
    border-top-right-radius: 3px;
}

.crm-chat-bubble-wrap.is-agent .crm-chat-msg {
    background: #ffffff;
    color: #1e293b;
    border: 1px solid #cbd5e1;
    border-top-left-radius: 3px;
}

.crm-chat-msg-meta {
    font-size: 10px;
    color: #64748b;
    margin-top: 2px;
    padding: 0 4px;
    display: flex;
    align-items: center;
    gap: 4px;
}

.crm-chat-bubble-wrap.is-agent .crm-chat-msg-meta {
    justify-content: flex-end;
}

.crm-chat-feedback {
    font-size: 11.5px;
    padding: 6px 10px;
    margin: 0 10px 6px;
    border-radius: 6px;
}

.crm-chat-feedback.is-error {
    background: #fef2f2;
    color: #dc2626;
    border: 1px solid #fecaca;
}

.crm-chat-feedback.is-success {
    background: #f0fdf4;
    color: #16a34a;
    border: 1px solid #bbf7d0;
}

.crm-chat-composer {
    padding: 9px 10px;
    background: #ffffff;
    border-top: 1px solid #e2e8f0;
    display: flex;
    align-items: flex-end;
    gap: 6px;
}

.crm-chat-composer textarea {
    flex: 1;
    resize: none;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    padding: 8px 10px;
    font-size: 12.5px;
    font-family: inherit;
    color: #1e293b;
    max-height: 85px;
    outline: none;
}

.crm-chat-composer textarea:focus {
    border-color: #2563eb;
}

.crm-chat-submit {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    background: #2563eb;
    color: #ffffff;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    transition: background 0.15s ease;
    padding: 0;
}

.crm-chat-submit:hover {
    background: #1d4ed8;
}

.crm-chat-submit:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}
