/* ==========================================================================
   FreeJankari.com — Facebook-Style Floating Messenger Popup Stylesheet
   Target: CodeIgniter 4.5.7 / Bootstrap 5.3
   Desktop: Fixed bottom-right (bottom: 20px; right: 20px; width: 580px; height: 540px)
   Tablet: Compact responsive popup
   Mobile: Near-full-screen / full-screen responsive Messenger
   ========================================================================== */

.fj-floating-messenger {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 580px;
    height: 540px;
    max-width: calc(100vw - 24px);
    max-height: calc(100vh - 88px);
    background: #ffffff;
    border: 1px solid rgba(226, 232, 240, 0.95);
    border-radius: 16px;
    box-shadow: 0 18px 48px rgba(15, 23, 42, 0.22), 0 4px 14px rgba(29, 78, 216, 0.10);
    z-index: 1060;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: translateY(18px) scale(0.97);
    transform-origin: bottom right;
    transition: opacity 0.22s cubic-bezier(0.16, 1, 0.3, 1),
                transform 0.22s cubic-bezier(0.16, 1, 0.3, 1),
                width 0.24s cubic-bezier(0.16, 1, 0.3, 1),
                height 0.24s cubic-bezier(0.16, 1, 0.3, 1),
                visibility 0.22s;
}

.fj-floating-messenger.is-open {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: translateY(0) scale(1);
}

/* Expanded state on Desktop */
.fj-floating-messenger.is-open.is-expanded {
    width: 780px;
    height: 640px;
    max-width: calc(100vw - 32px);
    max-height: calc(100vh - 80px);
}

/* Minimized state (preserves selected conversation) */
.fj-floating-messenger.is-open.is-minimized {
    width: 330px;
    height: 54px;
    border-radius: 27px;
    overflow: hidden;
}

.fj-floating-messenger.is-minimized .fj-msg-body {
    display: none !important;
}

/* Top Blue Header */
.fj-msg-header {
    background: linear-gradient(135deg, #1e3a8a 0%, #1d4ed8 60%, #2563eb 100%);
    color: #ffffff;
    padding: 10px 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    flex-shrink: 0;
    user-select: none;
    cursor: pointer;
    min-height: 54px;
}

.fj-msg-header-brand {
    display: flex;
    align-items: center;
    gap: 9px;
    min-width: 0;
}

.fj-msg-header-logo {
    width: 32px;
    height: 32px;
    border-radius: 9px;
    object-fit: cover;
    background: #ffffff;
    padding: 2px;
    border: 1px solid rgba(255, 255, 255, 0.4);
    flex-shrink: 0;
}

.fj-msg-header-title-wrap {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.fj-msg-header-title {
    font-size: 0.92rem;
    font-weight: 700;
    line-height: 1.2;
    color: #ffffff;
    display: flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
}

.fj-msg-conn-status {
    font-size: 0.70rem;
    color: rgba(255, 255, 255, 0.88);
    display: inline-flex;
    align-items: center;
    gap: 5px;
    line-height: 1.1;
}

.fj-msg-conn-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #22c55e;
    box-shadow: 0 0 0 2px rgba(34, 197, 94, 0.28);
    display: inline-block;
}

.fj-msg-conn-dot.is-offline {
    background: #f59e0b;
    box-shadow: 0 0 0 2px rgba(245, 158, 11, 0.28);
}

.fj-msg-header-controls {
    display: flex;
    align-items: center;
    gap: 5px;
    flex-shrink: 0;
}

.fj-msg-ctrl-btn {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    border: none;
    background: rgba(255, 255, 255, 0.14);
    color: #ffffff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.80rem;
    transition: background 0.16s ease, transform 0.16s ease;
    cursor: pointer;
}

.fj-msg-ctrl-btn:hover,
.fj-msg-ctrl-btn:focus-visible {
    background: rgba(255, 255, 255, 0.28);
    transform: translateY(-1px);
    outline: none;
}

/* Two-Column Body */
.fj-msg-body {
    display: flex;
    flex: 1;
    min-height: 0;
    background: #ffffff;
    position: relative;
}

/* Left Column: Conversations List */
.fj-msg-left {
    width: 225px;
    min-width: 215px;
    max-width: 245px;
    border-right: 1px solid #e2e8f0;
    display: flex;
    flex-direction: column;
    background: #f8fafc;
    min-height: 0;
}

.fj-floating-messenger.is-expanded .fj-msg-left {
    width: 270px;
    max-width: 270px;
}

.fj-msg-search-box {
    padding: 9px 10px 6px;
    background: #ffffff;
}

.fj-msg-search-input-wrap {
    position: relative;
    display: flex;
    align-items: center;
}

.fj-msg-search-input-wrap i.fa-magnifying-glass {
    position: absolute;
    left: 10px;
    color: #64748b;
    font-size: 0.76rem;
    pointer-events: none;
}

.fj-msg-search-input {
    width: 100%;
    border: 1px solid #e2e8f0;
    background: #f1f5f9;
    border-radius: 999px;
    padding: 5px 26px 5px 28px;
    font-size: 0.78rem;
    color: #0f172a;
    transition: border-color 0.15s, background 0.15s;
}

.fj-msg-search-input:focus {
    background: #ffffff;
    border-color: #2563eb;
    outline: none;
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.12);
}

.fj-msg-filter-bar {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px 8px;
    background: #ffffff;
    border-bottom: 1px solid #e2e8f0;
    overflow-x: auto;
    scrollbar-width: none;
}

.fj-msg-filter-bar::-webkit-scrollbar {
    display: none;
}

.fj-msg-filter-pill {
    border: 1px solid #e2e8f0;
    background: #f8fafc;
    color: #475569;
    border-radius: 999px;
    padding: 3px 8px;
    font-size: 0.70rem;
    font-weight: 600;
    white-space: nowrap;
    cursor: pointer;
    transition: all 0.15s ease;
}

.fj-msg-filter-pill:hover {
    background: #eff6ff;
    color: #1d4ed8;
    border-color: #bfdbfe;
}

.fj-msg-filter-pill.active {
    background: #1d4ed8;
    color: #ffffff;
    border-color: #1d4ed8;
}

.fj-msg-conv-list {
    flex: 1;
    overflow-y: auto;
    padding: 6px;
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.fj-msg-conv-item {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 8px 9px;
    border-radius: 11px;
    cursor: pointer;
    transition: background 0.14s ease;
    text-decoration: none;
    color: inherit;
    border: 1px solid transparent;
}

.fj-msg-conv-item:hover {
    background: #eef2ff;
}

.fj-msg-conv-item.active {
    background: #eff6ff;
    border-color: #bfdbfe;
}

.fj-msg-avatar-wrap {
    position: relative;
    flex-shrink: 0;
}

.fj-msg-avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    object-fit: cover;
    border: 1px solid #cbd5e1;
    background: #ffffff;
}

.fj-msg-online-dot {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #22c55e;
    border: 2px solid #ffffff;
}

.fj-msg-online-dot.is-offline {
    background: #94a3b8;
}

.fj-msg-conv-meta {
    flex: 1;
    min-width: 0;
}

.fj-msg-conv-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 4px;
    margin-bottom: 2px;
}

.fj-msg-conv-name {
    font-size: 0.80rem;
    font-weight: 700;
    color: #0f172a;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.fj-msg-conv-time {
    font-size: 0.66rem;
    color: #64748b;
    flex-shrink: 0;
}

.fj-msg-conv-bottom {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 4px;
}

.fj-msg-conv-preview {
    font-size: 0.73rem;
    color: #64748b;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.fj-msg-conv-item.has-unread .fj-msg-conv-preview {
    color: #0f172a;
    font-weight: 600;
}

.fj-msg-unread-pill {
    background: #1d4ed8;
    color: #ffffff;
    font-size: 0.65rem;
    font-weight: 700;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: 999px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.fj-msg-left-footer {
    padding: 8px 10px;
    background: #ffffff;
    border-top: 1px solid #e2e8f0;
    display: flex;
    gap: 6px;
}

.fj-msg-new-chat-btn {
    width: 100%;
    border: 1px solid #bfdbfe;
    background: #eff6ff;
    color: #1d4ed8;
    border-radius: 999px;
    padding: 5px 10px;
    font-size: 0.76rem;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    cursor: pointer;
    transition: all 0.15s ease;
}

.fj-msg-new-chat-btn:hover {
    background: #1d4ed8;
    color: #ffffff;
    border-color: #1d4ed8;
}

/* Right Column: Active Conversation */
.fj-msg-right {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
    background: #ffffff;
    position: relative;
}

.fj-msg-active-header {
    padding: 8px 12px;
    border-bottom: 1px solid #e2e8f0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    background: #ffffff;
    min-height: 52px;
    flex-shrink: 0;
}

.fj-msg-history-box {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    background: #f4f7fb;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.fj-msg-bubble-row {
    display: flex;
    align-items: flex-end;
    gap: 6px;
    max-width: 85%;
}

.fj-msg-bubble-row.is-mine {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.fj-msg-bubble-row.is-theirs {
    align-self: flex-start;
}

.fj-msg-bubble {
    padding: 8px 12px;
    border-radius: 15px;
    font-size: 0.82rem;
    line-height: 1.42;
    word-break: break-word;
    position: relative;
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.05);
}

.fj-msg-bubble-row.is-mine .fj-msg-bubble {
    background: linear-gradient(135deg, #1d4ed8, #2563eb);
    color: #ffffff;
    border-bottom-right-radius: 4px;
}

.fj-msg-bubble-row.is-theirs .fj-msg-bubble {
    background: #ffffff;
    color: #0f172a;
    border: 1px solid #e2e8f0;
    border-bottom-left-radius: 4px;
}

.fj-msg-meta-line {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 0.65rem;
    margin-top: 2px;
    color: #64748b;
}

.fj-msg-bubble-row.is-mine .fj-msg-meta-line {
    justify-content: flex-end;
}

/* Composer Area */
.fj-msg-composer-wrap {
    border-top: 1px solid #e2e8f0;
    background: #ffffff;
    padding: 8px 10px;
    position: relative;
    flex-shrink: 0;
}

.fj-msg-composer-row {
    display: flex;
    align-items: center;
    gap: 6px;
}

.fj-msg-tool-btn {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: none;
    background: #f1f5f9;
    color: #475569;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.88rem;
    cursor: pointer;
    flex-shrink: 0;
    transition: all 0.15s ease;
}

.fj-msg-tool-btn:hover {
    background: #e0e7ff;
    color: #1d4ed8;
}

.fj-msg-input {
    flex: 1;
    border: 1px solid #cbd5e1;
    border-radius: 18px;
    padding: 6px 12px;
    font-size: 0.82rem;
    line-height: 1.35;
    max-height: 84px;
    resize: none;
    background: #f8fafc;
    color: #0f172a;
}

.fj-msg-input:focus {
    background: #ffffff;
    border-color: #2563eb;
    outline: none;
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.12);
}

.fj-msg-send-btn {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    border: none;
    background: #1d4ed8;
    color: #ffffff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.84rem;
    cursor: pointer;
    flex-shrink: 0;
    transition: background 0.15s ease, transform 0.15s ease;
}

.fj-msg-send-btn:hover:not(:disabled) {
    background: #1e40af;
    transform: scale(1.04);
}

.fj-msg-send-btn:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

/* Emoji Picker Popup */
.fj-msg-emoji-picker {
    position: absolute;
    bottom: calc(100% + 6px);
    left: 10px;
    width: 248px;
    background: #ffffff;
    border: 1px solid #cbd5e1;
    border-radius: 12px;
    box-shadow: 0 10px 28px rgba(15, 23, 42, 0.16);
    padding: 8px;
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 4px;
    z-index: 25;
}

.fj-msg-emoji-btn {
    border: none;
    background: transparent;
    font-size: 1.1rem;
    padding: 4px;
    border-radius: 6px;
    cursor: pointer;
    line-height: 1;
}

.fj-msg-emoji-btn:hover {
    background: #f1f5f9;
}

/* Tablet Responsive (576px to 991.98px) */
@media (max-width: 991.98px) and (min-width: 576px) {
    .fj-floating-messenger {
        width: min(540px, calc(100vw - 24px));
        height: min(500px, calc(100vh - 84px));
        bottom: 14px;
        right: 12px;
    }
    .fj-msg-left {
        width: 200px;
        min-width: 190px;
    }
}

/* Mobile Responsive (< 576px): Full-Screen / Near-Full-Screen Interface */
@media (max-width: 575.98px) {
    .fj-floating-messenger {
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100vw !important;
        height: 100dvh !important;
        max-width: 100vw !important;
        max-height: 100dvh !important;
        border-radius: 0 !important;
        z-index: 1080;
    }

    .fj-floating-messenger.is-open.is-minimized {
        top: auto;
        left: auto;
        bottom: 68px;
        right: 12px;
        width: 260px !important;
        height: 50px !important;
        border-radius: 25px !important;
    }

    .fj-msg-left {
        width: 100% !important;
        max-width: 100% !important;
        border-right: none;
    }

    .fj-msg-right {
        display: none;
        width: 100% !important;
    }

    .fj-floating-messenger.mobile-chat-active .fj-msg-left {
        display: none;
    }

    .fj-floating-messenger.mobile-chat-active .fj-msg-right {
        display: flex;
    }
}

@media (prefers-reduced-motion: reduce) {
    .fj-floating-messenger,
    .fj-msg-ctrl-btn,
    .fj-msg-conv-item,
    .fj-msg-send-btn {
        transition: none !important;
    }
}
