/* ================================================================
   B2B MESSAGING SYSTEM — Premium Responsive Design v1.3.0
================================================================ */

:root {
    --msg-primary:  #012c5c;
    --msg-blue:     #0051a8;
    --msg-accent:   #3b82f6;
    --msg-light:    #f0f4f8;
    --msg-border:   #e2e8f0;
    --msg-gray:     #64748b;
    --msg-radius:   14px;
    --msg-sidebar:  300px;
}

/* ── Wrapper ── */
.b2b-messaging-wrapper { width:100%; box-sizing:border-box; }
.b2b-messaging-wrapper .b2b-container { max-width:100%; padding:0; margin:0; }

/* ── Main grid ── */
.b2b-messaging-container {
    display: grid;
    grid-template-columns: var(--msg-sidebar) 1fr;
    height: 600px;
    background: #fff;
    border-radius: var(--msg-radius);
    box-shadow: 0 4px 24px rgba(1,44,92,.1);
    overflow: hidden;
    border: 1px solid var(--msg-border);
}

/* ════════════════════════
   SIDEBAR
════════════════════════ */
.b2b-conversations-sidebar {
    border-right: 1px solid var(--msg-border);
    display: flex;
    flex-direction: column;
    background: #fff;
    overflow: hidden;
}
.b2b-conversations-header {
    padding: 16px 16px 12px;
    border-bottom: 1px solid var(--msg-border);
    flex-shrink: 0;
}
.b2b-conversations-header h2 {
    font-size: .95rem;
    font-weight: 700;
    color: var(--msg-primary);
    margin: 0;
}
.b2b-conversations-search {
    padding: 10px 12px;
    border-bottom: 1px solid var(--msg-border);
    flex-shrink: 0;
}
.b2b-conversations-search input {
    width: 100%;
    padding: 8px 12px;
    border: 1.5px solid var(--msg-border);
    border-radius: 10px;
    font-size: .84rem;
    outline: none;
    box-sizing: border-box;
    background: var(--msg-light);
    transition: border .2s;
}
.b2b-conversations-search input:focus {
    border-color: var(--msg-accent);
    background: #fff;
}
.b2b-conversations-list {
    flex: 1;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: rgba(0,81,168,.15) transparent;
}
.b2b-conversations-list::-webkit-scrollbar { width:4px; }
.b2b-conversations-list::-webkit-scrollbar-thumb { background:rgba(0,81,168,.2); border-radius:99px; }
.b2b-conv-empty {
    padding: 32px 16px;
    text-align: center;
    color: var(--msg-gray);
    font-size: .84rem;
}
.b2b-conv-empty i { display:block; font-size:2rem; margin-bottom:8px; opacity:.3; }

/* Conversation item */
.b2b-conversation-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 11px 14px;
    cursor: pointer;
    border-bottom: 1px solid #f8f9fb;
    transition: background .15s;
    position: relative;
}
.b2b-conversation-item:hover { background:#f8fafc; }
.b2b-conversation-item.active {
    background: linear-gradient(90deg,rgba(0,81,168,.07),rgba(0,81,168,.02));
    border-left: 3px solid var(--msg-blue);
}
.b2b-conv-av-wrap { position: relative; flex-shrink:0; }
.b2b-conversation-avatar {
    width:40px; height:40px; border-radius:50%;
    background: linear-gradient(135deg,var(--msg-primary),var(--msg-blue));
    color:#fff;
    display:flex; align-items:center; justify-content:center;
    font-weight:700; font-size:.82rem;
}
.b2b-conversation-info { flex:1; min-width:0; }
.b2b-conversation-name {
    font-weight:600; font-size:.86rem; color:#1e293b;
    white-space:nowrap; overflow:hidden; text-overflow:ellipsis;
}
.b2b-conversation-preview {
    font-size:.75rem; color:var(--msg-gray);
    white-space:nowrap; overflow:hidden; text-overflow:ellipsis;
    margin-top:2px;
}
.b2b-conversation-meta { display:flex; flex-direction:column; align-items:flex-end; gap:4px; flex-shrink:0; }
.b2b-conversation-time { font-size:.7rem; color:var(--msg-gray); }
.b2b-conversation-unread {
    background:var(--msg-blue); color:#fff;
    font-size:.67rem; font-weight:700;
    padding:2px 6px; border-radius:99px; min-width:18px; text-align:center;
}

/* ════════════════════════
   CHAT AREA
════════════════════════ */
.b2b-chat-area {
    display:flex; flex-direction:column;
    overflow:hidden; background:var(--msg-light);
    position:relative;
}

/* Empty state — shows by default */
.b2b-chat-empty {
    display:flex; flex-direction:column;
    align-items:center; justify-content:center;
    height:100%; color:var(--msg-gray);
    text-align:center; padding:40px;
}
.b2b-chat-empty i { font-size:3.2rem; margin-bottom:14px; color:#cbd5e1; }
.b2b-chat-empty h3 { font-size:1.05rem; color:#475569; margin:0 0 6px; }
.b2b-chat-empty p  { font-size:.84rem; margin:0; }

/* Chat window — HIDDEN by default, shown with .active */
.b2b-chat-window {
    display: none;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
}
.b2b-chat-window.active { display:flex; }

/* Chat header */
.b2b-chat-header {
    padding: 13px 18px;
    border-bottom: 1px solid var(--msg-border);
    background: #fff;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
    box-shadow: 0 1px 4px rgba(0,0,0,.05);
}
.b2b-chat-avatar {
    width:40px; height:40px; border-radius:50%;
    background: linear-gradient(135deg,var(--msg-primary),var(--msg-blue));
    color:#fff;
    display:flex; align-items:center; justify-content:center;
    font-weight:700; font-size:.85rem; flex-shrink:0;
}
#chat-header-name { font-weight:700; font-size:.95rem; color:var(--msg-primary); }
#chat-header-status { font-size:.74rem; color:var(--msg-gray); margin-top:2px; display:flex; align-items:center; gap:5px; }
#chat-status-dot {
    display:inline-block; width:8px; height:8px; border-radius:50%;
    background:#4ade80;
    box-shadow:0 0 0 2px rgba(74,222,128,.3);
    flex-shrink:0;
    transition: background .4s, box-shadow .4s;
}

/* Messages area */
.b2b-chat-messages {
    flex:1; overflow-y:auto; padding:16px;
    display:flex; flex-direction:column; gap:12px;
    background:var(--msg-light);
    scrollbar-width:thin;
    scrollbar-color:rgba(0,81,168,.15) transparent;
}
.b2b-chat-messages::-webkit-scrollbar { width:5px; }
.b2b-chat-messages::-webkit-scrollbar-thumb { background:rgba(0,81,168,.2); border-radius:99px; }

/* Bubbles */
.b2b-msg-bubble {
    display:flex; align-items:flex-end; gap:8px;
    max-width:72%;
    animation: b2b-msgIn .2s ease;
}
@keyframes b2b-msgIn {
    from { opacity:0; transform:translateY(8px); }
    to   { opacity:1; transform:translateY(0); }
}
.b2b-msg-in  { align-self:flex-start; }
.b2b-msg-out { align-self:flex-end; flex-direction:row-reverse; }
.b2b-msg-avatar {
    width:28px; height:28px; border-radius:50%; flex-shrink:0;
    display:flex; align-items:center; justify-content:center;
    font-weight:700; font-size:.7rem; color:#fff;
    background:linear-gradient(135deg,#64748b,#94a3b8);
}
.b2b-msg-out .b2b-msg-avatar { background:linear-gradient(135deg,var(--msg-primary),var(--msg-blue)); }
.b2b-msg-content { display:flex; flex-direction:column; gap:2px; }
.b2b-msg-out .b2b-msg-content { align-items:flex-end; }
.b2b-msg-content p {
    margin:0; padding:10px 14px; border-radius:16px;
    font-size:.875rem; line-height:1.5; word-break:break-word;
}
.b2b-msg-in  .b2b-msg-content p {
    background:#fff; color:#1e293b;
    border:1px solid var(--msg-border);
    border-bottom-left-radius:4px;
    box-shadow:0 1px 3px rgba(0,0,0,.05);
}
.b2b-msg-out .b2b-msg-content p {
    background:linear-gradient(135deg,var(--msg-primary),var(--msg-blue));
    color:#fff; border-bottom-right-radius:4px;
    box-shadow:0 4px 12px rgba(0,81,168,.25);
}
.b2b-msg-time { font-size:.69rem; color:var(--msg-gray); padding:0 4px; }

/* Input row */
.b2b-chat-input-row {
    padding:11px 14px;
    background:#fff; border-top:1px solid var(--msg-border);
    display:flex; gap:10px; align-items:flex-end; flex-shrink:0;
}
.b2b-message-input {
    flex:1; border:2px solid var(--msg-border) !important;
    border-radius:12px !important; padding:9px 14px !important;
    font-size:.9rem !important; resize:none !important;
    outline:none !important; font-family:inherit;
    transition:border .2s; max-height:100px; overflow-y:auto;
    background:var(--msg-light) !important; line-height:1.4;
}
.b2b-message-input:focus { border-color:var(--msg-accent) !important; background:#fff !important; }
.b2b-message-btn {
    width:42px; height:42px; border-radius:12px !important; flex-shrink:0;
    background:linear-gradient(135deg,var(--msg-primary),var(--msg-blue)) !important;
    color:#fff !important; border:none !important; cursor:pointer;
    display:flex !important; align-items:center !important; justify-content:center !important;
    font-size:.95rem; transition:all .2s;
    box-shadow:0 4px 12px rgba(0,81,168,.28);
}
.b2b-message-btn:hover { transform:translateY(-1px); box-shadow:0 6px 16px rgba(0,81,168,.38); }
.b2b-message-btn:disabled { opacity:.55; transform:none; cursor:not-allowed; }

/* ════════════════════════
   RESPONSIVE — MOBILE
════════════════════════ */
@media (max-width: 900px) {
    .b2b-messaging-container { height: 560px; }
}

@media (max-width: 640px) {
    /* Full-screen container — fit content, no dead space */
    .b2b-messaging-container {
        display: block;
        position: relative;
        height: calc(100dvh - 170px);
        min-height: 400px;
        max-height: 680px;
        border-radius: 12px;
        overflow: hidden;
    }

    /* PANEL 1: Conversation list — full width, slides left when chat open */
    .b2b-conversations-sidebar {
        position: absolute;
        inset: 0;
        width: 100%;
        height: 100%;
        border-right: none;
        transition: transform .3s cubic-bezier(.4,0,.2,1);
        z-index: 1;
        background: #fff;
    }
    .b2b-messaging-container.mob-chat-open .b2b-conversations-sidebar {
        transform: translateX(-100%);
    }

    /* PANEL 2: Chat area — starts off-screen right, slides in */
    .b2b-chat-area {
        position: absolute;
        inset: 0;
        width: 100%;
        height: 100%;
        transform: translateX(100%);
        transition: transform .3s cubic-bezier(.4,0,.2,1);
        z-index: 2;
        background: var(--msg-light);
    }
    .b2b-messaging-container.mob-chat-open .b2b-chat-area {
        transform: translateX(0);
    }

    /* Back button in chat header */
    .b2b-chat-back-btn {
        display: flex !important;
        align-items: center;
        justify-content: center;
        width: 34px; height: 34px;
        border-radius: 50%;
        border: none;
        background: rgba(1,44,92,.08);
        color: var(--msg-primary);
        cursor: pointer;
        font-size: 1rem;
        flex-shrink: 0;
        margin-right: 4px;
        -webkit-tap-highlight-color: transparent;
        transition: background .2s;
    }
    .b2b-chat-back-btn:active { background: rgba(1,44,92,.18); }

    /* Conversations list — full height on mobile */
    .b2b-conversations-list { max-height: unset; }

    /* Bigger tap targets */
    .b2b-conversation-item { padding: 14px 16px; }
    .b2b-msg-bubble { max-width: 88%; }
}

/* Back btn hidden on desktop */
.b2b-chat-back-btn { display: none; }

/* Hide scrollbar on message textarea */
.b2b-message-input {
    scrollbar-width: none !important;
    -ms-overflow-style: none !important;
}
.b2b-message-input::-webkit-scrollbar {
    display: none !important;
    width: 0 !important;
}
