/* ============================================
   Chat Widget — BTIS Broker Pricing Portal
   Global CSS — all selectors scoped via #id
   for specificity over framework styles
   ============================================ */

/* --- FAB --- */

#chat-fab-btn {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 60px;
    height: 60px;
    background: linear-gradient(135deg, #076e6c 0%, #1d2951 100%);
    border: none;
    border-radius: 16px;
    color: #fff;
    cursor: pointer;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    box-shadow: 0 4px 20px rgba(7, 110, 108, 0.35), 0 8px 32px rgba(0, 0, 0, 0.15);
    padding: 0;
}
#chat-fab-btn:hover {
    transform: translateY(-3px) scale(1.05);
    box-shadow: 0 6px 28px rgba(7, 110, 108, 0.45), 0 12px 40px rgba(0, 0, 0, 0.2);
}

#chat-fab-badge {
    position: absolute;
    top: -6px;
    right: -6px;
    background: #e53935;
    color: #fff;
    font-family: 'Raleway', sans-serif;
    font-size: 11px;
    font-weight: 700;
    min-width: 22px;
    height: 22px;
    padding: 0 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 11px;
    box-shadow: 0 2px 6px rgba(229, 57, 53, 0.4);
    border: 2px solid #fff;
    line-height: 1;
}

/* --- Widget Container --- */

#chat-panel {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 400px;
    height: 560px;
    background: #fff;
    border: none;
    border-radius: 16px;
    flex-direction: column;
    z-index: 9999;
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.18), 0 2px 12px rgba(7, 110, 108, 0.12);
    animation: chat-slide-up 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    overflow: hidden;
}

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

/* --- Header --- */

#chat-panel .chat-header {
    background: linear-gradient(135deg, #076e6c 0%, #1d2951 100%);
    color: #fff;
    padding: 14px 16px;
    display: flex !important;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
    min-height: 52px;
}

#chat-panel .chat-header-content {
    display: flex !important;
    align-items: center;
    gap: 10px;
    font-family: 'Raleway', sans-serif;
    font-size: 14px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

#chat-panel .chat-header-icon {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    opacity: 0.85;
}

#chat-panel .chat-back-btn,
#chat-panel .chat-close-btn {
    background: rgba(255, 255, 255, 0.12);
    border: none;
    color: #fff;
    cursor: pointer;
    padding: 5px;
    display: flex;
    align-items: center;
    border-radius: 6px;
    transition: background 0.15s;
}
#chat-panel .chat-back-btn:hover,
#chat-panel .chat-close-btn:hover {
    background: rgba(255, 255, 255, 0.22);
}

/* =============================================
   Conversation List — Telegram Style
   ============================================= */

#chat-conv-list {
    flex: 1;
    overflow-y: auto;
    background: #fff;
    flex-direction: column;
}

#chat-conv-list .chat-conv-item {
    width: 100%;
    display: flex !important;
    flex-direction: row !important;
    align-items: center !important;
    gap: 14px;
    padding: 12px 16px;
    background: none;
    border: none;
    border-bottom: 1px solid #f0f0f0;
    cursor: pointer;
    text-align: left;
    font-family: 'Raleway', sans-serif;
    transition: background-color 0.12s;
}

#chat-conv-list .chat-conv-item:hover {
    background: #f8f8f8;
}

#chat-conv-list .chat-conv-item.has-unread {
    background: rgba(7, 110, 108, 0.04);
}
#chat-conv-list .chat-conv-item.has-unread:hover {
    background: rgba(7, 110, 108, 0.08);
}

#chat-conv-list .chat-conv-avatar {
    width: 48px;
    height: 48px;
    min-width: 48px;
    min-height: 48px;
    background: linear-gradient(135deg, #076e6c 0%, #1d2951 100%);
    color: #fff;
    display: flex !important;
    align-items: center;
    justify-content: center;
    font-family: 'Raleway', sans-serif;
    font-size: 18px;
    font-weight: 700;
    flex-shrink: 0;
    border-radius: 50%;
    line-height: 1;
}

#chat-conv-list .chat-conv-body {
    flex: 1;
    min-width: 0;
    display: flex !important;
    flex-direction: column !important;
    gap: 3px;
}

#chat-conv-list .chat-conv-top {
    display: flex !important;
    flex-direction: row !important;
    justify-content: space-between;
    align-items: baseline;
    gap: 8px;
}

#chat-conv-list .chat-conv-name {
    font-size: 14px;
    font-weight: 400;
    color: #2b2b2b;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.3;
}

#chat-conv-list .chat-conv-name.unread {
    font-weight: 700;
    color: #1a1a1a;
}

#chat-conv-list .chat-conv-time {
    font-size: 11px;
    color: #999;
    flex-shrink: 0;
    white-space: nowrap;
}

#chat-conv-list .chat-conv-item.has-unread .chat-conv-time {
    color: #076e6c;
    font-weight: 600;
}

#chat-conv-list .chat-conv-bottom {
    display: flex !important;
    flex-direction: row !important;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
}

#chat-conv-list .chat-conv-preview {
    font-size: 13px;
    color: #999;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
    min-width: 0;
    line-height: 1.3;
}

#chat-conv-list .chat-conv-preview.unread {
    color: #555;
    font-weight: 500;
}

#chat-conv-list .chat-conv-preview em {
    font-style: italic;
    color: #bbb;
}

#chat-conv-list .chat-unread-badge {
    background: #a0ce4e;
    color: #1d2951;
    font-family: 'Raleway', sans-serif;
    font-size: 11px;
    font-weight: 700;
    min-width: 22px;
    height: 22px;
    padding: 0 7px;
    display: flex !important;
    align-items: center;
    justify-content: center;
    border-radius: 11px;
    flex-shrink: 0;
    line-height: 1;
}

/* --- Empty state --- */

#chat-panel .chat-empty {
    flex: 1;
    display: flex !important;
    flex-direction: column !important;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 40px 20px;
    text-align: center;
}

#chat-panel .chat-empty-icon {
    color: #ccc;
}

#chat-panel .chat-empty p {
    font-family: 'Raleway', sans-serif;
    font-size: 13px;
    color: #999;
    margin: 0;
    background: none !important;
    border: none !important;
    padding: 0 !important;
    border-radius: 0 !important;
    box-shadow: none !important;
}

/* =============================================
   Messages Area
   ============================================= */

#chat-body {
    flex: 1;
    overflow-y: auto;
    padding: 14px 16px;
    flex-direction: column;
    gap: 6px;
    background: #f0f2f5;
}

/* --- Message Bubbles --- */

#chat-body .chat-msg {
    display: flex !important;
    align-items: flex-end;
    gap: 8px;
    max-width: 82%;
    margin-bottom: 4px;
}

#chat-body .chat-msg.own {
    align-self: flex-end;
    flex-direction: row-reverse;
    margin-left: auto;
}

#chat-body .chat-msg.other {
    align-self: flex-start;
    margin-right: auto;
}

#chat-body .chat-msg-avatar {
    width: 30px;
    height: 30px;
    min-width: 30px;
    min-height: 30px;
    color: #fff;
    display: flex !important;
    align-items: center;
    justify-content: center;
    font-family: 'Raleway', sans-serif;
    font-size: 11px;
    font-weight: 700;
    flex-shrink: 0;
    border-radius: 50%;
    margin-bottom: 18px;
    background: linear-gradient(135deg, #1d2951 0%, #076e6c 100%);
    line-height: 1;
}

#chat-body .chat-msg-avatar.own-avatar {
    background: linear-gradient(135deg, #076e6c 0%, #0a8b89 100%);
}

#chat-body .chat-msg-bubble {
    display: flex !important;
    flex-direction: column !important;
    gap: 1px;
    max-width: 100%;
}

#chat-body .chat-msg-sender {
    font-family: 'Raleway', sans-serif;
    font-size: 11px;
    font-weight: 700;
    padding: 0 4px;
    margin-bottom: 1px;
    display: block;
}

#chat-body .chat-msg.other .chat-msg-sender {
    color: #076e6c;
}

#chat-body .chat-msg.own .chat-msg-sender {
    color: #999;
    text-align: right;
}

#chat-body .chat-msg-bubble p {
    margin: 0 !important;
    padding: 9px 12px !important;
    font-family: 'Raleway', sans-serif;
    font-size: 13px;
    line-height: 1.45;
    word-break: break-word;
    border-radius: 14px;
    display: inline-block;
}

#chat-body .chat-msg.own .chat-msg-bubble p {
    background: linear-gradient(135deg, #076e6c 0%, #1d2951 100%) !important;
    color: #fff !important;
    border-bottom-right-radius: 4px;
    border: none !important;
    box-shadow: none !important;
}

#chat-body .chat-msg.other .chat-msg-bubble p {
    background: #fff !important;
    color: #2b2b2b !important;
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
    border: none !important;
}

#chat-body .chat-msg-time {
    font-family: 'Raleway', sans-serif;
    font-size: 10px;
    color: #bbb;
    padding: 2px 4px 0;
    display: block;
}

#chat-body .chat-msg.own .chat-msg-time {
    text-align: right;
}

/* =============================================
   Input Area
   ============================================= */

#chat-input-area {
    flex-shrink: 0;
    border-top: 1px solid #eee;
    background: #fff;
    padding: 10px 12px;
}

#chat-input-area .chat-input-row {
    display: flex !important;
    flex-direction: row !important;
    align-items: center;
    gap: 8px;
    background: #f0f2f5;
    border: 1px solid transparent;
    border-radius: 22px;
    padding: 4px 4px 4px 16px;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

#chat-input-area .chat-input-row:focus-within {
    border-color: #076e6c;
    box-shadow: 0 0 0 2px rgba(7, 110, 108, 0.1);
    background: #fff;
}

#chat-input-area .chat-text-input {
    flex: 1;
    border: none;
    outline: none;
    background: transparent;
    font-family: 'Raleway', sans-serif;
    font-size: 13px;
    color: #2b2b2b;
    padding: 8px 0;
    height: 36px;
    min-width: 0;
}

#chat-input-area .chat-text-input::placeholder {
    color: #aaa;
}

#chat-input-area .chat-send-btn {
    width: 36px;
    height: 36px;
    min-width: 36px;
    background: linear-gradient(135deg, #076e6c 0%, #1d2951 100%);
    border: none;
    border-radius: 50%;
    color: #fff;
    cursor: pointer;
    display: flex !important;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    padding: 0;
    transition: transform 0.15s;
}
#chat-input-area .chat-send-btn:hover {
    transform: scale(1.08);
}

/* =============================================
   Connecting State
   ============================================= */

#chat-connecting {
    flex: 1;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 14px;
    padding: 40px 20px;
}

#chat-connecting .chat-spinner {
    width: 28px;
    height: 28px;
    border: 3px solid #eee;
    border-top-color: #076e6c;
    border-radius: 50%;
    animation: chat-spin 0.7s linear infinite;
}

@keyframes chat-spin {
    to { transform: rotate(360deg); }
}

#chat-connecting p {
    font-family: 'Raleway', sans-serif;
    font-size: 13px;
    color: #999;
    margin: 0;
}

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

@media (max-width: 768px) {
    #chat-panel {
        bottom: 0;
        right: 0;
        width: 100%;
        height: 100%;
        border-radius: 0;
        box-shadow: none;
    }
    #chat-fab-btn {
        bottom: 16px;
        right: 16px;
    }
}

/* =============================================
   Scrollbars
   ============================================= */

#chat-body::-webkit-scrollbar,
#chat-conv-list::-webkit-scrollbar {
    width: 5px;
}

#chat-body::-webkit-scrollbar-track,
#chat-conv-list::-webkit-scrollbar-track {
    background: transparent;
}

#chat-body::-webkit-scrollbar-thumb,
#chat-conv-list::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 3px;
}

#chat-body::-webkit-scrollbar-thumb:hover,
#chat-conv-list::-webkit-scrollbar-thumb:hover {
    background: #aaa;
}
