/**
 * Estilos CSS para el Sistema de Mensajería
 * Inspirado en WhatsApp con diseño responsive
 */

/* Reset y configuración base */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    /* Colores principales */
    --primary-color: #25D366;
    --primary-dark: #128C7E;
    --secondary-color: #34B7F1;
    --background: #E5DDD5;
    --sidebar-bg: #FFFFFF;
    --chat-bg: #F7F8FA;
    --message-bg-own: #DCF8C6;
    --message-bg-other: #FFFFFF;
    --text-primary: #111B21;
    --text-secondary: #667781;
    --text-muted: #8696A0;
    --border-color: #E9EDEF;
    --hover-bg: #F5F6F6;
    --online-color: #06D755;
    --error-color: #E53E3E;
    
    /* Tipografía */
    --font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    
    /* Espaciado y bordes */
    --border-radius: 8px;
    --shadow-small: 0 1px 2px rgba(0, 0, 0, 0.1);
    --shadow-medium: 0 2px 8px rgba(0, 0, 0, 0.15);
    --shadow-large: 0 4px 16px rgba(0, 0, 0, 0.2);
}

body {
    font-family: var(--font-family);
    font-size: 14px;
    color: var(--text-primary);
    background-color: var(--background);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Estilos de la página de login */
.login-page {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-dark) 100%);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.login-container {
    width: 100%;
    max-width: 400px;
}

.login-card {
    background: white;
    border-radius: 12px;
    box-shadow: var(--shadow-large);
    overflow: hidden;
}

.login-header {
    text-align: center;
    padding: 24px;
    background: var(--primary-color);
    color: white;
}

.logo-icon {
    font-size: 48px;
    margin-bottom: 16px;
}

.app-logo h1 {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 8px;
}

.login-subtitle {
    color: rgba(255, 255, 255, 0.9);
    font-size: 12px;
}

.login-form {
    padding: 24px;
}

.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 500;
    color: var(--text-primary);
}

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

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

.login-btn {
    width: 100%;
    padding: 12px;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: var(--border-radius);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.login-btn:hover {
    background: var(--primary-dark);
}

.login-btn:disabled {
    background: var(--text-muted);
    cursor: not-allowed;
}

.spinner {
    width: 20px;
    height: 20px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: white;
    animation: spin 1s ease-in-out infinite;
}

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

.error-message {
    background: var(--error-color);
    color: white;
    padding: 8px;
    border-radius: var(--border-radius);
    text-align: center;
    margin: 16px 24px;
    font-size: 12px;
}

.demo-users {
    background: #F8F9FA;
    padding: 16px;
    border-top: 1px solid var(--border-color);
}

.demo-users h3 {
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.demo-user {
    padding: 8px;
    background: white;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    margin-bottom: 8px;
    cursor: pointer;
    transition: background-color 0.3s ease;
    font-size: 12px;
}

.demo-user:hover {
    background: var(--hover-bg);
}

.demo-user:last-child {
    margin-bottom: 0;
}

/* Estilos de la página de chat */
.chat-page {
    height: 100vh;
    overflow: hidden;
}

.app-container {
    display: flex;
    height: 100vh;
    background: var(--background);
}

/* Sidebar (panel izquierdo) */
.sidebar {
    width: 400px;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    min-width: 320px;
}

.sidebar-header {
    padding: 16px;
    background: var(--primary-color);
    color: white;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

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

.user-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid rgba(255, 255, 255, 0.3);
}

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

.user-status {
    font-size: 12px;
    opacity: 0.9;
}

.user-status.online::before {
    content: "● ";
    color: var(--online-color);
}

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

.action-btn {
    width: 40px;
    height: 40px;
    border: none;
    background: rgba(255, 255, 255, 0.1);
    color: white;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.3s ease;
}

.action-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

.search-container {
    padding: 16px;
    background: white;
    border-bottom: 1px solid var(--border-color);
}

.search-input {
    width: 100%;
    padding: 10px;
    border: 1px solid var(--border-color);
    border-radius: 20px;
    background: #F0F2F5;
    font-size: 12px;
}

.search-input:focus {
    outline: none;
    background: white;
    border-color: var(--primary-color);
}

.chat-list {
    flex: 1;
    overflow-y: auto;
    background: white;
}

.chat-item {
    padding: 16px;
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    transition: background-color 0.3s ease;
    display: flex;
    align-items: center;
    gap: 16px;
    position: relative;
}

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

.chat-item.active {
    background: #E3F2FD;
    border-left: 3px solid var(--primary-color);
}

.chat-item.unread {
    background: #F0F9FF;
    border-left: 3px solid var(--primary-color);
}

.chat-item.unread .chat-name {
    font-weight: 700;
    color: var(--text-primary);
}

.chat-item.unread .chat-last-message {
    font-weight: 600;
    color: var(--text-primary);
}

.chat-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
}

.group-avatar {
    border: 2px solid var(--primary-color);
}

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

.chat-name {
    font-weight: 600;
    margin-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

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

.chat-meta {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    flex-shrink: 0;
    gap: 4px;
}

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

.chat-status {
    font-size: 10px;
}

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

.chat-status.offline {
    color: var(--text-muted);
}

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

.chat-options-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px;
    border-radius: 50%;
    opacity: 0;
    transition: all 0.3s ease;
    position: absolute;
    top: 50%;
    right: 8px;
    transform: translateY(-50%);
}

.chat-item:hover .chat-options-btn {
    opacity: 1;
}

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

.loading-chats {
    padding: 24px;
    text-align: center;
    color: var(--text-secondary);
}

/* Ventana de chat (panel derecho) */
.chat-window {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--chat-bg);
}

.no-chat-selected {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
}

.no-chat-content {
    max-width: 300px;
}

.no-chat-icon {
    font-size: 64px;
    margin-bottom: 16px;
    opacity: 0.6;
}

.no-chat-content h2 {
    color: var(--text-primary);
    margin-bottom: 8px;
}

.no-chat-content p {
    color: var(--text-secondary);
}

.chat-header {
    padding: 16px;
    background: var(--sidebar-bg);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 16px;
}

.mobile-back-btn {
    display: none;
    background: none;
    border: none;
    color: var(--text-primary);
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
}

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

.chat-contact-info {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 16px;
    cursor: pointer;
    padding: 8px;
    border-radius: var(--border-radius);
    transition: background-color 0.3s ease;
}

.chat-contact-info:hover {
    background: var(--hover-bg);
}

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

.contact-details h3 {
    font-weight: 600;
    margin-bottom: 2px;
}

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

.messages-area {
    flex: 1;
    background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><defs><pattern id="chat-bg" x="0" y="0" width="100" height="100" patternUnits="userSpaceOnUse"><circle cx="50" cy="50" r="1" fill="%23E5DDD5" opacity="0.3"/></pattern></defs><rect width="100" height="100" fill="url(%23chat-bg)"/></svg>');
    overflow-y: auto;
    padding: 16px;
}

.messages-container {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.message {
    display: flex;
    max-width: 80%;
    word-wrap: break-word;
}

.message.own {
    align-self: flex-end;
}

.message.other {
    align-self: flex-start;
}

.message.system {
    align-self: center;
    max-width: 60%;
}

.message-bubble {
    background: var(--message-bg-other);
    padding: 8px 12px;
    border-radius: 12px;
    box-shadow: var(--shadow-small);
    position: relative;
    min-width: 0;
}

.message.own .message-bubble {
    background: var(--message-bg-own);
    border-bottom-right-radius: 4px;
}

.message.other .message-bubble {
    border-bottom-left-radius: 4px;
}

.message.system .message-bubble {
    background: #F0F2F5;
    color: var(--text-secondary);
    font-size: 12px;
    text-align: center;
    font-style: italic;
}

.message-content {
    margin-bottom: 4px;
    word-break: break-word;
}

.message-time-status {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 4px;
    margin-top: 2px;
}

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

.status-icon {
    font-size: 14px;
    margin-left: 4px;
}

.status-icon.single-check::after {
    content: "✓";
    color: #8696A0;
}

.status-icon.double-check-gray::after {
    content: "✓✓";
    color: #8696A0;
}

.status-icon.double-check-blue::after {
    content: "✓✓";
    color: var(--primary-color);
}

.message.other .message-time-status {
    justify-content: flex-start;
}

/* Estilos para mensajes de archivo */
.message-image {
    max-width: 200px;
    max-height: 200px;
    border-radius: var(--border-radius);
    cursor: pointer;
    margin-bottom: 4px;
    display: block;
}

.image-caption {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 4px;
}

.file-message {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: var(--border-radius);
    margin-bottom: 4px;
}

.file-icon {
    font-size: 24px;
}

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

.file-name {
    font-weight: 600;
    margin-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.file-size {
    font-size: 11px;
    color: var(--text-muted);
}

.file-download {
    color: var(--primary-color);
    text-decoration: none;
    font-size: 12px;
    font-weight: 600;
    padding: 4px 8px;
    border-radius: 4px;
    transition: background-color 0.3s ease;
}

.file-download:hover {
    background: rgba(37, 211, 102, 0.1);
    text-decoration: none;
}

.message-input-area {
    padding: 16px;
    background: var(--sidebar-bg);
    border-top: 1px solid var(--border-color);
}

.message-input-container {
    display: flex;
    align-items: center;
    gap: 8px;
    background: white;
    border: 1px solid var(--border-color);
    border-radius: 24px;
    padding: 8px;
}

.attachment-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    transition: background-color 0.3s ease;
}

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

.message-input {
    flex: 1;
    border: none;
    outline: none;
    padding: 8px 12px;
    font-size: 14px;
    resize: none;
    max-height: 100px;
}

.send-btn {
    background: var(--primary-color);
    border: none;
    color: white;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.3s ease;
}

.send-btn:hover:not(:disabled) {
    background: var(--primary-dark);
}

.send-btn:disabled {
    background: var(--text-muted);
    cursor: not-allowed;
}

/* Estilos de modales */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1001;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.modal-content {
    background: white;
    border-radius: 12px;
    box-shadow: var(--shadow-large);
    max-width: 500px;
    width: 100%;
    max-height: 80vh;
    overflow-y: auto;
}

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

.modal-header h3 {
    font-size: 16px;
    font-weight: 600;
}

.modal-close {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
}

.modal-close:hover {
    background: var(--hover-bg);
}

.modal-body {
    padding: 24px;
}

.modal-footer {
    padding: 24px;
    border-top: 1px solid var(--border-color);
    display: flex;
    gap: 16px;
    justify-content: flex-end;
}

/* Estilos mejorados para el modal de creación de grupos */
.participants-list {
    max-height: 300px;
    overflow-y: auto;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: 8px;
    background: #FAFAFA;
}

.participant-item {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    transition: all 0.3s ease;
    border-radius: 8px;
    margin-bottom: 4px;
}

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

.participant-item:last-child {
    border-bottom: none;
}

.participant-item.selected {
    background: #E3F2FD;
    border-color: var(--primary-color);
}

.participant-checkbox {
    width: 18px;
    height: 18px;
    accent-color: var(--primary-color);
    cursor: pointer;
}

.participant-checkbox:checked {
    background: var(--primary-color);
    border-color: var(--primary-color);
}

.participant-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
}

.participant-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.participant-name {
    font-weight: 600;
    font-size: 14px;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 8px;
}

.participant-email {
    color: var(--text-secondary);
    font-size: 12px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.participant-status {
    font-size: 10px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

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

.participant-status.offline {
    color: var(--text-muted);
}

/* Botones */
.btn-primary {
    background: var(--primary-color);
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: var(--border-radius);
    cursor: pointer;
    font-weight: 600;
    transition: background-color 0.3s ease;
}

.btn-primary:hover:not(:disabled) {
    background: var(--primary-dark);
}

.btn-primary:disabled {
    background: var(--text-muted);
    cursor: not-allowed;
}

.btn-secondary {
    background: transparent;
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    padding: 10px 20px;
    border-radius: var(--border-radius);
    cursor: pointer;
    font-weight: 600;
    transition: background-color 0.3s ease;
}

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

.btn-danger {
    background: var(--error-color);
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: var(--border-radius);
    cursor: pointer;
    font-weight: 600;
    transition: background-color 0.3s ease;
}

.btn-danger:hover {
    background: #C53030;
}

/* Menú contextual */
.context-menu {
    position: fixed;
    background: white;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-medium);
    z-index: 1000;
    min-width: 150px;
    overflow: hidden;
}

.context-menu-item {
    padding: 12px 16px;
    cursor: pointer;
    font-size: 14px;
    transition: background-color 0.3s ease;
    display: flex;
    align-items: center;
    gap: 8px;
}

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

.context-menu-item.danger:hover {
    background: #FED7D7;
    color: var(--error-color);
}

/* Modal de imagen ampliada */
.image-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.image-modal img {
    max-width: 100%;
    max-height: 100%;
    border-radius: var(--border-radius);
}

.image-modal-close {
    position: absolute;
    top: 20px;
    right: 20px;
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 20px;
}

/* Notificaciones de mensajes nuevos */
.new-message-notification {
    position: fixed;
    top: 20px;
    right: 20px;
    background: var(--primary-color);
    color: white;
    padding: 12px 16px;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-medium);
    z-index: 1000;
    animation: slideInRight 0.3s ease-out;
    cursor: pointer;
    max-width: 300px;
}

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

.notification-content {
    display: flex;
    align-items: center;
}

.notification-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    margin-right: 8px;
}

.notification-text {
    flex: 1;
}

.notification-sender {
    font-weight: 600;
    margin-bottom: 2px;
}

.notification-message {
    font-size: 14px;
    opacity: 0.9;
}

/* Diseño responsive */
@media (max-width: 768px) {
    .sidebar {
        width: 100%;
        position: absolute;
        z-index: 10;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
    }
    
    .sidebar.active {
        transform: translateX(0);
    }
    
    .chat-window {
        width: 100%;
    }
    
    .mobile-back-btn {
        display: block;
    }
    
    .message {
        max-width: 90%;
    }
    
    .modal-content {
        margin: 16px;
        max-height: 90vh;
    }
    
    .unread-badge {
        min-width: 18px;
        height: 18px;
        font-size: 10px;
    }
    
    .new-message-notification {
        top: 10px;
        right: 10px;
        left: 10px;
        max-width: none;
    }
    
    .chat-options-btn {
        opacity: 1;
        position: static;
        transform: none;
    }
    
    .chat-meta {
        align-items: center;
        flex-direction: row;
        gap: 8px;
    }
    
    .participant-item {
        padding: 10px 12px;
        gap: 10px;
    }
    
    .participant-avatar {
        width: 36px;
        height: 36px;
    }
    
    .participant-name {
        font-size: 13px;
    }
    
    .participant-email {
        font-size: 11px;
    }
}

@media (max-width: 480px) {
    .sidebar {
        min-width: 100%;
    }
    
    .login-container {
        padding: 8px;
    }
    
    .message {
        max-width: 95%;
    }
    
    .message-bubble {
        padding: 6px 10px;
    }
    
    .file-message {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }
}

/* Scrollbar personalizado */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: #f1f1f1;
}

::-webkit-scrollbar-thumb {
    background: var(--text-muted);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

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

.message {
    animation: fadeIn 0.3s ease;
}

/* Estados de carga */
.loading {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    color: var(--text-secondary);
}

.loading .spinner {
    width: 16px;
    height: 16px;
    border-width: 2px;
}

/* Utilidades */
.hidden {
    display: none !important;
}

.visible {
    display: block !important;
}

.text-center {
    text-align: center;
}

.text-muted {
    color: var(--text-muted);
}

.text-primary {
    color: var(--primary-color);
}

hr {
    border: none;
    border-top: 1px solid var(--border-color);
    margin: 16px 0;
}