/**
 * mFLIP v10.10.0 - Unified Chat CSS
 * WhatsApp-like split view for desktop, slide for mobile
 */

/* ========== BASE LAYOUT ========== */
/* IMPORTANT: display is controlled by .skyjo-screen and .skyjo-screen.active
   Do NOT set display here - it would override the base display:none */
.unified-chat {
    /* display: flex is set by .skyjo-screen.active */
    flex-direction: row;
    width: 100%;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    background: linear-gradient(180deg, #101217 0%, #0b0d12 100%);
}

/* Ensure proper flex layout when active */
#screen-unified-chat.active {
    display: flex;
    flex-direction: row;
}

/* ========== THREADS PANEL (Left) ========== */
.unified-chat__threads {
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100%;
    background: rgba(12, 14, 18, 0.95);
    border-right: 1px solid rgba(255, 255, 255, 0.06);
    transition: transform 0.3s ease, width 0.3s ease;
}

.unified-chat__header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: max(env(safe-area-inset-top, 12px), 12px) 16px 12px;
    background: rgba(12, 14, 18, 0.9);
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.unified-chat__back {
    width: 40px;
    height: 40px;
    background: rgba(255, 255, 255, 0.08);
    border: none;
    border-radius: 12px;
    color: rgba(255, 255, 255, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
    flex-shrink: 0;
}

.unified-chat__back:hover {
    background: rgba(255, 255, 255, 0.15);
}

.unified-chat__header-title {
    flex: 1;
    min-width: 0;
}

.unified-chat__header-title h1 {
    font-size: 1.25rem;
    font-weight: 700;
    color: white;
    margin: 0;
}

.unified-chat__header-subtitle {
    font-size: 0.75rem;
    color: rgba(255, 255, 255, 0.5);
}

.unified-chat__new-chat {
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, #2aa78b, #1b7a66);
    border: none;
    border-radius: 12px;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
    flex-shrink: 0;
}

.unified-chat__new-chat:hover {
    transform: scale(1.05);
}

/* Search */
.unified-chat__search {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 12px 16px;
    padding: 10px 14px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 12px;
}

.unified-chat__search i {
    color: rgba(255, 255, 255, 0.4);
    font-size: 0.9rem;
}

.unified-chat__search input {
    flex: 1;
    background: transparent;
    border: none;
    color: white;
    font-size: 0.95rem;
    outline: none;
}

.unified-chat__search input::placeholder {
    color: rgba(255, 255, 255, 0.4);
}

/* Thread List */
.unified-chat__thread-list {
    flex: 1;
    overflow-y: auto;
    padding: 0 8px 80px;
    -webkit-overflow-scrolling: touch;
}

.unified-chat__thread-list::-webkit-scrollbar {
    width: 4px;
}

.unified-chat__thread-list::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.15);
    border-radius: 2px;
}

.unified-chat__loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 40px;
    color: rgba(255, 255, 255, 0.5);
}

.unified-chat__empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 40px;
    text-align: center;
    color: rgba(255, 255, 255, 0.5);
}

.unified-chat__empty i {
    font-size: 3rem;
    opacity: 0.5;
}

/* Thread Item */
.unified-chat__thread {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    margin: 4px 0;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid transparent;
    border-radius: 14px;
    cursor: pointer;
    transition: all 0.2s;
}

.unified-chat__thread:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.08);
}

.unified-chat__thread--active {
    background: rgba(42, 167, 139, 0.15);
    border-color: rgba(42, 167, 139, 0.3);
}

.unified-chat__thread--unread {
    background: rgba(255, 255, 255, 0.06);
}

.unified-chat__thread-avatar {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: linear-gradient(135deg, #2aa78b, #3b82f6);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    overflow: hidden;
    position: relative;
}

.unified-chat__thread-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.unified-chat__thread-avatar-initial {
    font-size: 1.3rem;
    font-weight: 700;
    color: white;
}

.unified-chat__thread-online {
    position: absolute;
    bottom: 2px;
    right: 2px;
    width: 14px;
    height: 14px;
    background: #4CAF50;
    border: 2px solid #0b0d12;
    border-radius: 50%;
}

.unified-chat__thread-body {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.unified-chat__thread-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.unified-chat__thread-name {
    font-size: 1rem;
    font-weight: 600;
    color: white;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.unified-chat__thread--unread .unified-chat__thread-name {
    font-weight: 700;
}

.unified-chat__thread-time {
    font-size: 0.75rem;
    color: rgba(255, 255, 255, 0.45);
    flex-shrink: 0;
}

.unified-chat__thread--unread .unified-chat__thread-time {
    color: #2aa78b;
}

.unified-chat__thread-bottom {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
}

.unified-chat__thread-preview {
    font-size: 0.85rem;
    color: rgba(255, 255, 255, 0.55);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
}

.unified-chat__thread--unread .unified-chat__thread-preview {
    color: rgba(255, 255, 255, 0.75);
}

.unified-chat__thread-badge {
    min-width: 22px;
    height: 22px;
    padding: 0 6px;
    background: linear-gradient(135deg, #2aa78b, #1b7a66);
    border-radius: 11px;
    font-size: 0.75rem;
    font-weight: 700;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

/* ========== DETAIL PANEL (Right) ========== */
.unified-chat__detail {
    display: none;
    flex-direction: column;
    width: 100%;
    height: 100%;
    background:
        radial-gradient(circle at 15% 10%, rgba(42, 167, 139, 0.12), transparent 45%),
        radial-gradient(circle at 85% 0%, rgba(59, 130, 246, 0.1), transparent 45%),
        linear-gradient(180deg, #101217 0%, #0b0d12 100%);
}

.unified-chat__placeholder {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    text-align: center;
    color: rgba(255, 255, 255, 0.5);
}

.unified-chat__placeholder-icon {
    font-size: 4rem;
    opacity: 0.4;
}

.unified-chat__placeholder h3 {
    font-size: 1.2rem;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.7);
    margin: 0;
}

.unified-chat__placeholder p {
    font-size: 0.9rem;
    margin: 0;
}

/* Chat Content */
.unified-chat__content {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.unified-chat__chat-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: max(env(safe-area-inset-top, 12px), 12px) 16px 12px;
    background: rgba(12, 14, 18, 0.9);
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    flex-shrink: 0;
}

.unified-chat__detail-back {
    display: none; /* Hidden on desktop */
    width: 40px;
    height: 40px;
    background: rgba(255, 255, 255, 0.08);
    border: none;
    border-radius: 12px;
    color: rgba(255, 255, 255, 0.8);
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
}

.unified-chat__chat-user {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
    min-width: 0;
    cursor: pointer;
}

.unified-chat__chat-avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: linear-gradient(135deg, #2aa78b, #3b82f6);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    overflow: hidden;
}

.unified-chat__chat-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.unified-chat__chat-info {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.unified-chat__chat-name {
    font-size: 1.05rem;
    font-weight: 600;
    color: white;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.unified-chat__chat-status {
    font-size: 0.8rem;
    color: rgba(255, 255, 255, 0.5);
}

.unified-chat__chat-status--online {
    color: #4CAF50;
}

.unified-chat__chat-status--ingame {
    color: #FF9800;
}

.unified-chat__chat-actions {
    display: flex;
    gap: 8px;
}

.unified-chat__action-btn {
    width: 40px;
    height: 40px;
    background: rgba(255, 255, 255, 0.08);
    border: none;
    border-radius: 12px;
    color: rgba(255, 255, 255, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
}

.unified-chat__action-btn:hover {
    background: rgba(255, 255, 255, 0.15);
    color: #2aa78b;
}

/* Messages */
.unified-chat__messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    -webkit-overflow-scrolling: touch;
}

.unified-chat__messages::-webkit-scrollbar {
    width: 4px;
}

.unified-chat__messages::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.15);
    border-radius: 2px;
}

/* Input Bar */
.unified-chat__input-bar {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    padding: 12px 16px calc(env(safe-area-inset-bottom, 12px) + 12px);
    background: rgba(12, 14, 18, 0.95);
    border-top: 1px solid rgba(255, 255, 255, 0.06);
    flex-shrink: 0;
}

.unified-chat__attach-btn {
    width: 44px;
    height: 44px;
    background: rgba(255, 255, 255, 0.08);
    border: none;
    border-radius: 50%;
    color: rgba(255, 255, 255, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
    flex-shrink: 0;
}

.unified-chat__attach-btn:hover {
    background: rgba(255, 255, 255, 0.15);
    color: #2aa78b;
}

.unified-chat__input-wrapper {
    flex: 1;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 22px;
    padding: 10px 16px;
}

.unified-chat__input-wrapper textarea {
    width: 100%;
    background: transparent;
    border: none;
    color: white;
    font-size: 1rem;
    font-family: inherit;
    line-height: 1.4;
    resize: none;
    outline: none;
    max-height: 120px;
}

.unified-chat__input-wrapper textarea::placeholder {
    color: rgba(255, 255, 255, 0.4);
}

.unified-chat__send-btn {
    width: 48px;
    height: 48px;
    background: linear-gradient(135deg, #2aa78b, #1b7a66);
    border: none;
    border-radius: 50%;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
    flex-shrink: 0;
}

.unified-chat__send-btn:hover {
    transform: scale(1.05);
}

.unified-chat__send-btn:active {
    transform: scale(0.95);
}

/* Attachment Menu */
.unified-chat__attach-menu {
    display: none;
    position: absolute;
    bottom: calc(100% + 8px);
    left: 16px;
    background: rgba(18, 20, 26, 0.98);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 16px;
    padding: 8px;
    gap: 4px;
    flex-direction: column;
    min-width: 160px;
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.4);
    z-index: 10;
}

.unified-chat__attach-menu--open {
    display: flex;
}

.unified-chat__attach-option {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    background: transparent;
    border: none;
    border-radius: 12px;
    color: rgba(255, 255, 255, 0.85);
    font-size: 0.95rem;
    cursor: pointer;
    transition: all 0.2s;
}

.unified-chat__attach-option i {
    width: 24px;
    color: #2aa78b;
}

.unified-chat__attach-option:hover {
    background: rgba(255, 255, 255, 0.1);
}

/* ========== RESPONSIVE: DESKTOP (Split View) ========== */
@media (min-width: 768px) {
    .unified-chat__threads {
        width: 340px;
        max-width: 340px;
        flex-shrink: 0;
    }

    .unified-chat__detail {
        display: flex;
        flex: 1;
    }

    .unified-chat__detail-back {
        display: none;
    }
}

/* ========== RESPONSIVE: MOBILE (Slide) ========== */
@media (max-width: 767px) {
    .unified-chat {
        position: relative;
    }

    .unified-chat__threads {
        position: absolute;
        inset: 0;
        z-index: 2;
        transform: translateX(0);
    }

    .unified-chat__detail {
        display: flex;
        position: absolute;
        inset: 0;
        z-index: 3;
        transform: translateX(100%);
    }

    /* When chat is open on mobile */
    .unified-chat--chat-open .unified-chat__threads {
        transform: translateX(-30%);
        opacity: 0.5;
        pointer-events: none;
    }

    .unified-chat--chat-open .unified-chat__detail {
        transform: translateX(0);
    }

    .unified-chat__detail-back {
        display: flex;
    }

    .unified-chat__placeholder {
        display: none;
    }
}

/* ========== RESPONSIVE: Smaller heights ========== */
@media (max-height: 650px) {
    .unified-chat__thread {
        padding: 10px;
    }

    .unified-chat__thread-avatar {
        width: 46px;
        height: 46px;
    }

    .unified-chat__messages {
        padding: 16px 14px;
    }
}
