:root {
    --bg-dark: #0a0e17;
    --bg-panel: #111927;
    --bg-hover: #1a2338;
    --bg-input: #0d1421;
    --text-primary: #f0f4ff;
    --text-secondary: #8896b5;
    --text-tertiary: #5a6a8a;
    --accent-color: #7c6cf0;
    --accent-hover: #6a5cd9;
    --accent-light: rgba(124, 108, 240, 0.15);
    --msg-sent: #7c6cf0;
    --msg-sent-hover: #6a5cd9;
    --msg-received: #1a2338;
    --border-color: #1a2338;
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.5);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 18px;
    --radius-xl: 24px;
    --transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
}

body {
    background-color: var(--bg-dark);
    color: var(--text-primary);
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
}

.app-container {
    display: flex;
    width: 100%;
    max-width: 1400px;
    height: 100vh;
    background-color: var(--bg-panel);
    position: relative;
    overflow: hidden;
}

/* ==========================================
   SIDEBAR - LISTA DE CONTATOS
   ========================================== */
.sidebar {
    width: 360px;
    min-width: 320px;
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    background-color: var(--bg-panel);
    z-index: 2;
    transition: var(--transition);
}

.sidebar-header {
    padding: 16px 20px;
    background-color: var(--bg-panel);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
    min-height: 72px;
}

.logo-container {
    display: flex;
    align-items: center;
    gap: 10px;
}

.logo-icon {
    font-size: 28px;
    line-height: 1;
}

.sidebar-header h2 {
    font-size: 20px;
    font-weight: 700;
    background: linear-gradient(135deg, var(--accent-color), #a78bfa);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.btn-icon {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
    width: 40px;
    height: 40px;
}

.btn-icon:hover {
    background-color: var(--bg-hover);
    color: var(--text-primary);
}

.btn-icon:active {
    transform: scale(0.92);
}

.search-bar {
    padding: 12px 20px;
    background-color: var(--bg-panel);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 8px;
    animation: slideDown 0.3s ease;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

#search-input {
    flex: 1;
    padding: 10px 16px;
    border-radius: var(--radius-xl);
    border: 1px solid var(--border-color);
    background-color: var(--bg-input);
    color: var(--text-primary);
    font-size: 14px;
    outline: none;
    transition: var(--transition);
}

#search-input:focus {
    border-color: var(--accent-color);
    box-shadow: 0 0 0 3px var(--accent-light);
}

#search-input::placeholder {
    color: var(--text-tertiary);
}

.btn-close-search {
    width: 36px;
    height: 36px;
}

.contacts-list {
    flex: 1;
    overflow-y: auto;
    padding: 4px 0;
}

.contacts-list::-webkit-scrollbar {
    width: 4px;
}

.contacts-list::-webkit-scrollbar-track {
    background: transparent;
}

.contacts-list::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 10px;
}

.contact-item {
    display: flex;
    align-items: center;
    padding: 12px 20px;
    cursor: pointer;
    transition: var(--transition);
    border-bottom: 1px solid rgba(255, 255, 255, 0.02);
    position: relative;
}

.contact-item:hover {
    background-color: var(--bg-hover);
}

.contact-item.active {
    background-color: var(--accent-light);
    border-left: 3px solid var(--accent-color);
}

.contact-item:active {
    transform: scale(0.98);
}

.avatar-container {
    position: relative;
    flex-shrink: 0;
    margin-right: 14px;
}

.contact-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid transparent;
    transition: var(--transition);
}

.contact-item.active .contact-avatar {
    border-color: var(--accent-color);
}

.status-dot {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: 2px solid var(--bg-panel);
    background-color: #4ade80;
    transition: var(--transition);
}

.status-dot.offline {
    background-color: #64748b;
}

.contact-info {
    flex: 1;
    min-width: 0;
}

.contact-info h4 {
    font-size: 15px;
    font-weight: 600;
    margin-bottom: 3px;
    color: var(--text-primary);
}

.contact-info .last-message {
    font-size: 13px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: flex;
    align-items: center;
    gap: 4px;
}

.contact-info .last-message .timestamp {
    font-size: 11px;
    color: var(--text-tertiary);
    flex-shrink: 0;
}

.contact-item .unread-badge {
    background-color: var(--accent-color);
    color: white;
    font-size: 11px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: var(--radius-xl);
    min-width: 20px;
    text-align: center;
    flex-shrink: 0;
}

/* ==========================================
   CHAT AREA
   ========================================== */
.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    background-color: var(--bg-dark);
    position: relative;
}

.chat-header {
    padding: 12px 20px;
    background-color: var(--bg-panel);
    border-bottom: 1px solid var(--border-color);
    min-height: 72px;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

.btn-back {
    display: none;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    transition: var(--transition);
    align-items: center;
    justify-content: center;
}

.btn-back:hover {
    background-color: var(--bg-hover);
    color: var(--text-primary);
}

.chat-user-info {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
    min-width: 0;
}

.chat-user-info .avatar-container {
    margin-right: 0;
}

.chat-header-avatar {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid var(--border-color);
    display: none;
    animation: fadeIn 0.3s ease;
}

.chat-header-avatar[style*="display: block"] {
    display: block !important;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: scale(0.8);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.chat-user-info .status-dot {
    width: 10px;
    height: 10px;
    border-width: 2px;
    display: none;
}

.chat-header-avatar[style*="display: block"] ~ .status-dot {
    display: block;
}

.current-chat-info {
    flex: 1;
    min-width: 0;
}

.current-chat-info h3 {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.status-text {
    font-size: 12px;
    color: var(--text-secondary);
}

.status-text.online {
    color: #4ade80;
}

.status-text.typing {
    color: var(--accent-color);
    animation: pulse 1s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.chat-actions {
    display: flex;
    gap: 4px;
}

.btn-more {
    width: 40px;
    height: 40px;
}

/* ==========================================
   MESSAGES CONTAINER
   ========================================== */
.messages-container {
    flex: 1;
    padding: 20px 24px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
    background-image: 
        radial-gradient(ellipse at 20% 50%, rgba(124, 108, 240, 0.03) 0%, transparent 50%),
        radial-gradient(ellipse at 80% 50%, rgba(124, 108, 240, 0.03) 0%, transparent 50%);
}

.messages-container::-webkit-scrollbar {
    width: 4px;
}

.messages-container::-webkit-scrollbar-track {
    background: transparent;
}

.messages-container::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 10px;
}

.empty-state {
    margin: auto;
    text-align: center;
    color: var(--text-secondary);
    padding: 40px 20px;
}

.empty-state-icon {
    font-size: 48px;
    margin-bottom: 16px;
    display: block;
}

.empty-state h3 {
    color: var(--text-primary);
    margin-bottom: 8px;
    font-weight: 600;
}

.empty-state p {
    color: var(--text-tertiary);
    font-size: 14px;
}

/* ==========================================
   MESSAGES
   ========================================== */
.message {
    max-width: 70%;
    padding: 10px 16px;
    border-radius: var(--radius-lg);
    font-size: 14px;
    line-height: 1.6;
    position: relative;
    word-break: break-word;
    animation: messageAppear 0.25s ease;
}

@keyframes messageAppear {
    from {
        opacity: 0;
        transform: translateY(10px) scale(0.96);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.message.received {
    background-color: var(--msg-received);
    align-self: flex-start;
    border-bottom-left-radius: 4px;
    box-shadow: var(--shadow-sm);
}

.message.sent {
    background: linear-gradient(135deg, var(--msg-sent), var(--msg-sent-hover));
    align-self: flex-end;
    border-bottom-right-radius: 4px;
    box-shadow: var(--shadow-sm);
}

.message .message-content {
    margin-bottom: 4px;
}

.message .message-time {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 4px;
    font-size: 10px;
    color: rgba(255, 255, 255, 0.5);
    margin-top: 2px;
}

.message.sent .message-time {
    color: rgba(255, 255, 255, 0.6);
}

.message .checkmark {
    font-size: 11px;
    color: rgba(255, 255, 255, 0.4);
    transition: var(--transition);
}

.message.sent.read .checkmark {
    color: #a5b4fc;
}

.message.sent .message-time .checkmark.delivered {
    color: rgba(255, 255, 255, 0.4);
}

.message.sent.read .message-time .checkmark.delivered {
    color: #a5b4fc;
}

/* Typing Indicator */
.typing-bubble {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 12px 20px !important;
    background-color: var(--msg-received) !important;
    border-bottom-left-radius: 4px !important;
}

.typing-bubble .dot {
    width: 7px;
    height: 7px;
    background-color: var(--text-secondary);
    border-radius: 50%;
    animation: typingBounce 1.4s infinite ease-in-out;
}

.typing-bubble .dot:nth-child(2) { animation-delay: 0.15s; }
.typing-bubble .dot:nth-child(3) { animation-delay: 0.3s; }

@keyframes typingBounce {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-8px); }
}

/* ==========================================
   CHAT INPUT AREA
   ========================================== */
.chat-input-area {
    padding: 12px 20px;
    background-color: var(--bg-panel);
    display: flex;
    gap: 10px;
    align-items: center;
    border-top: 1px solid var(--border-color);
    flex-shrink: 0;
    min-height: 72px;
}

#message-input {
    flex: 1;
    padding: 12px 18px;
    border-radius: var(--radius-xl);
    border: 1px solid var(--border-color);
    background-color: var(--bg-input);
    color: var(--text-primary);
    font-size: 14px;
    outline: none;
    transition: var(--transition);
    resize: none;
    max-height: 120px;
    min-height: 44px;
}

#message-input:focus {
    border-color: var(--accent-color);
    box-shadow: 0 0 0 3px var(--accent-light);
}

#message-input::placeholder {
    color: var(--text-tertiary);
}

.btn-emoji {
    width: 44px;
    height: 44px;
    color: var(--text-tertiary);
}

.btn-emoji:hover {
    color: var(--text-primary);
}

.btn-send {
    background: linear-gradient(135deg, var(--accent-color), var(--accent-hover));
    border: none;
    color: white;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: var(--transition);
    box-shadow: 0 2px 12px rgba(124, 108, 240, 0.3);
}

.btn-send:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 20px rgba(124, 108, 240, 0.4);
}

.btn-send:active {
    transform: scale(0.92);
}

.btn-send:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none;
}

/* ==========================================
   RESPONSIVIDADE - MOBILE & TABLET
   ========================================== */
@media (max-width: 768px) {
    .sidebar {
        position: absolute;
        width: 100%;
        height: 100%;
        left: 0;
        top: 0;
        transform: translateX(0);
        z-index: 5;
        border-right: none;
        box-shadow: var(--shadow-lg);
    }

    .chat-area {
        position: absolute;
        width: 100%;
        height: 100%;
        left: 0;
        top: 0;
        transform: translateX(100%);
        z-index: 10;
        transition: var(--transition);
    }

    .app-container.chat-open .sidebar {
        transform: translateX(-100%);
    }

    .app-container.chat-open .chat-area {
        transform: translateX(0);
    }

    .btn-back {
        display: flex;
    }

    .message {
        max-width: 85%;
    }

    .sidebar-header {
        padding: 12px 16px;
        min-height: 64px;
    }

    .sidebar-header h2 {
        font-size: 18px;
    }

    .contact-item {
        padding: 10px 16px;
    }

    .contact-avatar {
        width: 44px;
        height: 44px;
    }

    .chat-header {
        padding: 10px 16px;
        min-height: 64px;
    }

    .chat-header-avatar {
        width: 38px;
        height: 38px;
    }

    .current-chat-info h3 {
        font-size: 15px;
    }

    .messages-container {
        padding: 16px;
    }

    .chat-input-area {
        padding: 10px 16px;
        min-height: 64px;
    }

    #message-input {
        font-size: 15px;
        padding: 10px 16px;
    }

    .btn-send {
        width: 44px;
        height: 44px;
    }
}

@media (max-width: 480px) {
    .sidebar {
        min-width: unset;
    }

    .sidebar-header h2 {
        font-size: 16px;
    }

    .logo-icon {
        font-size: 22px;
    }

    .contact-avatar {
        width: 38px;
        height: 38px;
    }

    .contact-info h4 {
        font-size: 14px;
    }

    .contact-info .last-message {
        font-size: 12px;
    }

    .message {
        max-width: 90%;
        font-size: 13px;
        padding: 8px 14px;
    }

    .chat-header-avatar {
        width: 34px;
        height: 34px;
    }

    .current-chat-info h3 {
        font-size: 14px;
    }

    .status-text {
        font-size: 11px;
    }

    .messages-container {
        padding: 12px;
    }

    .chat-input-area {
        padding: 8px 12px;
        gap: 8px;
        min-height: 56px;
    }

    #message-input {
        font-size: 14px;
        padding: 8px 14px;
        min-height: 38px;
    }

    .btn-send {
        width: 40px;
        height: 40px;
    }

    .btn-send svg {
        width: 18px;
        height: 18px;
    }

    .btn-emoji {
        width: 38px;
        height: 38px;
    }
}

@media (max-width: 380px) {
    .contact-item {
        padding: 8px 12px;
    }

    .contact-avatar {
        width: 34px;
        height: 34px;
    }

    .contact-info h4 {
        font-size: 13px;
    }

    .current-chat-info h3 {
        font-size: 13px;
    }

    .message {
        max-width: 92%;
        font-size: 12px;
        padding: 8px 12px;
    }
}

/* ==========================================
   EMOJI MODAL
   ========================================== */
.emoji-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(8px);
    z-index: 100;
    display: none;
    align-items: center;
    justify-content: center;
    animation: overlayFadeIn 0.25s ease;
}

.emoji-modal-overlay.active {
    display: flex;
}

@keyframes overlayFadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

.emoji-modal {
    background-color: var(--bg-panel);
    border-radius: var(--radius-lg);
    width: 90%;
    max-width: 480px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-lg);
    animation: modalSlideUp 0.3s ease;
    border: 1px solid var(--border-color);
}

@keyframes modalSlideUp {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.emoji-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.emoji-modal-header h3 {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
}

.btn-close-emoji {
    width: 36px;
    height: 36px;
}

.emoji-search-wrapper {
    padding: 12px 20px;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

#emoji-search-input {
    width: 100%;
    padding: 10px 16px;
    border-radius: var(--radius-xl);
    border: 1px solid var(--border-color);
    background-color: var(--bg-input);
    color: var(--text-primary);
    font-size: 14px;
    outline: none;
    transition: var(--transition);
}

#emoji-search-input:focus {
    border-color: var(--accent-color);
    box-shadow: 0 0 0 3px var(--accent-light);
}

#emoji-search-input::placeholder {
    color: var(--text-tertiary);
}

.emoji-categories {
    display: flex;
    gap: 4px;
    padding: 8px 16px;
    overflow-x: auto;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
    scrollbar-width: none;
}

.emoji-categories::-webkit-scrollbar {
    display: none;
}

.emoji-category {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 6px 10px;
    border-radius: var(--radius-sm);
    font-size: 18px;
    transition: var(--transition);
    flex-shrink: 0;
    white-space: nowrap;
}

.emoji-category:hover {
    background-color: var(--bg-hover);
    color: var(--text-primary);
}

.emoji-category.active {
    background-color: var(--accent-light);
    color: var(--text-primary);
    box-shadow: 0 0 0 1px var(--accent-color);
}

.emoji-grid {
    flex: 1;
    overflow-y: auto;
    padding: 12px 16px;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(42px, 1fr));
    gap: 4px;
    max-height: 300px;
}

.emoji-grid::-webkit-scrollbar {
    width: 4px;
}

.emoji-grid::-webkit-scrollbar-track {
    background: transparent;
}

.emoji-grid::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 10px;
}

.emoji-item {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 26px;
    padding: 6px;
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: var(--transition);
    background: transparent;
    border: none;
    user-select: none;
}

.emoji-item:hover {
    background-color: var(--bg-hover);
    transform: scale(1.15);
}

.emoji-item:active {
    transform: scale(0.9);
}

.emoji-no-results {
    grid-column: 1 / -1;
    text-align: center;
    padding: 40px 20px;
    color: var(--text-secondary);
}

.emoji-no-results .emoji-icon {
    font-size: 40px;
    display: block;
    margin-bottom: 12px;
}

.emoji-no-results h4 {
    color: var(--text-primary);
    margin-bottom: 4px;
}

.emoji-no-results p {
    font-size: 13px;
    color: var(--text-tertiary);
}

/* ==========================================
   EMOJI RESPONSIVIDADE
   ========================================== */
@media (max-width: 480px) {
    .emoji-modal {
        width: 95%;
        max-height: 90vh;
        border-radius: var(--radius-md);
    }

    .emoji-modal-header {
        padding: 12px 16px;
    }

    .emoji-modal-header h3 {
        font-size: 15px;
    }

    .emoji-search-wrapper {
        padding: 8px 16px;
    }

    #emoji-search-input {
        font-size: 13px;
        padding: 8px 14px;
    }

    .emoji-categories {
        padding: 6px 12px;
        gap: 2px;
    }

    .emoji-category {
        font-size: 16px;
        padding: 4px 8px;
    }

    .emoji-grid {
        padding: 8px 12px;
        grid-template-columns: repeat(auto-fill, minmax(36px, 1fr));
        max-height: 250px;
    }

    .emoji-item {
        font-size: 22px;
        padding: 4px;
    }
}

@media (max-width: 380px) {
    .emoji-grid {
        grid-template-columns: repeat(auto-fill, minmax(32px, 1fr));
        max-height: 200px;
    }

    .emoji-item {
        font-size: 18px;
        padding: 3px;
    }

    .emoji-category {
        font-size: 14px;
        padding: 3px 6px;
    }
}