/* =========================================
   CRM Chat Widget Styles
   All classes prefixed with crm-chat- to
   avoid conflicts with VTiger/host page CSS
   ========================================= */

/* Reset for widget container */
#crm-chat-container,
#crm-chat-container * {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    font-size: 14px;
    line-height: 1.5;
}

/* ---- Bubble Button ---- */
.crm-chat-bubble {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: #4A6CF7;
    color: #fff;
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(74, 108, 247, 0.4);
    z-index: 99999;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.crm-chat-bubble:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 24px rgba(74, 108, 247, 0.5);
}

.crm-chat-bubble svg {
    width: 28px;
    height: 28px;
    fill: currentColor;
}

.crm-chat-bubble--close svg {
    width: 22px;
    height: 22px;
}

/* ---- Chat Panel ---- */
.crm-chat-panel {
    position: fixed;
    bottom: 96px;
    right: 24px;
    width: 400px;
    height: 560px;
    max-height: calc(100vh - 120px);
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.15);
    z-index: 99998;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    pointer-events: none;
    transition: opacity 0.25s ease, transform 0.25s ease;
}

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

/* ---- Header ---- */
.crm-chat-header {
    background: #4A6CF7;
    color: #fff;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.crm-chat-header-title {
    font-size: 16px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
}

.crm-chat-header-title svg {
    width: 20px;
    height: 20px;
    fill: currentColor;
    opacity: 0.9;
}

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

.crm-chat-header-btn {
    background: rgba(255, 255, 255, 0.15);
    border: none;
    color: #fff;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
}

.crm-chat-header-btn:hover {
    background: rgba(255, 255, 255, 0.25);
}

.crm-chat-header-btn svg {
    width: 16px;
    height: 16px;
    fill: currentColor;
}

/* ---- Messages Area ---- */
.crm-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: #f7f8fc;
}

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

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

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

/* ---- Message Bubbles ---- */
.crm-chat-msg {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 12px;
    word-wrap: break-word;
    white-space: pre-wrap;
}

.crm-chat-msg--user {
    align-self: flex-end;
    background: #4A6CF7;
    color: #fff;
    border-bottom-right-radius: 4px;
}

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

/* ---- Welcome Message ---- */
.crm-chat-welcome {
    text-align: center;
    color: #6b7280;
    padding: 32px 20px;
    font-size: 13px;
}

.crm-chat-welcome-icon {
    font-size: 40px;
    margin-bottom: 12px;
    display: block;
}

.crm-chat-welcome strong {
    display: block;
    font-size: 16px;
    color: #1a1a2e;
    margin-bottom: 8px;
}

/* ---- Data Table ---- */
.crm-chat-table-wrap {
    align-self: flex-start;
    max-width: 100%;
    overflow-x: auto;
    margin: 4px 0;
    border-radius: 8px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
}

.crm-chat-table {
    border-collapse: collapse;
    font-size: 12px;
    width: 100%;
    min-width: 280px;
    background: #fff;
}

.crm-chat-table th {
    background: #f0f2f8;
    color: #374151;
    font-weight: 600;
    padding: 8px 12px;
    text-align: left;
    white-space: nowrap;
    border-bottom: 2px solid #e5e7eb;
    position: sticky;
    top: 0;
}

.crm-chat-table td {
    padding: 6px 12px;
    border-bottom: 1px solid #f0f2f8;
    white-space: nowrap;
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.crm-chat-table tr:hover td {
    background: #f7f8fc;
}

.crm-chat-table-info {
    font-size: 11px;
    color: #9ca3af;
    padding: 6px 12px;
    text-align: right;
    background: #fafbfd;
    border-top: 1px solid #f0f2f8;
}

/* ---- Loading Animation ---- */
.crm-chat-loading {
    align-self: flex-start;
    display: flex;
    gap: 4px;
    padding: 12px 18px;
    background: #fff;
    border-radius: 12px;
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
}

.crm-chat-loading-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #4A6CF7;
    animation: crm-chat-bounce 1.4s ease-in-out infinite both;
}

.crm-chat-loading-dot:nth-child(1) { animation-delay: -0.32s; }
.crm-chat-loading-dot:nth-child(2) { animation-delay: -0.16s; }
.crm-chat-loading-dot:nth-child(3) { animation-delay: 0s; }

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

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

.crm-chat-input {
    flex: 1;
    border: 1.5px solid #e5e7eb;
    border-radius: 10px;
    padding: 10px 14px;
    font-size: 14px;
    resize: none;
    outline: none;
    transition: border-color 0.15s;
    max-height: 100px;
    min-height: 40px;
    font-family: inherit;
}

.crm-chat-input:focus {
    border-color: #4A6CF7;
}

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

.crm-chat-send {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background: #4A6CF7;
    color: #fff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
    flex-shrink: 0;
    align-self: flex-end;
}

.crm-chat-send:hover {
    background: #3b5de7;
}

.crm-chat-send:disabled {
    background: #c7d0e8;
    cursor: not-allowed;
}

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

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

    .crm-chat-bubble {
        bottom: 16px;
        right: 16px;
        width: 52px;
        height: 52px;
    }
}

/* ---- Dark mode (optional, follows system preference) ---- */
@media (prefers-color-scheme: dark) {
    .crm-chat-panel {
        background: #1e1e2e;
    }

    .crm-chat-messages {
        background: #16161e;
    }

    .crm-chat-msg--bot {
        background: #2a2a3e;
        color: #e0e0f0;
    }

    .crm-chat-input-area {
        background: #1e1e2e;
        border-color: #2a2a3e;
    }

    .crm-chat-input {
        background: #2a2a3e;
        color: #e0e0f0;
        border-color: #3a3a4e;
    }

    .crm-chat-table th {
        background: #2a2a3e;
        color: #c0c0d0;
    }

    .crm-chat-table td {
        border-color: #2a2a3e;
        color: #d0d0e0;
    }

    .crm-chat-table tr:hover td {
        background: #222233;
    }

    .crm-chat-welcome {
        color: #8888aa;
    }

    .crm-chat-welcome strong {
        color: #d0d0e0;
    }

    .crm-chat-table-wrap {
        box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
    }

    .crm-chat-table {
        background: #1e1e2e;
    }

    .crm-chat-table-info {
        background: #1a1a2a;
        border-color: #2a2a3e;
        color: #6666aa;
    }
}
