/* ========================================
   BEXILY CHAT SYSTEM FRONTEND
======================================== */
.bex-chat-launcher {
    position: fixed;
    right: 24px;
    bottom: 24px;
    z-index: 9999;
    width: 62px;
    height: 62px;
    border: 0;
    border-radius: 50%;
    color: #fff;
    background: linear-gradient(135deg, #1e40af, #0f766e);
    box-shadow: 0 18px 45px rgba(15, 23, 42, 0.28);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.55rem;
    cursor: pointer;
    transition: transform 0.25s ease, box-shadow 0.25s ease;
}

.bex-chat-launcher:hover {
    transform: translateY(-3px) scale(1.03);
    box-shadow: 0 24px 58px rgba(30, 64, 175, 0.35);
}

.bex-chat-launcher::before {
    content: "";
    position: absolute;
    inset: -8px;
    border-radius: inherit;
    border: 2px solid rgba(30, 64, 175, 0.22);
    animation: bexChatPulse 1.8s ease-out infinite;
}

.bex-chat-unread {
    position: absolute;
    top: -4px;
    right: -2px;
    min-width: 22px;
    height: 22px;
    border-radius: 999px;
    background: #f59e0b;
    color: #111827;
    font-size: 12px;
    font-weight: 800;
    display: grid;
    place-items: center;
    border: 2px solid #fff;
}

.bex-chat-widget {
    position: fixed;
    right: 24px;
    bottom: 98px;
    z-index: 9999;
    width: min(390px, calc(100vw - 28px));
    height: min(620px, calc(100vh - 128px));
    display: none;
    flex-direction: column;
    border-radius: 18px;
    overflow: hidden;
    background: #fff;
    border: 1px solid rgba(226, 232, 240, 0.92);
    box-shadow: 0 30px 80px rgba(15, 23, 42, 0.32);
}

.bex-chat-widget.is-open {
    display: flex;
    animation: bexChatIn 0.28s ease both;
}

.bex-chat-widget-head {
    position: relative;
    padding: 20px;
    color: #fff;
    background:
        linear-gradient(135deg, rgba(15, 23, 42, 0.96), rgba(30, 64, 175, 0.9)),
        url("../../images/tech-bg-2.png") center/cover;
}

.bex-chat-widget-head::after {
    content: "";
    position: absolute;
    inset: 0;
    background-image: linear-gradient(90deg, rgba(255,255,255,0.08) 1px, transparent 1px);
    background-size: 34px 34px;
    opacity: 0.38;
}

.bex-chat-widget-head > * {
    position: relative;
    z-index: 1;
}

.bex-chat-status {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 12px;
}

.bex-chat-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #22c55e;
    box-shadow: 0 0 0 6px rgba(34, 197, 94, 0.18);
}

.bex-chat-widget-head h3 {
    font-size: 1.2rem;
    line-height: 1.25;
    margin: 0 0 6px;
    font-weight: 850;
}

.bex-chat-widget-head p {
    margin: 0;
    color: rgba(255,255,255,0.78);
    font-size: 0.9rem;
}

.bex-chat-close {
    position: absolute;
    top: 14px;
    right: 14px;
    z-index: 2;
    width: 34px;
    height: 34px;
    border: 0;
    border-radius: 50%;
    color: #fff;
    background: rgba(255,255,255,0.12);
}

.bex-chat-messages {
    flex: 1;
    padding: 18px;
    overflow-y: auto;
    background:
        linear-gradient(180deg, rgba(248, 250, 252, 0.9), rgba(239, 246, 255, 0.72)),
        #f8fafc;
}

.bex-chat-row {
    display: flex;
    margin-bottom: 12px;
}

.bex-chat-row.is-user {
    justify-content: flex-end;
}

.bex-chat-bubble {
    max-width: 82%;
    padding: 11px 13px;
    border-radius: 16px;
    background: #fff;
    color: #334155;
    box-shadow: 0 8px 22px rgba(15, 23, 42, 0.08);
    font-size: 0.92rem;
    line-height: 1.5;
}

.bex-chat-row.is-user .bex-chat-bubble {
    background: #1e40af;
    color: #fff;
    border-bottom-right-radius: 5px;
}

.bex-chat-row.is-agent .bex-chat-bubble {
    border-bottom-left-radius: 5px;
}

.bex-chat-time {
    display: block;
    margin-top: 5px;
    font-size: 0.72rem;
    opacity: 0.62;
}

.bex-chat-form {
    padding: 14px;
    border-top: 1px solid #e2e8f0;
    background: #fff;
}

.bex-chat-fields {
    display: grid;
    gap: 9px;
    margin-bottom: 10px;
}

.bex-chat-fields input,
.bex-chat-input {
    width: 100%;
    border: 1px solid #dbe3ef;
    border-radius: 12px;
    min-height: 44px;
    padding: 10px 12px;
    outline: none;
    font: inherit;
}

.bex-chat-fields input:focus,
.bex-chat-input:focus {
    border-color: #1e40af;
    box-shadow: 0 0 0 4px rgba(30, 64, 175, 0.1);
}

.bex-chat-compose {
    display: grid;
    grid-template-columns: 1fr 46px;
    gap: 9px;
}

.bex-chat-send {
    border: 0;
    border-radius: 12px;
    color: #fff;
    background: #1e40af;
    font-size: 1.1rem;
}

.bex-chat-hint {
    margin: 9px 0 0;
    color: #64748b;
    font-size: 0.75rem;
}

/* ========================================
   ADMIN CHAT PAGE
======================================== */
.chat-admin-page {
    background: #eef4fb;
    background-image:
        linear-gradient(120deg, rgba(248, 250, 252, 0.84), rgba(239, 246, 255, 0.82)),
        url("../../images/tech-bg.jpg");
    background-size: cover;
    min-height: 100vh;
}

.chat-admin-page .bex-chat-launcher {
    display: none !important;
}

.bex-chat-login {
    min-height: 100vh;
    display: grid;
    grid-template-columns: minmax(0, 1.05fr) minmax(380px, 0.95fr);
    align-items: stretch;
    font-family: "Inter", sans-serif;
}

.bex-login-visual {
    position: relative;
    overflow: hidden;
    color: #fff;
    padding: clamp(32px, 6vw, 76px);
    display: flex;
    flex-direction: column;
    justify-content: center;
    background:
        linear-gradient(135deg, rgba(15, 23, 42, 0.96), rgba(30, 64, 175, 0.78)),
        url("../../images/tech-bg-2.png") center/cover;
}

.bex-login-visual::after {
    content: "";
    position: absolute;
    inset: 0;
    background:
        linear-gradient(90deg, rgba(255,255,255,0.07) 1px, transparent 1px),
        linear-gradient(0deg, rgba(255,255,255,0.05) 1px, transparent 1px);
    background-size: 48px 48px;
    opacity: 0.5;
}

.bex-login-visual > * {
    position: relative;
    z-index: 1;
}

.bex-login-brand {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 42px;
}

.bex-login-brand img {
    width: 136px;
    max-height: 54px;
    object-fit: contain;
}

.bex-login-brand span {
    color: rgba(255,255,255,0.74);
    font-weight: 800;
}

.bex-login-visual h1 {
    max-width: 760px;
    font-size: clamp(2.1rem, 5vw, 4.7rem);
    line-height: 1.04;
    font-weight: 900;
    letter-spacing: 0;
    margin: 0 0 22px;
}

.bex-login-visual p {
    max-width: 640px;
    color: rgba(255,255,255,0.78);
    font-size: 1.04rem;
    line-height: 1.8;
}

.bex-login-stats {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
    max-width: 640px;
    margin-top: 34px;
}

.bex-login-stats div {
    padding: 16px;
    border-radius: 16px;
    background: rgba(255,255,255,0.1);
    border: 1px solid rgba(255,255,255,0.14);
    backdrop-filter: blur(8px);
}

.bex-login-stats strong {
    display: block;
    color: #fbbf24;
    font-size: 1.4rem;
    line-height: 1;
    margin-bottom: 8px;
}

.bex-login-stats span {
    color: rgba(255,255,255,0.78);
    font-size: 0.86rem;
}

.bex-login-card {
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: clamp(28px, 5vw, 72px);
    background: rgba(255,255,255,0.9);
    backdrop-filter: blur(12px);
}

.bex-login-kicker {
    color: #1e40af;
    font-size: 0.8rem;
    font-weight: 900;
    text-transform: uppercase;
    margin-bottom: 12px;
}

.bex-login-card h2 {
    margin: 0 0 10px;
    font-size: clamp(1.7rem, 3vw, 2.35rem);
    font-weight: 900;
    letter-spacing: 0;
}

.bex-login-card p {
    color: #64748b;
    line-height: 1.7;
    margin-bottom: 26px;
}

.bex-login-card form {
    display: grid;
    gap: 16px;
}

.bex-login-card label span {
    display: block;
    margin-bottom: 7px;
    color: #334155;
    font-weight: 800;
    font-size: 0.88rem;
}

.bex-login-card input[type="email"],
.bex-login-card input[type="password"] {
    width: 100%;
    min-height: 52px;
    border: 1px solid #dbe3ef;
    border-radius: 14px;
    padding: 12px 14px;
    outline: none;
    font: inherit;
}

.bex-login-card input:focus {
    border-color: #1e40af;
    box-shadow: 0 0 0 4px rgba(30, 64, 175, 0.1);
}

.bex-login-row {
    display: flex;
    justify-content: space-between;
    gap: 14px;
    align-items: center;
    color: #64748b;
    font-size: 0.9rem;
}

.bex-login-check {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.bex-login-row a {
    color: #1e40af;
    font-weight: 800;
    text-decoration: none;
}

.bex-login-card button {
    min-height: 54px;
    border: 0;
    border-radius: 14px;
    color: #fff;
    background: linear-gradient(135deg, #1e40af, #0f766e);
    font-weight: 900;
    box-shadow: 0 18px 38px rgba(30, 64, 175, 0.22);
}

.bex-chat-admin {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 280px minmax(0, 1fr);
    font-family: "Inter", sans-serif;
    color: #0f172a;
}

.bex-chat-sidebar {
    background: rgba(15, 23, 42, 0.96);
    color: #fff;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 22px;
}

.bex-chat-brand,
.bex-chat-agent {
    display: flex;
    align-items: center;
    gap: 12px;
}

.bex-chat-brand img {
    width: 112px;
    max-height: 48px;
    object-fit: contain;
}

.bex-chat-brand span,
.bex-chat-agent span {
    display: block;
    color: rgba(255,255,255,0.68);
    font-size: 0.82rem;
}

.bex-agent-avatar {
    width: 42px;
    height: 42px;
    border-radius: 14px;
    background: linear-gradient(135deg, #1e40af, #14b8a6);
    color: #fff;
    display: grid;
    place-items: center;
    font-weight: 850;
}

.is-online::before {
    content: "";
    display: inline-block;
    width: 8px;
    height: 8px;
    margin-right: 7px;
    border-radius: 50%;
    background: #22c55e;
}

.bex-chat-nav {
    display: grid;
    gap: 8px;
}

.bex-chat-nav button {
    border: 0;
    border-radius: 14px;
    padding: 13px 14px;
    color: rgba(255,255,255,0.82);
    background: transparent;
    display: flex;
    align-items: center;
    gap: 10px;
    text-align: left;
}

.bex-chat-nav button strong {
    margin-left: auto;
    font-size: 0.78rem;
    padding: 3px 8px;
    border-radius: 999px;
    background: rgba(255,255,255,0.12);
}

.bex-chat-nav button.is-active,
.bex-chat-nav button:hover {
    color: #fff;
    background: rgba(255,255,255,0.11);
}

.bex-admin-note {
    margin-top: auto;
    border-radius: 18px;
    padding: 16px;
    background: rgba(251, 191, 36, 0.12);
    border: 1px solid rgba(251, 191, 36, 0.18);
}

.bex-admin-note i {
    color: #fbbf24;
    font-size: 1.35rem;
}

.bex-admin-note p {
    margin: 8px 0 0;
    color: rgba(255,255,255,0.74);
    font-size: 0.84rem;
    line-height: 1.6;
}

.bex-chat-panel {
    padding: 22px;
    min-width: 0;
}

.bex-chat-topbar {
    display: flex;
    justify-content: space-between;
    gap: 18px;
    align-items: center;
    margin-bottom: 18px;
}

.bex-chat-topbar span {
    color: #1e40af;
    font-weight: 800;
    font-size: 0.82rem;
    text-transform: uppercase;
}

.bex-chat-topbar h1 {
    margin: 4px 0 0;
    font-size: clamp(1.35rem, 2.5vw, 2.25rem);
    font-weight: 900;
    letter-spacing: 0;
}

.bex-chat-top-actions {
    display: flex;
    gap: 10px;
}

.bex-chat-top-actions button,
.bex-conversation-actions button,
.bex-reply-box button {
    border: 0;
    border-radius: 12px;
    background: #fff;
    color: #334155;
    min-height: 42px;
    padding: 10px 14px;
    box-shadow: 0 10px 25px rgba(15, 23, 42, 0.08);
}

.bex-chat-workspace {
    height: calc(100vh - 118px);
    min-height: 620px;
    display: grid;
    grid-template-columns: 320px minmax(0, 1fr) 280px;
    background: rgba(255,255,255,0.72);
    border: 1px solid rgba(226, 232, 240, 0.9);
    border-radius: 24px;
    overflow: hidden;
    box-shadow: 0 24px 70px rgba(15, 23, 42, 0.12);
    backdrop-filter: blur(12px);
}

.bex-visitor-list,
.bex-visitor-profile {
    background: rgba(248, 250, 252, 0.92);
    padding: 18px;
    overflow-y: auto;
}

.bex-list-tools label {
    display: flex;
    align-items: center;
    gap: 9px;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 14px;
    padding: 0 12px;
}

.bex-list-tools input {
    width: 100%;
    min-height: 44px;
    border: 0;
    outline: none;
    background: transparent;
    font: inherit;
}

.bex-inbox-tabs {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
    margin: 14px 0;
}

.bex-inbox-tabs button {
    border: 0;
    border-radius: 999px;
    padding: 8px;
    font-size: 0.82rem;
    background: transparent;
    color: #64748b;
}

.bex-inbox-tabs button.is-active {
    color: #fff;
    background: #1e40af;
}

.bex-visitor-card {
    width: 100%;
    border: 1px solid transparent;
    border-radius: 16px;
    padding: 13px;
    margin-bottom: 9px;
    background: #fff;
    display: grid;
    grid-template-columns: 42px minmax(0, 1fr) auto;
    gap: 11px;
    text-align: left;
    transition: all 0.2s ease;
}

.bex-visitor-card:hover,
.bex-visitor-card.is-active {
    border-color: rgba(30, 64, 175, 0.25);
    box-shadow: 0 12px 28px rgba(30, 64, 175, 0.12);
    transform: translateY(-1px);
}

.bex-visitor-card h3 {
    margin: 0;
    font-size: 0.96rem;
    font-weight: 850;
}

.bex-visitor-card p {
    margin: 3px 0 0;
    color: #64748b;
    font-size: 0.82rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.bex-chat-badge {
    min-width: 22px;
    height: 22px;
    border-radius: 999px;
    background: #f59e0b;
    color: #111827;
    display: grid;
    place-items: center;
    font-size: 0.75rem;
    font-weight: 900;
}

.bex-conversation {
    display: flex;
    flex-direction: column;
    min-width: 0;
    background: #fff;
}

.bex-conversation-head {
    min-height: 78px;
    padding: 16px 18px;
    border-bottom: 1px solid #e2e8f0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 14px;
}

.bex-active-user {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.bex-active-user h2 {
    margin: 0;
    font-size: 1.05rem;
    font-weight: 900;
}

.bex-active-user span {
    color: #64748b;
    font-size: 0.84rem;
}

.bex-conversation-actions {
    display: flex;
    gap: 8px;
}

.bex-conversation-actions button {
    width: 42px;
    padding: 0;
}

.bex-message-stream {
    flex: 1;
    padding: 22px;
    overflow-y: auto;
    background:
        linear-gradient(180deg, rgba(248,250,252,0.82), rgba(239,246,255,0.72)),
        #f8fafc;
}

.bex-admin-message-row {
    display: flex;
    margin-bottom: 14px;
}

.bex-admin-message-row.is-agent {
    justify-content: flex-end;
}

.bex-admin-message {
    max-width: min(560px, 78%);
    border-radius: 16px;
    padding: 12px 14px;
    background: #fff;
    color: #334155;
    box-shadow: 0 8px 22px rgba(15, 23, 42, 0.07);
    line-height: 1.55;
}

.bex-admin-message-row.is-agent .bex-admin-message {
    background: #1e40af;
    color: #fff;
}

.bex-admin-message small {
    display: block;
    margin-top: 6px;
    opacity: 0.62;
}

.bex-quick-replies {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 12px 18px 0;
}

.bex-quick-replies button {
    border: 1px solid #dbe3ef;
    border-radius: 999px;
    color: #334155;
    background: #fff;
    padding: 8px 12px;
    font-size: 0.82rem;
}

.bex-reply-box {
    display: grid;
    grid-template-columns: 44px 1fr 48px;
    gap: 10px;
    padding: 14px 18px 18px;
}

.bex-reply-box textarea {
    resize: none;
    min-height: 46px;
    max-height: 120px;
    border: 1px solid #dbe3ef;
    border-radius: 14px;
    outline: none;
    padding: 12px 14px;
    font: inherit;
}

.bex-reply-box textarea:focus {
    border-color: #1e40af;
    box-shadow: 0 0 0 4px rgba(30, 64, 175, 0.1);
}

.bex-send-btn {
    background: #1e40af !important;
    color: #fff !important;
}

.bex-profile-card {
    text-align: center;
    padding: 20px 12px;
    border-radius: 18px;
    background: #fff;
    box-shadow: 0 12px 30px rgba(15, 23, 42, 0.08);
}

.bex-profile-avatar {
    width: 72px;
    height: 72px;
    margin: 0 auto 12px;
    border-radius: 22px;
    background: linear-gradient(135deg, #1e40af, #14b8a6);
    display: grid;
    place-items: center;
    color: #fff;
    font-weight: 900;
    font-size: 1.35rem;
}

.bex-profile-card h3 {
    margin: 0;
    font-size: 1.05rem;
    font-weight: 900;
}

.bex-profile-card span {
    color: #16a34a;
    font-size: 0.84rem;
}

.bex-profile-section {
    margin-top: 16px;
    padding: 16px;
    border-radius: 18px;
    background: #fff;
    box-shadow: 0 12px 30px rgba(15, 23, 42, 0.06);
}

.bex-profile-section h4 {
    margin: 0 0 12px;
    font-size: 0.9rem;
    font-weight: 900;
}

.bex-profile-section p {
    display: flex;
    gap: 9px;
    margin: 9px 0;
    color: #475569;
    font-size: 0.88rem;
}

.bex-profile-section select {
    width: 100%;
    min-height: 42px;
    border: 1px solid #dbe3ef;
    border-radius: 12px;
    padding: 8px 10px;
    outline: none;
}

.bex-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.bex-tags span {
    padding: 7px 10px;
    border-radius: 999px;
    color: #1e40af;
    background: #eff6ff;
    font-size: 0.78rem;
    font-weight: 800;
}

@keyframes bexChatPulse {
    0% { transform: scale(0.9); opacity: 0.8; }
    100% { transform: scale(1.35); opacity: 0; }
}

@keyframes bexChatIn {
    from { opacity: 0; transform: translateY(18px) scale(0.96); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

@media (max-width: 1180px) {
    .bex-chat-workspace {
        grid-template-columns: 300px minmax(0, 1fr);
    }

    .bex-visitor-profile {
        display: none;
    }
}

@media (max-width: 860px) {
    .bex-chat-login {
        grid-template-columns: 1fr;
    }

    .bex-login-visual {
        min-height: 52vh;
    }

    .bex-chat-admin {
        grid-template-columns: 1fr;
    }

    .bex-chat-sidebar {
        display: none;
    }

    .bex-chat-workspace {
        height: auto;
        min-height: 0;
        grid-template-columns: 1fr;
    }

    .bex-visitor-list {
        max-height: 320px;
    }

    .bex-conversation {
        min-height: 620px;
    }
}

@media (max-width: 560px) {
    .bex-login-stats {
        grid-template-columns: 1fr;
    }

    .bex-chat-launcher {
        right: 16px;
        bottom: 16px;
    }

    .bex-chat-widget {
        right: 14px;
        bottom: 88px;
        height: calc(100vh - 110px);
    }

    .bex-chat-topbar,
    .bex-conversation-head {
        align-items: flex-start;
        flex-direction: column;
    }

    .bex-chat-top-actions {
        width: 100%;
    }

    .bex-chat-top-actions button {
        flex: 1;
    }
}
