:root {
    --primary-color: #07c160;
    --sidebar-bg: #28292c;
    /* PC WeChat Dark Sidebar */
    --list-bg: #e6e5e5;
    /* PC WeChat List Gray */
    --active-list-bg: #c5c4c4;
    --chat-bg: #f5f5f5;
    --border-color: #d1d1d1;
    --text-main: #333333;
    --received-bubble: #ffffff;
    --sent-bubble: #95ec69;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: "Microsoft YaHei", -apple-system, sans-serif;
}

img {
    max-width: 100%;
}

body {
    background: #ccc;
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
}

.app-container {
    width: 1100px;
    /* Slightly wider for better PC feel */
    height: 750px;
    /* Taller for better view */
    background: #fff;
    display: flex;
    box-shadow: 0 15px 50px rgba(0, 0, 0, 0.2);
    border-radius: 4px;
    overflow: hidden;
    /* CRITICAL: Prevent layout popping out */
}

/* Sidebar */
.sidebar {
    width: 55px;
    background: var(--sidebar-bg);
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 20px 0;
}

.sidebar i {
    font-size: 20px;
    color: #929292;
    cursor: pointer;
    transition: color 0.2s;
}

.nav-item {
    margin-bottom: 30px;
    color: #929292;
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
}

.nav-item.active {
    color: var(--primary-color);
}

.nav-item:hover {
    color: #fff;
}

#navMe {
    margin-top: auto;
}

.nav-label {
    display: none;
    /* Hidden on desktop */
}

.sidebar .user-avatar {
    width: 35px;
    height: 35px;
    border-radius: 2px;
    margin-bottom: 25px;
}

/* List Panel */
.list-panel {
    width: 250px;
    background: var(--list-bg);
    border-right: 1px solid var(--border-color);
}

.search-area {
    padding: 25px 12px 15px 12px;
    display: flex;
    gap: 8px;
}

.search-area input {
    flex: 1;
    background: #dcd9d8;
    border: none;
    border-radius: 2px;
    padding: 4px 8px;
    font-size: 12px;
    outline: none;
}

.search-area .add-btn {
    width: 24px;
    height: 24px;
    background: #dcd9d8;
    border-radius: 2px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    font-size: 12px;
}

.chat-items {
    height: calc(100% - 70px);
    overflow-y: auto;
}

.chat-item {
    display: flex;
    padding: 12px;
    cursor: pointer;
}

.chat-item:hover {
    background: #dcd9d8;
}

.chat-item.active {
    background: var(--active-list-bg);
}

.item-avatar {
    width: 40px;
    height: 40px;
    border-radius: 2px;
    margin-right: 10px;
}

.item-info {
    flex: 1;
    min-width: 0;
}

.item-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 2px;
}

.item-name {
    font-size: 14px;
    font-weight: 400;
    color: #000;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.item-time {
    font-size: 11px;
    color: #999;
}

.item-msg {
    font-size: 12px;
    color: #999;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Chat Panel */
.chat-panel {
    flex: 1;
    background: var(--chat-bg);
    display: flex;
    flex-direction: column;
    position: relative;
}

.chat-header {
    height: 50px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 20px;
    background: #f5f5f5;
}

.chat-messages {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
}

.message-item {
    display: flex;
    margin-bottom: 15px;
}

.message-item.sent {
    flex-direction: row-reverse;
}

.msg-avatar {
    width: 38px;
    height: 38px;
    border-radius: 4px;
    flex-shrink: 0;
    object-fit: cover;
}

.msg-content {
    max-width: 65%;
    margin: 0 12px;
    padding: 10px 14px;
    border-radius: 5px;
    font-size: 14px;
    word-break: break-all;
    position: relative;
    line-height: 1.5;
}

.msg-received .msg-content,
.received .msg-content {
    background: #fff;
    border: 1px solid #e1e1e1;
    color: #333;
}

.msg-sent .msg-content,
.sent .msg-content {
    background: #fff;
    /* Changed from green to white */
    border: 1px solid #e1e1e1;
    color: #333;
}

/* No background for images and large emojis */
.msg-content.msg-no-bg {
    background: transparent !important;
    border: none !important;
    padding: 0 !important;
    box-shadow: none !important;
}

.msg-content.msg-no-bg::after,
.msg-content.msg-no-bg::before {
    display: none !important;
}

/* Triangles */
.msg-received .msg-content::before {
    content: "";
    position: absolute;
    left: -7px;
    top: 10px;
    border-top: 6px solid transparent;
    border-bottom: 6px solid transparent;
    border-right: 7px solid #e1e1e1;
}

.msg-sent .msg-content::after {
    content: "";
    position: absolute;
    right: -7px;
    top: 10px;
    border-top: 6px solid transparent;
    border-bottom: 6px solid transparent;
    border-left: 7px solid #e1e1e1;
}

.chat-img {
    max-width: 250px;
    max-height: 250px;
    border-radius: 4px;
    cursor: pointer;
    display: block;
    margin-top: 5px;
}

/* Emoji Picker Premium */
.emoji-picker {
    position: absolute;
    bottom: 185px;
    left: 10px;
    width: 320px;
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 5px 25px rgba(0, 0, 0, 0.15);
    z-index: 2000;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.emoji-grid {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 5px;
    padding: 15px;
    max-height: 250px;
    overflow-y: auto;
}

.emoji-item {
    font-size: 22px;
    cursor: pointer;
    text-align: center;
    padding: 5px;
    border-radius: 4px;
    transition: background 0.2s;
}

.emoji-item:hover {
    background: #f0f0f0;
}

.emoji-tabs {
    background: #f7f7f7;
    height: 40px;
    display: flex;
    align-items: center;
    padding: 0 10px;
    border-top: 1px solid #eee;
    gap: 15px;
}

.emoji-tab {
    color: #888;
    font-size: 16px;
    cursor: pointer;
}

.emoji-tab.active {
    color: #444;
    background: #fff;
    padding: 5px 8px;
    border-radius: 4px;
}

.emoji-arrow {
    position: absolute;
    bottom: -8px;
    left: 21px;
    width: 0;
    height: 0;
    border-left: 8px solid transparent;
    border-right: 8px solid transparent;
    border-top: 8px solid #f7f7f7;
}

@media (max-width: 768px) {
    .emoji-picker {
        width: 90vw;
        left: 5vw;
        bottom: 120px;
    }
}

/* Input Area */
.chat-input-area {
    height: 180px;
    border-top: 1px solid var(--border-color);
    background: #fff;
    display: flex;
    flex-direction: column;
}

.input-toolbar {
    padding: 10px 20px;
    display: flex;
    gap: 15px;
    color: #666;
    font-size: 18px;
}

.input-toolbar i {
    cursor: pointer;
}

.input-toolbar i:hover {
    color: #000;
}

#msgText {
    flex: 1;
    border: none;
    padding: 0 20px;
    outline: none;
    resize: none;
    font-size: 14px;
    color: #333;
}

.input-footer {
    padding: 10px 20px;
    display: flex;
    justify-content: flex-end;
}

.send-btn {
    padding: 5px 25px;
    background: #f5f5f5;
    border: 1px solid #e5e5e5;
    border-radius: 2px;
    color: var(--primary-color);
    cursor: pointer;
    font-size: 14px;
}

.send-btn:hover {
    background: #e5e5e5;
}

/* Auth Page Styling */
.auth-page {
    background: linear-gradient(135deg, #07c160 0%, #059d4c 100%) !important;
    display: flex !important;
    justify-content: center !important;
    align-items: center !important;
    height: 100vh !important;
    width: 100vw !important;
    margin: 0 !important;
}

.auth-box {
    background: #fff;
    width: 380px;
    padding: 40px;
    border-radius: 8px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
    text-align: center;
    position: relative;
    z-index: 10;
}

.auth-box h2 {
    margin-bottom: 30px;
    color: #333;
    font-weight: 500;
}

.auth-form {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.auth-input {
    width: 100%;
    padding: 12px 15px;
    border: 1px solid #ddd;
    border-radius: 4px;
    outline: none;
    font-size: 14px;
    transition: border-color 0.2s;
}

.auth-input:focus {
    border-color: var(--primary-color);
}

.auth-btn {
    background: var(--primary-color);
    color: #fff;
    border: none;
    padding: 12px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 16px;
    font-weight: 500;
    margin-top: 10px;
    transition: background 0.2s;
}

.auth-btn:hover {
    background: #06ad56;
}

.auth-switch {
    margin-top: 25px;
    font-size: 13px;
    color: #999;
}

.auth-switch a {
    color: var(--primary-color);
    text-decoration: none;
    margin-left: 5px;
    font-weight: 500;
}

.auth-switch a:hover {
    text-decoration: underline;
}

.toast {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.7);
    color: #fff;
    padding: 10px 25px;
    border-radius: 20px;
    z-index: 10000;
    display: none;
    font-size: 14px;
}

.custom-context-menu {
    position: absolute;
    background: #fff;
    border: 1px solid #ddd;
    border-radius: 4px;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.1);
    z-index: 10000;
    min-width: 120px;
    padding: 5px 0;
}

.menu-item {
    padding: 8px 20px;
    font-size: 14px;
    color: #333;
    cursor: pointer;
    transition: background 0.2s;
}

.menu-item:hover {
    background: #f5f5f5;
}

/* --- Mobile Responsive (WeChat Style) --- */
@media (max-width: 768px) {
    body {
        background: #f7f7f7;
        height: 100dvh !important;
        display: flex !important;
        flex-direction: column !important;
        overflow: hidden !important;
    }

    .app-container {
        width: 100vw !important;
        flex: 1 !important;
        height: auto !important;
        flex-direction: column !important;
        border-radius: 0;
        box-shadow: none;
        display: flex !important;
        overflow: hidden !important;
    }

    /* Fixed Top Header for Mobile */
    .mobile-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        background: #ededed;
        padding: 10px 15px;
        height: 50px;
        border-bottom: 1px solid #ddd;
    }

    .mobile-header span {
        font-size: 17px;
        font-weight: 500;
        color: #000;
    }

    .header-icons {
        display: flex;
        gap: 20px;
        font-size: 18px;
        color: #000;
    }

    /* Sidebar to Bottom Nav */
    .sidebar {
        order: 3;
        width: 100% !important;
        height: 62px !important;
        flex-direction: row !important;
        justify-content: space-evenly !important;
        /* Perfect spacing */
        align-items: stretch !important;
        padding: 0 !important;
        background: #f7f7f7 !important;
        border-top: 1px solid #e1e1e1 !important;
    }

    .nav-item {
        flex: 1 !important;
        display: flex !important;
        flex-direction: column !important;
        align-items: center !important;
        justify-content: flex-start !important;
        padding-top: 10px !important;
        /* Force icons down */
        gap: 0px !important;
        color: #515151 !important;
        cursor: pointer;
        position: relative;
        margin-top: 0 !important;
        padding-bottom: env(safe-area-inset-bottom) !important;
    }

    .nav-item i {
        margin-bottom: 2px !important;
        font-size: 25px !important;
        color: inherit !important;
        font-weight: 300 !important;
    }

    .nav-label {
        display: block !important;
        font-size: 10px !important;
        color: inherit !important;
        line-height: 1 !important;
    }

    .nav-item.active {
        color: #07c160 !important;
    }

    .desktop-only {
        display: none !important;
    }

    .sidebar .user-avatar {
        display: none;
    }

    /* List Panel */
    .list-panel {
        width: 100% !important;
        flex: 1;
        background: #fff !important;
    }

    .search-area {
        background: #fff !important;
        padding: 10px !important;
    }

    .search-area input {
        background: #f7f7f7 !important;
        height: 35px;
    }

    /* Message Panel (Hidden by default on mobile) */
    .chat-panel {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        width: 100vw !important;
        height: 100vh !important;
        z-index: 1000;
    }

    body.chat-view .chat-panel {
        display: flex !important;
    }

    body.chat-view .mobile-header,
    body.chat-view .sidebar,
    body.chat-view .list-panel {
        display: none !important;
    }

    /* Mobile Chat Header */
    .chat-header {
        background: #ededed !important;
        height: 50px !important;
    }

    .mobile-back {
        display: block !important;
        font-size: 20px;
        margin-right: 15px;
        color: #000;
    }

    /* Modals for Mobile */
    #settingsModal,
    #addFriendModal,
    #requestsModal {
        left: 0 !important;
        width: 100% !important;
        height: 100% !important;
    }

    .chat-input-area {
        height: auto !important;
        min-height: 100px;
        padding-bottom: env(safe-area-inset-bottom);
    }
}

/* Hide mobile header on desktop */
.mobile-header {
    display: none;
}

.mobile-back {
    display: none;
}