/* =========================================================
   Spehre Chat System — Premium Messaging UI
   ========================================================= */

/* ── Layout: Two-Panel Chat ── */
#view-messages {
    padding: 0 !important;
}

.chat-container {
    display: flex;
    height: calc(100vh - 100px);
    min-height: 600px;
    background: #fff;
    box-shadow: rgba(0, 0, 0, 0.04) 0px 1px 3px;
    border-radius: 20px;
    /* TEMP DEBUG */
    overflow: hidden;
    border-width: 1px;
    border-style: solid;
    border-color: rgb(226, 232, 240);
}

/* ── Left Panel: Conversation List ── */
.chat-sidebar {
    width: 340px;
    min-width: 300px;
    border-right: 1px solid #f1f5f9;
    display: flex;
    flex-direction: column;
    background: #fafbfc;
}

.chat-sidebar-header {
    padding: 20px 18px 14px;
    border-bottom: 1px solid #f1f5f9;
}

.chat-sidebar-header h2 {
    font-size: 1.25rem;
    font-weight: 800;
    color: #0f172a;
    margin: 0 0 12px;
    display: flex;
    align-items: center;
    gap: 10px;
    letter-spacing: -0.02em;
}

.chat-sidebar-header h2 i {
    font-size: 1rem;
    background: linear-gradient(135deg, #0085ff, #6366f1);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.chat-search-box {
    position: relative;
}

.chat-search-box input {
    width: 100%;
    padding: 9px 14px 9px 36px;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    font-size: 0.82rem;
    font-family: inherit;
    background: #fff;
    color: #0f172a;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.chat-search-box input:focus {
    border-color: #0085ff;
    box-shadow: 0 0 0 3px rgba(0, 133, 255, 0.08);
}

.chat-search-box input::placeholder {
    color: #94a3b8;
}

.chat-search-box i {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: #94a3b8;
    font-size: 0.78rem;
}

/* ── Conversation List ── */
.chat-conv-list {
    flex: 1;
    overflow-y: auto;
    padding: 6px 0;
}

.chat-conv-list::-webkit-scrollbar {
    width: 4px;
}

.chat-conv-list::-webkit-scrollbar-thumb {
    background: #e2e8f0;
    border-radius: 10px;
}

.chat-conv-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 18px;
    cursor: pointer;
    transition: background 0.15s;
    position: relative;
    border-left: 3px solid transparent;
}

.chat-conv-item:hover {
    background: #f1f5f9;
}

.chat-conv-item.active {
    background: #eff6ff;
    border-left-color: #0085ff;
}

.chat-conv-avatar {
    position: relative;
    flex-shrink: 0;
}

.chat-conv-avatar img {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: 2px solid #e2e8f0;
    object-fit: cover;
}

.chat-conv-avatar .online-dot {
    position: absolute;
    bottom: 1px;
    right: 1px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #22c55e;
    border: 2px solid #fafbfc;
}

.chat-conv-info {
    flex: 1;
    min-width: 0;
}

.chat-conv-name {
    font-size: 0.88rem;
    font-weight: 700;
    color: #0f172a;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.2;
}

.chat-conv-preview {
    font-size: 0.76rem;
    color: #64748b;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 2px;
    line-height: 1.3;
}

.chat-conv-preview.unread {
    color: #0f172a;
    font-weight: 600;
}

.chat-conv-meta {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 4px;
    flex-shrink: 0;
}

.chat-conv-time {
    font-size: 0.68rem;
    color: #94a3b8;
    font-weight: 500;
}

.chat-conv-badge {
    min-width: 18px;
    height: 18px;
    border-radius: 100px;
    background: linear-gradient(135deg, #0085ff, #6366f1);
    color: #fff;
    font-size: 0.65rem;
    font-weight: 800;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 5px;
}

/* ── Right Panel: Chat Thread ── */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    background: #fff;
}

/* Empty state */
.chat-empty-state {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: #94a3b8;
    gap: 12px;
    padding: 40px;
}

.chat-empty-state i {
    font-size: 3.5rem;
    background: linear-gradient(135deg, #cbd5e1, #94a3b8);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.chat-empty-state h3 {
    font-size: 1.1rem;
    font-weight: 700;
    color: #475569;
    margin: 0;
}

.chat-empty-state p {
    font-size: 0.85rem;
    color: #94a3b8;
    margin: 0;
    text-align: center;
    line-height: 1.5;
}

/* ── Chat Header ── */
.chat-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 20px;
    border-bottom: 1px solid #f1f5f9;
    background: #fff;
}

.chat-header-avatar img {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    border: 2px solid #e2e8f0;
    object-fit: cover;
}

.chat-header-info {
    flex: 1;
}

.chat-header-name {
    font-size: 0.95rem;
    font-weight: 700;
    color: #0f172a;
    line-height: 1.2;
}

.chat-header-status {
    font-size: 0.72rem;
    color: #94a3b8;
    display: flex;
    align-items: center;
    gap: 5px;
    margin-top: 1px;
}

.chat-header-status .status-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #22c55e;
    display: inline-block;
}

.chat-header-actions {
    display: flex;
    gap: 6px;
}

.chat-header-actions button {
    width: 34px;
    height: 34px;
    border-radius: 10px;
    border: 1px solid #e2e8f0;
    background: #f8fafc;
    color: #64748b;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
    transition: all 0.15s;
}

.chat-header-actions button:hover {
    background: #eff6ff;
    color: #0085ff;
    border-color: #bfdbfe;
}

/* ── Message Thread ── */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px 24px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    scroll-behavior: smooth;
}

.chat-messages::-webkit-scrollbar {
    width: 4px;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: #e2e8f0;
    border-radius: 10px;
}

/* Date separator */
.chat-date-sep {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 12px 0;
}

.chat-date-sep::before,
.chat-date-sep::after {
    content: '';
    flex: 1;
    height: 1px;
    background: #f1f5f9;
}

.chat-date-sep span {
    font-size: 0.68rem;
    font-weight: 600;
    color: #94a3b8;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    white-space: nowrap;
}

/* Message bubble wrapper */
.chat-msg {
    display: flex;
    max-width: 72%;
    animation: chatMsgIn 0.25s ease-out;
}

.chat-msg.sent {
    align-self: flex-end;
}

.chat-msg.received {
    align-self: flex-start;
}

/* Bubble */
.chat-bubble {
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 0.86rem;
    line-height: 1.55;
    word-wrap: break-word;
    word-break: break-word;
    position: relative;
}

.chat-msg.sent .chat-bubble {
    background: linear-gradient(135deg, #0085ff 0%, #6366f1 100%);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.chat-msg.received .chat-bubble {
    background: #f1f5f9;
    color: #0f172a;
    border-bottom-left-radius: 4px;
}

.chat-msg-time {
    font-size: 0.62rem;
    margin-top: 4px;
    display: flex;
    align-items: center;
    gap: 4px;
}

.chat-msg.sent .chat-msg-time {
    color: rgba(255, 255, 255, 0.6);
    justify-content: flex-end;
}

.chat-msg.received .chat-msg-time {
    color: #94a3b8;
}

/* Read receipts */
.chat-msg-time .read-tick {
    font-size: 0.7rem;
}

.chat-msg-time .read-tick.read {
    color: rgba(255, 255, 255, 0.85);
}

/* Typing indicator */
.chat-typing-indicator {
    display: none;
    align-items: center;
    gap: 8px;
    padding: 6px 0;
    font-size: 0.75rem;
    color: #94a3b8;
    font-weight: 500;
}

.chat-typing-indicator.visible {
    display: flex;
}

.typing-dots {
    display: flex;
    gap: 3px;
}

.typing-dots span {
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: #94a3b8;
    animation: typingBounce 1.4s infinite ease-in-out;
}

.typing-dots span:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-dots span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typingBounce {

    0%,
    80%,
    100% {
        transform: scale(0.6);
        opacity: 0.4;
    }

    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* ── Input Bar ── */
.chat-input-bar {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    padding: 14px 20px;
    border-top: 1px solid #f1f5f9;
    background: #fafbfc;
}

.chat-input-wrapper {
    flex: 1;
    position: relative;
}

.chat-input-wrapper textarea {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid #e2e8f0;
    border-radius: 14px;
    font-size: 0.85rem;
    font-family: inherit;
    background: #fff;
    color: #0f172a;
    outline: none;
    resize: none;
    min-height: 40px;
    max-height: 120px;
    line-height: 1.5;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.chat-input-wrapper textarea:focus {
    border-color: #0085ff;
    box-shadow: 0 0 0 3px rgba(0, 133, 255, 0.06);
}

.chat-input-wrapper textarea::placeholder {
    color: #94a3b8;
}

.chat-send-btn {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    border: none;
    background: linear-gradient(135deg, #0085ff, #6366f1);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.95rem;
    transition: transform 0.15s, box-shadow 0.15s;
    flex-shrink: 0;
    box-shadow: 0 4px 12px rgba(0, 133, 255, 0.25);
}

.chat-send-btn:hover {
    transform: scale(1.06);
    box-shadow: 0 6px 16px rgba(0, 133, 255, 0.35);
}

.chat-send-btn:active {
    transform: scale(0.96);
}

.chat-send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

/* ── Load More ── */
.chat-load-more {
    text-align: center;
    padding: 8px;
}

.chat-load-more button {
    background: transparent;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 6px 16px;
    font-size: 0.75rem;
    font-weight: 600;
    color: #64748b;
    cursor: pointer;
    font-family: inherit;
    transition: all 0.15s;
}

.chat-load-more button:hover {
    background: #f8fafc;
    border-color: #cbd5e1;
}

/* ── New Conversation Button ── */
.chat-new-btn {
    margin: 0 18px 14px;
    padding: 9px;
    border: 1px dashed #cbd5e1;
    border-radius: 10px;
    background: transparent;
    color: #64748b;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    font-family: inherit;
    transition: all 0.15s;
}

.chat-new-btn:hover {
    background: #eff6ff;
    border-color: #0085ff;
    color: #0085ff;
}

/* ── User Search Dropdown (new conversation) ── */
.chat-user-search-dropdown {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    box-shadow: 0 8px 30px -4px rgba(15, 23, 42, 0.12);
    max-height: 240px;
    overflow-y: auto;
    z-index: 100;
    display: none;
}

.chat-user-search-dropdown.visible {
    display: block;
}

.chat-user-search-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    cursor: pointer;
    transition: background 0.1s;
}

.chat-user-search-item:hover {
    background: #f8fafc;
}

.chat-user-search-item img {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    border: 1.5px solid #e2e8f0;
    object-fit: cover;
}

.chat-user-search-item .search-name {
    font-size: 0.83rem;
    font-weight: 600;
    color: #0f172a;
}

.chat-user-search-item .search-role {
    font-size: 0.72rem;
    color: #94a3b8;
}

/* ── Back Button (Mobile) ── */
.chat-back-btn {
    display: none;
    width: 34px;
    height: 34px;
    border-radius: 10px;
    border: 1px solid #e2e8f0;
    background: #f8fafc;
    color: #64748b;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
    margin-right: 4px;
    flex-shrink: 0;
}

/* ── Nav Badge ── */
.chat-nav-badge {
    min-width: 16px;
    height: 16px;
    border-radius: 100px;
    background: #ef4444;
    color: #fff;
    font-size: 0.6rem;
    font-weight: 800;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 0 4px;
    position: absolute;
    top: 4px;
    right: 4px;
}

.chat-nav-badge.visible {
    display: flex;
}

/* ── Animations ── */
@keyframes chatMsgIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ── Mobile Responsive ── */
@media (max-width: 768px) {
    .chat-container {
        border-radius: 0;
        max-height: calc(100vh - 60px);
        border: none;
    }

    .chat-sidebar {
        width: 100%;
        min-width: 100%;
        transition: transform 0.3s ease;
    }

    .chat-main {
        position: absolute;
        inset: 0;
        z-index: 10;
        transform: translateX(100%);
        transition: transform 0.3s ease;
    }

    .chat-container.chat-open .chat-sidebar {
        transform: translateX(-100%);
    }

    .chat-container.chat-open .chat-main {
        transform: translateX(0);
    }

    .chat-back-btn {
        display: flex;
    }

    .chat-msg {
        max-width: 85%;
    }
}

@media (max-width: 480px) {
    .chat-sidebar-header {
        padding: 14px 14px 10px;
    }

    .chat-conv-item {
        padding: 10px 14px;
    }

    .chat-messages {
        padding: 14px 12px;
    }

    .chat-input-bar {
        padding: 10px 12px;
    }
}