/* CSS Variables */
:root {
    --primary-blue: #3370FF;
    --bg-white: #FFFFFF;
    --text-dark: #1F2329;
    --text-gray: #646A73;
    --text-light: #8F959E;
    --border-color: #E5E6EB;
    --avatar-orange: #F86B00;
    --avatar-purple: #8B5CF6;
    --avatar-pink: #FF4D94;
    --avatar-blue: #3370FF;
    --tag-blue: #E8F0FE;
    --tag-blue-text: #3370FF;
    --tag-orange: #FFF3E8;
    --tag-orange-text: #F86B00;
    --tag-light-blue: #E8F4FD;
    --tag-light-blue-text: #0089D6;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    --gradient-bg: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

/* Reset */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'PingFang SC', 'Microsoft YaHei', sans-serif;
    background: #FFFFFF;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: 0;
}

/* Main Container */
.container {
    width: 100%;
    max-width: 430px;
    min-height: 100vh;
    background: var(--bg-white);
    display: flex;
    flex-direction: column;
    position: relative;
}

/* Header */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    background: var(--bg-white);
    position: sticky;
    top: 0;
    z-index: 10;
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    transition: opacity 0.2s;
}

.user-profile:hover {
    opacity: 0.8;
}

.avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 600;
    color: white;
    position: relative;
    overflow: hidden;
}

.avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.avatar-blue {
    background: var(--avatar-blue);
}

.avatar-orange {
    background: var(--avatar-orange);
}

.avatar-purple {
    background: var(--avatar-purple);
}

.avatar-pink {
    background: var(--avatar-pink);
}

.avatar-gradient {
    background: linear-gradient(135deg, #4A90E2, #667eea);
}

.online-dot {
    position: absolute;
    bottom: 2px;
    right: 2px;
    width: 10px;
    height: 10px;
    background: #34C759;
    border: 2px solid white;
    border-radius: 50%;
}

.user-info {
    display: flex;
    flex-direction: column;
}

.user-name {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-dark);
}

.company {
    font-size: 12px;
    color: var(--text-gray);
    margin-top: 2px;
}

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

.icon-btn {
    width: 36px;
    height: 36px;
    border: none;
    background: transparent;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    color: var(--text-dark);
    transition: background 0.2s;
}

.icon-btn:hover {
    background: var(--border-color);
}

/* Tab Navigation */
.tab-nav {
    display: flex;
    align-items: center;
    padding: 8px 20px;
    gap: 12px;
}

.filter-btn {
    width: 32px;
    height: 32px;
    border: none;
    background: var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-gray);
}

.tabs {
    display: flex;
    background: #F5F6F7;
    border-radius: 20px;
    padding: 4px;
}

.tab {
    padding: 8px 16px;
    border: none;
    background: transparent;
    border-radius: 16px;
    font-size: 14px;
    color: var(--text-gray);
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 4px;
}

.tab.active {
    background: var(--bg-white);
    color: var(--primary-blue);
    font-weight: 500;
    box-shadow: var(--shadow);
}

.unread-count {
    background: var(--primary-blue);
    color: white;
    font-size: 11px;
    padding: 2px 6px;
    border-radius: 10px;
}

/* Announcement */
.announcement {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    background: #FFF8E6;
    font-size: 13px;
    color: var(--text-dark);
}

.announcement-icon {
    font-size: 16px;
}

.announcement a {
    color: var(--primary-blue);
    text-decoration: none;
}

/* Message List */
.message-list {
    flex: 1;
    overflow-y: auto;
    padding-bottom: 80px;
}

.message-item {
    display: flex;
    align-items: flex-start;
    padding: 14px 20px;
    gap: 12px;
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    transition: background 0.2s;
}

.message-item:hover {
    background: #F9FAFB;
}

.message-item .avatar {
    flex-shrink: 0;
}

.message-content {
    flex: 1;
    min-width: 0;
}

.message-header {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 4px;
}

.contact-name {
    font-size: 15px;
    font-weight: 500;
    color: var(--text-dark);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tag {
    font-size: 11px;
    padding: 2px 6px;
    border-radius: 4px;
    flex-shrink: 0;
}

.tag-robot {
    background: var(--tag-orange);
    color: var(--tag-orange-text);
}

.tag-all {
    background: var(--tag-blue);
    color: var(--tag-blue-text);
}

.tag-external {
    background: var(--tag-light-blue);
    color: var(--tag-light-blue-text);
}

.last-message {
    font-size: 13px;
    color: var(--text-gray);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.message-date {
    font-size: 12px;
    color: var(--text-light);
    white-space: nowrap;
    flex-shrink: 0;
}

/* Bottom Navigation */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 100%;
    max-width: 430px;
    background: var(--bg-white);
    border-top: 1px solid var(--border-color);
    z-index: 100;
}

.nav-bg-image {
    width: 100%;
    height: auto;
    display: block;
}

.nav-clickable-areas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
}

.nav-click-area {
    flex: 1;
    cursor: pointer;
    transition: background 0.2s;
}

.nav-click-area:hover {
    background: rgba(51, 112, 255, 0.08);
}

.nav-click-area:active {
    background: rgba(51, 112, 255, 0.15);
}

/* Overlay */
.overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
    z-index: 200;
}

.overlay.active {
    opacity: 1;
    visibility: visible;
}

/* Popup Drawer - Two Column Layout */
.popup-drawer {
    position: fixed;
    top: 0;
    left: -100%;
    width: 100%;
    max-width: 420px;
    height: 100%;
    background: var(--bg-white);
    z-index: 300;
    transition: left 0.3s ease;
    display: flex;
    box-shadow: 4px 0 20px rgba(0, 0, 0, 0.15);
}

.popup-drawer.active {
    left: 0;
}

/* Left Sidebar */
.popup-sidebar {
    width: 80px;
    min-width: 80px;
    background: #F5F6F7;
    padding: 20px 8px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    border-right: 1px solid var(--border-color);
}

.sidebar-account {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    padding: 8px 4px;
    border-radius: 8px;
    transition: background 0.2s;
}

.sidebar-account:hover {
    background: rgba(0, 0, 0, 0.05);
}

.sidebar-account.active {
    background: rgba(51, 112, 255, 0.1);
}

.sidebar-avatar {
    width: 44px;
    height: 44px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    font-weight: 600;
    color: white;
    position: relative;
}

.sidebar-avatar-blue {
    background: linear-gradient(135deg, #3370FF, #5B8DEF);
}

.sidebar-avatar-feishu {
    background: #E8F0FE;
}

.sidebar-avatar-add {
    background: transparent;
    border: 2px dashed #C4C6CC;
}

.sidebar-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background: #FF3B30;
    color: white;
    font-size: 10px;
    padding: 1px 4px;
    border-radius: 8px;
    font-weight: 500;
}

.sidebar-label {
    font-size: 11px;
    color: var(--text-gray);
    text-align: center;
    line-height: 1.2;
    max-width: 70px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Right Content Area */
.popup-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    background: var(--bg-white);
}

.popup-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    padding: 24px 16px 16px;
    background: var(--bg-white);
}

.popup-avatar {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: linear-gradient(135deg, #3370FF, #5B8DEF);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    font-weight: 600;
}

.popup-header-right {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 8px;
}

.status-btn {
    padding: 6px 14px;
    border: 1px solid var(--border-color);
    background: var(--bg-white);
    border-radius: 16px;
    color: var(--primary-blue);
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
}

.status-btn:hover {
    background: #F5F6F7;
    border-color: var(--primary-blue);
}

.qr-icon {
    display: flex;
    align-items: center;
    gap: 2px;
    cursor: pointer;
    padding: 4px;
}

.qr-arrow {
    color: #C4C6CC;
    font-size: 18px;
    font-weight: 300;
}

.popup-user-info {
    padding: 0 16px 16px;
}

.popup-name {
    font-size: 20px;
    font-weight: 600;
    color: var(--text-dark);
    margin-bottom: 6px;
}

.company-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
}

.company-name {
    font-size: 13px;
    color: var(--text-gray);
}

.verified-badge {
    display: flex;
    align-items: center;
    gap: 4px;
    color: #34C759;
    font-size: 12px;
    font-weight: 500;
}

.signature-input {
    width: 100%;
    padding: 10px 12px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    color: var(--text-light);
    background: #F5F6F7;
}

.signature-input:focus {
    outline: none;
    background: #EEEEF0;
}

.signature-input::placeholder {
    color: var(--text-light);
}

.popup-menu {
    flex: 1;
    padding: 8px 0;
    border-top: 1px solid var(--border-color);
}

.menu-item {
    display: flex;
    align-items: center;
    padding: 14px 16px;
    gap: 14px;
    cursor: pointer;
    transition: background 0.2s;
}

.menu-item:hover {
    background: #F5F6F7;
}

.menu-icon {
    width: 22px;
    height: 22px;
    flex-shrink: 0;
}

.menu-item>span:nth-child(2) {
    flex: 1;
    font-size: 15px;
    color: var(--text-dark);
}

.menu-badge {
    background: #F5F6F7;
    color: var(--text-gray);
    font-size: 12px;
    padding: 2px 8px;
    border-radius: 10px;
}

.menu-arrow {
    margin-left: auto;
}

/* Mobile Responsiveness for Popup */
@media (max-width: 430px) {
    .popup-drawer {
        max-width: 100%;
    }

    .popup-sidebar {
        width: 72px;
        min-width: 72px;
        padding: 16px 6px;
    }

    .sidebar-avatar {
        width: 40px;
        height: 40px;
    }

    .sidebar-label {
        font-size: 10px;
        max-width: 60px;
    }
}

/* Mobile Responsiveness */
@media (max-width: 430px) {
    body {
        background: var(--bg-white);
    }

    .container {
        box-shadow: none;
        max-width: 100%;
    }

    .bottom-nav {
        max-width: 100%;
    }
}

/* Desktop Enhancement */
@media (min-width: 768px) {
    body {
        padding: 20px;
        align-items: center;
    }

    .container {
        border-radius: 24px;
        min-height: calc(100vh - 40px);
        max-height: calc(100vh - 40px);
        overflow: hidden;
    }

    .message-list {
        max-height: calc(100vh - 280px);
    }

    .bottom-nav {
        border-radius: 0 0 24px 24px;
        position: absolute;
    }
}

/* Smooth Scrollbar */
.message-list::-webkit-scrollbar {
    width: 4px;
}

.message-list::-webkit-scrollbar-track {
    background: transparent;
}

.message-list::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 2px;
}

/* Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message-item {
    animation: fadeIn 0.3s ease forwards;
}

/* Settings Modal */
.settings-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 400;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.settings-modal.active {
    opacity: 1;
    visibility: visible;
}

.settings-content {
    background: var(--bg-white);
    border-radius: 16px;
    width: 90%;
    max-width: 360px;
    max-height: 90vh;
    overflow: hidden;
    transform: scale(0.9);
    transition: transform 0.3s ease;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
}

.settings-modal.active .settings-content {
    transform: scale(1);
}

.settings-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
}

.settings-header h3 {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-dark);
    margin: 0;
}

.settings-close {
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    transition: background 0.2s;
}

.settings-close:hover {
    background: #F5F6F7;
}

.settings-body {
    padding: 24px 20px;
}

.settings-avatar-preview {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-bottom: 24px;
}

.avatar-preview {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: linear-gradient(135deg, #3370FF, #5B8DEF);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    font-weight: 600;
    margin-bottom: 8px;
    overflow: hidden;
}

.avatar-preview img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.avatar-hint {
    font-size: 12px;
    color: var(--text-light);
}

.settings-form {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.form-group label {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-dark);
}

.form-group input {
    padding: 12px 14px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 14px;
    color: var(--text-dark);
    transition: all 0.2s;
}

.form-group input:focus {
    outline: none;
    border-color: var(--primary-blue);
    box-shadow: 0 0 0 3px rgba(51, 112, 255, 0.1);
}

.form-group input::placeholder {
    color: var(--text-light);
}

.settings-footer {
    display: flex;
    gap: 12px;
    padding: 16px 20px;
    border-top: 1px solid var(--border-color);
}

.btn-cancel,
.btn-save {
    flex: 1;
    padding: 12px 20px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-cancel {
    background: #F5F6F7;
    border: none;
    color: var(--text-dark);
}

.btn-cancel:hover {
    background: #EEEEF0;
}

.btn-save {
    background: var(--primary-blue);
    border: none;
    color: white;
}

.btn-save:hover {
    background: #2860E1;
}

/* Avatar with image support */
.avatar.has-image,
.popup-avatar.has-image,
.avatar-preview.has-image,
.sidebar-avatar.has-image {
    padding: 0;
    overflow: hidden;
}

.avatar.has-image img,
.popup-avatar.has-image img,
.avatar-preview.has-image img,
.sidebar-avatar.has-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Avatar Upload */
.avatar-upload-group {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.btn-upload {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 10px 16px;
    background: #F5F6F7;
    border: 1px dashed var(--border-color);
    border-radius: 8px;
    font-size: 14px;
    color: var(--text-dark);
    cursor: pointer;
    transition: all 0.2s;
}

.btn-upload:hover {
    background: #EEEEF0;
    border-color: var(--primary-blue);
    color: var(--primary-blue);
}

.btn-upload svg {
    flex-shrink: 0;
}

.upload-hint {
    font-size: 12px;
    color: var(--text-light);
}

.upload-hint.success {
    color: #34C759;
}

/* Clickable elements */
.clickable {
    cursor: pointer;
    transition: opacity 0.2s;
}

.clickable:hover {
    opacity: 0.7;
}