.app-layout {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 16px 0;
    gap: 8px;
    flex-shrink: 0;
}

.sidebar-header {
    margin-bottom: 16px;
}

.user-avatar {
    width: 44px;
    height: 44px;
    border-radius: var(--radius-md);
    overflow: hidden;
    cursor: pointer;
    position: relative;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
}

.user-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.avatar-placeholder {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 600;
    font-size: 18px;
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 1;
}

.nav-item {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-md);
    border: none;
    background: transparent;
    color: var(--text-tertiary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
    position: relative;
}

.nav-item:hover {
    background: var(--bg-hover);
    color: var(--text-secondary);
}

.nav-item.active {
    color: var(--primary);
    background: rgba(255, 107, 53, 0.1);
}

.nav-item svg {
    width: 22px;
    height: 22px;
}

.nav-badge {
    position: absolute;
    top: 4px;
    right: 4px;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    background: var(--danger);
    color: white;
    font-size: 11px;
    font-weight: 600;
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
}

.sidebar-footer {
    margin-top: auto;
}

.theme-toggle {
    width: 44px;
    height: 44px;
    border-radius: var(--radius-md);
    border: none;
    background: transparent;
    color: var(--text-tertiary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
}

.theme-toggle:hover {
    background: var(--bg-hover);
    color: var(--text-secondary);
}

.theme-toggle svg {
    width: 20px;
    height: 20px;
}

[data-theme="dark"] .icon-sun { display: none; }
[data-theme="dark"] .icon-moon { display: block; }
[data-theme="light"] .icon-sun { display: block; }
[data-theme="light"] .icon-moon { display: none; }

.panel-list {
    width: var(--panel-list-width);
    background: var(--bg-primary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

.panel-header {
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border);
}

.panel-header h2 {
    font-size: 20px;
    font-weight: 700;
}

.panel-actions {
    display: flex;
    gap: 4px;
}

.search-bar {
    padding: 0 16px 12px;
    animation: slideDown 0.2s ease;
}

.search-bar input {
    width: 100%;
    padding: 10px 14px;
    background: var(--bg-tertiary);
    border: 2px solid transparent;
    border-radius: var(--radius-md);
    font-size: 14px;
    color: var(--text-primary);
    outline: none;
    transition: all var(--transition-fast);
    font-family: var(--font-family);
}

.search-bar input:focus {
    border-color: var(--primary);
    background: var(--bg-primary);
}

.panel-content {
    flex: 1;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--bg-hover) transparent;
}

.panel-content::-webkit-scrollbar {
    width: 4px;
}

.panel-content::-webkit-scrollbar-track {
    background: transparent;
}

.panel-content::-webkit-scrollbar-thumb {
    background: var(--bg-hover);
    border-radius: var(--radius-full);
}

.chat-list {
    display: flex;
    flex-direction: column;
}

.chat-item {
    display: flex;
    align-items: center;
    padding: 12px 20px;
    cursor: pointer;
    transition: background var(--transition-fast);
    gap: 12px;
    position: relative;
}

.chat-item:hover {
    background: var(--bg-hover);
}

.chat-item.active {
    background: var(--bg-tertiary);
}

.chat-item-avatar {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-md);
    overflow: hidden;
    flex-shrink: 0;
    position: relative;
    background: linear-gradient(135deg, var(--primary-light), var(--secondary));
}

.chat-item-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.chat-item-avatar .avatar-text {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 600;
    font-size: 18px;
}

.online-dot {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 12px;
    height: 12px;
    background: var(--success);
    border: 2px solid var(--bg-primary);
    border-radius: 50%;
}

.chat-item-info {
    flex: 1;
    min-width: 0;
}

.chat-item-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 4px;
}

.chat-item-name {
    font-weight: 600;
    font-size: 15px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-item-time {
    font-size: 12px;
    color: var(--text-tertiary);
    flex-shrink: 0;
    margin-left: 8px;
}

.chat-item-bottom {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chat-item-msg {
    font-size: 13px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
}

.chat-item-badge {
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    background: var(--primary);
    color: white;
    font-size: 11px;
    font-weight: 600;
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    margin-left: 8px;
}

.panel-chat {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    background: var(--bg-secondary);
}

.empty-chat {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-tertiary);
    gap: 16px;
}

.empty-logo {
    width: 80px;
    height: 80px;
    opacity: 0.5;
}

.empty-chat p {
    font-size: 15px;
}

.chat-view {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.chat-header {
    padding: 12px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border);
}

.chat-header-info {
    flex: 1;
    min-width: 0;
}

.chat-header-name {
    font-weight: 600;
    font-size: 16px;
}

.chat-header-status {
    font-size: 12px;
    color: var(--text-secondary);
}

.chat-header-actions {
    display: flex;
    gap: 4px;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px 20px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    scrollbar-width: thin;
    scrollbar-color: var(--bg-hover) transparent;
}

.chat-messages::-webkit-scrollbar {
    width: 4px;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: var(--bg-hover);
    border-radius: var(--radius-full);
}

.message {
    display: flex;
    gap: 8px;
    max-width: 70%;
    animation: slideUp 0.2s ease;
}

.message.sent {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.message.received {
    align-self: flex-start;
}

.message-avatar {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-sm);
    overflow: hidden;
    flex-shrink: 0;
    background: linear-gradient(135deg, var(--primary-light), var(--secondary));
}

.message-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.message-content {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.message-bubble {
    padding: 10px 14px;
    border-radius: var(--radius-lg);
    font-size: 14px;
    line-height: 1.5;
    word-break: break-word;
    position: relative;
}

.message.sent .message-bubble {
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    color: white;
    border-bottom-right-radius: var(--radius-sm);
}

.message.received .message-bubble {
    background: var(--bg-primary);
    color: var(--text-primary);
    border-bottom-left-radius: var(--radius-sm);
    box-shadow: var(--shadow-sm);
}

.message-meta {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    color: var(--text-tertiary);
    padding: 0 4px;
}

.message.sent .message-meta {
    justify-content: flex-end;
}

.message-status {
    display: flex;
    align-items: center;
}

.message-status svg {
    width: 14px;
    height: 14px;
}

.message-status.sent { color: var(--text-tertiary); }
.message-status.delivered { color: var(--info); }
.message-status.read { color: var(--success); }
.message-status.sending { color: var(--text-tertiary); opacity: 0.6; }
.message-status.failed { color: var(--danger); font-size: 11px; font-weight: 500; }

.message.sending .message-bubble {
    opacity: 0.7;
}

.message.failed .message-bubble {
    border: 1px dashed var(--danger);
    opacity: 0.8;
}

.message-voice {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 120px;
    cursor: pointer;
}

.voice-wave {
    display: flex;
    align-items: center;
    gap: 2px;
    flex: 1;
}

.voice-wave span {
    width: 3px;
    background: currentColor;
    border-radius: var(--radius-full);
    opacity: 0.6;
    animation: voiceWave 0.5s ease-in-out infinite alternate;
}

.voice-wave span:nth-child(1) { height: 8px; animation-delay: 0s; }
.voice-wave span:nth-child(2) { height: 14px; animation-delay: 0.1s; }
.voice-wave span:nth-child(3) { height: 10px; animation-delay: 0.2s; }
.voice-wave span:nth-child(4) { height: 18px; animation-delay: 0.3s; }
.voice-wave span:nth-child(5) { height: 12px; animation-delay: 0.4s; }

@keyframes voiceWave {
    from { transform: scaleY(0.5); }
    to { transform: scaleY(1); }
}

.voice-duration {
    font-size: 12px;
    opacity: 0.8;
}

.typing-indicator {
    padding: 8px 20px;
    font-size: 13px;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 8px;
}

.typing-dots {
    display: flex;
    gap: 3px;
}

.typing-dots span {
    width: 6px;
    height: 6px;
    background: var(--text-tertiary);
    border-radius: 50%;
    animation: typingBounce 1.2s ease-in-out infinite;
}

.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingBounce {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-6px); }
}

.chat-input-area {
    padding: 12px 16px;
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: var(--bg-primary);
    border-top: 1px solid var(--border);
}

.input-wrapper {
    flex: 1;
    position: relative;
}

.input-wrapper textarea {
    width: 100%;
    padding: 10px 14px;
    background: var(--bg-tertiary);
    border: 2px solid transparent;
    border-radius: var(--radius-lg);
    font-size: 14px;
    color: var(--text-primary);
    resize: none;
    outline: none;
    max-height: 120px;
    min-height: 42px;
    line-height: 1.5;
    font-family: var(--font-family);
    transition: border-color var(--transition-fast);
}

.input-wrapper textarea:focus {
    border-color: var(--primary);
}

.send-btn {
    width: 42px;
    height: 42px;
    border-radius: var(--radius-md);
    border: none;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
    flex-shrink: 0;
}

.send-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(255, 107, 53, 0.4);
}

.send-btn:active {
    transform: scale(0.95);
}

.send-btn svg {
    width: 18px;
    height: 18px;
}

.date-divider {
    text-align: center;
    padding: 12px 0;
    font-size: 12px;
    color: var(--text-tertiary);
}

.date-divider span {
    background: var(--bg-secondary);
    padding: 4px 12px;
    border-radius: var(--radius-full);
}

@media (max-width: 768px) {
    .panel-list {
        width: 100%;
    }
    .panel-chat {
        position: fixed;
        inset: 0;
        z-index: 100;
        transform: translateX(100%);
        transition: transform var(--transition-normal);
    }
    .panel-chat.show {
        transform: translateX(0);
    }
    .sidebar {
        display: none;
    }
    .message {
        max-width: 85%;
    }
}
