/* Reset e Variáveis */
:root {
    --primary-color: #1976D2;
    --primary-dark: #0D47A1;
    --secondary-color: #42A5F5;
    --bg-color: #F0F2F5;
    --sidebar-bg: #FFFFFF;
    --message-bg: #E3F2FD;
    --message-sent: #DCF8C6;
    --border-color: #E0E0E0;
    --text-primary: #333333;
    --text-secondary: #666666;
    --hover-bg: #F5F5F5;
    --online-color: #31A24C;
    --offline-color: #8696A0;
    --shadow: 0 2px 5px rgba(0,0,0,0.1);
}

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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: var(--bg-color);
    color: var(--text-primary);
}

body.login-page {
    overflow-y: auto;
    overflow-x: hidden;
}

body.chat-page {
    overflow: hidden;
}

/* ===== LOGIN PAGE ===== */
.login-page {
    background: linear-gradient(135deg, #1976D2 0%, #0D47A1 100%);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: 40px 20px;
    overflow-y: auto;
}

.login-container {
    width: 100%;
    max-width: 450px;
    padding: 20px;
}

.login-box {
    background: white;
    border-radius: 20px;
    padding: 40px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.2);
    height: auto;
    width: 100%;
}

.login-header {
    text-align: center;
    margin-bottom: 30px;
}

.login-header i {
    font-size: 60px;
    color: var(--primary-color);
    margin-bottom: 15px;
}

.login-header h1 {
    font-size: 28px;
    color: var(--text-primary);
    margin-bottom: 5px;
}

.login-header p {
    color: var(--text-secondary);
    font-size: 14px;
}

.form-container {
    display: none;
    height: auto;
    overflow: visible;
}

.form-container.active {
    display: block;
}

.form-container h2 {
    font-size: 24px;
    margin-bottom: 25px;
    color: var(--text-primary);
}

.form-container form {
    width: 100%;
    height: auto;
    overflow: visible;
}

.form-container button[type="submit"],
.form-container .btn {
    display: flex !important;
    width: 100%;
    padding: 15px;
    border: none;
    border-radius: 10px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    background: var(--primary-color);
    color: white;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin: 15px 0 20px 0;
    visibility: visible !important;
    opacity: 1 !important;
    position: relative;
    z-index: 10;
    transition: all 0.3s ease;
}

.form-container button[type="submit"]:hover,
.form-container .btn:hover {
    background: var(--primary-dark);
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(25, 118, 210, 0.3);
}

/* Garantir que o formulário de cadastro seja totalmente visível */
#registerForm.active {
    min-height: 500px;
    padding-bottom: 20px;
}

#registerForm button {
    display: flex !important;
}

.form-group {
    position: relative;
    margin-bottom: 20px;
}

.form-group i {
    position: absolute;
    left: 15px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-secondary);
}

.form-group input {
    width: 100%;
    padding: 15px 15px 15px 45px;
    border: 2px solid var(--border-color);
    border-radius: 10px;
    font-size: 14px;
    transition: all 0.3s;
}

.form-group input:focus {
    outline: none;
    border-color: var(--primary-color);
}

.checkbox-group {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 20px;
    position: relative;
    z-index: 1;
}

.checkbox-group input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
    accent-color: var(--primary-color);
    position: relative;
    z-index: 2;
    pointer-events: auto;
    flex-shrink: 0;
}

.checkbox-group label {
    font-size: 14px;
    color: var(--text-primary);
    cursor: pointer;
    user-select: none;
    position: relative;
    z-index: 2;
}

.btn {
    width: 100%;
    padding: 15px;
    border: none;
    border-radius: 10px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin-top: 10px;
    position: relative;
    z-index: 1;
}

.btn-primary {
    background: var(--primary-color);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-dark);
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(25, 118, 210, 0.3);
}

.btn-primary:active {
    transform: translateY(0);
}

.form-toggle {
    text-align: center;
    margin-top: 20px;
    color: var(--text-secondary);
    font-size: 14px;
}

.form-toggle a {
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 600;
}

.form-toggle a:hover {
    text-decoration: underline;
}


.alert {
    padding: 12px 15px;
    border-radius: 8px;
    margin-top: 15px;
    font-size: 14px;
    position: relative;
    z-index: 0;
    animation: slideDown 0.3s ease;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.alert.success {
    background: #D4EDDA;
    color: #155724;
    border: 1px solid #C3E6CB;
    border-left: 4px solid #28A745;
}

.alert.error {
    background: #F8D7DA;
    color: #721C24;
    border: 1px solid #F5C6CB;
    border-left: 4px solid #DC3545;
}

/* ===== CHAT PAGE ===== */
.chat-container {
    display: flex;
    height: 100vh;
    max-width: 1600px;
    margin: 0 auto;
    background: white;
    box-shadow: var(--shadow);
}

/* ===== SIDEBAR ===== */
.sidebar {
    width: 380px;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
}

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

.user-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.avatar {
    width: 45px;
    height: 45px;
    border-radius: 50%;
    object-fit: cover;
}

.user-details h3 {
    font-size: 16px;
    font-weight: 500;
    margin-bottom: 2px;
}

.status-indicator {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--online-color);
}

.status-indicator.offline {
    background: var(--offline-color);
}

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

.icon-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 18px;
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    transition: background 0.3s;
}

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

.search-box {
    padding: 10px 15px;
    background: var(--bg-color);
    display: flex;
    align-items: center;
    gap: 15px;
    border-bottom: 1px solid var(--border-color);
}

.search-box i {
    color: var(--text-secondary);
}

.search-box input {
    flex: 1;
    border: none;
    background: white;
    padding: 10px 15px;
    border-radius: 20px;
    font-size: 14px;
}

.search-box input:focus {
    outline: none;
}

.conversations-list {
    flex: 1;
    overflow-y: auto;
}

.conversation-item {
    display: flex;
    padding: 15px 20px;
    cursor: pointer;
    border-bottom: 1px solid var(--border-color);
    transition: background 0.3s;
}

.conversation-item:hover {
    background: var(--hover-bg);
}

.conversation-item.active {
    background: var(--bg-color);
}

.conversation-item .avatar {
    width: 50px;
    height: 50px;
    margin-right: 15px;
}

.conversation-info {
    flex: 1;
    min-width: 0;
}

.conversation-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 5px;
}

.conversation-name {
    font-size: 16px;
    font-weight: 500;
    color: var(--text-primary);
}

.conversation-time {
    font-size: 12px;
    color: var(--text-secondary);
}

.conversation-preview {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.last-message {
    font-size: 14px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 220px;
}

.unread-badge {
    background: var(--secondary-color);
    color: white;
    border-radius: 50%;
    min-width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 600;
    padding: 0 6px;
}

/* ===== CHAT AREA ===== */
.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--chat-bg);
    position: relative;
}

.no-chat-selected {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-secondary);
}

.no-chat-selected i {
    font-size: 80px;
    margin-bottom: 20px;
    opacity: 0.5;
}

.no-chat-selected h2 {
    font-size: 24px;
    margin-bottom: 10px;
}

.chat-content {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.chat-header {
    background: var(--bg-color);
    padding: 15px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border-color);
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    overflow: hidden;
}

.chat-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.chat-info h3 {
    font-size: 16px;
    font-weight: 500;
    margin-bottom: 2px;
}

.chat-status {
    font-size: 13px;
    color: var(--text-secondary);
}

.chat-actions {
    display: flex;
    gap: 15px;
}

/* Barra de pesquisa de mensagens */
.message-search-bar {
    display: none;
    background: white;
    padding: 10px 10px;
    border-bottom: 1px solid var(--border-color);
    align-items: center;
    gap: 8px;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    overflow: hidden;
    overflow-x: hidden;
    position: relative;
    left: 0;
    right: 0;
    margin: 0;
    /* Desabilitada animação para evitar overflow inicial no mobile */
    /* animation: slideDown 0.3s ease; */
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.search-input-wrapper {
    flex: 1;
    display: flex;
    align-items: center;
    background: var(--bg-color);
    border-radius: 20px;
    padding: 8px 12px;
    gap: 6px;
    min-width: 0;
    max-width: calc(100% - 55px);
    box-sizing: border-box;
    overflow: hidden;
    flex-shrink: 1;
}

.search-input-wrapper i {
    color: var(--text-secondary);
    font-size: 14px;
}

.search-input-wrapper input {
    flex: 1;
    border: none;
    background: transparent;
    outline: none;
    font-size: 14px;
    color: var(--text-primary);
    min-width: 0;
    width: 100%;
    max-width: 100%;
}

.search-input-wrapper input::placeholder {
    color: var(--text-secondary);
}

.btn-clear-search {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background 0.3s;
    flex-shrink: 0;
    width: 24px;
    height: 24px;
}

.btn-clear-search:hover {
    background: rgba(0, 0, 0, 0.05);
}

.btn-close-search {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background 0.3s, color 0.3s;
    font-size: 16px;
    flex-shrink: 0;
    width: 36px;
    height: 36px;
    min-width: 36px;
}

.btn-close-search:hover {
    background: var(--hover-bg);
    color: var(--text-primary);
}

/* Highlight de mensagens na pesquisa */
.message.search-highlight {
    animation: highlightPulse 0.5s ease;
}

.message.search-highlight .message-content {
    background: #FFF9C4 !important;
    box-shadow: 0 2px 8px rgba(255, 193, 7, 0.3);
}

@keyframes highlightPulse {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.02);
    }
}

/* Feedback de pesquisa */
.search-feedback {
    display: none;
    text-align: center;
    padding: 20px;
    color: var(--text-secondary);
    font-size: 14px;
}

.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100" viewBox="0 0 100 100"><rect fill="%23E5DDD5" width="100" height="100"/></svg>');
}

.message {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    margin-bottom: 15px;
    animation: messageSlide 0.3s ease;
}

@keyframes messageSlide {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message.sent {
    justify-content: flex-end;
}

.message.received {
    justify-content: flex-start;
}

.message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
    border: 2px solid white;
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

.message-content {
    max-width: 65%;
    padding: 8px 12px;
    border-radius: 8px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
    position: relative;
    box-sizing: border-box;
    overflow: hidden;
    word-wrap: break-word;
}

.message.sent .message-content {
    background: var(--message-sent);
    border-bottom-right-radius: 2px;
}

.message.received .message-content {
    background: var(--message-received);
    border-bottom-left-radius: 2px;
}

/* Garantir que imagens dentro de mensagens não ultrapassem o container */
.message-content img {
    max-width: 100%;
    height: auto;
    display: block;
}

.message-sender {
    font-size: 13px;
    font-weight: 600;
    color: var(--primary-color);
    margin-bottom: 3px;
}

.message-text {
    font-size: 14px;
    line-height: 1.5;
    word-wrap: break-word;
}

.message-image {
    max-width: 100%;
    min-width: 150px;
    width: auto;
    height: auto;
    border-radius: 8px;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    object-fit: contain;
    display: block;
    box-sizing: border-box;
}

.message-image:hover {
    transform: scale(1.02);
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

.message-file {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px;
    background: rgba(0,0,0,0.05);
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.2s, transform 0.2s;
    user-select: none;
}

.message-file:hover {
    background: rgba(0,0,0,0.08);
    transform: translateX(2px);
}

.message-file:active {
    transform: scale(0.98);
}

.message-file i {
    font-size: 24px;
    color: var(--primary-color);
}

.message-file-info {
    flex: 1;
}

.message-file-name {
    font-size: 14px;
    font-weight: 500;
}

.message-file-size {
    font-size: 12px;
    color: var(--text-secondary);
}

.message-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 3px;
    gap: 8px;
}

.message-time {
    font-size: 11px;
    color: var(--text-secondary);
    flex: 1;
}

.btn-delete-message {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px 6px;
    border-radius: 4px;
    font-size: 12px;
    opacity: 0.5; /* TEMPORÁRIO: mudado de 0 para 0.5 para debug */
    transition: opacity 0.2s, background 0.2s, color 0.2s;
    flex-shrink: 0;
}

.message:hover .btn-delete-message {
    opacity: 1;
}

.btn-delete-message:hover {
    background: rgba(244, 67, 54, 0.1);
    color: #f44336;
}

.file-downloaded-indicator {
    color: var(--text-secondary);
    font-size: 12px;
    padding: 4px 6px;
    opacity: 0.6;
    flex-shrink: 0;
}

.file-downloaded-indicator i {
    font-size: 11px;
}

.chat-input {
    background: var(--bg-color);
    padding: 15px 20px;
    display: flex;
    align-items: flex-end;
    gap: 10px;
    border-top: 1px solid var(--border-color);
}

.input-wrapper {
    flex: 1;
    background: white;
    border-radius: 25px;
    padding: 10px 20px;
}

.input-wrapper textarea {
    width: 100%;
    border: none;
    resize: none;
    font-size: 14px;
    font-family: inherit;
    max-height: 120px;
}

.input-wrapper textarea:focus {
    outline: none;
}

.btn-send {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: var(--primary-color);
    color: white;
    border: none;
    font-size: 18px;
    cursor: pointer;
    transition: all 0.3s;
}

.btn-send:hover {
    background: var(--primary-dark);
    transform: scale(1.05);
}

/* ===== MODAL ===== */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: 20px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: white;
    border-radius: 15px;
    width: 90%;
    max-width: 500px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 10px 40px rgba(0,0,0,0.3);
    margin: auto;
    position: relative;
}

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

.modal-header h3 {
    font-size: 20px;
}

.close-modal {
    background: transparent;
    border: none;
    font-size: 20px;
    cursor: pointer;
    color: var(--text-secondary);
    padding: 5px;
}

.modal-body {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
}

.users-list {
    margin-top: 15px;
}

.user-item {
    display: flex;
    align-items: center;
    padding: 12px;
    cursor: pointer;
    border-radius: 10px;
    transition: background 0.3s;
    -webkit-tap-highlight-color: rgba(0,0,0,0.1);
    touch-action: manipulation;
    user-select: none;
}

.user-item:hover,
.user-item:active {
    background: var(--hover-bg);
}

.user-item .avatar {
    width: 45px;
    height: 45px;
    margin-right: 12px;
}

.user-item-info {
    flex: 1;
}

.user-name {
    font-size: 15px;
    font-weight: 500;
}

.user-email {
    font-size: 13px;
    color: var(--text-secondary);
}

/* ===== DROPDOWN MENU ===== */
.dropdown-menu {
    position: absolute;
    background: white;
    border-radius: 8px;
    box-shadow: 0 5px 20px rgba(0,0,0,0.2);
    min-width: 200px;
    z-index: 1000;
    overflow: hidden;
}

.dropdown-menu a {
    display: block;
    padding: 15px 20px;
    color: var(--text-primary);
    text-decoration: none;
    font-size: 14px;
    transition: background 0.3s;
}

.dropdown-menu a:hover {
    background: var(--hover-bg);
}

.dropdown-menu a i {
    margin-right: 10px;
    color: var(--text-secondary);
}

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: #CCC;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #999;
}

/* ===== GROUP INFO PANEL ===== */
.group-info-panel {
    width: 350px;
    background: var(--sidebar-bg);
    border-left: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    animation: slideInRight 0.3s ease;
}

@keyframes slideInRight {
    from {
        transform: translateX(100%);
    }
    to {
        transform: translateX(0);
    }
}

.group-info-header {
    padding: 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 15px;
}

.group-info-header h3 {
    flex: 1;
    font-size: 18px;
    color: var(--text-primary);
}

.group-info-content {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
}

.group-info-avatar {
    text-align: center;
    padding: 30px 20px;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 20px;
}

.group-info-avatar img {
    width: 120px;
    height: 120px;
    border-radius: 50%;
    object-fit: cover;
    margin-bottom: 15px;
    box-shadow: var(--shadow);
}

.group-info-avatar h2 {
    font-size: 20px;
    color: var(--text-primary);
    word-break: break-word;
}

.group-info-section {
    margin-bottom: 25px;
}

.section-header {
    margin-bottom: 15px;
}

.section-header h4 {
    font-size: 14px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.group-members-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.member-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px;
    border-radius: 8px;
    transition: background 0.2s;
}

.member-item:hover {
    background: var(--hover-bg);
}

.member-item img {
    width: 45px;
    height: 45px;
    border-radius: 50%;
    object-fit: cover;
}

.member-info {
    flex: 1;
}

.member-name {
    font-size: 15px;
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 2px;
}

.member-email {
    font-size: 13px;
    color: var(--text-secondary);
}

.member-badge {
    font-size: 11px;
    padding: 3px 8px;
    border-radius: 12px;
    background: var(--primary-color);
    color: white;
    font-weight: 500;
}

.member-status {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    border: 2px solid white;
}

.member-status.online {
    background: var(--online-color);
}

.member-status.offline {
    background: var(--offline-color);
}

/* ===== RESPONSIVE ===== */

/* Tablets e iPads (entre 768px e 1024px) */
@media (min-width: 769px) and (max-width: 1024px) {
    .messages-container {
        overflow-x: hidden;
        max-width: 100%;
        padding: 18px 12px;
    }
    
    .message-image {
        max-width: 100%;
        min-width: 140px;
        object-fit: contain;
        box-sizing: border-box;
    }
    
    .message-content {
        max-width: 70%;
        box-sizing: border-box;
    }
    
    .message-content:has(.message-image) {
        max-width: 68%;
        padding: 8px;
    }
}

/* Smartphones e tablets pequenos (até 768px) */
@media (max-width: 768px) {
    /* Prevenir overflow horizontal global */
    body, html {
        overflow-x: hidden;
        max-width: 100vw;
        position: relative;
    }
    
    .chat-container {
        max-width: 100%;
        overflow-x: hidden;
    }
    
    .sidebar {
        width: 100%;
        position: relative;
        z-index: 2;
    }
    
    .chat-area {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        transform: translateX(100%);
        transition: transform 0.3s ease;
        z-index: 3;
        background: white;
        overflow-x: hidden;
        max-width: 100vw;
    }
    
    .chat-area.active {
        transform: translateX(0);
    }
    
    /* Painel de informações do grupo mobile */
    .group-info-panel {
        position: absolute;
        top: 0;
        right: 0;
        width: 100%;
        height: 100%;
        z-index: 4;
        animation: slideInRight 0.3s ease;
    }
    
    /* Limitar tamanho do avatar do grupo no mobile/tablet */
    .group-info-avatar img {
        max-width: 100px !important;
        max-height: 100px !important;
        width: 100px !important;
        height: 100px !important;
    }
    
    .group-info-avatar {
        padding: 20px 15px !important;
    }
    
    .group-info-avatar h2 {
        font-size: 18px !important;
    }
    
    /* Melhorar visualização dos membros no mobile/tablet */
    .group-members-list {
        max-height: calc(100vh - 280px) !important;
        overflow-y: auto !important;
    }
    
    .member-item {
        padding: 12px 10px !important;
    }
    
    .member-item img {
        width: 40px !important;
        height: 40px !important;
        flex-shrink: 0;
    }
    
    .member-info {
        flex: 1;
        min-width: 0;
    }
    
    .member-name {
        font-size: 14px !important;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    
    .member-email {
        font-size: 12px !important;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    
    /* Botão voltar mobile */
    .chat-header::before {
        content: '\f060';
        font-family: 'Font Awesome 5 Free';
        font-weight: 900;
        position: absolute;
        left: 15px;
        top: 50%;
        transform: translateY(-50%);
        font-size: 18px;
        color: var(--text-primary);
        cursor: pointer;
        padding: 8px;
        border-radius: 50%;
        transition: background 0.3s;
    }
    
    .chat-header::before:hover {
        background: var(--hover-bg);
    }
    
    .chat-header .user-info {
        margin-left: 40px;
    }
    
    .message-content {
        max-width: 85%;
    }
    
    /* Container de mensagens com padding reduzido */
    .messages-container {
        padding: 15px 10px;
        overflow-x: hidden;
        max-width: 100vw;
        box-sizing: border-box;
    }
    
    .message {
        max-width: 100%;
        padding-right: 5px;
    }
    
    /* Ajuste de imagens anexadas no mobile */
    .message-image {
        max-width: 100% !important;
        min-width: 100px;
        width: auto;
        height: auto;
        display: block;
        margin: 4px 0;
        object-fit: contain;
        box-sizing: border-box;
    }
    
    .message-image:hover {
        transform: none;
    }
    
    /* Garantir que o conteúdo da mensagem com imagem não ultrapasse */
    .message-content {
        max-width: calc(100vw - 100px) !important;
        padding: 6px !important;
        box-sizing: border-box;
    }
    
    .message.sent .message-content {
        max-width: calc(100vw - 100px) !important;
        margin-right: 5px;
    }
    
    .message.received .message-content {
        max-width: calc(100vw - 120px) !important;
        margin-left: 5px;
    }
    
    .message-content:has(.message-image) {
        max-width: calc(100vw - 110px) !important;
        padding: 6px !important;
    }
    
    .message.sent .message-content:has(.message-image) {
        max-width: calc(100vw - 100px) !important;
    }
    
    .message.received .message-content:has(.message-image) {
        max-width: calc(100vw - 130px) !important;
    }
    
    /* Ajustes de texto */
    .conversation-header h4 {
        font-size: 14px;
    }
    
    .last-message {
        font-size: 13px;
    }
    
    .user-details h3 {
        font-size: 14px;
    }
    
    /* Input de mensagem */
    .message-input-area {
        padding: 10px;
    }
    
    #messageInput {
        font-size: 14px;
    }
    
    .send-btn {
        width: 40px;
        height: 40px;
    }
    
    /* Correção: Campo de entrada no mobile */
    .chat-input {
        padding: 10px 15px 15px 15px;
        gap: 8px;
        position: sticky;
        bottom: 10px;
        width: 100%;
        max-width: 100vw;
        box-sizing: border-box;
        margin-bottom: 10px;
    }
    
    .input-wrapper {
        flex: 1;
        min-width: 0;
        padding: 8px 15px;
    }
    
    .input-wrapper textarea {
        font-size: 14px;
        max-height: 100px;
    }
    
    .btn-send, .btn-attach {
        width: 45px;
        height: 45px;
        flex-shrink: 0;
    }
    
    /* Garantir que chat-area não ultrapasse viewport */
    .chat-area {
        max-width: 100vw;
        overflow-x: hidden;
    }
    
    .chat-messages {
        padding: 15px 10px;
    }
}

@media (max-width: 480px) {
    .sidebar-header {
        padding: 12px 15px;
    }
    
    .avatar {
        width: 40px;
        height: 40px;
    }
    
    .user-details h3 {
        font-size: 13px;
    }
    
    .search-box input {
        font-size: 14px;
        padding: 8px 12px;
    }
    
    .conversation-item {
        padding: 12px 15px;
    }
    
    .message-content {
        padding: 10px 12px;
        font-size: 14px;
    }
    
    /* Container de mensagens com padding reduzido em telas pequenas */
    .messages-container {
        padding: 12px 8px;
        overflow-x: hidden;
        max-width: 100vw;
        box-sizing: border-box;
    }
    
    .message {
        max-width: 100%;
        padding-right: 3px;
    }
    
    /* Ajuste de imagens anexadas em telas menores */
    .message-image {
        max-width: 100% !important;
        min-width: 80px;
        width: auto;
        height: auto;
        display: block;
        margin: 3px 0;
        border-radius: 6px;
        object-fit: contain;
        box-sizing: border-box;
    }
    
    .message-image:hover {
        transform: none;
    }
    
    /* Garantir que o conteúdo da mensagem com imagem não ultrapasse */
    .message-content {
        max-width: calc(100vw - 90px) !important;
        padding: 5px !important;
        box-sizing: border-box;
    }
    
    .message.sent .message-content {
        max-width: calc(100vw - 80px) !important;
        margin-right: 3px;
    }
    
    .message.received .message-content {
        max-width: calc(100vw - 110px) !important;
        margin-left: 3px;
    }
    
    .message-content:has(.message-image) {
        max-width: calc(100vw - 100px) !important;
        padding: 4px !important;
    }
    
    .message.sent .message-content:has(.message-image) {
        max-width: calc(100vw - 85px) !important;
    }
    
    .message.received .message-content:has(.message-image) {
        max-width: calc(100vw - 120px) !important;
    }
    
    .chat-header {
        padding: 12px 15px;
    }
    
    .message-input-area {
        padding: 8px;
        gap: 8px;
    }
    
    #messageInput {
        padding: 10px 12px;
        font-size: 13px;
    }
    
    /* Correção extra: Campo de entrada em telas muito pequenas */
    .chat-input {
        padding: 8px 10px 12px 10px;
        gap: 6px;
        bottom: 15px;
        margin-bottom: 15px;
    }
    
    .input-wrapper {
        padding: 6px 12px;
    }
    
    .btn-send, .btn-attach {
        width: 40px;
        height: 40px;
        font-size: 16px;
    }
    
    /* Barra de pesquisa no mobile - CORREÇÃO CRÍTICA */
    .message-search-bar {
        padding: 6px 6px !important;
        gap: 4px !important;
        width: 100% !important;
        max-width: 100% !important;
        margin: 0 !important;
        box-sizing: border-box !important;
        overflow: hidden !important;
        overflow-x: hidden !important;
    }
    
    .search-input-wrapper {
        padding: 5px 8px !important;
        gap: 4px !important;
        max-width: calc(100% - 45px) !important;
        min-width: 0 !important;
        flex-shrink: 1 !important;
        overflow: hidden !important;
    }
    
    .search-input-wrapper input {
        font-size: 13px !important;
        min-width: 0 !important;
        width: 100% !important;
        max-width: 100% !important;
    }
    
    .search-input-wrapper i {
        font-size: 11px !important;
        flex-shrink: 0 !important;
    }
    
    .btn-clear-search {
        padding: 4px !important;
        flex-shrink: 0 !important;
        width: 22px !important;
        height: 22px !important;
    }
    
    .btn-close-search {
        padding: 4px !important;
        flex-shrink: 0 !important;
        width: 28px !important;
        height: 28px !important;
        min-width: 28px !important;
        font-size: 13px !important;
    }
    
    /* Prevenir scroll horizontal */
    body, html {
        overflow-x: hidden;
        max-width: 100vw;
    }
    
    .chat-container {
        max-width: 100vw;
        overflow-x: hidden;
    }
    
    /* Modal mobile - CORREÇÃO CRÍTICA */
    .modal {
        padding: 10px !important;
        align-items: flex-start !important;
        padding-top: 20px !important;
    }
    
    .modal-content {
        width: 100% !important;
        max-width: 100% !important;
        max-height: calc(100vh - 40px) !important;
        margin: 0 !important;
        border-radius: 10px;
    }
    
    .modal-header {
        padding: 15px;
    }
    
    .modal-header h3 {
        font-size: 18px;
    }
    
    .modal-body {
        padding: 15px;
        overflow-y: auto;
        max-height: calc(100vh - 140px);
    }
    
    .users-list {
        margin-top: 10px;
    }
    
    .user-item {
        padding: 12px 10px;
    }
    
    .user-item .avatar {
        width: 45px;
        height: 45px;
    }
    
    .user-item-info {
        flex: 1;
    }
    
    .user-name {
        font-size: 15px;
    }
    
    .user-email {
        font-size: 13px;
    }
    
    .user-select-item {
        padding: 12px;
    }
    
    .user-select-item .user-name {
        font-size: 14px;
    }
    
    .user-select-item .user-email {
        font-size: 12px;
    }
    
    /* Menu do usuário mobile */
    #userMenu {
        width: 200px;
        right: 10px !important;
        left: auto !important;
    }
}

/* ===== LOADING ===== */
.loading {
    text-align: center;
    padding: 20px;
    color: var(--text-secondary);
}

.loading i {
    font-size: 24px;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    from {
        transform: rotate(0deg);
    }
    to {
        transform: rotate(360deg);
    }
}

/* ===== CORREÇÕES MOBILE/TABLET CRÍTICAS ===== */
/* Prevenir overflow horizontal em todos os dispositivos */
* {
    -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
    box-sizing: border-box;
}

html {
    overflow-x: hidden;
    width: 100%;
}

body {
    overflow-x: hidden;
    width: 100%;
    position: relative;
}

/* Garantir que containers não ultrapassem viewport */
.chat-container,
.sidebar,
.chat-area,
.chat-messages,
.chat-input,
.messages-container,
.message-search-bar {
    max-width: 100%;
    overflow-x: hidden;
}

/* Correção específica para área de input */
@media (max-width: 768px) {
    .chat-input {
        position: sticky !important;
        bottom: 10px !important;
        left: 0 !important;
        right: 0 !important;
        width: 100% !important;
        max-width: 100vw !important;
        margin: 0 0 10px 0 !important;
        box-sizing: border-box !important;
        padding-bottom: 12px !important;
    }
    
    .input-wrapper {
        max-width: calc(100% - 120px) !important;
        box-sizing: border-box !important;
    }
    
    /* Barra de pesquisa mobile - CRÍTICO */
    .message-search-bar {
        width: 100% !important;
        max-width: 100% !important;
        padding: 8px 8px !important;
        margin: 0 !important;
        box-sizing: border-box !important;
        overflow: hidden !important;
        overflow-x: hidden !important;
        left: 0 !important;
        right: 0 !important;
        gap: 6px !important;
    }
    
    /* CRÍTICO: Mensagens e imagens */
    .message {
        width: 100% !important;
        max-width: 100% !important;
        overflow: visible !important;
        box-sizing: border-box !important;
    }
    
    .message-content,
    .message.sent .message-content,
    .message.received .message-content {
        display: inline-block !important;
        max-width: calc(100vw - 70px) !important;
        box-sizing: border-box !important;
        overflow: hidden !important;
        word-wrap: break-word !important;
    }
    
    .message-image {
        width: 100% !important;
        max-width: 100% !important;
        height: auto !important;
        display: block !important;
        box-sizing: border-box !important;
    }
    
    .search-input-wrapper {
        max-width: calc(100% - 50px) !important;
        min-width: 0 !important;
        padding: 6px 10px !important;
        flex-shrink: 1 !important;
        gap: 4px !important;
        overflow: hidden !important;
    }
    
    .search-input-wrapper input {
        min-width: 0 !important;
        width: 100% !important;
        max-width: 100% !important;
        font-size: 13px !important;
    }
    
    .search-input-wrapper i {
        font-size: 12px !important;
        flex-shrink: 0 !important;
    }
    
    .btn-clear-search {
        flex-shrink: 0 !important;
        width: 24px !important;
        height: 24px !important;
        padding: 4px !important;
    }
    
    .btn-close-search {
        flex-shrink: 0 !important;
        width: 32px !important;
        height: 32px !important;
        min-width: 32px !important;
        padding: 4px !important;
        font-size: 14px !important;
    }
    
    /* Modal acima de tudo */
    .modal {
        z-index: 9999 !important;
    }
    
    .modal-content {
        position: relative;
        z-index: 10000;
    }
}

/* Correção para telas de tablet - CRÍTICO para iPad */
@media (min-width: 481px) and (max-width: 1024px) {
    /* Garantir que body/html não ultrapassem */
    body, html {
        overflow-x: hidden;
        max-width: 100vw;
        width: 100%;
    }
    
    .chat-container {
        max-width: 100vw;
        overflow-x: hidden;
    }
    
    /* Campo de entrada - CORREÇÃO CRÍTICA iPad */
    .chat-input {
        position: sticky !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        width: 100% !important;
        max-width: 100vw !important;
        padding: 12px 15px !important;
        margin: 0 !important;
        box-sizing: border-box !important;
        display: flex !important;
        align-items: center !important;
        gap: 10px !important;
        background: white !important;
        border-top: 1px solid var(--border-color) !important;
        z-index: 100 !important;
    }
    
    .input-wrapper {
        flex: 1 !important;
        min-width: 0 !important;
        max-width: calc(100% - 130px) !important;
        padding: 10px 15px !important;
        box-sizing: border-box !important;
    }
    
    #messageInput {
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
        resize: none !important;
    }
    
    .btn-send, .btn-attach {
        width: 48px !important;
        height: 48px !important;
        flex-shrink: 0 !important;
        min-width: 48px !important;
    }
    
    /* Modal para iPad */
    .modal {
        padding: 15px !important;
    }
    
    .modal-content {
        width: 90% !important;
        max-width: 600px !important;
        max-height: calc(100vh - 60px) !important;
    }
    
    .modal-body {
        overflow-y: auto;
        max-height: calc(100vh - 180px);
    }
}

/* ======================================
   CORREÇÕES ESPECÍFICAS PARA iPad
   ====================================== */

/* iPad Portrait (vertical) - 768px */
@media only screen 
  and (min-device-width: 768px) 
  and (max-device-width: 1024px) 
  and (orientation: portrait) {
    
    html, body {
        height: 100vh !important;
        overflow-x: hidden !important;
        -webkit-overflow-scrolling: touch !important;
    }
    
    .chat-container {
        height: 100vh !important;
        display: flex !important;
        flex-direction: row !important;
    }
    
    .chat-area {
        display: flex !important;
        flex-direction: column !important;
        height: 100vh !important;
    }
    
    .messages {
        flex: 1 !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch !important;
    }
    
    .chat-input {
        position: sticky !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        width: 100% !important;
        max-width: 100vw !important;
        padding: 15px !important;
        margin: 0 !important;
        box-sizing: border-box !important;
        display: flex !important;
        background: white !important;
        border-top: 1px solid var(--border-color) !important;
        z-index: 1000 !important;
    }
    
    .input-wrapper {
        flex: 1 !important;
        min-width: 0 !important;
        max-width: calc(100% - 140px) !important;
        box-sizing: border-box !important;
    }
    
    #messageInput {
        width: 100% !important;
        box-sizing: border-box !important;
    }
    
    .btn-send, .btn-attach {
        width: 50px !important;
        height: 50px !important;
        flex-shrink: 0 !important;
    }
}

/* iPad Landscape (horizontal) - 1024px */
@media only screen 
  and (min-device-width: 768px) 
  and (max-device-width: 1024px) 
  and (orientation: landscape) {
    
    html, body {
        height: 100vh !important;
        overflow-x: hidden !important;
        -webkit-overflow-scrolling: touch !important;
    }
    
    .chat-container {
        height: 100vh !important;
        display: flex !important;
        flex-direction: row !important;
    }
    
    .chat-area {
        display: flex !important;
        flex-direction: column !important;
        height: 100vh !important;
    }
    
    .messages {
        flex: 1 !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch !important;
    }
    
    .chat-input {
        position: sticky !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        width: 100% !important;
        max-width: 100vw !important;
        padding: 12px 20px !important;
        margin: 0 !important;
        box-sizing: border-box !important;
        display: flex !important;
        background: white !important;
        border-top: 1px solid var(--border-color) !important;
        z-index: 1000 !important;
    }
    
    .input-wrapper {
        flex: 1 !important;
        min-width: 0 !important;
        max-width: calc(100% - 150px) !important;
        box-sizing: border-box !important;
    }
    
    #messageInput {
        width: 100% !important;
        box-sizing: border-box !important;
    }
    
    .btn-send, .btn-attach {
        width: 52px !important;
        height: 52px !important;
        flex-shrink: 0 !important;
    }
}

/* iPad Pro 11" e 12.9" */
@media only screen 
  and (min-device-width: 1024px) 
  and (max-device-width: 1366px) {
    
    .chat-input {
        position: sticky !important;
        bottom: 0 !important;
        width: 100% !important;
        max-width: 100vw !important;
        box-sizing: border-box !important;
    }
    
    .input-wrapper {
        max-width: calc(100% - 160px) !important;
    }
}

/* ======================================
   CORREÇÃO DE TAMANHO DE INPUTS NO iPAD
   Problema: inputs com font-size < 16px aparecem menores
   Solução: Normalizar todos os inputs para 16px no iPad
   ====================================== */

/* Todos os iPads - Portrait e Landscape */
@media only screen 
  and (min-device-width: 768px) 
  and (max-device-width: 1366px) {
    
    /* TODOS os inputs, textareas e selects */
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="search"],
    input[type="tel"],
    input[type="url"],
    input[type="number"],
    input[type="date"],
    textarea,
    select {
        font-size: 16px !important;
        -webkit-text-size-adjust: 100% !important;
        -webkit-appearance: none !important;
        appearance: none !important;
    }
    
    /* Form group inputs (login, registro, perfil) */
    .form-group input {
        font-size: 16px !important;
        padding: 15px 15px 15px 45px !important;
        min-height: 48px !important;
        box-sizing: border-box !important;
    }
    
    /* Search box inputs */
    .search-box input {
        font-size: 16px !important;
        padding: 12px 15px !important;
        min-height: 44px !important;
    }
    
    /* Message input textarea */
    .input-wrapper textarea,
    #messageInput {
        font-size: 16px !important;
        min-height: 44px !important;
    }
    
    /* Search input wrapper */
    .search-input-wrapper input {
        font-size: 16px !important;
        min-height: 40px !important;
    }
    
    /* Placeholder text também em 16px */
    input::placeholder,
    textarea::placeholder {
        font-size: 16px !important;
    }
    
    /* Prevenir zoom automático do iOS em inputs */
    input:focus,
    textarea:focus,
    select:focus {
        font-size: 16px !important;
    }
    
    /* Checkboxes e radio buttons mantêm tamanho original */
    input[type="checkbox"],
    input[type="radio"] {
        width: 20px !important;
        height: 20px !important;
        min-height: 20px !important;
    }
    
    /* Botões de envio e ações */
    .btn-send,
    .btn-attach,
    #btnAttach {
        min-width: 48px !important;
        min-height: 48px !important;
        font-size: 18px !important;
    }
    
    /* Botão de anexo específico */
    #btnAttach {
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        border-radius: 50% !important;
        transition: all 0.3s ease !important;
    }
    
    #btnAttach:active {
        transform: scale(0.95) !important;
        background: rgba(0, 0, 0, 0.05) !important;
    }
    
    /* Feedback visual durante upload */
    #btnAttach:disabled {
        opacity: 0.6 !important;
        cursor: not-allowed !important;
    }
}

/* ======================================
   MENU DE CONTEXTO E ENCAMINHAMENTO
   ====================================== */

/* Menu de Contexto da Mensagem */
.message-context-menu {
    position: fixed;
    background: white;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    z-index: 1000;
    min-width: 160px;
    overflow: hidden;
    animation: contextMenuFadeIn 0.15s ease;
}

@keyframes contextMenuFadeIn {
    from {
        opacity: 0;
        transform: scale(0.95);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.context-menu-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 12px 16px;
    border: none;
    background: none;
    font-size: 14px;
    color: var(--text-primary);
    cursor: pointer;
    transition: background 0.2s;
    text-align: left;
}

.context-menu-item:hover {
    background: var(--hover-bg);
}

.context-menu-item i {
    width: 18px;
    color: var(--text-secondary);
}

/* Modal de Encaminhamento */
#forwardMessageModal .modal-content {
    max-width: 450px;
}

.forward-preview {
    background: var(--bg-color);
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 15px;
    border-left: 4px solid var(--primary-color);
}

.forward-preview-header {
    font-size: 12px;
    color: var(--primary-color);
    font-weight: 600;
    margin-bottom: 6px;
}

.forward-preview-content {
    font-size: 14px;
    color: var(--text-primary);
    word-break: break-word;
    max-height: 80px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.forward-preview-content.file-preview {
    display: flex;
    align-items: center;
    gap: 10px;
}

.forward-preview-content.file-preview i {
    font-size: 24px;
    color: var(--primary-color);
}

.forward-conversations-list {
    max-height: 350px;
    overflow-y: auto;
}

.forward-conversation-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    cursor: pointer;
    border-radius: 8px;
    transition: background 0.2s;
}

.forward-conversation-item:hover {
    background: var(--hover-bg);
}

.forward-conversation-item .avatar {
    width: 45px;
    height: 45px;
    border-radius: 50%;
    object-fit: cover;
}

.forward-conversation-item .conv-info {
    flex: 1;
    min-width: 0;
}

.forward-conversation-item .conv-name {
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.forward-conversation-item .conv-type {
    font-size: 12px;
    color: var(--text-secondary);
}

/* Indicador de mensagem encaminhada */
.forwarded-indicator {
    font-size: 11px;
    color: var(--text-secondary);
    margin-bottom: 4px;
    display: flex;
    align-items: center;
    gap: 4px;
}

.forwarded-indicator i {
    font-size: 10px;
}

/* Mensagem selecionada para contexto */
.message.context-active {
    background: rgba(25, 118, 210, 0.08) !important;
    border-radius: 8px;
}
